Jump to content

  • Log In with Google      Sign In   
  • Create Account


Converting a 32bit bitmap to 24 or 16 bit?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Zeke   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 November 2001 - 04:22 AM

I have a 32 bit tga file that i need to convert to a custom format. What i normally do is convert the tga to a bmp and then convert the bmp to this custom format. However I cant convert a 32 bit bmp to this format so I need to convert it to a diferent bit depth and then convert it to the format i want. Can anyone help me to either convert the 32 bit tga to a 16 bit or 24 bit bmp or convert a 32 bit bmp to a 16 or 24 bit bmp? If anyone can help i would be very thankful. Cheers

Sponsor:

#2 Zeke   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 November 2001 - 05:09 AM

ok ive found out a little bit about this. I can convert 32 bit bmp to 24 bit bmp by losing the alpha channel for each pixel. So if i go through the images pixel by pixel i can store the pixel in a DWORD (right?) and then extract the rgb bits. But how can i extract the rgb bits from the dword and where do i store them (because there isnt any type that is 3 bytes in size).

And also how do I find out if the 32 bit bmp is in AGRB or RGBA or whatever else it can be?

Anyway I hope someone can help me

Edited by - Zeke on November 6, 2001 12:14:47 PM

#3 MirekCz   Members   -  Reputation: 132

Like
Likes
Like

Posted 06 November 2001 - 05:22 AM

first of all, it''s easiest when you work with bytes while converting 32 to 24bit image, what you do is:
1.read 3 bytes for RGB value from 32bit image (skip the A value)
2.save 3 bytes into the 24bit bitmap (don''t skip any bytes)

and when you convert 32->16bpp image(16bit 565 RGB image) it''s best when you use WORD for the 16bit image.
16bit 565 RGB image is build like this (in bits)
RRRRRGGGGGGBBBBB
and you convert 32->16 like this:
1.read B value from 32bpp bitmap
2.do 16bitvalue=(b>>3) (00000000000BBBBB)
3.read G value from 32bpp bitmap
4.do 16bitvalue+=((g>>2)<<5) (00000GGGGGGBBBBB)
5.read R value from 32bpp bitmap
6.16bitvalue+=((r>>3)<<11) (RRRRRGGGGGGBBBBB)

of course skip A value from the 32bit image.

<< and >> means bit shifting, check your C book on that if you don''t know them yet.

As you can see it''s pretty straightforward. Just a bit of throwing bits around. Of course those methods aren''t very fast, but if you don''t do it in real-time they are surelly fast enought.
Hope it helps

With best regards,
Mirek Czerwiñski
http://kris.top.pl/~kherin/

#4 Zeke   Members   -  Reputation: 122

Like
Likes
Like

Posted 07 November 2001 - 02:07 AM

I got it working.Thanks very much. I really appreciate it.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS