@absolutejs/geometry 0.1.0 → 0.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/README.md CHANGED
@@ -75,3 +75,24 @@ Run `bun install --frozen-lockfile` and `bun run check:package`.
75
75
  and its development asset tooling; see docs/canopy-audit/README.md.
76
76
 
77
77
  Licensed under BSL-1.1; see LICENSE for the additional use grant and change date.
78
+
79
+ ## Worker-side alpha preparation (0.1.1)
80
+
81
+ `alphaFromRgba(rgba, width, height)` copies one alpha byte per RGBA8 texel into an
82
+ owned Uint8Array. It accepts Uint8Array or Uint8ClampedArray and validates the
83
+ exact byte length and the same 4,194,304-texel budget before allocation.
84
+
85
+ `alphaFromImageBitmap(bitmap)` reads an already decoded bitmap using a temporary
86
+ OffscreenCanvas 2D context with `willReadFrequently: true`. Call it in a worker;
87
+ it performs synchronous CPU readback wherever it is called. The temporary canvas
88
+ is released afterward. It does not create a WebGL context, close the input bitmap,
89
+ or detach any borrowed renderer resource. The caller owns bitmap cleanup.
90
+ Unsupported runtimes, closed/invalid bitmaps and oversized images fail explicitly.
91
+ There is no hidden main-thread fallback.
92
+
93
+ ImageBitmap supports structured cloning as well as transfer. The browser-worker
94
+ qualification checks exact alpha values and that closing a cloned worker image
95
+ leaves its source usable. Transfer only owned copies if using a transfer list.
96
+ See the [HTML ImageBitmap ownership contract](https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#imagebitmap)
97
+ and [OffscreenCanvas](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas).
98
+ These helpers prepare raster inputs; they do not assign hydrologic meaning to alpha.
@@ -0,0 +1,5 @@
1
+ /** Copy one alpha byte per row-major RGBA8 texel. Does not mutate borrowed pixels. */
2
+ export declare function alphaFromRgba(rgba: Uint8Array | Uint8ClampedArray, width: number, height: number): Uint8Array;
3
+ /** Worker/setup-time CPU readback. The caller owns and closes the bitmap.
4
+ * This never closes/detaches the caller's image and never creates a WebGL context. */
5
+ export declare function alphaFromImageBitmap(bitmap: ImageBitmap): Uint8Array;
package/dist/alpha.js ADDED
@@ -0,0 +1,37 @@
1
+ const MAX_TEXELS = 4_194_304;
2
+ function validateSize(width, height) {
3
+ if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 1 || height < 1 || width * height > MAX_TEXELS)
4
+ throw Error('Invalid or oversized alpha source');
5
+ }
6
+ /** Copy one alpha byte per row-major RGBA8 texel. Does not mutate borrowed pixels. */
7
+ export function alphaFromRgba(rgba, width, height) {
8
+ validateSize(width, height);
9
+ if (!(rgba instanceof Uint8Array || rgba instanceof Uint8ClampedArray) || rgba.length !== width * height * 4)
10
+ throw Error('Expected tightly packed RGBA8 alpha source');
11
+ const alpha = new Uint8Array(width * height);
12
+ for (let i = 0; i < alpha.length; i++)
13
+ alpha[i] = rgba[i * 4 + 3];
14
+ return alpha;
15
+ }
16
+ /** Worker/setup-time CPU readback. The caller owns and closes the bitmap.
17
+ * This never closes/detaches the caller's image and never creates a WebGL context. */
18
+ export function alphaFromImageBitmap(bitmap) {
19
+ if (typeof ImageBitmap === 'undefined' || !(bitmap instanceof ImageBitmap))
20
+ throw Error('Expected an available ImageBitmap');
21
+ validateSize(bitmap.width, bitmap.height);
22
+ if (typeof OffscreenCanvas === 'undefined')
23
+ throw Error('OffscreenCanvas is unavailable for alpha readback');
24
+ const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
25
+ try {
26
+ const context = canvas.getContext('2d', { willReadFrequently: true });
27
+ if (!context)
28
+ throw Error('Canvas2D is unavailable for alpha readback');
29
+ context.drawImage(bitmap, 0, 0);
30
+ const pixels = context.getImageData(0, 0, bitmap.width, bitmap.height);
31
+ return alphaFromRgba(pixels.data, pixels.width, pixels.height);
32
+ }
33
+ finally {
34
+ canvas.width = 0;
35
+ canvas.height = 0;
36
+ }
37
+ }
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { projectAlphaCoverage, type AlphaProjectionInput, type AlphaProjection, } from "./projection.js";
2
+ export { alphaFromRgba, alphaFromImageBitmap } from './alpha.js';
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export { projectAlphaCoverage, } from "./projection.js";
2
+ export { alphaFromRgba, alphaFromImageBitmap } from './alpha.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/geometry",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Bounded alpha-aware geometry projection for worker-side asset measurement and web 3D tooling.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",