Another simple question

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:

Rmask: 0xFF0000 Gmask: 0x00FF00 Bmask: 0x0000FF Amask: 0

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 :frowning: So I’m just trying to
clear up this bit to make sure I’ve interpreted the library code
properly…

Cheers,
Simon.

but what is pitch ? And are the masks specified as longs ? (so for
…RGBRGBRGB… data, would they be:

Rmask: 0xFF0000 Gmask: 0x00FF00 Bmask: 0x0000FF Amask: 0

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.

but what is pitch ?

I added this to the FAQ:
http://www.devolution.com/~slouken/SDL/faq/FAQ-General.html#GENERAL_VIDEO1

And are the masks specified as longs ? (so for
…RGBRGBRGB… data, would they be:

Rmask: 0xFF0000 Gmask: 0x00FF00 Bmask: 0x0000FF Amask: 0

That’s correct.

Is ‘pitch’ W or W*3 and is depth in bits/pixel or bytes ?

W*3 in your case.

See ya!
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

depet at gmx.de wrote:

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 bytes

Ooops!

And there was me thinking that

surface->widthsurface->heightsurface->BytesPerPixel=whole bytes

and that

surface->pitch = surface->width*surface->BytesPerPixel

Now I’m confused!

-Lea.

but what is pitch ? And are the masks specified as longs ? (so for
…RGBRGBRGB… data, would they be:

Rmask: 0xFF0000 Gmask: 0x00FF00 Bmask: 0x0000FF Amask: 0

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.

Nichola

vining at pacificcoast.net wrote:

but what is pitch ? And are the masks specified as longs ? (so for
…RGBRGBRGB… data, would they be:

Rmask: 0xFF0000 Gmask: 0x00FF00 Bmask: 0x0000FF Amask: 0

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 :slight_smile:

ATB,
Simon

vining at pacificcoast.net wrote:

but what is pitch ? And are the masks specified as longs ? (so for
…RGBRGBRGB… data, would they be:

Rmask: 0xFF0000 Gmask: 0x00FF00 Bmask: 0x0000FF Amask: 0

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 :slight_smile:

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…

Ooops!

And there was me thinking that

surface->widthsurface->heightsurface->BytesPerPixel=whole bytes

and that

surface->pitch = surface->width*surface->BytesPerPixel

Now I’m confused!

You are right, I was wrong, please excuse I was in a complete wierdo stateOn 18-Jan-00 Lea Anthony wrote:

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.

Adam Meyerowitz

In article <38849DCF.8D4D67C5 at prismtechnologies.com>,
lea.anthony at prismtechnologies.com says…>

depet at gmx.de wrote:

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 bytes

Ooops!

And there was me thinking that

surface->widthsurface->heightsurface->BytesPerPixel=whole bytes

and that

surface->pitch = surface->width*surface->BytesPerPixel

Now I’m confused!

-Lea.