Skip to content

A simple BMP image viewer written in C. It reads BMP files and displays them pixel by pixel without using external libraries, helping to understand the BMP file structure and image rendering process.

Notifications You must be signed in to change notification settings

Prashant-0409/BMP_Image_Viewer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ–ผ๏ธ BMP Image Viewer

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.


๐Ÿš€ Features

  • 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.

๐Ÿ“‚ Project Structure

BMP_Image_Viewer/
โ”‚โ”€โ”€ src/            # Source code
โ”‚    โ””โ”€โ”€ bmp_viewer.c
โ”‚โ”€โ”€ pictures/       # Sample BMP images for testing
โ”‚โ”€โ”€ README.md       # Project documentation

โš™๏ธ Requirements

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-dev

๐Ÿ› ๏ธ Build & Run

Compile the project:

gcc src/bmp_viewer.c -o src/bmp_viewer -lSDL2

Run the program with a BMP image:

src/bmp_viewer pictures/test_image.bmp

๐Ÿ–ผ๏ธ Example

Sample BMP images are provided inside the pictures/ folder.
Try:

src/bmp_viewer pictures/sample1.bmp

๐Ÿ“‘ BMP File Structure (Simplified)

+----------------------+-----------------------------+
| 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)

โš ๏ธ Current Limitations

  • Supports only 24-bit BMP images.
  • Works only with uncompressed BMP files (biCompression = 0).
  • No GUI features โ€“ runs from command line.

๐Ÿ”ฎ Future Improvements

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).

๐Ÿ“š Learning Outcome

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.

๐Ÿค Contributing

Contributions are welcome!
You can:

  • Fix bugs
  • Add support for new BMP formats
  • Improve documentation
  • Suggest new features

๐Ÿ“œ License

This project is licensed under the MIT License โ€“ feel free to use and modify it.


About

A simple BMP image viewer written in C. It reads BMP files and displays them pixel by pixel without using external libraries, helping to understand the BMP file structure and image rendering process.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages