[SDL] single pixel drawing

Loren Osborn linux_dr at yahoo.com
Wed Jul 17 13:12:01 PDT 2002

You can *ONLY* use a shift instead of a multiply *IF*
pitch is a power of 2... You could them determin the
conversion of pitch to a shift before drawing a large
batch of pixels... the problem is them you would need
to *BRANCH* depending on whether to shift or
multiply... Unfortunately a conditional branch is more
expensive than the original multiply!

What you can do instead is find your initial pixel,
then move incrementally relative to it... For example,
to draw a line, you are generally moving from one
pixel in one of 8 directions to an adjecent pixel. to
move up a row, subtract pitch. to move over (left or
right) ad or subtract sizeof(pixel), and to move down
add pitch... so now you're adding/subtracting instead
or multiplying....Understand?

--- Atrix Wolfe <Atrix2 at cox.net> wrote:
> ok so shifting seems optimal to multiplication.  How
> would you take something like y*pitch+x and figure
> out what shifting to do for a pitch that is
> determined at run-time?

Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes

More information about the SDL mailing list