A simple BMP image viewer written in C using SDL2.
This project demonstrates how BMP files are structured and how pixel data can be read and displayed without relying on external image libraries.
๐ The main goal is educational โ to help beginners understand the BMP file format and the process of rendering images pixel by pixel.
- Reads and displays 24-bit BMP images.
- Supports uncompressed BMP files (biCompression = 0).
- Command-line based โ just provide the image file path as an argument.
- Uses SDL2 for rendering pixels on the screen.
- Helps in learning file I/O, BMP headers, and image rendering basics.
BMP_Image_Viewer/
โโโ src/ # Source code
โ โโโ bmp_viewer.c
โโโ pictures/ # Sample BMP images for testing
โโโ README.md # Project documentation
To build and run this project, you need:
- GCC (or any C compiler)
- SDL2 library
Install SDL2 (Linux example):
sudo apt update
sudo apt install libsdl2-devCompile the project:
gcc src/bmp_viewer.c -o src/bmp_viewer -lSDL2Run the program with a BMP image:
src/bmp_viewer pictures/test_image.bmpSample BMP images are provided inside the pictures/ folder.
Try:
src/bmp_viewer pictures/sample1.bmp+----------------------+-----------------------------+
| Offset (Bytes) | Field |
+----------------------+-----------------------------+
| 0 - 1 | Signature ("BM") |
| 2 - 5 | File size |
| 6 - 9 | Reserved |
| 10 - 13 | Pixel data offset |
+----------------------+-----------------------------+
| 14 - 17 | DIB header size |
| 18 - 21 | Image width |
| 22 - 25 | Image height |
| 26 - 27 | Color planes (always 1) |
| 28 - 29 | Bits per pixel (24 in this) |
| 30 - 33 | Compression (0 = none) |
| 34 - 37 | Image size (may be 0) |
| ... | More header fields |
+----------------------+-----------------------------+
| Pixel Array | Actual pixel data (BGR) |
+----------------------+-----------------------------+
๐ In this project, we only handle:
- 24-bit images (
Bits per pixel = 24) - Uncompressed data (
Compression = 0)
- Supports only 24-bit BMP images.
- Works only with uncompressed BMP files (biCompression = 0).
- No GUI features โ runs from command line.
Planned features:
- Support for 32-bit BMP images.
- Support for different compression methods.
- Add image operations: rotate, crop, zoom.
- Cross-platform build scripts (Windows & Linux).
By studying this project, you will learn:
- How BMP headers are structured.
- How raw pixel data is stored in a file.
- How to use SDL2 for rendering images pixel by pixel.
- Basics of graphics programming in C.
Contributions are welcome!
You can:
- Fix bugs
- Add support for new BMP formats
- Improve documentation
- Suggest new features
This project is licensed under the MIT License โ feel free to use and modify it.