A simple, yet powerful C-based utility for applying geometric transformations to BMP images. This project was built with modular design in mind, making it easy to extend, maintain, and experiment with new image formats and transformations.
- Efficient handling of BMP files (24-bit format).
- Various transformation options:
- 🔄 Rotate 90° Clockwise (cw90)
- 🔄 Rotate 90° Counterclockwise (ccw90)
- 🔁 Horizontal Flip (fliph)
- 🔃 Vertical Flip (flipv)
- ➡️ No Transformation (none)
Run the utility using the following syntax in the terminal:
./image-transform <source-image> <transformed-image> <transformation>./image-transform input.bmp output.bmp cw90| Transformation | Description |
|---|---|
none |
No transformation; output = input |
cw90 |
Rotate the image 90° clockwise |
ccw90 |
Rotate the image 90° counterclockwise |
fliph |
Flip the image horizontally |
flipv |
Flip the image vertically |
The project adheres to modular architecture, dividing the responsibilities into different modules to ensure maintainability and extendability.
/solution
├── /src # Source files (C files)
├── /include # Header files (definitions and declarations)
├── /build # Compiled binaries
├── /tester # Test cases and example BMP images
The project uses CMake for its build system. Follow the instructions below to get started:
- CMake version 3.12 or higher
- A C compiler (GCC or Clang)
- Optional tools:
- AddressSanitizer (ASan), LeakSanitizer (LSan), and UndefinedBehaviorSanitizer (UBSan) for debugging.
- clang-tidy for static code analysis.
-
Clone the repository:
git clone https://github.com/yourusername/image-transform.git cd image-transform -
Generate the build files:
cmake -S . -B build -
Compile the project:
cmake --build build
-
Run the tests:
ctest --test-dir build
The project handles BMP images by interpreting their headers and pixel data using the following structures:
struct bmp_header {
uint16_t bfType;
uint32_t bfileSize;
uint32_t bfReserved;
uint32_t bOffBits;
uint32_t biSize;
uint32_t biWidth;
uint32_t biHeight;
uint16_t biPlanes;
uint16_t biBitCount;
uint32_t biCompression;
uint32_t biSizeImage;
uint32_t biXPelsPerMeter;
uint32_t biYPelsPerMeter;
uint32_t biClrUsed;
uint32_t biClrImportant;
} __attribute__((packed));Pixel Structure:
Each pixel is represented using 3 bytes for the blue, green, and red channels:
struct pixel {
uint8_t b, g, r;
};Transformations are applied to the image in memory using the following internal image representation:
struct image {
uint64_t width, height;
struct pixel* data;
};Examples of transformations include:
- Rotating the image by creating a new image with swapped dimensions.
- Flipping by rearranging pixel rows or columns.
Want to add more transformations or image formats? The project’s modular structure makes it simple:
-
New Image Formats:
Implement additional formats by adding new modules for deserialization and serialization, similar tofrom_bmpandto_bmp. -
New Transformations:
Add transformations by implementing functions that manipulate thestruct image.
Robust error handling ensures that:
- Memory allocation issues return appropriate error codes (e.g.,
ENOMEM). - File I/O errors are properly handled with warnings or termination.
To aid development, sanitizers are used to detect issues like memory leaks, buffer overflows, or uninitialized memory reads.
- ASan: Detects invalid memory access.
- LSan: Detects memory leaks.
- UBSan: Detects undefined behavior.
Test cases are provided in the tester/ directory. Use CTest to verify your implementation.
Contributions are welcome! Feel free to open issues or submit pull requests. To contribute, please:
- Fork the repository.
- Create a new branch (
git checkout -b feature-name). - Commit your changes (
git commit -m "Add feature"). - Push to the branch (
git push origin feature-name). - Open a pull request.
This pet project is not just about manipulating BMP images. It's an excellent opportunity to:
- Practice low-level programming in C.
- Learn modular design and code maintainability.
- Get hands-on experience with error handling, memory management, and testing tools.
Feel free to experiment, extend, and share your ideas! 😊