1 Introduction
Lossless image compression remains critical in imaging pipelines where exact pixel fidelity is mandatory—such as in scientific visualization, medical imaging and digital archiving. Classical schemes span several paradigms: entropy coding [Reference Huffman5, Reference Rissanen12]; predictive coding exemplified by the joint photographic experts group (JPEG), JPEG lossless standard (JPEG-LS) and portable network graphics (PNG) [Reference Boutell1, Reference Wallace19, Reference Weinberger, Seroussi and Sapiro20]; transform coding as in JPEG 2000 [Reference Skodras, Christopoulos and Ebrahimi15, Reference Taubman, Marcellin and Rabbani18]; and context-adaptive methods such as context-based adaptive lossless image coding (CALIC) [Reference Wu and Memon21, Reference Wu and Memon22] (see also general surveys [Reference Rahman and Hamada10]).
The Quite OK Image Format (QOI) [Reference Szablewski17] is a recent, minimalist and fast lossless codec that achieves compression ratios comparable to PNG while being typically 3 to 4 times faster in both encoding and decoding. Despite its efficiency, certain design choices—particularly, sequential pixel processing and the index mode—can limit performance on high-resolution or pathology images, motivating the development of improved variants.
1.1 Overview of the QOI algorithm
To motivate our proposed variants, we briefly review the standard QOI encoding mechanisms. The algorithm compresses 8-bit per channel images—red, green, blue (RGB) or red, green, blue, alpha (RGBA)—by processing pixels sequentially and selecting one of six operational modes based on the current pixel and its context.
1.1.1 Run-length encoding
Consecutive identical pixels are encoded in run-length mode, using a 6-bit counter combined with the 2-bit flag. This is the most efficient compression mode in QOI. (See Table 1.)
QOI_OP_RUN encoding.

1.1.2 Hash encoding
A 64-entry hash table stores recently encountered unique pixels. The hash is computed as
If the current pixel matches the table entry, the “00” flag and 6-bit index are emitted; otherwise, the table is updated. (See Table 2.)
QOI_OP_INDEX encoding.

1.1.3 Pixel differential encoding
If the alpha channel is unchanged and RGB differences (
$\text {dr}, \text {dg}, \text {db}$
) with the previous pixel are in
$[-2,1]$
, each difference is encoded with 2 bits and combined with the “01” flag, achieving a compression ratio of
$1/4$
. (See Table 3.)
QOI_OP_DIFF encoding.

1.1.4 Chroma differential encoding
This mode exploits the green channel as a luminance reference. If
$\Delta G \in [-32,31]$
and
$\Delta R-\Delta G, \Delta B-\Delta G \in [-8,7]$
, values are encoded into two bytes with the “10” flag, achieving a compression ratio of
$1/2$
. (See Table 4.)
QOI_OP_LUMA encoding.

