Listing 1 Algorithm for a bitmap that has four bits-per-pixel
/*

* This function displays a 4-bit bitmap described by the

* BitmapData structure.

* It has one restriction.

* 1. The bitmap must be an even number of pixels wide.

*

* left, top is the location of the upper left dot

* of the bitmap on the display.

*/

void imageRender(const BitmapData * imagePtr, int left, int top)

{

/*

* x and y will track the location we are

* drawing within the bitmap.

*/

unsigned int x,y;

/*

* index tracks our location within the array of bytes

* that represent the image.

*/

long index;

/*

* The value of pixel is the color of the dot

*/

unsigned char pixel;

/*

* Make sure that the bitmap does not go outside of the display.

*/

assert(top + imagePtr->height <= DISPLAY_FULL_HEIGHT);

assert(left + imagePtr->width <= DISPLAY_FULL_WIDTH);

index = 0;

for (y = 0; y < imagePtr->height; y++)

{

/*

* x will step forward 2 at a time, since each

* byte contains 2 pixels

*/

for (x = 0; x < imagePtr->width; x += 2)

{

/*

* First extract the color of the next pixel

* from the high order nibble

*/

pixel = imagePtr->raw[index] >> 4;

/*

* Now place a dot, with the color pixel in

* the next location on the display

*/

drawDot(x + left, y + top, pixel);

/*

* Next extract the color from the second pixel

* from the low order nibble

*/

pixel = imagePtr->raw[index] & (0x0F);

drawDot(x+1 + left, y + top, pixel);

/*

index increases once for every two dots drawn,

since we have two dots-per-pixel.

*/

index++;

}

}

}

Back