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.
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?
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/