Skip to content

Repository files navigation

viewer

Load and display image files

What is this?

I got so tired of Windows Photo Viewer misbehaving that I decided to write a clone.

Things WPV does that drove me to insanity:

  • No support for animated GIFs.
    • I had to resort to opening GIFs in Internet Explorer, truly a cursed experience.
    • As of version 0.3.X, animated GIFs are nearly fully supported.
  • "Windows Photo Viewer can't display this picture because there might not be enough memory available on your computer"
    • Let me assure you, this is not correct.
    • Afflicted photos open correctly in Photoshop, web browsers, etc. It's just WPV that has a problem.
  • Very low FPS and bad screen tearing with no warning when zooming or when panning while zoomed in.
    • Really annoying, and there's no good reason for it.

How hard could it be to write a replacement, right?

Things Viewer can do:

  • Display many common image formats.
  • Zoom!
  • Pan!
  • Wow!

Also, it's GPU accelerated (via SDL's Accelerated Rendering features). There are some trade-offs:

  • PRO: Ultra low CPU usage once image is loaded -- this is still a CPU process.
  • PRO: Panning and zooming are very smooth and take advantage of better GPU hardware rendering.
  • CON: Startup takes a little longer than WPV due to the conversion of the input image to a GPU texture.
  • CON: Image size limited by typically smaller VRAM size compared to RAM - I have yet to find an image large enough to hit this limit though.

Requirements:

This project depends on:

  • C++17 for std::filesystem
  • MSYS2 for MingW64 and required libraries

Packages you'll need, as they appear in MSYS:

  • mingw-w64-x86_64-gcc
  • mingw-w64-x86_64-make
  • mingw-w64-x86_64-SDL2
  • mingw-w64-x86_64-SDL2_image
  • mingw-w64-x86_64-giflib
  • mingw-w64-x86_64-libheif

Building:

Run make <type> in the Viewer folder where type is either Debug or Release (defaults to Release).

Notes:

  • If your make.exe isn't on your PATH, you need to launch it via it's complete path or hard link it into the Viewer directory.
  • You will need to modify the makefile at the marked lines to point to your mingw64 install (for g++ and windres).
  • You will also need to point to the library include and lib folders - they shouldn't require much modification unless MSYS is installed somewhere other than default.
  • These are mostly just the build commands as CodeBlocks runs them - they may not always be up to date enough to build the project without modification.

Usage:

First, ensure that the executable has all the .dll files available to it. There are a number you need:

  • SDL2, SDL2_image & all the related image .dlls (including zlib)
  • libaom, libde265, libheif, libx265 for HEIF files
  • libgcc_s_seh, libstdc++, libwinpthread for basic program functions

Then call the program by either dragging an image onto Viewer.exe or by running Viewer.exe <filename> in a terminal.

You can also set Viewer as the default program for some image formats if you want to commit to it.

Controls:

Mouse:
CONTROLFUNCTIONNOTES
SCROLL UPIncrease zoom-
SCROLL DOWNDecrease zoom-
LEFT CLICKPan imageMust be held while dragging.
MIDDLE CLICKReset zoom and panThis is usually a scroll wheel click.
MOUSE X1Previous imageIf the mouse is equipped with a back button.
MOUSE X2Next imageIf the mouse is equipped with a forward button.
Keyboard:
SYMBOLCONTROLFUNCTIONNOTES
+PLUSIncrease zoomFor keyboards without keypad, use equals (=).
-MINUSDecrease zoom-
0ZEROReset zoom and panZero, not the letter O.
ESCESCAPEClose programIdentical to window close button.
<-LEFT ARROWPrevious image-
->RIGHT ARROWNext image-
|<->|TABToggle light theme-
SPACEBARPlay/Pause animationOnly applicable to animated images.
DELDELETEDelete imagePermanent! This will not go to Recycle Bin!
F1F1View version infoProbably not useful to you if you're reading this.
F2F2View file infoDisplay Windows Explorer's Properties window for the image.
F3F3Containing folderLaunches Windows Explorer to the image's parent folder.
F5F5RefreshReload the current image.

Supported formats (by library):

SDL:

  • JP(E)G
  • PNG
  • BMP
  • TIF(F)
  • TGA

GIFLIB:

  • GIF

LIBHEIF:

  • HEIC
  • HEIF

Notes:

  • Some file types can contain multiple resolutions/variations of an image (ICO, CUR, ...). SDL_image documentation states that "for files with multiple images, the first one found with the highest color count is chosen."
  • Window size and position are stored in settings.cfg in the program folder. If this becomes broken somehow (window appears off-screen, etc.) it is safe to delete this file to restore defaults.
  • Setting up a version of GCC new enough to support C++17 is a really bad time on Windows and unless you really need to build from source, I highly recommend you use one of the builds. Otherwise, I'll direct you to MSYS2's homepage.

TODO:

  • Add key to set zoom to 1:1 pixel ratio
  • Zoom on mouse instead of window center
  • Stop image from being moved off-screen
  • Possible minimal RAW support

Known Problems:

  • ICO: Files stored as "NEW PNG" type do not load with SDL_image
  • ICO: Files with partially transparent pixels do not render correctly
  • ALL: Images loaded from RO-type media (cell phones, cameras) are copied to a temp folder by Windows before being loaded. This breaks in-folder navigation. It's unclear to me how WPV works around this.
  • ALL: Images with UTF-8 characters anywhere in the path are broken - this is because of the conversion from wchar string to char string done to accommodate SDL_Image. I can't find anything online about how to work around this.

About

Load and display image files

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages