Skip to content

libultrahdr

github-actions[bot] edited this page Feb 6, 2024 · 93 revisions

Module: libultrahdr

Table of contents

Interfaces

Type Aliases

Decoding

Encoding

WASM

Decoding

decodeJPEGMetadata

decodeJPEGMetadata(file): Promise<{ errorMessage: any ; gainMap: any ; metadata: string | Uint8ClampedArray | Int8Array | ArrayBuffer | Uint8Array ; parsedMetadata: GainMapMetadata ; sdr: any ; success: boolean }>

Decodes a JPEG file with an embedded Gainmap and XMP Metadata (aka JPEG-R)

Parameters

Name Type Description
file Uint8Array A Jpeg file Uint8Array.

Returns

Promise<{ errorMessage: any ; gainMap: any ; metadata: string | Uint8ClampedArray | Int8Array | ArrayBuffer | Uint8Array ; parsedMetadata: GainMapMetadata ; sdr: any ; success: boolean }>

The decoded data

Deprecated

Example

import { decodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'

// fetch a JPEG image containing a gainmap as ArrayBuffer
const gainmap = new Uint8Array(await (await fetch('gainmap.jpeg')).arrayBuffer())

// extract data from the JPEG
const { gainMap, sdr, parsedMetadata } = await decodeJPEGMetadata(gainmap)

Throws

if the provided file cannot be parsed or does not contain a valid Gainmap

Defined in

src/libultrahdr/decode-jpeg-metadata.ts:54

Encoding

encodeJPEGMetadata

encodeJPEGMetadata(encodingResult): Promise<Uint8Array>

Encapsulates a Gainmap into a single JPEG file (aka: JPEG-R) with the base map as the sdr visualization and the gainMap encoded into a MPF (Multi-Picture Format) tag.

Parameters

Name Type
encodingResult GainMapMetadata & { gainMap: CompressedImage ; sdr: CompressedImage }

Returns

Promise<Uint8Array>

an Uint8Array representing a JPEG-R file

Example

import { compress, encode, 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 = encode({
  image,
  maxContentBoost: Math.max.apply(this, textureMax)
})

// obtain the RAW RGBA SDR buffer and create an ImageData
const sdrImageData = new ImageData(
  encodingResult.sdr.toArray(),
  encodingResult.sdr.width,
  encodingResult.sdr.height
)
// obtain the RAW RGBA Gain map buffer and create an ImageData
const gainMapImageData = new ImageData(
  encodingResult.gainMap.toArray(),
  encodingResult.gainMap.width,
  encodingResult.gainMap.height
)

// parallel compress the RAW buffers into the specified mimeType
const mimeType = 'image/jpeg'
const quality = 0.9

const [sdr, gainMap] = await Promise.all([
  compress({
    source: sdrImageData,
    mimeType,
    quality,
    flipY: true // output needs to be flipped
  }),
  compress({
    source: gainMapImageData,
    mimeType,
    quality,
    flipY: true // output needs to be flipped
  })
])

// obtain the metadata which will be embedded into
// and XMP tag inside the final JPEG file
const metadata = encodingResult.getMetadata()

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

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

Throws

If encodingResult.sdr.mimeType !== 'image/jpeg'

Throws

If encodingResult.gainMap.mimeType !== 'image/jpeg'

Defined in

src/libultrahdr/encode-jpeg-metadata.ts:83

Other

JPEGRInfo

Ƭ JPEGRInfo: Object

Type declaration

Name Type
height number
width number

Defined in

libultrahdr-wasm/build/libultrahdr.d.ts:1


UltraHDRMetadata

Ƭ UltraHDRMetadata: Object

Type declaration

Name Type
gamma number
hdrCapacityMax number
hdrCapacityMin number
maxContentBoost number
minContentBoost number
offsetHdr number
offsetSdr number
version ArrayBuffer | Uint8Array | Uint8ClampedArray | Int8Array | string

Defined in

libultrahdr-wasm/build/libultrahdr.d.ts:6


UltraHDRUnpacked

Ƭ UltraHDRUnpacked: Object

Type declaration

Name Type
errorMessage any
gainMap any
metadata ArrayBuffer | Uint8Array | Uint8ClampedArray | Int8Array | string
sdr any
success boolean

Defined in

libultrahdr-wasm/build/libultrahdr.d.ts:17

WASM

getLibrary

getLibrary(): Promise<MainModule>

Instances the WASM module and returns it, only one module will be created upon multiple calls.

Returns

Promise<MainModule>

Defined in

src/libultrahdr/library.ts:14

Clone this wiki locally