optimizing pixel conversion

This commit is contained in:
Attila Body 2020-12-02 09:22:10 +01:00
parent 3f48d95efd
commit a7a7443d0a

View file

@ -30,14 +30,18 @@ volatile uint32_t g_tick = 0;
void convert(uint8_t *src, uint8_t *dst, uint16_t src_size) void convert(uint8_t *src, uint8_t *dst, uint16_t src_size)
{ {
static uint8_t const bits[4] = { 0b10001000, 0b10001110, 0b11101000, 0b11101110 }; static uint16_t const bits[16] = { // due to LE-ness the bit order is 1 0 3 2
0b1000100010001000, 0b1000111010001000, 0b1110100010001000, 0b1110111010001000,
0b1000100010001110, 0b1000111010001110, 0b1110100010001110, 0b1110111010001110,
0b1000100011101000, 0b1000111011101000, 0b1110100011101000, 0b1110111011101000,
0b1000100011101110, 0b1000111011101110, 0b1110100011101110, 0b1110111011101110
};
uint16_t *dstptr = (uint16_t*)dst;
while(src_size--) { while(src_size--) {
uint8_t byte=*src++; uint8_t tmp =*src++;
for(int8_t shift = 6; shift >= 0; shift -= 2) { *dstptr++ = bits[tmp >> 4];
uint8_t mask = 3 << shift; *dstptr++ = bits[tmp & 0x0f];
*dst++ = bits[ (byte & mask) >> shift ];
}
} }
} }