Incompatible adaptation of QOI format - https://phoboslab.org
-- LICENSE: The MIT License(MIT) Copyright(c) 2021 Dominic Szablewski (original QOI format) Copyright(c) 2022 Guillaume Piolat (QOI-10b variant for 10b images, 1/2/3/4 channels). Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions : The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- Documentation This library provides the following functions; - qoi10b_decode -- decode the raw bytes of a QOI-10b image from memory - qoi10b_encode -- encode an rgba buffer into a QOI-10b image in memory
A QOI-10b file has a 25 byte header, compatible with Gamut QOIX.
struct qoix_header_t { char magic[4]; // magic bytes "qoix" uint32_t width; // image width in pixels (BE) uint32_t height; // image height in pixels (BE) uint8_t version_; // Major version of QOIX format. uint8_t channels; // 1, 2, 3 or 4 uint8_t bitdepth; // 10 = this QOI-10b codec is always 10-bit (8 would indicate QOI2AVG or QOI-plane) uint8_t colorspace; // 0 = sRGB with linear alpha, 1 = all channels linear uint8_t compression; // 0 = none, 1 = LZ4 float pixelAspectRatio; // -1 = unknown, else Pixel Aspect Ratio float resolutionX; // -1 = unknown, else physical resolution in DPI };
The decoder and encoder start with {r: 0; g: 0; b: 0; a: 0} as the previous pixel value. Pixels are either encoded as - a run of the previous pixel - a difference to the previous pixel value - full luminance value
The byte stream's end is marked with 5 0xff bytes.
This codec is simply like QOI2AVG but with extra 2 bits for each components, and it breaks byte alignment.
Optimized? Opcode Bits(RGB) Bits(grey) Meaning [ ] QOI_OP_LUMA 14 6 0gggggrrrrbbbb (less g or more g => doesn't work) [ ] QOI_OP_LUMA0 12 6 10ggggrrrbbb [ ] QOI_OP_LUMA2 22 10 110gggggggrrrrrrbbbbbb [ ] QOI_OP_LUMA3 30 14 11100gggggggggrrrrrrrrbbbbbbbb [ ] QOI_OP_ADIFF 10 10 11101xxxxx x QOI_OP_RUN 8 8 11110xxx 16 16 11110111xxxxxxxx [ ] QOI_OP_ADIFF2 16 16 111110xxxxxxxx x QOI_OP_GRAY 18 18 11111100gggggggggg [ ] QOI_OP_RGB 38 18 11111101rrrrrrrrrrggggggggggbbbbbbbbbb [ ] QOI_OP_RGBA 48 28 11111110rrrrrrrrrrggggggggggbbbbbbbbbbaaaaaaaaaa [ ] QOI_OP_END 8 8 11111111
A QOI-inspired codec for 10-bit images, called "QOI-10b". Input image is 16-bit ushort, but only 10-bits gets encoded making it lossy.