@monogrid/gainmap-js 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +103 -19
  3. package/dist/LoaderBase-aa4842c4.js +373 -0
  4. package/dist/_commonjsHelpers-1789f0cf.js +1 -1
  5. package/dist/compress-a4b59cab.js +1 -1
  6. package/dist/decode.d.ts +25 -6
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +173 -246
  9. package/dist/index.umd.js +305 -14
  10. package/dist/libultrahdr-esm.wasm +0 -0
  11. package/dist/libultrahdr.d.ts +14 -19
  12. package/dist/libultrahdr.js +245 -203
  13. package/dist/libultrahdr.umd.js +611 -206
  14. package/dist/loaders/GainMapLoader.d.ts +68 -0
  15. package/dist/loaders/JPEGRLoader.d.ts +60 -0
  16. package/dist/loaders/LoaderBase.d.ts +27 -0
  17. package/dist/materials/GainMapDecoderMaterial.d.ts +44 -1
  18. package/dist/materials/GainMapEncoderMaterial.d.ts +29 -2
  19. package/dist/types.d.ts +10 -0
  20. package/dist/utils/QuadRenderer.d.ts +2 -1
  21. package/dist/worker-interface.js +1 -1
  22. package/dist/worker-interface.umd.js +1 -1
  23. package/dist/worker.js +1 -1
  24. package/dist/worker.umd.js +1 -1
  25. package/libultrahdr-wasm/build/libultrahdr-debug.js +156 -182
  26. package/libultrahdr-wasm/build/libultrahdr-debug.wasm +0 -0
  27. package/libultrahdr-wasm/build/libultrahdr-esm.js +153 -182
  28. package/libultrahdr-wasm/build/libultrahdr-esm.wasm +0 -0
  29. package/libultrahdr-wasm/build/libultrahdr.js +151 -180
  30. package/libultrahdr-wasm/build/libultrahdr.wasm +0 -0
  31. package/package.json +1 -1
  32. package/examples/README.md +0 -3
  33. package/examples/compress.ts +0 -43
  34. package/examples/decode-from-jpeg.ts +0 -40
  35. package/examples/decode-from-separate-data.ts +0 -41
  36. package/examples/decode-to-datatexture.ts +0 -65
  37. package/examples/encode-and-compress.ts +0 -29
  38. package/examples/encode-jpeg-metadata.ts +0 -57
  39. package/examples/encode.ts +0 -28
  40. package/examples/globals.d.ts +0 -6
  41. package/examples/worker.ts +0 -41
  42. package/reports/eslint-examples.json +0 -1
  43. package/reports/eslint-src.json +0 -1
  44. package/reports/eslint-tests.json +0 -1
  45. package/reports/junit.xml +0 -35
  46. package/reports/typecheck-examples.log +0 -0
  47. package/reports/typecheck-tests.log +0 -0
  48. package/reports/typecheck.log +0 -0
