BGR Bitmap to RGB Bitmap Converter
Convert BGR-ordered BMP bitmap files to standard RGB channel order. Client-side binary pixel swap with header analysis and instant download.
Drop a .bmp file here or click to browse
Supports 24-bit and 32-bit uncompressed BMP files
About
BMP (Bitmap) files store pixel color channels in BGR order - Blue first, then Green, then Red - a legacy of the Windows GDI specification from 1990. Many image processing pipelines, particularly those using OpenCV or raw framebuffer data, output BGR-ordered bitmaps that display with inverted Red and Blue channels in software expecting standard RGB order. A portrait with natural skin tones rendered in BGR appears with blue-tinted faces and orange skies. This tool performs a precise binary-level channel swap on the pixel data array of .bmp files, converting each pixel triplet from BGR to RGB (or vice versa, since the operation is symmetric). It parses the BMP file header, DIB info header, and raw pixel buffer at the byte level without re-encoding or lossy compression.
The converter handles 24-bit and 32-bit uncompressed BMPs, correctly accounting for row padding to 4-byte boundaries and both top-down and bottom-up scanline orders. Note: compressed BMPs (RLE4, RLE8) and indexed-color formats (1/4/8-bit) are not supported because their pixel data is palette-referenced, not direct BGR triplets. All processing occurs entirely in your browser. No file data leaves your machine.
Formulas
The BGR to RGB conversion is a symmetric byte-swap operation applied to every pixel in the raw pixel data array. For a 24-bit BMP, each pixel occupies 3 consecutive bytes. The swap exchanges the first and third bytes while leaving the second unchanged.
For each pixel at byte offset i in the pixel data buffer:
R ← buffer[i] (was Blue)
buffer[i] ← buffer[i + 2] (Red moves to position 0)
buffer[i + 2] ← R (Blue moves to position 2)
Row stride (bytes per scanline including padding):
Where bpp = bits per pixel (24 or 32), w = image width in pixels. The pixel loop iterates row by row, advancing by stride bytes per row, and within each row processes w pixels spaced bpp8 bytes apart. Padding bytes at the end of each row are not modified. Since swapping byte 0 and byte 2 is its own inverse, the same operation converts RGB back to BGR. The function f(f(x)) = x - the transform is an involution.
Reference Data
| BMP Property | Location (Byte Offset) | Size | Description |
|---|---|---|---|
| Magic Bytes | 0x00 | 2 bytes | 0x42 0x4D ("BM" in ASCII) |
| File Size | 0x02 | 4 bytes | Total file size in bytes (LE uint32) |
| Reserved | 0x06 | 4 bytes | Application-specific; usually 0 |
| Pixel Data Offset | 0x0A | 4 bytes | Offset from file start to pixel array |
| DIB Header Size | 0x0E | 4 bytes | 40 = BITMAPINFOHEADER, 108 = V4, 124 = V5 |
| Image Width | 0x12 | 4 bytes | Width in pixels (signed int32) |
| Image Height | 0x16 | 4 bytes | Height in pixels (signed; negative = top-down) |
| Color Planes | 0x1A | 2 bytes | Must be 1 |
| Bits Per Pixel | 0x1C | 2 bytes | 24 (BGR) or 32 (BGRA) |
| Compression | 0x1E | 4 bytes | 0 = BI_RGB (none), 3 = BI_BITFIELDS |
| Raw Image Size | 0x22 | 4 bytes | Size of pixel data (may be 0 if uncompressed) |
| H Resolution | 0x26 | 4 bytes | Pixels per meter (horizontal) |
| V Resolution | 0x2A | 4 bytes | Pixels per meter (vertical) |
| Colors Used | 0x2E | 4 bytes | Number of palette colors (0 = default) |
| Important Colors | 0x32 | 4 bytes | Number of important colors (0 = all) |
| Row Padding | Calculated | Variable | Each row padded to 4-byte boundary |
| Scanline Order | Height sign | - | Positive height = bottom-up; Negative = top-down |
| Pixel Byte Order (24-bit) | Pixel offset | 3 bytes | Byte 0 = Blue, Byte 1 = Green, Byte 2 = Red |
| Pixel Byte Order (32-bit) | Pixel offset | 4 bytes | Byte 0 = Blue, Byte 1 = Green, Byte 2 = Red, Byte 3 = Alpha |