4 releases (breaking)

0.4.0 Jul 10, 2023
0.3.0 May 17, 2023
0.2.0 May 12, 2023
0.1.0 Apr 4, 2023

#599 in Images

Download history 43/week @ 2024-01-06 57/week @ 2024-01-13 13/week @ 2024-01-27 21/week @ 2024-02-03 37/week @ 2024-02-10 85/week @ 2024-02-17 84/week @ 2024-02-24 104/week @ 2024-03-02 73/week @ 2024-03-09 70/week @ 2024-03-16 18/week @ 2024-03-23 50/week @ 2024-03-30 22/week @ 2024-04-06 36/week @ 2024-04-13

139 downloads per month

MIT/Apache

45KB
954 lines

Reference implementation for the Q565 image format.

Q565 is heavily based on the QOI Image format, but altered to support the 16-bit RGB565 pixel format (and that format only).

Differences from QOI

Header

  • 4-byte magic: q565
  • u16le width (non-zero)
  • u16le height (non-zero)

Color array

Q565 uses a simplified color array compared to the one from QOI. The "hash" function was replaced with just adding the bytes of the RGB565 u16 together and keeping the lowest 6 bits of the result. This resulted in smaller images on average and has the additional bonus of eliminating the last usage of multiplication in the decoder loop, making it reasonably fast even on microcontrollers without fast multiplication support.

In addition, pixels that can already be described in one byte are not added to the color array (Q565_OP_DIFF). This helps keep the color array from being flooded with similar colors.

Q565_OP_DIFF_INDEXED

Since we only have 5/6 bits per channel, Q565_OP_LUMA was reduced to represent the green channel difference with just 5 instead of 6 bits. The gained bit is now used as part of the tag, to discern between the new Q565_OP_DIFF_INDEXED and Q565_OP_LUMA.

Q565_OP_DIFF_INDEXED is similar to Q565_OP_DIFF, but instead applies the difference to a color from the color array. This results in an up to 5% smaller image size, at the expense of a slower encoder (needing to calculate up to 64 color differences in the worst case). If a faster encoder is needed, this operation can be omitted.

Stream format

See [consts] for the different operation types.

Dependencies

~2MB
~46K SLoC