Converting pixel values into RGB components...part 2



Hi all,

It turns out I can use the default GdkRGB colormap in order to extract the RGB
components for PseudoColor GdkImages.

However, my problem now lies in TrueColor and PseudoColor visuals. I know I can
take the RGB values and convert them to a pixel value with the equation:

pixel = 
    ((R >> (component_depth - red_prec)) << red_shift) | 
    ((G >> (component_depth - green_prec)) << green_shift) | 
    ((B >> (component_depth - blue_prec)) << blue_shift)

Now what I need to do is to take the pixel value and extract the RGB values. I
tried doing something like this:

R = (pixel & red_mask) >> red_shift
G = (pixel & green_mask) >> green_shift
B = (pixel & blue_mask) >> blue_shift

but that didn't seem to work. The colors are all wrong when I try doing this!

I'm pretty stumped with the math. Do any of you know what I'm missing?

Thanks,
--Arthur



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