BMP (.bmp)
0
Upvotes
3
Views
0
Downloads
1,181
Words
Description
BMP (.bmp) is a simple, uncompressed bitmap format; learn its headers, pixel storage, palettes, and row padding to read, write, or debug BMP images.
When to Use
help me understand BMP file structure | explain how BMP headers work | show BMP row padding example | read uncompressed BMP pixel data | compare BMP vs other image formats
Use Cases
Legacy image interchange with Windows apps | Study BMP headers and pixel storage for education | Use in embedded systems needing uncompressed data | Debug pixel arrays in 24/32-bit images
SKILL.md Content
---
name: bmp
description: "BMP (.bmp) is a simple, uncompressed bitmap format; learn its headers, pixel storage, palettes, and row padding to read, write, or debug BMP images."
metadata:
tags: "image-format, bitmap, bmp, uncompressed, palette, bitmap-headers, windows-legacy"
source: "https://skilldb.dev/skills/file-formats-skills/bmp"
pack: "file-formats-skills"
category: "Technology & Engineering"
---
# BMP (.bmp)
## When to use this skill
Use when the user says things like:
- "help me understand BMP file structure"
- "explain how BMP headers work"
- "show BMP row padding example"
- "read uncompressed BMP pixel data"
- "compare BMP vs other image formats"
You are a file format specialist with deep knowledge of the BMP image format, its header structures, pixel storage, and the scenarios where this uncompressed format is appropriate.
## Overview
BMP (Bitmap Image File) is a raster graphics format developed by Microsoft and IBM for use in Windows and OS/2 operating systems. It first appeared with Windows 2.0 in 1987. The format stores images as a grid of pixels with a straightforward header structure, making it one of the simplest image formats to read and write programmatically. BMP files are typically uncompressed, which means they preserve exact pixel data at the cost of very large file sizes. While rarely used for distribution or web delivery today, BMP remains relevant as an interchange format, for embedded systems, and as a learning tool for understanding image file structure.
## Technical Specifications
- **File extension(s):** `.bmp`, `.dib` (device-independent bitmap)
- **MIME type:** `image/bmp`, `image/x-bmp`
- **Compression type:** Typically none (uncompressed). Optional RLE4 and RLE8 run-length encoding for 4-bit and 8-bit images. BITMAPV4/V5 headers support JPEG and PNG compression within BMP containers (rarely used).
- **Color depth:** 1-bit (monochrome), 4-bit (16 colors), 8-bit (256 colors with palette), 16-bit (High Color, various channel layouts), 24-bit (True Color, 8 bits per channel), 32-bit (True Color + alpha or padding)
- **Max dimensions:** Limited by 32-bit signed integer for width and height (2,147,483,647 pixels per dimension), practically limited by available memory
- **Transparency:** 32-bit BMP supports an alpha channel (BITMAPV4HEADER or later), but support is inconsistent across applications
- **Metadata support:** Minimal. No EXIF, IPTC, or XMP. ICC color profiles supported in BITMAPV5HEADER.
- **Pixel order:** Bottom-up by default (first row in file is the bottom of the image). Top-down is indicated by a negative height value.
- **Row padding:** Each row is padded to a multiple of 4 bytes
## How to Work With It
### Opening & Viewing
BMP is universally supported on Windows and works in all major image viewers and editors across platforms. Web browsers support BMP display, though it is rarely used on the web.
### Creating & Editing
- **Windows Paint:** The classic BMP editor; saves BMP by default in older Windows versions
- **Any image editor:** Photoshop, GIMP, Paint.NET all support BMP read/write
- **Programming:** BMP's simple structure makes it an excellent format for learning image I/O. The header is a fixed-size struct followed by raw pixel data.
- **Header versions:** BITMAPINFOHEADER (40 bytes, most common), BITMAPV4HEADER (108 bytes, adds color space), BITMAPV5HEADER (124 bytes, adds ICC profiles)
### Converting To/From
- **To PNG:** `magick input.bmp output.png` (recommended for lossless size reduction)
- **To JPEG:** `magick input.bmp -quality 85 output.jpg`
- **From other formats:** `magick input.png output.bmp`
- **Python:** `from PIL import Image; Image.open("in.bmp").save("out.png")`
- **Batch convert:** `magick mogrify -format png *.bmp`
## Common Use Cases
- Windows system graphics and legacy application resources
- Embedded systems and microcontrollers (simple parsing, no decompression needed)
- Clipboard image transfer (Windows clipboard uses BMP/DIB internally)
- Learning and teaching image file format structure
- Intermediate format for image processing pipelines
- Scientific instrumentation output
- Situations requiring zero compression artifacts and simple I/O
## Pros & Cons
**Pros:**
- Extremely simple format structure (easy to read/write programmatically)
- No compression artifacts (exact pixel preservation when uncompressed)
- Universal Windows support
- Fast read/write (no compression/decompression overhead)
- Well-documented specification
- Good for embedded systems with limited processing power
**Cons:**
- Very large file sizes (a 1920x1080 24-bit BMP is ~6 MB vs ~200 KB JPEG)
- No useful metadata support (no EXIF, no XMP)
- Alpha channel support is inconsistent across applications
- Impractical for web use due to file size
- RLE compression is basic and rarely achieves meaningful reduction
- Bottom-up pixel order is counterintuitive and a common source of bugs
- No progressive/interlaced loading
## Compatibility
| Platform | Support |
|----------|---------|
| Windows | Native (first-class support) |
| macOS | Supported via Preview and image frameworks |
| Linux | Supported via ImageMagick, GIMP, most viewers |
| Web browsers | Supported but rarely used |
| Photoshop | Full support |
| GIMP | Full support |
| Embedded systems | Widely used due to simplicity |
## Practical Usage
### Embedded Systems and Microcontrollers
BMP is a natural fit for resource-constrained systems that lack the processing power or memory to decompress PNG or JPEG. Many microcontroller display libraries (e.g., Adafruit GFX, LVGL) include BMP parsers because the format requires almost no decompression logic — just read the header, skip to pixel data, and push bytes to the framebuffer.
### Clipboard and Screenshot Pipelines
Windows clipboard operations use DIB (Device-Independent Bitmap) internally. When you paste an image from the clipboard in a Windows application, you are working with BMP data. Automation scripts that capture and process clipboard images often encounter BMP as the native interchange format.
### Learning Image Format Internals
BMP is the best format for teaching image I/O because the structure is transparent. A minimal BMP parser in C or Python can be written in under 50 lines:
```python
import struct
with open("image.bmp", "rb") as f:
f.read(14) # skip file header
info = f.read(40) # BITMAPINFOHEADER
width, height = struct.unpack_from("<ii", info, 4)
f.seek(struct.unpack_from("<I", f.read(14), 10)[0]) # seek to pixel data offset
# pixel data is now BGR, bottom-up, rows padded to 4 bytes
```
### CI/CD and Test Fixtures
BMP files make excellent test fixtures for image-processing code because they are deterministic — no compression means byte-for-byte reproducibility. Comparing output against a known BMP reference image is trivial with a simple byte comparison.
## Anti-Patterns
**Using BMP for web delivery.** BMP files are enormous compared to PNG or WebP. A 1920x1080 24-bit BMP is approximately 6 MB; the same image as a PNG is typically under 1 MB. Never serve BMP over HTTP.
**Ignoring row padding.** Each BMP row must be padded to a 4-byte boundary. Forgetting this produces images with a characteristic diagonal skew. The padding per row is `(4 - (width * bytes_per_pixel) % 4) % 4`.
**Assuming top-down pixel order.** BMP stores rows bottom-up by default. Many custom parsers render the image upside down because they assume top-down order. Check the height field — a negative value indicates top-down storage.
**Storing alpha-channel images as BMP.** While 32-bit BMP technically supports alpha, most applications ignore the alpha channel or interpret the extra 8 bits as padding. Use PNG for any image that requires transparency.
**Using BMP as an archival format.** BMP lacks metadata (no EXIF, no ICC profiles, no XMP), making it unsuitable for long-term archival. Use TIFF or PNG with embedded metadata instead.
## Related Formats
- **PNG:** Lossless compressed alternative (always prefer PNG over BMP for file exchange)
- **TIFF:** Another uncompressed option with far richer metadata and professional features
- **PCX:** Legacy bitmap format from the DOS era, predecessor in some workflows
- **TGA:** Another simple uncompressed format, more common in game development
- **DIB:** Device-Independent Bitmap; the in-memory representation of BMP data on Windows
- **PPM/PGM/PBM:** Netpbm formats with similarly simple structure, used in Unix environments