This program is a multi-threaded image processing tool designed to apply various filters to BMP images. It uses POSIX threads to parallelize the processing of image data for efficiency. The program supports multiple filter types, including grayscale, color shift, box blur, and a "Swiss cheese" effect.
- Multi-threaded Processing: Divides the image into sections processed independently by multiple threads.
- Supported Filters:
- Grayscale (
-f g
) - Color Shift (
-f s
with optional-r
,-g
,-b
for red, green, and blue shifts) - Box Blur (
-f b
) - Swiss Cheese Effect (
-f c
)
- Grayscale (
- BMP File Support: Reads and writes uncompressed BMP image files.
- Modular Design: Cleanly structured code for ease of maintenance and extension.
- Ensure you have a C compiler (e.g.,
gcc
) andmake
installed on your system. - Clone this repository:
git clone <repository-url> cd <repository-directory>
The program takes the following arguments:
./image_processor -i <input_file> -o <output_file> -f <filter> [-r <red_shift>] [-g <green_shift>] [-b <blue_shift>]
-i
: Input BMP file.-o
: Output BMP file.-f
: Filter type (b, g, s, or c).-r
,-g
,-b
: Optional red, green, and blue shift values for the color shift filter (-f
s).
Apply Grayscale Filter
./image_processor -i input.bmp -o output.bmp -f g
Apply Color Shift Filter
./image_processor -i input.bmp -o output.bmp -f s -r 255 -g 0 -b 100
Apply Box Blur Filter
./image_processor -i input.bmp -o output.bmp -f b
./image_processor -i input.bmp -o output.bmp -f c
-
Command-Line Parsing:
- The program reads user-provided arguments using
getopt
. - File paths, filter type, and optional RGB shift values are stored in a
ProgramOptions
structure.
- The program reads user-provided arguments using
-
Image Reading:
- BMP file headers (
BMP_Header
andDIB_Header
) are parsed to retrieve image metadata. - Pixel data is loaded into a dynamically allocated 2D array of
struct Pixel
.
- BMP file headers (
-
Multi-Threaded Processing:
- The image is divided into vertical sections, each assigned to a thread.
- Threads process their respective sections using the selected filter.
-
Filter Application:
- Grayscale: Converts each pixel to grayscale by calculating a weighted average of the RGB components.
- Color Shift: Adjusts RGB values based on user-specified shifts for red, green, and blue channels.
- Box Blur: Averages the RGB values of neighboring pixels within a kernel window to produce a blur effect.
- Swiss Cheese: Randomly applies black circular holes across the image to simulate a “cheese-like” appearance.
-
Image Writing:
- The program combines the results from all threads.
- The processed pixel data is written back to a new BMP file, preserving the original file’s metadata.