JPEG(1)
πΈ NAME πΈ
jpeg β jpeg compressor π
π¦ SYNOPSIS π¦
jpeg [options] source target
β¨ DESCRIPTION β¨
Okay bestie, legal stuff first, don't skip it π
jpeg Copyright (C) 2012-2018 Thomas Richter, University of Stuttgart and Accusoft
For license conditions, see README.license for details. πβ¨
So here's the default vibe, no cap: if you do nothing else, it decodes the jpeg input and writes a ppm output. That's the baseline. Wanna force it into encoding mode instead? Hit it with -q [1..100] or -p and it'll switch gears. π₯
Now. The options. Buckle up buttercup, there are a LOT and they're all iconic in their own way π
-qquality β selects the encoding mode and defines the quality of the base image β¨-Qquality β defines the quality for the extension layer π-qualityq β use a profile and part specific weighting between base and extension layer quality π-rβ enable the residual codestream for HDR and lossless coding. This one needs-qand-Qto define the base and enhancement layer quality. π₯-r12β use a 12 bit residual image instead of an 8 bit residual image π-rlβ enforce an int-to-int lossless DCT in the residual domain, for lossless coding enabled by-Q 100π-roβ disable the DCT in the residual domain, and quantize spatially instead, for near-lossless coding π¦-ldrfile β specifies a separate file containing the base layer for encoding πΈ-Rbits β specify refinement bits for the base images. This works like-rbut in the DCT domain π-rRbits β specify refinement bits for the residual image β¨-Nβ enable noise shaping of the prediction residual π-Uβ disable automatic upsampling π-lβ enable lossless coding without a residual image by an int-to-int DCT. It also requires-cand-q 100for true lossless π-pβ JPEG lossless (predictive) mode. Also requires-cfor true lossless β¨-cβ disable the RGB to YCbCr decorrelation transformation π-xyzβ indicates that the HDR image is in the XYZ colorspace. Careful though: the image is not converted to this space, it's just assumed to be encoded in this space π¦-cxyzβ similar to the above, but it uses the dedicated C transformation to implement a XYZ colorspace conversion π₯-spβ use separate LUTs for each component β¨-mdβ use the median instead of the center of mass for constructing the inverse TMO of ISO/IEC 18477-7 profile C π-ctβ use the center of mass instead of the median for constructing the inverse TMO of ISO/IEC 18477-7 profile C π-smiter β use iter iterations to smooth out the histogram for inverse-TMO based algorithms. Default is not to smooth the histogram π«Ά-nclβ disable clamping of out-of-gamut colors. Heads up: this is automatically enabled for lossless π-mmaxerr β defines a maximum pixel error for JPEG LS coding πΈ-hβ optimize the Huffman tables β¨-aβ use arithmetic coding instead of Huffman coding. Available for all coding schemes (-p,-v,-land default) π-blβ force encoding in the baseline process; the default is extended sequential π-vβ use progressive instead of sequential encoding. Available for all coding schemes (-r,-a,-land default) π-qvβ use a simplified scan pattern for progressive that only separates AC from DC bands, and it may improve the performance π-dβ encode the DC band only (requires-p) β¨-ylevels β hierarchical JPEG coding with the given number of decomposition levels. If levels is zero, then a lossless coding mode for hierarchical is used, in which the second lossless scan encodes the DCT residuals of the first scan β and for that,-cis suggested for true lossless. If levels is one, then the lossy initial scan is downscaled by a power of two π¦-ggamma β define the exponent for the gamma for the LDR domain, or rather, for mapping HDR to LDR. A suggested value is2.4for mapping scRGB to sRBG. This option controls the base-nonlinearity that generates the HDR pre-cursor image from the LDR image. It is also used in the absence of-ldr(i.e. no LDR image) to tonemap the HDR input image. Use-g 0to use an approximate inverse TMO as base-nonlinearity, and for tonemapping with the Reinhard operator if the LDR image is missing π₯-gffile β define the inverse one-point L-nonlinearity on decoding from a file. That file contains one (ASCII encoded) digit per line,256*2^hlines in total, where h is the number of refinement bits. Each line contains an (integer) output value the corresponding input is mapped to π-zmcus β define the restart interval size; zero disables it β¨-nβ indicate the image height by a DNL marker π-sWxH,... β define subsampling factors for all components. Note that these are NOT MCU sizes. Default is1x1,1x1,1x1(444 subsampling), and1x1,2x2,2x2is the 420 subsampling often used πΈ-srWxH,... β define subsampling in the residual domain π¦-rsβ encode the residual image in sequential (rather than the modified residual) coding mode β¨-rvβ encode the residual image in progressive coding mode π-olβ open loop encoding: residuals are based on the original, not the reconstructed π-dzβ improved deadzone quantizer, may help to improve the R/D performance π₯-ozβ optimize quantizer, may help to improve the R/D performance π-drβ include the optional de-ringing (Gibbs Phenomenon) filter on encoding π-qtn β define the quantization table. The following tables are currently defined:n = 0β the example tables from Rec. ITU-T T.81 | ISO/IEC 10918-1 (default)n = 1β a completely flat table that should be PSNR-optimaln = 2β a MS-SSIM optimized tablen = 3β the table suggested by ImageMagickn = 4β a HSV-PSNR optimized tablen = 5β the table from Klein, Silverstein and Carney: Relevance of human vision to JPEG-DCT compression (1992)n = 6β the table from Watson, Taylor, Borthwick: DCTune perceptual optimization of compressed dental X-Rays (1997)n = 7β the table from Ahumada, Watson, Peterson: A visual detection model for DCT coefficient quantization (1993)n = 8β the table from Peterson, Ahumada and Watson: An improved detection model for DCT coefficient quantization (1993)
-qtffile β read the quantization steps from a file,64*2integers (luma & chroma) π-rqtn β defines the quantization table for the residual stream in the same way β¨-rqtffile β read the residual quantization steps from a file π-alfile β specifies a one-componentpgm/pfmfile that contains an alpha component, or that the code will write the alpha component to. And fr fr: this demo code DOES NOT implement compositing of alpha and background β οΈ-ammode β specifies the mode of the alpha:1(regular),2(premultiplied),3(matte-removal) π-abr,g,b β specifies the matte (background) color for mode 3 as an RGB triple π-arβ enable residual coding for the alpha channel; required if the alpha channel is larger than 8bpp β¨-ar12β use a 12 bit residual for the alpha channel πΈ-aRbits β set refinement bits in the alpha base codestream π¦-arRbits β set refinement bits in the residual alpha codestream π-aolβ enable open loop coding for the alpha channel π₯-adzβ enable the deadzone quantizer for the alpha channel π-aozβ enable the quantization optimization for the alpha channel π-adrβ include the de-ringing filter for the alpha channel π-allβ enable lossless DCT for alpha coding π-aloβ disable the DCT in the residual alpha channel, quantize spatially β¨-aqqu β specify a quality for the alpha base channel (usually the only one) π-aQqu β specify a quality for the alpha extension layer πΈ-aqtn β specify the quantization table for the alpha channel π-aqtffile β read the alpha quantization tables from a file π¦-arqtn β specify the quantization table for residual alpha π₯-arqtffile β read the residual alpha quantization tables from a file π-aqualityq β specify a combined quality for both π-raβ enable arithmetic coding for the residual image (NOT SPECIFIED) π-lsmode β encode in JPEG LS mode, where0is scan-interleaved,1is line interleaved and2is sample interleaved.
NOTE THAT THIS IS NOT CONFORMING TO REC. ITU-T T.81 | ISO/IEC 10918 BUT COMPLIANT TO REC. ITU-T T.87 | ISO/IEC 14495-1 (JPEG-LS) WHICH IS A DIFFERENT STANDARD.
Use -c to bypass the YCbCr color transformation for true lossless, and also use -c for decoding images encoded by the UBC reference software, as it does not write an indicator marker to disable the transformation itself. Note that the UBC implementation will not able to decode streams created by this software due to a limitation of the UBC code β the streams are nevertheless fully conforming πΈ
-clsβ Use a JPEG LS part-2 conforming pseudo-RCT color transformation.
Note that this transformation is only CONFORMING TO REC. ITU-T T.870 | ISO/IEC 14495-2 AND NOT CONFORMING TO REC. ITU-T T.81 | ISO/IEC 10918-1.
Works for near-lossless JPEG LS. DO NOT USE FOR LOSSY JPEG, it will also create artifacts π
π EXAMPLES π
okay bestie, this is the fun part β actual commands you can copy-paste π«Ά let's go one vibe at a time.
πΈ The classics
Standard JPEG compression, with 444 (aka "no") subsampling:
$ jpeg -q <quality> infile.ppm outfile.jpg
Standard JPEG compression, with 422 subsampling:
$ jpeg -q <quality> -s 1x1,2x2,2x2 infile.ppm outfile.jpg
π Intermediate dynamic range compression
i.e. compression of images of a bit-depth between 8 and 16 bits:
$ jpeg -r -q <base-quality> -Q <extension-quality> -h -r12 infile.ppm
outfile.jpg
This type of encoding uses a technology known as "residual scans" which increase the bit-depths in the spatial domain, and that whole thing is enabled by the -r command line switch. The -Q parameter sets the quality of the residual image. π
To improve the precision in the frequency domain, "refinement scans" can be used. The following encodes a 12-bit image with four additional refinement scans, enabled by the -R 4 parameter:
$ jpeg -q <quality> -R 4 -h infile.ppm outfile.jpg
Both technologies can be combined, and the precision of the residual scan can also be enlarged by using residual refinement scans with the -rR option. The following command line will use a 12-bit residual scan with four refinement scans:
$ jpeg -r -q <base-quality> -Q <extension-quality> -h -rR 4 infile.ppm
outfile.jpg
π High-dynamic range compression
High-dynamic range compression allows three different profiles of varying complexity and performance. The profiles are denoted by -profile <X> where <X> is a, b or c. The following encodes an HDR image in profile C:
$ jpeg -r -q <base-quality> -Q <extension-quality> -h -profile c -rR 4
infile.pfm outfile.jpg
HDR images here have to be fed into the command line in pfm format. exr or hdr is not supported as input format and requires conversion to pfm first. ngl pfm is basically the floating-point equivalent of ppm, and it encodes each pixel by three 32-bit floating point numbers. π¦
Encoding in profiles a and b works likewise, though it is generally advisable to use "open loop" rather than "closed loop" coding for these two profiles by additionally providing the -ol parameter. This also works for profile C:
$ jpeg -ol -r -profile a -q <base-quality> -Q <extension-quality> -h
infile.pfm out.jpg
similar for profile B.
What is common to profiles A and C is that you may optionally also specify the LDR image, i.e. the image that a legacy JPEG decoder will show. By default, a simple tone mapping algorithm ("global Reinhard") will be used to derive a suitable LDR image from the input image:
$ jpeg -ldr infile.ppm -q <base-quality> -Q <extension-quality> -h -rR 4
infile.pfm out.jpg
The profile is by default profile c, but it also works for profile a:
$ jpeg -ol profile a -ldr infile.ppm -q <base-quality> -Q <extension-
quality> infile.pfm out.jpg
It is in general advisable for profile c encoding to enable residual refinement scans, profiles a or b do not require them.
π Lossless coding, integer edition
The following options exist for lossless coding integer:
predictive Rec. ITU-T T.81 | ISO/IEC 10918-1 coding. Note, however, that not many implementations are capable of decoding such stream, thus this is probably not a good option for all-day purposes.
$ jpeg -p -c infile.ppm out.jpg
While the result is a valid Rec. ITU-T T.81 | ISO/IEC 10918-1 stream, most other implementations will hick up and break, thus it is not advisable to use it. π
bestie I'm serious, other decoders will literally just perish. don't do this to yourself unless you have a reason.
A second option for lossless coding is residual coding within profile c:
$ jpeg -q <quality> -Q 100 -h -r infile.ppm out.jpg
This also works for floating point coding. Note that lossless coding is enabled by setting the extension quality to 100.
$ jpeg -q <quality> -Q 100 -h -r infile.pfm out.jpg
However, this is only lossless for 16 bit input samples, i.e. there is a precision loss due to down-converting the 32-bit input to 16 bit. If samples are out of the 601 gamut, the problem also exists that clamping will happen. To avoid that, encode in the XYZ color space (profile C only, currently):
$ jpeg -xyz -q <quality> -Q 100 -h -r infile.pfm out.jpg
A second option for lossless integer coding is to use a lossless 1-1 DCT process. This is enabled with the -l command line option:
$ jpeg -l -q 100 -c infile.ppm out.jpg
Refinement scans can be used to increase the sample precision to up to 12 bits. The -c command line option disables the lossy color transformation. β¨
π§ JPEG LS
Additionally, this implementation also supports JPEG LS, which is outside of Rec. ITU-T T.81 | ISO/IEC 10918-1 and ISO/IEC 18477. For that, use the command line option -ls:
$ jpeg -ls -c infile.ppm out.jpg
The -c command line switch is necessary to disable the color transformation as JPEG LS typically encodes in RGB and not YCbCr space.
Optionally, you may specify the JPEG LS "near" parameter (maximum error) with the -m command line switch:
$ jpeg -ls -m 2 -c infile.ppm out.jpg
JPEG LS also specifies a lossless color transformation that is enabled with -cls:
$ jpeg -ls -cls infile.ppm out.jpg
π Alpha channels
To encode images with an alpha channel, specify the source image that contains the alpha channel with -al. The alpha channel is a one-component grey-scale image, either integer or floating point. The quality of the alpha channel is specified with -aq, that of the regular image with -q:
$ jpeg -al alpha.pgm -aq 80 -q 85 input.ppm output.jpg
Alpha channels can be larger than 8bpp or can be floating point. In both cases, residual coding is required. To enable residual coding in the alpha channel, use the -ar command line option. Similar to the regular image, where residual coding requires two parameters, -q for the base quality and -Q for the extension quality, an alpha channel that uses residual coding also requires a base and extension quality, the former is given by -aq, the latter with -aQ:
$ jpeg -ar -al alphahigh.pgm -q 85 -Q 90 -aq 80 -aQ 90 input.ppm out.jpg
The alpha channel can be encoded without loss if desired. For that, enable residual coding with -ar and specify an extension quality of 100:
$ jpeg -ar -al alphahigh.pgm -q 85 -Q 90 -aq 80 -aQ 100 input.ppm
out.jpg
The alpha channel can use the same technology extensions as the image, namely refinement scans in the base or extension image, or 12-bit residual images. The number of refinement scans is selected with -aR and -arR for the base and residual image, a 12-bit residual image is selected with -ar12.
π Decoding
Decoding is so much simpler, thank god:
$ jpeg infile.jpg out.ppm
or, for floating point images:
$ jpeg infile.jpg out.pfm
If you want to decode a JPEG LS image, then you may want to tell the decoder explicitly to disable the color transformation even though the corresponding marker signalling coding in RGB space is typically missing for JPEG LS:
$ jpeg -c infile.jpg out.ppm
If an alpha channel is included in the image, the decoder does not reconstruct this automatically, nor does it attempt to merge the alpha image into the file. Instead, it may optionally be instructed to write the alpha channel into a separate 1-component (grey-scale) file:
$ jpeg -al alpha.pgm infile.jpg outfile.ppm
The -al option for the decoder provides the target file for the alpha channel.
π AUTHOR
This manual page was written by Mathieu Malaterre <malat@debian.org> for the Debian GNU/Linux system (but may be used by others).
and that's a wrap bestie π«Ά this page is from fake version 1.71, dated June 2026 β go forth and encode responsibly, slay π
β¨
π¦ where this page comes from
- ubuntu stonking: libjpeg-tools 0.0~git20250815.25f7128-3 Β· GPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms