QOI (image format)
{{short description|Image compression file format}}
{{Infobox file format
| name = Quite OK Image
| logo = File:Qoi-logo-black.svg
| extension = .qoi
| magic = {{code|qoif}} (4 bytes, ASCII)
| developer = Dominic Szablewski
| released = 24 November 2021
| latest_release_version = 1.0
| latest_release_date = {{start date and age|2022|1|5|df=yes}}
| genre = Lossless bitmap image format
| standard = [https://qoiformat.org/qoi-specification.pdf Specification]
| free = Yes
| open = Yes
| url = [https://qoiformat.org qoiformat.org]
}}
The Quite OK Image Format (QOI) is a specification for lossless image compression of 24-bit (8 bits per color RGB) or 32-bit (8 bits per color with 8-bit alpha channel RGBA) color raster (bitmapped) images, invented by Dominic Szablewski and first announced on 24 November 2021.{{cite web |url=https://phoboslab.org/log/2021/11/qoi-fast-lossless-image-compression |title=Lossless Image Compression in O(n) Time |date=2021-11-24 |website=Phoboslab.org |access-date=May 1, 2022 |archive-date=2022-05-08 |archive-url=https://web.archive.org/web/20220508110906/https://phoboslab.org/log/2021/11/qoi-fast-lossless-image-compression |url-status=live }}
Description
The intended purpose was to create an open source lossless compression method that was faster and easier to implement than PNG. Figures specified in the blog post announcing the format claim 20-50 times faster encoding, and 3-4 times faster decoding speed compared to PNG, with similar file sizes. The author has donated the specification to the public domain (CC0).{{cite web|url=https://qoiformat.org/|title=QOI The Quite OK Image Format|date=2023-12-14|website=qoiformat.org|access-date=December 14, 2023|archive-date=2023-12-16|archive-url=https://web.archive.org/web/20231216100658/https://qoiformat.org/|url-status=live}}
Software and language support
QOI is supported by FFmpeg (v5.1+),{{Cite web|title=FFmpeg Changelog - Gitweb|url=https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/Changelog|access-date=2022-07-13|website=ffmpeg.org|archive-date=2022-07-13|archive-url=https://web.archive.org/web/20220713044937/https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/Changelog|url-status=live}} GIMP (v3.0+),{{cite web |title=GIMP 3.0 Release Notes |url=https://www.gimp.org/release-notes/gimp-3.0.html |publisher=GIMP's Team |access-date=18 March 2025}} GraphicConverter (v11.8+),{{cite web |title=GraphicConverter Release Notes version 11.8 (build 5762) |url=https://www.lemkesoft.info/sparkle/graphicconverter/notes/5762.html |website=Lemke Software |access-date=21 February 2023 |archive-date=11 February 2023 |archive-url=https://web.archive.org/web/20230211145543/https://www.lemkesoft.info/sparkle/graphicconverter/notes/5762.html |url-status=live }} ImageGlass (v8.5+, read-only),{{cite web |title=Announcing ImageGlass 8.5 |url=https://imageglass.org/news/announcing-imageglass-8-5-74 |publisher=Duong Dieu Phap |access-date=14 March 2025 |date=2022-01-22}} ImageMagick (v7.1.0-20+),{{cite web |title=Changelog |url=https://github.com/ImageMagick/Website/blob/main/ChangeLog.md#710-20---2022-01-22 |publisher=ImageMagick |access-date=14 March 2025}} Imagine (v1.3.9+),{{cite web |title=Imagine - What's new? |url=https://www.nyam.pe.kr/dev/imagine/whatsnew/ |publisher=Sejin Chun |access-date=14 March 2025}} and IrfanView (v4.60+, with plugin).{{Cite web |title=History of IrfanView Changes/Versions |url=https://www.irfanview.com/main_history.htm |access-date=2022-05-10 |website=www.irfanview.com |archive-date=2021-01-14 |archive-url=https://web.archive.org/web/20210114060228/https://www.irfanview.com/main_history.htm |url-status=live }} Microsoft PowerToys (v0.76+) for Windows 10 and 11 adds support for previewing QOI images to File Explorer.{{cite web |title=Release v0.76.0 |url=https://github.com/microsoft/PowerToys/releases/tag/v0.76.0 |publisher=Microsoft |access-date=26 March 2024}}{{Cite web |date=2023-12-04 |title=PowerToys File Explorer add-ons utility for Windows |url=https://learn.microsoft.com/en-us/windows/powertoys/file-explorer |access-date=2024-02-05 |website=learn.microsoft.com |language=en-us}} Community made plugins are available in GIMP, Paint.NET and XnView MP.{{cite news|url=https://www.bangkokpost.com/tech/2279999/moving-images-to-the-next-level | title=Moving images to the next level |access-date=April 1, 2022 |author=James Hein |work=Bangkok Post| date=16 March 2022 }}
The game engine GameMaker has used a combination of bzip2 and QOI as the default storage format for texture groups since version 2022.1.0.609. Despite being smaller, files in the format decompress faster than those in the PNG format it displaced. The engine also offers plain QOI for increased decompression performance, and PNG for compatibility with tooling and web platforms.{{cite web |title=Version 2022.1.0.609 |url=https://gms.yoyogames.com/ReleaseNotes.html |website=GameMaker Release Notes |publisher=YoYo Games |access-date=26 March 2024 |date=26 January 2022}}{{cite web |title=Texture Groups |url=https://manual.gamemaker.io/monthly/en/Settings/Texture_Groups.htm |website=GameMaker Manual |publisher=YoYo Games |access-date=26 March 2024}}
There are also implementations for various languages such as Rust, Python, Java, C++, C# and more.{{cite news |url=https://www.theregister.com/2021/12/21/quite_ok_image_format/ |title=Developer creates 'Quite OK Image Format' – but it performs better than just OK |author=Simon Sharwood |work=The Register |access-date=2023-12-30 |archive-date=2023-06-02 |archive-url=https://web.archive.org/web/20230602214542/https://www.theregister.com/2021/12/21/quite_ok_image_format/ |url-status=live }} A full list can be found on the [https://github.com/phoboslab/qoi#implementations--bindings-of-qoi project's Git(Hub) repository README].
File format
= Header=
A QOI file consists of a 14-byte header, followed by any number of data “chunks” and an 8-byte end marker.
char magic[4]; // magic bytes "qoif"
uint32_t width; // image width in pixels (BE)
uint32_t height; // image height in pixels (BE)
uint8_t channels; // 3 = RGB, 4 = RGBA
uint8_t colorspace; // 0 = sRGB with linear alpha
// 1 = all channels linear
};
The colorspace and channel fields are purely informative. They do not change the way data chunks are encoded.
= Encoding =
Images are encoded row by row, left to right, top to bottom. The
decoder and encoder start with {{code|2=yaml| {r: 0, g: 0, b: 0, a: 255} }} as the previous pixel value. An image is complete when all pixels specified by {{code|width * height}} have been covered. Pixels are encoded as:
- Run-length encoding of the previous pixel ({{code|QOI_OP_RUN}})
- an index into the array of previously seen pixels ({{code|QOI_OP_INDEX}})
- a difference compared to the previous pixel value in r,g,b ({{code|QOI_OP_DIFF}} or {{code|QOI_OP_LUMA}})
- Full r,g,b or r,g,b,a values ({{code|QOI_OP_RGB}} or {{code|QOI_OP_RGBA}})
The color channels are assumed to not be premultiplied with the alpha channel (“un-premultiplied alpha”). A running {{code|array[64]}} (zero-initialized) of previously seen pixel
values is maintained by the encoder and decoder. Each pixel that is seen by the encoder and decoder is put into this array at the position formed by a hash function of the color value.
In the encoder, if the pixel value at the index matches the current pixel, this index position is written to the stream as {{code|QOI_OP_INDEX}}. The hash function for the index is:
Each chunk starts with a 2- or 8-bit tag, followed by a number of data bits. The bit length of chunks is divisible by 8 - i.e. all chunks are byte aligned. All values encoded in these data bits have the most significant bit on the left. The 8-bit tags have precedence over the 2-bit tags. A decoder must check for the presence of an 8-bit tag first. The byte stream's end is marked with 7 {{code|0x00}} bytes followed by a single {{code|0x01}} byte.
The possible chunks are:
== {{code|QOI_OP_RGB}} ==
class="wikitable" style="text-align:center;"
! colspan="8" | Byte[0] ! Byte[1] ! Byte[2] ! Byte[3] |
7
| 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 .. 0 | 7 .. 0 | 7 .. 0 |
1
| 1 | 1 | 1 | 1 | 1 | 1 | 0 | red | green | blue |
- 8-bit tag {{code|b11111110}} (254)
- 8-bit red channel value
- 8-bit green channel value
- 8-bit blue channel value
The alpha value remains unchanged from the previous pixel.
== {{code|QOI_OP_RGBA}} ==
class="wikitable" style="text-align:center;"
! colspan="8" | Byte[0] ! Byte[1] ! Byte[2] ! Byte[3] ! Byte[4] |
7
| 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 .. 0 | 7 .. 0 | 7 .. 0 | 7 .. 0 |
1
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | red | green | blue | alpha |
- 8-bit tag {{code|b11111111}} (255)
- 8-bit red channel value
- 8-bit green channel value
- 8-bit blue channel value
- 8-bit alpha channel value
== {{code|QOI_OP_INDEX}} ==
class="wikitable" style="text-align:center;" |
colspan="8" | Byte[0] (Range: 0 .. 63) |
---|
7
| 6 | 5 | 4 | 3 | 2 | 1 | 0 |
0
| 0 | colspan="6" | index |
- 2-bit tag {{code|b00}}
- 6-bit index into the color index array: {{code|0..63}}
A valid encoder must not issue 2 or more consecutive {{code|QOI_OP_INDEX}}
chunks to the same index. {{code|QOI_OP_RUN}} should be used instead.
== {{code|QOI_OP_DIFF}} ==
class="wikitable" style="text-align:center;" |
colspan="8" | Byte[0] (Range: 64 .. 127) |
---|
7
| 6 | 5 | 4 | 3 | 2 | 1 | 0 |
0
| 1 | colspan="2" | dr | colspan="2" | dg | colspan="2" | db |
- 2-bit tag {{code|b01}}
- 2-bit red channel difference from the previous pixel {{code|-2..1}}
- 2-bit green channel difference from the previous pixel {{code|-2..1}}
- 2-bit blue channel difference from the previous pixel {{code|-2..1}}
The difference to the current channel values are using a wraparound operation, so {{code|1 - 2}} will result in 255, while {{code|255 + 1}} will result in 0.
Values are stored as unsigned integers with a bias of 2. E.g. −2 is stored as 0 ({{code|b00}}). 1 is stored as 3 ({{code|b11}}). The alpha value remains unchanged from the previous pixel.
== {{code|QOI_OP_LUMA}} ==
class="wikitable" style="text-align:center;" |
colspan="8" | Byte[0] (Range: 128 .. 191)
! colspan="8" | Byte[1] |
---|
7
| 6 | 5 | 4 | 3 | 2 | 1 | 0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
1
| 0 | colspan="6" | dg | colspan="4" | dr - dg | colspan="4" | db - dg |
- 2-bit tag {{code|b10}}
- 6-bit green channel difference from the previous pixel {{code|-32..31}}
- 4-bit red channel difference minus green channel difference {{code|-8..7}}
- 4-bit blue channel difference minus green channel difference {{code|-8..7}}
The green channel is used to indicate the general direction of change and is encoded in 6 bits. The red and blue channels (dr and db) base their diffs off of the green channel difference. I.e.:
dr_dg = (cur_px.r - prev_px.r) - (cur_px.g - prev_px.g)
db_dg = (cur_px.b - prev_px.b) - (cur_px.g - prev_px.g)
The difference to the current channel values are using a wraparound operation, so {{code|10 - 13}} will result in 253, while {{code|250 + 7}} will result in 1.
Values are stored as unsigned integers with a bias of 32 for the green channel and a bias of 8 for the red and blue channel. The alpha value remains unchanged from the previous pixel.
== {{code|QOI_OP_RUN}} ==
class="wikitable" style="text-align:center;" |
colspan="8" | Byte[0] (Range: 192 .. 253) |
---|
7
| 6 | 5 | 4 | 3 | 2 | 1 | 0 |
1
| 1 | colspan="6" | run |
- 2-bit tag {{code|b11}}
- 6-bit run-length repeating the previous pixel
The run-length is stored with a bias of −1. Note that the runlengths 63 and 64 ({{code|b111110}} and {{code|b111111}}) are illegal as they are occupied by the {{code|QOI_OP_RGB}} and {{code|QOI_OP_RGBA}} tags.{{Cite web|url=https://qoiformat.org/qoi-specification.pdf|title=The Quite OK Image Format Specification|last=Szablewski|first=Dominic|date=2022-01-05|access-date=2022-06-05|archive-date=2022-04-30|archive-url=https://web.archive.org/web/20220430064011/https://qoiformat.org/qoi-specification.pdf|url-status=live}} {{Source-attribution}}
References
External links
- [https://qoiformat.org Format website: C Source code and benchmark results]
- [https://qoiformat.org/qoi-specification.pdf 1 page PDF specification]
- [https://github.com/phoboslab/qoi GitHub repository (including C implementation)]
- [https://www.youtube.com/watch?v=EFUYNoFRHQI How PNG Works: Compromising Speed for Quality - YouTube] A video comparing compression techniques in PNG and QOI with animations and examples.
{{Graphics file formats|state=expanded}}
{{Compression formats}}
{{Authority control}}