A lightweight image viewer written in C/C++.

Complete

About Cactus Image Viewer


Cactus Image Viewer

by Wassim Alhajomar (@wassimulator)

A single-file handmade image viewer for Windows, written in C/C++.

VIDEO: Watch it in action:

Featured on the Handmade Network's Wheel Reinvention Jam.

Video


F7HthCRWYAAnZQH


Consider donating if you like this project

Used libraries:

Homemade immediate mode UI, a custom D3D11 renderer, Windows Imaging Component, stb_image and libwebp for decoding, cute_files.h to manage directories on different platforms, FreeType for font loading, and easyexif for fetching image metadata.

Supported codecs:

BMP, GIF, ICO, JPEG, JPEG XR, PNG, TIFF, DDS, WEBP.
It also supports installed codecs for WIC, check Microsoft Store to get codecs like HEIF, RAW, or AVIF. Here:
AV1 Video Extension
HEVC Video Extensions
HEIF Image Extensions
Raw Image Extension

Features:

  • Standalone executable.
  • Crisp font rendering with subpixel antialiasing.
  • Scans folder of opened image and allows flipping through supported images within folder, and rotating the view without changing the source files.
  • Supports loading image files in the sorted order of the folder, can be optionally disabled to default to alphabetic.
  • Support for unicode file names.
  • Multithreaded file loading.
  • Fullscreen mode with F11.
  • Image pan and zoom with fitting modes; to width or height.
  • RGB Histograms.
  • Adjustable hue, saturation, gamma, and brightness values.
  • Image cropping
  • Gaussian blur filters
  • Ability to save images with current adjustments
  • Support for reading and displaying EXIF metadata off of JPEG images and rotation info.
  • Pixel color inspector and a quick copy of HEX value to clipboard.
  • Animated GIF and WebP support with play/pause and seek controls.
  • Quick toggle between nearest-neighbor and linear filtering for pixelart images.
  • Pixel grid.
  • 3 UI themes.
  • Customizable background color with support for checkerboard with custom colors.
  • Drag and drop support for opening image files and folders.
  • Switches to turn individual RGB channels off and switch between premultiplied alpha and straight RGB.
  • Keyboard controls to pan, zoom, and flip through files and GIF controls.
  • Customizable settings to save each image's zoom and pan locations within a session, or to reset image zoom and pan upon file change.

Usage:

  • Opening a file:
    • Drag and drop image file into the viewer, if the file is supported it should load the file and read the folder contents of the file's directory.
    • CactusViewer also supports "Open With..." by choosing it as the program to open an image with.
    • You can also use the command line to open a file by typing: > CactusViewer.exe "path_to_file" (make sure you write the full path of the file!).
  • Move the mouse to the bottom of the screen to view controls, click on "config" to see controls and change settings.

Building:

Windows:

All dependencies are within the repo for your, my, and everyone's convenience. Using an MSVC 64 bit developer terminal:

  • run b.bat to build the project in debug mode, output in \bin (the debug version expects the font file in src, so terminal calls need to have bin as the working directory to run).
  • run b.bat release to build the project in release mode, output in \bin

Remarks:

  • Update 2.0 ditches ImGui and OpenGL, the executable runs now on D3D11 with a handmade immediate mode UI library. If you have Windows, it should work, so please report any bugs!
  • For the sake of everyone's sanity, this repo has prebuilt binaries of all the above for Windows x64, I will provide other builds if I make any.

Possible improvements:

Possible things to expand on:

  • Unlock the supported image resolutions sizes beyond maximum GPU texture sizes, to support images larger than 60MP or 268MP respectively.
  • Decode images at lower resolutions at first and only decode full image upon zooming, to improve display speed of large files.
  • Rectangle selection and viewing of x,y,w,h values.
  • Crop and rotate image, stb_image_write.h is already included and should be able to save the files, only the editing algorithms and UI need to be written.
  • Providing an optional software renderer backend.
Read more
Filters

Recent Activity

Cactus Image Viewer version 2.2.0
New major feature!

  • Interactable thumbnail preview strip of current images in the folder (á la Picasa)
    This feature is inspired by Google Picasa, which had something like this, a non-intrusive UI strip of thumbnails at the bottom that provided a nice overview of the images in the folder and allows you to jump between files visually. This feature is toggleable in the settings.
    Other new additions:
  • Added .ppm support through #42, thanks @hkva for the great work!

