Class GainMap

A gain map: a small image saying how much brighter each part of an image gets on an HDR display, as Ultra HDR (JPEG-R) photos from phones carry it. HDR displays show the image boosted by it, the others the image as it is.

Image.decode reads the gain maps of JPEGs, AVIFs and JPEG XLs into Image.gainMap, Image.encodeJPEG, Image.encodeAVIF and Image.encodeJXL write them. The map covers the whole image, at any resolution (phones write a quarter of the width and height). Its value v (0-255, per channel or one for all) boosts the linear light of the image by 2^(gainMapMin + (gainMapMax - gainMapMin) * (v / 255)^(1 / gamma))

Constructors

Properties

gainMapMax: number[]

log2 of the boost of the map's value 255, per channel

gainMapMin: number[]

log2 of the boost of the map's value 0, per channel (red, green, blue)

gamma: number[]

the gamma the map's values are stored with, per channel

hdrCapacityMax: number

log2 of the display headroom at which it applies fully

hdrCapacityMin: number

log2 of the display headroom from which on the map starts to apply

offsetHDR: number[]

subtracted from the HDR result, per channel

offsetSDR: number[]

added to the SDR image's linear values before the boost, per channel

useBaseColorSpace: boolean

whether the boost applies in the SDR image's color space (else in the HDR image's)

Accessors

  • get channels(): 1 | 3

    1 for a grey map (one boost for red, green and blue), 3 for one per channel

    Returns 1 | 3

Methods

  • Decodes a gain map JPEG with its parameters (hdrgm XMP or ISO 21496-1), like the second image in an Ultra HDR JPEG, or the gain map of an Ultra HDR JPEG (or an iPhone's JPEG: its values converted to these parameters)

    Parameters

    Returns Promise<GainMap>

  • Encodes the gain map alone: a JPEG with its parameters (hdrgm XMP and ISO 21496-1), like the second image in an Ultra HDR JPEG

    Parameters

    • Optionalquality: number

      The JPEG quality (1-100). Default: 90

    Returns Promise<Uint8Array<ArrayBufferLike>>