libjpeg is a free library with functions for handling the JPEG image data format. It implements a JPEG codec (encoding and decoding) 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 (BSD-like) free software license, which demands attribution.

The original variant is maintained and published by the Independent JPEG Group (IJG). 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

thumb|jpegtran transforms JPEG data without reencoding<br />(here with user interface CropGUI)

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:

  • optimisation of the Huffman coding layer of a JPEG file to increase compression,
  • conversion between progressive and sequential JPEG formats,
  • conversion between Huffman and arithmetic coding in the entropy coding layer.

Change in IJG leadership

After 11 years and a change in leadership, the IJG under Guido Vollbeding released new versions of libjpeg (7 through 9), of which each broke ABI compatibility with previous versions.

  • Scaled DCT
  • jpegtran extended to use SmartScale
  • Internal fixes

|-

|

| 2010-02-28

| RGBA

|-

|

| 2010-05-16

| Memory corruption & build fixes

|-

|

| 2011-01-16

| Option for selecting DCT block size (SmartScale)

|-

|

| 2012-01-15

| RGB JPEG (no color transform to YCbCr)

|-

|

| 2013-01-13

|

  • YCoCg color
  • Lossless compression (1x1 DCT)

|-

|

| 2014-01-19

|

  • "JFIFv2" scRGB Wide color gamut (standard unknown)
  • 8-12 bit color (standardJPEG)

|-

|

| 2016-01-17

|Computation improvements

|-

|

| 2018-01-14

|

|-

|

| 2020-01-12

|

  • Code cleanup
  • Huffman optimization
  • x64 support (MSVC)

|-

|

| 2022-01-16

|ARM and ARM64 support (MSVC)

|-

|

| 2024-01-14

|

  • ARM64EC support (MSVC)
  • Xcode build system
  • C++Builder/RAD Studio build system

|}

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

<!-- Q28515827 -->

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 Linux distributions (Fedora, Debian, Mageia, openSUSE, ...), Mozilla, and Chrome. 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.

Since 2019, libjpeg-turbo is one of the two JPEG reference implementations, available as ISO/IEC 10918-7 and ITU-T T.873. The other reference implementation is ISO libjpeg which also includes support for JPEG XT and JPEG LS.

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 (of about 10%) and therefore transmission time through improvement of coding efficiency while retaining image quality. To achieve this, it uses more processing power for the encoding (asymmetry) 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.

| latest release date =

In April 2024, Google introduced Jpegli, a new JPEG coding library that offers enhanced capabilities and a 35% compression ratio improvement at high quality compression settings, while the coding speed is comparable with MozJPEG.

ISO libjpeg

ISO/IEC Joint Photography Experts Group maintains a reference software implementation for base JPEG (ISO/IEC 10918-1 and 18477-1) and JPEG XT extensions (ISO/IEC 18477 Parts 2 and 6-9), as well as lossless JPEG-LS (ISO/IEC 14495). It also includes some of the optimizations of MozJPEG. Though also named libjpeg, it is not related to the source code provided by Independent JPEG Group (IJG) and does not support proprietary extensions introduced by IJG since 2007.

See also

  • Lossless editing
  • The Guetzli JPEG encoder

References

  • JPEG FAQs