Permalink
Browse files

[Bug #582114] Take layer opacity into account when blending over the …

…checkerboard pattern.
  • Loading branch information...
1 parent 644594b commit 1dac720abcc3450c3fb9c5de450ab3a0b53abdf7 @jpobst jpobst committed May 5, 2012
@@ -13,12 +13,19 @@ namespace Pinta.Core
{
public class CheckerBoardOperation
{
+ public int opacity = 255;
+
+ public CheckerBoardOperation (double opacity)
+ {
+ this.opacity = (int)(opacity * 255);
+ }
+
public ColorBgra Apply (ColorBgra color, int checkerX, int checkerY)
{
int b = color.B;
int g = color.G;
int r = color.R;
- int a = color.A;
+ int a = ApplyOpacity (color.A);
int v = ((checkerX ^ checkerY) & 8) * 8 + 191;
a = a + (a >> 7);
@@ -30,5 +37,13 @@ public ColorBgra Apply (ColorBgra color, int checkerX, int checkerY)
return ColorBgra.FromUInt32 ((uint)b + ((uint)g << 8) + ((uint)r << 16) + 0xff000000);
}
+
+ private byte ApplyOpacity (byte a)
+ {
+ int r = a;
+ r = r * this.opacity + 0x80;
+ r = ((((r) >> 8) + (r)) >> 8);
+ return (byte)r;
+ }
}
}
@@ -16,8 +16,6 @@ namespace Pinta.Gui.Widgets
{
class CanvasRenderer
{
- private static CheckerBoardOperation checker_op = new CheckerBoardOperation ();
-
private Size source_size;
private Size destination_size;
private Layer offset_layer;
@@ -105,6 +103,7 @@ private unsafe void RenderOneToOne (List<Layer> layers, Cairo.ImageSurface dst,
{
// The first layer should be blended with the transparent checkerboard
var checker = true;
+ CheckerBoardOperation checker_op = null;
for (int i = 0; i < layers.Count; i++) {
var layer = layers[i];
@@ -122,6 +121,9 @@ private unsafe void RenderOneToOne (List<Layer> layers, Cairo.ImageSurface dst,
// Get the blend mode for this layer and opacity
var blend_op = UserBlendOps.GetBlendOp (layer.BlendMode, layer.Opacity);
+ if (checker)
+ checker_op = new CheckerBoardOperation (layer.Opacity);
+
// Figure out where our source and destination intersect
var srcRect = new Gdk.Rectangle (offset, dst.GetBounds ().Size);
srcRect.Intersect (src.GetBounds ());
@@ -165,6 +167,7 @@ private unsafe void RenderZoomIn (List<Layer> layers, Cairo.ImageSurface dst, Gd
{
// The first layer should be blended with the transparent checkerboard
var checker = true;
+ CheckerBoardOperation checker_op = null;
for (int i = 0; i < layers.Count; i++) {
var layer = layers[i];
@@ -181,6 +184,9 @@ private unsafe void RenderZoomIn (List<Layer> layers, Cairo.ImageSurface dst, Gd
// Get the blend mode for this layer and opacity
var blend_op = UserBlendOps.GetBlendOp (layer.BlendMode, layer.Opacity);
+
+ if (checker)
+ checker_op = new CheckerBoardOperation (layer.Opacity);
ColorBgra* src_ptr = (ColorBgra*)src.DataPtr;
ColorBgra* dst_ptr = (ColorBgra*)dst.DataPtr;
@@ -232,6 +238,7 @@ private unsafe void RenderZoomOut (List<Layer> layers, Cairo.ImageSurface dst, G
{
// The first layer should be blended with the transparent checkerboard
var checker = true;
+ CheckerBoardOperation checker_op = null;
for (int i = 0; i < layers.Count; i++) {
var layer = layers[i];
@@ -248,7 +255,10 @@ private unsafe void RenderZoomOut (List<Layer> layers, Cairo.ImageSurface dst, G
// Get the blend mode for this layer and opacity
var blend_op = UserBlendOps.GetBlendOp (layer.BlendMode, layer.Opacity);
-
+
+ if (checker)
+ checker_op = new CheckerBoardOperation (layer.Opacity);
+
const int fpShift = 12;
const int fpFactor = (1 << fpShift);

0 comments on commit 1dac720

Please sign in to comment.