rgb3toppm
Convert RGB image files to PPM format
TLDR
Combine three PGM images (representing red, green and blue color components) into one PPM image
SYNOPSIS
rgb3toppm [ -verbose ] [ -alpha | -alphafile alpha_filename ] [ -gamma gamma_value ] [ width height ]
PARAMETERS
-verbose
Prints verbose messages during the conversion process, providing details about the input and output.
-alpha
Instructs rgb3toppm to expect 4-byte (RGBA) input per pixel. The output will be a Netpbm PAM image, which supports an alpha channel.
-alphafile alpha_filename
Reads the alpha channel data from the specified alpha_filename. The main input stream (typically stdin) must contain 3-byte (RGB) pixel data.
-gamma gamma_value
Applies gamma correction to the image pixels using the specified gamma_value. The value is a floating-point number.
width
The width of the input image in pixels. This is a required argument if the command cannot infer the dimensions from the input stream's length.
height
The height of the input image in pixels. This is a required argument if the command cannot infer the dimensions from the input stream's length.
DESCRIPTION
rgb3toppm is a utility from the Netpbm suite designed to convert raw RGB pixel data streams into a portable pixmap (PPM) image format. It reads uncompressed, byte-stream pixel data, typically from standard input, and writes the formatted PPM image to standard output.
The standard input is expected to be a sequence of 3 bytes per pixel (Red, Green, Blue) in that order. If the -alpha option is used, it expects 4 bytes per pixel (Red, Green, Blue, Alpha) and outputs a PAM (Portable Arbitrary Map) image, which is Netpbm's format for handling images with arbitrary planes, including alpha channels. Alternatively, the -alphafile option allows reading the alpha channel from a separate file while the main input remains 3-byte RGB.
This command is highly valuable in scripting and pipelines, enabling conversion of custom or exotic raw image data into a widely compatible and easily manipulable format within the Netpbm ecosystem or for further conversion to other standard image formats like JPEG, PNG, or GIF.
CAVEATS
Input data must be raw, uncompressed pixel streams; no image headers (like PNG, JPEG, or TIFF headers) are supported.
The command assumes a strict byte order of R, G, B for 3-byte input, or R, G, B, A for 4-byte input.
If the input stream length does not explicitly define the image dimensions (e.g., from a pipe where EOF signifies the end), width and height must be provided as command-line arguments.
STANDARD INPUT/OUTPUT
By default, rgb3toppm processes data from standard input and writes the resulting PPM or PAM image to standard output. This design makes it exceptionally suitable for use in Unix pipes, allowing it to easily integrate with other commands for complex image processing workflows.
PPM VS. PAM OUTPUT
While its name implies PPM output, when the -alpha option is used, rgb3toppm produces a PAM (Portable Arbitrary Map) file. PAM is a more general Netpbm format that can handle images with multiple planes, making it suitable for representing images with an alpha channel or other arbitrary data channels beyond basic color components.
HISTORY
rgb3toppm is an integral part of the Netpbm project, a comprehensive suite of graphics manipulation tools that originated in the early days of Unix. Netpbm tools are known for their simplicity, adherence to the Unix philosophy of small, single-purpose utilities that can be chained together, and their stable, long-standing development history.