LinuxCommandLibrary

bmptopbm

Convert BMP to PBM image format

SYNOPSIS

bmptopbm [options] [filename]
bmptopbm [options] < input.bmp > output.pbm_or_pgm

PARAMETERS

-2
    Forces the output PGM file (when input is color/grayscale) to have a maxval of 3, implying 2 bits per pixel.

-4
    Forces the output PGM file (when input is color/grayscale) to have a maxval of 15, implying 4 bits per pixel.

-8
    Forces the output PGM file (when input is color/grayscale) to have a maxval of 255, implying 8 bits per pixel (this is the default).

-alphacolor color
    Specifies a color (e.g., red, blue, #RRGGBB) to be used for transparent pixels if no alpha output file is specified with -alphaout.

-alphaout={alpha-filename|DISCARD}
    Extracts the alpha channel from the BMP to a separate PGM file named alpha-filename. If DISCARD is specified, the alpha channel is ignored.

-imagetype={type}
    Forces bmptopbm to interpret the BMP file as a specific type, which can be useful for malformed or ambiguous BMPs. Supported types depend on the Netpbm version.

-mapfile=map-filename
    Uses the colors in the specified map-filename (a Netpbm image file) to quantize the input image's colors.

-truecolor
    Forces bmptopbm to interpret 16-bit and 32-bit BMP files as truecolor images, even if they appear to be palette-based.

-verbose
    Prints informative messages about the conversion process to standard error.

--help
    Displays a brief help message and exits.

--version
    Displays the version information of the Netpbm package and exits.

DESCRIPTION

bmptopbm is a utility from the Netpbm package designed to convert Microsoft Windows bitmap (BMP) files into Netpbm formats. Despite its name, which implies output only to Portable Bitmap (PBM) format, bmptopbm intelligently produces either a PBM or a Portable Graymap (PGM) file depending on the input BMP's content.

If the input BMP file is black and white, the command generates a PBM file, which represents a binary image. However, if the BMP contains color or grayscale data, bmptopbm converts it into a PGM file. This conversion typically involves transforming color or grayscale information into a grayscale representation, often with a default maximum pixel value of 255.

The command supports various BMP formats, including uncompressed and run-length encoded types, as well as different bit depths (1, 4, 8, 16, 24, 32-bit). It can read BMP data from standard input if no filename is specified, and by default, writes the resulting PBM or PGM image to standard output. Options allow for fine-tuning the conversion, such as handling alpha channels, forcing specific output bit depths for PGM, and verbose reporting.

CAVEATS

The command's name, bmptopbm, can be misleading. While it always handles BMP input, it produces a Portable Graymap (PGM) file when the input BMP contains color or grayscale information, and only produces a Portable Bitmap (PBM) file if the input is strictly black and white. It cannot handle very old OS/2 Presentation Manager 1.x BMP formats.

OUTPUT FORMAT DETERMINATION

bmptopbm automatically determines the output Netpbm format. It produces a PBM file for purely black and white BMPs and a PGM file for color or grayscale BMPs. The output maxval for PGM files is 255 by default but can be changed using the -2, -4, or -8 options.

STANDARD INPUT/OUTPUT

If no input filename is provided, bmptopbm reads the BMP data from standard input. The converted image output is written to standard output unless redirected to a file. This allows for piping operations within shell scripts.

HISTORY

bmptopbm is an integral part of the Netpbm project, a toolkit for manipulating graphic images that originated in the early 1990s. As a foundational converter within the suite, its development has evolved with the Netpbm standard, ensuring compatibility with various BMP formats and contributing to the suite's robust image conversion capabilities.

SEE ALSO

pbm(5), pgm(5), ppm(5), bmptopnm(1), netpbm(1), pnmtopbm(1)

Copied to clipboard