Primitive Texture Compression

Wednesday, February 5th, 2014

PTCX a very simple compressed image format that I designed in 2003 as part of my Vision 1.0 project. This format features a basic adaptive quantization scheme that is reasonably effective for low frequency texture information (e.g. grass and gravel), and supports a wide variety of pixel formats (and high quality alpha).

My goal for this project was simply to explore image quantization and create something similar to the DirectX Texture Compression (DXT/S3TC) formats but with significantly greater flexibility (albeit without hardware support!). I dug PTCX up the other day and decided to see how it performed against the Lena test image.

For more information about the design of PTCX check out its project page.


The source image (a) is simply the Lena test image, scaled to 256x256. In raw uncompressed format (R8G8B8), this image is 196 KB. When converted to PNG with default settings, the image is 105 KB.

Test Image

PTCX adapts the quantization block size and the range evaluation function based on the source data. The second image (b) shows PTCX's quantization plan for the image both in terms of block size and evaluation kernel. The larger blocks in this image indicate regions of relative calm or low frequency data, and the encoding process will use larger block sizes to trade minimal quantization error for significant compression efficiency.

The third image (c) is simply our quantization plan superimposed on the Lena image. Notice how PTCX selects smaller block sizes along the border of her hat and eyes, where there are large and abrupt changes in pixel data.


By adjusting the quantization step size, the maximum macroblock size, and our quality value, we can drastically affect the performance of PTCX. The following images illustrate the results of a few different configurations. For clarity, I've placed the native output image (256x256) alongside an upscaled version (512x512).

The first image (below) uses the highest quality settings for PTCX. A maximum macroblock size of 2x2 with a quality level of 4. At this setting, the distortion introduced by the quantizer is extremely low and visually difficult to detect.

Test Image

At quality 3 the maximum macroblock size of 4x4 matches that of DXT, but we're using a larger quantization step value. This quality level has introduced clearly visible distortion versus quality 4, but this error seems acceptable given the significantly reduced file size.

Test Image

At quality 1, the lowest quality setting for PTCX, the output now contains banding and general block errors over almost the entire image. If the data within a block has a high variance and low repetition, then the quantization error will be high. For this reason, PTCX is mostly suited for compression of game textures such as grass and gravel, rather than faces and text.

Test Image

Returning back to quality 4 but reducing the quantization step precision to two bits and increasing the maximum macroblock size results in a 41 KB image that contains significant quantization error. Most areas that contain smooth gradients in the source image are represented with step-wise banding artifacts in the output.

Test Image

Just for kicks, this is the result of reducing all quality settings to their lowest values: quality of 1, a large macroblock maximum size (64), and low quantization step bit precision.

Test Image


PTCX performs a simple quantization of image data and produces a usable compression ratio of around 4:1. As one might expect, its PSNR is significantly worse than existing alternatives such as PNG and JPG, and so the practical utility of PTCX is limited.

The following table summarizes the PTCX settings tested for this post:

Block SizesQuant BitsQualityFile Size
2x244100 KB
4x4, 2x24353 KB
8x8, 4x4, 2x24244 KB
16x16, 8x8, 4x44138 KB
2x22484 KB
8x8, 4x4, 2x22441 KB
64x64, 32x32, 16x162117 KB

For more information including source code, check out the project page.