@bb-studio/exr 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/README.md +151 -4
- package/THIRD_PARTY_LICENSES.md +2 -2
- package/dist/browser/chunk-RJALO6PD.js +9 -0
- package/dist/browser/chunk-RJALO6PD.js.map +1 -0
- package/dist/browser/dwaDecodeWorker.js +21 -16
- package/dist/browser/dwaDecodeWorker.js.map +1 -1
- package/dist/browser/index.d.ts +65 -8
- package/dist/browser/index.js +854 -488
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/zipDecodeWorker.js +13 -11
- package/dist/browser/zipDecodeWorker.js.map +1 -1
- package/dist/index.cjs +699 -219
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -4
- package/dist/index.d.ts +66 -4
- package/dist/index.js +695 -219
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,20 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
workerDecodeClock
|
|
3
|
+
} from "./chunk-RJALO6PD.js";
|
|
4
|
+
|
|
1
5
|
// src/browser/zipDecodeWorker.ts
|
|
2
6
|
import { unzlibSync } from "fflate";
|
|
3
7
|
var scope = self;
|
|
4
8
|
var inflateScratch = new Uint8Array(0);
|
|
5
|
-
var outputScratch = new Uint8Array(0);
|
|
6
9
|
function ensureInflateScratch(size) {
|
|
7
10
|
if (inflateScratch.byteLength < size) {
|
|
8
11
|
inflateScratch = new Uint8Array(size);
|
|
9
12
|
}
|
|
10
13
|
return inflateScratch.subarray(0, size);
|
|
11
14
|
}
|
|
12
|
-
function ensureOutputScratch(size) {
|
|
13
|
-
if (outputScratch.byteLength < size) {
|
|
14
|
-
outputScratch = new Uint8Array(size);
|
|
15
|
-
}
|
|
16
|
-
return outputScratch.subarray(0, size);
|
|
17
|
-
}
|
|
18
15
|
function undoZipPredictorAndInterleave(data, output) {
|
|
19
16
|
const length = data.length;
|
|
20
17
|
if (length === 0) return data;
|
|
@@ -33,16 +30,21 @@ function undoZipPredictorAndInterleave(data, output) {
|
|
|
33
30
|
}
|
|
34
31
|
scope.onmessage = (event) => {
|
|
35
32
|
const message = event.data;
|
|
33
|
+
if ("type" in message) {
|
|
34
|
+
inflateScratch = new Uint8Array(0);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const startedAt = workerDecodeClock();
|
|
36
38
|
try {
|
|
37
39
|
const compressed = new Uint8Array(message.compressed);
|
|
38
40
|
const raw = message.expectedUncompressedSize > 0 ? unzlibSync(compressed, { out: ensureInflateScratch(message.expectedUncompressedSize) }) : unzlibSync(compressed);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
decoded.set(decodedView);
|
|
41
|
+
const decoded = new Uint8Array(raw.byteLength);
|
|
42
|
+
undoZipPredictorAndInterleave(raw, decoded);
|
|
42
43
|
const response = {
|
|
43
44
|
id: message.id,
|
|
44
45
|
ok: true,
|
|
45
|
-
decoded: decoded.buffer
|
|
46
|
+
decoded: decoded.buffer,
|
|
47
|
+
timing: { startedAt, finishedAt: workerDecodeClock() }
|
|
46
48
|
};
|
|
47
49
|
scope.postMessage(response, [decoded.buffer]);
|
|
48
50
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/browser/zipDecodeWorker.ts"],"sourcesContent":["import { unzlibSync } from 'fflate';\n\ninterface ZipDecodeRequest {\n id: number;\n compressed: ArrayBuffer;\n expectedUncompressedSize: number;\n}\n\ninterface ZipDecodeSuccess {\n id: number;\n ok: true;\n decoded: ArrayBuffer;\n}\n\ninterface ZipDecodeFailure {\n id: number;\n ok: false;\n error: string;\n}\n\ntype ZipDecodeResponse = ZipDecodeSuccess | ZipDecodeFailure;\n\nconst scope = self as DedicatedWorkerGlobalScope;\n\nlet inflateScratch = new Uint8Array(0);\
|
|
1
|
+
{"version":3,"sources":["../../src/browser/zipDecodeWorker.ts"],"sourcesContent":["import { workerDecodeClock, type WorkerDecodeTiming } from './workerDecodeTiming';\nimport { unzlibSync } from 'fflate';\n\ninterface ZipDecodeRequest {\n id: number;\n compressed: ArrayBuffer;\n expectedUncompressedSize: number;\n}\n\ninterface ZipDecodeSuccess {\n id: number;\n ok: true;\n decoded: ArrayBuffer;\n timing: WorkerDecodeTiming;\n}\n\ninterface ZipDecodeFailure {\n id: number;\n ok: false;\n error: string;\n}\n\ntype ZipDecodeResponse = ZipDecodeSuccess | ZipDecodeFailure;\n\nconst scope = self as DedicatedWorkerGlobalScope;\n\nlet inflateScratch = new Uint8Array(0);\n\nfunction ensureInflateScratch(size: number): Uint8Array {\n if (inflateScratch.byteLength < size) {\n inflateScratch = new Uint8Array(size);\n }\n return inflateScratch.subarray(0, size);\n}\n\nfunction undoZipPredictorAndInterleave(data: Uint8Array, output: Uint8Array): Uint8Array {\n const length = data.length;\n if (length === 0) return data;\n\n const half = (length + 1) >> 1;\n let predicted = data[0];\n output[0] = predicted;\n\n for (let i = 1; i < half; i++) {\n predicted = (predicted + data[i] - 128) & 0xff;\n output[i << 1] = predicted;\n }\n\n for (let i = half; i < length; i++) {\n predicted = (predicted + data[i] - 128) & 0xff;\n output[((i - half) << 1) + 1] = predicted;\n }\n\n return output;\n}\n\nscope.onmessage = (event: MessageEvent<ZipDecodeRequest | { type: 'reset' }>) => {\n const message = event.data;\n if ('type' in message) {\n inflateScratch = new Uint8Array(0);\n return;\n }\n\n const startedAt = workerDecodeClock();\n try {\n const compressed = new Uint8Array(message.compressed);\n const raw =\n message.expectedUncompressedSize > 0\n ? unzlibSync(compressed, { out: ensureInflateScratch(message.expectedUncompressedSize) })\n : unzlibSync(compressed);\n\n // Write directly into the transferable output; keep only inflate scratch.\n const decoded = new Uint8Array(raw.byteLength);\n undoZipPredictorAndInterleave(raw, decoded);\n\n const response: ZipDecodeSuccess = {\n id: message.id,\n ok: true,\n decoded: decoded.buffer,\n timing: { startedAt, finishedAt: workerDecodeClock() },\n };\n scope.postMessage(response, [decoded.buffer]);\n } catch (error) {\n const response: ZipDecodeFailure = {\n id: message.id,\n ok: false,\n error: error instanceof Error ? error.message : String(error),\n };\n scope.postMessage(response as ZipDecodeResponse);\n }\n};\n\nexport {};\n"],"mappings":";;;;;AACA,SAAS,kBAAkB;AAuB3B,IAAM,QAAQ;AAEd,IAAI,iBAAiB,IAAI,WAAW,CAAC;AAErC,SAAS,qBAAqB,MAA0B;AACtD,MAAI,eAAe,aAAa,MAAM;AACpC,qBAAiB,IAAI,WAAW,IAAI;AAAA,EACtC;AACA,SAAO,eAAe,SAAS,GAAG,IAAI;AACxC;AAEA,SAAS,8BAA8B,MAAkB,QAAgC;AACvF,QAAM,SAAS,KAAK;AACpB,MAAI,WAAW,EAAG,QAAO;AAEzB,QAAM,OAAQ,SAAS,KAAM;AAC7B,MAAI,YAAY,KAAK,CAAC;AACtB,SAAO,CAAC,IAAI;AAEZ,WAAS,IAAI,GAAG,IAAI,MAAM,KAAK;AAC7B,gBAAa,YAAY,KAAK,CAAC,IAAI,MAAO;AAC1C,WAAO,KAAK,CAAC,IAAI;AAAA,EACnB;AAEA,WAAS,IAAI,MAAM,IAAI,QAAQ,KAAK;AAClC,gBAAa,YAAY,KAAK,CAAC,IAAI,MAAO;AAC1C,YAAS,IAAI,QAAS,KAAK,CAAC,IAAI;AAAA,EAClC;AAEA,SAAO;AACT;AAEA,MAAM,YAAY,CAAC,UAA8D;AAC/E,QAAM,UAAU,MAAM;AACtB,MAAI,UAAU,SAAS;AACrB,qBAAiB,IAAI,WAAW,CAAC;AACjC;AAAA,EACF;AAEA,QAAM,YAAY,kBAAkB;AACpC,MAAI;AACF,UAAM,aAAa,IAAI,WAAW,QAAQ,UAAU;AACpD,UAAM,MACJ,QAAQ,2BAA2B,IAC/B,WAAW,YAAY,EAAE,KAAK,qBAAqB,QAAQ,wBAAwB,EAAE,CAAC,IACtF,WAAW,UAAU;AAG3B,UAAM,UAAU,IAAI,WAAW,IAAI,UAAU;AAC7C,kCAA8B,KAAK,OAAO;AAE1C,UAAM,WAA6B;AAAA,MACjC,IAAI,QAAQ;AAAA,MACZ,IAAI;AAAA,MACJ,SAAS,QAAQ;AAAA,MACjB,QAAQ,EAAE,WAAW,YAAY,kBAAkB,EAAE;AAAA,IACvD;AACA,UAAM,YAAY,UAAU,CAAC,QAAQ,MAAM,CAAC;AAAA,EAC9C,SAAS,OAAO;AACd,UAAM,WAA6B;AAAA,MACjC,IAAI,QAAQ;AAAA,MACZ,IAAI;AAAA,MACJ,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,IAC9D;AACA,UAAM,YAAY,QAA6B;AAAA,EACjD;AACF;","names":[]}
|