Jump to content

  • Log In with Google      Sign In   
  • Create Account

FreeImage converting to 32bit...


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
10 replies to this topic

#1 MatsK   Members   -  Reputation: 226

Like
0Likes
Like

Posted 22 May 2011 - 11:06 AM

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?

Sponsor:

#2 empirical2   Members   -  Reputation: 566

Like
1Likes
Like

Posted 22 May 2011 - 12:23 PM

Any idea?



Try adding, before saving
FreeImage_SetTransparent(Img,true);

#3 MatsK   Members   -  Reputation: 226

Like
0Likes
Like

Posted 22 May 2011 - 01:19 PM

Thanks!
That didn't work. :(
The bit-depth is still 24.

#4 Matias Goldberg   Crossbones+   -  Reputation: 3470

Like
1Likes
Like

Posted 22 May 2011 - 01:54 PM

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 )

#5 MChiz   Members   -  Reputation: 161

Like
1Likes
Like

Posted 22 May 2011 - 01:59 PM

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

#6 MatsK   Members   -  Reputation: 226

Like
0Likes
Like

Posted 22 May 2011 - 02:06 PM

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

'8 bits per channel give 256 colours per channel, and an RGB image of 24 bit.'

#7 MatsK   Members   -  Reputation: 226

Like
0Likes
Like

Posted 22 May 2011 - 02:09 PM

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.



#8 ryan20fun   Members   -  Reputation: 1040

Like
0Likes
Like

Posted 22 May 2011 - 11:59 PM

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.

#9 ryan20fun   Members   -  Reputation: 1040

Like
0Likes
Like

Posted 23 May 2011 - 12:05 AM

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

#10 MatsK   Members   -  Reputation: 226

Like
0Likes
Like

Posted 24 May 2011 - 01:50 AM

Thanks! :)

#11 ryan20fun   Members   -  Reputation: 1040

Like
0Likes
Like

Posted 24 May 2011 - 02:14 AM

so you managed to get them to 32Bit ?
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.




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