Tiny and Obfuscated Image Decoder

The goal of this project was to write a very small C program generating a non trivial RGB image. It won the 2018 Obfuscated C Code Contest as the "most inflationary" entry. Here are the corresponding files.

This tiny C program outputs a 128x128 RGB image file to the standard output using the portable pixmap file format (PPM). The output looks like:

It contains the famous "Lena" image which is used in many image compression tests.

The uncompressed image is 12 times larger than the source code of the program which includes the image data and the complete decoder. The actual image data is 1220 byte long, which gives a compression ratio of 40. Using a JPEG-like algorithm would not be enough to reach this level of compression (the Lena image would be barely recognizable). So the algorithm is based on the latest advances in image compression. It includes the following features:

The image data is encoded to a C string with some tricks to make the best use of the IOCCC size constraints. The identifiers were shortened to a single letter to save space. No specific obfuscation was needed as the algorithms already have a significant complexity.

Those interested by the inner working of the program can read A Tour of the Tiny and Obfuscated Image Decoder by Andrew Kensler.

The DCT transform is based on integer coefficients to avoid rounding errors. However I had not enough space to precompute them in the IOCCC entry so they were computed each time with a floating point expression which explains most of the slowness of the decoding. With comments from László Papp and Alex Rhatushnyak I updated the program to precompute the inverse DCT coefficients: prog.c. The result is a much faster decoding while still complying with the IOCCC size constraints. As the original IOCCC entry, it can be compiled and run under Linux with:

gcc -O2 prog.c -o prog -lm
./prog > lena.ppm
Here is the corresponding deobfuscated version: ld.c, img.h.
Fabrice Bellard - https://bellard.org/