espressif / esp32-camera

Apache License 2.0
1.86k stars 634 forks source link

Incorrect handling of RGB565 images during conversion to BMP or RGB888 #676

Open jksemple opened 1 month ago

jksemple commented 1 month ago

There is an inconsistency in the handling of RGB565 images in memory. When decoding a JPG the 16-bit RGB565 pixel value is composed (conversions/to_bmp.c lines 150-155) with R G B bits in that order in the word and then written to memory as low-byte high-byte. This little-endian order is consistent with the ordering of bytes for other 16-bit or 32-bit values in a BMP e.g. image length.

However, when converting to BMP or RGB888 format the RGB565 pixel value is read as if it were stored as high byte followed by low byte (conversions/to_bmp.c lines 360 and 361 and lines 254 255). This has a psychedelic effect on the colours in resulting images. A workaround is to swap the order of bytes in an RGB565 image before such a conversion but this is not an acceptable fix.

Please swap lines 360/361 and lines 254/255