Advertisement

I have some questions .

Started by February 24, 2003 07:10 AM
3 comments, last by pluto_knight 21 years, 8 months ago
1)I still don''t understand the differences between "pitch" and "widith". 2)Would you like to give me some info about YUV? 3)What is timer and how it work? I''ve known a little about it .I am not able to work until I comprehend it profoundly. If you like ,please give some examples with explains.Thank you in advance.
Pitch and width are related, but very different. When you create a DirectDraw surface, for example, you specify a width (for instance, 640). However, let''s suppose you try to write directly to that surface. You can''t simply write to address [SurfacePointer] + ((Width * Y) + X). This should only work for one line, then you''ll end up with problems.

Since an offscreen buffer could be reserved by DirectDraw, your surface could be, in actuality, 800x480 instead of 640x480. The width, which you asked for, is 640. But the pitch, what the program really reserved, is 800. You don''t have to worry about this buffer, but you still have to keep it into consideration.

So, briefly...
Width: What you asked for and what you''d see.
Pitch: What was really reserved and what you should use when plotting pixels directly to the surface.

Not sure I explained this too well, but I hope it helps.
Advertisement
What library are you using Pluto_Night?

My understanding with SDL is that width is the number of horizontal pixels across, while pitch is the number of bytes needed for each line (someone please correct me if I’m wrong).

For example if you have a 8-bit surface (1 byte per pixel) then the width and pitch of will be the same, if you have a 32-bit surface (4 bytes per pixel) then the pitch will be 4 times as big as your width.

Cheers.
Direct X


If I have a 32-bit surface of 100 size ,the width is 800 and the pitch is 3200.Is it right?
Okay, if you are using C/C++ read this:

Scan line is a horizontal line across a monitor.

Pitch is the distance in bytes to the next scan line.
Width is the number of pixels displayed on each scan line.

Calculating a Pixel offset

// cannot use
buffer[(y * pitch) + x] = pixel_color;

You will have to convert the pitch because it is in bytes and not in pixels.

// have to use something like this
converted_pitch = pitch / bytes_per_pixel;
buffer[(y * converted_pitch) + x] = pixel_color;

**** Special Case ****
Now this will only work if pitch is divisible by bytes per pixel. Yes 24 bit color uses 3 bytes per pixel and most graphics cards use scanlines divisible by 4, 8 and so on.

You could limit yourself to using display modes that use 8 bit, 15/16 bit, and 32 bit color and the above formula should work just fine. Otherwise, you will have to use a little more complicated formula that would involve pointer arithmetc and casting.

unsigned char far *buffer; // pointer will increment by bytes

buffer = (unsigned char far *)Surface_pointer; // assign surface base address
buffer += (y * pitch); // offset to correct scanline first
(struct RGB24 *)buffer[x]=pixel_color; // Cast to correct type


I hope this makes sense??

[edit] Sorry forgot to assign the surface pointer to the buffer pointer

[edited by - CodeJunkie on February 25, 2003 4:47:21 PM]

This topic is closed to new replies.

Advertisement