Re: Pixel format conversion
- From: "BW" <this@xxxxxxxxxxxxxxxxx>
- Date: Fri, 28 Oct 2005 13:03:32 +0100
> Hi,
>
> I want to convert one pixel format to another pixel format. For example
> 8bit raw pixel data to 16 bit raw...16 to 24...32 to 16.....etc....
>
> -What's the best way and fast to do this conversion?
> -I referred few references and find out something like this...
>
> from 32bit RGB to 8bit RGB is ( (((pixel) & 0xE00000) >> 16) | \
> (((pixel) & 0x00E000) >> 11) | \
> (((pixel) & 0x0000C0) >> 6) )
>
> and from 8bit RGB to 16 RGB is
> ( (((pixel) & 0xF80000) >> 8) | \
> (((pixel) & 0x00FC00) >> 5) | \
> (((pixel) & 0x0000F8) >> 3) )
>
> But I am not sure how its derived!!! thanks for any explation?
>
> -Is there any generic way to derive such calculation/formula? Where can
> I find find more info about it?
>
> Thanks...
>
> GG
>
It works like this...
Say your source format is 24bpp and it's in the format R8 G8 B8
(rrrrrrrrggggggggbbbbbbbb).
and your destination format is 16bpp and it's in the format R5 G6 B5
(rrrrrggggggbbbbb).
First, do the red:
Extract the 5 most significant red bits by ANDing with binary
111110000000000000000000 (&F80000)
then shift it 8 places to the right so the bits are in the right position
for the 16bpp format.
Eg. RedBits = (Col24 & F80000) >> 8
Do the same for Blue and Green and then OR (or just add) the values together
to get your 16bpp colour value.
It's pretty much the same going the other way round. You extract the bits by
ORing, and then shift them so they cover the most significant (i.e. left
most) bits for that colour in your destination format.
The conversion is very fast as bitwise ANDs and shifts are very fast
operations.
Hope that makes sense. One thing to note is that 8bpp formats are sometimes
palettised, so the values are indexes into an RGB colour table. To convert
to/from a palettised 8bpp format, you'd need to do colour matching.
.
- References:
- Pixel format conversion
- From: splender . dev
- Pixel format conversion
- Prev by Date: Re: Photogrametry algorithms (3D from 2D images)
- Next by Date: Re: Pixel format conversion
- Previous by thread: Pixel format conversion
- Next by thread: Re: Pixel format conversion
- Index(es):
Relevant Pages
|