Fast and accurate screen/image color depth conversion #displays #images
When converting between low-bit color color formats (R4G4B4A4, R5G6B6, R8G8B8A8, and so on), the conversion routines used often don’t map to the nearest color channel values in the target bit depth.
For example, when converting 8 bit to 4 bit colors, this is typically done by simply the discarding the lower 4 bits of each channel. This is fast, but not very accurate; the maximum error of this method is 15 units in the source range compared to an error of 8 units when mapping to the closest value.
Inspired by this stackoverflow answer, which lists a method of expanding 5 and 6 bit color channels to their closest equivalent 8 bit value with a cheap combination of integer multiplication, addition and shifting, threadlocalmutex.com has devised a table lists conversion formulas for mapping between UNORM ranges of 4, 5, 6, 8, 10 and 11 bits with correct rounding. This is enough to cover all common color formats (4444, 555, 565, 8888, 10-10-10, 11-11-10) and build fast and accurate conversion routines for them.
Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7:30pm ET! To join, head over to YouTube and check out the show’s live chat and our Discord!
Python for Microcontrollers – Adafruit Daily — Python on Microcontrollers Newsletter: A New Arduino MicroPython Package Manager, How-Tos and Much More! #CircuitPython #Python #micropython @ThePSF @Raspberry_Pi
EYE on NPI – Adafruit Daily — EYE on NPI Maxim’s Himalaya uSLIC Step-Down Power Module #EyeOnNPI @maximintegrated @digikey