*bump* I recently added the ability for SourceCoder to generate 8-bit, 2-bit, and 1-bit data from images. The following two routines work with the 2-bit versions. Two-bit images are particularly good for two-color or three-color images that also have a mask color.
Sample usages:
Code: unsigned short int palette[4] = {COLOR_BLACK, COLOR_BLUEVIOLET, COLOR_RED, COLOR_WHITE};
CopySpriteMasked2bit(mysprite, 5, 70, 32, 32, palette);
CopySprite2bit(mysprite, 5, 70, 32, 32, palette);
For the Masked version, the COLOR_RED (aka, color #2 of 0,1,2,3) is the transparent color.
Code: void CopySpriteMasked2bit(const unsigned char* data, int x, int y, int width, int height, short unsigned int* palette) {
short unsigned int* VRAM = (short unsigned int*)0xA8000000;
VRAM += (LCD_WIDTH_PX*y + x);
int offset = 0;
unsigned char buf;
for(int j=y; j<y+height; j++) {
int availbits = 0;
for(int i=x; i<x+width; i++) {
if (!availbits) {
buf = data[offset++];
availbits = 8;
}
char this = ((buf&0xC0)>>6);
if (this != 0x02)
*VRAM = palette[(int)this];
VRAM++;
buf<<=2;
availbits-=2;
}
VRAM += (LCD_WIDTH_PX-width);
}
}
Code: void CopySprite2bit(const unsigned char* data, int x, int y, int width, int height, short unsigned int* palette) {
short unsigned int* VRAM = (short unsigned int*)0xA8000000;
VRAM += (LCD_WIDTH_PX*y + x);
int offset = 0;
unsigned char buf;
for(int j=y; j<y+height; j++) {
int availbits = 0;
for(int i=x; i<x+width; i++) {
if (!availbits) {
buf = data[offset++];
availbits = 8;
}
char this = ((buf&0xC0)>>6);
*VRAM = palette[(int)this];
VRAM++;
buf<<=2;
availbits-=2;
}
VRAM += (LCD_WIDTH_PX-width);
}
}