@monogrid/gainmap-js 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/{LoaderBase-aa4842c4.js → LoaderBase-eee19701.js} +13 -4
- package/dist/_commonjsHelpers-1789f0cf.js +1 -1
- package/dist/compress-a4b59cab.js +1 -1
- package/dist/encode-utils/get-sdr-rendition.d.ts +2 -2
- package/dist/encode.d.ts +3 -3
- package/dist/index.js +22 -18
- package/dist/index.umd.js +30 -17
- package/dist/libultrahdr/decode-jpeg-metadata.d.ts +31 -0
- package/dist/libultrahdr/encode-jpeg-metadata.d.ts +83 -0
- package/dist/libultrahdr/library.d.ts +9 -0
- package/dist/libultrahdr.d.ts +3 -122
- package/dist/libultrahdr.js +158 -156
- package/dist/libultrahdr.umd.js +205 -194
- package/dist/loaders/GainMapLoader.d.ts +2 -2
- package/dist/loaders/JPEGRLoader.d.ts +1 -1
- package/dist/types.d.ts +21 -11
- package/dist/utils/QuadRenderer.d.ts +6 -0
- package/dist/worker-interface.js +1 -1
- package/dist/worker-interface.umd.js +1 -1
- package/dist/worker-types.d.ts +1 -1
- package/dist/worker.js +1 -1
- package/dist/worker.umd.js +1 -1
- package/package.json +1 -1
package/dist/libultrahdr.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js v1.0
|
|
2
|
+
* @monogrid/gainmap-js v1.1.0
|
|
3
3
|
* With ❤️, by MONOGRID <hello@mono-grid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -6506,6 +6506,198 @@
|
|
|
6506
6506
|
})();
|
|
6507
6507
|
var libultrahdr = Module;
|
|
6508
6508
|
|
|
6509
|
+
// @ts-expect-error untyped
|
|
6510
|
+
let library;
|
|
6511
|
+
/**
|
|
6512
|
+
* Instances the WASM module and returns it, only one module will be created upon multiple calls.
|
|
6513
|
+
* @category General
|
|
6514
|
+
* @group General
|
|
6515
|
+
*
|
|
6516
|
+
* @returns
|
|
6517
|
+
*/
|
|
6518
|
+
const getLibrary = async () => {
|
|
6519
|
+
if (!library) {
|
|
6520
|
+
library = await libultrahdr();
|
|
6521
|
+
}
|
|
6522
|
+
return library;
|
|
6523
|
+
};
|
|
6524
|
+
|
|
6525
|
+
/**
|
|
6526
|
+
*
|
|
6527
|
+
* @param description
|
|
6528
|
+
* @param name
|
|
6529
|
+
* @param defaultValue
|
|
6530
|
+
* @returns
|
|
6531
|
+
*/
|
|
6532
|
+
const getAttribute = (description, name, defaultValue) => {
|
|
6533
|
+
var _a;
|
|
6534
|
+
let returnValue;
|
|
6535
|
+
const parsedValue = (_a = description.attributes.getNamedItem(name)) === null || _a === void 0 ? void 0 : _a.nodeValue;
|
|
6536
|
+
if (!parsedValue) {
|
|
6537
|
+
const node = description.getElementsByTagName(name)[0];
|
|
6538
|
+
if (node) {
|
|
6539
|
+
const values = node.getElementsByTagName('rdf:li');
|
|
6540
|
+
if (values.length === 3) {
|
|
6541
|
+
returnValue = Array.from(values).map(v => v.innerHTML);
|
|
6542
|
+
}
|
|
6543
|
+
else {
|
|
6544
|
+
throw new Error(`Gainmap metadata contains an array of items for ${name} but its length is not 3`);
|
|
6545
|
+
}
|
|
6546
|
+
}
|
|
6547
|
+
else {
|
|
6548
|
+
if (defaultValue)
|
|
6549
|
+
return defaultValue;
|
|
6550
|
+
else
|
|
6551
|
+
throw new Error(`Can't find ${name} in gainmap metadata`);
|
|
6552
|
+
}
|
|
6553
|
+
}
|
|
6554
|
+
else {
|
|
6555
|
+
returnValue = parsedValue;
|
|
6556
|
+
}
|
|
6557
|
+
return returnValue;
|
|
6558
|
+
};
|
|
6559
|
+
/**
|
|
6560
|
+
* Decodes a JPEG file with an embedded Gainmap and XMP Metadata (aka JPEG-R)
|
|
6561
|
+
*
|
|
6562
|
+
* @category Decoding
|
|
6563
|
+
* @group Decoding
|
|
6564
|
+
*
|
|
6565
|
+
* @example
|
|
6566
|
+
* import { decodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
|
|
6567
|
+
*
|
|
6568
|
+
* // fetch a JPEG image containing a gainmap as ArrayBuffer
|
|
6569
|
+
* const gainmap = new Uint8Array(await (await fetch('gainmap.jpeg')).arrayBuffer())
|
|
6570
|
+
*
|
|
6571
|
+
* // extract data from the JPEG
|
|
6572
|
+
* const { gainMap, sdr, parsedMetadata } = await decodeJPEGMetadata(gainmap)
|
|
6573
|
+
*
|
|
6574
|
+
* @param file A Jpeg file Uint8Array.
|
|
6575
|
+
* @returns The decoded data
|
|
6576
|
+
* @throws {Error} if the provided file cannot be parsed or does not contain a valid Gainmap
|
|
6577
|
+
*/
|
|
6578
|
+
const decodeJPEGMetadata = async (file) => {
|
|
6579
|
+
var _a, _b;
|
|
6580
|
+
const lib = await getLibrary();
|
|
6581
|
+
const result = lib.extractJpegR(file, file.length);
|
|
6582
|
+
if (!result.success)
|
|
6583
|
+
throw new Error(result.errorMessage);
|
|
6584
|
+
const parser = new DOMParser();
|
|
6585
|
+
const xmlDocument = parser.parseFromString(result.metadata, 'text/xml');
|
|
6586
|
+
const description = xmlDocument.getElementsByTagName('rdf:Description')[0];
|
|
6587
|
+
const gainMapMin = getAttribute(description, 'hdrgm:GainMapMin', '0');
|
|
6588
|
+
const gainMapMax = getAttribute(description, 'hdrgm:GainMapMax');
|
|
6589
|
+
const gamma = getAttribute(description, 'hdrgm:Gamma', '1');
|
|
6590
|
+
const offsetSDR = getAttribute(description, 'hdrgm:OffsetSDR', '0.015625');
|
|
6591
|
+
const offsetHDR = getAttribute(description, 'hdrgm:OffsetHDR', '0.015625');
|
|
6592
|
+
let hdrCapacityMin = (_a = description.attributes.getNamedItem('hdrgm:HDRCapacityMin')) === null || _a === void 0 ? void 0 : _a.nodeValue;
|
|
6593
|
+
if (!hdrCapacityMin)
|
|
6594
|
+
hdrCapacityMin = '0';
|
|
6595
|
+
const hdrCapacityMax = (_b = description.attributes.getNamedItem('hdrgm:HDRCapacityMax')) === null || _b === void 0 ? void 0 : _b.nodeValue;
|
|
6596
|
+
if (!hdrCapacityMax)
|
|
6597
|
+
throw new Error('Incomplete gainmap metadata');
|
|
6598
|
+
const parsedMetadata = {
|
|
6599
|
+
gainMapMin: Array.isArray(gainMapMin) ? gainMapMin.map(v => parseFloat(v)) : [parseFloat(gainMapMin), parseFloat(gainMapMin), parseFloat(gainMapMin)],
|
|
6600
|
+
gainMapMax: Array.isArray(gainMapMax) ? gainMapMax.map(v => parseFloat(v)) : [parseFloat(gainMapMax), parseFloat(gainMapMax), parseFloat(gainMapMax)],
|
|
6601
|
+
gamma: Array.isArray(gamma) ? gamma.map(v => parseFloat(v)) : [parseFloat(gamma), parseFloat(gamma), parseFloat(gamma)],
|
|
6602
|
+
offsetSdr: Array.isArray(offsetSDR) ? offsetSDR.map(v => parseFloat(v)) : [parseFloat(offsetSDR), parseFloat(offsetSDR), parseFloat(offsetSDR)],
|
|
6603
|
+
offsetHdr: Array.isArray(offsetHDR) ? offsetHDR.map(v => parseFloat(v)) : [parseFloat(offsetHDR), parseFloat(offsetHDR), parseFloat(offsetHDR)],
|
|
6604
|
+
hdrCapacityMin: parseFloat(hdrCapacityMin),
|
|
6605
|
+
hdrCapacityMax: parseFloat(hdrCapacityMax)
|
|
6606
|
+
};
|
|
6607
|
+
return Object.assign(Object.assign({}, result), {
|
|
6608
|
+
/**
|
|
6609
|
+
* Parsed metadata
|
|
6610
|
+
*/
|
|
6611
|
+
parsedMetadata });
|
|
6612
|
+
};
|
|
6613
|
+
|
|
6614
|
+
/**
|
|
6615
|
+
* Encapsulates a Gainmap into a single JPEG file (aka: JPEG-R) with the base map
|
|
6616
|
+
* as the sdr visualization and the gainMap encoded into a MPF (Multi-Picture Format) tag.
|
|
6617
|
+
*
|
|
6618
|
+
* @category Encoding
|
|
6619
|
+
* @group Encoding
|
|
6620
|
+
*
|
|
6621
|
+
* @example
|
|
6622
|
+
* import { compress, encode, findTextureMinMax } from '@monogrid/gainmap-js'
|
|
6623
|
+
* import { encodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
|
|
6624
|
+
* import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'
|
|
6625
|
+
*
|
|
6626
|
+
* // load an HDR file
|
|
6627
|
+
* const loader = new EXRLoader()
|
|
6628
|
+
* const image = await loader.loadAsync('image.exr')
|
|
6629
|
+
*
|
|
6630
|
+
* // find RAW RGB Max value of a texture
|
|
6631
|
+
* const textureMax = await findTextureMinMax(image)
|
|
6632
|
+
*
|
|
6633
|
+
* // Encode the gainmap
|
|
6634
|
+
* const encodingResult = encode({
|
|
6635
|
+
* image,
|
|
6636
|
+
* maxContentBoost: Math.max.apply(this, textureMax)
|
|
6637
|
+
* })
|
|
6638
|
+
*
|
|
6639
|
+
* // obtain the RAW RGBA SDR buffer and create an ImageData
|
|
6640
|
+
* const sdrImageData = new ImageData(
|
|
6641
|
+
* encodingResult.sdr.toArray(),
|
|
6642
|
+
* encodingResult.sdr.width,
|
|
6643
|
+
* encodingResult.sdr.height
|
|
6644
|
+
* )
|
|
6645
|
+
* // obtain the RAW RGBA Gain map buffer and create an ImageData
|
|
6646
|
+
* const gainMapImageData = new ImageData(
|
|
6647
|
+
* encodingResult.gainMap.toArray(),
|
|
6648
|
+
* encodingResult.gainMap.width,
|
|
6649
|
+
* encodingResult.gainMap.height
|
|
6650
|
+
* )
|
|
6651
|
+
*
|
|
6652
|
+
* // parallel compress the RAW buffers into the specified mimeType
|
|
6653
|
+
* const mimeType = 'image/jpeg'
|
|
6654
|
+
* const quality = 0.9
|
|
6655
|
+
*
|
|
6656
|
+
* const [sdr, gainMap] = await Promise.all([
|
|
6657
|
+
* compress({
|
|
6658
|
+
* source: sdrImageData,
|
|
6659
|
+
* mimeType,
|
|
6660
|
+
* quality,
|
|
6661
|
+
* flipY: true // output needs to be flipped
|
|
6662
|
+
* }),
|
|
6663
|
+
* compress({
|
|
6664
|
+
* source: gainMapImageData,
|
|
6665
|
+
* mimeType,
|
|
6666
|
+
* quality,
|
|
6667
|
+
* flipY: true // output needs to be flipped
|
|
6668
|
+
* })
|
|
6669
|
+
* ])
|
|
6670
|
+
*
|
|
6671
|
+
* // obtain the metadata which will be embedded into
|
|
6672
|
+
* // and XMP tag inside the final JPEG file
|
|
6673
|
+
* const metadata = encodingResult.getMetadata()
|
|
6674
|
+
*
|
|
6675
|
+
* // embed the compressed images + metadata into a single
|
|
6676
|
+
* // JPEG file
|
|
6677
|
+
* const jpeg = await encodeJPEGMetadata({
|
|
6678
|
+
* ...encodingResult,
|
|
6679
|
+
* ...metadata,
|
|
6680
|
+
* sdr,
|
|
6681
|
+
* gainMap
|
|
6682
|
+
* })
|
|
6683
|
+
*
|
|
6684
|
+
* // `jpeg` will be an `Uint8Array` which can be saved somewhere
|
|
6685
|
+
*
|
|
6686
|
+
*
|
|
6687
|
+
* @param encodingResult
|
|
6688
|
+
* @returns an Uint8Array representing a JPEG-R file
|
|
6689
|
+
* @throws {Error} If `encodingResult.sdr.mimeType !== 'image/jpeg'`
|
|
6690
|
+
* @throws {Error} If `encodingResult.gainMap.mimeType !== 'image/jpeg'`
|
|
6691
|
+
*/
|
|
6692
|
+
const encodeJPEGMetadata = async (encodingResult) => {
|
|
6693
|
+
const lib = await getLibrary();
|
|
6694
|
+
if (encodingResult.sdr.mimeType !== 'image/jpeg')
|
|
6695
|
+
throw new Error('This function expects an SDR image compressed in jpeg');
|
|
6696
|
+
if (encodingResult.gainMap.mimeType !== 'image/jpeg')
|
|
6697
|
+
throw new Error('This function expects a GainMap image compressed in jpeg');
|
|
6698
|
+
return lib.appendGainMap(encodingResult.sdr.width, encodingResult.sdr.height, encodingResult.sdr.data, encodingResult.sdr.data.length, encodingResult.gainMap.data, encodingResult.gainMap.data.length, encodingResult.gainMapMax.reduce((p, n) => p + n, 0) / encodingResult.gainMapMax.length, encodingResult.gainMapMin.reduce((p, n) => p + n, 0) / encodingResult.gainMapMin.length, encodingResult.gamma.reduce((p, n) => p + n, 0) / encodingResult.gamma.length, encodingResult.offsetSdr.reduce((p, n) => p + n, 0) / encodingResult.offsetSdr.length, encodingResult.offsetHdr.reduce((p, n) => p + n, 0) / encodingResult.offsetHdr.length, encodingResult.hdrCapacityMin, encodingResult.hdrCapacityMax);
|
|
6699
|
+
};
|
|
6700
|
+
|
|
6509
6701
|
const vertexShader = /* glsl */ `
|
|
6510
6702
|
varying vec2 vUv;
|
|
6511
6703
|
|
|
@@ -6673,6 +6865,10 @@ void main() {
|
|
|
6673
6865
|
this._width = width;
|
|
6674
6866
|
this._height = height;
|
|
6675
6867
|
this._type = type;
|
|
6868
|
+
this._colorSpace = colorSpace;
|
|
6869
|
+
if (type === three.HalfFloatType && navigator.userAgent.toLowerCase().includes('firefox')) {
|
|
6870
|
+
this._type = three.FloatType;
|
|
6871
|
+
}
|
|
6676
6872
|
this._material = material;
|
|
6677
6873
|
if (renderer) {
|
|
6678
6874
|
this._renderer = renderer;
|
|
@@ -6693,7 +6889,7 @@ void main() {
|
|
|
6693
6889
|
this._quad.geometry.computeBoundingBox();
|
|
6694
6890
|
this._scene.add(this._quad);
|
|
6695
6891
|
this._renderTarget = new three.WebGLRenderTarget(width, height, {
|
|
6696
|
-
type,
|
|
6892
|
+
type: this._type,
|
|
6697
6893
|
colorSpace,
|
|
6698
6894
|
format: three.RGBAFormat,
|
|
6699
6895
|
magFilter: three.LinearFilter,
|
|
@@ -6755,7 +6951,7 @@ void main() {
|
|
|
6755
6951
|
return out;
|
|
6756
6952
|
}
|
|
6757
6953
|
toDataTexture() {
|
|
6758
|
-
return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat,
|
|
6954
|
+
return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat, this._type, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, 1, three.NoColorSpace);
|
|
6759
6955
|
}
|
|
6760
6956
|
/**
|
|
6761
6957
|
* If using a disposable renderer, it will dispose it.
|
|
@@ -6801,6 +6997,11 @@ void main() {
|
|
|
6801
6997
|
* The `Material` used.
|
|
6802
6998
|
*/
|
|
6803
6999
|
get material() { return this._material; }
|
|
7000
|
+
/**
|
|
7001
|
+
*
|
|
7002
|
+
*/
|
|
7003
|
+
get type() { return this._type; }
|
|
7004
|
+
get colorSpace() { return this._colorSpace; }
|
|
6804
7005
|
}
|
|
6805
7006
|
|
|
6806
7007
|
class LoaderBase extends three.Loader {
|
|
@@ -6907,7 +7108,7 @@ void main() {
|
|
|
6907
7108
|
*
|
|
6908
7109
|
* // `result.renderTarget.texture` must be
|
|
6909
7110
|
* // converted to `DataTexture` in order
|
|
6910
|
-
* // to use it as
|
|
7111
|
+
* // to use it as Equirectangular scene background
|
|
6911
7112
|
* // if needed
|
|
6912
7113
|
*
|
|
6913
7114
|
* scene.background = result.toDataTexture()
|
|
@@ -6945,196 +7146,6 @@ void main() {
|
|
|
6945
7146
|
}
|
|
6946
7147
|
}
|
|
6947
7148
|
|
|
6948
|
-
// @ts-expect-error untyped
|
|
6949
|
-
let library;
|
|
6950
|
-
/**
|
|
6951
|
-
* Instances the WASM module and returns it, only one module will be created upon multiple calls.
|
|
6952
|
-
* @category General
|
|
6953
|
-
* @group General
|
|
6954
|
-
*
|
|
6955
|
-
* @returns
|
|
6956
|
-
*/
|
|
6957
|
-
const getLibrary = async () => {
|
|
6958
|
-
if (!library) {
|
|
6959
|
-
library = await libultrahdr();
|
|
6960
|
-
}
|
|
6961
|
-
return library;
|
|
6962
|
-
};
|
|
6963
|
-
/**
|
|
6964
|
-
* Encapsulates a Gainmap into a single JPEG file (aka: JPEG-R) with the base map
|
|
6965
|
-
* as the sdr visualization and the gainMap encoded into a MPF (Multi-Picture Format) tag.
|
|
6966
|
-
*
|
|
6967
|
-
* @category Encoding
|
|
6968
|
-
* @group Encoding
|
|
6969
|
-
*
|
|
6970
|
-
* @example
|
|
6971
|
-
* import { compress, encode, findTextureMinMax } from '@monogrid/gainmap-js'
|
|
6972
|
-
* import { encodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
|
|
6973
|
-
* import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'
|
|
6974
|
-
*
|
|
6975
|
-
* // load an HDR file
|
|
6976
|
-
* const loader = new EXRLoader()
|
|
6977
|
-
* const image = await loader.loadAsync('image.exr')
|
|
6978
|
-
*
|
|
6979
|
-
* // find RAW RGB Max value of a texture
|
|
6980
|
-
* const textureMax = await findTextureMinMax(image)
|
|
6981
|
-
*
|
|
6982
|
-
* // Encode the gainmap
|
|
6983
|
-
* const encodingResult = encode({
|
|
6984
|
-
* image,
|
|
6985
|
-
* maxContentBoost: Math.max.apply(this, textureMax)
|
|
6986
|
-
* })
|
|
6987
|
-
*
|
|
6988
|
-
* // obtain the RAW RGBA SDR buffer and create an ImageData
|
|
6989
|
-
* const sdrImageData = new ImageData(
|
|
6990
|
-
* encodingResult.sdr.toArray(),
|
|
6991
|
-
* encodingResult.sdr.width,
|
|
6992
|
-
* encodingResult.sdr.height
|
|
6993
|
-
* )
|
|
6994
|
-
* // obtain the RAW RGBA Gain map buffer and create an ImageData
|
|
6995
|
-
* const gainMapImageData = new ImageData(
|
|
6996
|
-
* encodingResult.gainMap.toArray(),
|
|
6997
|
-
* encodingResult.gainMap.width,
|
|
6998
|
-
* encodingResult.gainMap.height
|
|
6999
|
-
* )
|
|
7000
|
-
*
|
|
7001
|
-
* // parallel compress the RAW buffers into the specified mimeType
|
|
7002
|
-
* const mimeType = 'image/jpeg'
|
|
7003
|
-
* const quality = 0.9
|
|
7004
|
-
*
|
|
7005
|
-
* const [sdr, gainMap] = await Promise.all([
|
|
7006
|
-
* compress({
|
|
7007
|
-
* source: sdrImageData,
|
|
7008
|
-
* mimeType,
|
|
7009
|
-
* quality,
|
|
7010
|
-
* flipY: true // output needs to be flipped
|
|
7011
|
-
* }),
|
|
7012
|
-
* compress({
|
|
7013
|
-
* source: gainMapImageData,
|
|
7014
|
-
* mimeType,
|
|
7015
|
-
* quality,
|
|
7016
|
-
* flipY: true // output needs to be flipped
|
|
7017
|
-
* })
|
|
7018
|
-
* ])
|
|
7019
|
-
*
|
|
7020
|
-
* // obtain the metadata which will be embedded into
|
|
7021
|
-
* // and XMP tag inside the final JPEG file
|
|
7022
|
-
* const metadata = encodingResult.getMetadata()
|
|
7023
|
-
*
|
|
7024
|
-
* // embed the compressed images + metadata into a single
|
|
7025
|
-
* // JPEG file
|
|
7026
|
-
* const jpeg = await encodeJPEGMetadata({
|
|
7027
|
-
* ...encodingResult,
|
|
7028
|
-
* ...metadata,
|
|
7029
|
-
* sdr,
|
|
7030
|
-
* gainMap
|
|
7031
|
-
* })
|
|
7032
|
-
*
|
|
7033
|
-
* // `jpeg` will be an `Uint8Array` which can be saved somewhere
|
|
7034
|
-
*
|
|
7035
|
-
*
|
|
7036
|
-
* @param encodingResult
|
|
7037
|
-
* @returns an Uint8Array representing a JPEG-R file
|
|
7038
|
-
* @throws {Error} If `encodingResult.sdr.mimeType !== 'image/jpeg'`
|
|
7039
|
-
* @throws {Error} If `encodingResult.gainMap.mimeType !== 'image/jpeg'`
|
|
7040
|
-
*/
|
|
7041
|
-
const encodeJPEGMetadata = async (encodingResult) => {
|
|
7042
|
-
const lib = await getLibrary();
|
|
7043
|
-
if (encodingResult.sdr.mimeType !== 'image/jpeg')
|
|
7044
|
-
throw new Error('This function expects an SDR image compressed in jpeg');
|
|
7045
|
-
if (encodingResult.gainMap.mimeType !== 'image/jpeg')
|
|
7046
|
-
throw new Error('This function expects a GainMap image compressed in jpeg');
|
|
7047
|
-
return lib.appendGainMap(encodingResult.sdr.width, encodingResult.sdr.height, encodingResult.sdr.data, encodingResult.sdr.data.length, encodingResult.gainMap.data, encodingResult.gainMap.data.length, encodingResult.gainMapMax.reduce((p, n) => p + n, 0) / encodingResult.gainMapMax.length, encodingResult.gainMapMin.reduce((p, n) => p + n, 0) / encodingResult.gainMapMin.length, encodingResult.gamma.reduce((p, n) => p + n, 0) / encodingResult.gamma.length, encodingResult.offsetSdr.reduce((p, n) => p + n, 0) / encodingResult.offsetSdr.length, encodingResult.offsetHdr.reduce((p, n) => p + n, 0) / encodingResult.offsetHdr.length, encodingResult.hdrCapacityMin, encodingResult.hdrCapacityMax);
|
|
7048
|
-
};
|
|
7049
|
-
/**
|
|
7050
|
-
*
|
|
7051
|
-
* @param description
|
|
7052
|
-
* @param name
|
|
7053
|
-
* @param defaultValue
|
|
7054
|
-
* @returns
|
|
7055
|
-
*/
|
|
7056
|
-
const getAttribute = (description, name, defaultValue) => {
|
|
7057
|
-
var _a;
|
|
7058
|
-
let returnValue;
|
|
7059
|
-
const parsedValue = (_a = description.attributes.getNamedItem(name)) === null || _a === void 0 ? void 0 : _a.nodeValue;
|
|
7060
|
-
if (!parsedValue) {
|
|
7061
|
-
const node = description.getElementsByTagName(name)[0];
|
|
7062
|
-
if (node) {
|
|
7063
|
-
const values = node.getElementsByTagName('rdf:li');
|
|
7064
|
-
if (values.length === 3) {
|
|
7065
|
-
returnValue = Array.from(values).map(v => v.innerHTML);
|
|
7066
|
-
}
|
|
7067
|
-
else {
|
|
7068
|
-
throw new Error(`Gainmap metadata contains an array of items for ${name} but its length is not 3`);
|
|
7069
|
-
}
|
|
7070
|
-
}
|
|
7071
|
-
else {
|
|
7072
|
-
if (defaultValue)
|
|
7073
|
-
return defaultValue;
|
|
7074
|
-
else
|
|
7075
|
-
throw new Error(`Can't find ${name} in gainmap metadata`);
|
|
7076
|
-
}
|
|
7077
|
-
}
|
|
7078
|
-
else {
|
|
7079
|
-
returnValue = parsedValue;
|
|
7080
|
-
}
|
|
7081
|
-
return returnValue;
|
|
7082
|
-
};
|
|
7083
|
-
/**
|
|
7084
|
-
* Decodes a JPEG file with an embedded Gainmap and XMP Metadata (aka JPEG-R)
|
|
7085
|
-
*
|
|
7086
|
-
* @category Decoding
|
|
7087
|
-
* @group Decoding
|
|
7088
|
-
*
|
|
7089
|
-
* @example
|
|
7090
|
-
* import { decodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
|
|
7091
|
-
*
|
|
7092
|
-
* // fetch a JPEG image containing a gainmap as ArrayBuffer
|
|
7093
|
-
* const gainmap = new Uint8Array(await (await fetch('gainmap.jpeg')).arrayBuffer())
|
|
7094
|
-
*
|
|
7095
|
-
* // extract data from the JPEG
|
|
7096
|
-
* const { gainMap, sdr, parsedMetadata } = await decodeJPEGMetadata(gainmap)
|
|
7097
|
-
*
|
|
7098
|
-
* @param file A Jpeg file Uint8Array.
|
|
7099
|
-
* @returns The decoded data
|
|
7100
|
-
* @throws {Error} if the provided file cannot be parsed or does not contain a valid Gainmap
|
|
7101
|
-
*/
|
|
7102
|
-
const decodeJPEGMetadata = async (file) => {
|
|
7103
|
-
var _a, _b;
|
|
7104
|
-
const lib = await getLibrary();
|
|
7105
|
-
const result = lib.extractJpegR(file, file.length);
|
|
7106
|
-
if (!result.success)
|
|
7107
|
-
throw new Error(result.errorMessage);
|
|
7108
|
-
const parser = new DOMParser();
|
|
7109
|
-
const xmldocuemnt = parser.parseFromString(result.metadata, 'text/xml');
|
|
7110
|
-
const description = xmldocuemnt.getElementsByTagName('rdf:Description')[0];
|
|
7111
|
-
const gainMapMin = getAttribute(description, 'hdrgm:GainMapMin', '0');
|
|
7112
|
-
const gainMapMax = getAttribute(description, 'hdrgm:GainMapMax');
|
|
7113
|
-
const gamma = getAttribute(description, 'hdrgm:Gamma', '1');
|
|
7114
|
-
const offsetSDR = getAttribute(description, 'hdrgm:OffsetSDR', '0.015625');
|
|
7115
|
-
const offsetHDR = getAttribute(description, 'hdrgm:OffsetHDR', '0.015625');
|
|
7116
|
-
let hdrCapacityMin = (_a = description.attributes.getNamedItem('hdrgm:HDRCapacityMin')) === null || _a === void 0 ? void 0 : _a.nodeValue;
|
|
7117
|
-
if (!hdrCapacityMin)
|
|
7118
|
-
hdrCapacityMin = '0';
|
|
7119
|
-
const hdrCapacityMax = (_b = description.attributes.getNamedItem('hdrgm:HDRCapacityMax')) === null || _b === void 0 ? void 0 : _b.nodeValue;
|
|
7120
|
-
if (!hdrCapacityMax)
|
|
7121
|
-
throw new Error('Incomplete gainmap metadata');
|
|
7122
|
-
const parsedMetadata = {
|
|
7123
|
-
gainMapMin: Array.isArray(gainMapMin) ? gainMapMin.map(v => parseFloat(v)) : [parseFloat(gainMapMin), parseFloat(gainMapMin), parseFloat(gainMapMin)],
|
|
7124
|
-
gainMapMax: Array.isArray(gainMapMax) ? gainMapMax.map(v => parseFloat(v)) : [parseFloat(gainMapMax), parseFloat(gainMapMax), parseFloat(gainMapMax)],
|
|
7125
|
-
gamma: Array.isArray(gamma) ? gamma.map(v => parseFloat(v)) : [parseFloat(gamma), parseFloat(gamma), parseFloat(gamma)],
|
|
7126
|
-
offsetSdr: Array.isArray(offsetSDR) ? offsetSDR.map(v => parseFloat(v)) : [parseFloat(offsetSDR), parseFloat(offsetSDR), parseFloat(offsetSDR)],
|
|
7127
|
-
offsetHdr: Array.isArray(offsetHDR) ? offsetHDR.map(v => parseFloat(v)) : [parseFloat(offsetHDR), parseFloat(offsetHDR), parseFloat(offsetHDR)],
|
|
7128
|
-
hdrCapacityMin: parseFloat(hdrCapacityMin),
|
|
7129
|
-
hdrCapacityMax: parseFloat(hdrCapacityMax)
|
|
7130
|
-
};
|
|
7131
|
-
return Object.assign(Object.assign({}, result), {
|
|
7132
|
-
/**
|
|
7133
|
-
* Parsed metadata
|
|
7134
|
-
*/
|
|
7135
|
-
parsedMetadata });
|
|
7136
|
-
};
|
|
7137
|
-
|
|
7138
7149
|
exports.JPEGRLoader = JPEGRLoader;
|
|
7139
7150
|
exports.decodeJPEGMetadata = decodeJPEGMetadata;
|
|
7140
7151
|
exports.encodeJPEGMetadata = encodeJPEGMetadata;
|
|
@@ -38,7 +38,7 @@ import { LoaderBase } from './LoaderBase';
|
|
|
38
38
|
*
|
|
39
39
|
* // `result.renderTarget.texture` must be
|
|
40
40
|
* // converted to `DataTexture` in order
|
|
41
|
-
* // to use it as
|
|
41
|
+
* // to use it as Equirectangular scene background
|
|
42
42
|
* // if needed
|
|
43
43
|
*
|
|
44
44
|
* scene.background = result.toDataTexture()
|
|
@@ -54,7 +54,7 @@ export declare class GainMapLoader extends LoaderBase<[string, string, string]>
|
|
|
54
54
|
* * gain map image
|
|
55
55
|
* * metadata json
|
|
56
56
|
*
|
|
57
|
-
* useful for webp
|
|
57
|
+
* useful for webp gain maps
|
|
58
58
|
*
|
|
59
59
|
* @param sdrUrl
|
|
60
60
|
* @param gainMapUrl
|
|
@@ -38,7 +38,7 @@ import { LoaderBase } from './LoaderBase';
|
|
|
38
38
|
*
|
|
39
39
|
* // `result.renderTarget.texture` must be
|
|
40
40
|
* // converted to `DataTexture` in order
|
|
41
|
-
* // to use it as
|
|
41
|
+
* // to use it as Equirectangular scene background
|
|
42
42
|
* // if needed
|
|
43
43
|
*
|
|
44
44
|
* scene.background = result.toDataTexture()
|
package/dist/types.d.ts
CHANGED
|
@@ -18,7 +18,9 @@ export type GainMapMetadata = {
|
|
|
18
18
|
* * Typically you can use a gamma of 1.0.
|
|
19
19
|
* * You can use a different value if your gain map has a very uneven distribution of log_recovery(x, y) values.
|
|
20
20
|
*
|
|
21
|
-
* 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),
|
|
21
|
+
* 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),
|
|
22
|
+
* 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).
|
|
23
|
+
* 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).
|
|
22
24
|
*/
|
|
23
25
|
gamma: [number, number, number];
|
|
24
26
|
/**
|
|
@@ -28,7 +30,7 @@ export type GainMapMetadata = {
|
|
|
28
30
|
* * This value also affects how much to apply the gain map based on the display boost.
|
|
29
31
|
* * Must be 0.0 or greater.
|
|
30
32
|
*
|
|
31
|
-
*
|
|
33
|
+
* Logarithmic space
|
|
32
34
|
*/
|
|
33
35
|
hdrCapacityMin: number;
|
|
34
36
|
/**
|
|
@@ -39,7 +41,7 @@ export type GainMapMetadata = {
|
|
|
39
41
|
* * Must be greater than hdrCapacityMin.
|
|
40
42
|
* * Required.
|
|
41
43
|
*
|
|
42
|
-
*
|
|
44
|
+
* Logarithmic space
|
|
43
45
|
*/
|
|
44
46
|
hdrCapacityMax: number;
|
|
45
47
|
/**
|
|
@@ -82,25 +84,29 @@ export type GainmapEncodingParameters = {
|
|
|
82
84
|
*/
|
|
83
85
|
offsetSdr?: [number, number, number];
|
|
84
86
|
/**
|
|
85
|
-
* This value lets the content creator constrain how much darker an image can get, when shown on an HDR display, relative to the SDR rendition.
|
|
87
|
+
* This value lets the content creator constrain how much darker an image can get, when shown on an HDR display, relative to the SDR rendition.
|
|
88
|
+
* This value is a constant for a particular image.
|
|
86
89
|
* @defaultValue 1
|
|
87
90
|
* @remarks
|
|
88
91
|
* * If, for example, the value is 0.5, then for any given pixel, the linear luminance of the displayed HDR rendition must be (at the least) 0.5x the linear luminance of the SDR rendition.
|
|
89
92
|
* * In practice, this value is typically equal to or just less than 1.0.
|
|
90
93
|
* * Always less than or equal to Max content boost.
|
|
91
94
|
*
|
|
92
|
-
*
|
|
95
|
+
* Non Logarithmic space
|
|
93
96
|
*/
|
|
94
97
|
minContentBoost?: number;
|
|
95
98
|
/**
|
|
96
99
|
* This value lets the content creator constrain how much brighter an image can get, when shown on an HDR display, relative to the SDR rendition.
|
|
97
100
|
*
|
|
98
101
|
* @remarks
|
|
99
|
-
* * This value is a constant for a particular image.
|
|
102
|
+
* * This value is a constant for a particular image.
|
|
103
|
+
* For example, if the value is four, then for any given pixel, the linear luminance of the
|
|
104
|
+
* displayed HDR rendition must be, at the most, 4x the linear luminance of the SDR rendition.
|
|
105
|
+
* In practice, this means that the brighter parts of the scene can be shown up to 4x brighter.
|
|
100
106
|
* * In practice, this value is typically greater than 1.0.
|
|
101
107
|
* * Always greater than or equal to Min content boost.
|
|
102
108
|
*
|
|
103
|
-
*
|
|
109
|
+
* Non Logarithmic space
|
|
104
110
|
*/
|
|
105
111
|
maxContentBoost: number;
|
|
106
112
|
/**
|
|
@@ -110,7 +116,11 @@ export type GainmapEncodingParameters = {
|
|
|
110
116
|
* @remarks
|
|
111
117
|
* * Typically you can use a gamma of 1.0.
|
|
112
118
|
* * You can use a different value if your gain map has a very uneven distribution of log_recovery(x, y) values.
|
|
113
|
-
* For example, this might apply if a gain map has a lot of detail just above SDR range
|
|
119
|
+
* For example, this might apply if a gain map has a lot of detail just above SDR range
|
|
120
|
+
* (represented as small log_recovery(x, y) values), and a very large map_max_log2 for the top
|
|
121
|
+
* end of the HDR rendition's desired brightness (represented by large log_recovery(x, y) values).
|
|
122
|
+
* In this case, you can use a map_gamma higher than 1.0 so that recovery(x, y)
|
|
123
|
+
* can precisely encode the detail in both the low end and high end of log_recovery(x, y).
|
|
114
124
|
*/
|
|
115
125
|
gamma?: [number, number, number];
|
|
116
126
|
};
|
|
@@ -128,12 +138,12 @@ export type GainmapDecodingParameters = {
|
|
|
128
138
|
* This value can change over time based on device settings and other factors,
|
|
129
139
|
* such as ambient light conditions, or how many bright pixels are on the screen.
|
|
130
140
|
*
|
|
131
|
-
*
|
|
141
|
+
* Non Logarithmic space
|
|
132
142
|
*/
|
|
133
143
|
maxDisplayBoost: number;
|
|
134
144
|
};
|
|
135
145
|
/**
|
|
136
|
-
*
|
|
146
|
+
* Parameters used to Encode a GainMap
|
|
137
147
|
*
|
|
138
148
|
* @category Encoding Parameters
|
|
139
149
|
* @group Encoding Parameters
|
|
@@ -150,7 +160,7 @@ export type EncodingParametersBase = GainmapEncodingParameters & {
|
|
|
150
160
|
*/
|
|
151
161
|
renderer?: WebGLRenderer;
|
|
152
162
|
/**
|
|
153
|
-
* Optional
|
|
163
|
+
* Optional tone mapping to apply to the SDR Rendition
|
|
154
164
|
* @defaultValue `ACESFilmicToneMapping`
|
|
155
165
|
*/
|
|
156
166
|
toneMapping?: ToneMapping;
|
|
@@ -21,6 +21,7 @@ export declare class QuadRenderer<TType extends TextureDataType, TMaterial exten
|
|
|
21
21
|
private _width;
|
|
22
22
|
private _height;
|
|
23
23
|
private _type;
|
|
24
|
+
private _colorSpace;
|
|
24
25
|
/**
|
|
25
26
|
*
|
|
26
27
|
* @param sourceTexture
|
|
@@ -71,4 +72,9 @@ export declare class QuadRenderer<TType extends TextureDataType, TMaterial exten
|
|
|
71
72
|
* The `Material` used.
|
|
72
73
|
*/
|
|
73
74
|
get material(): TMaterial;
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
get type(): TType;
|
|
79
|
+
get colorSpace(): ColorSpace;
|
|
74
80
|
}
|
package/dist/worker-interface.js
CHANGED
package/dist/worker-types.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type WorkerInterfaceImplementation = {
|
|
|
18
18
|
[k in keyof WorkerInterface]: (payload: WorkerInterface[k]['request']['payload']) => Promise<WorkerInterface[k]['result']>;
|
|
19
19
|
};
|
|
20
20
|
export type WorkerRequest = WorkerInterface[keyof WorkerInterface]['request'];
|
|
21
|
-
export type
|
|
21
|
+
export type WithTransferListFunction = <T>(payload: T, transferList: Transferable[]) => T;
|
|
22
22
|
export type PromiseWorkerType = {
|
|
23
23
|
postMessage: (message: any, transferables?: Transferable[]) => Promise<any>;
|
|
24
24
|
};
|
package/dist/worker.js
CHANGED
package/dist/worker.umd.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monogrid/gainmap-js",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A Javascript (TypeScript) Port of Adobe Gainmap Technology for storing HDR Images using an SDR Image + a gain map",
|
|
5
5
|
"homepage": "https://github.com/MONOGRID/gainmap-js#readme",
|
|
6
6
|
"repository": {
|