FreeImage converting to 32bit...

Started by
9 comments, last by ryan20fun 12 years, 11 months ago
I'm using FreeImage to convert images from 8-bit to 32-bit RGBA. Here's my code:

FARExtractItemFromFileByName(m_ArchivePath.c_str(), StrFilename.c_str(),
(unsigned char**)&Buffer, 1);

FREE_IMAGE_FORMAT Fif = FreeImage_GetFIFFromFilename(StrFilename.c_str());

if(Fif != FIF_UNKNOWN)
{
FIBITMAP *Img = FreeImage_Load(Fif, StrFilename.c_str());

FIBITMAP *Tmp = Img;
Img = FreeImage_ConvertTo32Bits(Tmp);
FreeImage_Unload(Tmp);

if(StrFilename.find(".tga") == string::npos)
FreeImage_Save(FREE_IMAGE_FORMAT::FIF_PNG, Img, Replace(StrFilename, ".bmp", ".png").c_str());
else
FreeImage_Save(FREE_IMAGE_FORMAT::FIF_PNG, Img, Replace(StrFilename, ".tga", ".png").c_str());

remove(StrFilename.c_str());
//delete Img; //This causes an assertion... o_O
}


It works without crashing and all, but... when I view the images in Windows Explorer, they're supposedly only 24-bits! And SFML refuses to display them, because it only likes 32-bit images! :(

Any idea?
Advertisement

Any idea?



Try adding, before saving
FreeImage_SetTransparent(Img,true);
Thanks!
That didn't work. :(
The bit-depth is still 24.
Don't know about SFML requirements, but Windows Explorer is very unreliable for giving image data. I suggest you use a more advanced program to double check your image has alpha (GIMP is able to do so)

BTW, "delete Img" causes an assertion because you should call FreeImage_Unload( Img )
Hi:

I'm guessing that you are saving the image to disk just for debug purposes. I haven't used FreeImage to save images, so I can't help you there.

However, if you are converting the image to 32bpp just to upload it to the graphics card, you could use 'FreeImage_GetBPP' to make sure that the image is 32 bpp ( it works for me ).

About your comment on the assertion when deleting the image, I think you should call 'FreeImage_Unload' to free it.

Hope it helps.
Carlos
Thanks!
I don't have GIMP installed currently, but I opened the image in Photoshop, and it says 'RGB/8'. I Googled and found:

'[font=Verdana, Geneva, Arial, Helvetica, sans-serif][size=2]8 bits per channel give 256 colours per channel, and an RGB image of 24 bit.'[/font]

Hi:

I'm guessing that you are saving the image to disk just for debug purposes. I haven't used FreeImage to save images, so I can't help you there.

However, if you are converting the image to 32bpp just to upload it to the graphics card, you could use 'FreeImage_GetBPP' to make sure that the image is 32 bpp ( it works for me ).

About your comment on the assertion when deleting the image, I think you should call 'FreeImage_Unload' to free it.

Hope it helps.
Carlos



Nope, I'm not saving the images for debug purposes. I'm recompressing them after they've been converted. It doesn't change the bit depth though. I'll try outputting the bit-depth using FreeImage_GetBPP and see what happens.

i could conveert them to 32Bit for you, but if they are like a good few MB's can you put them in a rar / zip / whatever archive or something so that it is not a big download and upload (i dont have a fast internet connection, 192KB per sec)
you can upload it here but is wont allow archives and such only images and media as far as i know (and i dont think there are bad reprocusions for that or you could upload them to a file server or something)

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

i just noticed you are using Photoshop i have used the CS3 version and there is an option to change the image editiong mode or something like that.
here is what i think should do the job
[attachment=2407:untitled.jpg]

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

Thanks! :)

This topic is closed to new replies.

Advertisement