Surface->Pitch?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
ssj4goku128
Insane DCEmu
Insane DCEmu
Posts: 290
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Surface->Pitch?

Post by ssj4goku128 »

Is the pitch the number of bytes per pixel? I am confused as to what it really is.
"So I gotta be carefull, can't let tha evil of tha money trap me
so when ya see me #@#$%
ya better holla at me "

Tupac Shakur[1971-1996]
Makaveli[1996-????]
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY
Has thanked: 0
Been thanked: 0

Post by OneThirty8 »

The pitch, if I remember correctly, is the number of bytes per line. So, if your surface is 640x480 then your pitch is 640*2=1280. If it's 320x240, then the pitch is 320*2=640. (that assumes you're using a 16-bit surcace.)
Rand Linden
bleemcast! Creator
bleemcast! Creator
Posts: 882
Joined: Wed Oct 17, 2001 7:44 pm
Location: Los Angeles, CA
Has thanked: 0
Been thanked: 0
Contact:

Post by Rand Linden »

"Pitch" is the number of bytes between consecutive scanlines.

In almost all cases, it's simply (Width in pixels * #Bytes per Pixel) ... just as 138 wrote above.

There's a few reasons why it would be different from that -- here's two examples:

Example 1:
--------------
If a particular video chip only fetches memory in blocks of 128 bytes, and you want it to display 24bpp at 320 pixels wide.

24bpp (using 3 bytes per pixel) at 320 pixels wide works out to 960 bytes for the data.

... but the video hardware can't fetch memory if it's not aligned to 128-byte boundary, so the next scanline will be "bumped" to start at byte 1024.

What happened to the 64 bytes off the end of the scanline? They're unused and simply skipped over.

Example 2:
-------------
Interleaved scanlines for NTSC and PAL composite display fields.

The pitch is 2x what you expect (assuming no other hardware oddness), because every other scanline is actually from the opposite field.

Rand.
ssj4goku128
Insane DCEmu
Insane DCEmu
Posts: 290
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Post by ssj4goku128 »

Thank you for clearing that up Rand. :) It's always good to hear from the elite of programmers. Also, thank you OneThirty8.
"So I gotta be carefull, can't let tha evil of tha money trap me
so when ya see me #@#$%
ya better holla at me "

Tupac Shakur[1971-1996]
Makaveli[1996-????]
Post Reply