Assuming I already have an unsigned char * array for an RGB image of
width W and height H (so there are 3WH elements in the array), how
do I go about assigning a surface pointing to that array ?
I’m assuming I use:
extern SDL_Surface *SDL_CreateRGBSurfaceFrom( void *pixels,
int width, int height, int depth, int pitch,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
but what is pitch ? And are the masks specified as longs ? (so for
…RGBRGBRGB… data, would they be:
Is ‘pitch’ W or W*3 and is depth in bits/pixel or bytes ?
The examples I’ve seen tend to load an image using an SDL function,
so it’s all set up for them. I’ve tried to copy the library function
semantics, but my program still crashes So I’m just trying to
clear up this bit to make sure I’ve interpreted the library code
properly…
Is ‘pitch’ W or W*3 and is depth in bits/pixel or bytes ?
this problem screwed my newbie for days, trial and error gave me:
pitch seems to be the real width in pixels, width is still a mystery to me,
height seems to be the number of rows (pitch) so for 24bit data :
surface->pitchsurface->heightsurface->BytesPerPixel=whole bytesOn 18-Jan-00 Simon Gornall wrote:
Assuming I already have an unsigned char * array for an RGB image of
width W and height H (so there are 3WH elements in the array), how
do I go about assigning a surface pointing to that array ?
I’m assuming I use:
extern SDL_Surface *SDL_CreateRGBSurfaceFrom( void *pixels,
int width, int height, int depth, int pitch,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
A surface is assumed to be a linear block of memory allocated large enough
for the desired width and height. You pass a pointer to this memory to the
SDL_CreateRGBSurfaceFrom() function to create an SDL surface from preallocated
memory, or you can use SDL_CreateRGBSurface() to have SDL allocate the memory
for you.
this problem screwed my newbie for days, trial and error gave me:
pitch seems to be the real width in pixels, width is still a mystery to me,
height seems to be the number of rows (pitch) so for 24bit data :
Is ‘pitch’ W or W*3 and is depth in bits/pixel or bytes ?
Pitch is the “physical length of the width of the screen”, or the amount of
memory it takes. The 24-bit “truecolor” mode you’re describing probably
actually has a pitch of 32, because really what it looks like is:
Rmask: 0x00FF0000 Gmask:0x0000FF00 …
So pitch is really (usually) w*4. I just rip the code out of the example SDL
programs and hack it to the right settings, so I don’t remember exactly what I
use.
Is ‘pitch’ W or W*3 and is depth in bits/pixel or bytes ?
Pitch is the “physical length of the width of the screen”, or the amount of
memory it takes. The 24-bit “truecolor” mode you’re describing probably
actually has a pitch of 32, because really what it looks like is:
Rmask: 0x00FF0000 Gmask:0x0000FF00 …
So pitch is really (usually) w*4. I just rip the code out of the example SDL
programs and hack it to the right settings, so I don’t remember exactly what I
use.
No, I’m sure that my data is RGBRGB… etc so I guess it’s 24-bit, but
thanks for
the info
Is ‘pitch’ W or W*3 and is depth in bits/pixel or bytes ?
Pitch is the “physical length of the width of the screen”, or the amount
of
memory it takes. The 24-bit “truecolor” mode you’re describing probably
actually has a pitch of 32, because really what it looks like is:
Rmask: 0x00FF0000 Gmask:0x0000FF00 …
So pitch is really (usually) w*4. I just rip the code out of the example
SDL
programs and hack it to the right settings, so I don’t remember exactly
what I
use.
No, I’m sure that my data is RGBRGB… etc so I guess it’s 24-bit, but
thanks for
the info
I doubt it, but guess and test until you’re right. Very often with video
cards, 24 bit is defined as “32 bit, but we’re not going to put in any extra
stuff in that 8 bits”. Oh well, your call.
ATB,
Simon
Nicholas
----- Original Message -----
From: simon@unique-id.com (Simon Gornall)
To: sdl at lokigames.com
Date: Tuesday, January 18, 2000 6:19 PM
Subject: Re: [SDL] Another simple question…
Actually the width and the pitch aren’t always the same.
For example usually in 24bpp mode the width of a scanline
(in bytes) is width*3. So for a 640 pixel scanline the
width in bytes is 1920. However for various reasons
video card manufacturers pad scanlines for alignment
and other reasons. So the pitch might actually be larger
then the width. For 640 @ 24bpp the pitch is often
2560 (640 *4 bytes per pixel). The pitch is the amount
of bytes that must be added to a pointer to get to the
same pixel position on the next scanline…This is not
always the width.
this problem screwed my newbie for days, trial and error gave me:
pitch seems to be the real width in pixels, width is still a mystery to me,
height seems to be the number of rows (pitch) so for 24bit data :