Class GainMap
An HDR gain map: a small image that, with GainMapInfo, turns an SDR base image into its HDR rendition (or the reverse). Read from Ultra HDR, ISO 21496-1 and Apple JPEG files into GainMap; written back by the JPEG writer. Immutable, so rasters can share it.
public sealed class GainMap
- Inheritance
-
GainMap
- Inherited Members
Examples
// As stored: the SDR base image, with the gain map in the metadata.
using Raster sdr = Raster.Load("ultrahdr.jpg");
GainMap? map = sdr.Metadata.GainMap; // null for a plain JPEG
// The HDR rendition for a display 4x as bright as SDR white: linear half floats, 1.0 = SDR white.
using Raster<RgbaF16> hdr = Raster.Load<RgbaF16>("ultrahdr.jpg", options: new ReaderOptions { Hdr = new HdrDecode { Headroom = 4 } });
// The same from a raster in hand, at the map's full capacity.
using Raster<RgbaF16> full = map!.Apply(sdr);
Constructors
GainMap(GainMapInfo, Raster)
Initializes a gain map from its metadata and image, whose pixels are copied.
public GainMap(GainMapInfo info, Raster image)
Parameters
infoGainMapInfoHow the map applies.
imageRasterThe map: gray for one channel, anything else as three (red, green, blue), 8 bits a sample.
Exceptions
- ArgumentNullException
An argument is null.
Properties
Channels
Gets 1 for a gray map that boosts red, green and blue alike, or 3 for one boost each.
public int Channels { get; }
Property Value
Height
Gets the map's height.
public int Height { get; }
Property Value
Info
Gets how the map applies.
public GainMapInfo Info { get; }
Property Value
Width
Gets the map's width, often a fraction of the base image's.
public int Width { get; }
Property Value
Methods
Apply(Raster, double?)
Returns the rendition of baseImage for a display with headroom (its peak over SDR
white, linear; null for the map's full HDR capacity): linear RgbaF16 with 1.0 as SDR white
(203 cd/m²), in the base image's primaries, with MaxContentLightLevel set from the map's
largest boost. The map is upsampled bilinearly row by row, so no full-size copy of it is made.
public Raster<RgbaF16> Apply(Raster baseImage, double? headroom = null)
Parameters
baseImageRasterThe base image, in its own encoding (usually sRGB), the size the map was made for (it may differ by scale).
headroomdouble?The display headroom, 1 or more, or null for full HDR.
Returns
Examples
// As stored: the SDR base image, with the gain map in the metadata.
using Raster sdr = Raster.Load("ultrahdr.jpg");
GainMap? map = sdr.Metadata.GainMap; // null for a plain JPEG
// The HDR rendition for a display 4x as bright as SDR white: linear half floats, 1.0 = SDR white.
using Raster<RgbaF16> hdr = Raster.Load<RgbaF16>("ultrahdr.jpg", options: new ReaderOptions { Hdr = new HdrDecode { Headroom = 4 } });
// The same from a raster in hand, at the map's full capacity.
using Raster<RgbaF16> full = map!.Apply(sdr);
Exceptions
- ArgumentNullException
baseImageis null.- ArgumentOutOfRangeException
headroomis below 1.
Create(Raster, Raster?, GainMapOptions?)
Computes the gain map that turns sdr into hdr: for each map pixel, the log2 ratio of the
HDR light to the SDR light, averaged over the pixels it covers, stored in 8 bits between the smallest and largest gain.
public static GainMap Create(Raster hdr, Raster? sdr = null, GainMapOptions? options = null)
Parameters
hdrRasterThe HDR rendition: linear light with 1.0 as SDR white (as Radiance, OpenEXR and HDR decodes give), or PQ or HLG with its color profile.
sdrRasterThe SDR rendition to show on SDR displays, the same size; or null to make one with Bt2390, as GainMap does.
optionsGainMapOptionsHow to make the map, or null for the defaults.
Returns
Examples
// An HDR raster as Ultra HDR: the SDR base, tone mapped with BT.2390, and a gain map that brings the HDR raster back.
using Raster<RgbaF32> hdr = Raster.Load<RgbaF32>("render.exr");
hdr.Save("render.jpg", new JpegWriterOptions { Quality = 90, GainMap = new GainMapOptions() });
// Or choose the SDR rendition: the map goes in its metadata, and saving as JPEG writes both.
using Raster<Rgb8> sdr = hdr.Derive(ops => ops.ToneMap(ToneMapping.Reinhard)).As<Rgb8>();
sdr.Metadata.GainMap = GainMap.Create(hdr, sdr, new GainMapOptions { Scale = 4 });
sdr.Save("graded.jpg", new JpegWriterOptions { Quality = 90 });
Exceptions
- ArgumentNullException
hdris null.- ArgumentException
sdris not the size ofhdr.
ToRaster(EgamiContext?)
public Raster ToRaster(EgamiContext? context = null)
Parameters
contextEgamiContext
Returns
- Raster
The map's image.
WithInfo(GainMapInfo)
Returns the same map with other metadata.
public GainMap WithInfo(GainMapInfo info)
Parameters
infoGainMapInfoThe new metadata.
Returns
- GainMap
The map.