This is a lightweight, hardware accelerated C++ application for parsing and viewing .ppm (Portable Pixel Map) images. This project manually parses ASCII based and raw .ppm files and renders them using the SDL2 library.
- Custom Parser: Manually reads .ppm files, handling headers, comments, empty spaces and different types of formatting data.
- Hardware Acceleration: Uses
SDL_RendererandSDL_Texturefor efficient rendering. - Smart Windowing: Automatically resizes the window and the image according to the size of the image.
- Multithreaded Loading: Optionally reads raw (P6) pixel data across several threads to speed up loading large images.
To build and run this project, all that you'll need is a C++ compiler and the SDL2 Development Library.
sudo apt install g++ make libsdl2-devsudo pacman -S sdl2sudo dnf install SDL2-develFor macOS systems you might want to have homebrew installed for convenience.
brew install sdl2You can use the Makefile for easy compilation.
After cloning the repository, simply run
make. This will generate an executable with the name view.
If you are on an UNIX like system, then run chmod +x view. Then you are ready to go.
./view <path-to-your-image-file.ppm>
For further information you can use the -h flag.
./view <path-to-your-image-file.ppm> [-h/--help]
For raw (P6) images you can spread the pixel reading across multiple threads with the -t flag. The count is clamped to the available cores and the number of image rows.
./view <path-to-your-image-file.ppm> [-t/--threads <count>]
├── include/ # Custom header files
| ├── BilinearLerper.h # Declarations of the bilinear interpolation algorithm
│ ├── Image.h # Struct to hold image data
│ ├── InverseMap.h # Declarations of the inverse mapping algorithm
│ ├── ViewState.h # Struct to hold zooming and offsetting data
│ ├── Pixel.h # Packed struct for pixel data
│ ├── Parser.h # Declarations of file reading and text parsing
│ └── PPMViewer.h # Declarations of SDL2 window creation and rendering
├── src/ # Implementation files
│ ├── main.cpp # Entry point & argument handling
│ ├── Parser.cpp # Implementations for file reading and parsing information
│ ├── BilinearLerper.cpp # Implementations for the bilinear interpolation algorithm
│ ├── InverseMap.cpp # Implementations for the inverse mapping algorithm
│ └── PPMViewer.cpp # Implementations for window creation and rendering the image
├── Makefile # Build configuration file
└── README.md # README file?
- Interactive panning and zooming system
- Implementation of a better way of passing files to the program
- Support for different formats