GainMapMetadata Class

The parameters of a gain map (ISO 21496-1, the hdrgm XMP namespace of Adobe and Ultra HDR): an image stored next to a base image, which gives the gain that turns the base image into an alternate rendition, typically a standard dynamic range photo into its high dynamic range version.

public sealed class GainMapMetadata : IEquatable<GainMapMetadata>

Remarks

The headrooms are in stops: the log2 of the ratio of the peak light of a rendition to the white of standard dynamic range. A display of headroom H shows the base image when H is at most GainMapMetadata.BaseHdrHeadroom, the alternate image when H is at least GainMapMetadata.AlternateHdrHeadroom, and an interpolation in the log domain between them (GainMapMetadata.GetWeight).

A file stores the values as fractions (ISO 21496-1) or decimal numbers (XMP): they are converted to Double, and an Ultra HDR description with a high dynamic range base rendition (BaseRenditionIsHDR) is expressed with the headrooms and the offsets of the base and alternate renditions swapped, which gives the same colors.

Implements

Constructors

NameDescription
GainMapMetadata(double, double, IEnumerable<GainMapChannel>, bool)Initializes a new instance of the GainMapMetadata class.

GainMapMetadata(double, double, IEnumerable<GainMapChannel>, bool)

GainMapMetadata.cs

Initializes a new instance of the GainMapMetadata class.

public GainMapMetadata(double baseHdrHeadroom, double alternateHdrHeadroom, IEnumerable<GainMapChannel> channels, bool useBaseColorSpace = true)

Parameters

baseHdrHeadroom double
The headroom of the base rendition, in stops; 0 for a standard dynamic range base image.
alternateHdrHeadroom double
The headroom of the alternate rendition, in stops.
channels IEnumerable<GainMapChannel>
The parameters of the channels: one, for the three color channels, or three (red, green and blue).
useBaseColorSpace bool
true when the gain applies to the linear colors of the base image, false when it applies to their conversion to the color space of the alternate rendition.

Exceptions

ArgumentNullException
channels or one of its values is null.
ArgumentException
channels does not have one or three values.
ArgumentOutOfRangeException
A headroom is negative or not finite.

Properties

NameDescription
AlternateHdrHeadroomGets the headroom of the alternate rendition, in stops.
BaseHdrHeadroomGets the headroom of the base rendition, in stops; 0 for a standard dynamic range base image.
ChannelsGets the parameters of the channels: one, for the three color channels, or three (red, green and blue).
UseBaseColorSpaceGets a value indicating whether the gain applies to the linear colors of the base image (true), or to their conversion to the color space of the alternate rendition.

AlternateHdrHeadroom

GainMapMetadata.cs

Gets the headroom of the alternate rendition, in stops.

public double AlternateHdrHeadroom { get; }

Property value

double

BaseHdrHeadroom

GainMapMetadata.cs

Gets the headroom of the base rendition, in stops; 0 for a standard dynamic range base image.

public double BaseHdrHeadroom { get; }

Property value

double

Gets the parameters of the channels: one, for the three color channels, or three (red, green and blue).

public IReadOnlyList<GainMapChannel> Channels { get; }

UseBaseColorSpace

GainMapMetadata.cs

Gets a value indicating whether the gain applies to the linear colors of the base image (true), or to their conversion to the color space of the alternate rendition.

public bool UseBaseColorSpace { get; }

Property value

bool

Methods

NameDescription
Apply(Image, Image, double, CancellationToken)Applies a gain map to a base image: computes the rendition of the image for a display of a given headroom, in linear light, with the values above 1 that high dynamic range colors have.
Equals(GainMapMetadata?)Indicates whether the current object is equal to another object of the same type.
Equals(object?)Determines whether the specified object is equal to the current object.
GetHashCode()Serves as the default hash function.
GetWeight(double)Gets how much of the gain a display of a given headroom applies: 0 shows the base rendition, 1 the alternate rendition.
ToString()Returns a string that represents the current object.

Apply(Image, Image, double, CancellationToken)

GainMapMetadata.cs

Applies a gain map to a base image: computes the rendition of the image for a display of a given headroom, in linear light, with the values above 1 that high dynamic range colors have.

public Image<RgbaFloat> Apply(Image baseImage, Image gainMap, double hdrHeadroom, CancellationToken cancellationToken = default)

Parameters

baseImage Image
The base image: its first frame is used.
gainMap Image
The gain map image: its first frame is used. A grayscale image applies its gain to the three channels; it may be smaller than the base image, which it then covers with bilinear interpolation.
hdrHeadroom double
The headroom of the display, in stops (GainMapMetadata.GetWeight).
cancellationToken CancellationToken
The token checked between rows.

Returns

Image<RgbaFloat> A new image of the size of the base image whose colors are linear light, 1 being the white of standard dynamic range, in the primaries of the base image. Nothing is clipped: colors may exceed 1, and an offset may make a channel slightly negative. Alpha is the one of the base image. The metadata is labeled accordingly: linear sRGB primaries are ColorTransferFunction.Linear, the other primaries a CICP description with the linear transfer characteristics (8); the orientation and the EXIF and XMP metadata of the base image are kept.

Exceptions

ArgumentNullException
baseImage or gainMap is null.
ArgumentOutOfRangeException
hdrHeadroom is negative or not finite.
UnsupportedImageFeatureException
The color description of the base image is not one of those above, or GainMapMetadata.UseBaseColorSpace is false: the color space of the alternate rendition is not known here (AuxiliaryImageCollection.DecodeHdr reads it from the file).
ObjectDisposedException
An image is disposed.
ImageResourceLimitException
The result exceeds the allocation limit of the configuration of the base image.
OperationCanceledException
cancellationToken is canceled.

Remarks

The base image is converted to linear light with its color description: an RGB ICC profile whose primaries are those of sRGB, Display P3, DCI-P3 or BT.2020, a CICP description whose transfer characteristics are not high dynamic range ones, the linear transfer function, or else sRGB. The samples of both images are read with 16-bit precision, and the samples of the gain map are its coded values, whatever its color description.

Equals overloads

Equals(GainMapMetadata?)

GainMapMetadata.cs

Indicates whether the current object is equal to another object of the same type.

public bool Equals(GainMapMetadata? other)
Parameters
other GainMapMetadata?
An object to compare with this object.
Returns

bool true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

GainMapMetadata.cs

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)
Parameters
obj object?
The object to compare with the current object.
Returns

bool true if the specified object is equal to the current object; otherwise, false.

GetHashCode()

GainMapMetadata.cs

Serves as the default hash function.

public override int GetHashCode()

Returns

int A hash code for the current object.

GetWeight(double)

GainMapMetadata.cs

Gets how much of the gain a display of a given headroom applies: 0 shows the base rendition, 1 the alternate rendition.

public double GetWeight(double hdrHeadroom)

Parameters

hdrHeadroom double
The headroom of the display, in stops: the log2 of the ratio of its peak light to the white of standard dynamic range (0 for a standard dynamic range display).

Returns

double (hdrHeadroom - BaseHdrHeadroom) / (AlternateHdrHeadroom - BaseHdrHeadroom) clamped to [0, 1]; when the two headrooms are equal, 1 from that headroom on and 0 below it.

Exceptions

ArgumentOutOfRangeException
hdrHeadroom is negative or not finite.

Returns a string that represents the current object.

public override string ToString()

Returns

string A string that represents the current object.