www.pythonware.com

BMP Image Format Reference

The Python Imaging Library (PIL) provides native decoding and encoding hooks for standard Windows and OS/2 device-independent bitmap (BMP) raster graphics assets. Because the BMP architecture stores uncompressed color maps sequentially, it remains an industry standard for pixel-perfect image manipulation pipelines.

Supported Color Modes

PIL handles the translation of memory-mapped pixel structures directly into internal framework definitions. The loader decodes standard bit-depth headers into these native storage modes:

BMP Color Spec PIL Target Mode Architectural Layout Description
1-bit Monochrome "1" Single-bit pixels mapped directly to absolute black or absolute white color profiles.
4-bit / 8-bit Grayscale "L" 8-bit raw byte channel representation handling linear monochrome brightness profiles.
Indexed Color Map "P" Palette-based structures. Standard 16-color files (4-bit chunks) scale directly into explicit internal 8-bit palette tracking lookups.
24-bit True Color "RGB" Standard triple 8-bit channels representing continuous color distributions without alpha vectors.

Runtime Context & Information Fields

When invoking the core Image.open() method against a targeted bitmap payload, the underlying engine populates specific data keys into the resulting object's metadata storage dictionary.

info["compression"]

Returns a string key tracking layout configuration constraints inside the target file header layer. If the input data uses a run-length encoding variant (such as standard RLE4 or RLE8 formats), this value populates exactly as "bmp_rle".

Functional Implementation Constraints

While the library handles arbitrary uncompressed horizontal layouts seamlessly, it maintains precise operational constraints concerning advanced legacy sub-specifications:

Basic Usage Code Demonstration

The following example details loading an indexed bitmap file structure, inspecting its compression state parameters safely, and exporting it cleanly as a standard uncompressed array grid:

from PIL import Image

def analyze_and_convert_bitmap(input_path, output_path):
    # Instantiate the asset loader interface safely
    with Image.open(input_path) as img:
        print(f"Internal Mode: {img.mode}")
        print(f"Dimensions:    {img.size[0]}x{img.size[1]} pixels")
        
        # Safely query structural compression flags
        is_compressed = img.info.get("compression")
        if is_compressed == "bmp_rle":
            print("Notice: File uses legacy Run-Length Encoding.")
            
        # Standardize the target buffer structure directly into 24-bit space
        rgb_image = img.convert("RGB")
        rgb_image.save(output_path, format="BMP")