AnsweredAssumed Answered

Losing color depth

Question asked by sleziak.marcin on Feb 12, 2018
Latest reply on Feb 12, 2018 by T J

I've been working on a simple UI library for my project.

 

I'm using the stm32F7 with LTDC configured to RGB888 color space.

 

Whilst I was writing a color gradient function, I noticed that my gradients looked 'choppy'

 

Left gradient: Dithered RGB888 bitmap

Middle gradient: non-dithered RGB888 bitmap

Right gradient: custom gradient function

 

My gradient code does a simple loop:

for (uint32_t yPos = y; yPos < height; yPos++) {
    LCD::fillRectangle(x, yPos, width, 1, LCD::getGradientColor(yPos, height, fromColor, toColor, (ColorFormat) hLtdcHandler.LayerCfg[0].PixelFormat));
}

which calls the getGradientFunction:

uint32_t LCD::getGradientColor(uint32_t current, uint32_t max, uint32_t fromColor, uint32_t toColor) {
    float position = (float) current / max;
    uint8_t red = (uint8_t) (((1.0 - position) * (fromColor & 0xff0000 >> 16)) + (position * (toColor & 0xff0000 >> 16)));
    uint8_t green = (uint8_t) (((1.0 - position) * (fromColor & 0x00ff00 >> 8)) + (position * (toColor & 0x00ff00 >> 8)));
    uint8_t blue = (uint8_t) (((1.0 - position) * (fromColor & 0x0000ff)) + (position * (toColor & 0x0000ff)));

    switch (hLtdcHandler.LayerCfg[0].PixelFormat) {
        case LTDC_PIXEL_FORMAT_ARGB8888:
            return ((uint8_t) 0xFF << 24) | (red << 16) | (green << 8) | blue;
        default:
        case LTDC_PIXEL_FORMAT_RGB565:
        case LTDC_PIXEL_FORMAT_RGB888:
            return (red << 16) | (green << 8) | blue;
    }
}

Based on my calculations, I have a 600px high display and I am drawing a full-height gradient. I expect a different color value every ~2.35 lines (600 lines / 255 grey shades). However, my display shows a color change every ~9 lines.

 

Does anybody have an idea where I shall start looking for the cause?

 

I am using DMA to draw the two bitmaps, with the appropriate input color modes for both bitmaps.

For gradient I just use a simple register to memory call for each line.

Outcomes