-
Notifications
You must be signed in to change notification settings - Fork 9
libultrahdr
▸ 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)
Name | Type | Description |
---|---|---|
file |
Uint8Array |
A Jpeg file Uint8Array. |
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
src/libultrahdr/decode-jpeg-metadata.ts:54
▸ 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.
Name | Type |
---|---|
encodingResult |
GainMapMetadata & { gainMap : CompressedImage ; sdr : CompressedImage } |
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'
src/libultrahdr/encode-jpeg-metadata.ts:83
Ƭ JPEGRInfo: Object
Name | Type |
---|---|
height |
number |
width |
number |
libultrahdr-wasm/build/libultrahdr.d.ts:1
Ƭ UltraHDRMetadata: Object
Name | Type |
---|---|
gamma |
number |
hdrCapacityMax |
number |
hdrCapacityMin |
number |
maxContentBoost |
number |
minContentBoost |
number |
offsetHdr |
number |
offsetSdr |
number |
version |
ArrayBuffer | Uint8Array | Uint8ClampedArray | Int8Array | string
|
libultrahdr-wasm/build/libultrahdr.d.ts:6
Ƭ UltraHDRUnpacked: Object
Name | Type |
---|---|
errorMessage |
any |
gainMap |
any |
metadata |
ArrayBuffer | Uint8Array | Uint8ClampedArray | Int8Array | string
|
sdr |
any |
success |
boolean |
libultrahdr-wasm/build/libultrahdr.d.ts:17
▸ getLibrary(): Promise
<MainModule
>
Instances the WASM module and returns it, only one module will be created upon multiple calls.
Promise
<MainModule
>