This library provides functionalities for manipulating BMP images. It allows forbasic image operations such as:saving and editing images, inserting one image into another, setting brush properties, and drawing shapes including dots, lines, rectangles, and triangles.
The BMP image format is characterized by its simplicity and comprises mainly two parts: afile header and an info header, followed by the actualpixel data (bitmap).
File Header (bmp_fileheader
)
- Signature:
2
bytes ('B'
and'M'
in ASCII) indicating the BMP file format. - File Size:
4
bytes representing thetotal size of the file. - Reserved:
4
bytes (2 fields of2
bytes each) unused and application-specific. - Image Data Offset:
4
bytes specifying theoffset to the start of the image data (pixel matrix).
Info Header (bmp_infoheader
)
- Size:
4
bytes indicating thesize of the info header, fixed at40 bytes. - Width:
4
bytes for the width of the image (number of columns). - Height:
4
bytes for the height of the image (number of rows). - Planes:
2
bytes set to the fixed value of1
. - Bit Count:
2
bytes for thenumber of bits per pixel, always set to24
in this project, meaning each pixel is represented by3
bytes (RGB channels). - Compression:
4
bytes for thetype of compression, which will be0
(no compression). - Image Size:
4
bytes referring to thesize of the pixel matrix, includingany added padding. - X Pixels Per Meter:
4
bytes for thehorizontal print resolution, set to0
for simplification. - Y Pixels Per Meter:
4
bytes for thevertical print resolution, also set to0
. - Colors Used:
4
bytes for thenumber of colors in the color palette, set to0
(not used in this project). - Colors Important:
4
bytes for thenumber of important colors, set to0
, implyingall colors are important.
The pixel data is stored in a matrix ofheight x width
, butmay include padding at the end of each row to ensure that each line starts at a4
-byte boundary. This padding should be ignored during reading and explicitly set to0
during writing.Note: thepixel data is stored in reverse order, with the first row of the matrix actually representing the bottom line of the image. The color channels for each pixel are inBGR (Blue, Green, Red) order.
SAVE (char *file, BMP *bmp)
: Saves the modified BMP image to a file.EDIT (char *file, BMP *bmp)
: Loads a BMP image from a file, allowing it to be edited or manipulated.INSERT (char *file, BMP *bmp, int y, int x)
: Inserts another BMP image into the current BMP structure at the specified position.FILL (BMP *bmp, int y, int x)
: Fills an area of the BMP image with the current brush color, starting from the specified coordinates.SET_COLOR (BMP *bmp, u_int8_t R, u_int8_t G, u_int8_t B)
: Sets the brush color in the BMP image for subsequent drawing or filling operations.SET_LINE (BMP *bmp, u_int8_t brush_size)
: Sets the brush size for drawing operations on the BMP image.
DOT (BMP *bmp, int y1, int x1)
: Draws a dot at the specified coordinates on the BMP image, using the currently set brush size and color.LINE (BMP *bmp, int y1, int x1, int y2, int x2)
: Draws a line between two points on the BMP image, using the currently set brush size and color.RECTANGLE (BMP *bmp, int y1, int x1, int width, int height)
: Purpose: Draws a filled rectangle on the BMP image, using the currently set brush color.TRIANGLE (BMP *bmp, int y1, int x1, int y2, int x2, int y3, int x3)
: Draws a filled triangle on the BMP image, connecting three specified points with the currently set brush color.
- Navigate to the
build
directory. - Run the
make
command to build the executable.
TheMakefile
provided will compile the source files and link them with the necessary libraries.
After building the project, you can run the program with the shell scripttemple_run.sh
to execute the program. This script sets up the necessary environment and arguments for the program to run the test suite.
./bmp_run.sh ............................Basic Commands......................... Test 0.......................................................passed Test valgrind................................................passed ............................Insert Image........................... Test 0.......................................................passed Test valgrind................................................passed Test 1.......................................................passed Test valgrind................................................passed Test 2.......................................................passed Test valgrind................................................passed Test 3.......................................................passed Test valgrind................................................passed Test 4.......................................................passed Test valgrind................................................passed ............................Draw Commands.......................... Test 0.......................................................passed Test valgrind................................................passed Test 1.......................................................passed Test valgrind................................................passed Test 2.......................................................passed Test valgrind................................................passed Test 3.......................................................passed Test valgrind................................................passed ............................Fill Color............................. Test 0.......................................................passed Test valgrind................................................passed Test 1.......................................................passed Test valgrind................................................passed Test 2.......................................................passed Test valgrind................................................passed ............................Mix Commands........................... Test 0.......................................................passed Test valgrind................................................passed Test 1.......................................................passed Test valgrind................................................passed Test 2.......................................................passed Test valgrind................................................passed Test 3.......................................................passed Test valgrind................................................passed Test 4.......................................................passed Test valgrind................................................passed