QOI (image format)

Last updated
Quite OK Image
Qoi-logo-black.svg
Filename extension
.qoi
Magic number qoif (4 bytes, ASCII)
Developed byDominic Szablewski
Initial release24 November 2021
Latest release
1.0
5 January 2022;2 years ago (2022-01-05)
Type of format Lossless bitmap image format
Standard Specification
Open format?Yes
Free format?Yes
Website 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. [1]

Contents

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. [1] The author has donated the specification to the public domain (CC0). [2]

Software and language support

QOI is supported natively by ImageMagick, [3] Imagine (v1.3.9+), IrfanView (v4.60+), [4] FFmpeg (v5.1+), [5] and GraphicConverter (v11.8+). [6] Microsoft PowerToys (v0.76+) for Windows 10 and 11 adds support for previewing QOI images to the Windows File Explorer. [7] [8] Community made plugins are available in GIMP, Paint.NET and XnView MP. [9]

The game engine GameMaker designates bzip2 + QOI as the default format of texture groups since version 2022.1.0.609, to achieve the better compression but still quicker to decompress, while the standalone QOI and PNG formats are optional for the even faster performance and better compabilities respectively. [10] [11]

There are also implementations for various languages such as Rust, Python, Java, C++, C# and more. [12] A full list can be found on the project's Git(Hub) repository README.

File format

A QOI file consists of a 14-byte header, followed by any number of data “chunks” and an 8-byte end marker.

qoi_header{charmagic[4];// magic bytes "qoif"uint32_twidth;// image width in pixels (BE)uint32_theight;// image height in pixels (BE)uint8_tchannels;// 3 = RGB, 4 = RGBAuint8_tcolorspace;// 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 {r:0, g:0, b:0, a:255} as the previous pixel value. An image is complete when all pixels specified by width * height have been covered. Pixels are encoded as:

The color channels are assumed to not be premultiplied with the alpha channel (“un-premultiplied alpha”). A running 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 QOI_OP_INDEX. The hash function for the index is:

index_position=(r*3+g*5+b*7+a*11)%64

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 0x00 bytes followed by a single 0x01 byte.

The possible chunks are:

QOI_OP_RGB

Byte[0]Byte[1]Byte[2]Byte[3]
765432107 .. 07 .. 07 .. 0
11111110redgreenblue
  • 8-bit tag 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.

QOI_OP_RGBA

Byte[0]Byte[1]Byte[2]Byte[3]Byte[4]
765432107 .. 07 .. 07 .. 07 .. 0
11111111redgreenbluealpha
  • 8-bit tag b11111111 (255)
  • 8-bit red channel value
  • 8-bit green channel value
  • 8-bit blue channel value
  • 8-bit alpha channel value

QOI_OP_INDEX

Byte[0] (Range: 0 .. 63)
76543210
00index
  • 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] (Range: 64 .. 127)
76543210
01drdgdb
  • 2-bit tag b01
  • 2-bit red channel difference from the previous pixel -2..1
  • 2-bit green channel difference from the previous pixel -2..1
  • 2-bit blue channel difference from the previous pixel -2..1

The difference to the current channel values are using a wraparound operation, so 1 - 2 will result in 255, while 255 + 1 will result in 0.

Values are stored as unsigned integers with a bias of 2. E.g. 2 is stored as 0 (b00). 1 is stored as 3 (b11). The alpha value remains unchanged from the previous pixel.

QOI_OP_LUMA

Byte[0] (Range: 128 .. 191)Byte[1]
7654321076543210
10dgdr - dgdb - dg
  • 2-bit tag b10
  • 6-bit green channel difference from the previous pixel -32..31
  • 4-bit red channel difference minus green channel difference -8..7
  • 4-bit blue channel difference minus green channel difference -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 10 - 13 will result in 253, while 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.

QOI_OP_RUN

Byte[0] (Range: 192 .. 253)
76543210
11run
  • 2-bit tag 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 (b111110 and b111111) are illegal as they are occupied by the QOI_OP_RGB and QOI_OP_RGBA tags. [13]

Related Research Articles

<span class="mw-page-title-main">Alpha compositing</span> Operation in computer graphics

