<<<<<<< HEAD
A lightweight image viewer written in C that renders binary PPM (P6) images using SDL2.
PixView is a minimal graphics application built to explore image parsing, raster rendering, and event-driven programming in C. It reads binary PPM (P6) images from standard input, decodes their pixel data, and displays them in an SDL2 window.
The project demonstrates the fundamentals of graphics programming while maintaining a compact and easily understandable codebase.
- Binary PPM (P6) image support
- SDL2-based rendering
- Standard input image streaming
- Lightweight implementation in C
- Event-driven window management
- Portable and easy to build
Screenshot or GIF goes here.
| Component | Technology |
|---|---|
| Language | C |
| Graphics Library | SDL2 |
| Image Format | Binary PPM (P6) |
- GCC or Clang
- SDL2 development libraries
Ubuntu/Debian
sudo apt install libsdl2-devA small C image viewer that reads a binary PPM (P6) image from standard input and displays it in an SDL2 window.
- Reads RGB pixel data from a
P6PPM stream. - Creates a window sized to the input image.
- Renders the image with SDL2 and keeps the window open until it is closed.
- Works with files, pipelines, and generated PPM output.
- A C compiler such as GCC or Clang.
- SDL2 development libraries and headers.
- A desktop environment capable of opening an SDL2 window.
Debian or Ubuntu:
sudo apt-get update
sudo apt-get install build-essential libsdl2-devmacOS with Homebrew:
7320844 (Rewrite README for Image Viewer)
brew install sdl2======= Windows users can install SDL2 through MSYS2 or download the development libraries from SDL's website.
7320844 (Rewrite README for Image Viewer)
Compile the viewer from the repository root:
<<<<<<< HEAD
gcc image_viewer.c -o pixview -lSDL2Run the viewer by piping a binary PPM image into standard input.
./pixview < image.ppmOr generate a PPM image dynamically using ImageMagick.
convert input.jpg ppm:- | ./pixviewPixView performs the following steps:
- Parses the PPM header.
- Reads the image dimensions.
- Loads RGB pixel data.
- Creates an SDL2 window.
- Renders each pixel.
- Processes window events until exit.
PixView/
│
├── image_viewer.c
├── README.md
└── LICENSE
| Format | Status |
|---|---|
| PPM (P6) | Supported |
| PPM (P3) | Not supported |
- Supports only binary PPM (P6) images.
- Assumes a maximum colour value of 255.
- Images are rendered pixel-by-pixel.
- Accepts input only through standard input.
- Limited validation of malformed files.
cc iv.c -o iv $(sdl2-config --cflags --libs)
If `sdl2-config` is unavailable, provide SDL2's include and linker flags directly. A typical Linux command is:
```bash
cc iv.c -o iv -lSDL2
Pass a binary PPM image through standard input:
./iv < images.ppmThe repository includes images.ppm and flower.ppm as sample inputs:
./iv < flower.ppmOther tools can be used to generate a PPM stream. For example, with ImageMagick:
convert input.jpg ppm:- | ./ivClose the window to exit the application.
| Path | Description |
|---|---|
iv.c |
SDL2 image viewer implementation |
images.ppm |
Sample PPM image |
flower.ppm |
Sample PPM image |
iv |
Prebuilt executable, when present |
The viewer expects a binary P6 PPM with this structure:
P6
# optional comment
<width> <height>
255
<binary RGB pixel data>
Pixel bytes are read left to right, then top to bottom, as consecutive red, green, and blue values.
No license has been specified for this repository. Treat the source and bundled images as all rights reserved unless the project owner adds licensing terms.
- Only binary
P6PPM data is supported in practice. The magic number is currently read but not validated. - The header parser expects the comment and header fields in fixed line positions.
- The maximum color value is assumed to be
255. - Malformed headers, truncated input, and SDL initialization errors are not reported robustly.
- Pixels are drawn individually with
SDL_FillRect, so large images may render slowly. - The complete image is read before the window becomes interactive.
- Validate the PPM magic number and all header fields.
- Support comments and whitespace according to the full PPM specification.
- Handle arbitrary maximum color values and truncated streams.
- Replace per-pixel surface fills with a texture or direct pixel buffer.
- Accept an image path as an optional command-line argument.
7320844 (Rewrite README for Image Viewer)