1.2 Limitations of QOI
While elegant and fast, QOI has two main limitations for modern high-resolution workloads: (i) limited pixel-level parallelism due to sequential dependencies; and (ii) suboptimal compression for natural and pathology images where the index mode is a bottleneck. Parallel CPU/GPU implementations and GPU-oriented codecs [Reference de Cea-Dominguez, Moure, Bartrina-Rapesta and Aulí-Llinàs2, Reference De Cea-Dominguez, Moure-Lopez, Bartrina-Rapesta and Aulí-Llinàs3, Reference Shi, Ma, Wu, Du, Xia and Li14, Reference Sneyers and Wuille16] partially alleviate throughput issues but increase architectural complexity. Learning-based approaches [Reference Liao and Li8, Reference Rhee, Jang, Kim and Cho11, Reference Schiopu and Munteanu13] improve modelling but are resource-intensive for ultra-high-resolution images (
$10^8$
–
$10^{10}$
pixels).
1.3 Recent works
Recent advances address lossless image coding from modelling and system perspectives. Fitted neural lossless image compression (FNLIC) fits channel-wise discrete mixture models with lightweight heads [Reference Zhang, Chen and Liu23], content-adaptive learning for lossless image compression (CALLIC) adapts entropy models to image content [Reference Li, Bai, Wang, Jiang, Liu and Gao6] and large language model (LLM)-driven entropy modelling achieves state-of-the-art results while maintaining domain flexibility [Reference Du, Zhou, Cao, Chen, Chen, Cheng, Song, Lu and Zhang4]. Foundation-model-scale approaches such as lossless data compression by large models (LMCompress) explore large-model-based general-purpose compression [Reference Li, Huang, Wang, Hu, Wyeth, Bu, Yu, Gao, Liu and Li7]. For whole-slide imaging, the whole-slide-image lossless compression framework (WISE) [Reference Mao, Wang, Guan and Xue9] introduces tile-wise parallelism, and segmentation-assisted multi-entropy models for learned lossless image compression (SEEC) [Reference Zheng, Ren and Li24] incorporate semantic masks—a concept complementary to our proposed DIFF/DIFF UP contexts.
1.4 Contributions
Building upon QOI [Reference Szablewski17] and the LOCO-I predictor underlying JPEG-LS [Reference Weinberger, Seroussi and Sapiro20], we propose two QOI-compatible and fully parallelizable variants: QOI3 for 8-bit RGB images and QOI2 for 8-bit two-channel pathology images. Composite pipelines—QOI3JPEGLS and QOI2JPEGLS—prepend LOCO-I prediction to our QOI variants, eliminating the index mode, introducing a DIFF UP mode to exploit vertical context and optimizing traversal order for full parallelism. Empirically, these methods improve compression ratios on natural and pathology images while preserving QOI-style simplicity and speed.
The contributions are summarized as follows.
-
(i) Full-process parallelization: algorithmic modifications that remove serial bottlenecks and scale efficiently across threads and cores.
-
(ii) Specialized variants: QOI3 for RGB and QOI2 for two-channel pathology images, exploiting inter-channel statistical structure.
-
(iii) Composite pipelines: integration of LOCO-I with QOI variants to reduce residual entropy, maintaining strict losslessness and reversibility.
2 Proposed algorithms
2.1 Lossless compression algorithm for 8-bit three-channel images (QOI3)
This algorithm takes an 8-bit three-channel image as input and encodes pixels in a sequential order: the first pixel, the first column, the first row, and then the remaining pixels from left to right and top to bottom. The encoding uses five modes: RUN MODE, DIFF MODE, DIFF UP MODE, LUMA MODE and RGB MODE. These modes are organized in ascending order of byte usage and exploit differences in the three channels of neighbouring pixels to optimize compression under both best- and worst-case scenarios.
QOI3 is built upon the original QOI algorithm with several enhancements. It captures contextual relationships in 8-bit three-channel images more effectively by replacing the original INDEX MODE with a newly designed DIFF UP MODE and by optimizing pixel traversal to enable parallel processing. While INDEX MODE in standard QOI performs well for images with many discontinuously repeated pixels (for example, screenshots of phone memos), it often becomes the limiting factor for compression efficiency on natural and pathology images.
2.1.1 RUN MODE
RUN MODE implements run-length encoding, which compresses consecutive identical pixels. The maximum run-length is
$run = 62$
because
$0b11111110$
is reserved as the RGB MODE tag. (See Algorithm 1.)

2.1.2 DIFF MODE
DIFF MODE encodes the difference between the current pixel and the pixel to its left. It leverages the fact that differences among the three channels are often small. (See Algorithm 2.)

2.1.3 DIFF UP MODE
DIFF UP MODE encodes the difference between the current pixel and the pixel above it. This mode is similar in principle to DIFF MODE and is used when DIFF MODE is inapplicable, aiming to encode a pixel within a single byte. (See Algorithm 3.)

2.1.4 LUMA MODE
LUMA MODE encodes pixels whose difference from the previous pixel is large. It exploits the property that channel differences relative to the green channel are often small, allowing compression of larger differences using only two bytes. In most cases, LUMA MODE is rarely activated; for the tested images, fewer than 5% of pixels required this mode. (See Algorithm 4.)

2.1.5 RGB MODE
RGB MODE encodes pixels when the difference from the previous pixel is too large for DIFF or LUMA MODE. It is the least frequently used mode for most natural images. (See Algorithm 5.)

2.1.6 Lossless compression algorithm for 8-bit three-channel images
This encoding combines the five compression modes mentioned earlier in sequence to achieve a correct encoding algorithm. (See Algorithm 6.)

QOI3 lossless image compression algorithm.

