@monogrid/gainmap-js 1.0.2
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 +17 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +130 -0
- package/LICENSE +21 -0
- package/README.md +149 -0
- package/dist/_commonjsHelpers-1789f0cf.js +12 -0
- package/dist/compress-a4b59cab.js +82 -0
- package/dist/decode.d.ts +37 -0
- package/dist/encode-utils/compress.d.ts +12 -0
- package/dist/encode-utils/find-texture-min-max.d.ts +15 -0
- package/dist/encode-utils/get-gainmap.d.ts +13 -0
- package/dist/encode-utils/get-sdr-rendition.d.ts +16 -0
- package/dist/encode.d.ts +117 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +976 -0
- package/dist/index.umd.js +1069 -0
- package/dist/libultrahdr-esm.wasm +0 -0
- package/dist/libultrahdr.d.ts +129 -0
- package/dist/libultrahdr.js +6728 -0
- package/dist/libultrahdr.umd.js +6740 -0
- package/dist/materials/GainMapDecoderMaterial.d.ts +26 -0
- package/dist/materials/GainMapEncoderMaterial.d.ts +43 -0
- package/dist/materials/SDRMaterial.d.ts +35 -0
- package/dist/materials/index.d.ts +3 -0
- package/dist/types.d.ts +252 -0
- package/dist/utils/QuadRenderer.d.ts +73 -0
- package/dist/utils/get-data-texture.d.ts +14 -0
- package/dist/worker-interface.d.ts +26 -0
- package/dist/worker-interface.js +501 -0
- package/dist/worker-interface.umd.js +516 -0
- package/dist/worker-types.d.ts +24 -0
- package/dist/worker.d.ts +1 -0
- package/dist/worker.js +123 -0
- package/dist/worker.umd.js +207 -0
- package/examples/README.md +3 -0
- package/examples/compress.ts +43 -0
- package/examples/decode-from-jpeg.ts +40 -0
- package/examples/decode-from-separate-data.ts +41 -0
- package/examples/decode-to-datatexture.ts +65 -0
- package/examples/encode-and-compress.ts +29 -0
- package/examples/encode-jpeg-metadata.ts +57 -0
- package/examples/encode.ts +28 -0
- package/examples/globals.d.ts +6 -0
- package/examples/worker.ts +41 -0
- package/libultrahdr-wasm/LICENSE +202 -0
- package/libultrahdr-wasm/README.md +99 -0
- package/libultrahdr-wasm/build/libultrahdr-debug.js +7156 -0
- package/libultrahdr-wasm/build/libultrahdr-debug.wasm +0 -0
- package/libultrahdr-wasm/build/libultrahdr-esm.js +6633 -0
- package/libultrahdr-wasm/build/libultrahdr-esm.wasm +0 -0
- package/libultrahdr-wasm/build/libultrahdr.d.ts +30 -0
- package/libultrahdr-wasm/build/libultrahdr.js +6591 -0
- package/libultrahdr-wasm/build/libultrahdr.wasm +0 -0
- package/package.json +143 -0
- package/reports/eslint-examples.json +1 -0
- package/reports/eslint-src.json +1 -0
- package/reports/eslint-tests.json +1 -0
- package/reports/junit.xml +35 -0
- package/reports/typecheck-examples.log +0 -0
- package/reports/typecheck-tests.log +0 -0
- package/reports/typecheck.log +0 -0
|
Binary file
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { MainModule } from '../libultrahdr-wasm/build/libultrahdr';
|
|
2
|
+
import { CompressedImage, GainMapMetadata } from './types';
|
|
3
|
+
export * from '../libultrahdr-wasm/build/libultrahdr';
|
|
4
|
+
/**
|
|
5
|
+
* Instances the WASM module and returns it, only one module will be created upon multiple calls.
|
|
6
|
+
* @category General
|
|
7
|
+
* @group General
|
|
8
|
+
*
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare const getLibrary: () => Promise<MainModule>;
|
|
12
|
+
/**
|
|
13
|
+
* Encapsulates a Gainmap into a single JPEG file (aka: JPEG-R) with the base map
|
|
14
|
+
* as the sdr visualization and the gainMap encoded into a MPF (Multi-Picture Format) tag.
|
|
15
|
+
*
|
|
16
|
+
* @category Encoding
|
|
17
|
+
* @group Encoding
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { compress, encode, findTextureMinMax } from '@monogrid/gainmap-js'
|
|
21
|
+
* import { encodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
|
|
22
|
+
* import { EXRLoader } from 'three/examples/jsm/loaders/EXRLoader.js'
|
|
23
|
+
*
|
|
24
|
+
* // load an HDR file
|
|
25
|
+
* const loader = new EXRLoader()
|
|
26
|
+
* const image = await loader.loadAsync('image.exr')
|
|
27
|
+
*
|
|
28
|
+
* // find RAW RGB Max value of a texture
|
|
29
|
+
* const textureMax = await findTextureMinMax(image)
|
|
30
|
+
*
|
|
31
|
+
* // Encode the gainmap
|
|
32
|
+
* const encodingResult = encode({
|
|
33
|
+
* image,
|
|
34
|
+
* maxContentBoost: Math.max.apply(this, textureMax)
|
|
35
|
+
* })
|
|
36
|
+
*
|
|
37
|
+
* // obtain the RAW RGBA SDR buffer and create an ImageData
|
|
38
|
+
* const sdrImageData = new ImageData(encodingResult.sdr.toArray(), encodingResult.sdr.width, encodingResult.sdr.height)
|
|
39
|
+
* // obtain the RAW RGBA Gain map buffer and create an ImageData
|
|
40
|
+
* const gainMapImageData = new ImageData(encodingResult.gainMap.toArray(), encodingResult.gainMap.width, encodingResult.gainMap.height)
|
|
41
|
+
*
|
|
42
|
+
* // parallel compress the RAW buffers into the specified mimeType
|
|
43
|
+
* const mimeType = 'image/jpeg'
|
|
44
|
+
* const quality = 0.9
|
|
45
|
+
*
|
|
46
|
+
* const [sdr, gainMap] = await Promise.all([
|
|
47
|
+
* compress({
|
|
48
|
+
* source: sdrImageData,
|
|
49
|
+
* mimeType,
|
|
50
|
+
* quality,
|
|
51
|
+
* flipY: true // output needs to be flipped
|
|
52
|
+
* }),
|
|
53
|
+
* compress({
|
|
54
|
+
* source: gainMapImageData,
|
|
55
|
+
* mimeType,
|
|
56
|
+
* quality,
|
|
57
|
+
* flipY: true // output needs to be flipped
|
|
58
|
+
* })
|
|
59
|
+
* ])
|
|
60
|
+
*
|
|
61
|
+
* // obtain the metadata which will be embedded into
|
|
62
|
+
* // and XMP tag inside the final JPEG file
|
|
63
|
+
* const metadata = encodingResult.getMetadata()
|
|
64
|
+
*
|
|
65
|
+
* // embed the compressed images + metadata into a single
|
|
66
|
+
* // JPEG file
|
|
67
|
+
* const jpeg = await encodeJPEGMetadata({
|
|
68
|
+
* ...encodingResult,
|
|
69
|
+
* ...metadata,
|
|
70
|
+
* sdr,
|
|
71
|
+
* gainMap
|
|
72
|
+
* })
|
|
73
|
+
*
|
|
74
|
+
* // `jpeg` will be an `Uint8Array` which can be saved somewhere
|
|
75
|
+
*
|
|
76
|
+
*
|
|
77
|
+
* @param encodingResult
|
|
78
|
+
* @returns an Uint8Array representing a JPEG-R file
|
|
79
|
+
* @throws {Error} If `encodingResult.sdr.mimeType !== 'image/jpeg'`
|
|
80
|
+
* @throws {Error} If `encodingResult.gainMap.mimeType !== 'image/jpeg'`
|
|
81
|
+
*/
|
|
82
|
+
export declare const encodeJPEGMetadata: (encodingResult: GainMapMetadata & {
|
|
83
|
+
sdr: CompressedImage;
|
|
84
|
+
gainMap: CompressedImage;
|
|
85
|
+
}) => Promise<Uint8Array>;
|
|
86
|
+
/**
|
|
87
|
+
* Decodes a JPEG file with an embedded Gainmap and XMP Metadata (aka JPEG-R)
|
|
88
|
+
*
|
|
89
|
+
* @category Decoding
|
|
90
|
+
* @group Decoding
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* import { decode } from '@monogrid/gainmap-js'
|
|
94
|
+
* import { decodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
|
|
95
|
+
* import { Mesh, MeshBasicMaterial, PlaneGeometry } from 'three'
|
|
96
|
+
* // fetch a JPEG image containing a gainmap as ArrayBuffer
|
|
97
|
+
* const gainmap = await (await fetch('gainmap.jpeg')).arrayBuffer()
|
|
98
|
+
*
|
|
99
|
+
* // extract data from the JPEG
|
|
100
|
+
* const { sdr, gainMap, parsedMetadata } = await decodeJPEGMetadata(new Uint8Array(gainmap))
|
|
101
|
+
*
|
|
102
|
+
* // restore the HDR texture
|
|
103
|
+
* const result = await decode({
|
|
104
|
+
* sdr,
|
|
105
|
+
* gainMap,
|
|
106
|
+
* // this will restore the full HDR range
|
|
107
|
+
* maxDisplayBoost: Math.pow(2, parsedMetadata.hdrCapacityMax),
|
|
108
|
+
* ...parsedMetadata
|
|
109
|
+
* })
|
|
110
|
+
*
|
|
111
|
+
* // result can be used to populate a Texture
|
|
112
|
+
* const mesh = new Mesh(new PlaneGeometry(), new MeshBasicMaterial({ map: result.renderTarget.texture }))
|
|
113
|
+
*
|
|
114
|
+
*
|
|
115
|
+
* @param file A Jpeg file Uint8Array.
|
|
116
|
+
* @returns The decoded data
|
|
117
|
+
* @throws {Error} if the provided file cannot be parsed or does not contain a valid Gainmap
|
|
118
|
+
*/
|
|
119
|
+
export declare const decodeJPEGMetadata: (file: Uint8Array) => Promise<{
|
|
120
|
+
/**
|
|
121
|
+
* Parsed metadata
|
|
122
|
+
*/
|
|
123
|
+
parsedMetadata: GainMapMetadata;
|
|
124
|
+
metadata: string | Uint8ClampedArray | ArrayBuffer | Uint8Array | Int8Array;
|
|
125
|
+
success: boolean;
|
|
126
|
+
errorMessage: any;
|
|
127
|
+
sdr: any;
|
|
128
|
+
gainMap: any;
|
|
129
|
+
}>;
|