Libjpeg


libjpeg is a free library with functions for handling the JPEG image data format. It implements a JPEG codec alongside various utilities for handling JPEG data.
It is written in C and distributed as free software together with its source code under the terms of a custom permissive free software license, which demands attribution.
The original variant is maintained and published by the Independent JPEG Group. Meanwhile, there are several forks with additional features.
JPEG JFIF images are widely used on the Web. The amount of compression can be adjusted to achieve the desired trade-off between file size and visual quality.

Utilities

The following utility programs are shipped together with libjpeg:
; cjpeg and djpeg: for performing conversions between JPEG and some other popular image file formats.
; rdjpgcom and wrjpgcom: for inserting and extracting textual comments in JPEG files.
; jpegtran: for transformation of existing JPEG files.

jpegtran

The command-line program jpegtran provides several features for reformatting and recoding the representation of the DCT coefficients, for transformation of actual image data and for discarding auxiliary data in JPEG files, respectively. The transformations regarding the representation of the coefficients comprise:
These transformations are each completely lossless and reversible. The transformations on the image data comprise:
These are lossless and reversible only regarding the image data that is kept. Reencoding with repeated lossy quantisation of the image data does not take place.
There is an associated Windows application, , which provides a user interface to jpegtran. For Unix-like systems like Linux there is the free with similar functionality.
More programs supporting JPEG lossless transformation functions based on the IJG code are given on the .

History

The JPEG implementation of the Independent JPEG Group was first publicly released on and has been considerably developed since that time.
The development was initially mainly done by Tom Lane.
The open-source implementation of the IJG was one of the major open-source packages and was key to the success of the JPEG standard. Many companies incorporated it into a variety of products such as image editors and web browsers.
For version 5, which was released on September 24, 1994, the whole code base was rewritten. It introduced the utility programs rdjpgcom and wrjpgcom for handling embedded text comments.
The version 6 from came with support for progressive JPEG and for the first time with the utility program jpegtran. This utility was extended with features to rotate and flip images and grayscale reduction in version 6b.
From version 6b of libjpeg of, Miyasaka Masaru forked a branch named libjpeg/SIMD, which included x86 SIMD optimisations. It got substantial contributions from the TigerVNC and the VirtualGL projects in 2009. On that basis the libjpeg-turbo project was created in 2010.
After 11 years and a change in leadership, the IJG released new versions of libjpeg, of which each broke ABI compatibility with previous versions. The changes that were held in prospect after the 6x series were not delivered.
In version 7, support for arithmetic coding was introduced, which earlier has been rejected because of the patent situation, as well as the crop feature in jpegtran.
Versions 8 and 9 served basically for the introduction of controversial incompatible format extensions. These are widely regarded as ineffective and inferior to existing, standardised solutions. Their standardisation was rejected after submission to the ITU-T. The original organiser Tom Lane and others criticize these changes as a break from the goals of the IJG.
On, the first version of the filesize-optimising fork mozjpeg was published. For this version Josh Aas from Mozilla Research reworked the Perl script jpegcrush from x264's main developer Loren Merritt and integrated it into the code base of libjpeg-turbo.
On, Mozilla released version 2.0, which mainly added trellis quantisation and is now able to reduce the size of baseline JPEGs also. Facebook, Inc. donated for the development of the next version, and CloudFlare assigned a developer for the improvement of mozjpeg.

Versions

Forks

Well-known forks are libjpeg-turbo, which optimises for speed of execution, and mozjpeg, which optimises for smaller file sizes.
There is also a [|similarly named library] from the ISO, which aims to be a complete implementation of JPEG, JPEG XT and JPEG-LS standards.

libjpeg-turbo

libjpeg-turbo is a fork of libjpeg that uses SIMD instructions to accelerate baseline JPEG encoding and decoding. Many projects are now using libjpeg-turbo instead of libjpeg, including popular GNU/Linux distributions, Mozilla, and Chrome. Apart from performance, some projects have chosen to use libjpeg-turbo because it allows them to retain backward ABI compatibility with the older libjpeg v6b release. libjpeg v7, v8 and v9 broke ABI compatibility with prior releases.
libjpeg-turbo can be configured to be compatible with the libjpeg v7 or v8 ABI, but it does not implement the complete set of features in recent IJG releases, including the SmartScale format extension. The libjpeg-turbo Project has chosen not to support SmartScale, citing concerns regarding the fact that it is not an ITU-T standard and citing their own research that questions the usefulness of the feature. By extension, since the only major new feature in libjpeg v9 is specific to the SmartScale format, the libjpeg-turbo Project has chosen to forgo emulating libjpeg v9. Therefore, SmartScale files created by libjpeg v8 and later will not be decompressed correctly by libjpeg-turbo.

mozjpeg

mozjpeg is a fork from libjpeg-turbo done by Josh Aas and others from Mozilla Research. It aims to speed up loading times of webpages by achieving a reduction in file size and therefore transmission time through improvement of coding efficiency while retaining image quality. To achieve this, it uses more processing power for the encoding while retaining full compatibility with the JPEG standard and requiring no changes on the decoder side.
The techniques mozjpeg uses to achieve high compression include optimising Huffman trees, using progressive coding to optimally split the spectrum of DCT coefficients into separate scans, and through the use of trellis quantisation. Additionally, the presets are aggressively tuned towards the minimisation of file sizes.
Besides libjpeg-turbo, mozjpeg also builds upon jpegcrush, a Perl script by Loren Merritt.

ISO libjpeg

ISO/IEC Joint Photography Experts Group maintains a reference software implementation for base JPEG and JPEG XT extensions, as well as lossless JPEG-LS. Though also named libjpeg, it is not related to the source code provided by Independent JPEG Group and does not support proprietary extensions introduced by IJG since 2007.