@webex/ladon-ts 5.2.0 → 5.4.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 +37 -1
- package/build/module/config.json.js +1 -1
- package/build/module/index.js +17 -16
- package/build/module/lib/config-types.d.ts +9 -9
- package/build/module/lib/generator.d.ts +1 -1
- package/build/module/lib/generator.js +52 -40
- package/build/module/lib/generator.js.map +1 -1
- package/build/module/lib/renderer/webgl-renderer.d.ts +1 -1
- package/build/module/lib/shared-resource-manager.js +37 -21
- package/build/module/lib/shared-resource-manager.js.map +1 -1
- package/build/module/lib/util.d.ts +1 -0
- package/build/module/lib/util.js +83 -64
- package/build/module/lib/util.js.map +1 -1
- package/build/module/lib/version.d.ts +1 -1
- package/build/module/lib/version.js +1 -1
- package/build/module/lib/version.js.map +1 -1
- package/build/worker/segmentation.js +1475 -13968
- package/package.json +2 -2
package/build/module/lib/util.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
var
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
let
|
|
5
|
-
for (let
|
|
6
|
-
const
|
|
7
|
-
for (let
|
|
8
|
-
const
|
|
9
|
-
|
|
1
|
+
var C = /* @__PURE__ */ ((o) => (o.Nearest = "nearest", o))(C || {});
|
|
2
|
+
const E = (o, r, s, n, t) => {
|
|
3
|
+
const a = new Uint8ClampedArray(n * t * 4), m = r / n, M = s / t, i = r * 4;
|
|
4
|
+
let c = 0;
|
|
5
|
+
for (let e = 0; e < t; e++) {
|
|
6
|
+
const l = Math.floor(e * M) * i;
|
|
7
|
+
for (let f = 0; f < n; f++) {
|
|
8
|
+
const u = l + Math.floor(f * m) * 4;
|
|
9
|
+
a[c++] = o[u], a[c++] = o[u + 1], a[c++] = o[u + 2], a[c++] = o[u + 3];
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
return
|
|
12
|
+
return a;
|
|
13
13
|
};
|
|
14
|
-
function
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
for (let
|
|
18
|
-
|
|
19
|
-
return
|
|
14
|
+
function I(o, r, s, n, t) {
|
|
15
|
+
const a = new Uint8ClampedArray(n * t);
|
|
16
|
+
if (r === n && s === t) {
|
|
17
|
+
for (let i = 0; i < o.length; i++)
|
|
18
|
+
a[i] = Math.min(Math.max(o[i], 0), 255);
|
|
19
|
+
return a;
|
|
20
20
|
}
|
|
21
|
-
const
|
|
22
|
-
for (let
|
|
23
|
-
for (let
|
|
24
|
-
const
|
|
25
|
-
|
|
21
|
+
const m = (r - 1) / (n - 1), M = (s - 1) / (t - 1);
|
|
22
|
+
for (let i = 0; i < t; i++)
|
|
23
|
+
for (let c = 0; c < n; c++) {
|
|
24
|
+
const e = m * c, l = M * i, f = Math.floor(e), u = Math.floor(l), d = Math.min(Math.ceil(e), r - 1), S = Math.min(Math.ceil(l), s - 1), y = e - f, h = l - u, p = o[u * r + f], w = o[u * r + d], P = o[S * r + f], x = o[S * r + d], k = p * (1 - y) * (1 - h) + w * y * (1 - h) + P * (1 - y) * h + x * y * h;
|
|
25
|
+
a[i * n + c] = Math.min(Math.max(k, 0), 255);
|
|
26
26
|
}
|
|
27
|
-
return
|
|
27
|
+
return a;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
if (
|
|
33
|
-
const
|
|
34
|
-
return
|
|
29
|
+
function R(o, r, s, n, t) {
|
|
30
|
+
const a = new Uint8ClampedArray(n * t), m = r / n, M = s / t, i = (e, l) => {
|
|
31
|
+
if (e === 0) return 1;
|
|
32
|
+
if (e < 0 && (e = -e), e < l) {
|
|
33
|
+
const f = Math.PI * e;
|
|
34
|
+
return l * Math.sin(f) * Math.sin(f / l) / (f * f);
|
|
35
35
|
}
|
|
36
36
|
return 0;
|
|
37
|
-
},
|
|
38
|
-
for (let
|
|
39
|
-
for (let
|
|
40
|
-
const
|
|
41
|
-
let
|
|
42
|
-
for (let
|
|
43
|
-
for (let
|
|
44
|
-
if (
|
|
45
|
-
const
|
|
46
|
-
|
|
37
|
+
}, c = 3;
|
|
38
|
+
for (let e = 0; e < t; e++)
|
|
39
|
+
for (let l = 0; l < n; l++) {
|
|
40
|
+
const f = l * m, u = e * M, d = Math.floor(f), S = Math.floor(u);
|
|
41
|
+
let y = 0, h = 0;
|
|
42
|
+
for (let p = S - c + 1; p <= S + c; p++)
|
|
43
|
+
for (let w = d - c + 1; w <= d + c; w++)
|
|
44
|
+
if (w >= 0 && w < r && p >= 0 && p < s) {
|
|
45
|
+
const P = o[p * r + w], x = i(f - w, c) * i(u - p, c);
|
|
46
|
+
y += P * x, h += x;
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
a[e * n + l] = h !== 0 ? Math.round(y / h) : 0;
|
|
49
49
|
}
|
|
50
|
-
return
|
|
50
|
+
return a;
|
|
51
51
|
}
|
|
52
|
-
const
|
|
53
|
-
function
|
|
54
|
-
const
|
|
55
|
-
if (!
|
|
52
|
+
const A = (o, r) => !r || o.startsWith("http") ? new URL(o).href : o ? r.replace(/\/+$/, "") + "/" + o.replace(/^\/+/, "") : r;
|
|
53
|
+
function L(o, r, s) {
|
|
54
|
+
const n = o.createShader(r);
|
|
55
|
+
if (!n)
|
|
56
56
|
throw new Error("[ladon-ts] - error creating shader");
|
|
57
|
-
if (o.shaderSource(
|
|
58
|
-
const
|
|
59
|
-
throw new Error("[ladon-ts] - " +
|
|
57
|
+
if (o.shaderSource(n, s), o.compileShader(n), !o.getShaderParameter(n, o.COMPILE_STATUS)) {
|
|
58
|
+
const t = o.getShaderInfoLog(n) ?? "unknown error compiling shader.";
|
|
59
|
+
throw new Error("[ladon-ts] - " + t);
|
|
60
60
|
}
|
|
61
|
-
return
|
|
61
|
+
return n;
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
63
|
+
function T(o, r, s) {
|
|
64
|
+
const n = o.createProgram();
|
|
65
|
+
if (!n)
|
|
66
66
|
throw new Error("[ladon-ts] - error creating GPU program");
|
|
67
|
-
if (o.attachShader(
|
|
68
|
-
const
|
|
69
|
-
throw new Error("[ladon-ts] - " +
|
|
67
|
+
if (o.attachShader(n, r), o.attachShader(n, s), o.linkProgram(n), !o.getProgramParameter(n, o.LINK_STATUS)) {
|
|
68
|
+
const t = o.getProgramInfoLog(n) ?? "unknown error linking program.";
|
|
69
|
+
throw new Error("[ladon-ts] - " + t);
|
|
70
70
|
}
|
|
71
|
-
return
|
|
71
|
+
return n;
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function b(o) {
|
|
74
74
|
if (o.startsWith("blob:"))
|
|
75
75
|
return !0;
|
|
76
76
|
try {
|
|
@@ -79,14 +79,33 @@ function T(o) {
|
|
|
79
79
|
return !1;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
+
async function U(o) {
|
|
83
|
+
const r = await caches.open("ladon-cache"), s = await r.match(o);
|
|
84
|
+
if (s)
|
|
85
|
+
return s.arrayBuffer();
|
|
86
|
+
const n = await fetch(o);
|
|
87
|
+
if (!n.ok)
|
|
88
|
+
throw new Error(`Failed to fetch file: ${o}`);
|
|
89
|
+
const t = n.headers.get("Content-Type") || "application/octet-stream";
|
|
90
|
+
if (!t.includes("application/wasm") && !t.includes("binary/octet-stream"))
|
|
91
|
+
throw new Error(`Unexpected MIME type: ${t} for ${o}`);
|
|
92
|
+
const a = await n.arrayBuffer(), m = new Response(a, {
|
|
93
|
+
headers: {
|
|
94
|
+
"Content-Type": t,
|
|
95
|
+
"Content-Length": a.byteLength.toString()
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return await r.put(o, m), a;
|
|
99
|
+
}
|
|
82
100
|
export {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
C as InterpolationMethod,
|
|
102
|
+
I as bilinearUpsample,
|
|
103
|
+
L as compileShader,
|
|
104
|
+
b as isResolvedUri,
|
|
105
|
+
R as lanczos3Upsample,
|
|
106
|
+
T as linkProgram,
|
|
107
|
+
U as loadAndCacheFile,
|
|
108
|
+
E as resizeImage,
|
|
109
|
+
A as toAbsoluteURI
|
|
91
110
|
};
|
|
92
111
|
//# sourceMappingURL=util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sources":["../../../src/lib/util.ts"],"sourcesContent":["export enum InterpolationMethod {\n Nearest = 'nearest',\n}\n\n/**\n * Resizes an image from the source dimensions to target dimensions.\n *\n * @param {Uint8ClampedArray} imageData The source image data in Uint8ClampedArray format.\n * @param {number} srcWidth The width of the source image.\n * @param {number} srcHeight The height of the source image.\n * @param {number} targetWidth The width of the target image.\n * @param {number} targetHeight The height of the target image.\n *\n * @returns {Uint8ClampedArray} The target image data in Uint8ClampedArray format.\n *\n * @example\n * const targetData = resizeImage(sourceData, 800, 600, 400, 300);\n *\n * @note The function uses a \"nearest neighbor\" algorithm for resizing,\n * which is fast but might not provide the best quality for all images.\n */\nexport const resizeImage = (\n imageData: Uint8ClampedArray,\n srcWidth: number,\n srcHeight: number,\n targetWidth: number,\n targetHeight: number\n): Uint8ClampedArray => {\n const targetData = new Uint8ClampedArray(targetWidth * targetHeight * 4);\n const xRatio = srcWidth / targetWidth;\n const yRatio = srcHeight / targetHeight;\n const scaledSrcWidth = srcWidth * 4;\n let offset = 0;\n\n for (let y = 0; y < targetHeight; y++) {\n const srcY = Math.floor(y * yRatio) * scaledSrcWidth;\n for (let x = 0; x < targetWidth; x++) {\n const srcOffset = srcY + Math.floor(x * xRatio) * 4;\n\n targetData[offset++] = imageData[srcOffset];\n targetData[offset++] = imageData[srcOffset + 1];\n targetData[offset++] = imageData[srcOffset + 2];\n targetData[offset++] = imageData[srcOffset + 3];\n }\n }\n\n return targetData;\n};\n\n/**\n * Upsamples an image using the bilinear interpolation method. The input image is expected to be in\n * Float32Array format. The output image is in Uint8ClampedArray format. The input image is expected\n * to be in the [0, 1] range. The output image is in the [0, 255] range.\n *\n * @param {Float32Array} input The input image data in Float32Array format.\n * @param {number} srcWidth The width of the source image.\n * @param {number} srcHeight The height of the source image.\n * @param {number} targetWidth The width of the target image.\n * @param {number} targetHeight The height of the target image.\n *\n * @returns {Uint8ClampedArray} The upsampled image data in Uint8ClampedArray format.\n *\n */\nexport function bilinearUpsample(\n input: Float32Array,\n srcWidth: number,\n srcHeight: number,\n targetWidth: number,\n targetHeight: number\n) {\n const output = new Uint8ClampedArray(targetWidth * targetHeight);\n\n // If the source and target dimensions are the same, just copy the input to the output.\n // The output is expected to be in the [0, 255] range\n if (srcWidth === targetWidth && srcHeight === targetHeight) {\n for (let i = 0; i < input.length; i++) {\n output[i] = Math.min(Math.max(input[i], 0), 255);\n }\n return output;\n }\n\n const xRatio = (srcWidth - 1) / (targetWidth - 1);\n const yRatio = (srcHeight - 1) / (targetHeight - 1);\n\n for (let i = 0; i < targetHeight; i++) {\n for (let j = 0; j < targetWidth; j++) {\n const x = xRatio * j;\n const y = yRatio * i;\n\n const xL = Math.floor(x);\n const yL = Math.floor(y);\n const xH = Math.min(Math.ceil(x), srcWidth - 1);\n const yH = Math.min(Math.ceil(y), srcHeight - 1);\n\n const xWeight = x - xL;\n const yWeight = y - yL;\n\n const a = input[yL * srcWidth + xL];\n const b = input[yL * srcWidth + xH];\n const c = input[yH * srcWidth + xL];\n const d = input[yH * srcWidth + xH];\n\n const value =\n a * (1 - xWeight) * (1 - yWeight) +\n b * xWeight * (1 - yWeight) +\n c * (1 - xWeight) * yWeight +\n d * xWeight * yWeight;\n\n output[i * targetWidth + j] = Math.min(Math.max(value, 0), 255);\n }\n }\n\n return output;\n}\n\n/**\n * Upsamples an image using the Lanczos3 interpolation method. The input image is expected to be in\n * Float32Array format. The output image is in Uint8ClampedArray format. The input image is expected\n * to be in the [0, 1] range. The output image is in the [0, 255] range.\n *\n * @param {Float32Array} input The input image data in Float32Array format.\n * @param {number} srcWidth The width of the source image.\n * @param {number} srcHeight The height of the source image.\n * @param {number} targetWidth The width of the target image.\n * @param {number} targetHeight The height of the target image.\n *\n * @returns {Uint8ClampedArray} The upsampled image data in Uint8ClampedArray format.\n */\nexport function lanczos3Upsample(\n input: Float32Array,\n srcWidth: number,\n srcHeight: number,\n targetWidth: number,\n targetHeight: number\n) {\n const output = new Uint8ClampedArray(targetWidth * targetHeight);\n\n const xRatio = srcWidth / targetWidth;\n const yRatio = srcHeight / targetHeight;\n\n const lanczos = (x: number, a: number) => {\n if (x === 0) return 1;\n if (x < 0) x = -x;\n if (x < a) {\n const piX = Math.PI * x;\n return (a * Math.sin(piX) * Math.sin(piX / a)) / (piX * piX);\n }\n return 0;\n };\n\n const a = 3; // Lanczos parameter\n\n for (let i = 0; i < targetHeight; i++) {\n for (let j = 0; j < targetWidth; j++) {\n const x = j * xRatio;\n const y = i * yRatio;\n\n const xL = Math.floor(x);\n const yL = Math.floor(y);\n\n let value = 0;\n let weightSum = 0;\n\n for (let ky = yL - a + 1; ky <= yL + a; ky++) {\n for (let kx = xL - a + 1; kx <= xL + a; kx++) {\n if (kx >= 0 && kx < srcWidth && ky >= 0 && ky < srcHeight) {\n const pixel = input[ky * srcWidth + kx];\n const weight = lanczos(x - kx, a) * lanczos(y - ky, a);\n value += pixel * weight;\n weightSum += weight;\n }\n }\n }\n\n output[i * targetWidth + j] = weightSum !== 0 ? Math.round(value / weightSum) : 0;\n }\n }\n\n return output;\n}\n\nexport const toAbsoluteURI = (relativeURL: string, baseURL?: string) => {\n // adapted from - https://github.com/axios/axios/blob/fe7d09bb08fa1c0e414956b7fc760c80459b0a43/lib/helpers/combineURLs.js\n\n if (!baseURL || relativeURL.startsWith('http')) {\n return new URL(relativeURL).href;\n }\n\n return relativeURL\n ? baseURL.replace(/\\/+$/, '') + '/' + relativeURL.replace(/^\\/+/, '')\n : baseURL;\n};\n\nexport function compileShader(\n gl: WebGL2RenderingContext,\n shader_type: number,\n source: string\n): WebGLShader {\n const shader = gl.createShader(shader_type);\n\n if (!shader) {\n throw new Error('[ladon-ts] - error creating shader');\n }\n\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n const error = gl.getShaderInfoLog(shader) ?? 'unknown error compiling shader.';\n throw new Error('[ladon-ts] - ' + error);\n }\n\n return shader;\n}\n\nexport function linkProgram(\n gl: WebGL2RenderingContext,\n vertex_shader: WebGLShader,\n fragment_shader: WebGLShader\n): WebGLProgram {\n const program = gl.createProgram();\n\n if (!program) {\n throw new Error('[ladon-ts] - error creating GPU program');\n }\n\n gl.attachShader(program, vertex_shader);\n gl.attachShader(program, fragment_shader);\n\n gl.linkProgram(program);\n\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n const error = gl.getProgramInfoLog(program) ?? 'unknown error linking program.';\n throw new Error('[ladon-ts] - ' + error);\n }\n\n return program;\n}\n\n/**\n * Determines if a URI is already resolved.\n * A resolved URI is either:\n * - A blob URL (starts with 'blob:')\n * - A fully qualified URL (e.g., http:// or https://)\n *\n * @param uri - The URI to check.\n * @returns Whether the URI is already resolved.\n */\nexport function isResolvedUri(uri: string): boolean {\n if (uri.startsWith('blob:')) {\n // Blob URIs are resolved\n return true;\n }\n\n try {\n // Throws if the URI is not a valid full URL\n new URL(uri);\n return true;\n } catch {\n // Not a fully qualified URL\n return false;\n }\n}\n"],"names":["InterpolationMethod","resizeImage","imageData","srcWidth","srcHeight","targetWidth","targetHeight","targetData","xRatio","yRatio","scaledSrcWidth","offset","y","srcY","x","srcOffset","bilinearUpsample","input","output","i","j","xL","yL","xH","yH","xWeight","yWeight","a","b","c","d","value","lanczos3Upsample","lanczos","piX","weightSum","ky","kx","pixel","weight","toAbsoluteURI","relativeURL","baseURL","compileShader","gl","shader_type","source","shader","error","linkProgram","vertex_shader","fragment_shader","program","isResolvedUri","uri"],"mappings":"AAAY,IAAAA,sBAAAA,OACRA,EAAA,UAAU,WADFA,IAAAA,KAAA,CAAA,C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ASF,CAAa,GACnCN,EAAA,aAAaQ,GAASD,CAAe,GAExCP,EAAG,YAAYQ,CAAO,GAElB,CAACR,EAAG,oBAAoBQ,GAASR,EAAG,WAAW,GAAG;AAClD,UAAMI,IAAQJ,EAAG,kBAAkBQ,CAAO,KAAK;AACzC,UAAA,IAAI,MAAM,kBAAkBJ,CAAK;AAAA,EAAA;AAGpC,SAAAI;AACX;AAWO,SAASC,EAAcC,GAAsB;AAC5C,MAAAA,EAAI,WAAW,OAAO;AAEf,WAAA;AAGP,MAAA;AAEA,eAAI,IAAIA,CAAG,GACJ;AAAA,EAAA,QACH;AAEG,WAAA;AAAA,EAAA;AAEf;"}
|
|
1
|
+
{"version":3,"file":"util.js","sources":["../../../src/lib/util.ts"],"sourcesContent":["export enum InterpolationMethod {\n Nearest = 'nearest',\n}\n\n/**\n * Resizes an image from the source dimensions to target dimensions.\n *\n * @param {Uint8ClampedArray} imageData The source image data in Uint8ClampedArray format.\n * @param {number} srcWidth The width of the source image.\n * @param {number} srcHeight The height of the source image.\n * @param {number} targetWidth The width of the target image.\n * @param {number} targetHeight The height of the target image.\n *\n * @returns {Uint8ClampedArray} The target image data in Uint8ClampedArray format.\n *\n * @example\n * const targetData = resizeImage(sourceData, 800, 600, 400, 300);\n *\n * @note The function uses a \"nearest neighbor\" algorithm for resizing,\n * which is fast but might not provide the best quality for all images.\n */\nexport const resizeImage = (\n imageData: Uint8ClampedArray,\n srcWidth: number,\n srcHeight: number,\n targetWidth: number,\n targetHeight: number\n): Uint8ClampedArray => {\n const targetData = new Uint8ClampedArray(targetWidth * targetHeight * 4);\n const xRatio = srcWidth / targetWidth;\n const yRatio = srcHeight / targetHeight;\n const scaledSrcWidth = srcWidth * 4;\n let offset = 0;\n\n for (let y = 0; y < targetHeight; y++) {\n const srcY = Math.floor(y * yRatio) * scaledSrcWidth;\n for (let x = 0; x < targetWidth; x++) {\n const srcOffset = srcY + Math.floor(x * xRatio) * 4;\n\n targetData[offset++] = imageData[srcOffset];\n targetData[offset++] = imageData[srcOffset + 1];\n targetData[offset++] = imageData[srcOffset + 2];\n targetData[offset++] = imageData[srcOffset + 3];\n }\n }\n\n return targetData;\n};\n\n/**\n * Upsamples an image using the bilinear interpolation method. The input image is expected to be in\n * Float32Array format. The output image is in Uint8ClampedArray format. The input image is expected\n * to be in the [0, 1] range. The output image is in the [0, 255] range.\n *\n * @param {Float32Array} input The input image data in Float32Array format.\n * @param {number} srcWidth The width of the source image.\n * @param {number} srcHeight The height of the source image.\n * @param {number} targetWidth The width of the target image.\n * @param {number} targetHeight The height of the target image.\n *\n * @returns {Uint8ClampedArray} The upsampled image data in Uint8ClampedArray format.\n *\n */\nexport function bilinearUpsample(\n input: Float32Array,\n srcWidth: number,\n srcHeight: number,\n targetWidth: number,\n targetHeight: number\n) {\n const output = new Uint8ClampedArray(targetWidth * targetHeight);\n\n // If the source and target dimensions are the same, just copy the input to the output.\n // The output is expected to be in the [0, 255] range\n if (srcWidth === targetWidth && srcHeight === targetHeight) {\n for (let i = 0; i < input.length; i++) {\n output[i] = Math.min(Math.max(input[i], 0), 255);\n }\n return output;\n }\n\n const xRatio = (srcWidth - 1) / (targetWidth - 1);\n const yRatio = (srcHeight - 1) / (targetHeight - 1);\n\n for (let i = 0; i < targetHeight; i++) {\n for (let j = 0; j < targetWidth; j++) {\n const x = xRatio * j;\n const y = yRatio * i;\n\n const xL = Math.floor(x);\n const yL = Math.floor(y);\n const xH = Math.min(Math.ceil(x), srcWidth - 1);\n const yH = Math.min(Math.ceil(y), srcHeight - 1);\n\n const xWeight = x - xL;\n const yWeight = y - yL;\n\n const a = input[yL * srcWidth + xL];\n const b = input[yL * srcWidth + xH];\n const c = input[yH * srcWidth + xL];\n const d = input[yH * srcWidth + xH];\n\n const value =\n a * (1 - xWeight) * (1 - yWeight) +\n b * xWeight * (1 - yWeight) +\n c * (1 - xWeight) * yWeight +\n d * xWeight * yWeight;\n\n output[i * targetWidth + j] = Math.min(Math.max(value, 0), 255);\n }\n }\n\n return output;\n}\n\n/**\n * Upsamples an image using the Lanczos3 interpolation method. The input image is expected to be in\n * Float32Array format. The output image is in Uint8ClampedArray format. The input image is expected\n * to be in the [0, 1] range. The output image is in the [0, 255] range.\n *\n * @param {Float32Array} input The input image data in Float32Array format.\n * @param {number} srcWidth The width of the source image.\n * @param {number} srcHeight The height of the source image.\n * @param {number} targetWidth The width of the target image.\n * @param {number} targetHeight The height of the target image.\n *\n * @returns {Uint8ClampedArray} The upsampled image data in Uint8ClampedArray format.\n */\nexport function lanczos3Upsample(\n input: Float32Array,\n srcWidth: number,\n srcHeight: number,\n targetWidth: number,\n targetHeight: number\n) {\n const output = new Uint8ClampedArray(targetWidth * targetHeight);\n\n const xRatio = srcWidth / targetWidth;\n const yRatio = srcHeight / targetHeight;\n\n const lanczos = (x: number, a: number) => {\n if (x === 0) return 1;\n if (x < 0) x = -x;\n if (x < a) {\n const piX = Math.PI * x;\n return (a * Math.sin(piX) * Math.sin(piX / a)) / (piX * piX);\n }\n return 0;\n };\n\n const a = 3; // Lanczos parameter\n\n for (let i = 0; i < targetHeight; i++) {\n for (let j = 0; j < targetWidth; j++) {\n const x = j * xRatio;\n const y = i * yRatio;\n\n const xL = Math.floor(x);\n const yL = Math.floor(y);\n\n let value = 0;\n let weightSum = 0;\n\n for (let ky = yL - a + 1; ky <= yL + a; ky++) {\n for (let kx = xL - a + 1; kx <= xL + a; kx++) {\n if (kx >= 0 && kx < srcWidth && ky >= 0 && ky < srcHeight) {\n const pixel = input[ky * srcWidth + kx];\n const weight = lanczos(x - kx, a) * lanczos(y - ky, a);\n value += pixel * weight;\n weightSum += weight;\n }\n }\n }\n\n output[i * targetWidth + j] = weightSum !== 0 ? Math.round(value / weightSum) : 0;\n }\n }\n\n return output;\n}\n\nexport const toAbsoluteURI = (relativeURL: string, baseURL?: string) => {\n // adapted from - https://github.com/axios/axios/blob/fe7d09bb08fa1c0e414956b7fc760c80459b0a43/lib/helpers/combineURLs.js\n\n if (!baseURL || relativeURL.startsWith('http')) {\n return new URL(relativeURL).href;\n }\n\n return relativeURL\n ? baseURL.replace(/\\/+$/, '') + '/' + relativeURL.replace(/^\\/+/, '')\n : baseURL;\n};\n\nexport function compileShader(\n gl: WebGL2RenderingContext,\n shader_type: number,\n source: string\n): WebGLShader {\n const shader = gl.createShader(shader_type);\n\n if (!shader) {\n throw new Error('[ladon-ts] - error creating shader');\n }\n\n gl.shaderSource(shader, source);\n gl.compileShader(shader);\n\n if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n const error = gl.getShaderInfoLog(shader) ?? 'unknown error compiling shader.';\n throw new Error('[ladon-ts] - ' + error);\n }\n\n return shader;\n}\n\nexport function linkProgram(\n gl: WebGL2RenderingContext,\n vertex_shader: WebGLShader,\n fragment_shader: WebGLShader\n): WebGLProgram {\n const program = gl.createProgram();\n\n if (!program) {\n throw new Error('[ladon-ts] - error creating GPU program');\n }\n\n gl.attachShader(program, vertex_shader);\n gl.attachShader(program, fragment_shader);\n\n gl.linkProgram(program);\n\n if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n const error = gl.getProgramInfoLog(program) ?? 'unknown error linking program.';\n throw new Error('[ladon-ts] - ' + error);\n }\n\n return program;\n}\n\n/**\n * Determines if a URI is already resolved.\n * A resolved URI is either:\n * - A blob URL (starts with 'blob:')\n * - A fully qualified URL (e.g., http:// or https://)\n *\n * @param uri - The URI to check.\n * @returns Whether the URI is already resolved.\n */\nexport function isResolvedUri(uri: string): boolean {\n if (uri.startsWith('blob:')) {\n // Blob URIs are resolved\n return true;\n }\n\n try {\n // Throws if the URI is not a valid full URL\n new URL(uri);\n return true;\n } catch {\n // Not a fully qualified URL\n return false;\n }\n}\n\nexport async function loadAndCacheFile(fileUrl: string): Promise<ArrayBufferLike | Uint8Array> {\n const cache = await caches.open('ladon-cache');\n\n // Try to get the file from cache using its full URL\n const cachedResponse = await cache.match(fileUrl);\n if (cachedResponse) {\n return cachedResponse.arrayBuffer();\n }\n\n // If not in cache, fetch and cache the file\n const response = await fetch(fileUrl);\n\n // Ensure the response is valid\n if (!response.ok) {\n throw new Error(`Failed to fetch file: ${fileUrl}`);\n }\n\n const contentType = response.headers.get('Content-Type') || 'application/octet-stream';\n\n // Validate expected MIME types\n if (!contentType.includes('application/wasm') && !contentType.includes('binary/octet-stream')) {\n throw new Error(`Unexpected MIME type: ${contentType} for ${fileUrl}`);\n }\n\n const fileBinary = await response.arrayBuffer();\n\n // Cache the response with proper headers\n const cachedResponseWithHeaders = new Response(fileBinary, {\n headers: {\n 'Content-Type': contentType,\n 'Content-Length': fileBinary.byteLength.toString(),\n },\n });\n\n // Store the response in the cache using the full URL as the key\n await cache.put(fileUrl, cachedResponseWithHeaders);\n\n return fileBinary;\n}\n"],"names":["InterpolationMethod","resizeImage","imageData","srcWidth","srcHeight","targetWidth","targetHeight","targetData","xRatio","yRatio","scaledSrcWidth","offset","y","srcY","x","srcOffset","bilinearUpsample","input","output","j","xL","yL","xH","yH","xWeight","yWeight","a","b","c","d","value","lanczos3Upsample","lanczos","piX","i","weightSum","ky","kx","pixel","weight","toAbsoluteURI","relativeURL","baseURL","compileShader","gl","shader_type","source","shader","error","linkProgram","vertex_shader","fragment_shader","program","isResolvedUri","uri","loadAndCacheFile","fileUrl","cache","cachedResponse","response","contentType","fileBinary","cachedResponseWithHeaders"],"mappings":"AAAY,IAAAA,sBAAAA,OACRA,EAAA,UAAU,WADFA,IAAAA,KAAA,CAAA,CAAA;AAqBL,MAAMC,IAAc,CACvBC,GACAC,GACAC,GACAC,GACAC,MACoB;AACpB,QAAMC,IAAa,IAAI,kBAAkBF,IAAcC,IAAe,CAAC,GACjEE,IAASL,IAAWE,GACpBI,IAASL,IAAYE,GACrBI,IAAiBP,IAAW;AAClC,MAAIQ,IAAS;AAEb,WAASC,IAAI,GAAGA,IAAIN,GAAcM,KAAK;AACnC,UAAMC,IAAO,KAAK,MAAMD,IAAIH,CAAM,IAAIC;AACtC,aAASI,IAAI,GAAGA,IAAIT,GAAaS,KAAK;AA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AI,IAAIA,CAAG,GACJ;AAAA,EAAA,QACH;AAEG,WAAA;AAAA,EAAA;AAEf;AAEA,eAAsBC,EAAiBC,GAAwD;AAC3F,QAAMC,IAAQ,MAAM,OAAO,KAAK,aAAa,GAGvCC,IAAiB,MAAMD,EAAM,MAAMD,CAAO;AAChD,MAAIE;AACA,WAAOA,EAAe,YAAY;AAIhC,QAAAC,IAAW,MAAM,MAAMH,CAAO;AAGhC,MAAA,CAACG,EAAS;AACV,UAAM,IAAI,MAAM,yBAAyBH,CAAO,EAAE;AAGtD,QAAMI,IAAcD,EAAS,QAAQ,IAAI,cAAc,KAAK;AAGxD,MAAA,CAACC,EAAY,SAAS,kBAAkB,KAAK,CAACA,EAAY,SAAS,qBAAqB;AACxF,UAAM,IAAI,MAAM,yBAAyBA,CAAW,QAAQJ,CAAO,EAAE;AAGnE,QAAAK,IAAa,MAAMF,EAAS,YAAY,GAGxCG,IAA4B,IAAI,SAASD,GAAY;AAAA,IACvD,SAAS;AAAA,MACL,gBAAgBD;AAAA,MAChB,kBAAkBC,EAAW,WAAW,SAAS;AAAA,IAAA;AAAA,EACrD,CACH;AAGK,eAAAJ,EAAM,IAAID,GAASM,CAAyB,GAE3CD;AACX;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const LIB_VERSION = "5.
|
|
1
|
+
export declare const LIB_VERSION = "5.4.1";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sources":["../../../src/lib/version.ts"],"sourcesContent":["export const LIB_VERSION = '5.
|
|
1
|
+
{"version":3,"file":"version.js","sources":["../../../src/lib/version.ts"],"sourcesContent":["export const LIB_VERSION = '5.4.1';\n"],"names":["LIB_VERSION"],"mappings":"AAAO,MAAMA,IAAc;"}
|