Re: Converting pixel values into RGB components...part 2




Arthur Jerijian <lightmanaj@earthlink.net> writes:

> 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!

Looks right, except that you need:

 ((pixel & red_mask) >> red_shift) << (component_depth - red_prec)

Maybe this is your problem? (Note that the prec for the three
components will be different for 16 bit displays, so if you
don't handle this properly, you will get messed up colors.)

Regards,
                                        Owen



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