Skip to content

encode.Function.encode

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

@monogrid/gainmap-js / encode / encode

Function: encode()

encode(params): object

Encodes a Gainmap starting from an HDR file.

Parameters

params: EncodingParametersBase

Encoding Parameters

Returns

object

gainMap

gainMap: QuadRenderer<1009, GainMapEncoderMaterial> = gainMapRenderer

getMetadata()

getMetadata: () => GainMapMetadata

Returns

GainMapMetadata

hdr

hdr: DataTexture = dataTexture

sdr

sdr: QuadRenderer<1009, SDRMaterial>

Remarks

if you do not pass a renderer parameter you must manually dispose the result

const encodingResult = await encode({ ... })
// do something with the buffers
const sdr = encodingResult.sdr.getArray()
const gainMap = encodingResult.gainMap.getArray()
// after that
encodingResult.sdr.dispose()
encodingResult.gainMap.dispose()

Example

import { encode, findTextureMinMax } from '@monogrid/gainmap-js'
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 = encode({
  image,
  // this will encode the full HDR range
  maxContentBoost: Math.max.apply(this, textureMax)
})
// can be re-encoded after changing parameters
encodingResult.sdr.material.exposure = 0.9
encodingResult.sdr.render()
// or
encodingResult.gainMap.material.gamma = [1.1, 1.1, 1.1]
encodingResult.gainMap.render()

// do something with encodingResult.gainMap.toArray()
// and encodingResult.sdr.toArray()

// renderers must be manually disposed
encodingResult.sdr.dispose()
encodingResult.gainMap.dispose()

Defined in

src/encode/encode.ts:60

Clone this wiki locally