A simple image viewer built from scratch in C using SDL2. Loads and displays images from the current directory with various visual effects implemented through direct pixel manipulation.
Requires SDL2, SDL2_image, and SDL2_ttf installed on your system.
mkdir build
cd build
cmake ..
makeRun the program from a directory containing images.
./image_viewer| Key | Action |
|---|---|
← |
Previous image |
→ |
Next image |
F |
Toggle fill mode (stretch to window) |
I |
Toggle color inversion |
B |
Toggle blur effect |
M |
Toggle background color matching |
T |
Toggle filename display |
- Fit Mode (default): Scale image to fit window while maintaining aspect ratio
- Fill Mode: Stretch image to fill the entire window
All effects are implemented by directly accessing pixel memory and manipulating individual RGB channel bytes.
Inverts all colors in the image by subtracting each RGB channel value from 255.
Applies a box blur by sampling surrounding pixels in a configurable grid. For each pixel:
- Samples all neighboring pixels within the defined radius
- Applies a weight to each sample
- Averages the weighted values across all channels (R, G, B)
- Normalizes by the total weight to produce the final blurred pixel
The blur strength can be adjusted by modifying SURROUNDING_PIXELS (grid size) and BLUR_WEIGHT constants.
Analyzes the image to find the most common non-solid color and uses it as the background. The algorithm:
- Quantizes the color space from 256³ possible colors down to 8³ buckets (reducing each channel from 0-255 to 8 levels)
- Counts occurrences of each quantized color by mapping 3D color coordinates to a 1D array index
- Sorts colors by frequency
- Selects the most common color that isn't "solid" (where all RGB channels fall in the same bucket range)
- Falls back to the most common color if no non-solid colors exist
The color matching accuracy can be adjusted by modifying CHANNEL_BUCKET_SIZE constant.