The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
How to get SDL_Surface->pixels size?
Nemo3773


Joined: 05 Jun 2015
Posts: 6
I hope to copy RGBA data from "SDL_Surface->pixels", but I am not sure whether "pixels" is RGBA array, and what's "pixels" size. Thank you:D
How to get SDL_Surface->pixels size?
phao


Joined: 24 Nov 2014
Posts: 7
The amount of bytes the pixel data takes is .h * .pitch. You can also find more information on byte and bits size about the image by looking at the .format field (It's a SDL_PixelFormat*, which lets you access stuff like how many bytes per pixel you have there).

If you're copying pixel data directly through an SDL_Surface .pixels member, you should be aware of padding bytes. Each row of your image may be padded with some bytes. The row pixel bytes + row padding bytes is your image's pitch. When you're going through the image bytes, you want to be careful about that. You can look more about image pitch on the web.


If you're copying from an SDL_Surface to another, consider using SDL's own functions.

On Tue, Jun 9, 2015 at 11:39 PM, Nemo3773 wrote:
Quote:
I hope to copy RGBA data from "SDL_Surface->pixels", but I am not sure whether "pixels" is RGBA array, and what's "pixels" size. Thank you:D


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

How to get SDL_Surface->pixels size?
phao


Joined: 24 Nov 2014
Posts: 7
On image formats and functions to deal with SDL_Surface instances, you should check https://wiki.libsdl.org/CategoryPixels and https://wiki.libsdl.org/CategorySurface in case you haven't already. Also, check https://wiki.libsdl.org/SDL_Surface and look at the .format field (it's a pointer to an SDL_PixelFormat, https://wiki.libsdl.org/SDL_PixelFormat).

The wiki is easy enough to follow.


On Tue, Jun 9, 2015 at 11:56 PM, Pedro Henrique Antunes de Oliveira wrote:
Quote:
The amount of bytes the pixel data takes is .h * .pitch. You can also find more information on byte and bits size about the image by looking at the .format field (It's a SDL_PixelFormat*, which lets you access stuff like how many bytes per pixel you have there).

If you're copying pixel data directly through an SDL_Surface .pixels member, you should be aware of padding bytes. Each row of your image may be padded with some bytes. The row pixel bytes + row padding bytes is your image's pitch. When you're going through the image bytes, you want to be careful about that. You can look more about image pitch on the web.


If you're copying from an SDL_Surface to another, consider using SDL's own functions.

On Tue, Jun 9, 2015 at 11:39 PM, Nemo3773 wrote:
Quote:
I hope to copy RGBA data from "SDL_Surface->pixels", but I am not sure whether "pixels" is RGBA array, and what's "pixels" size. Thank you:D


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org