FreeImage and filesize

Started by
4 comments, last by Punchin Deck 15 years, 9 months ago
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
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.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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

This topic is closed to new replies.

Advertisement