void Image Viewer

repository·master·Indexed 23 days ago

https://github.com/voidtools/voidimageviewer

A lightweight, high-performance Windows application for viewing image formats including BMP, GIF, ICO, PNG, JPG, TIF, and WEBP, with a focus on fast loading and accurate GIF/WEBP animation. The repository also includes libwebp, a library for encoding and decoding WebP images featuring simple and advanced APIs, command-line tools (cwebp, dwebp), and bindings for Java, Python, and JavaScript/WASM.

Tokens
14K
Snippets
32
Records
79
Agent score
82%

What's inside void Image Viewer

  1. Overview of the WebP Codec

    master

    WebP codec is a library designed for encoding and decoding images in the WebP format. It provides two primary ways to interact with the format:

    1. As a Library: Integrate the codec into other software to add native WebP support.
    2. As Command Line Tools: Use the provided binaries cwebp (for compression/encoding) and dwebp (for decompression/decoding) to process images via the terminal.

    For detailed information on the image format itself, refer to the Google Developers WebP page.

  2. Compile the WebP JavaScript decoder

    master

    To build the WebP JavaScript decoder, you must use Emscripten and CMake. This process generates the necessary .js and .wasm files required for decoding WebP bitstreams in a web environment.

    Prerequisites

    • Install the Emscripten SDK following the official instructions.
    • Ensure the $EMSDK environment variable points to the top-level directory of your Emscripten installation.

    Build Steps

    1. Configure the WEBP_JS project using emcmake with the WEBP_BUILD_WEBP_JS flag set to ON:
      cd webp_js && \
      emcmake cmake -DWEBP_BUILD_WEBP_JS=ON ../
    2. Compile the project using emmake make:
      emmake make

    Upon successful completion, the following files will be generated:

    • webp.js
    • webp.js.mem
    • webp_wasm.js
    • webp_wasm.wasm
    cd webp_js && \
    emcmake cmake -DWEBP_BUILD_WEBP_JS=ON ../ && \
    emmake make
  3. Use the Advanced Decoding API for cropping and rescaling

    master

    The Advanced Decoding API allows for on-the-fly cropping and rescaling. This is highly efficient for memory-constrained environments (like mobile) because memory usage scales with the output size rather than the input size.

    Workflow:

    1. Initialize Config: Use WebPInitDecoderConfig(&config).
    2. Get Features: (Optional) Use WebPGetFeatures to inspect the bitstream.
    3. Configure Options: Set config.options.use_scaling = 1 and specify scaled_width and scaled_height.
    4. Configure Output: Set the desired colorspace in config.output.colorspace. You can also provide an external buffer via config.output.u.RGBA.rgba and set config.output.is_external_memory = 1.
    5. Decode:
      • Full Image: WebPDecode(data, data_size, &config)
      • Incremental: Use WebPIDecode(NULL, NULL, &config) to get a WebPIDecoder*, then feed it using WebPIAppend in a loop.
    6. Cleanup: Call WebPFreeDecBuffer(&config.output) to reclaim memory (this is safe even if the memory was externally supplied).
  4. Convert animated GIFs to WebP using gif2webp

    master

    The gif2webp utility (found in examples/) converts animated GIF files to animated WebP files.

    Usage

    gif2webp [options] gif_file -o webp_file

    Options

    • -h / -help: Help
    • -lossy: Encode image using lossy compression
    • -mixed: Heuristically pick lossy or lossless compression for each frame
    • -q <float>: Quality factor (0:small..100:big)
    • -m <int>: Compression method (0=fast, 6=slowest)
    • -min_size: Minimize output size (default:off; uses lossless by default; can be combined with -q, -m, -lossy or -mixed)
    • -kmin <int>: Min distance between key frames
    • -kmax <int>: Max distance between key frames
    • -f <int>: Filter strength (0=off..100)
    • -metadata <string>: Comma separated list of metadata to copy (Valid values: all, none, icc, xmp; default: xmp)
    • -loop_compatibility: Use compatibility mode for Chrome versions prior to M62
    • -mt: Use multi-threading if available
    • -version: Print version number
    • -v: Verbose
    • -quiet: Don't print anything

    Building

    To build gif2webp, you must have libgif development files installed. Use one of the following:

    Using makefile.unix:

    $ make -f makefile.unix examples/gif2webp

    Using autoconf:

    $ ./configure --enable-everything
    $ make
  5. Generate HTML Docs with Syntax Highlighting

    master

    To generate documentation with syntax highlighting for code blocks, use kramdown with CodeRay options. This method applies inline CSS styling, so no external stylesheet is required.

    Run the following command from the project root:

    kramdown doc/webp-lossless-bitstream-spec.txt --template doc/template.html --coderay-css style --coderay-line-numbers ' ' --coderay-default-lang c > doc/output/webp-lossless-bitstream-spec.html
    kramdown doc/webp-lossless-bitstream-spec.txt --template \
      doc/template.html --coderay-css style --coderay-line-numbers ' ' \
      --coderay-default-lang c > \
      doc/output/webp-lossless-bitstream-spec.html
  6. Use WebP Encoding and Decoding Tools

    master

    The package includes command-line tools for image manipulation:

    • cwebp: Used to compress and encode images into the WebP format.
    • dwebp: Used to decompress and decode WebP images.

    These tools can also be used to view metadata and information about WebP images and animations. For detailed usage instructions and flag definitions, see the tools documentation.

  7. Compare two animated images with anim_diff

    master

    The anim_diff utility (found in examples/) compares two animated images (GIF or WebP) to find differences.

    Usage

    anim_diff <image1> <image2> [options]

    Options

    • -dump_frames <folder>: Dump decoded frames in PAM format
    • -min_psnr <float>: Minimum per-frame PSNR
    • -raw_comparison: If not used, RGB is premultiplied before comparison
    • -max_diff <int>: Maximum allowed difference per channel between corresponding pixels in subsequent frames
    • -h: Help
    • -version: Print version number

    Building

    To build anim_diff, you must have libgif development files installed. Use one of the following:

    Using makefile.unix:

    $ make -f makefile.unix examples/anim_diff

    Using autoconf:

    $ ./configure --enable-everything
    $ make
  8. Build libwebp using Gradle

    master

    Gradle support is minimal and is used to compile libwebp, cwebp, dwebp, and webpmux_example.

    Prerequisites: A compiler (e.g., gcc with autotools) and gradle. On Debian-like systems: sudo apt-get install build-essential gradle.

    Build Command: Run the Gradle wrapper with the buildAllExecutables target.

    ./gradlew buildAllExecutables
  9. Build libwebp on Windows

    master

    To build libwebp on Windows, use nmake with the provided Makefile.vc. The target architecture (x86 or x64) is automatically detected based on the Visual Studio compiler (cl.exe) available in your system PATH.

    Output locations:

    • Tools (cwebp.exe, dwebp.exe): output\release-static\(x64|x86)\bin
    • Static library: output\release-static\(x64|x86)\lib
    nmake /f Makefile.vc CFG=release-static RTLIBCFG=static OBJDIR=output
  10. Generate libwebp Container Spec Docs from Text Source

    master

    To generate HTML documentation from the libwebp text source files, you must use kramdown.

    Prerequisites

    • Install kramdown via rubygems. Rubygems should handle all necessary dependencies automatically.
    • For syntax highlighting, ensure kramdown version 0.13.7 or newer is used. CodeRay will be installed automatically as a dependency of kramdown via rubygems.

    Basic HTML Generation

    Run the following command from the project root to convert a text specification into an HTML file using the provided template:

    kramdown doc/webp-container-spec.txt --template doc/template.html > doc/output/webp-container-spec.html
    kramdown doc/webp-container-spec.txt --template doc/template.html > \
      doc/output/webp-container-spec.html