djpeg
Decompress JPEG images to other formats
SYNOPSIS
djpeg [options] [inputfile]
PARAMETERS
-scale N/D
Scale the output image by the given fraction (N divided by D), e.g., 1/2, 1/4, or 1/8. This allows for quick generation of thumbnail-sized images directly from the JPEG data.
-crop X,Y,W,H
Crop the output image to a specified rectangular region. X and Y define the top-left corner coordinates, while W and H define the width and height of the crop region.
-grayscale
Convert the decompressed output image to grayscale. This can reduce file size for formats that support it and simplify color processing.
-rgb
Output an RGB image, even if the input is grayscale. This is typically the default color output mode if not using -grayscale.
-colors N
Quantize the output image to at most N colors. This is useful for reducing color depth for display on limited palettes or for specific image processing needs.
-idct ALGORITHM
Specify the Inverse Discrete Cosine Transform (IDCT) algorithm to use for decompression. Common algorithms include float, ifast, islow, iaccurate, and optimized versions like sse2 or avx2 (if supported by the CPU and compiled library).
-fast
Use a faster, lower-quality IDCT method for quicker decompression. This is a shorthand for a specific -idct algorithm.
-perfect
Use a more precise IDCT method, aiming for higher quality but potentially slower decompression. This is often the default or implied by its absence.
-pnm
Output the image in PNM (Portable Anymap) format, specifically PPM (Portable Pixmap) for color, PGM (Portable Graymap) for grayscale, or PBM (Portable Bitmap) for monochrome. This is often the default output format.
-bmp
Output the image in BMP (Windows Bitmap) format.
-tga
Output the image in TGA (Truevision Targa) format.
-tiff
Output the image in TIFF (Tagged Image File Format). Note: This option requires libtiff support to be compiled into the underlying JPEG library.
-outfile file
Write the decompressed output to the specified file. If this option is omitted, djpeg writes to standard output (stdout).
-strict
Use strict compliance with the JPEG standard during decompression, which may cause it to reject some malformed or non-standard JPEG files.
-verbose
Enable verbose messages, providing more information about the decompression process, such as image dimensions, color space, and memory usage.
DESCRIPTION
The djpeg command is a command-line utility for decompressing JPEG (Joint Photographic Experts Group) image files. It is part of the Independent JPEG Group (IJG) JPEG library, commonly provided by libjpeg or libjpeg-turbo. Its primary function is to read a JPEG-compressed image and output it in a different, uncompressed, or less-compressed format suitable for viewing, editing, or further processing.
Common output formats include PPM (Portable Pixmap), PGM (Portable Graymap), PBM (Portable Bitmap), BMP (Windows Bitmap), and TGA (Truevision Targa). Depending on the compilation options of the underlying library, it might also support TIFF (Tagged Image File Format). djpeg provides various options for controlling the decompression process, such as scaling the output image, converting to grayscale, specifying color quantization, and choosing different Inverse Discrete Cosine Transform (IDCT) algorithms for speed or quality tradeoffs.
CAVEATS
The availability of certain output formats (e.g., TIFF) depends on how the underlying libjpeg or libjpeg-turbo library was compiled and whether necessary external libraries (like libtiff) were present. Large input files or high resolution images can consume significant amounts of memory during decompression, potentially leading to performance issues or out-of-memory errors on systems with limited RAM. While djpeg is generally robust, malformed or corrupted JPEG files might lead to errors, warnings, or unexpected output behavior.
STANDARD INPUT/OUTPUT USAGE
If no input file is specified, djpeg reads JPEG data from standard input (stdin). If the -outfile option is not used, it writes the decompressed image to standard output (stdout). This makes djpeg highly suitable for use in shell pipelines, allowing it to decompress images directly from another command's output or pass its output to another image processing utility (e.g., cat image.jpg | djpeg -pnm | convert - output.png
).
ERROR HANDLING AND EXIT STATUS
djpeg typically prints error messages and warnings to standard error (stderr) if it encounters issues during decompression, such as corrupted JPEG headers, unsupported features, or file access problems. Upon successful completion, it exits with a status code of 0. A non-zero exit status indicates that an error occurred during processing.
HISTORY
djpeg is a core utility from the Independent JPEG Group (IJG) software, which developed and maintained the original JPEG library since the early 1990s. Its development closely tracks the evolution of the libjpeg library, a foundational component for JPEG encoding and decoding across various applications and operating systems. More recently, projects like libjpeg-turbo have forked the original IJG code to provide highly optimized versions of the JPEG algorithms, often utilizing SIMD instructions (like SSE2, AVX2, NEON) for significantly faster decompression on modern processors. This has ensured djpeg remains a fast and widely used tool for JPEG decoding on contemporary systems.