@@ -1,13 +1,13 @@
1
1
  /**
2
- * @monogrid/gainmap-js v1.0.1
2
+ * @monogrid/gainmap-js v1.0.2
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","__embind_initialize_bindings","_fflush","onRuntimeInitialized"].forEach((prop) => {
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 char_0 = 48;
1446
-
1447
- var char_9 = 57;
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 ${makeLegalFunctionName(humanName)}(${argsList}) {
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
- return newFunc(Function, args1).apply(null, args2);
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
- return FS.createDataFile(parent, name, fileData, canRead, canWrite, canOwn);
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();ERRNO_CODES = {
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
- 'craftEmvalAllocator',
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,11 +6502,449 @@
6530
6502
 
6531
6503
  return moduleArg.ready
6532
6504
  }
6533
-
6534
6505
  );
6535
6506
  })();
6536
6507
  var libultrahdr = Module;
6537
6508
 
6509
+ const vertexShader = /* glsl */ `
6510
+ varying vec2 vUv;
6511
+
6512
+ void main() {
6513
+ vUv = uv;
6514
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
6515
+ }
6516
+ `;
6517
+ const fragmentShader = /* glsl */ `
6518
+ uniform sampler2D sdr;
6519
+ uniform sampler2D gainMap;
6520
+ uniform vec3 gamma;
6521
+ uniform vec3 offsetHdr;
6522
+ uniform vec3 offsetSdr;
6523
+ uniform vec3 gainMapMin;
6524
+ uniform vec3 gainMapMax;
6525
+ uniform float weightFactor;
6526
+
6527
+ varying vec2 vUv;
6528
+
6529
+ void main() {
6530
+ vec3 rgb = texture2D(sdr, vUv).rgb;
6531
+ vec3 recovery = texture2D(gainMap, vUv).rgb;
6532
+ vec3 logRecovery = pow(recovery, gamma);
6533
+ vec3 logBoost = gainMapMin * (1.0 - logRecovery) + gainMapMax * logRecovery;
6534
+ vec3 hdrColor = (rgb + offsetSdr) * exp2(logBoost * weightFactor) - offsetHdr;
6535
+ gl_FragColor = vec4(hdrColor, 1.0);
6536
+ }
6537
+ `;
6538
+ /**
6539
+ * A Material which is able to decode the Gainmap into a full HDR Representation
6540
+ *
6541
+ * @category Materials
6542
+ * @group Materials
6543
+ */
6544
+ class GainMapDecoderMaterial extends three.ShaderMaterial {
6545
+ /**
6546
+ *
6547
+ * @param params
6548
+ */
6549
+ constructor({ gamma, offsetHdr, offsetSdr, gainMapMin, gainMapMax, maxDisplayBoost, hdrCapacityMin, hdrCapacityMax, sdr, gainMap }) {
6550
+ super({
6551
+ name: 'GainMapDecoderMaterial',
6552
+ vertexShader,
6553
+ fragmentShader,
6554
+ uniforms: {
6555
+ sdr: { value: sdr },
6556
+ gainMap: { value: gainMap },
6557
+ gamma: { value: new three.Vector3(1.0 / gamma[0], 1.0 / gamma[1], 1.0 / gamma[2]) },
6558
+ offsetHdr: { value: new three.Vector3().fromArray(offsetHdr) },
6559
+ offsetSdr: { value: new three.Vector3().fromArray(offsetSdr) },
6560
+ gainMapMin: { value: new three.Vector3().fromArray(gainMapMin) },
6561
+ gainMapMax: { value: new three.Vector3().fromArray(gainMapMax) },
6562
+ weightFactor: {
6563
+ value: (Math.log2(maxDisplayBoost) - hdrCapacityMin) / (hdrCapacityMax - hdrCapacityMin)
6564
+ }
6565
+ },
6566
+ blending: three.NoBlending,
6567
+ depthTest: false,
6568
+ depthWrite: false
6569
+ });
6570
+ this._maxDisplayBoost = maxDisplayBoost;
6571
+ this._hdrCapacityMin = hdrCapacityMin;
6572
+ this._hdrCapacityMax = hdrCapacityMax;
6573
+ this.needsUpdate = true;
6574
+ this.uniformsNeedUpdate = true;
6575
+ }
6576
+ get sdr() { return this.uniforms.sdr.value; }
6577
+ set sdr(value) { this.uniforms.sdr.value = value; }
6578
+ get gainMap() { return this.uniforms.gainMap.value; }
6579
+ set gainMap(value) { this.uniforms.gainMap.value = value; }
6580
+ /**
6581
+ * @see {@link GainMapMetadata.offsetHdr}
6582
+ */
6583
+ get offsetHdr() { return this.uniforms.offsetHdr.value.toArray(); }
6584
+ set offsetHdr(value) { this.uniforms.offsetHdr.value.fromArray(value); }
6585
+ /**
6586
+ * @see {@link GainMapMetadata.offsetSdr}
6587
+ */
6588
+ get offsetSdr() { return this.uniforms.offsetSdr.value.toArray(); }
6589
+ set offsetSdr(value) { this.uniforms.offsetSdr.value.fromArray(value); }
6590
+ /**
6591
+ * @see {@link GainMapMetadata.gainMapMin}
6592
+ */
6593
+ get gainMapMin() { return this.uniforms.gainMapMin.value.toArray(); }
6594
+ set gainMapMin(value) { this.uniforms.gainMapMin.value.fromArray(value); }
6595
+ /**
6596
+ * @see {@link GainMapMetadata.gainMapMax}
6597
+ */
6598
+ get gainMapMax() { return this.uniforms.gainMapMax.value.toArray(); }
6599
+ set gainMapMax(value) { this.uniforms.gainMapMax.value.fromArray(value); }
6600
+ /**
6601
+ * @see {@link GainmapEncodingParameters.gamma}
6602
+ */
6603
+ get gamma() {
6604
+ const g = this.uniforms.gamma.value;
6605
+ return [1 / g.x, 1 / g.y, 1 / g.z];
6606
+ }
6607
+ set gamma(value) {
6608
+ const g = this.uniforms.gamma.value;
6609
+ g.x = 1.0 / value[0];
6610
+ g.y = 1.0 / value[1];
6611
+ g.z = 1.0 / value[2];
6612
+ }
6613
+ /**
6614
+ * @see {@link GainMapMetadata.hdrCapacityMin}
6615
+ * @remarks Logarithmic space
6616
+ */
6617
+ get hdrCapacityMin() { return this._hdrCapacityMin; }
6618
+ set hdrCapacityMin(value) {
6619
+ this._hdrCapacityMin = value;
6620
+ this.calculateWeight();
6621
+ }
6622
+ /**
6623
+ * @see {@link GainMapMetadata.hdrCapacityMin}
6624
+ * @remarks Logarithmic space
6625
+ */
6626
+ get hdrCapacityMax() { return this._hdrCapacityMax; }
6627
+ set hdrCapacityMax(value) {
6628
+ this._hdrCapacityMax = value;
6629
+ this.calculateWeight();
6630
+ }
6631
+ /**
6632
+ * @see {@link GainmapDecodingParameters.maxDisplayBoost}
6633
+ * @remarks Non Logarithmic space
6634
+ */
6635
+ get maxDisplayBoost() { return this._maxDisplayBoost; }
6636
+ set maxDisplayBoost(value) {
6637
+ this._maxDisplayBoost = value;
6638
+ this.calculateWeight();
6639
+ }
6640
+ calculateWeight() {
6641
+ this.uniforms.weightFactor.value = (Math.log2(this._maxDisplayBoost) - this._hdrCapacityMin) / (this._hdrCapacityMax - this._hdrCapacityMin);
6642
+ }
6643
+ }
6644
+
6645
+ /**
6646
+ * Utility structure used for rendering a texture with a material
6647
+ *
6648
+ * @category General
6649
+ * @group General
6650
+ */
6651
+ class QuadRenderer {
6652
+ /**
6653
+ *
6654
+ * @param sourceTexture
6655
+ * @param renderer
6656
+ */
6657
+ constructor(width, height, type, colorSpace, material, renderer) {
6658
+ this._rendererIsDisposable = false;
6659
+ /**
6660
+ * Renders the input texture using the specified material
6661
+ */
6662
+ this.render = () => {
6663
+ this._renderer.setRenderTarget(this._renderTarget);
6664
+ try {
6665
+ this._renderer.render(this._scene, this._camera);
6666
+ }
6667
+ catch (e) {
6668
+ this._renderer.setRenderTarget(null);
6669
+ throw e;
6670
+ }
6671
+ this._renderer.setRenderTarget(null);
6672
+ };
6673
+ this._width = width;
6674
+ this._height = height;
6675
+ this._type = type;
6676
+ this._material = material;
6677
+ if (renderer) {
6678
+ this._renderer = renderer;
6679
+ }
6680
+ else {
6681
+ this._renderer = QuadRenderer.instantiateRenderer();
6682
+ this._rendererIsDisposable = true;
6683
+ }
6684
+ this._scene = new three.Scene();
6685
+ this._camera = new three.OrthographicCamera();
6686
+ this._camera.position.set(0, 0, 10);
6687
+ this._camera.left = -0.5;
6688
+ this._camera.right = 0.5;
6689
+ this._camera.top = 0.5;
6690
+ this._camera.bottom = -0.5;
6691
+ this._camera.updateProjectionMatrix();
6692
+ this._quad = new three.Mesh(new three.PlaneGeometry(), this._material);
6693
+ this._quad.geometry.computeBoundingBox();
6694
+ this._scene.add(this._quad);
6695
+ this._renderTarget = new three.WebGLRenderTarget(width, height, {
6696
+ type,
6697
+ colorSpace,
6698
+ format: three.RGBAFormat,
6699
+ magFilter: three.LinearFilter,
6700
+ minFilter: three.LinearMipMapLinearFilter,
6701
+ wrapS: three.RepeatWrapping,
6702
+ wrapT: three.RepeatWrapping,
6703
+ depthBuffer: false,
6704
+ stencilBuffer: false,
6705
+ generateMipmaps: true
6706
+ });
6707
+ }
6708
+ /**
6709
+ * Instantiates a temporary renderer
6710
+ *
6711
+ * @returns
6712
+ */
6713
+ static instantiateRenderer() {
6714
+ const renderer = new three.WebGLRenderer();
6715
+ renderer.setSize(128, 128);
6716
+ // renderer.outputColorSpace = SRGBColorSpace
6717
+ // renderer.toneMapping = LinearToneMapping
6718
+ // renderer.debug.checkShaderErrors = false
6719
+ // this._rendererIsDisposable = true
6720
+ return renderer;
6721
+ }
6722
+ /**
6723
+ * Obtains a Buffer containing the rendered texture.
6724
+ *
6725
+ * @returns
6726
+ */
6727
+ toArray() {
6728
+ let out;
6729
+ switch (this._type) {
6730
+ case three.UnsignedByteType:
6731
+ out = new Uint8ClampedArray(this._width * this._height * 4);
6732
+ break;
6733
+ case three.HalfFloatType:
6734
+ out = new Uint16Array(this._width * this._height * 4);
6735
+ break;
6736
+ case three.UnsignedIntType:
6737
+ out = new Uint32Array(this._width * this._height * 4);
6738
+ break;
6739
+ case three.ByteType:
6740
+ out = new Int8Array(this._width * this._height * 4);
6741
+ break;
6742
+ case three.ShortType:
6743
+ out = new Int16Array(this._width * this._height * 4);
6744
+ break;
6745
+ case three.IntType:
6746
+ out = new Int32Array(this._width * this._height * 4);
6747
+ break;
6748
+ case three.FloatType:
6749
+ out = new Float32Array(this._width * this._height * 4);
6750
+ break;
6751
+ default:
6752
+ throw new Error('Unsupported data type');
6753
+ }
6754
+ this._renderer.readRenderTargetPixels(this._renderTarget, 0, 0, this._width, this._height, out);
6755
+ return out;
6756
+ }
6757
+ toDataTexture() {
6758
+ return new three.DataTexture(this.toArray(), this.width, this.height, three.RGBAFormat, three.HalfFloatType, three.UVMapping, three.RepeatWrapping, three.RepeatWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, 1, three.NoColorSpace);
6759
+ }
6760
+ /**
6761
+ * If using a disposable renderer, it will dispose it.
6762
+ */
6763
+ dispose() {
6764
+ this._renderer.setRenderTarget(null);
6765
+ if (this._rendererIsDisposable) {
6766
+ this._renderer.dispose();
6767
+ this._renderer.forceContextLoss();
6768
+ }
6769
+ }
6770
+ /**
6771
+ * Width of the texture
6772
+ */
6773
+ get width() { return this._width; }
6774
+ set width(value) {
6775
+ this._width = value;
6776
+ this._renderTarget.setSize(this._width, this._height);
6777
+ }
6778
+ /**
6779
+ * Height of the texture
6780
+ */
6781
+ get height() { return this._height; }
6782
+ set height(value) {
6783
+ this._height = value;
6784
+ this._renderTarget.setSize(this._width, this._height);
6785
+ }
6786
+ /**
6787
+ * The renderer used
6788
+ */
6789
+ get renderer() { return this._renderer; }
6790
+ /**
6791
+ * The `WebGLRenderTarget` used.
6792
+ */
6793
+ get renderTarget() { return this._renderTarget; }
6794
+ set renderTarget(value) {
6795
+ this._renderTarget = value;
6796
+ this._width = value.width;
6797
+ this._height = value.height;
6798
+ // this._type = value.texture.type
6799
+ }
6800
+ /**
6801
+ * The `Material` used.
6802
+ */
6803
+ get material() { return this._material; }
6804
+ }
6805
+
6806
+ class LoaderBase extends three.Loader {
6807
+ /**
6808
+ *
6809
+ * @param renderer
6810
+ * @param manager
6811
+ */
6812
+ constructor(renderer, manager) {
6813
+ super(manager);
6814
+ this.renderer = renderer;
6815
+ }
6816
+ /**
6817
+ * @private
6818
+ * @returns
6819
+ */
6820
+ prepareQuadRenderer() {
6821
+ // temporary values
6822
+ const material = new GainMapDecoderMaterial({
6823
+ gainMapMax: [1, 1, 1],
6824
+ gainMapMin: [0, 0, 0],
6825
+ gamma: [1, 1, 1],
6826
+ offsetHdr: [1, 1, 1],
6827
+ offsetSdr: [1, 1, 1],
6828
+ hdrCapacityMax: 1,
6829
+ hdrCapacityMin: 0,
6830
+ maxDisplayBoost: 1,
6831
+ gainMap: new three.Texture(),
6832
+ sdr: new three.Texture()
6833
+ });
6834
+ return new QuadRenderer(16, 16, three.HalfFloatType, three.NoColorSpace, material, this.renderer);
6835
+ }
6836
+ /**
6837
+ *
6838
+ * @private
6839
+ * @param quadRenderer
6840
+ * @param gainMapBuffer
6841
+ * @param sdrBuffer
6842
+ * @param metadata
6843
+ */
6844
+ async render(quadRenderer, gainMapBuffer, sdrBuffer, metadata) {
6845
+ const gainMapBlob = new Blob([gainMapBuffer], { type: 'image/jpeg' });
6846
+ // TODO: figure out why result.sdr is not usable here, problem is in the libultrahdr-wasm repo
6847
+ // we use the original image buffer instead
6848
+ const sdrBlob = new Blob([sdrBuffer], { type: 'image/jpeg' });
6849
+ const [gainMapImageBitmap, sdrImageBitmap] = await Promise.all([
6850
+ createImageBitmap(gainMapBlob, { imageOrientation: 'flipY' }),
6851
+ createImageBitmap(sdrBlob, { imageOrientation: 'flipY' })
6852
+ ]);
6853
+ const gainMap = new three.Texture(gainMapImageBitmap, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.NoColorSpace);
6854
+ gainMap.needsUpdate = true;
6855
+ const sdr = new three.Texture(sdrImageBitmap, three.UVMapping, three.ClampToEdgeWrapping, three.ClampToEdgeWrapping, three.LinearFilter, three.LinearMipMapLinearFilter, three.RGBAFormat, three.UnsignedByteType, 1, three.SRGBColorSpace);
6856
+ sdr.needsUpdate = true;
6857
+ quadRenderer.width = sdrImageBitmap.width;
6858
+ quadRenderer.height = sdrImageBitmap.height;
6859
+ quadRenderer.material.gainMap = gainMap;
6860
+ quadRenderer.material.sdr = sdr;
6861
+ quadRenderer.material.gainMapMin = metadata.gainMapMin;
6862
+ quadRenderer.material.gainMapMax = metadata.gainMapMax;
6863
+ quadRenderer.material.offsetHdr = metadata.offsetHdr;
6864
+ quadRenderer.material.offsetSdr = metadata.offsetSdr;
6865
+ quadRenderer.material.gamma = metadata.gamma;
6866
+ quadRenderer.material.hdrCapacityMin = metadata.hdrCapacityMin;
6867
+ quadRenderer.material.hdrCapacityMax = metadata.hdrCapacityMax;
6868
+ quadRenderer.material.maxDisplayBoost = Math.pow(2, metadata.hdrCapacityMax);
6869
+ quadRenderer.material.needsUpdate = true;
6870
+ quadRenderer.render();
6871
+ }
6872
+ }
6873
+
6874
+ /**
6875
+ * A Three.js Loader for a JPEG with embedded gainmap metadata.
6876
+ *
6877
+ * @category Loaders
6878
+ * @group Loaders
6879
+ *
6880
+ * @example
6881
+ * import { JPEGRLoader } from '@monogrid/gainmap-js/libultrahdr'
6882
+ * import {
6883
+ * EquirectangularReflectionMapping,
6884
+ * LinearFilter,
6885
+ * Mesh,
6886
+ * MeshBasicMaterial,
6887
+ * PerspectiveCamera,
6888
+ * PlaneGeometry,
6889
+ * Scene,
6890
+ * WebGLRenderer
6891
+ * } from 'three'
6892
+ *
6893
+ * const renderer = new WebGLRenderer()
6894
+ *
6895
+ * const loader = new JPEGRLoader(renderer)
6896
+ *
6897
+ * const result = loader.load('gainmap.jpeg')
6898
+ * // `result` can be used to populate a Texture
6899
+ *
6900
+ * const scene = new Scene()
6901
+ * const mesh = new Mesh(
6902
+ * new PlaneGeometry(),
6903
+ * new MeshBasicMaterial({ map: result.renderTarget.texture })
6904
+ * )
6905
+ * scene.add(mesh)
6906
+ * renderer.render(scene, new PerspectiveCamera())
6907
+ *
6908
+ * // `result.renderTarget.texture` must be
6909
+ * // converted to `DataTexture` in order
6910
+ * // to use it as Equirectanmgular scene background
6911
+ * // if needed
6912
+ *
6913
+ * scene.background = result.toDataTexture()
6914
+ * scene.background.mapping = EquirectangularReflectionMapping
6915
+ * scene.background.minFilter = LinearFilter
6916
+
6917
+ *
6918
+ */
6919
+ class JPEGRLoader extends LoaderBase {
6920
+ /**
6921
+ *
6922
+ * @param url
6923
+ * @param onLoad
6924
+ * @param onProgress
6925
+ * @param onError
6926
+ * @returns
6927
+ */
6928
+ load(url, onLoad, onProgress, onError) {
6929
+ const quadRenderer = this.prepareQuadRenderer();
6930
+ const loader = new three.FileLoader(this.manager);
6931
+ loader.setResponseType('arraybuffer');
6932
+ loader.setRequestHeader(this.requestHeader);
6933
+ loader.setPath(this.path);
6934
+ loader.setWithCredentials(this.withCredentials);
6935
+ loader.load(url, async (jpeg) => {
6936
+ if (typeof jpeg === 'string')
6937
+ throw new Error('Invalid buffer');
6938
+ const { gainMap: gainMapJPEG, parsedMetadata } = await decodeJPEGMetadata(new Uint8Array(jpeg));
6939
+ await this.render(quadRenderer, gainMapJPEG, jpeg, parsedMetadata);
6940
+ if (typeof onLoad === 'function')
6941
+ onLoad(quadRenderer);
6942
+ quadRenderer.dispose();
6943
+ }, onProgress, onError);
6944
+ return quadRenderer;
6945
+ }
6946
+ }
6947
+
6538
6948
  // @ts-expect-error untyped
