Skip to content
github-actions[bot] edited this page Nov 29, 2023 · 53 revisions

Module: decode

Table of contents

References

Decoding Functions

Loaders

Materials

Specs

Decoding Functions

DecodeParameters

Ƭ DecodeParameters: { gainMap: Texture ; renderTargetOptions?: QuadRendererTextureOptions ; renderer?: WebGLRenderer ; sdr: Texture } & GainmapDecodingParameters & GainMapMetadata

Defined in

src/decode/types.ts:27


decode

decode(params): QuadRenderer<1016, GainMapDecoderMaterial>

Decodes a gain map using a WebGLRenderTarget

Parameters

Name Type
params DecodeParameters

Returns

QuadRenderer<1016, GainMapDecoderMaterial>

Example

import { decode } from '@monogrid/gainmap-js'
import {
  Mesh,
  MeshBasicMaterial,
  PerspectiveCamera,
  PlaneGeometry,
  Scene,
  TextureLoader,
  WebGLRenderer
} from 'three'

const renderer = new WebGLRenderer()

const textureLoader = new TextureLoader()

// load SDR Representation
const sdr = await textureLoader.loadAsync('sdr.jpg')
// load Gain map recovery image
const gainMap = await textureLoader.loadAsync('gainmap.jpg')
// load metadata
const metadata = await (await fetch('metadata.json')).json()

const result = await decode({
  sdr,
  gainMap,
  // this allows to use `result.renderTarget.texture` directly
  renderer,
  // this will restore the full HDR range
  maxDisplayBoost: Math.pow(2, metadata.hdrCapacityMax),
  ...metadata
})

const scene = new Scene()
// `result` can be used to populate a Texture
const mesh = new Mesh(
  new PlaneGeometry(),
  new MeshBasicMaterial({ map: result.renderTarget.texture })
)
scene.add(mesh)
renderer.render(scene, new PerspectiveCamera())

// result must be manually disposed
// when you are done using it
result.dispose()

Throws

if the WebGLRenderer fails to render the gain map

Defined in

src/decode/decode.ts:66


extractGainmapFromJPEG

extractGainmapFromJPEG(jpegFile): Promise<{ gainMap: Uint8Array ; metadata: GainMapMetadata ; sdr: Uint8Array }>

Extracts XMP Metadata and the gain map recovery image from a single JPEG file.

Parameters

Name Type Description
jpegFile Uint8Array an Uint8Array containing and encoded JPEG file

Returns

Promise<{ gainMap: Uint8Array ; metadata: GainMapMetadata ; sdr: Uint8Array }>

an sdr Uint8Array compressed in JPEG, a gainMap Uint8Array compressed in JPEG and the XMP parsed XMP metadata

Throws

Error if XMP Metadata is not found

Throws

Error if Gain map image is not found

Example

import { FileLoader } from 'three'
import { extractGainmapFromJPEG } from '@monogrid/gainmap-js'

const jpegFile = await new FileLoader()
 .setResponseType('arraybuffer')
 .loadAsync('image.jpg')

const { sdr, gainMap, metadata } = extractGainmapFromJPEG(jpegFile)

Defined in

src/decode/extract.ts:25

Other

GainMapMetadata

Re-exports GainMapMetadata


HDRJPGLoader

Renames and re-exports JPEGRLoader


QuadRenderer

Re-exports QuadRenderer


QuadRendererOptions

Re-exports QuadRendererOptions


QuadRendererTextureOptions

Re-exports QuadRendererTextureOptions


TextureDataTypeToBufferType

Re-exports TextureDataTypeToBufferType

Specs

GainmapDecodingParameters

Ƭ GainmapDecodingParameters: Object

Necessary parameters for decoding a Gainmap

Type declaration

Name Type Description
maxDisplayBoost number The maximum available boost supported by a display, at a given point in time. Remarks This value can change over time based on device settings and other factors, such as ambient light conditions, or how many bright pixels are on the screen. Non Logarithmic space

Defined in

src/decode/types.ts:11

Clone this wiki locally