ppmtobmp
Convert PPM image to BMP image
TLDR
Convert a PPM image to a BMP file
Explicitly specify whether or not a Windows BMP file or an OS/2 BMP file should be created
Use a specific number of bits for each pixel
SYNOPSIS
ppmtobmp [options] [ppmfile]
PARAMETERS
-b
Outputs a 1-bit per pixel (monochrome) BMP image.
-1, -2, -4, -8
Specifies an indexed color BMP output with 1, 2, 4, or 8 bits per pixel respectively. The color palette will be generated or specified by -map.
-24
Outputs a 24-bit per pixel (true color) BMP image without an alpha channel.
-32
Outputs a 32-bit per pixel BMP image. By default, this implies -alpha unless explicitly denied.
-alpha
Creates a 32-bit BMP with an alpha channel. This option is only relevant when using -32.
-map colormapfile
Uses the specified PPM file as the color map for indexed color output (e.g., with -8). The input PPM's maxval must match the colormap file's maxval.
-clump
Applies a special quantization method that clumps similar colors together before mapping to a reduced color palette.
-force
Forces the output of BMP types that might not be fully compliant with standard BMP specifications or may cause issues with some readers. Use with caution.
-noforce
The default behavior, which prevents the output of potentially non-compliant BMP files.
-colorcount N
Specifies the maximum number of colors to use for indexed color images. The default is 256. Valid for 1, 2, 4, and 8-bit output modes.
-rowbytes N
Pads each row of the BMP image to a total of N bytes. This is primarily useful for debugging specific BMP reader implementations.
-compression N
Specifies the compression type for the output BMP. Supported values include:
0: BI_RGB (no compression, default for non-indexed)
1: BI_RLE8 (8-bit Run-Length Encoding)
2: BI_RLE4 (4-bit Run-Length Encoding)
3: BI_BITFIELDS (custom masks, typically used with -32)
4: BI_JPEG (JPEG compression embedding)
5: BI_PNG (PNG compression embedding)
Note that not all combinations of bit depth and compression are valid or fully supported.
-verbose
Prints informative messages about the conversion process to standard error.
-debug
Prints detailed debugging information during the conversion process.
DESCRIPTION
The ppmtobmp command is a utility from the Netpbm image processing toolkit. It reads a Portable Pixmap (PPM) image from standard input (or a specified file) and converts it into a Windows Bitmap (BMP) file, outputting to standard output. It supports various BMP bit depths (1, 2, 4, 8, 24, 32 bits per pixel) and can apply different compression methods. This tool is essential for converting between Netpbm's flexible formats and the widely used BMP format, often required for compatibility with Windows applications.
CAVEATS
Older versions of ppmtobmp only supported BI_RGB (uncompressed) output. BMP images with alpha channels (created with -alpha and -32) are considered non-standard and may not be supported by all image viewers or applications. Run-Length Encoding (RLE) compression in BMP is often inefficient and has limitations on the image content it can effectively compress. Embedded JPEG or PNG compression (via -compression 4 or 5) is specific to certain BMP versions and may not be universally compatible.
INPUT/OUTPUT
The command reads a PPM image from standard input if no ppmfile argument is provided. The resulting BMP image is written to standard output. This design allows for easy piping with other Netpbm commands.
BIT DEPTH AND COLOR HANDLING
ppmtobmp automatically quantizes colors when converting to indexed color formats (1, 2, 4, or 8-bit). For 24-bit and 32-bit output, it attempts to preserve full color information. The -map option allows precise control over the color palette for indexed output, while -colorcount limits the number of colors in the palette.
HISTORY
The ppmtobmp command is part of the Netpbm project, a long-standing and widely used toolkit for graphic file format conversion and manipulation. Netpbm originated from the Pbmplus package developed in the late 1980s by Jef Poskanzer. Over the decades, it has evolved into a robust collection of tools, including ppmtobmp, which was developed to facilitate interoperability between the flexible Netpbm formats and the prevalent Windows Bitmap standard, continually adapting to new BMP features like alpha channels and embedded compression.