6539
6949
  let library;
6540
6950
  /**
@@ -6576,9 +6986,17 @@
6576
6986
  * })
6577
6987
  *
6578
6988
  * // obtain the RAW RGBA SDR buffer and create an ImageData
6579
- * const sdrImageData = new ImageData(encodingResult.sdr.toArray(), encodingResult.sdr.width, encodingResult.sdr.height)
6989
+ * const sdrImageData = new ImageData(
6990
+ * encodingResult.sdr.toArray(),
6991
+ * encodingResult.sdr.width,
6992
+ * encodingResult.sdr.height
6993
+ * )
6580
6994
  * // obtain the RAW RGBA Gain map buffer and create an ImageData
6581
- * const gainMapImageData = new ImageData(encodingResult.gainMap.toArray(), encodingResult.gainMap.width, encodingResult.gainMap.height)
6995
+ * const gainMapImageData = new ImageData(
6996
+ * encodingResult.gainMap.toArray(),
6997
+ * encodingResult.gainMap.width,
6998
+ * encodingResult.gainMap.height
6999
+ * )
6582
7000
  *
6583
7001
  * // parallel compress the RAW buffers into the specified mimeType
6584
7002
  * const mimeType = 'image/jpeg'
@@ -6669,27 +7087,13 @@
6669
7087
  * @group Decoding
6670
7088
  *
6671
7089
  * @example
6672
- * import { decode } from '@monogrid/gainmap-js'
6673
7090
  * import { decodeJPEGMetadata } from '@monogrid/gainmap-js/libultrahdr'
6674
- * import { Mesh, MeshBasicMaterial, PlaneGeometry } from 'three'
7091
+ *
6675
7092
  * // fetch a JPEG image containing a gainmap as ArrayBuffer
6676
- * const gainmap = await (await fetch('gainmap.jpeg')).arrayBuffer()
7093
+ * const gainmap = new Uint8Array(await (await fetch('gainmap.jpeg')).arrayBuffer())
6677
7094
  *
6678
7095
  * // extract data from the JPEG
6679
- * const { sdr, gainMap, parsedMetadata } = await decodeJPEGMetadata(new Uint8Array(gainmap))
6680
- *
6681
- * // restore the HDR texture
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
- * })
6689
- *
6690
- * // result can be used to populate a Texture
6691
- * const mesh = new Mesh(new PlaneGeometry(), new MeshBasicMaterial({ map: result.renderTarget.texture }))
6692
- *
7096
+ * const { gainMap, sdr, parsedMetadata } = await decodeJPEGMetadata(gainmap)
6693
7097
  *
6694
7098
  * @param file A Jpeg file Uint8Array.
6695
7099
  * @returns The decoded data
@@ -6731,6 +7135,7 @@
6731
7135
  parsedMetadata });
6732
7136
  };
6733
7137
 
7138
+ exports.JPEGRLoader = JPEGRLoader;
6734
7139
  exports.decodeJPEGMetadata = decodeJPEGMetadata;
6735
7140
  exports.encodeJPEGMetadata = encodeJPEGMetadata;
6736
7141
  exports.getLibrary = getLibrary;