Advertisement

Saving surfaces..

Started by April 29, 2001 09:19 PM
2 comments, last by [bobafet] 23 years, 9 months ago
Hi.. I''ve been having a bit of trouble saving surfaces to files. I get the surface pointer with Lock() and then save the surface data to the file. The problem is that if the display is in 16-bit mode and the surface is saved and then loaded again with the display in a different mode, it doesn''t work because the surface data is dependant on the bit depth (obviously). My question is, do I have to convert the saved surface to the display''s bit-depth everytime I load it? Is there an easier and/or more efficient way of doing this? Am I taking the wrong approach? Any help on this matter is greatly appreciated, thanks. - Ian Perez (fett@willcomp.com) - "It is by will alone I set my mind in motion"
- Ian Perez (iperez.fett@verizon.net) - "It is by will alone I set my mind in motion"
It sounds like you''re not using any standard file format, just writing the raw image data out to a file. If so, just add a byte near the beginning of the file that gives the color depth at the time it was saved. When you read it back in, compare that value with the current color depth and do the conversion if necessary.

-Ironblayde
 Aeon Software

Down with Tiberia!
"All your women are belong to me." - Nekrophidius
"Your superior intellect is no match for our puny weapons!"
Advertisement
Ahh, ok.. how about the conversion? What''s the best way to convert the data to the display''s bpp?

- Ian Perez (fett@willcomp.com) - "It is by will alone I set my mind in motion"
- Ian Perez (iperez.fett@verizon.net) - "It is by will alone I set my mind in motion"
What I would do is save the data out always in a 24 bit mode (assuming you don''t need an alpha channel).

Depending on what the bit depth of the surface you''re saving is, you''ll need to handle it differently:

8 bit: Save the RGB of each pixel''s palette entry to the file.

16 bit: retrieve the rgb values from each pixel, and scale them up to be from 0-255 instead of 0-32 or 0-64. This means you''ll need to treat green differently depending on if you''re in 555 or 565 color mode. But you''ll need to scale up by 8 on each pixel, or by 4 on green if you''re in 565 mode.

24/32 bit: This should be obvious. Just store the RGB bytes in the file.

This way, when you read the file back in, you will have 1 byte each for RGB, and you can convert as necessary on load. If you are loading into 8 bit color, then you''ll have to search the palette for the closest match. If you''re in 16 bit or 24 bit, you probably already have a color encoding function/macro, and if you don''t, you should probably write one. But you can just pass in the values for each color channel.

Good luck.

This topic is closed to new replies.

Advertisement