Skip to content

encode.Function.encodeAndCompress

github-actions[bot] edited this page Sep 3, 2024 · 7 revisions

@monogrid/gainmap-js / encode / encodeAndCompress

Function: encodeAndCompress()

encodeAndCompress(params): Promise<object>

Encodes a Gainmap starting from an HDR file into compressed file formats (image/jpeg, image/webp or image/png).

Uses encode internally, then pipes the results to compress.

Parameters

params: EncodingParametersWithCompression

Encoding Parameters

Returns

Promise<object>

gainMap

gainMap: CompressedImage

gainMapMax

gainMapMax: [number, number, number]

This is log2 of max content boost, which is the maximum allowed ratio of the linear luminance for the Target HDR rendition relative to (divided by) that of the SDR image, at a given pixel.

gainMapMin

gainMapMin: [number, number, number]

This is log2 of min content boost, which is the minimum allowed ratio of the linear luminance for the target HDR rendition relative to (divided by) that of the SDR image, at a given pixel.

gamma

gamma: [number, number, number]

This is the gamma to apply to the stored map values.

Default Value

[1, 1, 1]

Remarks

  • Typically you can use a gamma of 1.0.

  • You can use a different value if your gain map has a very uneven distribution of log_recovery(x, y) values.

    For example, this might apply if a gain map has a lot of detail just above SDR range (represented as small log_recovery(x, y) values), and a very large map_max_log2 for the top end of the HDR rendition's desired brightness (represented by large log_recovery(x, y) values). In this case, you can use a map_gamma higher than 1.0 so that recovery(x, y) can precisely encode the detail in both the low end and high end of log_recovery(x, y).

getMetadata()

getMetadata: () => GainMapMetadata

Returns

GainMapMetadata

hdr

hdr: DataTexture = dataTexture

hdrCapacityMax

hdrCapacityMax: number

Stores the value of hdr_capacity_max. This is log2 of the maximum display boost value for which the map is applied completely.

Remarks

  • This value also affects how much to apply the gain map based on the display boost.
  • Must be greater than hdrCapacityMin.
  • Required.

Logarithmic space

hdrCapacityMin

hdrCapacityMin: number

This is log2 of the minimum display boost value for which the map is applied at all.

Remarks

  • This value also affects how much to apply the gain map based on the display boost.
  • Must be 0.0 or greater.

Logarithmic space

offsetHdr

offsetHdr: [number, number, number]

This is the offset to apply to the HDR pixel values during gain map generation and application.

Default Value

[1/64, 1/64, 1/64]

offsetSdr

offsetSdr: [number, number, number]

This is the offset to apply to the SDR pixel values during gain map generation and application

Default Value

[1/64, 1/64, 1/64]

rawGainMap

rawGainMap: Uint8ClampedArray

rawSDR

rawSDR: Uint8ClampedArray

sdr

sdr: CompressedImage

Remarks

if a renderer parameter is not provided This function will automatically dispose its "disposable" renderer, no need to dispose it manually later

Example

import { encodeAndCompress, findTextureMinMax } from '@monogrid/gainmap-js'
import { encodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'

// load an HDR file
const loader = new EXRLoader()
const image = await loader.loadAsync('image.exr')

// find RAW RGB Max value of a texture
const textureMax = await findTextureMinMax(image)

// Encode the gainmap
const encodingResult = await encodeAndCompress({
  image,
  maxContentBoost: Math.max.apply(this, textureMax),
  mimeType: 'image/jpeg'
})

// embed the compressed images + metadata into a single
// JPEG file
const jpeg = await encodeJPEGMetadata({
  ...encodingResult,
  sdr: encodingResult.sdr,
  gainMap: encodingResult.gainMap
})

// `jpeg` will be an `Uint8Array` which can be saved somewhere

Throws

if the browser does not support createImageBitmap

Defined in

src/encode/encode-and-compress.ts:50

Clone this wiki locally