@monogrid/gainmap-js 3.4.1 → 3.6.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 +14 -0
- package/README.md +111 -133
- package/dist/{QuadRenderer-Bl8ThfRL.js → QuadRenderer-CXtNzoCY.js} +1 -1
- package/dist/{QuadRenderer-D1rYlVRa.js → QuadRenderer-DcBTBLz6.js} +1 -1
- package/dist/{_commonjsHelpers-CHnLGTFq.js → _commonjsHelpers-Cdw2adc2.js} +1 -1
- package/dist/{_commonjsHelpers-D4ntYHBT.js → _commonjsHelpers-CnYhShyx.js} +1 -1
- package/dist/{compress-B5svUHuf.js → compress-C42bpk6O.js} +1 -1
- package/dist/{compress-DBGuVQfM.js → compress-CzMz2bpX.js} +1 -2
- package/dist/core/iso-gainmap-metadata.d.ts +40 -0
- package/dist/decode/shared/extract.d.ts +5 -3
- package/dist/decode/shared/index.d.ts +2 -0
- package/dist/decode/shared/utils/create-textures.d.ts +26 -0
- package/dist/decode/shared/utils/extractISO.d.ts +15 -0
- package/dist/decode/shared/utils/warn-deprecated.d.ts +8 -0
- package/dist/decode/webgl/decode.d.ts +1 -0
- package/dist/decode/webgl/index.d.ts +4 -0
- package/dist/decode/webgl/loaders/GainMapLoader.d.ts +3 -1
- package/dist/decode/webgl/loaders/HDRJPGLoader.d.ts +3 -1
- package/dist/decode/webgl/materials/GainMapDecoderMaterial.d.ts +1 -0
- package/dist/decode/webgpu/core/QuadRenderer.d.ts +1 -0
- package/dist/decode/webgpu/decode.d.ts +1 -0
- package/dist/decode/webgpu/index.d.ts +7 -0
- package/dist/decode/webgpu/loaders/GainMapLoader.d.ts +3 -1
- package/dist/decode/webgpu/loaders/GainMapNodeLoader.d.ts +42 -0
- package/dist/decode/webgpu/loaders/HDRJPGLoader.d.ts +3 -1
- package/dist/decode/webgpu/loaders/HDRJPGNodeLoader.d.ts +41 -0
- package/dist/decode/webgpu/loaders/LoaderBaseNode.d.ts +24 -0
- package/dist/decode/webgpu/materials/GainMapDecoderMaterial.d.ts +1 -0
- package/dist/decode/webgpu/nodes/GainMapNode.d.ts +137 -0
- package/dist/decode.js +18 -4
- package/dist/decode.min.js +2 -2
- package/dist/decode.umd.cjs +207 -36
- package/dist/decode.umd.min.cjs +2 -2
- package/dist/decode.webgpu.js +453 -8
- package/dist/decode.webgpu.min.js +2 -2
- package/dist/decode.webgpu.umd.cjs +644 -38
- package/dist/decode.webgpu.umd.min.cjs +2 -2
- package/dist/encode.js +4 -4
- package/dist/encode.min.js +2 -2
- package/dist/encode.umd.cjs +1 -2
- package/dist/encode.umd.min.cjs +1 -1
- package/dist/iso-gainmap-metadata-ByNqnUPn.js +141 -0
- package/dist/iso-gainmap-metadata-CEaaU7RT.js +5 -0
- package/dist/libultrahdr/jpeg-assembler.d.ts +2 -0
- package/dist/libultrahdr.js +30 -7
- package/dist/libultrahdr.min.js +2 -2
- package/dist/libultrahdr.umd.cjs +104 -7
- package/dist/libultrahdr.umd.min.cjs +2 -2
- package/dist/third-party.txt +69 -69
- package/dist/{Loader-Bi9FKrn4.js → warn-deprecated-Bk17fVbj.js} +117 -38
- package/dist/warn-deprecated-D0kPpXtA.js +5 -0
- package/dist/worker-interface.js +2 -2
- package/dist/worker-interface.min.js +2 -2
- package/dist/worker-interface.umd.cjs +1 -1
- package/dist/worker-interface.umd.min.cjs +1 -1
- package/dist/worker.js +3 -3
- package/dist/worker.min.js +2 -2
- package/dist/worker.umd.cjs +1 -2
- package/dist/worker.umd.min.cjs +1 -1
- package/package.json +34 -37
- package/dist/Loader-uEDs4JZg.js +0 -5
package/dist/libultrahdr.umd.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js v3.
|
|
2
|
+
* @monogrid/gainmap-js v3.6.0
|
|
3
3
|
* With ❤️, by MONOGRID <gainmap@monogrid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -9,6 +9,82 @@
|
|
|
9
9
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.libultrahdr = {}));
|
|
10
10
|
})(this, (function (exports) { 'use strict';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* ISO 21496-1 binary gain map metadata (de)serialization
|
|
14
|
+
* Based on libultrahdr gainmapmetadata.cpp implementation
|
|
15
|
+
*
|
|
16
|
+
* Layout (big endian):
|
|
17
|
+
* - u16 minimum_version, u16 writer_version
|
|
18
|
+
* - u8 flags (bit 7: multichannel, bit 6: use base colour space, bit 2: backward direction, bit 3: common denominator)
|
|
19
|
+
* - headroom: base_hdr_headroom, alternate_hdr_headroom (unsigned fractions)
|
|
20
|
+
* - per channel: gain_map_min (s), gain_map_max (s), gamma (u), base_offset (s), alternate_offset (s)
|
|
21
|
+
*
|
|
22
|
+
* Fractions are written as numerator + denominator, or numerator only when the common denominator flag is set.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Namespace identifying an ISO 21496-1 APP2 segment (null terminated)
|
|
26
|
+
*/
|
|
27
|
+
const ISO_NAMESPACE = 'urn:iso:std:iso:ts:21496:-1\0';
|
|
28
|
+
const IS_MULTICHANNEL_MASK = 1 << 7;
|
|
29
|
+
const USE_BASE_COLOR_SPACE_MASK = 1 << 6;
|
|
30
|
+
const INT32_MAX = 0x7fffffff;
|
|
31
|
+
const UINT32_MAX = 0xffffffff;
|
|
32
|
+
/**
|
|
33
|
+
* Converts a float into a fraction, using the largest denominator that keeps the numerator in range
|
|
34
|
+
*/
|
|
35
|
+
const toFraction = (value, signed) => {
|
|
36
|
+
const max = signed ? INT32_MAX : UINT32_MAX;
|
|
37
|
+
if (!Number.isFinite(value) || (!signed && value < 0) || Math.abs(value) > max) {
|
|
38
|
+
throw new Error(`Cannot represent ${value} as an ${signed ? 'signed' : 'unsigned'} ISO 21496-1 fraction`);
|
|
39
|
+
}
|
|
40
|
+
const denominator = Math.min(UINT32_MAX, Math.floor(max / Math.max(1, Math.abs(value))));
|
|
41
|
+
return [Math.round(value * denominator), denominator];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The version-only payload stored in the primary image (minimum_version = 0, writer_version = 0)
|
|
45
|
+
*/
|
|
46
|
+
const ISO_VERSION_ONLY = new Uint8Array(4);
|
|
47
|
+
/**
|
|
48
|
+
* Serializes gain map metadata into an ISO 21496-1 binary payload
|
|
49
|
+
* (without namespace), to be stored in the gain map image.
|
|
50
|
+
*
|
|
51
|
+
* Values are already in the expected space: gainMapMin/Max and hdrCapacityMin/Max
|
|
52
|
+
* are log2, gamma and offsets are linear.
|
|
53
|
+
*
|
|
54
|
+
* @param metadata
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
const encodeISOGainMapMetadata = (metadata) => {
|
|
58
|
+
const channels = [0, 1, 2].map(i => [metadata.gainMapMin[i], metadata.gainMapMax[i], metadata.gamma[i], metadata.offsetSdr[i], metadata.offsetHdr[i]]);
|
|
59
|
+
const isMultiChannel = channels.some(c => c.some((v, j) => v !== channels[0][j]));
|
|
60
|
+
const channelCount = isMultiChannel ? 3 : 1;
|
|
61
|
+
const data = new Uint8Array(5 + 16 + 40 * channelCount);
|
|
62
|
+
const view = new DataView(data.buffer);
|
|
63
|
+
let pos = 4; // minimum_version and writer_version are 0
|
|
64
|
+
// the gain map is computed in the base image colour space
|
|
65
|
+
view.setUint8(pos++, (isMultiChannel ? IS_MULTICHANNEL_MASK : 0) | USE_BASE_COLOR_SPACE_MASK);
|
|
66
|
+
const writeFraction = (value, signed) => {
|
|
67
|
+
const [n, d] = toFraction(value, signed);
|
|
68
|
+
if (signed)
|
|
69
|
+
view.setInt32(pos, n);
|
|
70
|
+
else
|
|
71
|
+
view.setUint32(pos, n);
|
|
72
|
+
view.setUint32(pos + 4, d);
|
|
73
|
+
pos += 8;
|
|
74
|
+
};
|
|
75
|
+
writeFraction(metadata.hdrCapacityMin, false);
|
|
76
|
+
writeFraction(metadata.hdrCapacityMax, false);
|
|
77
|
+
for (let i = 0; i < channelCount; i++) {
|
|
78
|
+
const [min, max, gamma, offsetSdr, offsetHdr] = channels[i];
|
|
79
|
+
writeFraction(min, true);
|
|
80
|
+
writeFraction(max, true);
|
|
81
|
+
writeFraction(gamma, false);
|
|
82
|
+
writeFraction(offsetSdr, true);
|
|
83
|
+
writeFraction(offsetHdr, true);
|
|
84
|
+
}
|
|
85
|
+
return data;
|
|
86
|
+
};
|
|
87
|
+
|
|
12
88
|
/**
|
|
13
89
|
* JPEG marker constants
|
|
14
90
|
* Based on JPEG specification and libultrahdr implementation
|
|
@@ -404,6 +480,15 @@
|
|
|
404
480
|
result.set(jpegData.subarray(exifPos + exifSize), exifPos);
|
|
405
481
|
return result;
|
|
406
482
|
}
|
|
483
|
+
/**
|
|
484
|
+
* Concatenate two byte arrays
|
|
485
|
+
*/
|
|
486
|
+
function concat(a, b) {
|
|
487
|
+
const result = new Uint8Array(a.length + b.length);
|
|
488
|
+
result.set(a, 0);
|
|
489
|
+
result.set(b, a.length);
|
|
490
|
+
return result;
|
|
491
|
+
}
|
|
407
492
|
/**
|
|
408
493
|
* Write a JPEG marker and its data
|
|
409
494
|
*
|
|
@@ -439,11 +524,13 @@
|
|
|
439
524
|
* - APP1 (EXIF if present)
|
|
440
525
|
* - APP1 (XMP with gain map metadata)
|
|
441
526
|
* - APP2 (ICC profile if present)
|
|
527
|
+
* - APP2 (ISO 21496-1 version)
|
|
442
528
|
* - APP2 (MPF data)
|
|
443
529
|
* - Rest of primary JPEG data
|
|
444
530
|
* 2. Secondary image (gain map):
|
|
445
531
|
* - SOI
|
|
446
532
|
* - APP1 (XMP with gain map parameters)
|
|
533
|
+
* - APP2 (ISO 21496-1 gain map parameters)
|
|
447
534
|
* - Rest of gain map JPEG data
|
|
448
535
|
*
|
|
449
536
|
* @param options - Assembly options
|
|
@@ -473,10 +560,17 @@
|
|
|
473
560
|
// Generate XMP for secondary image
|
|
474
561
|
const xmpSecondary = generateXmpForSecondaryImage(metadata);
|
|
475
562
|
const xmpSecondaryBytes = new TextEncoder().encode(xmpSecondary);
|
|
476
|
-
// Calculate secondary image size
|
|
477
|
-
// 2 bytes SOI + 2 bytes marker + 2 bytes length field + namespace + XMP data + gain map data (without SOI)
|
|
478
563
|
const namespaceBytes = new TextEncoder().encode(XMP_NAMESPACE);
|
|
479
|
-
const
|
|
564
|
+
const xmpSecondaryData = new Uint8Array(namespaceBytes.length + xmpSecondaryBytes.length);
|
|
565
|
+
xmpSecondaryData.set(namespaceBytes, 0);
|
|
566
|
+
xmpSecondaryData.set(xmpSecondaryBytes, namespaceBytes.length);
|
|
567
|
+
// ISO 21496-1 metadata: version only in the primary image, full metadata in the gain map image
|
|
568
|
+
const isoNamespaceBytes = new TextEncoder().encode(ISO_NAMESPACE);
|
|
569
|
+
const isoPrimaryData = concat(isoNamespaceBytes, ISO_VERSION_ONLY);
|
|
570
|
+
const isoSecondaryData = concat(isoNamespaceBytes, encodeISOGainMapMetadata(metadata));
|
|
571
|
+
// Calculate secondary image size
|
|
572
|
+
// SOI + APP1 (XMP) + APP2 (ISO) + gain map data (without SOI)
|
|
573
|
+
const secondaryImageSize = 2 + 2 + 2 + xmpSecondaryData.length + 2 + 2 + isoSecondaryData.length + (gainMap.data.length - 2);
|
|
480
574
|
// Generate XMP for primary image
|
|
481
575
|
const xmpPrimary = generateXmpForPrimaryImage(secondaryImageSize, metadata);
|
|
482
576
|
const xmpPrimaryBytes = new TextEncoder().encode(xmpPrimary);
|
|
@@ -492,6 +586,7 @@
|
|
|
492
586
|
totalSize += 2 + 2 + xmpPrimaryData.length; // APP1 + length + XMP primary
|
|
493
587
|
if (icc)
|
|
494
588
|
totalSize += 2 + 2 + icc.length; // APP2 + length + ICC
|
|
589
|
+
totalSize += 2 + 2 + isoPrimaryData.length; // APP2 + length + ISO version
|
|
495
590
|
totalSize += 2 + 2 + mpfLength; // APP2 + length + MPF
|
|
496
591
|
totalSize += primaryJpegData.length - 2; // Primary JPEG without SOI
|
|
497
592
|
totalSize += secondaryImageSize; // Secondary image
|
|
@@ -502,6 +597,7 @@
|
|
|
502
597
|
(exifData ? 2 + 2 + exifData.length : 0) +
|
|
503
598
|
2 + 2 + xmpPrimaryData.length +
|
|
504
599
|
(icc ? 2 + 2 + icc.length : 0) +
|
|
600
|
+
2 + 2 + isoPrimaryData.length +
|
|
505
601
|
2 + 2 + 4 // APP2 marker + length + MPF signature
|
|
506
602
|
);
|
|
507
603
|
// Generate MPF data
|
|
@@ -522,6 +618,8 @@
|
|
|
522
618
|
if (icc) {
|
|
523
619
|
pos = writeMarker(output, pos, MARKERS.APP2, icc);
|
|
524
620
|
}
|
|
621
|
+
// Write ISO 21496-1 version
|
|
622
|
+
pos = writeMarker(output, pos, MARKERS.APP2, isoPrimaryData);
|
|
525
623
|
// Write MPF
|
|
526
624
|
pos = writeMarker(output, pos, MARKERS.APP2, mpfDataActual);
|
|
527
625
|
// Write rest of primary JPEG (skip SOI)
|
|
@@ -531,10 +629,9 @@
|
|
|
531
629
|
// Write SOI
|
|
532
630
|
pos = writeMarker(output, pos, MARKERS.SOI);
|
|
533
631
|
// Write XMP for secondary image
|
|
534
|
-
const xmpSecondaryData = new Uint8Array(namespaceBytes.length + xmpSecondaryBytes.length);
|
|
535
|
-
xmpSecondaryData.set(namespaceBytes, 0);
|
|
536
|
-
xmpSecondaryData.set(xmpSecondaryBytes, namespaceBytes.length);
|
|
537
632
|
pos = writeMarker(output, pos, MARKERS.APP1, xmpSecondaryData);
|
|
633
|
+
// Write ISO 21496-1 metadata for secondary image
|
|
634
|
+
pos = writeMarker(output, pos, MARKERS.APP2, isoSecondaryData);
|
|
538
635
|
// Write rest of gain map JPEG (skip SOI)
|
|
539
636
|
output.set(gainMap.data.subarray(2), pos);
|
|
540
637
|
// pos += gainMap.data.length - 2
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js v3.
|
|
2
|
+
* @monogrid/gainmap-js v3.6.0
|
|
3
3
|
* With ❤️, by MONOGRID <gainmap@monogrid.com>
|
|
4
4
|
*/
|
|
5
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).libultrahdr={})}(this,function(t){"use strict";const e=
|
|
5
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).libultrahdr={})}(this,function(t){"use strict";const e=4294967295,n=new Uint8Array(4),a=t=>{const n=[0,1,2].map(e=>[t.gainMapMin[e],t.gainMapMax[e],t.gamma[e],t.offsetSdr[e],t.offsetHdr[e]]),a=n.some(t=>t.some((t,e)=>t!==n[0][e])),r=a?3:1,s=new Uint8Array(21+40*r),i=new DataView(s.buffer);let o=4;i.setUint8(o++,64|(a?128:0));const p=(t,n)=>{const[a,r]=((t,n)=>{const a=n?2147483647:e;if(!Number.isFinite(t)||!n&&t<0||Math.abs(t)>a)throw new Error(`Cannot represent ${t} as an ${n?"signed":"unsigned"} ISO 21496-1 fraction`);const r=Math.min(e,Math.floor(a/Math.max(1,Math.abs(t))));return[Math.round(t*r),r]})(t,n);n?i.setInt32(o,a):i.setUint32(o,a),i.setUint32(o+4,r),o+=8};p(t.hdrCapacityMin,!1),p(t.hdrCapacityMax,!1);for(let t=0;t<r;t++){const[e,a,r,s,i]=n[t];p(e,!0),p(a,!0),p(r,!1),p(s,!0),p(i,!0)}return s},r=216,s=225,i=226,o=218,p={SIGNATURE:new Uint8Array([77,80,70,0]),BIG_ENDIAN:new Uint8Array([77,77]),TIFF_MAGIC:42,NUM_PICTURES:2,TAG_COUNT:3,TAG_SIZE:12,MP_ENTRY_SIZE:16},h=45056,g=45057,d=45058,c=7,u=4,m=0,f=536870912,l=new Uint8Array([48,49,48,48]);function M(){return p.SIGNATURE.length+2+2+4+2+p.TAG_COUNT*p.TAG_SIZE+4+p.NUM_PICTURES*p.MP_ENTRY_SIZE}const U="Primary",x="GainMap",y="image/jpeg";function w(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function T(t,e){const n=new Uint8Array(t.length+e.length);return n.set(t,0),n.set(e,t.length),n}function A(t,e,n,a){const r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(r.setUint8(e++,255),r.setUint8(e++,n),a&&a.length>0){const n=a.length+2;r.setUint16(e,n,!1),e+=2,t.set(a,e),e+=a.length}return e}function E(t){const{sdr:e,gainMap:E,metadata:I,exif:b,icc:C}=t;if("image/jpeg"!==e.mimeType)throw new Error("SDR image must be JPEG format");if("image/jpeg"!==E.mimeType)throw new Error("Gain map image must be JPEG format");const S=function(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);if(255!==e.getUint8(0)||e.getUint8(1)!==r)return null;let n=2;const a="Exif\0\0";for(;n<t.length-1&&255===e.getUint8(n);){const r=e.getUint8(n+1);if(r===o)break;if(r===s){const r=e.getUint16(n+2,!1),s=n+4;let i=!0;for(let e=0;e<6;e++)if(s+e>=t.length||t[s+e]!==a.charCodeAt(e)){i=!1;break}if(i){const e=r-2;return{data:t.slice(s,s+e),pos:n,size:r+2}}}n+=2+e.getUint16(n+2,!1)}return null}(e.data);if(S&&b)throw new Error("Primary image already contains EXIF data, cannot add external EXIF");let R=e.data,G=b;S&&(R=function(t,e,n){const a=t.length-n,r=new Uint8Array(a);return r.set(t.subarray(0,e),0),r.set(t.subarray(e+n),e),r}(e.data,S.pos,S.size),G=S.data);const D=function(t){const e=[],n=t.hdrCapacityMin,a=t.hdrCapacityMax,r=t=>Array.isArray(t)?t.reduce((t,e)=>t+e,0)/t.length:t,s=r(t.gainMapMin),i=r(t.gainMapMax),o=r(t.gamma),p=r(t.offsetSdr),h=r(t.offsetHdr);return e.push('<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>'),e.push('<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.1.2">'),e.push(' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'),e.push(" <rdf:Description"),e.push(' xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/"'),e.push(` hdrgm:Version="${w(t.version)}"`),e.push(` hdrgm:GainMapMin="${w(s)}"`),e.push(` hdrgm:GainMapMax="${w(i)}"`),e.push(` hdrgm:Gamma="${w(o)}"`),e.push(` hdrgm:OffsetSDR="${w(p)}"`),e.push(` hdrgm:OffsetHDR="${w(h)}"`),e.push(` hdrgm:HDRCapacityMin="${w(n)}"`),e.push(` hdrgm:HDRCapacityMax="${w(a)}"`),e.push(' hdrgm:BaseRenditionIsHDR="False"'),e.push(' rdf:about=""/>'),e.push(" </rdf:RDF>"),e.push("</x:xmpmeta>"),e.push('<?xpacket end="w"?>'),e.join("\n")}(I),N=(new TextEncoder).encode(D),_=(new TextEncoder).encode("http://ns.adobe.com/xap/1.0/\0"),$=new Uint8Array(_.length+N.length);$.set(_,0),$.set(N,_.length);const P=(new TextEncoder).encode("urn:iso:std:iso:ts:21496:-1\0"),F=T(P,n),j=T(P,a(I)),k=6+$.length+2+2+j.length+(E.data.length-2),H=function(t,e){const n=[];return n.push('<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>'),n.push('<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.1.2">'),n.push(' <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'),n.push(" <rdf:Description"),n.push(' xmlns:Container="http://ns.google.com/photos/1.0/container/"'),n.push(' xmlns:Item="http://ns.google.com/photos/1.0/container/item/"'),n.push(' xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/"'),n.push(` hdrgm:Version="${w(e.version)}"`),n.push(' rdf:about="">'),n.push(" <Container:Directory>"),n.push(" <rdf:Seq>"),n.push(' <rdf:li rdf:parseType="Resource">'),n.push(" <Container:Item"),n.push(` Item:Semantic="${U}"`),n.push(` Item:Mime="${y}"/>`),n.push(" </rdf:li>"),n.push(' <rdf:li rdf:parseType="Resource">'),n.push(" <Container:Item"),n.push(` Item:Semantic="${x}"`),n.push(` Item:Mime="${y}"`),n.push(` Item:Length="${t}"/>`),n.push(" </rdf:li>"),n.push(" </rdf:Seq>"),n.push(" </Container:Directory>"),n.push(" </rdf:Description>"),n.push(" </rdf:RDF>"),n.push("</x:xmpmeta>"),n.push('<?xpacket end="w"?>'),n.join("\n")}(k,I),z=(new TextEncoder).encode(H),O=new Uint8Array(_.length+z.length);O.set(_,0),O.set(z,_.length);const B=M();let V=2;G&&(V+=4+G.length),V+=4+O.length,C&&(V+=4+C.length),V+=4+F.length,V+=4+B,V+=R.length-2,V+=k;const Z=V-k,X=function(t,e,n,a){const r=M(),s=new ArrayBuffer(r),i=new DataView(s),o=new Uint8Array(s);let U=0;o.set(p.SIGNATURE,U),U+=p.SIGNATURE.length,o.set(p.BIG_ENDIAN,U);const x=!1;U+=2,i.setUint16(U,p.TIFF_MAGIC,x),U+=2,i.setUint32(U,8,x),U+=4,i.setUint16(U,p.TAG_COUNT,x),U+=2,i.setUint16(U,h,x),U+=2,i.setUint16(U,c,x),U+=2,i.setUint32(U,l.length,x),U+=4,o.set(l,U),U+=4,i.setUint16(U,g,x),U+=2,i.setUint16(U,u,x),U+=2,i.setUint32(U,1,x),U+=4,i.setUint32(U,p.NUM_PICTURES,x),U+=4,i.setUint16(U,d,x),U+=2,i.setUint16(U,c,x),U+=2,i.setUint32(U,p.MP_ENTRY_SIZE*p.NUM_PICTURES,x),U+=4;const y=U-p.SIGNATURE.length+4+4;return i.setUint32(U,y,x),U+=4,i.setUint32(U,0,x),U+=4,i.setUint32(U,m|f,x),U+=4,i.setUint32(U,t,x),U+=4,i.setUint32(U,e,x),U+=4,i.setUint16(U,0,x),U+=2,i.setUint16(U,0,x),U+=2,i.setUint32(U,m,x),U+=4,i.setUint32(U,n,x),U+=4,i.setUint32(U,a,x),U+=4,i.setUint16(U,0,x),U+=2,i.setUint16(U,0,x),o}(Z,0,k,Z-(2+(G?4+G.length:0)+2+2+O.length+(C?4+C.length:0)+2+2+F.length+2+2+4)),q=new Uint8Array(V);let v=0;return v=A(q,v,r),G&&(v=A(q,v,s,G)),v=A(q,v,s,O),C&&(v=A(q,v,i,C)),v=A(q,v,i,F),v=A(q,v,i,X),q.set(R.subarray(2),v),v+=R.length-2,v=A(q,v,r),v=A(q,v,s,$),v=A(q,v,i,j),q.set(E.data.subarray(2),v),q}t.encodeJPEGMetadata=t=>{if("image/jpeg"!==t.sdr.mimeType)throw new Error("This function expects an SDR image compressed in jpeg");if("image/jpeg"!==t.gainMap.mimeType)throw new Error("This function expects a GainMap image compressed in jpeg");const e={version:"1.0",gainMapMin:t.gainMapMin,gainMapMax:t.gainMapMax,gamma:t.gamma,offsetSdr:t.offsetSdr,offsetHdr:t.offsetHdr,hdrCapacityMin:t.hdrCapacityMin,hdrCapacityMax:t.hdrCapacityMax,minContentBoost:Array.isArray(t.gainMapMin)?Math.pow(2,t.gainMapMin.reduce((t,e)=>t+e,0)/t.gainMapMin.length):Math.pow(2,t.gainMapMin),maxContentBoost:Array.isArray(t.gainMapMax)?Math.pow(2,t.gainMapMax.reduce((t,e)=>t+e,0)/t.gainMapMax.length):Math.pow(2,t.gainMapMax)};return E({sdr:t.sdr,gainMap:t.gainMap,metadata:e})}});
|
package/dist/third-party.txt
CHANGED
|
@@ -1,32 +1,56 @@
|
|
|
1
|
-
Name:
|
|
2
|
-
Version:
|
|
1
|
+
Name: immediate
|
|
2
|
+
Version: 3.0.6
|
|
3
3
|
License: MIT
|
|
4
4
|
Private: false
|
|
5
|
-
Description:
|
|
6
|
-
Repository:
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Description: A cross browser microtask library
|
|
6
|
+
Repository: git://github.com/calvinmetcalf/immediate.git
|
|
7
|
+
Contributors:
|
|
8
|
+
Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com)
|
|
9
|
+
Donavon West <github@donavon.com> (http://donavon.com)
|
|
10
|
+
Yaffle
|
|
11
|
+
Calvin Metcalf <calvin.metcalf@gmail.com>
|
|
12
|
+
License Text:
|
|
9
13
|
===
|
|
10
14
|
|
|
11
|
-
Copyright (c)
|
|
15
|
+
Copyright (c) 2012 Barnesandnoble.com, llc, Donavon West, Domenic Denicola, Brian Cavalier
|
|
12
16
|
|
|
13
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
-
of this software and associated documentation files (the
|
|
15
|
-
in the Software without restriction, including
|
|
16
|
-
to use, copy, modify, merge, publish,
|
|
17
|
-
copies of the Software, and to
|
|
18
|
-
furnished to do so, subject to
|
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
18
|
+
a copy of this software and associated documentation files (the
|
|
19
|
+
"Software"), to deal in the Software without restriction, including
|
|
20
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
21
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
22
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
23
|
+
the following conditions:
|
|
19
24
|
|
|
20
|
-
The above copyright notice and this permission notice shall be
|
|
21
|
-
all copies or substantial portions of the Software.
|
|
25
|
+
The above copyright notice and this permission notice shall be
|
|
26
|
+
included in all copies or substantial portions of the Software.
|
|
22
27
|
|
|
23
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
24
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
25
|
-
FITNESS FOR A PARTICULAR PURPOSE AND
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
THE SOFTWARE.
|
|
28
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
29
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
30
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
31
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
32
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
33
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
34
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
Name: lie
|
|
39
|
+
Version: 3.3.0
|
|
40
|
+
License: MIT
|
|
41
|
+
Private: false
|
|
42
|
+
Description: A basic but performant promise implementation
|
|
43
|
+
Repository: https://github.com/calvinmetcalf/lie.git
|
|
44
|
+
License Text:
|
|
45
|
+
===
|
|
46
|
+
|
|
47
|
+
#Copyright (c) 2014-2018 Calvin Metcalf, Jordan Harband
|
|
48
|
+
|
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
50
|
+
|
|
51
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
52
|
+
|
|
53
|
+
**THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.**
|
|
30
54
|
|
|
31
55
|
---
|
|
32
56
|
|
|
@@ -38,7 +62,7 @@ Description: Communicate with a Web Worker using Promises, allowing transferList
|
|
|
38
62
|
Repository: git+https://github.com/terikon/promise-worker-transferable.git
|
|
39
63
|
Homepage: https://github.com/terikon/promise-worker-transferable#readme
|
|
40
64
|
Author: Roman Viskin <npm@terikon.com>
|
|
41
|
-
License
|
|
65
|
+
License Text:
|
|
42
66
|
===
|
|
43
67
|
|
|
44
68
|
|
|
@@ -246,56 +270,32 @@ License Copyright:
|
|
|
246
270
|
|
|
247
271
|
---
|
|
248
272
|
|
|
249
|
-
Name:
|
|
250
|
-
Version:
|
|
251
|
-
License: MIT
|
|
252
|
-
Private: false
|
|
253
|
-
Description: A cross browser microtask library
|
|
254
|
-
Repository: git://github.com/calvinmetcalf/immediate.git
|
|
255
|
-
Contributors:
|
|
256
|
-
Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com)
|
|
257
|
-
Donavon West <github@donavon.com> (http://donavon.com)
|
|
258
|
-
Yaffle
|
|
259
|
-
Calvin Metcalf <calvin.metcalf@gmail.com>
|
|
260
|
-
License Copyright:
|
|
261
|
-
===
|
|
262
|
-
|
|
263
|
-
Copyright (c) 2012 Barnesandnoble.com, llc, Donavon West, Domenic Denicola, Brian Cavalier
|
|
264
|
-
|
|
265
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
266
|
-
a copy of this software and associated documentation files (the
|
|
267
|
-
"Software"), to deal in the Software without restriction, including
|
|
268
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
269
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
270
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
271
|
-
the following conditions:
|
|
272
|
-
|
|
273
|
-
The above copyright notice and this permission notice shall be
|
|
274
|
-
included in all copies or substantial portions of the Software.
|
|
275
|
-
|
|
276
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
277
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
278
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
279
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
280
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
281
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
282
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
283
|
-
|
|
284
|
-
---
|
|
285
|
-
|
|
286
|
-
Name: lie
|
|
287
|
-
Version: 3.3.0
|
|
273
|
+
Name: is-promise
|
|
274
|
+
Version: 2.2.2
|
|
288
275
|
License: MIT
|
|
289
276
|
Private: false
|
|
290
|
-
Description:
|
|
291
|
-
Repository: https://github.com/
|
|
292
|
-
|
|
277
|
+
Description: Test whether an object looks like a promises-a+ promise
|
|
278
|
+
Repository: https://github.com/then/is-promise.git
|
|
279
|
+
Author: ForbesLindesay
|
|
280
|
+
License Text:
|
|
293
281
|
===
|
|
294
282
|
|
|
295
|
-
|
|
283
|
+
Copyright (c) 2014 Forbes Lindesay
|
|
296
284
|
|
|
297
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
285
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
286
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
287
|
+
in the Software without restriction, including without limitation the rights
|
|
288
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
289
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
290
|
+
furnished to do so, subject to the following conditions:
|
|
298
291
|
|
|
299
|
-
The above copyright notice and this permission notice shall be included in
|
|
292
|
+
The above copyright notice and this permission notice shall be included in
|
|
293
|
+
all copies or substantial portions of the Software.
|
|
300
294
|
|
|
301
|
-
|
|
295
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
296
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
297
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
298
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
299
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
300
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
301
|
+
THE SOFTWARE.
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js v3.
|
|
2
|
+
* @monogrid/gainmap-js v3.6.0
|
|
3
3
|
* With ❤️, by MONOGRID <gainmap@monogrid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { SRGBColorSpace, LinearSRGBColorSpace, HalfFloatType,
|
|
6
|
+
import { SRGBColorSpace, LinearSRGBColorSpace, HalfFloatType, Texture, UVMapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, Loader, LoadingManager } from 'three';
|
|
7
|
+
import { I as ISO_NAMESPACE, d as decodeISOGainMapMetadata } from './iso-gainmap-metadata-ByNqnUPn.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Shared decode implementation factory
|
|
@@ -46,6 +47,43 @@ class GainMapNotFoundError extends Error {
|
|
|
46
47
|
class XMPMetadataNotFoundError extends Error {
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
const ISO_SIGNATURE = Array.from(ISO_NAMESPACE, c => c.charCodeAt(0));
|
|
51
|
+
/**
|
|
52
|
+
* Extracts ISO 21496-1 gain map metadata from a JPEG file
|
|
53
|
+
*
|
|
54
|
+
* Looks for APP2 segments carrying the ISO 21496-1 namespace, skipping
|
|
55
|
+
* the version-only segment stored in the primary image.
|
|
56
|
+
*
|
|
57
|
+
* `0xFF 0xE2` cannot appear inside entropy-coded data, so a byte scan is safe.
|
|
58
|
+
*
|
|
59
|
+
* @category Decoding Functions
|
|
60
|
+
* @group Decoding Functions
|
|
61
|
+
* @param input an `Uint8Array` containing an encoded JPEG file
|
|
62
|
+
* @returns the parsed metadata or `undefined` if no supported ISO 21496-1 metadata is found
|
|
63
|
+
*/
|
|
64
|
+
const extractISO = (input) => {
|
|
65
|
+
const view = new DataView(input.buffer, input.byteOffset, input.byteLength);
|
|
66
|
+
const payloadStart = 4 + ISO_SIGNATURE.length;
|
|
67
|
+
for (let i = 0; i + payloadStart < input.length; i++) {
|
|
68
|
+
if (input[i] !== 0xff || input[i + 1] !== 0xe2)
|
|
69
|
+
continue;
|
|
70
|
+
if (!ISO_SIGNATURE.every((c, j) => input[i + 4 + j] === c))
|
|
71
|
+
continue;
|
|
72
|
+
// segment length includes the 2 length bytes
|
|
73
|
+
const end = Math.min(input.length, i + 2 + view.getUint16(i + 2));
|
|
74
|
+
// version-only block in the primary image
|
|
75
|
+
if (end - (i + payloadStart) <= 4)
|
|
76
|
+
continue;
|
|
77
|
+
try {
|
|
78
|
+
return decodeISOGainMapMetadata(input.subarray(i + payloadStart, end));
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
// unsupported or malformed, let the caller fall back to XMP
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
49
87
|
const getXMLValue = (xml, tag, defaultValue) => {
|
|
50
88
|
// Check for attribute format first: tag="value"
|
|
51
89
|
const attributeMatch = new RegExp(`${tag}="([^"]*)"`, 'i').exec(xml);
|
|
@@ -271,14 +309,16 @@ class MPFExtractor {
|
|
|
271
309
|
}
|
|
272
310
|
|
|
273
311
|
/**
|
|
274
|
-
* Extracts
|
|
312
|
+
* Extracts gain map metadata and the gain map recovery image
|
|
275
313
|
* from a single JPEG file.
|
|
276
314
|
*
|
|
315
|
+
* ISO 21496-1 metadata is preferred when present, XMP (Ultra HDR / Adobe hdrgm) is used as fallback.
|
|
316
|
+
*
|
|
277
317
|
* @category Decoding Functions
|
|
278
318
|
* @group Decoding Functions
|
|
279
319
|
* @param jpegFile an `Uint8Array` containing and encoded JPEG file
|
|
280
|
-
* @returns an sdr `Uint8Array` compressed in JPEG, a gainMap `Uint8Array` compressed in JPEG and the
|
|
281
|
-
* @throws Error if XMP Metadata is
|
|
320
|
+
* @returns an sdr `Uint8Array` compressed in JPEG, a gainMap `Uint8Array` compressed in JPEG and the parsed metadata
|
|
321
|
+
* @throws Error if neither ISO 21496-1 nor XMP Metadata is found
|
|
282
322
|
* @throws Error if Gain map image is not found
|
|
283
323
|
* @example
|
|
284
324
|
* import { FileLoader } from 'three'
|
|
@@ -291,7 +331,7 @@ class MPFExtractor {
|
|
|
291
331
|
* const { sdr, gainMap, metadata } = extractGainmapFromJPEG(jpegFile)
|
|
292
332
|
*/
|
|
293
333
|
const extractGainmapFromJPEG = async (jpegFile) => {
|
|
294
|
-
const metadata = extractXMP(jpegFile);
|
|
334
|
+
const metadata = extractISO(jpegFile) ?? extractXMP(jpegFile);
|
|
295
335
|
if (!metadata)
|
|
296
336
|
throw new XMPMetadataNotFoundError('Gain map XMP metadata not found');
|
|
297
337
|
const mpfExtractor = new MPFExtractor({ extractFII: true, extractNonFII: true });
|
|
@@ -321,6 +361,57 @@ const getHTMLImageFromBlob = (blob) => {
|
|
|
321
361
|
});
|
|
322
362
|
};
|
|
323
363
|
|
|
364
|
+
/**
|
|
365
|
+
* Decodes the SDR and (optional) gain map JPEG buffers into images
|
|
366
|
+
*
|
|
367
|
+
* @param sdrBuffer
|
|
368
|
+
* @param gainMapBuffer
|
|
369
|
+
* @param imageOrientation
|
|
370
|
+
* @returns
|
|
371
|
+
*/
|
|
372
|
+
const processImages = async (sdrBuffer, gainMapBuffer, imageOrientation) => {
|
|
373
|
+
const gainMapBlob = gainMapBuffer ? new Blob([gainMapBuffer], { type: 'image/jpeg' }) : undefined;
|
|
374
|
+
const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
|
|
375
|
+
let sdrImage;
|
|
376
|
+
let gainMapImage;
|
|
377
|
+
let needsFlip = false;
|
|
378
|
+
if (typeof createImageBitmap === 'undefined') {
|
|
379
|
+
const res = await Promise.all([
|
|
380
|
+
gainMapBlob ? getHTMLImageFromBlob(gainMapBlob) : Promise.resolve(undefined),
|
|
381
|
+
getHTMLImageFromBlob(sdrBlob)
|
|
382
|
+
]);
|
|
383
|
+
gainMapImage = res[0];
|
|
384
|
+
sdrImage = res[1];
|
|
385
|
+
needsFlip = imageOrientation === 'flipY';
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
const res = await Promise.all([
|
|
389
|
+
gainMapBlob ? createImageBitmap(gainMapBlob, { imageOrientation: imageOrientation || 'flipY' }) : Promise.resolve(undefined),
|
|
390
|
+
createImageBitmap(sdrBlob, { imageOrientation: imageOrientation || 'flipY' })
|
|
391
|
+
]);
|
|
392
|
+
gainMapImage = res[0];
|
|
393
|
+
sdrImage = res[1];
|
|
394
|
+
}
|
|
395
|
+
return { sdrImage, gainMapImage, needsFlip };
|
|
396
|
+
};
|
|
397
|
+
/**
|
|
398
|
+
* Creates the SDR (sRGB) and gain map (linear) textures from decoded images
|
|
399
|
+
*
|
|
400
|
+
* @param sdrImage
|
|
401
|
+
* @param gainMapImage
|
|
402
|
+
* @param needsFlip
|
|
403
|
+
* @returns
|
|
404
|
+
*/
|
|
405
|
+
const createTextures = (sdrImage, gainMapImage, needsFlip) => {
|
|
406
|
+
const gainMap = new Texture(gainMapImage || new ImageData(2, 2), UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, LinearSRGBColorSpace);
|
|
407
|
+
gainMap.flipY = needsFlip;
|
|
408
|
+
gainMap.needsUpdate = true;
|
|
409
|
+
const sdr = new Texture(sdrImage, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, SRGBColorSpace);
|
|
410
|
+
sdr.flipY = needsFlip;
|
|
411
|
+
sdr.needsUpdate = true;
|
|
412
|
+
return { gainMap, sdr };
|
|
413
|
+
};
|
|
414
|
+
|
|
324
415
|
/**
|
|
325
416
|
* Shared base class for loaders that extracts common logic
|
|
326
417
|
*/
|
|
@@ -370,39 +461,11 @@ class LoaderBaseShared extends Loader {
|
|
|
370
461
|
renderTargetOptions: this._renderTargetOptions
|
|
371
462
|
});
|
|
372
463
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
|
|
376
|
-
let sdrImage;
|
|
377
|
-
let gainMapImage;
|
|
378
|
-
let needsFlip = false;
|
|
379
|
-
if (typeof createImageBitmap === 'undefined') {
|
|
380
|
-
const res = await Promise.all([
|
|
381
|
-
gainMapBlob ? getHTMLImageFromBlob(gainMapBlob) : Promise.resolve(undefined),
|
|
382
|
-
getHTMLImageFromBlob(sdrBlob)
|
|
383
|
-
]);
|
|
384
|
-
gainMapImage = res[0];
|
|
385
|
-
sdrImage = res[1];
|
|
386
|
-
needsFlip = imageOrientation === 'flipY';
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
const res = await Promise.all([
|
|
390
|
-
gainMapBlob ? createImageBitmap(gainMapBlob, { imageOrientation: imageOrientation || 'flipY' }) : Promise.resolve(undefined),
|
|
391
|
-
createImageBitmap(sdrBlob, { imageOrientation: imageOrientation || 'flipY' })
|
|
392
|
-
]);
|
|
393
|
-
gainMapImage = res[0];
|
|
394
|
-
sdrImage = res[1];
|
|
395
|
-
}
|
|
396
|
-
return { sdrImage, gainMapImage, needsFlip };
|
|
464
|
+
processImages(sdrBuffer, gainMapBuffer, imageOrientation) {
|
|
465
|
+
return processImages(sdrBuffer, gainMapBuffer, imageOrientation);
|
|
397
466
|
}
|
|
398
467
|
createTextures(sdrImage, gainMapImage, needsFlip) {
|
|
399
|
-
|
|
400
|
-
gainMap.flipY = needsFlip;
|
|
401
|
-
gainMap.needsUpdate = true;
|
|
402
|
-
const sdr = new Texture(sdrImage, UVMapping, ClampToEdgeWrapping, ClampToEdgeWrapping, LinearFilter, LinearMipMapLinearFilter, RGBAFormat, UnsignedByteType, 1, SRGBColorSpace);
|
|
403
|
-
sdr.flipY = needsFlip;
|
|
404
|
-
sdr.needsUpdate = true;
|
|
405
|
-
return { gainMap, sdr };
|
|
468
|
+
return createTextures(sdrImage, gainMapImage, needsFlip);
|
|
406
469
|
}
|
|
407
470
|
updateQuadRenderer(quadRenderer, sdrImage, gainMap, sdr, metadata) {
|
|
408
471
|
quadRenderer.width = sdrImage.width;
|
|
@@ -421,4 +484,20 @@ class LoaderBaseShared extends Loader {
|
|
|
421
484
|
}
|
|
422
485
|
}
|
|
423
486
|
|
|
424
|
-
|
|
487
|
+
const warned = new Set();
|
|
488
|
+
/**
|
|
489
|
+
* Warns once per API that a render target based decode API is going away in v4.0.0
|
|
490
|
+
*
|
|
491
|
+
* @param name deprecated API
|
|
492
|
+
* @param entry entry point exposing the deprecated API
|
|
493
|
+
* @param replacement node based API replacing it, from `@monogrid/gainmap-js/webgpu`
|
|
494
|
+
*/
|
|
495
|
+
const warnDeprecated = (name, entry, replacement) => {
|
|
496
|
+
const key = `${entry}:${name}`;
|
|
497
|
+
if (warned.has(key))
|
|
498
|
+
return;
|
|
499
|
+
warned.add(key);
|
|
500
|
+
console.warn(`gainmap-js: ${name} from '${entry}' is deprecated and will be removed in v4.0.0. Use ${replacement} from '@monogrid/gainmap-js/webgpu' with WebGPURenderer (which also has a WebGL2 backend) instead. It is not a drop-in replacement (it returns a GainMapNode, not a render target), see https://github.com/MONOGRID/gainmap-js#migrating-to-v400`);
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
export { GainMapNotFoundError as G, LoaderBaseShared as L, MPFExtractor as M, XMPMetadataNotFoundError as X, createTextures as a, extractISO as b, createDecodeFunction as c, extractXMP as d, extractGainmapFromJPEG as e, processImages as p, warnDeprecated as w };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @monogrid/gainmap-js v3.6.0
|
|
3
|
+
* With ❤️, by MONOGRID <gainmap@monogrid.com>
|
|
4
|
+
*/
|
|
5
|
+
import{SRGBColorSpace as e,LinearSRGBColorSpace as t,HalfFloatType as a,Texture as r,UVMapping as n,ClampToEdgeWrapping as i,LinearFilter as o,LinearMipMapLinearFilter as s,RGBAFormat as d,UnsignedByteType as p,Loader as c,LoadingManager as l}from"three";import{I as g,d as m}from"./iso-gainmap-metadata-CEaaU7RT.js";function f(r){return n=>{const{sdr:i,gainMap:o,renderer:s}=n;i.colorSpace!==e&&(console.warn("SDR Colorspace needs to be *SRGBColorSpace*, setting it automatically"),i.colorSpace=e),i.needsUpdate=!0,o.colorSpace!==t&&(console.warn("Gainmap Colorspace needs to be *LinearSRGBColorSpace*, setting it automatically"),o.colorSpace=t),o.needsUpdate=!0;const d=r.createMaterial({...n,sdr:i,gainMap:o});return r.createQuadRenderer({width:i.image.width,height:i.image.height,type:a,colorSpace:t,material:d,renderer:s,renderTargetOptions:n.renderTargetOptions})}}class h extends Error{}class u extends Error{}const w=Array.from(g,e=>e.charCodeAt(0)),x=e=>{const t=new DataView(e.buffer,e.byteOffset,e.byteLength),a=4+w.length;for(let r=0;r+a<e.length;r++){if(255!==e[r]||226!==e[r+1])continue;if(!w.every((t,a)=>e[r+4+a]===t))continue;const n=Math.min(e.length,r+2+t.getUint16(r+2));if(!(n-(r+a)<=4))try{return m(e.subarray(r+a,n))}catch(e){return}}},M=(e,t,a)=>{const r=new RegExp(`${t}="([^"]*)"`,"i").exec(e);if(r)return r[1];const n=new RegExp(`<${t}[^>]*>([\\s\\S]*?)</${t}>`,"i").exec(e);if(n){const e=n[1].match(/<rdf:li>([^<]*)<\/rdf:li>/g);return e&&3===e.length?e.map(e=>e.replace(/<\/?rdf:li>/g,"")):n[1].trim()}if(void 0!==a)return a;throw new Error(`Can't find ${t} in gainmap metadata`)},y=e=>{let t;t="undefined"!=typeof TextDecoder?(new TextDecoder).decode(e):e.toString();let a=t.indexOf("<x:xmpmeta");for(;-1!==a;){const e=t.indexOf("x:xmpmeta>",a),r=t.slice(a,e+10);try{const e=M(r,"hdrgm:GainMapMin","0"),t=M(r,"hdrgm:GainMapMax"),a=M(r,"hdrgm:Gamma","1"),n=M(r,"hdrgm:OffsetSDR","0.015625"),i=M(r,"hdrgm:OffsetHDR","0.015625"),o=/hdrgm:HDRCapacityMin="([^"]*)"/.exec(r),s=o?o[1]:"0",d=/hdrgm:HDRCapacityMax="([^"]*)"/.exec(r);if(!d)throw new Error("Incomplete gainmap metadata");const p=d[1];return{gainMapMin:Array.isArray(e)?e.map(e=>parseFloat(e)):[parseFloat(e),parseFloat(e),parseFloat(e)],gainMapMax:Array.isArray(t)?t.map(e=>parseFloat(e)):[parseFloat(t),parseFloat(t),parseFloat(t)],gamma:Array.isArray(a)?a.map(e=>parseFloat(e)):[parseFloat(a),parseFloat(a),parseFloat(a)],offsetSdr:Array.isArray(n)?n.map(e=>parseFloat(e)):[parseFloat(n),parseFloat(n),parseFloat(n)],offsetHdr:Array.isArray(i)?i.map(e=>parseFloat(e)):[parseFloat(i),parseFloat(i),parseFloat(i)],hdrCapacityMin:parseFloat(s),hdrCapacityMax:parseFloat(p)}}catch(e){}a=t.indexOf("<x:xmpmeta",e)}};class F{options;constructor(e){this.options={debug:!(!e||void 0===e.debug)&&e.debug,extractFII:!e||void 0===e.extractFII||e.extractFII,extractNonFII:!e||void 0===e.extractNonFII||e.extractNonFII}}extract(e){return new Promise((t,a)=>{const r=this.options.debug,n=new DataView(e.buffer);if(65496!==n.getUint16(0))return void a(new Error("Not a valid jpeg"));const i=n.byteLength;let o,s=2,d=0;for(;s<i;){if(++d>250)return void a(new Error(`Found no marker after ${d} loops 😵`));if(255!==n.getUint8(s))return void a(new Error(`Not a valid marker at offset 0x${s.toString(16)}, found: 0x${n.getUint8(s).toString(16)}`));if(o=n.getUint8(s+1),r&&console.log(`Marker: ${o.toString(16)}`),226===o){r&&console.log("Found APP2 marker (0xffe2)");const e=s+4;if(1297106432===n.getUint32(e)){const r=e+4;let i;if(18761===n.getUint16(r))i=!1;else{if(19789!==n.getUint16(r))return void a(new Error("No valid endianness marker found in TIFF header"));i=!0}if(42!==n.getUint16(r+2,!i))return void a(new Error("Not valid TIFF data! (no 0x002A marker)"));const o=n.getUint32(r+4,!i);if(o<8)return void a(new Error("Not valid TIFF data! (First offset less than 8)"));const s=r+o,d=n.getUint16(s,!i),p=s+2;let c=0;for(let e=p;e<p+12*d;e+=12)45057===n.getUint16(e,!i)&&(c=n.getUint32(e+8,!i));const l=s+2+12*d+4,g=[];for(let e=l;e<l+16*c;e+=16){const t={MPType:n.getUint32(e,!i),size:n.getUint32(e+4,!i),dataOffset:n.getUint32(e+8,!i),dependantImages:n.getUint32(e+12,!i),start:-1,end:-1,isFII:!1};t.dataOffset?(t.start=r+t.dataOffset,t.isFII=!1):(t.start=0,t.isFII=!0),t.end=t.start+t.size,g.push(t)}if(this.options.extractNonFII&&g.length){const e=new Blob([n]),a=[];for(const t of g){if(t.isFII&&!this.options.extractFII)continue;const r=e.slice(t.start,t.end+1,"image/jpeg");a.push(r)}t(a)}}}s+=2+n.getUint16(s+2)}})}}const I=async e=>{const t=x(e)??y(e);if(!t)throw new u("Gain map XMP metadata not found");const a=new F({extractFII:!0,extractNonFII:!0}),r=await a.extract(e);if(2!==r.length)throw new h("Gain map recovery image not found");return{sdr:new Uint8Array(await r[0].arrayBuffer()),gainMap:new Uint8Array(await r[1].arrayBuffer()),metadata:t}},U=e=>new Promise((t,a)=>{const r=document.createElement("img");r.onload=()=>{t(r)},r.onerror=e=>{a(e)},r.src=URL.createObjectURL(e)}),v=async(e,t,a)=>{const r=t?new Blob([t],{type:"image/jpeg"}):void 0,n=new Blob([e],{type:"image/jpeg"});let i,o,s=!1;if("undefined"==typeof createImageBitmap){const e=await Promise.all([r?U(r):Promise.resolve(void 0),U(n)]);o=e[0],i=e[1],s="flipY"===a}else{const e=await Promise.all([r?createImageBitmap(r,{imageOrientation:a||"flipY"}):Promise.resolve(void 0),createImageBitmap(n,{imageOrientation:a||"flipY"})]);o=e[0],i=e[1]}return{sdrImage:i,gainMapImage:o,needsFlip:s}},b=(a,c,l)=>{const g=new r(c||new ImageData(2,2),n,i,i,o,s,d,p,1,t);g.flipY=l,g.needsUpdate=!0;const m=new r(a,n,i,i,o,s,d,p,1,e);return m.flipY=l,m.needsUpdate=!0,{gainMap:g,sdr:m}};class R extends c{_renderer;_renderTargetOptions;_internalLoadingManager;_config;constructor(e,t){super(t),this._config=e,e.renderer&&(this._renderer=e.renderer),this._internalLoadingManager=new l}setRenderer(e){return this._renderer=e,this}setRenderTargetOptions(e){return this._renderTargetOptions=e,this}prepareQuadRenderer(){this._renderer||console.warn("WARNING: A Renderer was not passed to this Loader constructor or in setRenderer, the result of this Loader will need to be converted to a Data Texture with toDataTexture() before you can use it in your renderer.");const e=this._config.createMaterial({gainMapMax:[1,1,1],gainMapMin:[0,0,0],gamma:[1,1,1],offsetHdr:[1,1,1],offsetSdr:[1,1,1],hdrCapacityMax:1,hdrCapacityMin:0,maxDisplayBoost:1,gainMap:new r,sdr:new r});return this._config.createQuadRenderer({width:16,height:16,type:a,colorSpace:t,material:e,renderer:this._renderer,renderTargetOptions:this._renderTargetOptions})}processImages(e,t,a){return v(e,t,a)}createTextures(e,t,a){return b(e,t,a)}updateQuadRenderer(e,t,a,r,n){e.width=t.width,e.height=t.height,e.material.gainMap=a,e.material.sdr=r,e.material.gainMapMin=n.gainMapMin,e.material.gainMapMax=n.gainMapMax,e.material.offsetHdr=n.offsetHdr,e.material.offsetSdr=n.offsetSdr,e.material.gamma=n.gamma,e.material.hdrCapacityMin=n.hdrCapacityMin,e.material.hdrCapacityMax=n.hdrCapacityMax,e.material.maxDisplayBoost=Math.pow(2,n.hdrCapacityMax),e.material.needsUpdate=!0}}const S=new Set,O=(e,t,a)=>{const r=`${t}:${e}`;S.has(r)||(S.add(r),console.warn(`gainmap-js: ${e} from '${t}' is deprecated and will be removed in v4.0.0. Use ${a} from '@monogrid/gainmap-js/webgpu' with WebGPURenderer (which also has a WebGL2 backend) instead. It is not a drop-in replacement (it returns a GainMapNode, not a render target), see https://github.com/MONOGRID/gainmap-js#migrating-to-v400`))};export{h as G,R as L,F as M,u as X,b as a,x as b,f as c,y as d,I as e,v as p,O as w};
|
package/dist/worker-interface.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @monogrid/gainmap-js v3.
|
|
2
|
+
* @monogrid/gainmap-js v3.6.0
|
|
3
3
|
* With ❤️, by MONOGRID <gainmap@monogrid.com>
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-
|
|
6
|
+
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers-Cdw2adc2.js';
|
|
7
7
|
|
|
8
8
|
var lib$1;
|
|
9
9
|
var hasRequiredLib$1;
|