[SDL] Dumping a surface to a custom file
Bob Pendleton
bob at pendleton.com
Mon Mar 31 11:52:01 PST 2003
On Mon, 2003-03-31 at 13:02, Eduardo B. Fonseca wrote:
> Hello Guys,
>
> I'm developing an app that needs to manage a custom "archive" of images (on a
> single file). This file needs to be regenarated everytime the app quits. I
> developed a custom format that suits my app, but I'm having problems dumping
> surfaces to my file.
>
> First of all, (sorry for the newbie question) how can I *really* determine
> the *actual* size of the pixel array on the SDL_Surface? I thought it would
> be (surface->w + surface->h)*surface->format->BytesPerPixel. I must be
> missing something here.
That would be (surface->w * surface->h). Notice the * rather than a +
the area of a rectangle is width*height, not width+height.
>
> I need to keep alpha values and colorkeys on the file, so when I load the
> image, all is restored. Will a "raw dump" of the surface (keeping the
> SDL_PixelFormat and etc) work? If so, how? What about endianess?
Binary dumps rarely work across architectures. And raw dumps of pointers
never work. You can dump the values in binary, but when you read them
back you will have to reorder the bytes to adjust for endianess.
Also, think about what you are doing with respect to pixel depth. Are
you actually going to require everyone to have the same pixel depth on
every machine?
>
> My other solution was (using SDL_RWops) to use SDL_SaveBMP_RW, directing the
> output to my memory buffer. But, how can I determine it's output beforehand?
> Will it keep alphas and colorkeys? (I don't think so).
>
> Thanks a lot for *any* help.
--
+-----------------------------------+
+ Bob Pendleton: independent writer +
+ and programmer. +
+ email: Bob at Pendleton.com +
+-----------------------------------+
More information about the SDL
mailing list