OpenExrEncoder Class

Immutable settings for OpenEXR encoding (lossless, linear-light floating-point still images).

public sealed class OpenExrEncoder : ImageEncoder

Remarks

The output is a single-part scan-line file whose data window and display window are the image. Floating-point pixels may have values outside [0, 1], infinities and samples that are not numbers (ImageEncoder.FloatingPointConversion does not apply). Integer pixels are stored as the floating-point values of the conversion of Image.CloneAs to RgbaFloat (v / max). Gray pixel formats are written as a luminance channel (Y), the formats with alpha with an A channel.

Colors are multiplied by the alpha that is written (rounded to the sample type) when it is not 0, and divided by it when decoded, as OpenEXR stores premultiplied colors and the library holds straight colors. Rounding and underflow can change them: lossless compression preserves the stored samples, not necessarily the source pixels (RgbaHalf pixels written as OpenExrPixelType.Float samples come back exactly). A zero alpha keeps its colors without multiplication. Alpha is not limited to [0, 1]: a finite color that the multiplication takes beyond the range of the sample type, or that an alpha that is not finite makes infinite or not a number, is rejected with UnsupportedImageFeatureException before anything is written.

By default, the samples are written as OpenExrPixelType.Half for RgbaHalf and 8-bit pixel formats, and as OpenExrPixelType.Float otherwise. Writing RgbaFloat or 16-bit pixels as half samples rounds them (nearest, ties to even) and requires OpenExrEncoder.AllowBitDepthReduction; a finite sample beyond ±65,504 (the largest half) is rejected.

OpenEXR samples are linear light: the image must be labeled ColorTransferFunction.Linear (the default of floating-point images), or have a CICP description with the linear transfer characteristics (8) and the primaries of BT.709, BT.2020, DCI-P3 or Display P3, which are written as the chromaticities attribute. Any other label (sRGB-encoded samples, an ICC profile), EXIF, XMP, an orientation other than ExifOrientation.TopLeft, a resolution or text entries follow ImageEncoder.MetadataHandling (rejected by default).

Compressed output needs a seekable destination: the table of the offsets of the chunks precedes them.

With ImageConfiguration.MaxDegreeOfParallelism above 1, the samples of an image of at least 65,536 pixels are checked, and its chunks converted and compressed, by up to that many workers; the file, and the error of a sample out of range, are those of a single worker. Each worker needs its own chunk buffers, charged to ImageResourceLimits.MaxLiveAllocationBytes.

Inheritance
ImageEncoder OpenExrEncoder

Constructors

NameDescription
OpenExrEncoder()

OpenExrEncoder()

OpenExrEncoder.cs
public OpenExrEncoder()

No documentation is available.

Properties

NameDescription
AllowBitDepthReductionGets a value indicating whether RgbaFloat and 16-bit pixels may be written as half samples (OpenExrEncoder.PixelType set to OpenExrPixelType.Half), which rounds them. Defaults to false.
CompressionGets the compression of the chunks. Defaults to OpenExrCompression.Zip.
FormatGets the format produced by this encoder.
PixelTypeGets the type of the samples, or null (the default) for half samples of RgbaHalf and 8-bit pixels, float samples otherwise. Alpha conversion can round colors independently of this choice.

AllowBitDepthReduction

OpenExrEncoder.cs

Gets a value indicating whether RgbaFloat and 16-bit pixels may be written as half samples (OpenExrEncoder.PixelType set to OpenExrPixelType.Half), which rounds them. Defaults to false.

public bool AllowBitDepthReduction { get; init; }

Property value

bool

Gets the compression of the chunks. Defaults to OpenExrCompression.Zip.

public OpenExrCompression Compression { get; init; }

Property value

OpenExrCompression

Exceptions

ArgumentOutOfRangeException
The value is not a defined OpenExrCompression.

Gets the format produced by this encoder.

public override ImageFormat Format { get; }

Property value

ImageFormat

Gets the type of the samples, or null (the default) for half samples of RgbaHalf and 8-bit pixels, float samples otherwise. Alpha conversion can round colors independently of this choice.

public OpenExrPixelType? PixelType { get; init; }

Property value

OpenExrPixelType?

Exceptions

ArgumentOutOfRangeException
The value is not a defined OpenExrPixelType.