1. Definition
Bitmaps and pixel maps are digital representations of images where each pixel’s color value is stored in memory.
- Bitmap (BMP): A simple image format storing pixels in a grid, row by row.
- Pixel map (pixmap): A general term for any image representation that stores color values for each pixel.
Reading and writing refers to the process of importing image data into memory and exporting it from memory to storage or display.
2. Structure of Bitmaps
2.1 Bitmap Components
A standard bitmap image consists of:
-
Header
- Contains information like image width, height, color depth, and compression.
-
Color Table (optional)
- Used in indexed color bitmaps (e.g., 8-bit images).
- Maps pixel indices to actual RGB color values.
-
Pixel Data
- Stores the color information for each pixel.
- Usually stored row by row (bottom-to-top in BMP files).
2.2 Pixel Representation
3. Reading a Bitmap
To read a bitmap into memory:
- Open the file in binary mode.
- Read the header to get image dimensions and color depth.
- Read the color table (if indexed colors are used).
- Read pixel data into a 2D array or pixel buffer.
- Optional conversion to internal representation for processing.
open("image.bmp", "rb")
read header -> width, height, color depth
read color table (if exists)
for each row:
read pixel data into array
4. Writing a Bitmap
To write a bitmap from memory:
- Create a header with image size, width, height, and color depth.
- Write the header to the file.
- Write the color table (if indexed).
- Write the pixel data from memory row by row.
open("output.bmp", "wb")
write header
write color table (if needed)
for each row in pixel array:
write pixel data to file
5. Pixel Maps (Pixmaps)
-
A pixel map is similar to a bitmap but may use other formats like PNG, TIFF, or custom pixel buffers.
-
Reading/Writing pixel maps involves:
- Loading pixel values into memory
- Manipulating pixels
- Saving the modified pixels back to disk or display
6. Applications
- Image editing software (Photoshop, GIMP)
- Rendering engines for textures in 2D/3D graphics
- Graphics file conversion between formats
- Game development for sprites and textures
7. Summary Table
| Operation |
Purpose |
Key Steps |
| Reading bitmap |
Load image into memory |
Read header → Color table → Pixel data |
| Writing bitmap |
Save image from memory |
Create header → Write color table → Write pixel data |
| Pixel map |
General image buffer |
Store/modify pixels for rendering |
Key Points:
- Bitmaps/pixel maps store pixel-by-pixel color information.
- Reading involves loading header, color table, and pixels.
- Writing involves creating a file with proper header and pixel data.
- They are foundational for 2D graphics, textures, and image processing.