sumotoy / RA8875

A library for RAiO RA8875 display driver for Teensy3.x or LC/Arduino's/Energia/Spark
GNU General Public License v3.0
79 stars 55 forks source link

Conversion from 16bpp to 8bpp for drawPixel() and drawPixels() incorrect. #149

Open davewill opened 4 years ago

davewill commented 4 years ago

I noticed that I was getting odd colors that didn't match other elements on my screen drawn with the same colors. Pixels drawn with fillRect() had the correct colors, but pixels drawn with drawPixels() didn't. I tracked it down to this function in RA8875.h:

//convert a 16bit color(565) into 8bit color(332) as requested by RA8875 datasheet
inline __attribute__((always_inline))
    uint8_t _color16To8bpp(uint16_t color) {
        return ((color & 0x3800) >> 6 | (color & 0x00E0) >> 3 | (color & 0x0003));
    }

It's taking the low-order bits of the 565 color instead of the high-order bits. Correcting it to this:

//convert a 16bit color(565) into 8bit color(332) as requested by RA8875 datasheet
inline __attribute__((always_inline))
    uint8_t _color16To8bpp(uint16_t color) {
        return ((color & 0xE000) >> 8 | (color & 0x0700) >> 6 | (color & 0x0018) >> 3);
    }

Fixed my problem nicely.

What I also need to do is create a function, drawPixels8(), that takes the pixel array already in 8-bit color. It seems a bit silly to build a line of 16-bit pixels (the source data is 4-bit IRGB) only to have drawPixels() convert them again.

davewill commented 4 years ago

I found that this has been fixed over here: https://github.com/mjs513/RA8875/tree/RA8875_t4

It looks like that active development has moved there.