OpenEXR

repository·main·Indexed 23 days ago

https://github.com/academysoftwarefoundation/openexr

A professional-grade image storage format used in the motion picture industry for high-dynamic-range, multi-part, and multi-channel 2D image data. The project provides a specification and reference implementation, including Python bindings, and supports mandatory Zlib and optional dependencies such as Boost, NumPy, Fltk, and Cg.

Tokens
81.6K
Snippets
125
Records
477
Agent score
83%

What's inside OpenEXR

  1. Overview of OpenJPH (HTJ2K implementation)

    main

    OpenJPH is an open-source implementation of High-throughput JPEG2000 (HTJ2K), also referred to as JPH, JPEG2000 Part 15, ISO/IEC 15444-15, and ITU-T T.814.

    It focuses specifically on the HTJ2K standard and supports key features defined in JPEG2000 Part 1, including:

    • Reversible 5/3 wavelet transforms
    • Irreversible 9/7 wavelet transforms
  2. Overview of OpenEXR and Imath

    main

    OpenEXR is the professional-grade image storage format used in the motion picture industry. It is designed to accurately and efficiently represent high-dynamic-range (HDR) scene-linear image data, supporting multi-part, multi-channel use cases and extensive metadata. It is primarily used in photorealistic rendering, texture access, image compositing, deep compositing, and DI.

    The project includes Imath, a lightweight C++ library providing efficient representations of 2D and 3D vectors, matrices, and other mathematical objects common in computer graphics. Imath also includes the half 16-bit floating-point type and provides optional Python bindings for all types and functions, including optimized implementations for vector and matrix arrays.

  3. OpenEXR License Terms

    main

    OpenEXR is licensed under the BSD-3-Clause license.

    When redistributing OpenEXR in source or binary forms, you must adhere to the following conditions:

    1. Source Redistributions: Retain the original copyright notice, the list of conditions, and the disclaimer.
    2. Binary Redistributions: Reproduce the copyright notice, the list of conditions, and the disclaimer in the documentation and/or other materials provided with the distribution.
    3. Endorsement: You may not use the name of the copyright holder or contributors to endorse or promote products derived from this software without specific prior written permission.

    Disclaimer: The software is provided "AS IS" without warranty of any kind. The copyright holders and contributors are not liable for any direct, indirect, incidental, special, exemplary, or consequential damages arising from the use of this software.

  4. Key features of OpenEXR

    main

    OpenEXR is a high-performance image format and library designed for professional visual effects and imaging workflows. Key capabilities include:

    • High Dynamic Range (HDR): Supports 16-bit floating-point, 32-bit floating-point, and 32-bit integer pixels.
    • Compression: Multiple lossless and lossy codecs. Some lossless codecs can achieve 2:1 ratios on images with film grain.
    • Extensibility: Users can extend C++ classes to add new compression codecs and image types. New image attributes (strings, vectors, integers, etc.) can be added to headers without breaking backward compatibility.
    • Deep Data Support: Pixels can store variable-length lists of samples, allowing multiple values at different depths per pixel (useful for volumetric data).
    • Multipart Support: Allows encoding separate but related images in a single file, enabling access to specific parts without reading the entire file.
    • Stereoscopic/Multi-view: Built-in support for stereoscopic workflows and multi-view generalizations.
    • Versioning: Supports user-configurable C++ namespaces to allow multiple versions of the library to coexist in the same process space.
  5. Multi-View OpenEXR Image Formats

    main

    The OpenEXR project provides multi-view test images that demonstrate various formatting variations, including different scanline/tiled structures, channel configurations, and compression types. These images are designed for stereo display testing and typically contain at least a left-eye and a right-eye view.

    Key variations demonstrated in the test suite include:

    • Scanline vs. Tiled: Images can be stored as scanlineimage or tiledimage (including tiled mip-maps).
    • Channels: Support for multiple channels (e.g., R, G, B) or single luminance channels (e.g., Y).
    • Compression Types: Examples use b44a, piz, and zip compression.
    • View Configurations: Images may have different numbers of views (e.g., 2 or 3 views) and different default views (left, right, or center).
  6. Key features of the OpenEXR file format

    main

    OpenEXR is designed for high-quality image processing and storage with the following capabilities:

    • High Dynamic Range (HDR): Supports 16-bit or 32-bit floating-point pixel data, providing significantly higher dynamic range and color resolution than standard 8-bit formats.
    • Graphics Hardware Compatibility: 16-bit floating-point format is compatible with modern graphics hardware frame buffers.
    • Compression: Supports both lossless (preserves exact data) and lossy compression schemes.
    • Arbitrary Channels: Can store any number and combination of channels (e.g., RGB, Alpha, Depth, Surface Normals, Motion Vectors).
    • Storage Layouts: Supports scan line, tiled (for random-access to sub-regions), and multi-resolution (mipmaps/ripmaps) images.
    • Metadata/Attributes: Allows storing an arbitrary number of extra attributes of arbitrary types (e.g., camera position, color timing).
    • Multi-view & Multi-part: Supports multi-view imagery (e.g., 3D stereo) and multi-part files (storing multiple images or layers with different layouts/compression in one file).
    • Deep Data: Supports "deep images" where each pixel stores an arbitrarily long list of data, enabling accurate compositing of occluding objects.
    • Performance: Supports multi-threaded reading and writing.
  7. Introduction to OpenEXRCore (v3.1+)

    main

    OpenEXR 3.1 introduced OpenEXRCore, a new library designed to address scalability issues in multithreaded image I/O.

    Key Characteristics

    • Language: Written entirely in C, providing a C-language API alongside the existing C++ API.
    • Thread Safety: Provides thread-safe, non-blocking access to files.
    • Performance: Designed for high-performance use cases, such as custom data unpacking on the GPU or direct access in texturing applications.
    • Interoperability: The C API provides an easier path for implementing OpenEXR bindings in other languages (e.g., Rust).

    Usage Model

    • Incremental Rollout: The existing C++ API has not changed in v3.1; it will migrate to use the new core in stages in future releases.
    • Specialty Applications: While the C++ API remains the standard for most users, the C API is intended for specialty applications requiring the highest possible performance.
    • Limitations: The C API does not provide the rich set of utility classes available in the C++ layer.
  8. Compute a shallow mask from Deep IDs

    main

    A shallow mask is a pixel-level mask used with non-deep compositing operators. To correctly compute an ID selection mask for a single pixel, you must iterate through the samples sorted front-to-back and accumulate alpha based on the remaining visibility (uncovered alpha).

    total_combined_alpha = 0.0
    mask_alpha = 0.0
    sorted_pixel = sort_pixel_front_to_back(input_pixel)
    
    foreach(sample in sorted_pixel):
        if id_is_in_selection(sample.id):
            mask_alpha += sample.alpha * (1.0 - total_combined_alpha)
        total_combined_alpha += sample.alpha * (1.0 - total_combined_alpha)
    
    if total_combined_alpha == 0.0:
        return 0.0
    else:
        return mask_alpha / total_combined_alpha
  9. Configure libdeflate compression levels

    main

    libdeflate uses compression levels similar to zlib (where level 1 is fastest/lowest compression and level 9 is slowest/highest compression). However, libdeflate extends this range up to level 12.

    Levels 10-12 utilize a minimum-cost-path based algorithm (optimal parsing) to provide significantly better compression ratios than standard zlib level 9. You should test different levels to find the optimal balance between speed and ratio for your specific data.

  10. Link multiple OpenEXR versions in one executable

    main

    In scenarios like Digital Content Creation (DCC) tools (e.g., Nuke or Katana), you may need to link a custom plugin against a different version of OpenEXR than the one used by the host application. To prevent symbol clashes, use the following strategies:

    1. Namespace Options

    Configure your custom build of OpenEXR with a unique namespace so its symbols do not collide with the host's symbols.

    2. Handling OpenEXRCore (C API)

    Because OpenEXRCore is implemented in C and does not support a namespace option, you must use a specific CMake flag to hide its symbols. This prevents the OpenEXRCore symbols in your plugin from clashing with the host's symbols.

    Requirement: Build your custom OpenEXR library with: -DOPENEXR_FORCE_EMBEDDED_CORE=ON

    Effect: This links against a statically-built OpenEXRCore library with hidden symbols. Note that the installation will not include a libOpenEXRCore.so file.

    Limitation: This solution works if your plugin uses the OpenEXR C++ API. If your plugin requires direct access to the OpenEXR C API from OpenEXRCore, this method will not work, and you must use other symbol-hiding mechanisms.

    -DOPENEXR_FORCE_EMBEDDED_CORE=ON
  11. Understand Tiled OpenEXR Level Modes

    main

    Tiled OpenEXR files can store multiple versions of an image at different resolutions, known as levels. The level mode determines how these levels are structured:

    • ONE_LEVEL: Contains only a single, full-resolution level. This is functionally equivalent to a scan line based file, but pixels are accessed via tiles.
    • MIPMAP_LEVELS: Contains multiple levels where each successive level is half the resolution of the previous one in both x and y directions. The last level is a single pixel. Used for texture mapping.
    • RIPMAP_LEVELS: Similar to mipmaps but includes all combinations of reducing resolution by powers of two independently in x and y. This helps accelerate anisotropic filtering.

    The size of each level is determined by halving the size of the higher-resolution level. The rounding direction (if the dimension is odd) is controlled by the file's level size rounding mode.