Re: XOR gc function




Adrian Feiguin <feiguin@ifir.ifir.edu.ar> writes:

> I have seen an annoying behavior with the XOR function. 
> The outline of my code is something like this:
> 
> values = gdk_gc_get_values(widget->style->fg_gc[0]);
> values.function = GDK_XOR;
> xor_gc = gdk_gc_new_with_values(...,values,...);
> 
> gdk_gc_set_foreground(xor_gc, &red);
> 
> When I draw a line using xor_gc, sometimes it's red on a white background,
> and green on a black background. 
> 
> BUT, when I start prefdm, things are inverted, green on white and red on
> black. 
> 
> This is something that bothers me, because if I want to draw a xored black
> line, sometimes it looks white and I can't see it on a white background.
> 
> This is also happening if I run the program on a PC and I use a Sun as
> Xserver.
> 
> Can anybody explain to me what is the concept that I'm loosing?
> (values.background, maybe?)
> <ADRIAN>

XOR-mode works with pixel values. If you are using a 
pseudo-color display, the the effects will depend on
the order that the colors are allocated.

In fact, you need to be careful about XOR'ing with a
fixed color, because it just might happen to 
have pixel value zero.

There are two approaches that work pretty reliably:

 1) If you want to swap black and white, use XOR mode
    and use, as the foreground color, either white
    or black, whichever has a non-zero pixel value.

    (This works because either white or black is almost
    always zero)

    The effect on colors other than black will be
    pretty much random for a psuedo-color display.

    This is what gnumeric does for its spreadsheat 
    display.

 2) If you just want to change colors, but don't care
    how, use GDK_INVERT instead of GDK_XOR. In this
    case, it reverses the pixel values, 

    The effect on colors other than black will be
    pretty much random for a psuedo-color display.

    This has a slightly better chance than 1) in
    making any color distinct from its XOR'd counterpart,
    though both fail on a true-color display with
    50% gray.

XOR-mode is essentially a hack, and if you want really good results,
you probably should be drawing your overlay opaquely. With something
like the GNOME canvas, that isn't to hard to do efficiently.

Regards,
                                        Owen



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