In computer graphics, alpha compositing or alpha blending is the process of combining one image with a background to create the appearance of partial or full transparency. It is often useful to render picture elements (pixels) in separate passes or layers and then combine the resulting 2D images into a single, final image called the composite. Compositing is used extensively in film when combining computer-rendered image elements with live footage. Alpha blending is also used in 2D computer graphics to put rasterized foreground elements over a background.

<span class="mw-page-title-main">GIF</span> Bitmap image file format family

The Graphics Interchange Format is a bitmap image format that was developed by a team at the online services provider CompuServe led by American computer scientist Steve Wilhite and released on June 15, 1987.

<span class="mw-page-title-main">JPEG</span> Lossy compression method for reducing the size of digital images

JPEG is a commonly used method of lossy compression for digital images, particularly for those images produced by digital photography. The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image quality. JPEG typically achieves 10:1 compression with little perceptible loss in image quality. Since its introduction in 1992, JPEG has been the most widely used image compression standard in the world, and the most widely used digital image format, with several billion JPEG images produced every day as of 2015.

<span class="mw-page-title-main">PNG</span> Family of lossless-compression image file formats

Portable Network Graphics is a raster-graphics file format that supports lossless data compression. PNG was developed as an improved, non-patented replacement for Graphics Interchange Format (GIF)—unofficially, the initials PNG stood for the recursive acronym "PNG's not GIF".

PCX, standing for PiCture eXchange, is an image file format developed by the now-defunct ZSoft Corporation of Marietta, Georgia, United States. It was the native file format for PC Paintbrush and became one of the first widely accepted DOS imaging standards, although it has since been succeeded by more sophisticated image formats, such as BMP, JPEG, and PNG. PCX files commonly store palette-indexed images ranging from 2 or 4 colors to 16 and 256 colors, although the format has been extended to record true-color (24-bit) images as well.

Gamma correction or gamma is a nonlinear operation used to encode and decode luminance or tristimulus values in video or still image systems. Gamma correction is, in the simplest cases, defined by the following power-law expression:

The BMP file format, or bitmap, is a raster graphics image file format used to store bitmap digital images, independently of the display device, especially on Microsoft Windows and OS/2 operating systems.

<span class="mw-page-title-main">RGBA color model</span> RGB color model with an opacity channel

RGBA stands for red green blue alpha. While it is sometimes described as a color space, it is actually a three-channel RGB color model supplemented with a fourth alpha channel. Alpha indicates how opaque each pixel is and allows an image to be combined over others using alpha compositing, with transparent areas and anti-aliasing of the edges of opaque regions. Each pixel is a 4D vector.

<span class="mw-page-title-main">ILBM</span> File format

Interleaved Bitmap (ILBM) is an image file format conforming to the Interchange File Format (IFF) standard. The format originated on the Amiga platform, and on IBM-compatible systems, files in this format or the related PBM format are typically encountered in games from late 1980s and early 1990s that were either Amiga ports or had their graphical assets designed on Amiga machines.

Truevision TGA, often referred to as TARGA, is a raster graphics file format created by Truevision Inc.. It was the native format of TARGA and VISTA boards, which were the first graphic cards for IBM-compatible PCs to support high color or true color display. This family of graphic cards was intended for professional computer image synthesis and video editing with PCs; for this reason, usual resolutions of TGA image files match those of the NTSC and PAL video formats.

pngcrush Command-line PNG optimiser

pngcrush is a free and open-source command-line utility for optimizing PNG image files. It reduces the size of the file losslessly – that is, the resulting "crushed" image will have the same quality as the source image.

S3 Texture Compression (S3TC) is a group of related lossy texture compression algorithms originally developed by Iourcha et al. of S3 Graphics, Ltd. for use in their Savage 3D computer graphics accelerator. The method of compression is strikingly similar to the previously published Color Cell Compression, which is in turn an adaptation of Block Truncation Coding published in the late 1970s. Unlike some image compression algorithms, S3TC's fixed-rate data compression coupled with the single memory access made it well-suited for use in compressing textures in hardware-accelerated 3D computer graphics. Its subsequent inclusion in Microsoft's DirectX 6.0 and OpenGL 1.3 led to widespread adoption of the technology among hardware and software makers. While S3 Graphics is no longer a competitor in the graphics accelerator market, license fees have been levied and collected for the use of S3TC technology until October 2017, for example in game consoles and graphics cards. The wide use of S3TC has led to a de facto requirement for OpenGL drivers to support it, but the patent-encumbered status of S3TC presented a major obstacle to open source implementations, while implementation approaches which tried to avoid the patented parts existed.

