@monogrid/gainmap-js 1.0.2 → 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 +15 -0
- package/README.md +103 -19
- package/dist/LoaderBase-eee19701.js +382 -0
- package/dist/_commonjsHelpers-1789f0cf.js +1 -1
- package/dist/compress-a4b59cab.js +1 -1
- package/dist/decode.d.ts +25 -6
- package/dist/encode-utils/get-sdr-rendition.d.ts +2 -2
- package/dist/encode.d.ts +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +189 -258
- package/dist/index.umd.js +331 -27
- 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-esm.wasm +0 -0
- package/dist/libultrahdr.d.ts +4 -128
- package/dist/libultrahdr.js +322 -278
- package/dist/libultrahdr.umd.js +687 -271
- package/dist/loaders/GainMapLoader.d.ts +68 -0
- package/dist/loaders/JPEGRLoader.d.ts +60 -0
- package/dist/loaders/LoaderBase.d.ts +27 -0
- package/dist/materials/GainMapDecoderMaterial.d.ts +44 -1
- package/dist/materials/GainMapEncoderMaterial.d.ts +29 -2
- package/dist/types.d.ts +26 -6
- package/dist/utils/QuadRenderer.d.ts +8 -1
- 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/libultrahdr-wasm/build/libultrahdr-debug.js +156 -182
- package/libultrahdr-wasm/build/libultrahdr-debug.wasm +0 -0
- package/libultrahdr-wasm/build/libultrahdr-esm.js +153 -182
- package/libultrahdr-wasm/build/libultrahdr-esm.wasm +0 -0
- package/libultrahdr-wasm/build/libultrahdr.js +151 -180
- package/libultrahdr-wasm/build/libultrahdr.wasm +0 -0
- package/package.json +1 -1
- package/examples/README.md +0 -3
- package/examples/compress.ts +0 -43
- package/examples/decode-from-jpeg.ts +0 -40
- package/examples/decode-from-separate-data.ts +0 -41
- package/examples/decode-to-datatexture.ts +0 -65
- package/examples/encode-and-compress.ts +0 -29
- package/examples/encode-jpeg-metadata.ts +0 -57
- package/examples/encode.ts +0 -28
- package/examples/globals.d.ts +0 -6
- package/examples/worker.ts +0 -41
- package/reports/eslint-examples.json +0 -1
- package/reports/eslint-src.json +0 -1
- package/reports/eslint-tests.json +0 -1
- package/reports/junit.xml +0 -35
- package/reports/typecheck-examples.log +0 -0
- package/reports/typecheck-tests.log +0 -0
- package/reports/typecheck.log +0 -0
package/dist/libultrahdr.umd.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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
|
|
|
6
6
|
(function (global, factory) {
|
|
7
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
8
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
9
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.libultrahdr = {}));
|
|
10
|
-
})(this, (function (exports) { 'use strict';
|
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('three')) :
|
|
8
|
+
typeof define === 'function' && define.amd ? define(['exports', 'three'], factory) :
|
|
9
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.libultrahdr = {}, global.three));
|
|
10
|
+
})(this, (function (exports, three) { 'use strict';
|
|
11
11
|
|
|
12
12
|
var Module = (() => {
|
|
13
13
|
var _scriptDir = (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('libultrahdr.umd.js', document.baseURI).href));
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
readyPromiseResolve = resolve;
|
|
38
38
|
readyPromiseReject = reject;
|
|
39
39
|
});
|
|
40
|
-
["_main","_memory","___indirect_function_table","
|
|
40
|
+
["_main","_memory","___indirect_function_table","_fflush","onRuntimeInitialized"].forEach((prop) => {
|
|
41
41
|
if (!Object.getOwnPropertyDescriptor(Module['ready'], prop)) {
|
|
42
42
|
Object.defineProperty(Module['ready'], prop, {
|
|
43
43
|
get: () => abort('You are getting ' + prop + ' on the Promise object, instead of the instance. Use .then() to get called back with the instance, see the MODULARIZE docs in src/settings.js'),
|
|
@@ -355,7 +355,7 @@
|
|
|
355
355
|
// An online HTML version (which may be of a different version of Emscripten)
|
|
356
356
|
// is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html
|
|
357
357
|
|
|
358
|
-
var wasmBinary;
|
|
358
|
+
var wasmBinary;
|
|
359
359
|
if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];legacyModuleProp('wasmBinary', 'wasmBinary');
|
|
360
360
|
|
|
361
361
|
if (typeof WebAssembly != 'object') {
|
|
@@ -379,6 +379,10 @@
|
|
|
379
379
|
// but only when noExitRuntime is false.
|
|
380
380
|
var EXITSTATUS;
|
|
381
381
|
|
|
382
|
+
// In STRICT mode, we only define assert() when ASSERTIONS is set. i.e. we
|
|
383
|
+
// don't define it at all in release modes. This matches the behaviour of
|
|
384
|
+
// MINIMAL_RUNTIME.
|
|
385
|
+
// TODO(sbc): Make this the default even without STRICT enabled.
|
|
382
386
|
/** @type {function(*, string=)} */
|
|
383
387
|
function assert(condition, text) {
|
|
384
388
|
if (!condition) {
|
|
@@ -1173,10 +1177,7 @@
|
|
|
1173
1177
|
var setter = field.setter;
|
|
1174
1178
|
var setterContext = field.setterContext;
|
|
1175
1179
|
fields[fieldName] = {
|
|
1176
|
-
read: (ptr) =>
|
|
1177
|
-
return getterReturnType['fromWireType'](
|
|
1178
|
-
getter(getterContext, ptr));
|
|
1179
|
-
},
|
|
1180
|
+
read: (ptr) => getterReturnType['fromWireType'](getter(getterContext, ptr)),
|
|
1180
1181
|
write: (ptr, o) => {
|
|
1181
1182
|
var destructors = [];
|
|
1182
1183
|
setter(setterContext, ptr, setterArgumentType['toWireType'](destructors, o));
|
|
@@ -1442,33 +1443,12 @@
|
|
|
1442
1443
|
});
|
|
1443
1444
|
};
|
|
1444
1445
|
|
|
1445
|
-
var
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
var makeLegalFunctionName = (name) => {
|
|
1449
|
-
if (undefined === name) {
|
|
1450
|
-
return '_unknown';
|
|
1451
|
-
}
|
|
1452
|
-
name = name.replace(/[^a-zA-Z0-9_]/g, '$');
|
|
1453
|
-
var f = name.charCodeAt(0);
|
|
1454
|
-
if (f >= char_0 && f <= char_9) {
|
|
1455
|
-
return `_${name}`;
|
|
1456
|
-
}
|
|
1457
|
-
return name;
|
|
1458
|
-
};
|
|
1446
|
+
var createNamedFunction = (name, body) => Object.defineProperty(body, 'name', {
|
|
1447
|
+
value: name
|
|
1448
|
+
});
|
|
1459
1449
|
|
|
1460
1450
|
|
|
1461
1451
|
|
|
1462
|
-
function createNamedFunction(name, body) {
|
|
1463
|
-
name = makeLegalFunctionName(name);
|
|
1464
|
-
// Use an abject with a computed property name to create a new function with
|
|
1465
|
-
// a name specified at runtime, but without using `new Function` or `eval`.
|
|
1466
|
-
return {
|
|
1467
|
-
[name]: function() {
|
|
1468
|
-
return body.apply(this, arguments);
|
|
1469
|
-
}
|
|
1470
|
-
}[name];
|
|
1471
|
-
}
|
|
1472
1452
|
function newFunc(constructor, argumentList) {
|
|
1473
1453
|
if (!(constructor instanceof Function)) {
|
|
1474
1454
|
throw new TypeError(`new_ called with constructor type ${typeof(constructor)} which is not a function`);
|
|
@@ -1537,7 +1517,7 @@
|
|
|
1537
1517
|
}
|
|
1538
1518
|
|
|
1539
1519
|
var invokerFnBody = `
|
|
1540
|
-
return function
|
|
1520
|
+
return function (${argsList}) {
|
|
1541
1521
|
if (arguments.length !== ${argCount - 2}) {
|
|
1542
1522
|
throwBindingError('function ${humanName} called with ' + arguments.length + ' arguments, expected ${argCount - 2}');
|
|
1543
1523
|
}`;
|
|
@@ -1589,7 +1569,8 @@
|
|
|
1589
1569
|
|
|
1590
1570
|
args1.push(invokerFnBody);
|
|
1591
1571
|
|
|
1592
|
-
|
|
1572
|
+
var invokerFn = newFunc(Function, args1).apply(null, args2);
|
|
1573
|
+
return createNamedFunction(humanName, invokerFn);
|
|
1593
1574
|
}
|
|
1594
1575
|
|
|
1595
1576
|
var ensureOverloadTable = (proto, methodName, humanName) => {
|
|
@@ -1921,7 +1902,7 @@
|
|
|
1921
1902
|
|
|
1922
1903
|
|
|
1923
1904
|
var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
|
|
1924
|
-
assert(typeof str === 'string');
|
|
1905
|
+
assert(typeof str === 'string', `stringToUTF8Array expects a string (got ${typeof str})`);
|
|
1925
1906
|
// Parameter maxBytesToWrite is not optional. Negative values, 0, null,
|
|
1926
1907
|
// undefined and false each don't write out any bytes.
|
|
1927
1908
|
if (!(maxBytesToWrite > 0))
|
|
@@ -2065,7 +2046,7 @@
|
|
|
2065
2046
|
* @return {string}
|
|
2066
2047
|
*/
|
|
2067
2048
|
var UTF8ToString = (ptr, maxBytesToRead) => {
|
|
2068
|
-
assert(typeof ptr == 'number');
|
|
2049
|
+
assert(typeof ptr == 'number', `UTF8ToString expects a number (got ${typeof ptr})`);
|
|
2069
2050
|
return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : '';
|
|
2070
2051
|
};
|
|
2071
2052
|
var __embind_register_std_string = (rawType, name) => {
|
|
@@ -2438,9 +2419,7 @@
|
|
|
2438
2419
|
return symbol;
|
|
2439
2420
|
};
|
|
2440
2421
|
|
|
2441
|
-
var __emval_new_cstring = (v) =>
|
|
2442
|
-
return Emval.toHandle(getStringOrSymbol(v));
|
|
2443
|
-
};
|
|
2422
|
+
var __emval_new_cstring = (v) => Emval.toHandle(getStringOrSymbol(v));
|
|
2444
2423
|
|
|
2445
2424
|
|
|
2446
2425
|
|
|
@@ -2655,9 +2634,7 @@
|
|
|
2655
2634
|
var paths = Array.prototype.slice.call(arguments);
|
|
2656
2635
|
return PATH.normalize(paths.join('/'));
|
|
2657
2636
|
},
|
|
2658
|
-
join2:(l, r) =>
|
|
2659
|
-
return PATH.normalize(l + '/' + r);
|
|
2660
|
-
},
|
|
2637
|
+
join2:(l, r) => PATH.normalize(l + '/' + r),
|
|
2661
2638
|
};
|
|
2662
2639
|
|
|
2663
2640
|
var initRandomFill = () => {
|
|
@@ -3314,7 +3291,7 @@
|
|
|
3314
3291
|
|
|
3315
3292
|
|
|
3316
3293
|
var FS_createDataFile = (parent, name, fileData, canRead, canWrite, canOwn) => {
|
|
3317
|
-
|
|
3294
|
+
FS.createDataFile(parent, name, fileData, canRead, canWrite, canOwn);
|
|
3318
3295
|
};
|
|
3319
3296
|
|
|
3320
3297
|
var preloadPlugins = Module['preloadPlugins'] || [];
|
|
@@ -3511,7 +3488,128 @@
|
|
|
3511
3488
|
};
|
|
3512
3489
|
|
|
3513
3490
|
var ERRNO_CODES = {
|
|
3514
|
-
|
|
3491
|
+
'EPERM': 63,
|
|
3492
|
+
'ENOENT': 44,
|
|
3493
|
+
'ESRCH': 71,
|
|
3494
|
+
'EINTR': 27,
|
|
3495
|
+
'EIO': 29,
|
|
3496
|
+
'ENXIO': 60,
|
|
3497
|
+
'E2BIG': 1,
|
|
3498
|
+
'ENOEXEC': 45,
|
|
3499
|
+
'EBADF': 8,
|
|
3500
|
+
'ECHILD': 12,
|
|
3501
|
+
'EAGAIN': 6,
|
|
3502
|
+
'EWOULDBLOCK': 6,
|
|
3503
|
+
'ENOMEM': 48,
|
|
3504
|
+
'EACCES': 2,
|
|
3505
|
+
'EFAULT': 21,
|
|
3506
|
+
'ENOTBLK': 105,
|
|
3507
|
+
'EBUSY': 10,
|
|
3508
|
+
'EEXIST': 20,
|
|
3509
|
+
'EXDEV': 75,
|
|
3510
|
+
'ENODEV': 43,
|
|
3511
|
+
'ENOTDIR': 54,
|
|
3512
|
+
'EISDIR': 31,
|
|
3513
|
+
'EINVAL': 28,
|
|
3514
|
+
'ENFILE': 41,
|
|
3515
|
+
'EMFILE': 33,
|
|
3516
|
+
'ENOTTY': 59,
|
|
3517
|
+
'ETXTBSY': 74,
|
|
3518
|
+
'EFBIG': 22,
|
|
3519
|
+
'ENOSPC': 51,
|
|
3520
|
+
'ESPIPE': 70,
|
|
3521
|
+
'EROFS': 69,
|
|
3522
|
+
'EMLINK': 34,
|
|
3523
|
+
'EPIPE': 64,
|
|
3524
|
+
'EDOM': 18,
|
|
3525
|
+
'ERANGE': 68,
|
|
3526
|
+
'ENOMSG': 49,
|
|
3527
|
+
'EIDRM': 24,
|
|
3528
|
+
'ECHRNG': 106,
|
|
3529
|
+
'EL2NSYNC': 156,
|
|
3530
|
+
'EL3HLT': 107,
|
|
3531
|
+
'EL3RST': 108,
|
|
3532
|
+
'ELNRNG': 109,
|
|
3533
|
+
'EUNATCH': 110,
|
|
3534
|
+
'ENOCSI': 111,
|
|
3535
|
+
'EL2HLT': 112,
|
|
3536
|
+
'EDEADLK': 16,
|
|
3537
|
+
'ENOLCK': 46,
|
|
3538
|
+
'EBADE': 113,
|
|
3539
|
+
'EBADR': 114,
|
|
3540
|
+
'EXFULL': 115,
|
|
3541
|
+
'ENOANO': 104,
|
|
3542
|
+
'EBADRQC': 103,
|
|
3543
|
+
'EBADSLT': 102,
|
|
3544
|
+
'EDEADLOCK': 16,
|
|
3545
|
+
'EBFONT': 101,
|
|
3546
|
+
'ENOSTR': 100,
|
|
3547
|
+
'ENODATA': 116,
|
|
3548
|
+
'ETIME': 117,
|
|
3549
|
+
'ENOSR': 118,
|
|
3550
|
+
'ENONET': 119,
|
|
3551
|
+
'ENOPKG': 120,
|
|
3552
|
+
'EREMOTE': 121,
|
|
3553
|
+
'ENOLINK': 47,
|
|
3554
|
+
'EADV': 122,
|
|
3555
|
+
'ESRMNT': 123,
|
|
3556
|
+
'ECOMM': 124,
|
|
3557
|
+
'EPROTO': 65,
|
|
3558
|
+
'EMULTIHOP': 36,
|
|
3559
|
+
'EDOTDOT': 125,
|
|
3560
|
+
'EBADMSG': 9,
|
|
3561
|
+
'ENOTUNIQ': 126,
|
|
3562
|
+
'EBADFD': 127,
|
|
3563
|
+
'EREMCHG': 128,
|
|
3564
|
+
'ELIBACC': 129,
|
|
3565
|
+
'ELIBBAD': 130,
|
|
3566
|
+
'ELIBSCN': 131,
|
|
3567
|
+
'ELIBMAX': 132,
|
|
3568
|
+
'ELIBEXEC': 133,
|
|
3569
|
+
'ENOSYS': 52,
|
|
3570
|
+
'ENOTEMPTY': 55,
|
|
3571
|
+
'ENAMETOOLONG': 37,
|
|
3572
|
+
'ELOOP': 32,
|
|
3573
|
+
'EOPNOTSUPP': 138,
|
|
3574
|
+
'EPFNOSUPPORT': 139,
|
|
3575
|
+
'ECONNRESET': 15,
|
|
3576
|
+
'ENOBUFS': 42,
|
|
3577
|
+
'EAFNOSUPPORT': 5,
|
|
3578
|
+
'EPROTOTYPE': 67,
|
|
3579
|
+
'ENOTSOCK': 57,
|
|
3580
|
+
'ENOPROTOOPT': 50,
|
|
3581
|
+
'ESHUTDOWN': 140,
|
|
3582
|
+
'ECONNREFUSED': 14,
|
|
3583
|
+
'EADDRINUSE': 3,
|
|
3584
|
+
'ECONNABORTED': 13,
|
|
3585
|
+
'ENETUNREACH': 40,
|
|
3586
|
+
'ENETDOWN': 38,
|
|
3587
|
+
'ETIMEDOUT': 73,
|
|
3588
|
+
'EHOSTDOWN': 142,
|
|
3589
|
+
'EHOSTUNREACH': 23,
|
|
3590
|
+
'EINPROGRESS': 26,
|
|
3591
|
+
'EALREADY': 7,
|
|
3592
|
+
'EDESTADDRREQ': 17,
|
|
3593
|
+
'EMSGSIZE': 35,
|
|
3594
|
+
'EPROTONOSUPPORT': 66,
|
|
3595
|
+
'ESOCKTNOSUPPORT': 137,
|
|
3596
|
+
'EADDRNOTAVAIL': 4,
|
|
3597
|
+
'ENETRESET': 39,
|
|
3598
|
+
'EISCONN': 30,
|
|
3599
|
+
'ENOTCONN': 53,
|
|
3600
|
+
'ETOOMANYREFS': 141,
|
|
3601
|
+
'EUSERS': 136,
|
|
3602
|
+
'EDQUOT': 19,
|
|
3603
|
+
'ESTALE': 72,
|
|
3604
|
+
'ENOTSUP': 138,
|
|
3605
|
+
'ENOMEDIUM': 148,
|
|
3606
|
+
'EILSEQ': 25,
|
|
3607
|
+
'EOVERFLOW': 61,
|
|
3608
|
+
'ECANCELED': 11,
|
|
3609
|
+
'ENOTRECOVERABLE': 56,
|
|
3610
|
+
'EOWNERDEAD': 62,
|
|
3611
|
+
'ESTRPIPE': 135,
|
|
3612
|
+
};
|
|
3515
3613
|
|
|
3516
3614
|
var demangle = (func) => {
|
|
3517
3615
|
warnOnce('warning: build with -sDEMANGLE_SUPPORT to link in libcxxabi demangling');
|
|
@@ -4850,7 +4948,6 @@
|
|
|
4850
4948
|
FS.close(stream);
|
|
4851
4949
|
FS.chmod(node, mode);
|
|
4852
4950
|
}
|
|
4853
|
-
return node;
|
|
4854
4951
|
},
|
|
4855
4952
|
createDevice(parent, name, input, output) {
|
|
4856
4953
|
var path = PATH.join2(typeof parent == 'string' ? parent : FS.getPath(parent), name);
|
|
@@ -5149,19 +5246,19 @@
|
|
|
5149
5246
|
HEAP32[(((buf)+(12))>>2)] = stat.uid;
|
|
5150
5247
|
HEAP32[(((buf)+(16))>>2)] = stat.gid;
|
|
5151
5248
|
HEAP32[(((buf)+(20))>>2)] = stat.rdev;
|
|
5152
|
-
(tempI64 = [stat.size>>>0,(tempDouble=stat.size,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(24))>>2)] = tempI64[0],HEAP32[(((buf)+(28))>>2)] = tempI64[1]);
|
|
5249
|
+
(tempI64 = [stat.size>>>0,(tempDouble = stat.size,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(24))>>2)] = tempI64[0],HEAP32[(((buf)+(28))>>2)] = tempI64[1]);
|
|
5153
5250
|
HEAP32[(((buf)+(32))>>2)] = 4096;
|
|
5154
5251
|
HEAP32[(((buf)+(36))>>2)] = stat.blocks;
|
|
5155
5252
|
var atime = stat.atime.getTime();
|
|
5156
5253
|
var mtime = stat.mtime.getTime();
|
|
5157
5254
|
var ctime = stat.ctime.getTime();
|
|
5158
|
-
(tempI64 = [Math.floor(atime / 1000)>>>0,(tempDouble=Math.floor(atime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(40))>>2)] = tempI64[0],HEAP32[(((buf)+(44))>>2)] = tempI64[1]);
|
|
5255
|
+
(tempI64 = [Math.floor(atime / 1000)>>>0,(tempDouble = Math.floor(atime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(40))>>2)] = tempI64[0],HEAP32[(((buf)+(44))>>2)] = tempI64[1]);
|
|
5159
5256
|
HEAPU32[(((buf)+(48))>>2)] = (atime % 1000) * 1000;
|
|
5160
|
-
(tempI64 = [Math.floor(mtime / 1000)>>>0,(tempDouble=Math.floor(mtime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(56))>>2)] = tempI64[0],HEAP32[(((buf)+(60))>>2)] = tempI64[1]);
|
|
5257
|
+
(tempI64 = [Math.floor(mtime / 1000)>>>0,(tempDouble = Math.floor(mtime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(56))>>2)] = tempI64[0],HEAP32[(((buf)+(60))>>2)] = tempI64[1]);
|
|
5161
5258
|
HEAPU32[(((buf)+(64))>>2)] = (mtime % 1000) * 1000;
|
|
5162
|
-
(tempI64 = [Math.floor(ctime / 1000)>>>0,(tempDouble=Math.floor(ctime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(72))>>2)] = tempI64[0],HEAP32[(((buf)+(76))>>2)] = tempI64[1]);
|
|
5259
|
+
(tempI64 = [Math.floor(ctime / 1000)>>>0,(tempDouble = Math.floor(ctime / 1000),(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(72))>>2)] = tempI64[0],HEAP32[(((buf)+(76))>>2)] = tempI64[1]);
|
|
5163
5260
|
HEAPU32[(((buf)+(80))>>2)] = (ctime % 1000) * 1000;
|
|
5164
|
-
(tempI64 = [stat.ino>>>0,(tempDouble=stat.ino,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(88))>>2)] = tempI64[0],HEAP32[(((buf)+(92))>>2)] = tempI64[1]);
|
|
5261
|
+
(tempI64 = [stat.ino>>>0,(tempDouble = stat.ino,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[(((buf)+(88))>>2)] = tempI64[0],HEAP32[(((buf)+(92))>>2)] = tempI64[1]);
|
|
5165
5262
|
return 0;
|
|
5166
5263
|
},
|
|
5167
5264
|
doMsync(addr, stream, len, flags, offset) {
|
|
@@ -5302,7 +5399,7 @@
|
|
|
5302
5399
|
if (isNaN(offset)) return 61;
|
|
5303
5400
|
var stream = SYSCALLS.getStreamFromFD(fd);
|
|
5304
5401
|
FS.llseek(stream, offset, whence);
|
|
5305
|
-
(tempI64 = [stream.position>>>0,(tempDouble=stream.position,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[((newOffset)>>2)] = tempI64[0],HEAP32[(((newOffset)+(4))>>2)] = tempI64[1]);
|
|
5402
|
+
(tempI64 = [stream.position>>>0,(tempDouble = stream.position,(+(Math.abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? (+(Math.floor((tempDouble)/4294967296.0)))>>>0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)], HEAP32[((newOffset)>>2)] = tempI64[0],HEAP32[(((newOffset)+(4))>>2)] = tempI64[1]);
|
|
5306
5403
|
if (stream.getdents && offset === 0 && whence === 0) stream.getdents = null; // reset readdir state
|
|
5307
5404
|
return 0;
|
|
5308
5405
|
} catch (e) {
|
|
@@ -5341,9 +5438,7 @@
|
|
|
5341
5438
|
}
|
|
5342
5439
|
}
|
|
5343
5440
|
|
|
5344
|
-
var isLeapYear = (year) =>
|
|
5345
|
-
return year%4 === 0 && (year%100 !== 0 || year%400 === 0);
|
|
5346
|
-
};
|
|
5441
|
+
var isLeapYear = (year) => year%4 === 0 && (year%100 !== 0 || year%400 === 0);
|
|
5347
5442
|
|
|
5348
5443
|
var arraySum = (array, index) => {
|
|
5349
5444
|
var sum = 0;
|
|
@@ -5715,129 +5810,7 @@
|
|
|
5715
5810
|
});
|
|
5716
5811
|
FS.FSNode = FSNode;
|
|
5717
5812
|
FS.createPreloadedFile = FS_createPreloadedFile;
|
|
5718
|
-
FS.staticInit();
|
|
5719
|
-
'EPERM': 63,
|
|
5720
|
-
'ENOENT': 44,
|
|
5721
|
-
'ESRCH': 71,
|
|
5722
|
-
'EINTR': 27,
|
|
5723
|
-
'EIO': 29,
|
|
5724
|
-
'ENXIO': 60,
|
|
5725
|
-
'E2BIG': 1,
|
|
5726
|
-
'ENOEXEC': 45,
|
|
5727
|
-
'EBADF': 8,
|
|
5728
|
-
'ECHILD': 12,
|
|
5729
|
-
'EAGAIN': 6,
|
|
5730
|
-
'EWOULDBLOCK': 6,
|
|
5731
|
-
'ENOMEM': 48,
|
|
5732
|
-
'EACCES': 2,
|
|
5733
|
-
'EFAULT': 21,
|
|
5734
|
-
'ENOTBLK': 105,
|
|
5735
|
-
'EBUSY': 10,
|
|
5736
|
-
'EEXIST': 20,
|
|
5737
|
-
'EXDEV': 75,
|
|
5738
|
-
'ENODEV': 43,
|
|
5739
|
-
'ENOTDIR': 54,
|
|
5740
|
-
'EISDIR': 31,
|
|
5741
|
-
'EINVAL': 28,
|
|
5742
|
-
'ENFILE': 41,
|
|
5743
|
-
'EMFILE': 33,
|
|
5744
|
-
'ENOTTY': 59,
|
|
5745
|
-
'ETXTBSY': 74,
|
|
5746
|
-
'EFBIG': 22,
|
|
5747
|
-
'ENOSPC': 51,
|
|
5748
|
-
'ESPIPE': 70,
|
|
5749
|
-
'EROFS': 69,
|
|
5750
|
-
'EMLINK': 34,
|
|
5751
|
-
'EPIPE': 64,
|
|
5752
|
-
'EDOM': 18,
|
|
5753
|
-
'ERANGE': 68,
|
|
5754
|
-
'ENOMSG': 49,
|
|
5755
|
-
'EIDRM': 24,
|
|
5756
|
-
'ECHRNG': 106,
|
|
5757
|
-
'EL2NSYNC': 156,
|
|
5758
|
-
'EL3HLT': 107,
|
|
5759
|
-
'EL3RST': 108,
|
|
5760
|
-
'ELNRNG': 109,
|
|
5761
|
-
'EUNATCH': 110,
|
|
5762
|
-
'ENOCSI': 111,
|
|
5763
|
-
'EL2HLT': 112,
|
|
5764
|
-
'EDEADLK': 16,
|
|
5765
|
-
'ENOLCK': 46,
|
|
5766
|
-
'EBADE': 113,
|
|
5767
|
-
'EBADR': 114,
|
|
5768
|
-
'EXFULL': 115,
|
|
5769
|
-
'ENOANO': 104,
|
|
5770
|
-
'EBADRQC': 103,
|
|
5771
|
-
'EBADSLT': 102,
|
|
5772
|
-
'EDEADLOCK': 16,
|
|
5773
|
-
'EBFONT': 101,
|
|
5774
|
-
'ENOSTR': 100,
|
|
5775
|
-
'ENODATA': 116,
|
|
5776
|
-
'ETIME': 117,
|
|
5777
|
-
'ENOSR': 118,
|
|
5778
|
-
'ENONET': 119,
|
|
5779
|
-
'ENOPKG': 120,
|
|
5780
|
-
'EREMOTE': 121,
|
|
5781
|
-
'ENOLINK': 47,
|
|
5782
|
-
'EADV': 122,
|
|
5783
|
-
'ESRMNT': 123,
|
|
5784
|
-
'ECOMM': 124,
|
|
5785
|
-
'EPROTO': 65,
|
|
5786
|
-
'EMULTIHOP': 36,
|
|
5787
|
-
'EDOTDOT': 125,
|
|
5788
|
-
'EBADMSG': 9,
|
|
5789
|
-
'ENOTUNIQ': 126,
|
|
5790
|
-
'EBADFD': 127,
|
|
5791
|
-
'EREMCHG': 128,
|
|
5792
|
-
'ELIBACC': 129,
|
|
5793
|
-
'ELIBBAD': 130,
|
|
5794
|
-
'ELIBSCN': 131,
|
|
5795
|
-
'ELIBMAX': 132,
|
|
5796
|
-
'ELIBEXEC': 133,
|
|
5797
|
-
'ENOSYS': 52,
|
|
5798
|
-
'ENOTEMPTY': 55,
|
|
5799
|
-
'ENAMETOOLONG': 37,
|
|
5800
|
-
'ELOOP': 32,
|
|
5801
|
-
'EOPNOTSUPP': 138,
|
|
5802
|
-
'EPFNOSUPPORT': 139,
|
|
5803
|
-
'ECONNRESET': 15,
|
|
5804
|
-
'ENOBUFS': 42,
|
|
5805
|
-
'EAFNOSUPPORT': 5,
|
|
5806
|
-
'EPROTOTYPE': 67,
|
|
5807
|
-
'ENOTSOCK': 57,
|
|
5808
|
-
'ENOPROTOOPT': 50,
|
|
5809
|
-
'ESHUTDOWN': 140,
|
|
5810
|
-
'ECONNREFUSED': 14,
|
|
5811
|
-
'EADDRINUSE': 3,
|
|
5812
|
-
'ECONNABORTED': 13,
|
|
5813
|
-
'ENETUNREACH': 40,
|
|
5814
|
-
'ENETDOWN': 38,
|
|
5815
|
-
'ETIMEDOUT': 73,
|
|
5816
|
-
'EHOSTDOWN': 142,
|
|
5817
|
-
'EHOSTUNREACH': 23,
|
|
5818
|
-
'EINPROGRESS': 26,
|
|
5819
|
-
'EALREADY': 7,
|
|
5820
|
-
'EDESTADDRREQ': 17,
|
|
5821
|
-
'EMSGSIZE': 35,
|
|
5822
|
-
'EPROTONOSUPPORT': 66,
|
|
5823
|
-
'ESOCKTNOSUPPORT': 137,
|
|
5824
|
-
'EADDRNOTAVAIL': 4,
|
|
5825
|
-
'ENETRESET': 39,
|
|
5826
|
-
'EISCONN': 30,
|
|
5827
|
-
'ENOTCONN': 53,
|
|
5828
|
-
'ETOOMANYREFS': 141,
|
|
5829
|
-
'EUSERS': 136,
|
|
5830
|
-
'EDQUOT': 19,
|
|
5831
|
-
'ESTALE': 72,
|
|
5832
|
-
'ENOTSUP': 138,
|
|
5833
|
-
'ENOMEDIUM': 148,
|
|
5834
|
-
'EILSEQ': 25,
|
|
5835
|
-
'EOVERFLOW': 61,
|
|
5836
|
-
'ECANCELED': 11,
|
|
5837
|
-
'ENOTRECOVERABLE': 56,
|
|
5838
|
-
'EOWNERDEAD': 62,
|
|
5839
|
-
'ESTRPIPE': 135,
|
|
5840
|
-
};function checkIncomingModuleAPI() {
|
|
5813
|
+
FS.staticInit();function checkIncomingModuleAPI() {
|
|
5841
5814
|
ignoredModuleProp('fetchSettings');
|
|
5842
5815
|
}
|
|
5843
5816
|
var wasmImports = {
|
|
@@ -5919,7 +5892,6 @@
|
|
|
5919
5892
|
var _main = Module['_main'] = createExportWrapper('main');
|
|
5920
5893
|
var _free = createExportWrapper('free');
|
|
5921
5894
|
var ___getTypeName = createExportWrapper('__getTypeName');
|
|
5922
|
-
Module['__embind_initialize_bindings'] = createExportWrapper('_embind_initialize_bindings');
|
|
5923
5895
|
var _fflush = Module['_fflush'] = createExportWrapper('fflush');
|
|
5924
5896
|
var _setThrew = createExportWrapper('setThrew');
|
|
5925
5897
|
var _emscripten_stack_init = () => (_emscripten_stack_init = wasmExports['emscripten_stack_init'])();
|
|
@@ -6183,8 +6155,11 @@
|
|
|
6183
6155
|
'downcastPointer',
|
|
6184
6156
|
'upcastPointer',
|
|
6185
6157
|
'validateThis',
|
|
6186
|
-
'
|
|
6158
|
+
'char_0',
|
|
6159
|
+
'char_9',
|
|
6160
|
+
'makeLegalFunctionName',
|
|
6187
6161
|
'emval_get_global',
|
|
6162
|
+
'emval_returnValue',
|
|
6188
6163
|
'emval_lookupTypes',
|
|
6189
6164
|
'emval_addMethodCaller',
|
|
6190
6165
|
];
|
|
@@ -6365,17 +6340,14 @@
|
|
|
6365
6340
|
'detachFinalizer_deps',
|
|
6366
6341
|
'deletionQueue',
|
|
6367
6342
|
'delayFunction',
|
|
6368
|
-
'char_0',
|
|
6369
|
-
'char_9',
|
|
6370
|
-
'makeLegalFunctionName',
|
|
6371
6343
|
'emval_handles',
|
|
6372
6344
|
'emval_symbols',
|
|
6373
6345
|
'init_emval',
|
|
6374
6346
|
'count_emval_handles',
|
|
6375
6347
|
'getStringOrSymbol',
|
|
6376
6348
|
'Emval',
|
|
6377
|
-
'emval_newers',
|
|
6378
6349
|
'emval_methodCallers',
|
|
6350
|
+
'reflectConstruct',
|
|
6379
6351
|
];
|
|
6380
6352
|
unexportedSymbols.forEach(unexportedRuntimeSymbol);
|
|
6381
6353
|
|
|
@@ -6530,7 +6502,6 @@
|
|
|
6530
6502
|
|
|
6531
6503
|
return moduleArg.ready
|
|
6532
6504
|
}
|
|
6533
|
-
|
|
6534
6505
|
);
|
|
6535
6506
|
})();
|
|
6536
6507
|
var libultrahdr = Module;
|
|
@@ -6550,6 +6521,96 @@
|
|
|
6550
6521
|
}
|
|
6551
6522
|
return library;
|
|
6552
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
|
+
|
|
6553
6614
|
/**
|
|
6554
6615
|
* Encapsulates a Gainmap into a single JPEG file (aka: JPEG-R) with the base map
|
|
6555
6616
|
* as the sdr visualization and the gainMap encoded into a MPF (Multi-Picture Format) tag.
|
|
@@ -6576,9 +6637,17 @@
|
|
|
6576
6637
|
* })
|
|
6577
6638
|
*
|
|
6578
6639
|
* // obtain the RAW RGBA SDR buffer and create an ImageData
|
|
6579
|
-
* const sdrImageData = new ImageData(
|
|
6640
|
+
* const sdrImageData = new ImageData(
|
|
6641
|
+
* encodingResult.sdr.toArray(),
|
|
6642
|
+
* encodingResult.sdr.width,
|
|
6643
|
+
* encodingResult.sdr.height
|
|
6644
|
+
* )
|
|
6580
6645
|
* // obtain the RAW RGBA Gain map buffer and create an ImageData
|
|
6581
|
-
* const gainMapImageData = new ImageData(
|
|
6646
|
+
* const gainMapImageData = new ImageData(
|
|
6647
|
+
* encodingResult.gainMap.toArray(),
|
|
6648
|
+
* encodingResult.gainMap.width,
|
|
6649
|
+
* encodingResult.gainMap.height
|
|
6650
|
+
* )
|
|
6582
6651
|
*
|
|
6583
6652
|
* // parallel compress the RAW buffers into the specified mimeType
|
|
6584
6653
|
* const mimeType = 'image/jpeg'
|
|
@@ -6628,109 +6697,456 @@
|
|
|
6628
6697
|
throw new Error('This function expects a GainMap image compressed in jpeg');
|
|
6629
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);
|
|
6630
6699
|
};
|
|
6700
|
+
|
|
6701
|
+
const vertexShader = /* glsl */ `
|
|
6702
|
+
varying vec2 vUv;
|
|
6703
|
+
|
|
6704
|
+
void main() {
|
|
6705
|
+
vUv = uv;
|
|
6706
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
6707
|
+
}
|
|
6708
|
+
`;
|
|
6709
|
+
const fragmentShader = /* glsl */ `
|
|
6710
|
+
uniform sampler2D sdr;
|
|
6711
|
+
uniform sampler2D gainMap;
|
|
6712
|
+
uniform vec3 gamma;
|
|
6713
|
+
uniform vec3 offsetHdr;
|
|
6714
|
+
uniform vec3 offsetSdr;
|
|
6715
|
+
uniform vec3 gainMapMin;
|
|
6716
|
+
uniform vec3 gainMapMax;
|
|
6717
|
+
uniform float weightFactor;
|
|
6718
|
+
|
|
6719
|
+
varying vec2 vUv;
|
|
6720
|
+
|
|
6721
|
+
void main() {
|
|
6722
|
+
vec3 rgb = texture2D(sdr, vUv).rgb;
|
|
6723
|
+
vec3 recovery = texture2D(gainMap, vUv).rgb;
|
|
6724
|
+
vec3 logRecovery = pow(recovery, gamma);
|
|
6725
|
+
vec3 logBoost = gainMapMin * (1.0 - logRecovery) + gainMapMax * logRecovery;
|
|
6726
|
+
vec3 hdrColor = (rgb + offsetSdr) * exp2(logBoost * weightFactor) - offsetHdr;
|
|
6727
|
+
gl_FragColor = vec4(hdrColor, 1.0);
|
|
6728
|
+
}
|
|
6729
|
+
`;
|
|
6631
6730
|
/**
|
|
6731
|
+
* A Material which is able to decode the Gainmap into a full HDR Representation
|
|
6632
6732
|
*
|
|
6633
|
-
* @
|
|
6634
|
-
* @
|
|
6635
|
-
* @param defaultValue
|
|
6636
|
-
* @returns
|
|
6733
|
+
* @category Materials
|
|
6734
|
+
* @group Materials
|
|
6637
6735
|
*/
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
|
|
6641
|
-
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6647
|
-
|
|
6736
|
+
class GainMapDecoderMaterial extends three.ShaderMaterial {
|
|
6737
|
+
/**
|
|
6738
|
+
*
|
|
6739
|
+
* @param params
|
|
6740
|
+
*/
|
|
6741
|
+
constructor({ gamma, offsetHdr, offsetSdr, gainMapMin, gainMapMax, maxDisplayBoost, hdrCapacityMin, hdrCapacityMax, sdr, gainMap }) {
|
|
6742
|
+
super({
|
|
6743
|
+
name: 'GainMapDecoderMaterial',
|
|
6744
|
+
vertexShader,
|
|
6745
|
+
fragmentShader,
|
|
6746
|
+
uniforms: {
|
|
6747
|
+
sdr: { value: sdr },
|
|
6748
|
+
gainMap: { value: gainMap },
|
|
6749
|
+
gamma: { value: new three.Vector3(1.0 / gamma[0], 1.0 / gamma[1], 1.0 / gamma[2]) },
|
|
6750
|
+
offsetHdr: { value: new three.Vector3().fromArray(offsetHdr) },
|
|
6751
|
+
offsetSdr: { value: new three.Vector3().fromArray(offsetSdr) },
|
|
6752
|
+
gainMapMin: { value: new three.Vector3().fromArray(gainMapMin) },
|
|
6753
|
+
gainMapMax: { value: new three.Vector3().fromArray(gainMapMax) },
|
|
6754
|
+
weightFactor: {
|
|
6755
|
+
value: (Math.log2(maxDisplayBoost) - hdrCapacityMin) / (hdrCapacityMax - hdrCapacityMin)
|
|
6756
|
+
}
|
|
6757
|
+
},
|
|
6758
|
+
blending: three.NoBlending,
|
|
6759
|
+
depthTest: false,
|
|
6760
|
+
depthWrite: false
|
|
6761
|
+
});
|
|
6762
|
+
this._maxDisplayBoost = maxDisplayBoost;
|
|
6763
|
+
this._hdrCapacityMin = hdrCapacityMin;
|
|
6764
|
+
this._hdrCapacityMax = hdrCapacityMax;
|
|
6765
|
+
this.needsUpdate = true;
|
|
6766
|
+
this.uniformsNeedUpdate = true;
|
|
6767
|
+
}
|
|
6768
|
+
get sdr() { return this.uniforms.sdr.value; }
|
|
6769
|
+
set sdr(value) { this.uniforms.sdr.value = value; }
|
|
6770
|
+
get gainMap() { return this.uniforms.gainMap.value; }
|
|
6771
|
+
set gainMap(value) { this.uniforms.gainMap.value = value; }
|
|
6772
|
+
/**
|
|
6773
|
+
* @see {@link GainMapMetadata.offsetHdr}
|
|
6774
|
+
*/
|
|
6775
|
+
get offsetHdr() { return this.uniforms.offsetHdr.value.toArray(); }
|
|
6776
|
+
set offsetHdr(value) { this.uniforms.offsetHdr.value.fromArray(value); }
|
|
6777
|
+
/**
|
|
6778
|
+
* @see {@link GainMapMetadata.offsetSdr}
|
|
6779
|
+
*/
|
|
6780
|
+
get offsetSdr() { return this.uniforms.offsetSdr.value.toArray(); }
|
|
6781
|
+
set offsetSdr(value) { this.uniforms.offsetSdr.value.fromArray(value); }
|
|
6782
|
+
/**
|
|
6783
|
+
* @see {@link GainMapMetadata.gainMapMin}
|
|
6784
|
+
*/
|
|
6785
|
+
get gainMapMin() { return this.uniforms.gainMapMin.value.toArray(); }
|
|
6786
|
+
set gainMapMin(value) { this.uniforms.gainMapMin.value.fromArray(value); }
|
|
6787
|
+
/**
|
|
6788
|
+
* @see {@link GainMapMetadata.gainMapMax}
|
|
6789
|
+
*/
|
|
6790
|
+
get gainMapMax() { return this.uniforms.gainMapMax.value.toArray(); }
|
|
6791
|
+
set gainMapMax(value) { this.uniforms.gainMapMax.value.fromArray(value); }
|
|
6792
|
+
/**
|
|
6793
|
+
* @see {@link GainmapEncodingParameters.gamma}
|
|
6794
|
+
*/
|
|
6795
|
+
get gamma() {
|
|
6796
|
+
const g = this.uniforms.gamma.value;
|
|
6797
|
+
return [1 / g.x, 1 / g.y, 1 / g.z];
|
|
6798
|
+
}
|
|
6799
|
+
set gamma(value) {
|
|
6800
|
+
const g = this.uniforms.gamma.value;
|
|
6801
|
+
g.x = 1.0 / value[0];
|
|
6802
|
+
g.y = 1.0 / value[1];
|
|
6803
|
+
g.z = 1.0 / value[2];
|
|
6804
|
+
}
|
|
6805
|
+
/**
|
|
6806
|
+
* @see {@link GainMapMetadata.hdrCapacityMin}
|
|
6807
|
+
* @remarks Logarithmic space
|
|
6808
|
+
*/
|
|
6809
|
+
get hdrCapacityMin() { return this._hdrCapacityMin; }
|
|
6810
|
+
set hdrCapacityMin(value) {
|
|
6811
|
+
this._hdrCapacityMin = value;
|
|
6812
|
+
this.calculateWeight();
|
|
6813
|
+
}
|
|
6814
|
+
/**
|
|
6815
|
+
* @see {@link GainMapMetadata.hdrCapacityMin}
|
|
6816
|
+
* @remarks Logarithmic space
|
|
6817
|
+
*/
|
|
6818
|
+
get hdrCapacityMax() { return this._hdrCapacityMax; }
|
|
6819
|
+
set hdrCapacityMax(value) {
|
|
6820
|
+
this._hdrCapacityMax = value;
|
|
6821
|
+
this.calculateWeight();
|
|
6822
|
+
}
|
|
6823
|
+
/**
|
|
6824
|
+
* @see {@link GainmapDecodingParameters.maxDisplayBoost}
|
|
6825
|
+
* @remarks Non Logarithmic space
|
|
6826
|
+
*/
|
|
6827
|
+
get maxDisplayBoost() { return this._maxDisplayBoost; }
|
|
6828
|
+
set maxDisplayBoost(value) {
|
|
6829
|
+
this._maxDisplayBoost = value;
|
|
6830
|
+
this.calculateWeight();
|
|
6831
|
+
}
|
|
6832
|
+
calculateWeight() {
|
|
6833
|
+
this.uniforms.weightFactor.value = (Math.log2(this._maxDisplayBoost) - this._hdrCapacityMin) / (this._hdrCapacityMax - this._hdrCapacityMin);
|
|
6834
|
+
}
|
|
6835
|
+
}
|
|
6836
|
+
|
|
6837
|
+
/**
|
|
6838
|
+
* Utility structure used for rendering a texture with a material
|
|
6839
|
+
*
|
|
6840
|
+
* @category General
|
|
6841
|
+
* @group General
|
|
6842
|
+
*/
|
|
6843
|
+
class QuadRenderer {
|
|
6844
|
+
/**
|
|
6845
|
+
*
|
|
6846
|
+
* @param sourceTexture
|
|
6847
|
+
* @param renderer
|
|
6848
|
+
*/
|
|
6849
|
+
constructor(width, height, type, colorSpace, material, renderer) {
|
|
6850
|
+
this._rendererIsDisposable = false;
|
|
6851
|
+
/**
|
|
6852
|
+
* Renders the input texture using the specified material
|
|
6853
|
+
*/
|
|
6854
|
+
this.render = () => {
|
|
6855
|
+
this._renderer.setRenderTarget(this._renderTarget);
|
|
6856
|
+
try {
|
|
6857
|
+
this._renderer.render(this._scene, this._camera);
|
|
6648
6858
|
}
|
|
6649
|
-
|
|
6650
|
-
|
|
6859
|
+
catch (e) {
|
|
6860
|
+
this._renderer.setRenderTarget(null);
|
|
6861
|
+
throw e;
|
|
6651
6862
|
}
|
|
6863
|
+
this._renderer.setRenderTarget(null);
|
|
6864
|
+
};
|
|
6865
|
+
this._width = width;
|
|
6866
|
+
this._height = height;
|
|
6867
|
+
this._type = type;
|
|
6868
|
+
this._colorSpace = colorSpace;
|
|
6869
|
+
if (type === three.HalfFloatType && navigator.userAgent.toLowerCase().includes('firefox')) {
|
|
6870
|
+
this._type = three.FloatType;
|
|
6871
|
+
}
|
|
6872
|
+
this._material = material;
|
|
6873
|
+
if (renderer) {
|
|
6874
|
+
this._renderer = renderer;
|
|
6652
6875
|
}
|
|
6653
6876
|
else {
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6877
|
+
this._renderer = QuadRenderer.instantiateRenderer();
|
|
6878
|
+
this._rendererIsDisposable = true;
|
|
6879
|
+
}
|
|
6880
|
+
this._scene = new three.Scene();
|
|
6881
|
+
this._camera = new three.OrthographicCamera();
|
|
6882
|
+
this._camera.position.set(0, 0, 10);
|
|
6883
|
+
this._camera.left = -0.5;
|
|
6884
|
+
this._camera.right = 0.5;
|
|
6885
|
+
this._camera.top = 0.5;
|
|
6886
|
+
this._camera.bottom = -0.5;
|
|
6887
|
+
this._camera.updateProjectionMatrix();
|
|
6888
|
+
this._quad = new three.Mesh(new three.PlaneGeometry(), this._material);
|
|
6889
|
+
this._quad.geometry.computeBoundingBox();
|
|
6890
|
+
this._scene.add(this._quad);
|
|
6891
|
+
this._renderTarget = new three.WebGLRenderTarget(width, height, {
|
|
6892
|
+
type: this._type,
|
|
6893
|
+
colorSpace,
|
|
6894
|
+
format: three.RGBAFormat,
|
|
6895
|
+
magFilter: three.LinearFilter,
|
|
6896
|
+
minFilter: three.LinearMipMapLinearFilter,
|
|
6897
|
+
wrapS: three.RepeatWrapping,
|
|
6898
|
+
wrapT: three.RepeatWrapping,
|
|
6899
|
+
depthBuffer: false,
|
|
6900
|
+
stencilBuffer: false,
|
|
6901
|
+
generateMipmaps: true
|
|
6902
|
+
});
|
|
6903
|
+
}
|
|
6904
|
+
/**
|
|
6905
|
+
* Instantiates a temporary renderer
|
|
6906
|
+
*
|
|
6907
|
+
* @returns
|
|
6908
|
+
*/
|
|
6909
|
+
static instantiateRenderer() {
|
|
6910
|
+
const renderer = new three.WebGLRenderer();
|
|
6911
|
+
renderer.setSize(128, 128);
|
|
6912
|
+
// renderer.outputColorSpace = SRGBColorSpace
|
|
6913
|
+
// renderer.toneMapping = LinearToneMapping
|
|
6914
|
+
// renderer.debug.checkShaderErrors = false
|
|
6915
|
+
// this._rendererIsDisposable = true
|
|
6916
|
+
return renderer;
|
|
6917
|
+
}
|
|
6918
|
+
/**
|
|
6919
|
+
* Obtains a Buffer containing the rendered texture.
|
|
6920
|
+
*
|
|
6921
|
+
* @returns
|
|
6922
|
+
*/
|
|
6923
|
+
toArray() {
|
|
6924
|
+
let out;
|
|
6925
|
+
switch (this._type) {
|
|
6926
|
+
case three.UnsignedByteType:
|
|
6927
|
+
out = new Uint8ClampedArray(this._width * this._height * 4);
|
|
6928
|
+
break;
|
|
6929
|
+
case three.HalfFloatType:
|
|
6930
|
+
out = new Uint16Array(this._width * this._height * 4);
|
|
6931
|
+
break;
|
|
6932
|
+
case three.UnsignedIntType:
|
|
6933
|
+
out = new Uint32Array(this._width * this._height * 4);
|
|
6934
|
+
break;
|
|
6935
|
+
case three.ByteType:
|
|
6936
|
+
out = new Int8Array(this._width * this._height * 4);
|
|
6937
|
+
break;
|
|
6938
|
+
case three.ShortType:
|
|
6939
|
+
out = new Int16Array(this._width * this._height * 4);
|
|
6940
|
+
break;
|
|
6941
|
+
case three.IntType:
|
|
6942
|
+
out = new Int32Array(this._width * this._height * 4);
|
|
6943
|
+
break;
|
|
6944
|
+
case three.FloatType:
|
|
6945
|
+
out = new Float32Array(this._width * this._height * 4);
|
|
6946
|
+
break;
|
|
6947
|
+
default:
|
|
6948
|
+
throw new Error('Unsupported data type');
|
|
6658
6949
|
}
|
|
6950
|
+
this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
|
|
6951
|
+
return out;
|
|
6659
6952
|
}
|
|
6660
|
-
|
|
6661
|
-
|
|
6953
|
+
toDataTexture() {
|
|
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);
|
|
6662
6955
|
}
|
|
6663
|
-
|
|
6664
|
-
|
|
6956
|
+
/**
|
|
6957
|
+
* If using a disposable renderer, it will dispose it.
|
|
6958
|
+
*/
|
|
6959
|
+
dispose() {
|
|
6960
|
+
this._renderer.setRenderTarget(null);
|
|
6961
|
+
if (this._rendererIsDisposable) {
|
|
6962
|
+
this._renderer.dispose();
|
|
6963
|
+
this._renderer.forceContextLoss();
|
|
6964
|
+
}
|
|
6965
|
+
}
|
|
6966
|
+
/**
|
|
6967
|
+
* Width of the texture
|
|
6968
|
+
*/
|
|
6969
|
+
get width() { return this._width; }
|
|
6970
|
+
set width(value) {
|
|
6971
|
+
this._width = value;
|
|
6972
|
+
this._renderTarget.setSize(this._width, this._height);
|
|
6973
|
+
}
|
|
6974
|
+
/**
|
|
6975
|
+
* Height of the texture
|
|
6976
|
+
*/
|
|
6977
|
+
get height() { return this._height; }
|
|
6978
|
+
set height(value) {
|
|
6979
|
+
this._height = value;
|
|
6980
|
+
this._renderTarget.setSize(this._width, this._height);
|
|
6981
|
+
}
|
|
6982
|
+
/**
|
|
6983
|
+
* The renderer used
|
|
6984
|
+
*/
|
|
6985
|
+
get renderer() { return this._renderer; }
|
|
6986
|
+
/**
|
|
6987
|
+
* The `WebGLRenderTarget` used.
|
|
6988
|
+
*/
|
|
6989
|
+
get renderTarget() { return this._renderTarget; }
|
|
6990
|
+
set renderTarget(value) {
|
|
6991
|
+
this._renderTarget = value;
|
|
6992
|
+
this._width = value.width;
|
|
6993
|
+
this._height = value.height;
|
|
6994
|
+
// this._type = value.texture.type
|
|
6995
|
+
}
|
|
6996
|
+
/**
|
|
6997
|
+
* The `Material` used.
|
|
6998
|
+
*/
|
|
6999
|
+
get material() { return this._material; }
|
|
7000
|
+
/**
|
|
7001
|
+
*
|
|
7002
|
+
*/
|
|
7003
|
+
get type() { return this._type; }
|
|
7004
|
+
get colorSpace() { return this._colorSpace; }
|
|
7005
|
+
}
|
|
7006
|
+
|
|
7007
|
+
class LoaderBase extends three.Loader {
|
|
7008
|
+
/**
|
|
7009
|
+
*
|
|
7010
|
+
* @param renderer
|
|
7011
|
+
* @param manager
|
|
7012
|
+
*/
|
|
7013
|
+
constructor(renderer, manager) {
|
|
7014
|
+
super(manager);
|
|
7015
|
+
this.renderer = renderer;
|
|
7016
|
+
}
|
|
7017
|
+
/**
|
|
7018
|
+
* @private
|
|
7019
|
+
* @returns
|
|
7020
|
+
*/
|
|
7021
|
+
prepareQuadRenderer() {
|
|
7022
|
+
// temporary values
|
|
7023
|
+
const material = new GainMapDecoderMaterial({
|
|
7024
|
+
gainMapMax: [1, 1, 1],
|
|
7025
|
+
gainMapMin: [0, 0, 0],
|
|
7026
|
+
gamma: [1, 1, 1],
|
|
7027
|
+
offsetHdr: [1, 1, 1],
|
|
7028
|
+
offsetSdr: [1, 1, 1],
|
|
7029
|
+
hdrCapacityMax: 1,
|
|
7030
|
+
hdrCapacityMin: 0,
|
|
7031
|
+
maxDisplayBoost: 1,
|
|
7032
|
+
gainMap: new three.Texture(),
|
|
7033
|
+
sdr: new three.Texture()
|
|
7034
|
+
});
|
|
7035
|
+
return new QuadRenderer(16, 16, three.HalfFloatType, three.NoColorSpace, material, this.renderer);
|
|
7036
|
+
}
|
|
7037
|
+
/**
|
|
7038
|
+
*
|
|
7039
|
+
* @private
|
|
7040
|
+
* @param quadRenderer
|
|
7041
|
+
* @param gainMapBuffer
|
|
7042
|
+
* @param sdrBuffer
|
|
7043
|
+
* @param metadata
|
|
7044
|
+
*/
|
|
7045
|
+
async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
|
|
7046
|
+
const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
|
|
7047
|
+
// TODO: figure out why result.sdr is not usable here, problem is in the libultrahdr-wasm repo
|
|
7048
|
+
// we use the original image buffer instead
|
|
7049
|
+
const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
|
|
7050
|
+
const [gainMapImageBitmap, sdrImageBitmap] = await Promise.all([
|
|
7051
|
+
createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
|
|
7052
|
+
createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
|
|
7053
|
+
]);
|
|
7054
|
+
const gainMap = new three.Texture(gainMapImageBitmap, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.NoColorSpace);
|
|
7055
|
+
gainMap.needsUpdate = true;
|
|
7056
|
+
const sdr = new three.Texture(sdrImageBitmap, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.SRGBColorSpace);
|
|
7057
|
+
sdr.needsUpdate = true;
|
|
7058
|
+
quadRenderer.width = sdrImageBitmap.width;
|
|
7059
|
+
quadRenderer.height = sdrImageBitmap.height;
|
|
7060
|
+
quadRenderer.material.gainMap = gainMap;
|
|
7061
|
+
quadRenderer.material.sdr = sdr;
|
|
7062
|
+
quadRenderer.material.gainMapMin = metadata.gainMapMin;
|
|
7063
|
+
quadRenderer.material.gainMapMax = metadata.gainMapMax;
|
|
7064
|
+
quadRenderer.material.offsetHdr = metadata.offsetHdr;
|
|
7065
|
+
quadRenderer.material.offsetSdr = metadata.offsetSdr;
|
|
7066
|
+
quadRenderer.material.gamma = metadata.gamma;
|
|
7067
|
+
quadRenderer.material.hdrCapacityMin = metadata.hdrCapacityMin;
|
|
7068
|
+
quadRenderer.material.hdrCapacityMax = metadata.hdrCapacityMax;
|
|
7069
|
+
quadRenderer.material.maxDisplayBoost = Math.pow(2, metadata.hdrCapacityMax);
|
|
7070
|
+
quadRenderer.material.needsUpdate = true;
|
|
7071
|
+
quadRenderer.render();
|
|
7072
|
+
}
|
|
7073
|
+
}
|
|
7074
|
+
|
|
6665
7075
|
/**
|
|
6666
|
-
*
|
|
7076
|
+
* A Three.js Loader for a JPEG with embedded gainmap metadata.
|
|
6667
7077
|
*
|
|
6668
|
-
* @category
|
|
6669
|
-
* @group
|
|
7078
|
+
* @category Loaders
|
|
7079
|
+
* @group Loaders
|
|
6670
7080
|
*
|
|
6671
7081
|
* @example
|
|
6672
|
-
* import {
|
|
6673
|
-
* import {
|
|
6674
|
-
*
|
|
6675
|
-
*
|
|
6676
|
-
*
|
|
7082
|
+
* import { JPEGRLoader } from '@monogrid/gainmap-js/libultrahdr'
|
|
7083
|
+
* import {
|
|
7084
|
+
* EquirectangularReflectionMapping,
|
|
7085
|
+
* LinearFilter,
|
|
7086
|
+
* Mesh,
|
|
7087
|
+
* MeshBasicMaterial,
|
|
7088
|
+
* PerspectiveCamera,
|
|
7089
|
+
* PlaneGeometry,
|
|
7090
|
+
* Scene,
|
|
7091
|
+
* WebGLRenderer
|
|
7092
|
+
* } from 'three'
|
|
6677
7093
|
*
|
|
6678
|
-
*
|
|
6679
|
-
* const { sdr, gainMap, parsedMetadata } = await decodeJPEGMetadata(new Uint8Array(gainmap))
|
|
7094
|
+
* const renderer = new WebGLRenderer()
|
|
6680
7095
|
*
|
|
6681
|
-
*
|
|
6682
|
-
* const result = await decode({
|
|
6683
|
-
* sdr,
|
|
6684
|
-
* gainMap,
|
|
6685
|
-
* // this will restore the full HDR range
|
|
6686
|
-
* maxDisplayBoost: Math.pow(2, parsedMetadata.hdrCapacityMax),
|
|
6687
|
-
* ...parsedMetadata
|
|
6688
|
-
* })
|
|
7096
|
+
* const loader = new JPEGRLoader(renderer)
|
|
6689
7097
|
*
|
|
6690
|
-
*
|
|
6691
|
-
*
|
|
7098
|
+
* const result = loader.load('gainmap.jpeg')
|
|
7099
|
+
* // `result` can be used to populate a Texture
|
|
6692
7100
|
*
|
|
7101
|
+
* const scene = new Scene()
|
|
7102
|
+
* const mesh = new Mesh(
|
|
7103
|
+
* new PlaneGeometry(),
|
|
7104
|
+
* new MeshBasicMaterial({ map: result.renderTarget.texture })
|
|
7105
|
+
* )
|
|
7106
|
+
* scene.add(mesh)
|
|
7107
|
+
* renderer.render(scene, new PerspectiveCamera())
|
|
7108
|
+
*
|
|
7109
|
+
* // `result.renderTarget.texture` must be
|
|
7110
|
+
* // converted to `DataTexture` in order
|
|
7111
|
+
* // to use it as Equirectangular scene background
|
|
7112
|
+
* // if needed
|
|
7113
|
+
*
|
|
7114
|
+
* scene.background = result.toDataTexture()
|
|
7115
|
+
* scene.background.mapping = EquirectangularReflectionMapping
|
|
7116
|
+
* scene.background.minFilter = LinearFilter
|
|
7117
|
+
|
|
6693
7118
|
*
|
|
6694
|
-
* @param file A Jpeg file Uint8Array.
|
|
6695
|
-
* @returns The decoded data
|
|
6696
|
-
* @throws {Error} if the provided file cannot be parsed or does not contain a valid Gainmap
|
|
6697
7119
|
*/
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
};
|
|
6727
|
-
return Object.assign(Object.assign({}, result), {
|
|
6728
|
-
/**
|
|
6729
|
-
* Parsed metadata
|
|
6730
|
-
*/
|
|
6731
|
-
parsedMetadata });
|
|
6732
|
-
};
|
|
7120
|
+
class JPEGRLoader extends LoaderBase {
|
|
7121
|
+
/**
|
|
7122
|
+
*
|
|
7123
|
+
* @param url
|
|
7124
|
+
* @param onLoad
|
|
7125
|
+
* @param onProgress
|
|
7126
|
+
* @param onError
|
|
7127
|
+
* @returns
|
|
7128
|
+
*/
|
|
7129
|
+
load(url, onLoad, onProgress, onError) {
|
|
7130
|
+
const quadRenderer = this.prepareQuadRenderer();
|
|
7131
|
+
const loader = new three.FileLoader(this.manager);
|
|
7132
|
+
loader.setResponseType('arraybuffer');
|
|
7133
|
+
loader.setRequestHeader(this.requestHeader);
|
|
7134
|
+
loader.setPath(this.path);
|
|
7135
|
+
loader.setWithCredentials(this.withCredentials);
|
|
7136
|
+
loader.load(url, async (jpeg) => {
|
|
7137
|
+
if (typeof jpeg === 'string')
|
|
7138
|
+
throw new Error('Invalid buffer');
|
|
7139
|
+
const { gainMap: gainMapJPEG, parsedMetadata } = await decodeJPEGMetadata(new Uint8Array(jpeg));
|
|
7140
|
+
await this.render(quadRenderer, gainMapJPEG, jpeg, parsedMetadata);
|
|
7141
|
+
if (typeof onLoad === 'function')
|
|
7142
|
+
onLoad(quadRenderer);
|
|
7143
|
+
quadRenderer.dispose();
|
|
7144
|
+
}, onProgress, onError);
|
|
7145
|
+
return quadRenderer;
|
|
7146
|
+
}
|
|
7147
|
+
}
|
|
6733
7148
|
|
|
7149
|
+
exports.JPEGRLoader = JPEGRLoader;
|
|
6734
7150
|
exports.decodeJPEGMetadata = decodeJPEGMetadata;
|
|
6735
7151
|
exports.encodeJPEGMetadata = encodeJPEGMetadata;
|
|
6736
7152
|
exports.getLibrary = getLibrary;
|