#172314 - Kensai - Sat Jan 30, 2010 11:05 am
I'm using mode 4 and all my images consist of only 16 colors (= 4 bits). In order to save EWRAM, I've written a program which "compresses" the image data: Even pixels are stored in the upper 4 bits and odd pixels are stored in the lower 4 bits of a byte.
But there is a tradeoff: If I want to copy the pixels from EWRAM to VRAM, the image has to be "decompressed" using bit swifting operations. Another option would be to store all my images in ROM but without the compression. Which variant is the faster one?
Code: |
bits 7 6 5 4 3 2 1 0 0 1 0 1 0 0 0 1 => left pixel color palett address = 0x5, \ / \ / right pixel color palett address = 0x1 left right pixel pixel |
But there is a tradeoff: If I want to copy the pixels from EWRAM to VRAM, the image has to be "decompressed" using bit swifting operations. Another option would be to store all my images in ROM but without the compression. Which variant is the faster one?
Code: |
void drawImage (u8 x, u8 y, const u8* image, u16 width, u16 height, Bool hFlip, u8 transparentColor) { width /= 2; x /= 2; u8 w, h; u8 leftColor, rightColor; if (hFlip == FALSE) { if (transparentColor == NO_TRANSPARENCY) { for (h=0; h<height; h++) for (w=0; w<width; w++) { leftColor = image[w+h*width] & 0x0F; rightColor = image[w+h*width] / 0x10; videoBuffer[(x+w)+120*(y+h)] = rightColor | 0x100*leftColor; } } else { for (h=0; h<height; h++) for (w=0; w<width; w++) { leftColor = image[w+h*width] & 0x0F; if (leftColor == transparentColor) leftColor = (0xF00 & videoBuffer[(x+w)+120*(y+h)]) >> 8; rightColor = image[w+h*width] / 0x10; if (rightColor == transparentColor) rightColor = videoBuffer[(x+w)+120*(y+h)] & 0x000F; videoBuffer[(x+w)+120*(y+h)] = rightColor | 0x100*leftColor; } } } else { if (transparentColor == NO_TRANSPARENCY) { for (h=0; h<height; h++) for (w=0; w<width; w++) { leftColor = image[w+h*width] / 0x10; rightColor = image[w+h*width] & 0x0F; videoBuffer[(x+(width-1-w))+120*(y+h)] = rightColor | 0x100*leftColor; } } else { for (h=0; h<height; h++) for (w=0; w<width; w++) { leftColor = image[w+h*width] / 0x10; if (leftColor == transparentColor) leftColor = (0xF00 & videoBuffer[(x+(width-1-w))+120*(y+h)]) >> 8; rightColor = image[w+h*width] & 0x0F; if (rightColor == transparentColor) rightColor = videoBuffer[(x+(width-1-w))+120*(y+h)] & 0x000F; videoBuffer[(x+(width-1-w))+120*(y+h)] = rightColor | 0x100*leftColor; } } } } |