nigeltao / qoi2-bikeshed

"Quite OK Image" version 2 discussions
33 stars 0 forks source link

QOI-plane, a 1 and 2 channels (grey and grey + alpha) codec like QOI #40

Open p0nce opened 2 years ago

p0nce commented 2 years ago

This "QOI-plane" codec breaks byte alignment and works in groups of 4-bits in order to encode greyscale. https://github.com/AuburnSounds/gamut/blob/main/source/gamut/codecs/qoiplane.d#L79

Typically it encodes a uint8 image with 4.55 bit / pixel, and a luminance + alpha image with lower number of bits, but I fear my test suite is too easy with alpha + grey images. Didn't find the opcode room to have a FIFO.

So it beat a qoiavg2 that would instead encode a greyscale input as rgb color, which leads to more than 8-bit / per pixel. All these numbers are after a LZ4, I haven't tried a naked QOI-plane.

/// Encoding:
///
/// QOIPLANE_DIFF1     0xxx                          => diff -4..+3 vs average of rounded up left pixel and top pixel
/// QOIPLANE_DIFF2     100x xxxx                     => diff -16..15 vs average of rounded up left pixel and top pixel
/// QOIPLANE_ADIFF     1011 xxxx                     => diff -7..+7 in alpha channel
/// QOIPLANE_LA        1011 0000 xxxx xxxx aaaa aaaa => encode direct full values
/// QOIPLANE_DIRECT    1010 xxxx xxxx                => direct value
///                                                   If channels == 2 and the last opcode is not a QOIPLANE_ADIFF
///                                                   then QOIPLANE_DIRECT encodes an alpha value.
/// QOIPLANE_REPEAT1   11xx                          => repeat 1 to 3 times the last pixel
/// QOIPLANE_REPEAT2   1111 xxxx xxxx                => repeat 4 to 258 times a pixel.
///                                                     (1111 1111 1111 disallowed, indicates end of stream)