IOCCC image by Matt Zucker

The International Obfuscated C Code Contest

2024/kurdyukov2 - Prize in art restoration

JPEG artifact removal

Author:

To build:

    make all

To use:

    ./prog < input.jpg > output.jpg
    # where the quality of input.jpg is less than 100

Try:

Using your favorite image viewing tool, look at gradient.png (the original), quality24.jpg, and restored.jpg. The difference is noticeable but subtle. To see it in detail, observe diff-histeq.png.

    ./try.sh

Alternate code:

If you have the jpegint.h include file from the libjpeg package, then you will be able to compile the alternate code.

Alternate build:

    make alt

NOTE: The above requires the jpegint.h include file.

Alternate use:

    ./prog.alt < input.jpg > output.jpg
    # where the quality of input.jpg is less than 100

Judges’ remarks:

We were able to guess the meaning of some magic numbers. Can you?

Author’s remarks:

JPEG artifact removal

This program removes compression artifacts from JPEG images using values from quantization tables. After completing its work, the program saves the image in a another JPEG file, but as saved with 100% quality (so output file is larger).

Notes

  1. The lost precision of the DCT coefficient values cannot be gotten out of nowhere. It’s an attempt to find values within possible ranges (defined by the quantization table), which will allow to produce smoother-looking image.

  2. If the image is saved several times with different quantization tables, the artifacts cannot be reduced, since the true range of possible coefficient values isn’t known. If you save with one quality (say 50%) and then with 100%, this code will do nothing.

  3. Don’t expect great results from images saved with extremely low quality (less than 25%). May look blurry.

  4. I written the code with respect of bits per sample set by libjpeg includes, but doesn’t test on something different than common 8 bits.

Alternative versions

Extra notes

This is an obfuscated version of JPEG Quant Smooth. The full version is heavily optimized using SIMD/OpenMP and has chroma scaling feature.

Inventory for 2024/kurdyukov2

Primary files

Secondary files


Jump to: top