Jump to content
  • Advertisement
Sign in to follow this  
Punchin Deck

FreeImage and filesize

This topic is 3799 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Afternoon All, I'm developing a fileformat that contains multiple images and other data that I will be using to load resources into my game in an efficient manner. However I'm having a problem actually calculating the size of the file prior to saving it. For example, lets say I have a 256x256x8 png (it could be a BMP, JPG or any other file format supported by FreeImage) file and I want to calculate the size of this file, output it, and then save the image data (as a PNG). I'm doing this because when I load the image into my game I would like to know the size of it prior to loading the image data. Any clarifications please ask. Thanks, Punchin' Deck

Share this post


Link to post
Share on other sites
Advertisement
I suppose the easiest way to do this would be to store a dummy value then go back and populate it later once you know the size of the saved image by seeking within the output stream.

Share this post


Link to post
Share on other sites
Yes, I was thinking along those lines. Save the file to a memory stream, get its size, write that to my custom file and then save the image to my custom file format. That seemed a little excessive though due to memory allocations etc. but I'm guessing that I'm for the time being stuck with it. Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by Punchin Deck
That seemed a little excessive though due to memory allocations etc. but I'm guessing that I'm for the time being stuck with it.
Could you not write the dummy size variable to the output stream directly, then seek back and fill it in later?

Share this post


Link to post
Share on other sites
Would there be anything wrong in relying on the os to give you the size - if this is c++ then boost::filesystem::file_size( *p); might be an ok answer here, alternatively opening the file in ios::binary and doing source->fs.seekg ( 0, ios::end); int64_t sz = source->fs.tellg(); source->fs.seekg ( 0, ios::beg); is likely more performant than loading into a memmory buffer and then testing. can i presume to add to the question and ask - would it be typical to embed this kind of meta-information together with binary data in xml for general content management or would it ordinarily be kept seperate?

Share this post


Link to post
Share on other sites
Quote:
Original post by benryvesCould you not write the dummy size variable to the output stream directly, then seek back and fill it in later?
Sorry misunderstood what you said earlier. It's just a case of taking the difference between two file positions. That is, the position of where the filesize goes and the new position after writing the image data to the file - 4. That gives me the filesize. Then moving back the position and overwriting the dummy value. Thanks. :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!