[NAME]
jpeg \- jpeg compressor

[EXAMPLES]
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 which 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 with 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 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. pfm is the floating-point equivalent of ppm and 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.


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.

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.

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


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 is much simpler:

$ 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).
