From: Shawn Jefferson (sjefferson_at_sd62.bc.ca)
Date: 2003-09-03 21:57:12
I have a routine that plots pixels on a memory bitmap and am making an attempt to optimize it. I'm hoping some of you C wizards can help.
The routine is passed a structure called bmp, which contains a pointer to the memory area and the graphics mode. The function, and the memory bitmap can be arbitrary lengths of y and x. Anyway, here is my attempt at optimizing it a little using some lookup tables:
const unsigned char plot4cmask[4] = {0xC0,0x30,0x0C,0x03};
const unsigned char plot4cshift[4] = {6,4,2,0};
/* plot_4colmode_nc
*
* Plots a point on the bitmap using the passed in color register. This
* function does no clipping, so you have to watch the parameters you pass
* in.
*/
void __fastcall__ plot_4colmode_nc(BITMAP *bmp, int x, int y, unsigned char creg)
{
unsigned char byte, bit, mask;
unsigned char data;
unsigned int index;
byte = (x / 4);
bit = (x % 4);
index = ((BYTES_PER_LINE(bmp) * y) + byte);
data = bmp->dat[index];
//mask = 3 << (6 - (bit * 2)); // clear the pixel first
data &= ~plot4cmask[bit];
if (creg != BAKCOL(bmp->mode)) { // not background color?
creg++; // creg 0->01, 1->10, 2->11
//mask = creg << (6 - (bit * 2));
mask = creg << plot4cshift[bit];
data |= mask;
}
bmp->dat[index] = data;
return;
}
¯
Shawn Jefferson
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2003-09-03 21:58:48 CEST