[SDL] surface pitch

Paul Duffy odubtaig at yahoo.co.uk
Sat Jun 6 10:52:27 PDT 2009


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 (y*pitch)+(x*bytesPerPixel).

So if I'm thinking properly I'd probably put ((y*pitch)+x)*BytesPerPixel and ((y*pitch)+(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:

> >
> > (y*pitch*BytesPerPixel)+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 y*pitch+x*bytesPerPixel
> 
> > Or, if you wanted to access the rightmost pixel on a
> line it could be
> > (someone correct me if I'm wrong):
> >
> > (y*pitch*BytesPerPixel)+(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
> 


      



More information about the SDL mailing list