Hello to everyone on the mailing list
Iām happy itās not dead 
My app creates an 8-bit surface. When surface->pitch is different than
surface->w in bytes?
I had that problem before - I was creating a Meritous port for Sony PSP, for
which SDL is fully ported, even with multitasking. The game had a very
strange way to show strings on a surface: it creates a pointer to
screen->pixels (or however itās called) and moves it to drawing position,
but instead of moving screen->pitch for each line, it moved screen->w bytes
down. When app was in resolution 640x480, this method was working, but when
I changed to 480x272 (PSP native resolution) the strings were all shattered.
I spent 2 days finding out what was wrong.
So, my question is: When surface->pitch is different than
surface->w*surface->format->BytesPerPixel (itās multiplying here)? And when
it is different, what data are stored between lines?
Donāt consider this an urgent question, why? because itās not 
You can find Meritous PSP port almost stable on my website:
http://elementgame.boo.pl/
Marach
Le Sat, 6 Jun 2009 10:44:30 +0200
Hubert Maraszek a ?crit:
My app creates an 8-bit surface. When surface->pitch is different than
surface->w in bytes?
It is different if SDL can not create a video mode for the width you
asked for (for example if the underlying hardware does nto support it).
I had that problem before - I was creating a Meritous port for Sony PSP, for
which SDL is fully ported, even with multitasking. The game had a very
strange way to show strings on a surface: it creates a pointer to
screen->pixels (or however itās called) and moves it to drawing position,
but instead of moving screen->pitch for each line, it moved screen->w bytes
down. When app was in resolution 640x480, this method was working, but when
I changed to 480x272 (PSP native resolution) the strings were all shattered.
I spent 2 days finding out what was wrong.
For example, if the target only provides a 640x480 resolution and you
want 480x272, SDL will give you 640 for pitch (for 8 bits/pixel), and
your 480x272 SDL_Surface screen in reality is only a part of the real
640x480 screen.
So, my question is: When surface->pitch is different than
surface->w*surface->format->BytesPerPixel (itās multiplying here)? And when
it is different, what data are stored between lines?
When drawing, you should always use surface->pitch *
surface->format->BytesPerPixel.ā
Patrice Mandin
WWW: http://pmandin.atari.org/
Programmeur Linux, Atari
Sp?cialit?: D?veloppement, jeux
For efficiency reasons, each line in a surface is memory-aligned.
The extra data is unused.
On a PSP:
32bit ā 2048
16bit ā 1024On Sat, Jun 06, 2009 at 10:44:30AM +0200, Hubert Maraszek wrote:
Hello to everyone on the mailing list
Iām happy itās not dead 
My app creates an 8-bit surface. When surface->pitch is different than
surface->w in bytes?
I had that problem before - I was creating a Meritous port for Sony PSP, for
which SDL is fully ported, even with multitasking. The game had a very
strange way to show strings on a surface: it creates a pointer to
screen->pixels (or however itās called) and moves it to drawing position,
but instead of moving screen->pitch for each line, it moved screen->w bytes
down. When app was in resolution 640x480, this method was working, but when
I changed to 480x272 (PSP native resolution) the strings were all shattered.
I spent 2 days finding out what was wrong.
So, my question is: When surface->pitch is different than
surface->w*surface->format->BytesPerPixel (itās multiplying here)? And when
it is different, what data are stored between lines?
Donāt consider this an urgent question, why? because itās not 
You can find Meritous PSP port almost stable on my website:
http://elementgame.boo.pl/
ā
Sylvain
But 640x480 is NOT a native resolution! 480x272 is and itās the only surface
hardware-supported on PSP, other resolutions are just scaled down/up to
480x272.
Maybe that difference is because of SDL trying to make a ābytes per
scanlineā amount a āroundā (in binary, of course) number? (in example: 1024,
640, 16, 65536 etc.)
2009/6/6 Patrice Mandin <mandin.patrice at orange.fr>> Le Sat, 6 Jun 2009 10:44:30 +0200
Hubert Maraszek <@Hubert_Maraszek> a ?crit:
My app creates an 8-bit surface. When surface->pitch is different than
surface->w in bytes?
It is different if SDL can not create a video mode for the width you
asked for (for example if the underlying hardware does nto support it).
I had that problem before - I was creating a Meritous port for Sony PSP,
for
which SDL is fully ported, even with multitasking. The game had a very
strange way to show strings on a surface: it creates a pointer to
screen->pixels (or however itās called) and moves it to drawing position,
but instead of moving screen->pitch for each line, it moved screen->w
bytes
down. When app was in resolution 640x480, this method was working, but
when
I changed to 480x272 (PSP native resolution) the strings were all
shattered.
I spent 2 days finding out what was wrong.
For example, if the target only provides a 640x480 resolution and you
want 480x272, SDL will give you 640 for pitch (for 8 bits/pixel), and
your 480x272 SDL_Surface screen in reality is only a part of the real
640x480 screen.
So, my question is: When surface->pitch is different than
surface->w*surface->format->BytesPerPixel (itās multiplying here)? And
when
it is different, what data are stored between lines?
When drawing, you should always use surface->pitch *
surface->format->BytesPerPixel.
ā
Patrice Mandin
WWW: http://pmandin.atari.org/
Programmeur Linux, Atari
Sp?cialit?: D?veloppement, jeux
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Maybe that difference is because of SDL trying to make a
ābytes per scanlineā amount a āroundā
(in binary, of course) number? (in example: 1024, 640, 16,
65536 etc.)
Youāre almost right. I canāt say if itās identical for PSP (actually, looking at the numbers where 272/4=68, almost certainly not) but on PC the graphics hardware will only accept data that is 4 byte aligned, that is 32 Bit, so the data for every line must be a multiple of 4 bytes in size regardless of whether all that data is actually used. This can make memory transfers 4x faster than if individual bytes were accessed because it costs the same on PC architechture to move one byte as it does to move four as one 32 bit integer. Other colour depths will not automatically line up to a multiple of 4 and so need to be padded out on each line until they do.
What it comes down to is, sometimes to get graphics data aligned and displaying properly you have to pad each line out a bit and while the original width of an image needs to be recorded the padded width is also required to compensate for this padding when you want to access the correct pixel. So, while this does speed up things like blitting whole images you have to access individual pixels as:
(ypitchBytesPerPixel)+x
Or, if you wanted to access the rightmost pixel on a line it could be (someone correct me if Iām wrong):
(ypitchBytesPerPixel)+(width-BytesPerPixel)
hope this helps, Paulā On Sat, 6/6/09, Hubert Maraszek wrote:
Maybe that difference is because of SDL trying to make a
ābytes per scanlineā amount a āroundā
(in binary, of course) number? (in example: 1024, 640, 16,
65536 etc.)
Youāre almost right. I canāt say if itās identical for PSP (actually,
looking at the numbers where 272/4=68, almost certainly not) but on PC the
graphics hardware will only accept data that is 4 byte aligned, that is 32
Bit, so the data for every line must be a multiple of 4 bytes in size
regardless of whether all that data is actually used. This can make memory
transfers 4x faster than if individual bytes were accessed because it costs
the same on PC architechture to move one byte as it does to move four as
one 32 bit integer. Other colour depths will not automatically line up to a
multiple of 4 and so need to be padded out on each line until they do.
In fact some platforms need the lines to be 64 bit aligned and for cache and
SIMD reasons it is better to set the row alignment as 128 bits.
What it comes down to is, sometimes to get graphics data aligned and
displaying properly you have to pad each line out a bit and while the
original width of an image needs to be recorded the padded width is also
required to compensate for this padding when you want to access the correct
pixel. So, while this does speed up things like blitting whole images you
have to access individual pixels as:
(ypitchBytesPerPixel)+x
This is wrong.
The start of row y is y*pitch bytes from the begining of the pixel data as
pitch is equal to the amount of bytes between two rows of pixel data.
The correct one is ypitch+xbytesPerPixel
Or, if you wanted to access the rightmost pixel on a line it could be
(someone correct me if Iām wrong):
(ypitchBytesPerPixel)+(width-BytesPerPixel)
This would be
y*pitch+(w-1)*bytesPerPixelOn Saturday 06 June 2009 14:09:14 Paul Duffy wrote:
ā On Sat, 6/6/09, Hubert Maraszek wrote:
Youāre right that Iām wrong. Thatās quite embarrasing. Iāve done this the right way before as well (not that Iāve had the time to work on that since last Nov). Youāre forgetting operator precedence though, youāre going to get (ypitch)+(xbytesPerPixel).
So if Iām thinking properly Iād probably put ((y*pitch)+x)BytesPerPixel and ((ypitch)+(width-1))*BytesPerPixel.
Yes, I use a lot of brackets. Iāve seen more than one buggy compiler āoptimiseā the operator precedence putting + before * and so on. Call me Mr. Paranoid if you like :o)
With our powers combined we could be an unstoppable force, we could even be⦠competent! Oh dear, Iāll go back to bed shall I?ā On Sat, 6/6/09, Sami N??t?nen <sn.ml at keijukammari.fi> wrote:
(ypitchBytesPerPixel)+x
This is wrong.
The start of row y is y*pitch bytes from the begining of
the pixel data as
pitch is equal to the amount of bytes between two rows of
pixel data.
The correct one is ypitch+xbytesPerPixel
Or, if you wanted to access the rightmost pixel on a
line it could be
(someone correct me if Iām wrong):
(ypitchBytesPerPixel)+(width-BytesPerPixel)
This would be
y*pitch+(w-1)*bytesPerPixel
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
No, the exprsesion Sami gave is correct.
Donāt forget: pitch is in bytes, not pixels.
John BOn Sat, 2009-06-06 at 17:52 +0000, Paul Duffy wrote:
Youāre right that Iām wrong. Thatās quite embarrasing. Iāve done this the right way before as well (not that Iāve had the time to work on that since last Nov). Youāre forgetting operator precedence though, youāre going to get (ypitch)+(xbytesPerPixel).
So if Iām thinking properly Iād probably put ((y*pitch)+x)BytesPerPixel and ((ypitch)+(width-1))*BytesPerPixel.
Youāre right that Iām wrong. Thatās quite embarrasing.
Iāve done this the right way before as well (not that Iāve
had the time to work on that since last Nov). Youāre
forgetting operator precedence though, youāre going to get
(ypitch)+(xbytesPerPixel).
So if Iām thinking properly Iād probably put
((y*pitch)+x)BytesPerPixel and
((ypitch)+(width-1))*BytesPerPixel.
No, the exprsesion Sami gave is correct.
Donāt forget: pitch is in bytes, not pixels.
Ah. I had quite forgotten that.
Somethingās clear. It has been way too long since I did any of this and my heads too much in pattern matching. Apologies for any confusion.ā On Sat, 6/6/09, John Bartholomew wrote:
From: John Bartholomew
Subject: Re: [SDL] surface pitch
To: āA list for developers using the SDL library. (includes SDL-announce)ā
Date: Saturday, June 6, 2009, 6:03 PM
On Sat, 2009-06-06 at 17:52 +0000, Paul Duffy wrote: