@monogrid/gainmap-js 3.0.6 → 3.1.0

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 CHANGED
@@ -1,3 +1,10 @@
1
+ # [3.1.0](https://github.com/MONOGRID/gainmap-js/compare/v3.0.6...v3.1.0) (2024-12-05)
2
+
3
+
4
+ ### Features
5
+
6
+ * **decode:** removes `DOMParser`, decode is now compatible with Web Workers ([b6a607d](https://github.com/MONOGRID/gainmap-js/commit/b6a607d1be3e7e86524e059c9eb61c8ee2a9e6f7))
7
+
1
8
  ## [3.0.6](https://github.com/MONOGRID/gainmap-js/compare/v3.0.5...v3.0.6) (2024-09-03)
2
9
 
3
10
 
package/README.md CHANGED
@@ -52,6 +52,7 @@ Refer to the [WIKI](https://github.com/MONOGRID/gainmap-js/wiki) for detailed do
52
52
  The main use case of this library is to decode a JPEG file that contains gain map data
53
53
  and use it instead of a traditional `.exr` or `.hdr` image.
54
54
 
55
+ > NOTE: Starting from v3.1.0 Decoding also works in a WebWorker, thanks to [Alejandro Romano](https://github.com/Arecsu) for the [contribution](https://github.com/MONOGRID/gainmap-js/pull/59)
55
56
 
56
57
  ### Using a single JPEG with embedded Gain map Metadata
57
58
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
@@ -1,7 +1,2 @@
1
1
  import { GainMapMetadata } from '../../core/types';
2
- /**
3
- *
4
- * @param input
5
- * @returns
6
- */
7
2
  export declare const extractXMP: (input: Uint8Array) => GainMapMetadata | undefined;
package/dist/decode.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
6
- import { Q as QuadRenderer } from './QuadRenderer-B3h-sJtp.js';
6
+ import { Q as QuadRenderer } from './QuadRenderer-DuOPRGA4.js';
7
7
  import { ShaderMaterial, Vector3, NoBlending, SRGBColorSpace, LinearSRGBColorSpace, HalfFloatType, Loader, LoadingManager, Texture, UVMapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, FileLoader } from 'three';
8
8
 
9
9
  const vertexShader = /* glsl */ `
@@ -250,40 +250,26 @@ class GainMapNotFoundError extends Error {
250
250
  class XMPMetadataNotFoundError extends Error {
251
251
  }
252
252
 
253
- const getAttribute = (description, name, defaultValue) => {
254
- var _a;
255
- let returnValue;
256
- const parsedValue = (_a = description.attributes.getNamedItem(name)) === null || _a === void 0 ? void 0 : _a.nodeValue;
257
- if (!parsedValue) {
258
- const node = description.getElementsByTagName(name)[0];
259
- if (node) {
260
- const values = node.getElementsByTagName('rdf:li');
261
- if (values.length === 3) {
262
- returnValue = Array.from(values).map(v => v.innerHTML);
263
- }
264
- else {
265
- throw new Error(`Gainmap metadata contains an array of items for ${name} but its length is not 3`);
266
- }
253
+ const getXMLValue = (xml, tag, defaultValue) => {
254
+ // Check for attribute format first: tag="value"
255
+ const attributeMatch = new RegExp(`${tag}="([^"]*)"`, 'i').exec(xml);
256
+ if (attributeMatch)
257
+ return attributeMatch[1];
258
+ // Check for tag format: <tag>value</tag> or <tag><rdf:li>value</rdf:li>...</tag>
259
+ const tagMatch = new RegExp(`<${tag}[^>]*>([\\s\\S]*?)</${tag}>`, 'i').exec(xml);
260
+ if (tagMatch) {
261
+ // Check if it contains rdf:li elements
262
+ const liValues = tagMatch[1].match(/<rdf:li>([^<]*)<\/rdf:li>/g);
263
+ if (liValues && liValues.length === 3) {
264
+ return liValues.map(v => v.replace(/<\/?rdf:li>/g, ''));
267
265
  }
268
- else {
269
- if (defaultValue)
270
- return defaultValue;
271
- else
272
- throw new Error(`Can't find ${name} in gainmap metadata`);
273
- }
274
- }
275
- else {
276
- returnValue = parsedValue;
266
+ return tagMatch[1].trim();
277
267
  }
278
- return returnValue;
268
+ if (defaultValue !== undefined)
269
+ return defaultValue;
270
+ throw new Error(`Can't find ${tag} in gainmap metadata`);
279
271
  };
280
- /**
281
- *
282
- * @param input
283
- * @returns
284
- */
285
272
  const extractXMP = (input) => {
286
- var _a, _b;
287
273
  let str;
288
274
  // support node test environment
289
275
  if (typeof TextDecoder !== 'undefined')
@@ -291,25 +277,22 @@ const extractXMP = (input) => {
291
277
  else
292
278
  str = input.toString();
293
279
  let start = str.indexOf('<x:xmpmeta');
294
- const parser = new DOMParser();
295
280
  while (start !== -1) {
296
281
  const end = str.indexOf('x:xmpmeta>', start);
297
- str.slice(start, end + 10);
298
282
  const xmpBlock = str.slice(start, end + 10);
299
283
  try {
300
- const xmlDocument = parser.parseFromString(xmpBlock, 'text/xml');
301
- const description = xmlDocument.getElementsByTagName('rdf:Description')[0];
302
- const gainMapMin = getAttribute(description, 'hdrgm:GainMapMin', '0');
303
- const gainMapMax = getAttribute(description, 'hdrgm:GainMapMax');
304
- const gamma = getAttribute(description, 'hdrgm:Gamma', '1');
305
- const offsetSDR = getAttribute(description, 'hdrgm:OffsetSDR', '0.015625');
306
- const offsetHDR = getAttribute(description, 'hdrgm:OffsetHDR', '0.015625');
307
- let hdrCapacityMin = (_a = description.attributes.getNamedItem('hdrgm:HDRCapacityMin')) === null || _a === void 0 ? void 0 : _a.nodeValue;
308
- if (!hdrCapacityMin)
309
- hdrCapacityMin = '0';
310
- const hdrCapacityMax = (_b = description.attributes.getNamedItem('hdrgm:HDRCapacityMax')) === null || _b === void 0 ? void 0 : _b.nodeValue;
311
- if (!hdrCapacityMax)
284
+ const gainMapMin = getXMLValue(xmpBlock, 'hdrgm:GainMapMin', '0');
285
+ const gainMapMax = getXMLValue(xmpBlock, 'hdrgm:GainMapMax');
286
+ const gamma = getXMLValue(xmpBlock, 'hdrgm:Gamma', '1');
287
+ const offsetSDR = getXMLValue(xmpBlock, 'hdrgm:OffsetSDR', '0.015625');
288
+ const offsetHDR = getXMLValue(xmpBlock, 'hdrgm:OffsetHDR', '0.015625');
289
+ // These are always attributes, so we can use a simpler regex
290
+ const hdrCapacityMinMatch = /hdrgm:HDRCapacityMin="([^"]*)"/.exec(xmpBlock);
291
+ const hdrCapacityMin = hdrCapacityMinMatch ? hdrCapacityMinMatch[1] : '0';
292
+ const hdrCapacityMaxMatch = /hdrgm:HDRCapacityMax="([^"]*)"/.exec(xmpBlock);
293
+ if (!hdrCapacityMaxMatch)
312
294
  throw new Error('Incomplete gainmap metadata');
295
+ const hdrCapacityMax = hdrCapacityMaxMatch[1];
313
296
  return {
314
297
  gainMapMin: Array.isArray(gainMapMin) ? gainMapMin.map(v => parseFloat(v)) : [parseFloat(gainMapMin), parseFloat(gainMapMin), parseFloat(gainMapMin)],
315
298
  gainMapMax: Array.isArray(gainMapMax) ? gainMapMax.map(v => parseFloat(v)) : [parseFloat(gainMapMax), parseFloat(gainMapMax), parseFloat(gainMapMax)],
@@ -321,6 +304,7 @@ const extractXMP = (input) => {
321
304
  };
322
305
  }
323
306
  catch (e) {
307
+ // Continue searching for another xmpmeta block if this one fails
324
308
  }
325
309
  start = str.indexOf('<x:xmpmeta', end);
326
310
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
@@ -546,40 +546,26 @@ void main() {
546
546
  class XMPMetadataNotFoundError extends Error {
547
547
  }
548
548
 
549
- const getAttribute = (description, name, defaultValue) => {
550
- var _a;
551
- let returnValue;
552
- const parsedValue = (_a = description.attributes.getNamedItem(name)) === null || _a === void 0 ? void 0 : _a.nodeValue;
553
- if (!parsedValue) {
554
- const node = description.getElementsByTagName(name)[0];
555
- if (node) {
556
- const values = node.getElementsByTagName('rdf:li');
557
- if (values.length === 3) {
558
- returnValue = Array.from(values).map(v => v.innerHTML);
559
- }
560
- else {
561
- throw new Error(`Gainmap metadata contains an array of items for ${name} but its length is not 3`);
562
- }
563
- }
564
- else {
565
- if (defaultValue)
566
- return defaultValue;
567
- else
568
- throw new Error(`Can't find ${name} in gainmap metadata`);
549
+ const getXMLValue = (xml, tag, defaultValue) => {
550
+ // Check for attribute format first: tag="value"
551
+ const attributeMatch = new RegExp(`${tag}="([^"]*)"`, 'i').exec(xml);
552
+ if (attributeMatch)
553
+ return attributeMatch[1];
554
+ // Check for tag format: <tag>value</tag> or <tag><rdf:li>value</rdf:li>...</tag>
555
+ const tagMatch = new RegExp(`<${tag}[^>]*>([\\s\\S]*?)</${tag}>`, 'i').exec(xml);
556
+ if (tagMatch) {
557
+ // Check if it contains rdf:li elements
558
+ const liValues = tagMatch[1].match(/<rdf:li>([^<]*)<\/rdf:li>/g);
559
+ if (liValues && liValues.length === 3) {
560
+ return liValues.map(v => v.replace(/<\/?rdf:li>/g, ''));
569
561
  }
562
+ return tagMatch[1].trim();
570
563
  }
571
- else {
572
- returnValue = parsedValue;
573
- }
574
- return returnValue;
564
+ if (defaultValue !== undefined)
565
+ return defaultValue;
566
+ throw new Error(`Can't find ${tag} in gainmap metadata`);
575
567
  };
576
- /**
577
- *
578
- * @param input
579
- * @returns
580
- */
581
568
  const extractXMP = (input) => {
582
- var _a, _b;
583
569
  let str;
584
570
  // support node test environment
585
571
  if (typeof TextDecoder !== 'undefined')
@@ -587,25 +573,22 @@ void main() {
587
573
  else
588
574
  str = input.toString();
589
575
  let start = str.indexOf('<x:xmpmeta');
590
- const parser = new DOMParser();
591
576
  while (start !== -1) {
592
577
  const end = str.indexOf('x:xmpmeta>', start);
593
- str.slice(start, end + 10);
594
578
  const xmpBlock = str.slice(start, end + 10);
595
579
  try {
596
- const xmlDocument = parser.parseFromString(xmpBlock, 'text/xml');
597
- const description = xmlDocument.getElementsByTagName('rdf:Description')[0];
598
- const gainMapMin = getAttribute(description, 'hdrgm:GainMapMin', '0');
599
- const gainMapMax = getAttribute(description, 'hdrgm:GainMapMax');
600
- const gamma = getAttribute(description, 'hdrgm:Gamma', '1');
601
- const offsetSDR = getAttribute(description, 'hdrgm:OffsetSDR', '0.015625');
602
- const offsetHDR = getAttribute(description, 'hdrgm:OffsetHDR', '0.015625');
603
- let hdrCapacityMin = (_a = description.attributes.getNamedItem('hdrgm:HDRCapacityMin')) === null || _a === void 0 ? void 0 : _a.nodeValue;
604
- if (!hdrCapacityMin)
605
- hdrCapacityMin = '0';
606
- const hdrCapacityMax = (_b = description.attributes.getNamedItem('hdrgm:HDRCapacityMax')) === null || _b === void 0 ? void 0 : _b.nodeValue;
607
- if (!hdrCapacityMax)
580
+ const gainMapMin = getXMLValue(xmpBlock, 'hdrgm:GainMapMin', '0');
581
+ const gainMapMax = getXMLValue(xmpBlock, 'hdrgm:GainMapMax');
582
+ const gamma = getXMLValue(xmpBlock, 'hdrgm:Gamma', '1');
583
+ const offsetSDR = getXMLValue(xmpBlock, 'hdrgm:OffsetSDR', '0.015625');
584
+ const offsetHDR = getXMLValue(xmpBlock, 'hdrgm:OffsetHDR', '0.015625');
585
+ // These are always attributes, so we can use a simpler regex
586
+ const hdrCapacityMinMatch = /hdrgm:HDRCapacityMin="([^"]*)"/.exec(xmpBlock);
587
+ const hdrCapacityMin = hdrCapacityMinMatch ? hdrCapacityMinMatch[1] : '0';
588
+ const hdrCapacityMaxMatch = /hdrgm:HDRCapacityMax="([^"]*)"/.exec(xmpBlock);
589
+ if (!hdrCapacityMaxMatch)
608
590
  throw new Error('Incomplete gainmap metadata');
591
+ const hdrCapacityMax = hdrCapacityMaxMatch[1];
609
592
  return {
610
593
  gainMapMin: Array.isArray(gainMapMin) ? gainMapMin.map(v => parseFloat(v)) : [parseFloat(gainMapMin), parseFloat(gainMapMin), parseFloat(gainMapMin)],
611
594
  gainMapMax: Array.isArray(gainMapMax) ? gainMapMax.map(v => parseFloat(v)) : [parseFloat(gainMapMax), parseFloat(gainMapMax), parseFloat(gainMapMax)],
@@ -617,6 +600,7 @@ void main() {
617
600
  };
618
601
  }
619
602
  catch (e) {
603
+ // Continue searching for another xmpmeta block if this one fails
620
604
  }
621
605
  start = str.indexOf('<x:xmpmeta', end);
622
606
  }
package/dist/encode.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
6
- import { c as compress } from './compress-CAiPfiRr.js';
6
+ import { c as compress } from './compress-B6OswAu8.js';
7
7
  import { DataTexture, RGBAFormat, UVMapping, RepeatWrapping, LinearFilter, LinearSRGBColorSpace, ShaderMaterial, Vector3, NoBlending, UnsignedByteType, ACESFilmicToneMapping, LinearToneMapping, CineonToneMapping, ReinhardToneMapping, SRGBColorSpace, Vector2, WebGLRenderTarget, NearestFilter, ClampToEdgeWrapping, FloatType, DataUtils } from 'three';
8
- import { Q as QuadRenderer } from './QuadRenderer-B3h-sJtp.js';
8
+ import { Q as QuadRenderer } from './QuadRenderer-DuOPRGA4.js';
9
9
 
10
10
  /**
11
11
  * Utility function to obtain a `DataTexture` from various input formats
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
@@ -19,9 +19,6 @@ import { GainMapMetadata } from '../core/types';
19
19
  * @throws {Error} if the provided file cannot be parsed or does not contain a valid Gainmap
20
20
  */
21
21
  export declare const decodeJPEGMetadata: (file: Uint8Array) => Promise<{
22
- /**
23
- * Parsed metadata
24
- */
25
22
  parsedMetadata: GainMapMetadata;
26
23
  metadata: ArrayBuffer | Uint8Array | Uint8ClampedArray | Int8Array | string;
27
24
  success: boolean;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
@@ -6538,41 +6538,6 @@ const getLibrary = async () => {
6538
6538
  return library;
6539
6539
  };
6540
6540
 
6541
- /**
6542
- * @deprecated
6543
- * @param description
6544
- * @param name
6545
- * @param defaultValue
6546
- * @returns
6547
- */
6548
- /* istanbul ignore next */
6549
- const getAttribute = (description, name, defaultValue) => {
6550
- var _a;
6551
- let returnValue;
6552
- const parsedValue = (_a = description.attributes.getNamedItem(name)) === null || _a === void 0 ? void 0 : _a.nodeValue;
6553
- if (!parsedValue) {
6554
- const node = description.getElementsByTagName(name)[0];
6555
- if (node) {
6556
- const values = node.getElementsByTagName('rdf:li');
6557
- if (values.length === 3) {
6558
- returnValue = Array.from(values).map(v => v.innerHTML);
6559
- }
6560
- else {
6561
- throw new Error(`Gainmap metadata contains an array of items for ${name} but its length is not 3`);
6562
- }
6563
- }
6564
- else {
6565
- if (defaultValue)
6566
- return defaultValue;
6567
- else
6568
- throw new Error(`Can't find ${name} in gainmap metadata`);
6569
- }
6570
- }
6571
- else {
6572
- returnValue = parsedValue;
6573
- }
6574
- return returnValue;
6575
- };
6576
6541
  /**
6577
6542
  * Decodes a JPEG file with an embedded Gainmap and XMP Metadata (aka JPEG-R)
6578
6543
  *
@@ -6594,25 +6559,42 @@ const getAttribute = (description, name, defaultValue) => {
6594
6559
  */
6595
6560
  /* istanbul ignore next */
6596
6561
  const decodeJPEGMetadata = async (file) => {
6597
- var _a, _b;
6598
6562
  const lib = await getLibrary();
6599
6563
  const result = lib.extractJpegR(file, file.length);
6600
6564
  if (!result.success)
6601
6565
  throw new Error(`${result.errorMessage}`);
6602
- const parser = new DOMParser();
6603
- const xmlDocument = parser.parseFromString(result.metadata, 'text/xml');
6604
- const description = xmlDocument.getElementsByTagName('rdf:Description')[0];
6605
- const gainMapMin = getAttribute(description, 'hdrgm:GainMapMin', '0');
6606
- const gainMapMax = getAttribute(description, 'hdrgm:GainMapMax');
6607
- const gamma = getAttribute(description, 'hdrgm:Gamma', '1');
6608
- const offsetSDR = getAttribute(description, 'hdrgm:OffsetSDR', '0.015625');
6609
- const offsetHDR = getAttribute(description, 'hdrgm:OffsetHDR', '0.015625');
6610
- let hdrCapacityMin = (_a = description.attributes.getNamedItem('hdrgm:HDRCapacityMin')) === null || _a === void 0 ? void 0 : _a.nodeValue;
6611
- if (!hdrCapacityMin)
6612
- hdrCapacityMin = '0';
6613
- const hdrCapacityMax = (_b = description.attributes.getNamedItem('hdrgm:HDRCapacityMax')) === null || _b === void 0 ? void 0 : _b.nodeValue;
6614
- if (!hdrCapacityMax)
6566
+ const getXMLValue = (xml, tag, defaultValue) => {
6567
+ // Check for attribute format first: tag="value"
6568
+ const attributeMatch = new RegExp(`${tag}="([^"]*)"`, 'i').exec(xml);
6569
+ if (attributeMatch)
6570
+ return attributeMatch[1];
6571
+ // Check for tag format: <tag>value</tag> or <tag><rdf:li>value</rdf:li>...</tag>
6572
+ const tagMatch = new RegExp(`<${tag}[^>]*>([\\s\\S]*?)</${tag}>`, 'i').exec(xml);
6573
+ if (tagMatch) {
6574
+ // Check if it contains rdf:li elements
6575
+ const liValues = tagMatch[1].match(/<rdf:li>([^<]*)<\/rdf:li>/g);
6576
+ if (liValues && liValues.length === 3) {
6577
+ return liValues.map(v => v.replace(/<\/?rdf:li>/g, ''));
6578
+ }
6579
+ return tagMatch[1].trim();
6580
+ }
6581
+ if (defaultValue !== undefined)
6582
+ return defaultValue;
6583
+ throw new Error(`Can't find ${tag} in gainmap metadata`);
6584
+ };
6585
+ const metadata = result.metadata;
6586
+ const gainMapMin = getXMLValue(metadata, 'hdrgm:GainMapMin', '0');
6587
+ const gainMapMax = getXMLValue(metadata, 'hdrgm:GainMapMax');
6588
+ const gamma = getXMLValue(metadata, 'hdrgm:Gamma', '1');
6589
+ const offsetSDR = getXMLValue(metadata, 'hdrgm:OffsetSDR', '0.015625');
6590
+ const offsetHDR = getXMLValue(metadata, 'hdrgm:OffsetHDR', '0.015625');
6591
+ // These are always attributes, so we can use a simpler regex
6592
+ const hdrCapacityMinMatch = /hdrgm:HDRCapacityMin="([^"]*)"/.exec(metadata);
6593
+ const hdrCapacityMin = hdrCapacityMinMatch ? hdrCapacityMinMatch[1] : '0';
6594
+ const hdrCapacityMaxMatch = /hdrgm:HDRCapacityMax="([^"]*)"/.exec(metadata);
6595
+ if (!hdrCapacityMaxMatch)
6615
6596
  throw new Error('Incomplete gainmap metadata');
6597
+ const hdrCapacityMax = hdrCapacityMaxMatch[1];
6616
6598
  const parsedMetadata = {
6617
6599
  gainMapMin: Array.isArray(gainMapMin) ? gainMapMin.map(v => parseFloat(v)) : [parseFloat(gainMapMin), parseFloat(gainMapMin), parseFloat(gainMapMin)],
6618
6600
  gainMapMax: Array.isArray(gainMapMax) ? gainMapMax.map(v => parseFloat(v)) : [parseFloat(gainMapMax), parseFloat(gainMapMax), parseFloat(gainMapMax)],
@@ -6624,9 +6606,6 @@ const decodeJPEGMetadata = async (file) => {
6624
6606
  };
6625
6607
  return {
6626
6608
  ...result,
6627
- /**
6628
- * Parsed metadata
6629
- */
6630
6609
  parsedMetadata
6631
6610
  };
6632
6611
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
13
  var Module = (() => {
14
- var _scriptDir = (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('libultrahdr.umd.cjs', document.baseURI).href));
14
+ var _scriptDir = (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('libultrahdr.umd.cjs', document.baseURI).href));
15
15
 
16
16
  return (
17
17
  async function(moduleArg = {}) {
@@ -107,7 +107,7 @@
107
107
  // TODO: Swap all `require()`'s with `import()`'s?
108
108
  const { createRequire } = await import('module');
109
109
  /** @suppress{duplicate} */
110
- var require$1 = createRequire((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('libultrahdr.umd.cjs', document.baseURI).href)));
110
+ var require$1 = createRequire((typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('libultrahdr.umd.cjs', document.baseURI).href)));
111
111
  // These modules will usually be used on Node.js. Load them eagerly to avoid
112
112
  // the complexity of lazy-loading.
113
113
  var fs = require$1('fs');
@@ -119,7 +119,7 @@
119
119
  // EXPORT_ES6 + ENVIRONMENT_IS_NODE always requires use of import.meta.url,
120
120
  // since there's no way getting the current absolute path of the module when
121
121
  // support for that is not available.
122
- scriptDirectory = require$1('url').fileURLToPath(new URL('./', (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('libultrahdr.umd.cjs', document.baseURI).href)))); // includes trailing slash
122
+ scriptDirectory = require$1('url').fileURLToPath(new URL('./', (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('libultrahdr.umd.cjs', document.baseURI).href)))); // includes trailing slash
123
123
  }
124
124
 
125
125
  // include: node_shell_read.js
@@ -709,7 +709,7 @@
709
709
  }
710
710
  } else {
711
711
  // Use bundler-friendly `new URL(..., import.meta.url)` pattern; works in browsers too.
712
- wasmBinaryFile = new URL('libultrahdr-esm.wasm', (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.src || new URL('libultrahdr.umd.cjs', document.baseURI).href))).href;
712
+ wasmBinaryFile = new URL('libultrahdr-esm.wasm', (typeof document === 'undefined' && typeof location === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : typeof document === 'undefined' ? location.href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('libultrahdr.umd.cjs', document.baseURI).href))).href;
713
713
  }
714
714
 
715
715
  function getBinarySync(file) {
@@ -6545,41 +6545,6 @@
6545
6545
  return library;
6546
6546
  };
6547
6547
 
6548
- /**
6549
- * @deprecated
6550
- * @param description
6551
- * @param name
6552
- * @param defaultValue
6553
- * @returns
6554
- */
6555
- /* istanbul ignore next */
6556
- const getAttribute = (description, name, defaultValue) => {
6557
- var _a;
6558
- let returnValue;
6559
- const parsedValue = (_a = description.attributes.getNamedItem(name)) === null || _a === void 0 ? void 0 : _a.nodeValue;
6560
- if (!parsedValue) {
6561
- const node = description.getElementsByTagName(name)[0];
6562
- if (node) {
6563
- const values = node.getElementsByTagName('rdf:li');
6564
- if (values.length === 3) {
6565
- returnValue = Array.from(values).map(v => v.innerHTML);
6566
- }
6567
- else {
6568
- throw new Error(`Gainmap metadata contains an array of items for ${name} but its length is not 3`);
6569
- }
6570
- }
6571
- else {
6572
- if (defaultValue)
6573
- return defaultValue;
6574
- else
6575
- throw new Error(`Can't find ${name} in gainmap metadata`);
6576
- }
6577
- }
6578
- else {
6579
- returnValue = parsedValue;
6580
- }
6581
- return returnValue;
6582
- };
6583
6548
  /**
6584
6549
  * Decodes a JPEG file with an embedded Gainmap and XMP Metadata (aka JPEG-R)
6585
6550
  *
@@ -6601,25 +6566,42 @@
6601
6566
  */
6602
6567
  /* istanbul ignore next */
6603
6568
  const decodeJPEGMetadata = async (file) => {
6604
- var _a, _b;
6605
6569
  const lib = await getLibrary();
6606
6570
  const result = lib.extractJpegR(file, file.length);
6607
6571
  if (!result.success)
6608
6572
  throw new Error(`${result.errorMessage}`);
6609
- const parser = new DOMParser();
6610
- const xmlDocument = parser.parseFromString(result.metadata, 'text/xml');
6611
- const description = xmlDocument.getElementsByTagName('rdf:Description')[0];
6612
- const gainMapMin = getAttribute(description, 'hdrgm:GainMapMin', '0');
6613
- const gainMapMax = getAttribute(description, 'hdrgm:GainMapMax');
6614
- const gamma = getAttribute(description, 'hdrgm:Gamma', '1');
6615
- const offsetSDR = getAttribute(description, 'hdrgm:OffsetSDR', '0.015625');
6616
- const offsetHDR = getAttribute(description, 'hdrgm:OffsetHDR', '0.015625');
6617
- let hdrCapacityMin = (_a = description.attributes.getNamedItem('hdrgm:HDRCapacityMin')) === null || _a === void 0 ? void 0 : _a.nodeValue;
6618
- if (!hdrCapacityMin)
6619
- hdrCapacityMin = '0';
6620
- const hdrCapacityMax = (_b = description.attributes.getNamedItem('hdrgm:HDRCapacityMax')) === null || _b === void 0 ? void 0 : _b.nodeValue;
6621
- if (!hdrCapacityMax)
6573
+ const getXMLValue = (xml, tag, defaultValue) => {
6574
+ // Check for attribute format first: tag="value"
6575
+ const attributeMatch = new RegExp(`${tag}="([^"]*)"`, 'i').exec(xml);
6576
+ if (attributeMatch)
6577
+ return attributeMatch[1];
6578
+ // Check for tag format: <tag>value</tag> or <tag><rdf:li>value</rdf:li>...</tag>
6579
+ const tagMatch = new RegExp(`<${tag}[^>]*>([\\s\\S]*?)</${tag}>`, 'i').exec(xml);
6580
+ if (tagMatch) {
6581
+ // Check if it contains rdf:li elements
6582
+ const liValues = tagMatch[1].match(/<rdf:li>([^<]*)<\/rdf:li>/g);
6583
+ if (liValues && liValues.length === 3) {
6584
+ return liValues.map(v => v.replace(/<\/?rdf:li>/g, ''));
6585
+ }
6586
+ return tagMatch[1].trim();
6587
+ }
6588
+ if (defaultValue !== undefined)
6589
+ return defaultValue;
6590
+ throw new Error(`Can't find ${tag} in gainmap metadata`);
6591
+ };
6592
+ const metadata = result.metadata;
6593
+ const gainMapMin = getXMLValue(metadata, 'hdrgm:GainMapMin', '0');
6594
+ const gainMapMax = getXMLValue(metadata, 'hdrgm:GainMapMax');
6595
+ const gamma = getXMLValue(metadata, 'hdrgm:Gamma', '1');
6596
+ const offsetSDR = getXMLValue(metadata, 'hdrgm:OffsetSDR', '0.015625');
6597
+ const offsetHDR = getXMLValue(metadata, 'hdrgm:OffsetHDR', '0.015625');
6598
+ // These are always attributes, so we can use a simpler regex
6599
+ const hdrCapacityMinMatch = /hdrgm:HDRCapacityMin="([^"]*)"/.exec(metadata);
6600
+ const hdrCapacityMin = hdrCapacityMinMatch ? hdrCapacityMinMatch[1] : '0';
6601
+ const hdrCapacityMaxMatch = /hdrgm:HDRCapacityMax="([^"]*)"/.exec(metadata);
6602
+ if (!hdrCapacityMaxMatch)
6622
6603
  throw new Error('Incomplete gainmap metadata');
6604
+ const hdrCapacityMax = hdrCapacityMaxMatch[1];
6623
6605
  const parsedMetadata = {
6624
6606
  gainMapMin: Array.isArray(gainMapMin) ? gainMapMin.map(v => parseFloat(v)) : [parseFloat(gainMapMin), parseFloat(gainMapMin), parseFloat(gainMapMin)],
6625
6607
  gainMapMax: Array.isArray(gainMapMax) ? gainMapMax.map(v => parseFloat(v)) : [parseFloat(gainMapMax), parseFloat(gainMapMax), parseFloat(gainMapMax)],
@@ -6631,9 +6613,6 @@
6631
6613
  };
6632
6614
  return {
6633
6615
  ...result,
6634
- /**
6635
- * Parsed metadata
6636
- */
6637
6616
  parsedMetadata
6638
6617
  };
6639
6618
  };
@@ -1,9 +1,9 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
6
- import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-UqyNh5ZN.js';
6
+ import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-DeBGiDfT.js';
7
7
 
8
8
  var lib$1;
9
9
  var hasRequiredLib$1;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
package/dist/worker.js CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
6
- import { g as getDefaultExportFromCjs } from './_commonjsHelpers-UqyNh5ZN.js';
7
- import { c as compress } from './compress-CAiPfiRr.js';
6
+ import { g as getDefaultExportFromCjs } from './_commonjsHelpers-DeBGiDfT.js';
7
+ import { c as compress } from './compress-B6OswAu8.js';
8
8
 
9
9
  var isPromise$2 = {exports: {}};
10
10
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @monogrid/gainmap-js v3.0.6
2
+ * @monogrid/gainmap-js v3.1.0
3
3
  * With ❤️, by MONOGRID <rnd@monogrid.com>
4
4
  */
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monogrid/gainmap-js",
3
- "version": "3.0.6",
3
+ "version": "3.1.0",
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": {
@@ -123,7 +123,7 @@
123
123
  "@semantic-release/npm": "^12.0.1",
124
124
  "@semantic-release/release-notes-generator": "^14.0.1",
125
125
  "@types/node": "^20.14.9",
126
- "@types/three": "^0.168.0",
126
+ "@types/three": "^0.170.0",
127
127
  "@typescript-eslint/eslint-plugin": "^7.15.0",
128
128
  "@typescript-eslint/parser": "^7.15.0",
129
129
  "concurrently": "^8.2.2",
@@ -148,7 +148,7 @@
148
148
  "semantic-release": "^24.0.0",
149
149
  "servez": "^2.2.3",
150
150
  "sharp": "^0.33.4",
151
- "three": "^0.168.0",
151
+ "three": "^0.170.0",
152
152
  "typedoc": "^0.26.5",
153
153
  "typedoc-github-wiki-theme": "^2.0.0",
154
154
  "typedoc-plugin-markdown": "^4.2.3",