Calculating the size of an sdl_surface

Hi

I want to copy the pixel data from a sdl surface to a custom c structure. I
am trying to figure out how large that structure’s data part should be.

I am using opengl as the renderer and I can load and draw the image
successfully.

I can get the width and height from the sdl surface. I can also get the
bytes per pixel.

Is the calculation for the size just be

(width * bytesperpixel) + (height * bytesperpixel)

?

Hello,

Hi

I want to copy the pixel data from a sdl surface to a custom c
structure. I am trying to figure out how large that structure’s data
part should be.

I am using opengl as the renderer and I can load and draw the image
successfully.

I can get the width and height from the sdl surface. I can also get
the bytes per pixel.

Is the calculation for the size just be

(width * bytesperpixel) + (height * bytesperpixel)

That would calculate the size of a single row + a single colum. What you
would want would more be like
"size = widthheightbytesperpixel"
Since you have width*height pixels and each one takes up the given
amount of bytes.

Also SDL_Surface has a member named pitch wich holds the length of a row
of pixels in bytes [1]. The calculation would now become
size = height*pitch

[1] https://wiki.libsdl.org/SDL_Surface

I hope i could help

Greetings
Malte

?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

-------------- next part --------------
A non-text attachment was scrubbed…
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20151207/a60295fe/attachment.pgpAm 06.12.2015 um 10:50 schrieb Owen Alanzo Hogarth: