Giter Site home page Giter Site logo

wassimulator / cactusviewer Goto Github PK

View Code? Open in Web Editor NEW
134.0 3.0 9.0 132.41 MB

A small single file image viewer written in C/C++.

License: BSD 2-Clause "Simplified" License

C 34.02% Batchfile 0.01% C++ 65.87% HLSL 0.11%
c cpp graphics graphics-engine graphics-programming image-processing image-viewer

cactusviewer's Introduction

logo-export

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 also make sure you have D3D11 debug layers from here installed or remove that flag in init_d3d11() when building in debug mode).
  • 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.

cactusviewer's People

Contributors

detrohutt avatar hkva avatar themole avatar wassimulator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cactusviewer's Issues

DPI scale issue on multiple monitors

With two monitors the UI is blurry.

Current setup:

  • Screen 1, 100% scale: UI is fine.
  • Screen 2, 125% scale: UI is blurry. The window scale to the proper size when dragging the window there.

The window should still scale properly, but the UI shouldn't be blurry.

If I understand it correctly, the app needs to be "DPI aware".

Crash opening file from command line or `Open with...`

CactusViewer crashes when started in a way that will immediately open an image.

The crash appears to be in atidxx64.dll

Some observations:

  • Opening method
    • error when opening from command-line: C:\bin\CactusViewer.exe "D:\Photos\2023 Seattle\phillip_avatar.png"
    • error when opening with file explorer > right click image > Open with
    • no error when starting CactusViewer then using Open dialogue
  • Format
    • error for both JPG & PNG
  • Path
    • error for paths on different drives & with/without spaces: C:\Photos\phillip_avatar.png & "D:\Photos\2023 Seattle\phillip_avatar.png"
  • Occurs completely consistently (no obvious randomness)

Caveat:

  • It's possible there's something wrong with my graphics drivers, as I have had problems with other software. (Windows photo viewer currently works fine though)

Opening Window's extended clipboard makes app unresponsive for a while

Opening any image and then opening the extended clipboard (WindowsKey + V) makes it unresponsive. Only the mouse coordinates and the taskbar close button respond to inputs, everything else stops working. After some time, the app recovers and works as intended.

OS: Windows 10 Pro 64-bit

TGA Support

Any hope for TGA support? Lots of games use this format so it's unfortunate that it's not supported.

Dropping a directory causes assertion fail

I know the instruction doesn’t mention the possibility of dropping a directory. But since the application is tied to a directory it seems reasonable to expect it to handle directories as targets.

Version 1.2.3 - 03/2023

Screenshot

App fails to startup when CWD is not bin/

When starting the app while your current working directory is not the bin/ folder, the app crashes. It seems the app fails to load the default font. It would be great to embed the font file in the exe when building to prevent this.

Opening empty BMP displays wrong error message

This is a small one, but when I open an empty bitmap, which has been generated through the right-click menu, the viewer says:
Error: Component not found: file '.bmp' not supported.
I would imagine just being told that the image is empty.

I am using Windows 10.

I can see that Windows' Photos app doesn't do much better, so maybe this is a shortcoming of the Windows decoder that you are depending on or Windows really generates an invalid BMP.

Direct3D 10 backend

Requested to support older hardware. It should invlove changing the shader model from 5 to 4, and replacing structured buffers with input layouts.

Opening older gif crashes Cactus Viewer

It crashes (access violation 0x0) in source.cpp/render() on if (delta >= G->anim_frame_delays[G->anim_index] && G->anim_play) {
because G->anim_frame_delays = delays; is 0.

and I suppose it needed to be set in stb.c/static unsigned char *stbi_xload(stbi__context *s, int *x, int *y, int *frames, int **delays)
but the if (stbi__gif_test(s)) returns false and thus never calls stbi__load_gif_main which very much looks like where it's set.

That's all the investigating I have time for, sorry.

One of the files that causes the crash:
amazing_adventures_116x87 1

Active UI does not keep focus when it is used outside the specified area

When you are interacting with a UI element that allows sliding (GIF scrubber and Edit Hue, Saturation etc... when while dragging you move outside the area it looses focus and stops

Example:
CactusViewer-UI-bug

This makes it harder to use those sliders, it would be nice if the active UI element keeps focus and you can drag outside the 'slider' region.

I build it on windows with commit acfcc00

Thanks for this it is a really nice and easy tool.

Unable to open a supported image after attempting to view an unsupported file

I found two related issues. I'll describe them separately.

  1. If I try to open an unsupported file via the Open button - in this case a .RAF from FujiFilm - the app correctly tells me it's not supported. At this point I can no longer view supported images. I tried various types using the Open button and it continues to show the generic image thumbnail and the error message at the bottom status bar remains. The app title contains the name of the last image it was able to render (or nothing if the first thing I tried to open at app start was a .RAF).

  2. If I try the above but I drag & drop the images instead then the app seg faults. Once an invalid image has been dropped (at cold open or after a valid), attempting to drop any valid or invalid image causes the app to crash. Note that the drag & drop crash does not happen when an invalid image has been first opened via the Open button. So there's something about putting the app into an invalid state with a drop that leads to a segfault on future image drops.

Hope the above isn't confusing. Let me know if you need any clarification or want this split into two separate issues.

Loading GIF file failed

Firstly, thanks for the great software! When I try to open the following gif in CactusViewer v2.1.3 it displays "Error: Loading GIF file failed". The gif works when I open it in chrome. It would be great if the message was a more helpful around diagnosing the problem with the gif. Is there a log somewhere that has more information?

focus-0 3 0

Rotating GIF causes crash

When a GIF is being displayed and I click either Rotale L or Rotate R, the program crashes after a moment. If the GIF is paused, this is all that happens. If the GIF is playing, then a rotated but corrupted image is being displayed until the crash.

Using Windows 10

Mouse movement speeds up keyboard controls

Demonstrated in the gif below. My completely uninformed guess is that mouse movements cause the GUI to update rapidly, which resamples the keyboard faster resulting in a faster pan. Also occurs with keyboard zoom.

v2.1.2 Windows x64

Great program btw!

bug

CactusViewer is now in Scoop bucket "extras" - Update readme with install instructions?

CactusViewer is now in Scoop bucket "Extras":

  • https://github.com/ScoopInstaller/Extras/blob/master/bucket/cactusviewer.json

It can be installed by:

  1. Install Scoop, if you don't have it already.
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
    Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
  2. Add the Extras bucket, if you don't have it already.
    • scoop bucket add extras
  3. Install CactusViewer with Scoop.
    • scoop install extras/cactusviewer

It will add a shortcut to the start menu, and CactusViewer is also added to PATH so it can be ran from CMD without specifying the full path.


Would you like a PR with install instructions to README, or do you want to add it yourself? 🙂

Exif orientation

Love this little program! It would be nice if it respected exif orientation as well. Some photos taken with my phone are displayed sideways.

Support embedded ICC color profile

It seems CactusView does not yet support viewing images with embedded ICC color profile properly. I tested with both JPG and PNG.

Test image source:

Test images transcoded by me:

JPEG example

Sample image can be transcoded to JPG with ICC profile using libjxl ( https://github.com/libjxl/libjxl/releases/tag/v0.9.1 ) like so:

  • With XYB: ".\libjxl-v0.9.1\cjpegli.exe" ".\forest.jxl" ".\forest_xyb.jpg" --quality=90 --xyb --chroma_subsampling=444
  • Without XYB: ".\libjxl-v0.9.1\cjpegli.exe" ".\forest.jxl" ".\forest.jpg" --quality=90 --chroma_subsampling=444

Result in CactusView vs. GIMP

Using XYB

240131 - CactusViewer - JPEG with ICC color profile XYB

Not using XYB

240131 - CactusViewer - JPEG with ICC color profile

PNG example

Sample image can be transcoded to PNG with ICC profile using libjxl ( https://github.com/libjxl/libjxl/releases/tag/v0.9.1 ) like so:

  • ".\libjxl-v0.9.1\djpegli.exe" ".\forest.jpg" ".\forest.png"

Result CactusView vs. GIMP

240131 - CactusViewer - PNG with ICC color profile

CPU usage spike when minimizing with playing GIF

The viewer use less than 1% of CPU when playing a GIF. If I then minimize it, it goes to 25% CPU usage and stays there. It doesn't happen if the GIF is paused when minimizing.

I am using Windows 10.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.