The functionality of the QOI3 algorithm is visually summarized in Figure 1.
2.2 Lossless compression algorithm for 8-bit two-channel pathology images (QOI2)
This algorithm is inspired by our proposed 8-bit two-channel lossless compression design and the original QOI algorithm. It integrates the key principles of both into the compression of 8-bit two-channel images, and hence named QOI2. Most pathology images are stained with two dyes, generating two distinct channels, which motivates the development of a dedicated two-channel compression method. QOI2 is particularly suitable for efficient compression of such pathology images.
2.2.1 RUN MODE
RUN MODE implements run-length encoding, compressing consecutive identical pixels. The maximum run-length is
$run = 63$
, as
$0b11111111$
is reserved for the RG MODE tag. (See Algorithm 7.)

2.2.2 DIFF MODE
DIFF MODE encodes the difference between the current pixel and its left neighbour, leveraging the fact that differences across channels are typically small. (See Algorithm 8.)

2.2.3 DIFF UP MODE
DIFF UP MODE encodes the difference between the current pixel and the pixel above it. It operates similarly to DIFF MODE and is used when DIFF MODE is inapplicable, striving to encode a pixel within one byte. (See Algorithm 9.)

2.2.4 LUMA MODE
LUMA MODE encodes pixels whose difference from the previous pixel is large. It exploits the property that the differences of the two channels relative to the first channel are often small, allowing compression of larger differences using two bytes. This mode is infrequently activated in typical pathology images. (See Algorithm 10.)

2.2.5 RG MODE
RG MODE encodes pixels when differences are too large for DIFF or LUMA MODE. It is the least frequently used mode in pathology images. (See Algorithm 11.)


2.3 LOCO-I context encoding
LOCO-I context encoding originates from the JPEG-LS image compression standard. This context-based predictive encoding estimates a pixel value using its neighbouring pixels to the left, top and top-left, and then encodes the resulting difference.
Applying LOCO-I encoding as a preprocessing step can further reduce spatial correlation, effectively “centring” pixel values and producing smaller residuals. When combined with our improved QOI algorithm, this preprocessing can lead to shorter encodings for certain images. The advantage arises because LOCO-I considers an additional top-left pixel, providing a slight spatial prediction improvement over our QOI-based encoding. (See Algorithm 13.)

2.4 Lossless compression algorithm for 8-bit three-channel images (QOI3JPEGLS)
We propose the QOI3JPEGLS lossless compression algorithm, which integrates LOCO-I encoding with QOI3 encoding. The algorithm first applies LOCO-I encoding to the image, followed by QOI3 encoding. Due to the losslessness and reversibility of both LOCO-I and QOI3, the combined QOI3JPEGLS algorithm is also fully lossless and reversible.
2.5 Lossless compression algorithm for 8-bit two-channel images (QOI2JPEGLS)
Similarly, we propose the QOI2JPEGLS algorithm, integrating LOCO-I encoding with QOI2 encoding. LOCO-I is applied first, followed by QOI2 encoding. The combination preserves the losslessness and reversibility of both components.
2.6 Parallelization algorithm
Parallelization is critical for fully exploiting hardware performance. Many traditional image compression algorithms do not parallelize effectively: some cannot be parallelized at all, while others support only limited parallelism. Our proposed algorithms support parallelization at every stage, maximizing computational efficiency, which is particularly important for large pathology images containing millions of pixels.
Recent 2025 work also explores parallel-friendly designs: SEEC employs ROI-guided multi-entropy coding while maintaining decode independence across tiles/regions [Reference Zheng, Ren and Li24], and WISE demonstrates WSI-scale tiling pipelines with high throughput on CPUs/GPUs [Reference Mao, Wang, Guan and Xue9]. Our decoupled DIFF UP mode and pixel traversal order provide a codec-level alternative to such region-conditioned approaches, enabling end-to-end parallelism without external semantic information.
Prior to our improvements, LOCO-I context encoding, three-channel 8-bit QOI and two-channel 8-bit QOI did not fully support parallelization. To enhance parallelizability, we introduced the following modifications.
-
(1) Removing INDEX encoding to broaden contextual dependencies.
-
(2) Optimizing pixel traversal order.
-
(3) Introducing DIFF UP MODE to decouple inter-row pixel dependencies during encoding and decoding.
Tables 7 and 8 illustrate the pixel traversal orders for parallel encoding and decoding, respectively.
Parallel encoding order (numbers indicate encoding sequence).

Parallel decoding order (numbers indicate decoding sequence).

3 Experimental results
3.1 Experimental design
Three-channel images: We compare the average compression ratios of traditional QOI, PNG, QOI3 and QOI3JPEGLS across constructed datasets, including screenshots, pathology images and landscape photography. Additionally, representative compression results for individual images in each category are presented.
Two-channel pathology images: We evaluate the average compression ratios of PNG (per-channel compression), QOI2 and QOI2JPEGLS on pathology images, accompanied by representative data for individual images.
Parallel performance: The parallel speed performance of each algorithm for both three-channel and two-channel image compression is compared across different numbers of threads (n) on the constructed datasets. Trends in parallel processing speed and scalability for the proposed compression algorithms are also analysed.
3.2 Definitions and metrics
3.2.1 Original image size
For 8-bit three-channel or two-channel images, the original image size is defined as
3.2.2 Compressed size (smaller is better)
Defined as the total number of encoded bytes after compression.
3.2.3 Compression ratio (smaller is better)
Defined as
$$ \begin{align*} \text{Compression Ratio } = \frac{\text{Compressed Size}}{\text{Original Image Size}} \times 100\%. \end{align*} $$
3.3 Comparison of three-channel images
Compression ratios for three-channel screenshots.

3.3.2 Landscape photography
(See Table 10.)
Compression ratios for three-channel pathology images.

3.3.3 Three-channel pathology images
(See Table 11.)
Average compression ratios for three-channel images.

3.3.4 Average compression ratios
(See Figure 3.)
3.4 Comparison of two-channel pathology images
(See Table 12.)
Compression ratios for two-channel pathology images.

3.4.1 Average compression ratios
These ratios for two-channel images are illustrated in Figure 4.
Average compression ratios for two-channel images.

3.5 Parallel speed comparison
The parallel efficiency of the proposed method was evaluated by comparing the compression speed under different numbers of threads. The specific speedup ratios are presented in Table 13 and the corresponding performance trend is illustrated in Figure 5. The results demonstrate favourable parallel scalability for all methods, with the QOI2JPEGLS and QOI3JPEGLS hybrids achieving the highest parallel efficiency at 8 threads.
Parallel performance across number of threads (n).

Impact of number of threads on compression speed.

3.6 Discussion of experimental results
The proposed QOI3 and QOI3JPEGLS algorithms consistently achieve superior compression ratios for both natural and pathology images compared with PNG and traditional QOI, although the advantage is less pronounced for screenshots. For two-channel pathology images, QOI2 and QOI2JPEGLS outperform PNG and per-channel compression approaches due to their consideration of inter-channel.
4 Conclusion
We have presented QOI3/QOI3JPEGLS (three-channel) and QOI2/QOI2 JPEGLS (two-channel) pathology codecs, which achieve superior lossless compression ratios on both natural and pathology images compared with PNG, baseline QOI and per-channel variants, while preserving the simplicity, determinism and end-to-end parallel scalability of QOI-style designs.
The proposed DIFF, DIFF UP and LUMA modes, together with the reordered traversal strategy, effectively eliminate serial dependencies and enable near-linear throughput scaling across CPU and GPU threads. When used with the reversible LOCO-I predictor, residual entropy is further reduced for specific content types without compromising parallelism or strict losslessness.
Future work will focus on enhancing the generality, efficiency and applicability of the codec family as follows.
-
(i) Bit-depth and channel generalization: extend encoding ranges and mode thresholds to higher bit-depth imagery (10/12/16-bit) and multi-channel formats (e.g. RGBA, multispectral/hyperspectral pathology) while maintaining reversible bitstreams.
-
(ii) Predictor and model exploration: investigate lightweight, parallelizable predictors beyond LOCO-I, such as CALIC-style adaptive contexts, to further reduce residual entropy without degrading decode parallelism.
-
(iii) Streaming and hardware acceleration: explore containerized bitstreams with chunked headers and per-tile restart markers for ROI decoding and low-latency streaming, alongside optimized SIMD/GPU/FPGA implementations to maximize practical throughput.
These directions aim to further improve the compression ratio–throughput trade-off, broaden applicability across medical and graphics domains, and ensure openness and reproducibility for future research and deployment.
Acknowledgements
This research was supported by the National Key Research and Development Program of China, Grant Number 2020YFA0712500; and the Research and Development Project of Pazhou Lab (Huangpu), Grant Number 2023K0601.





