You can get it here:
https://github.com/Wassimulator/CactusViewer/releases/tag/v2.2.0

Some technical info:
I create one big “thumbs” texture and loop retro- and prograde from the file index through the file list on a separate thread and use WIC to generate a thumbnail of fixed size and centered zoom (WIC has a nice interface for all of this) for each image, and periodically update this texture on the GPU, fixed size grid. Upon folder change, I overwrite on the same texture. This also necessitated introducing UI culling to only draw what’s on the screen which otherwise would’ve been a major bottleneck for folders with too many files. Good thing was culling was just one added if statement before rendering.

&cactus

View original message on Discord

Cactus Viewer now live redraws the window resposively when resizing the window. it's a small update, by using fibers there is no need to seperate the main loop to a separate thread to achieve this.
The update is live:
https://github.com/Wassimulator/CactusViewer/releases/tag/v2.1.3
&cactus

View original message on Discord

CactusViewer update 2.1.0 is released!

This update brings:

  • Image cropping
  • Gaussian Blur filters
  • Image saving functionality for any changes
  • No resource usage on idle (update only on relevant window events)
  • improvements to histogram rendering and a few bug fixes

You can download the image viewe and read the patch notes here:
https://github.com/Wassimulator/CactusViewer/releases/tag/v2.1.0
&cactus

View original message on Discord

you can now save image edits to disk, including rotation, cropping, and image value changes
&cactus

View original message on Discord

Cactus Viewer now now waits on Window events, instead of unnecessarily redrawing on idle, still supports UI animations and handles events set by image loader threads to wake up the process.
(tried demonstrating updates with printf("I");, best I could)
&cactus

View original message on Discord

You can also blur images for these specific purposes:
&cactus

View original message on Discord

image saving pipeline, which should allow you to save whatever the shader is displaying, so any image value changes for now like saturation or gamma, etc. Planning to implement more basic image editing functions such as cropping, soon.
the render and encoding pipeline now works.
&cactus

View original message on Discord

CactusViewer 2.0 is officially out!
https://github.com/Wassimulator/CactusViewer
This is a big one.
This update brings radical changes to the architecture, code structure, style, and intruduces a number of new features:

Architecture:

  • New render backend, replacing OpenGL with a Direct3D 11 renderer.
  • New handmade immediate-mode UI library that supports animations, themes, and subpixel antialiasing for text, replacing ImGui.
  • Windows Image Component decoders, opening the range of supported formats to pretty much anything Windows can open with their apps, plus the automatic support for any extra installed image codecs that WIC can support.
  • WebP codecs using Google's libwebp decoders, supporting both still and moving images.

Features:

  • Histograms with toggleable red, green, blue, and mix channels.
  • Live image value sliders to adjust brightness, saturation, contrast, and gamma.
  • A toggle to enable sRGB rendering.
  • Controls for rotating images without changing the file.
  • Support for reading EXIF metadata and displaying it, and correctly rotating JPEGs.
  • 3 UI themes to choose from in settings, including a light theme.
  • Fullscreen mode

Codebase:

  • An update to the coding style and naming convensions to something consistent, with better building scripts.
  • Moved the main repo to the current, under the master-2.0 branch, the previous version with ImGui and OpenGL is still available and be found under the branch: master-1.0.

&cactus

View original message on Discord

Over the last two or so weeks I've been working on a little handmade image viewer, and since I've started a new job I won't have much time to add more features to it. Since it's stable and I already use it on my own rig, I'm releasing CactusViewer alongside the source code today!

Features:

  • Supports PNG, JPG, JPEG, BMP, and GIF extensions.
  • Scans folder of opened image and allows flipping through supported images within folder.
  • Multithreaded file loading.
  • image pan and zoom with fitting modes; to width or height.
  • Pixel color inspector and a quick copy of HEX value to clipboad.
  • Animated GIF support with play/pause and seek controls.
  • Quick toggle between nearest-neighbor and linear filtering for pixelart images.
  • Pixel grid.
  • Customizable background color with support for checkerboard with custom colors.
  • Drag and drop support to opening image files.
  • Switches to turn individual RGB channels off and switch between premultiplied alpha and straight RGB.
  • Keyboard controls to pan, zoom, flip through files and GIF controls.
  • Customizable settings to save each image's zoom and pan locations within a session, or to reset image zoom and pan upon file change.

You can check out the source code, and find prebuilt binaries for Windows here:
https://github.com/Wassimulator/CactusViewer
&cactus

View original message on Discord