Skip to content

OpenEXR color data is incorrect when using HalfVector4 #3194

Description

@mhourousha

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

4.1.2

Other ImageSharp packages and versions

4.1.2

Environment (Operating system, version and so on)

windows11

.NET Framework version

10

Description

I encountered an issue where OpenEXR image data is being incorrectly altered during loading when using the HalfVector4 floating-point pixel formats

OpenEXR frequently stores High Dynamic Range (HDR) color data in floating-point formats, which means values often exceed the [0, 1] range. However, the current loading logic clamps and scales these values, destroying the original raw data.

I traced the issue to two specific areas in the codebase:
In ExrDecoderCore.cs (around line 225):
pixelRow[x] = TPixel.FromAssociatedScaledVector4(pixelValue);
If TPixel is HalfVector4 and the EXR pixel type is half or float, the RGB channels are clamped to [0, 1] and then scaled/biased to [FiniteMinimum, FiniteMaximum]. This breaks the original floating-point data. I believe the clamp and scale operations should be avoided here.

As a side note for other floating point pixel format like RgbaHalf and RgbaVector.The FromAssociatedScaledVector4 method calls FromVector4(Vector4 source). Inside FromVector4, the original values are explicitly clamped to [0, 1]. This also breaks the raw EXR data.

Steps to Reproduce

load a openEXR file in HalfVector4 or HalfVector4P format,then check the pixel value of ToVector4();

Images

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions