[ros-dev] DecompressBitmap / Decompress4bpp / Decompress8bpp

Love Nystrom love.nystrom at gmail.com
Sun May 9 08:15:07 CEST 2010


Hi guys,

Sorry for barging in on a discussion about code that's not on my desk,
but looking at your code there is something I want to point out.

Graphics code need to be *fast*, that's a primary consideration,
so I'm taken aback when I look at your inner bit expansion loop.
This is horrible from a standpoint of performance.

>        length = (*bits++) >> shift;
>        if (length)
>        {
>            c = *bits++;
>            while (length--)
>            {
>                if (x >= width) break;
>                temp = UncompressedBits + (((height - y) * Delta) + x);
>                x++;
>                *temp = c;
>            }
>        }

You're recomputing the start of the bit-run for every pixel you emit,
when you should move that calculation out of the inner loop to get
high performance. Graphics code is not the arena where you can be lazy
and hope that the optimizer will make your inefficient code faster.
At the very least You ought to write it something like this:

>        length = (*bits++) >> shift;
>        if (length)
>        {
>            c = *bits++;
>            if (x + length > width) {
>                // RLE encoding error - Bit-run exceeds width
>                length = width - x;
>            }
>            temp = UncompressedBits + ((height - y) * Delta);
>            x += length; // precompute finishing x
>            while (length--)
>            {
>                *temp++ = c;
>            }
>        }

As a sideline note I'd like to mention that it's standard practice
in graphics libraries to use one unified bitmap format internally
to make internal processing like alpha-blend or text rendering or
whatever straight forward. The 32bit DIB format is quite suitable,
even if it uses the most memory - Graphics never was cheap on memory.


Just my penny to the pot
Best Regards
// Love






More information about the Ros-dev mailing list