Re: Strange behaviour / Possible Bug with GC Function



Colin Thomas <colin designresources co uk> writes:
As I am always drawing to the foreground, are you saying that the GDKFUNCTIONS
are not ORing the rectangle (I am adding to the foreground), with what I have
already drawn to the foreground? If this is the case, why is the RED-BLUE 
overlap marked?

I hope you can see what I am trying to achieve now :-) 

Yes, I didn't understand before.

If we can only GDK_OR foreground to background, AFTER a rectangle has been 
applied, could it be that we "copy" the foreground to the background ( and
simultaneously clear the foreground)in readiness for the next rectangle to be 
applied (or something similar), to get around this??

The GDK_OR is with whatever is already drawn to the drawable.

So say your drawable pixel contains the bits:

  11

and you draw with the foreground pixel:
  
  01

then the resulting bits in the drawable will be:

  11 | 01 = 11

So as you can see frequently an OR operation doesn't change anything.

Also, as you can see the exact color generated by OR depends on the
GdkVisual (whether the display is 8-bit or 24-bit or whatever). 
Because on 8-bit displays, a pixel is an index into a color table,
and on 24-bit displays it's an RGB triplet.

GDK_XOR is more likely to always give you a different value from the
two originals:

 11 ^ 01 = 10

But doesn't always:

 0 ^ 0 = 0
 0 ^ 1 = 1
 1 ^ 0 = 1

Owen points out that what you're really after is probably alpha
blending, which is the following operation with 24-bit pixels:

 
  void set_pixel(const guint col, const guint row,  // x, y 
                 const guchar r, const guchar g, const guchar b,
                 const int alpha)
    {
      int v;
      guchar* pixel = buf_ + rowstride_*row + col*3;
      v = *pixel;
      *pixel++ = v + (((r - v) * alpha + 0x80) >> 8);
      v = *pixel;
      *pixel++ =  v + (((g - v) * alpha + 0x80) >> 8);
      v = *pixel;
      *pixel++ =  v + (((b - v) * alpha + 0x80) >> 8);
    }

So there you blend one color into another, so the foreground color is
partially transparent and the background "shows through." There's no
GdkFunction for this. What you're really after if you want alpha
blending is a 2D rendering API along the lines of Java2D. libart_lgpl
and the GnomeCanvas have a limited form of this.

Havoc








[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]