Skip to content

YahiaJouini/image-viewer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SDL Image Viewer

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.

Preview

project preview

Building

Requires SDL2, SDL2_image, and SDL2_ttf installed on your system.

mkdir build
cd build
cmake ..
make

Usage

Run the program from a directory containing images.

./image_viewer

Controls

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

Features

Display Modes

  • Fit Mode (default): Scale image to fit window while maintaining aspect ratio
  • Fill Mode: Stretch image to fill the entire window

Visual Effects

All effects are implemented by directly accessing pixel memory and manipulating individual RGB channel bytes.

Color Inversion

Inverts all colors in the image by subtracting each RGB channel value from 255.

Blur Effect

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.

Background Color Matching

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.

About

A minimal image viewer built in C with real-time visual effects and basic image processing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors