PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

PocketHAL Surface: Who needs pitch?

Hello,

From what I gather, pitch is the width of a surface times the byte depth of one pixel (2 in PPC).

Well, since this is true for all devices, and is not likely to change anytime soon, what are the reasons for storing pitch?


- Alex
Because it is not always true. For example the Casio E-115, E-125 and the EM500 return a pitch of 512 (and not 480).

It might also not be true for non-PPC devices.

It also might not stay true for the current devices once I add support for WM2003 SE.

If you want to maximize compatibility and minimize problems in the future, use the pitch. If you want to run into problems, don't.
I see, but the width in the casios is different, hence the pitch is different. I guess my point is if pitch is always width*2 then why store it.
Also the GetPixels function returns a uint16 ptr; so if the color depth were to change to say 24bits, the surface class would no longer function properly even if we adjust pitch (not to speak of optimized 32bit blitters).
In my POV it is better to overload the Surface class for each of the color depth situations and incorporate a blitter that is optimized for each of these few cases.

ie:

class 16BitSurface : public Surface {...}
class 24BitSurface : public Surface {...}

and then Surface->draw(Point &pt;); through polymorphism will call the right blitter in each of the respective classes. And if the blitters are the same we still have the option of not overloading :)

But then aigain, I might be missing the point altogether...

- Alex
Again, the pitch of some devices *IS NOT* 2x width. You can't assume that. This is why it is stored. It is needed. To access a given pixel, use GetPixel. To access a given row, use GetPixel( 0, row ). If you want to manipulate a pixel pointer yourself, then you have to take the pitch into account.

Currently, PocketHAL only returns 16 bits (R5G6B5) surfaces. The underlying device can be grayscale, 8-bit palette, 12 bits (R4G4B4) 24 bits or even 32 bits. It doesn't matter. PocketHAL always return a 565 surface.

If this changes in a future release, then obviously GetPixel() will have to be modified to return void* instead of uint16_t*.


class 16BitSurface : public Surface {...}
class 24BitSurface : public Surface {...}


This is BAD BAD BAD. Don't do that. If you want to support multiple pixel formats, you will have to implement your own class, and do not derive it from PHAL's Surface. That's just wrong. A "24BitSurface" is certainly not a "PHAL::Surface". The two are unrelated.
Oh I see, so pitch is not width * color byte depth. It gives the offset in bytes for the pixel in the next row.
So *( (BYTE *)surface.GetPixel(0,0) + pitch ) would point to pixel (0,1).

Sorry, I'm still learning as I go along :oops: ...