Merge pull request #1218 from paulpv/fix-rgb565

Fix RGB 565 to 888
This commit is contained in:
Gabor Kiss-Vamosi
2019-10-21 06:30:49 +02:00
committed by GitHub

View File

@@ -303,21 +303,44 @@ static inline uint32_t lv_color_to32(lv_color_t color)
ret.ch.alpha = 0xFF;
return ret.full;
#elif LV_COLOR_DEPTH == 16
/**
* The floating point math for conversion is:
* valueto = valuefrom * ( (2^bitsto - 1) / (float)(2^bitsfrom - 1) )
* The faster integer math for conversion is:
* valueto = ( valuefrom * multiplier + adder ) >> divisor
* multiplier = FLOOR( ( (2^bitsto - 1) << divisor ) / (float)(2^bitsfrom - 1) )
*
* Find the first divisor where ( adder >> divisor ) <= 0
*
* 5-bit to 8-bit: ( 31 * multiplier + adder ) >> divisor = 255
* divisor multiplier adder min (0) max (31)
* 0 8 7 7 255
* 1 16 14 7 255
* 2 32 28 7 255
* 3 65 25 3 255
* 4 131 19 1 255
* 5 263 7 0 255
*
* 6-bit to 8-bit: 255 = ( 63 * multiplier + adder ) >> divisor
* divisor multiplier adder min (0) max (63)
* 0 4 3 3 255
* 1 8 6 3 255
* 2 16 12 3 255
* 3 32 24 3 255
* 4 64 48 3 255
* 5 129 33 1 255
* 6 259 3 0 255
*/
lv_color32_t ret;
ret.ch.red = ( color.ch.red * 263 + 7 ) >> 5;
#if LV_COLOR_16_SWAP == 0
lv_color32_t ret;
ret.ch.red = color.ch.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
ret.ch.green = color.ch.green * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/
ret.ch.blue = color.ch.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
ret.ch.alpha = 0xFF;
return ret.full;
ret.ch.green = ( color.ch.green * 259 + 3 ) >> 6;
#else
lv_color32_t ret;
ret.ch.red = color.ch.red * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
ret.ch.green = ((color.ch.green_h << 3) + color.ch.green_l) * 4; /*(2^8 - 1)/(2^6 - 1) = 255/63 = 4*/
ret.ch.blue = color.ch.blue * 8; /*(2^8 - 1)/(2^5 - 1) = 255/31 = 8*/
ret.ch.green = (((color.ch.green_h << 3) + color.ch.green_l) * 259 + 3 ) >> 6;
#endif
ret.ch.blue = ( color.ch.blue * 263 + 7 ) >> 5;
ret.ch.alpha = 0xFF;
return ret.full;
#endif
#elif LV_COLOR_DEPTH == 32
return color.full;
#endif