Netpbm is an open-source package of graphics programs and a programming library. It is used mainly in the Unix world, where one can find it included in all major open-source operating system distributions, but also works on Microsoft Windows, macOS, and other operating systems.

The ICO file format is an image file format for computer icons in Microsoft Windows. ICO files contain one or more small images at multiple sizes and color depths, such that they may be scaled appropriately. In Windows, all executables that display an icon to the user, on the desktop, in the Start Menu, or in file Explorer, must carry the icon in ICO format.

An image file format is a file format for a digital image. There are many formats that can be used, such as JPEG, PNG, and GIF. Most formats up until 2022 were for storing 2D images, not 3D ones. The data stored in an image file format may be compressed or uncompressed. If the data is compressed, it may be done so using lossy compression or lossless compression. For graphic design applications, vector formats are often used. Some image file formats support transparency.

The Apple Icon Image format (.icns) is an icon format used in Apple Inc.'s macOS. It supports icons of 16 × 16, 32 × 32, 48 × 48, 128 × 128, 256 × 256, 512 × 512 points at 1x and 2x scale, with both 1- and 8-bit alpha channels and multiple image states. The fixed-size icons can be scaled by the operating system and displayed at any intermediate size.

Silicon Graphics Image (SGI) or the RGB file format is the native raster graphics file format for Silicon Graphics workstations. The format was invented by Paul Haeberli. It can be run-length encoded (RLE). FFmpeg and ImageMagick, among others, support this format.

PVRTC and PVRTC2 are a family of lossy, fixed-rate texture compression formats used in PowerVR's MBX, SGX and Rogue technologies. The PVRTC algorithm is documented in Simon Fenney's paper "Texture Compression using Low-Frequency Signal Modulation" that was presented at Graphics Hardware 2003.

Ericsson Texture Compression (ETC) is a lossy texture compression technique developed in collaboration with Ericsson Research in early 2005. It was originally developed under the name iPACKMAN and based on an earlier compression scheme called iPACKMAN.

<span class="mw-page-title-main">Free Lossless Image Format</span> Raster graphics format

Free Lossless Image Format (FLIF) is a lossless image format claiming to outperform PNG, lossless WebP, lossless BPG and lossless JPEG 2000 in terms of compression ratio on a variety of inputs.

References

  1. 1 2 "Lossless Image Compression in O(n) Time". Phoboslab.org. 2021-11-24. Archived from the original on 2022-05-08. Retrieved May 1, 2022.
  2. "QOI The Quite OK Image Format". qoiformat.org. 2023-12-14. Archived from the original on 2023-12-16. Retrieved December 14, 2023.
  3. "ImageMagick - Image Formats". Archived from the original on January 2, 2022. Retrieved May 4, 2022.
  4. "History of IrfanView Changes/Versions". www.irfanview.com. Archived from the original on 2021-01-14. Retrieved 2022-05-10.
  5. "FFmpeg Changelog - Gitweb". ffmpeg.org. Archived from the original on 2022-07-13. Retrieved 2022-07-13.
  6. "GraphicConverter Release Notes version 11.8 (build 5762)". Lemke Software. Archived from the original on 11 February 2023. Retrieved 21 February 2023.
  7. "Release v0.76.0". Microsoft. Retrieved 26 March 2024.
  8. "PowerToys File Explorer add-ons utility for Windows". learn.microsoft.com. 2023-12-04. Retrieved 2024-02-05.
  9. James Hein. "Moving images to the next level". Bangkok Post . Retrieved April 1, 2022.
  10. "Version 2022.1.0.609". GameMaker Release Notes. YoYo Games. 26 January 2022. Retrieved 26 March 2024.
  11. "Texture Groups". GameMaker Manual. YoYo Games. Retrieved 26 March 2024.
  12. Simon Sharwood. "Developer creates 'Quite OK Image Format' – but it performs better than just OK". The Register . Archived from the original on 2023-06-02. Retrieved 2023-12-30.
  13. Szablewski, Dominic (2022-01-05). "The Quite OK Image Format Specification" (PDF). Archived (PDF) from the original on 2022-04-30. Retrieved 2022-06-05.PD-icon.svg This article incorporates text from this source, which is in the public domain .