-
Notifications
You must be signed in to change notification settings - Fork 5
encode.Function.encodeAndCompress
@monogrid/gainmap-js / encode / 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.
• params: EncodingParametersWithCompression
Encoding Parameters
Promise
<object
>
gainMap:
CompressedImage
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: [
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: [
number
,number
,number
]
This is the gamma to apply to the stored map values.
[1, 1, 1]
-
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: () =>
GainMapMetadata
hdr:
DataTexture
=dataTexture
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.
- 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:
number
This is log2 of the minimum display boost value for which the map is applied at all.
- 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: [
number
,number
,number
]
This is the offset to apply to the HDR pixel values during gain map generation and application.
[1/64, 1/64, 1/64]
offsetSdr: [
number
,number
,number
]
This is the offset to apply to the SDR pixel values during gain map generation and application
[1/64, 1/64, 1/64]
rawGainMap:
Uint8ClampedArray
rawSDR:
Uint8ClampedArray
sdr:
CompressedImage
if a renderer
parameter is not provided
This function will automatically dispose its "disposable"
renderer, no need to dispose it manually later
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
if the browser does not support createImageBitmap