q565 0.1.0

RGB565 image codec based on QOI
Documentation

Q565 reference implementation.

Format

Header

  • 4-byte magic: q565
  • u16le width: 1..65535
  • u16le height: 1..65535

Stream format

.- QOI_OP_INDEX ----------.
|         Byte[0]         |
|  7  6  5  4  3  2  1  0 |
|-------+-----------------|
|  0  0 |     index       |
`-------------------------`
  • 2-bit tag b00
  • 6-bit index into the color index array: 0..63
  • A valid encoder must not issue 2 or more consecutive QOI_OP_INDEX chunks to the same index. QOI_OP_RUN should be used instead.
.- QOI_OP_DIFF -----------.
|         Byte[0]         |
|  7  6  5  4  3  2  1  0 |
|-------+-----+-----+-----|
|  0  1 |  dr |  dg |  db |
`-------------------------`
  • 2-bit tag b01
  • 2-bit red channel difference from the previous pixel between -2..1
  • 2-bit green channel difference from the previous pixel between -2..1
  • 2-bit blue channel difference from the previous pixel between -2..1
.- QOI_OP_LUMA -------------------------------------.
|         Byte[0]         |         Byte[1]         |
|  7  6  5  4  3  2  1  0 |  7  6  5  4  3  2  1  0 |
|----------+--------------+-------------+-----------|
|  1  0  0 |  green diff  |   dr - dg   |  db - dg  |
`---------------------------------------------------`
  • 3-bit tag b100
  • 5-bit green channel difference from the previous pixel -16..15
  • 4-bit red channel difference minus green channel difference -8..7
  • 4-bit blue channel difference minus green channel difference -8..7
.- QOI_OP_DIFF_INDEXED -----------------------------.
|         Byte[0]         |         Byte[1]         |
|  7  6  5  4  3  2  1  0 |  7  6  5  4  3  2  1  0 |
|----------+--------------+------+------------------|
|  1  0  1 | dg    |  dr  |  db  |            index |
`---------------------------------------------------`
  • 3-bit tag b101
  • 3-bit green channel difference from the indexed array pixel between -4..3
  • 2-bit red channel difference from the indexed array pixel between -2..1
  • 2-bit blue channel difference from the indexed array pixel between -2..1
  • 6-bit index into the color index array: 0..63
.- QOI_OP_RUN ------------.
|         Byte[0]         |
|  7  6  5  4  3  2  1  0 |
|-------+-----------------|
|  1  1 |       run       |
`-------------------------`
  • 2-bit tag b11
  • 6-bit run-length repeating the previous pixel: 1..62
  • The run-length is stored with a bias of -1. Note that the run-lengths 63 and 64 (b111110 and b111111) are illegal as they are occupied by the QOI_OP_RGB565 and QOI_OP_END tag.
.- QOI_OP_RGB565 -----------------------------.
|         Byte[0]         | Byte[1] | Byte[2] |
|  7  6  5  4  3  2  1  0 | 7 .. 0  | 7 .. 0  |
|-------------------------+---------+---------|
|  1  1  1  1  1  1  1  0 | rgb565le          |
`---------------------------------------------`
  • 8-bit tag b11111110
  • 5-bit red channel value
  • 6-bit green channel value
  • 5-bit blue channel value
.- QOI_OP_END -------------
|         Byte[0]         |
|  7  6  5  4  3  2  1  0 |
|-------------------------+
|  1  1  1  1  1  1  1  1 |
`--------------------------

End of stream marker