Skip to content

rordenlab/nanojpeg

Repository files navigation

NanoJPEG: a compact JPEG decoder

NanoJPEG is a compact but comprehensive library for reading classic baseline images. Baseline images are described by ISO/IEC 10918-1 T.81 and use discrete cosine transforms (DCT) and have their signature is the Start Of Frame marker 0xFFC0. This repository extends this library to support the Lossless (sequential) format with the signature 0xFFC3. This format is described in Annex H ("Lossless mode of operation") of the standard and use Huffman tables for compression. While the original code only supports 8-bit precision, this project supports both 8 and 16-bit lossless data. This is useful, as this format and precision is popular with DICOM medical images, in particular transfer syntaxes 1.2.840.10008.1.2.4.57 and 1.2.840.10008.1.2.4.70.

Usage

While nanojpeg is intended to be as a library, the compiler directive _NJ_EXAMPLE_PROGRAM will create a minimal standalone executable. This is a terrific way to understand and extend the library. However, this minimal tool only saves data in the archaic but simple ppm format.

make
./nanojpeg lossyRGB.jpg lossyRGB.ppm
./nanojpeg losslessRGB.jpg losslessRGB.ppm
./nanojpeg lossless8.jpg lossless8.pgm 
./nanojpeg lossless16.jpg lossless16.pgm

Alternative

The jpg_0XC3 folder contains an alternative library, which only supports the lossless style 0xFFC3. This dedicated library is about 15% faster for 16-bit decoding, presumably because it uses a fast prefix lookup for the Huffman tables.

make
./jpg_0XC3 ../losslessRGB.jpg losslessRGB.ppm
./jpg_0XC3 ../lossless8.jpg lossless8.pgm 
./jpg_0XC3 ../lossless16.jpg lossless16.pgm

About

a compact JPEG decoder

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published