@flighthq/bitmap 0.3.0-edge.1458.0c01b63
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/dist/bitmap.d.ts +17 -0
- package/dist/bitmap.d.ts.map +1 -0
- package/dist/bitmap.js +87 -0
- package/dist/bitmap.js.map +1 -0
- package/dist/bitmapAffine.d.ts +27 -0
- package/dist/bitmapAffine.d.ts.map +1 -0
- package/dist/bitmapAffine.js +159 -0
- package/dist/bitmapAffine.js.map +1 -0
- package/dist/bitmapAlpha.d.ts +27 -0
- package/dist/bitmapAlpha.d.ts.map +1 -0
- package/dist/bitmapAlpha.js +83 -0
- package/dist/bitmapAlpha.js.map +1 -0
- package/dist/bitmapBevel.d.ts +24 -0
- package/dist/bitmapBevel.d.ts.map +1 -0
- package/dist/bitmapBevel.js +102 -0
- package/dist/bitmapBevel.js.map +1 -0
- package/dist/bitmapBlur.d.ts +57 -0
- package/dist/bitmapBlur.d.ts.map +1 -0
- package/dist/bitmapBlur.js +263 -0
- package/dist/bitmapBlur.js.map +1 -0
- package/dist/bitmapChannel.d.ts +24 -0
- package/dist/bitmapChannel.d.ts.map +1 -0
- package/dist/bitmapChannel.js +127 -0
- package/dist/bitmapChannel.js.map +1 -0
- package/dist/bitmapColorMatrix.d.ts +57 -0
- package/dist/bitmapColorMatrix.d.ts.map +1 -0
- package/dist/bitmapColorMatrix.js +127 -0
- package/dist/bitmapColorMatrix.js.map +1 -0
- package/dist/bitmapCompare.d.ts +18 -0
- package/dist/bitmapCompare.d.ts.map +1 -0
- package/dist/bitmapCompare.js +64 -0
- package/dist/bitmapCompare.js.map +1 -0
- package/dist/bitmapComposite.d.ts +54 -0
- package/dist/bitmapComposite.d.ts.map +1 -0
- package/dist/bitmapComposite.js +262 -0
- package/dist/bitmapComposite.js.map +1 -0
- package/dist/bitmapConvolution.d.ts +17 -0
- package/dist/bitmapConvolution.d.ts.map +1 -0
- package/dist/bitmapConvolution.js +103 -0
- package/dist/bitmapConvolution.js.map +1 -0
- package/dist/bitmapCopy.d.ts +23 -0
- package/dist/bitmapCopy.d.ts.map +1 -0
- package/dist/bitmapCopy.js +78 -0
- package/dist/bitmapCopy.js.map +1 -0
- package/dist/bitmapCoverage.d.ts +11 -0
- package/dist/bitmapCoverage.d.ts.map +1 -0
- package/dist/bitmapCoverage.js +29 -0
- package/dist/bitmapCoverage.js.map +1 -0
- package/dist/bitmapCrop.d.ts +33 -0
- package/dist/bitmapCrop.d.ts.map +1 -0
- package/dist/bitmapCrop.js +175 -0
- package/dist/bitmapCrop.js.map +1 -0
- package/dist/bitmapDisplacement.d.ts +22 -0
- package/dist/bitmapDisplacement.d.ts.map +1 -0
- package/dist/bitmapDisplacement.js +111 -0
- package/dist/bitmapDisplacement.js.map +1 -0
- package/dist/bitmapDissolve.d.ts +21 -0
- package/dist/bitmapDissolve.d.ts.map +1 -0
- package/dist/bitmapDissolve.js +97 -0
- package/dist/bitmapDissolve.js.map +1 -0
- package/dist/bitmapDraw.d.ts +8 -0
- package/dist/bitmapDraw.d.ts.map +1 -0
- package/dist/bitmapDraw.js +14 -0
- package/dist/bitmapDraw.js.map +1 -0
- package/dist/bitmapEncode.d.ts +3 -0
- package/dist/bitmapEncode.d.ts.map +1 -0
- package/dist/bitmapEncode.js +18 -0
- package/dist/bitmapEncode.js.map +1 -0
- package/dist/bitmapFill.d.ts +12 -0
- package/dist/bitmapFill.d.ts.map +1 -0
- package/dist/bitmapFill.js +85 -0
- package/dist/bitmapFill.js.map +1 -0
- package/dist/bitmapFingerprint.d.ts +26 -0
- package/dist/bitmapFingerprint.d.ts.map +1 -0
- package/dist/bitmapFingerprint.js +99 -0
- package/dist/bitmapFingerprint.js.map +1 -0
- package/dist/bitmapFlip.d.ts +16 -0
- package/dist/bitmapFlip.d.ts.map +1 -0
- package/dist/bitmapFlip.js +98 -0
- package/dist/bitmapFlip.js.map +1 -0
- package/dist/bitmapFormat.d.ts +26 -0
- package/dist/bitmapFormat.d.ts.map +1 -0
- package/dist/bitmapFormat.js +80 -0
- package/dist/bitmapFormat.js.map +1 -0
- package/dist/bitmapFrom.d.ts +23 -0
- package/dist/bitmapFrom.d.ts.map +1 -0
- package/dist/bitmapFrom.js +90 -0
- package/dist/bitmapFrom.js.map +1 -0
- package/dist/bitmapGradient.d.ts +36 -0
- package/dist/bitmapGradient.d.ts.map +1 -0
- package/dist/bitmapGradient.js +176 -0
- package/dist/bitmapGradient.js.map +1 -0
- package/dist/bitmapGradientFill.d.ts +32 -0
- package/dist/bitmapGradientFill.d.ts.map +1 -0
- package/dist/bitmapGradientFill.js +120 -0
- package/dist/bitmapGradientFill.js.map +1 -0
- package/dist/bitmapHistogram.d.ts +20 -0
- package/dist/bitmapHistogram.d.ts.map +1 -0
- package/dist/bitmapHistogram.js +61 -0
- package/dist/bitmapHistogram.js.map +1 -0
- package/dist/bitmapImageChannel.d.ts +2 -0
- package/dist/bitmapImageChannel.d.ts.map +1 -0
- package/dist/bitmapImageChannel.js +2 -0
- package/dist/bitmapImageChannel.js.map +1 -0
- package/dist/bitmapMedian.d.ts +14 -0
- package/dist/bitmapMedian.d.ts.map +1 -0
- package/dist/bitmapMedian.js +77 -0
- package/dist/bitmapMedian.js.map +1 -0
- package/dist/bitmapMorphological.d.ts +29 -0
- package/dist/bitmapMorphological.d.ts.map +1 -0
- package/dist/bitmapMorphological.js +81 -0
- package/dist/bitmapMorphological.js.map +1 -0
- package/dist/bitmapNoise.d.ts +48 -0
- package/dist/bitmapNoise.d.ts.map +1 -0
- package/dist/bitmapNoise.js +245 -0
- package/dist/bitmapNoise.js.map +1 -0
- package/dist/bitmapPaletteMap.d.ts +17 -0
- package/dist/bitmapPaletteMap.d.ts.map +1 -0
- package/dist/bitmapPaletteMap.js +45 -0
- package/dist/bitmapPaletteMap.js.map +1 -0
- package/dist/bitmapPixel.d.ts +9 -0
- package/dist/bitmapPixel.d.ts.map +1 -0
- package/dist/bitmapPixel.js +36 -0
- package/dist/bitmapPixel.js.map +1 -0
- package/dist/bitmapPixelate.d.ts +13 -0
- package/dist/bitmapPixelate.d.ts.map +1 -0
- package/dist/bitmapPixelate.js +61 -0
- package/dist/bitmapPixelate.js.map +1 -0
- package/dist/bitmapQuery.d.ts +13 -0
- package/dist/bitmapQuery.d.ts.map +1 -0
- package/dist/bitmapQuery.js +46 -0
- package/dist/bitmapQuery.js.map +1 -0
- package/dist/bitmapRegion.d.ts +20 -0
- package/dist/bitmapRegion.d.ts.map +1 -0
- package/dist/bitmapRegion.js +28 -0
- package/dist/bitmapRegion.js.map +1 -0
- package/dist/bitmapResize.d.ts +17 -0
- package/dist/bitmapResize.d.ts.map +1 -0
- package/dist/bitmapResize.js +191 -0
- package/dist/bitmapResize.js.map +1 -0
- package/dist/bitmapRotate.d.ts +32 -0
- package/dist/bitmapRotate.d.ts.map +1 -0
- package/dist/bitmapRotate.js +143 -0
- package/dist/bitmapRotate.js.map +1 -0
- package/dist/bitmapShadow.d.ts +72 -0
- package/dist/bitmapShadow.d.ts.map +1 -0
- package/dist/bitmapShadow.js +175 -0
- package/dist/bitmapShadow.js.map +1 -0
- package/dist/bitmapSharpen.d.ts +16 -0
- package/dist/bitmapSharpen.d.ts.map +1 -0
- package/dist/bitmapSharpen.js +47 -0
- package/dist/bitmapSharpen.js.map +1 -0
- package/dist/bitmapTone.d.ts +28 -0
- package/dist/bitmapTone.d.ts.map +1 -0
- package/dist/bitmapTone.js +69 -0
- package/dist/bitmapTone.js.map +1 -0
- package/dist/bitmapTransform.d.ts +40 -0
- package/dist/bitmapTransform.d.ts.map +1 -0
- package/dist/bitmapTransform.js +163 -0
- package/dist/bitmapTransform.js.map +1 -0
- package/dist/bitmapWarp.d.ts +48 -0
- package/dist/bitmapWarp.d.ts.map +1 -0
- package/dist/bitmapWarp.js +284 -0
- package/dist/bitmapWarp.js.map +1 -0
- package/dist/contract.d.ts +43 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +43 -0
- package/dist/contract.js.map +1 -0
- package/dist/explainBitmapReadback.d.ts +3 -0
- package/dist/explainBitmapReadback.d.ts.map +1 -0
- package/dist/explainBitmapReadback.js +39 -0
- package/dist/explainBitmapReadback.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
- package/src/bitmap.test.ts +88 -0
- package/src/bitmapAffine.test.ts +98 -0
- package/src/bitmapAlpha.test.ts +110 -0
- package/src/bitmapBevel.test.ts +61 -0
- package/src/bitmapBlur.test.ts +234 -0
- package/src/bitmapChannel.test.ts +97 -0
- package/src/bitmapColorMatrix.test.ts +214 -0
- package/src/bitmapCompare.test.ts +92 -0
- package/src/bitmapComposite.test.ts +259 -0
- package/src/bitmapConvolution.test.ts +130 -0
- package/src/bitmapCopy.test.ts +48 -0
- package/src/bitmapCoverage.test.ts +39 -0
- package/src/bitmapCrop.test.ts +116 -0
- package/src/bitmapDisplacement.test.ts +181 -0
- package/src/bitmapDissolve.test.ts +99 -0
- package/src/bitmapDraw.test.ts +68 -0
- package/src/bitmapEncode.test.ts +18 -0
- package/src/bitmapFill.test.ts +83 -0
- package/src/bitmapFingerprint.test.ts +103 -0
- package/src/bitmapFlip.test.ts +53 -0
- package/src/bitmapFormat.test.ts +124 -0
- package/src/bitmapFrom.test.ts +86 -0
- package/src/bitmapGradient.test.ts +85 -0
- package/src/bitmapGradientFill.test.ts +107 -0
- package/src/bitmapHistogram.test.ts +64 -0
- package/src/bitmapImageChannel.test.ts +19 -0
- package/src/bitmapMedian.test.ts +39 -0
- package/src/bitmapMorphological.test.ts +69 -0
- package/src/bitmapNoise.test.ts +163 -0
- package/src/bitmapPaletteMap.test.ts +49 -0
- package/src/bitmapPixel.test.ts +117 -0
- package/src/bitmapPixelate.test.ts +40 -0
- package/src/bitmapQuery.test.ts +42 -0
- package/src/bitmapRegion.test.ts +34 -0
- package/src/bitmapResize.test.ts +106 -0
- package/src/bitmapRotate.test.ts +108 -0
- package/src/bitmapShadow.test.ts +159 -0
- package/src/bitmapSharpen.test.ts +44 -0
- package/src/bitmapTone.test.ts +104 -0
- package/src/bitmapTransform.test.ts +128 -0
- package/src/bitmapWarp.test.ts +118 -0
- package/src/explainBitmapReadback.test.ts +84 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createEntity } from '@flighthq/entity/contract';
|
|
2
|
+
import { BitmapTextureSourceKind } from '@flighthq/types/contract';
|
|
3
|
+
/**
|
|
4
|
+
* Reads a host-backed Image into a newly allocated, CPU-readable Bitmap. The readback draws
|
|
5
|
+
* through a detached canvas; callers that need both representations should retain both objects.
|
|
6
|
+
*/
|
|
7
|
+
export function captureBitmapFromImageResource(resource) {
|
|
8
|
+
const canvas = document.createElement('canvas');
|
|
9
|
+
canvas.width = resource.width;
|
|
10
|
+
canvas.height = resource.height;
|
|
11
|
+
const ctx = canvas.getContext('2d');
|
|
12
|
+
ctx.drawImage(resource.source, 0, 0);
|
|
13
|
+
const raw = ctx.getImageData(0, 0, resource.width, resource.height);
|
|
14
|
+
return createEntity({
|
|
15
|
+
alphaType: 'straight',
|
|
16
|
+
colorSpace: raw.colorSpace,
|
|
17
|
+
data: raw.data,
|
|
18
|
+
format: 'rgba8unorm',
|
|
19
|
+
height: resource.height,
|
|
20
|
+
kind: BitmapTextureSourceKind,
|
|
21
|
+
version: 0,
|
|
22
|
+
width: resource.width,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function createBitmapFromCanvas(canvas, x = 0, y = 0, width, height) {
|
|
26
|
+
const w = width ?? canvas.width;
|
|
27
|
+
const h = height ?? canvas.height;
|
|
28
|
+
const ctx = canvas.getContext('2d');
|
|
29
|
+
const raw = ctx.getImageData(x, y, w, h);
|
|
30
|
+
return createEntity({
|
|
31
|
+
alphaType: 'straight',
|
|
32
|
+
colorSpace: raw.colorSpace,
|
|
33
|
+
data: raw.data,
|
|
34
|
+
format: 'rgba8unorm',
|
|
35
|
+
height: raw.height,
|
|
36
|
+
kind: BitmapTextureSourceKind,
|
|
37
|
+
version: 0,
|
|
38
|
+
width: raw.width,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Reads a bitmap out of any `CanvasImageSource` by drawing it into a scratch 2D canvas. Unlike
|
|
43
|
+
* createBitmapFromCanvas — which calls getContext('2d') and so only works on a 2D-rendered canvas —
|
|
44
|
+
* this captures a Gl or Wgpu canvas too, giving one readback path for every render backend.
|
|
45
|
+
* `width`/`height` are the device-pixel dimensions to capture (pass the render state's canvas size).
|
|
46
|
+
* For a Gl/Wgpu source, draw before the browser composites the frame away (in tests, enable the
|
|
47
|
+
* context's preserveDrawingBuffer, or read immediately after rendering).
|
|
48
|
+
*
|
|
49
|
+
* Returns `null` when the pixels cannot be read rather than letting a platform exception escape. A
|
|
50
|
+
* cross-origin source taints the scratch canvas and the platform refuses to return its pixels — that
|
|
51
|
+
* is an expected outcome of loading someone else's image, not a programmer error, so it takes the
|
|
52
|
+
* sentinel the diagnostics conventions reserve for expected failure. Call `explainBitmapReadback`
|
|
53
|
+
* with the same arguments for the reason; it re-derives it without allocating a bitmap.
|
|
54
|
+
*/
|
|
55
|
+
export function createBitmapFromImageSource(source, width, height) {
|
|
56
|
+
if (width <= 0 || height <= 0)
|
|
57
|
+
return null;
|
|
58
|
+
if (typeof document === 'undefined')
|
|
59
|
+
return null;
|
|
60
|
+
const canvas = document.createElement('canvas');
|
|
61
|
+
canvas.width = width;
|
|
62
|
+
canvas.height = height;
|
|
63
|
+
const ctx = canvas.getContext('2d');
|
|
64
|
+
if (ctx === null)
|
|
65
|
+
return null;
|
|
66
|
+
let raw;
|
|
67
|
+
try {
|
|
68
|
+
ctx.drawImage(source, 0, 0);
|
|
69
|
+
raw = ctx.getImageData(0, 0, width, height);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// A tainted canvas throws SecurityError from getImageData; a source the platform cannot draw
|
|
73
|
+
// throws from drawImage. Both mean "no pixels for you", which is the sentinel's job to say.
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
// Annotated rather than returned inline: with a `Bitmap | null` return the object literal loses the
|
|
77
|
+
// contextual typing that narrows its string fields to Bitmap's literal types.
|
|
78
|
+
const bitmap = createEntity({
|
|
79
|
+
alphaType: 'straight',
|
|
80
|
+
colorSpace: raw.colorSpace,
|
|
81
|
+
data: raw.data,
|
|
82
|
+
format: 'rgba8unorm',
|
|
83
|
+
height,
|
|
84
|
+
kind: BitmapTextureSourceKind,
|
|
85
|
+
version: 0,
|
|
86
|
+
width,
|
|
87
|
+
});
|
|
88
|
+
return bitmap;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=bitmapFrom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapFrom.js","sourceRoot":"","sources":["../src/bitmapFrom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAAC,QAAyB;IACtE,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC9B,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;IAChC,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAE,CAAC;IACrC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpE,OAAO,YAAY,CAAC;QAClB,SAAS,EAAE,UAAU;QACrB,UAAU,EAAE,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,GAAG,KAAK,CAAC;IACrB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC9B,IAAI,GAAc,CAAC;IACnB,IAAI,CAAC;QACH,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5B,GAAG,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,6FAA6F;QAC7F,4FAA4F;QAC5F,OAAO,IAAI,CAAC;IACd,CAAC;IACD,oGAAoG;IACpG,8EAA8E;IAC9E,MAAM,MAAM,GAAW,YAAY,CAAC;QAClC,SAAS,EAAE,UAAU;QACrB,UAAU,EAAE,GAAG,CAAC,UAAmC;QACnD,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,MAAM,EAAE,YAAY;QACpB,MAAM;QACN,IAAI,EAAE,uBAAuB;QAC7B,OAAO,EAAE,CAAC;QACV,KAAK;KACN,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BitmapGradientBevelOptions, BitmapGradientGlowOptions, BitmapRegion } from '@flighthq/types/contract';
|
|
2
|
+
/**
|
|
3
|
+
* Fills `out` (256 RGBA entries, 1024 bytes) with a gradient lookup table built
|
|
4
|
+
* from parallel `colors` (packed 0xRRGGBB), `alphas` (0..1), and `ratios`
|
|
5
|
+
* (0..255, ascending) arrays. Indices below the first ratio take the first stop;
|
|
6
|
+
* indices above the last take the last stop; in between, channels are linearly
|
|
7
|
+
* interpolated.
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildBitmapGradientRamp(out: Uint8ClampedArray, colors: ReadonlyArray<number>, alphas: ReadonlyArray<number>, ratios: ReadonlyArray<number>): void;
|
|
10
|
+
/**
|
|
11
|
+
* Produces a gradient bevel mask in `out`. Like `bevelBitmap`, but the signed
|
|
12
|
+
* edge gradient (-1..1) indexes the 256-entry `ramp` instead of selecting one of
|
|
13
|
+
* two flat colors: -1 maps to ramp index 0 (shadow side), 0 to 128 (flat,
|
|
14
|
+
* typically transparent), +1 to 255 (highlight side).
|
|
15
|
+
*
|
|
16
|
+
* `ramp` must be 256 RGBA entries (1024 bytes); build it with
|
|
17
|
+
* `buildBitmapGradientRamp`. `scratch` must be a distinct buffer from `out`,
|
|
18
|
+
* at least `source.width * source.height * 4` bytes; its contents are undefined
|
|
19
|
+
* after the call.
|
|
20
|
+
*
|
|
21
|
+
* `out` must NOT alias `source.bitmap.data`: `out` is used as the blur scratch,
|
|
22
|
+
* and the source alpha is read again afterward for `inner`/`outer` clipping.
|
|
23
|
+
*/
|
|
24
|
+
export declare function gradientBevelBitmap(out: Uint8ClampedArray, scratch: Uint8ClampedArray, source: Readonly<BitmapRegion>, ramp: Readonly<Uint8ClampedArray>, options?: Readonly<BitmapGradientBevelOptions>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Produces a gradient glow mask in `out`. Like `glowBitmap`, but the blurred
|
|
27
|
+
* source alpha (0..255) indexes the 256-entry `ramp` for both color and opacity,
|
|
28
|
+
* so the glow color varies with distance from the shape.
|
|
29
|
+
*
|
|
30
|
+
* `ramp` must be 256 RGBA entries (1024 bytes); build it with
|
|
31
|
+
* `buildBitmapGradientRamp`. `scratch` must be at least
|
|
32
|
+
* `source.width * source.height * 4` bytes; its contents are undefined after the
|
|
33
|
+
* call. Safe to pass `source.bitmap.data` as `out` for a full-bitmap region.
|
|
34
|
+
*/
|
|
35
|
+
export declare function gradientGlowBitmap(out: Uint8ClampedArray, scratch: Uint8ClampedArray, source: Readonly<BitmapRegion>, ramp: Readonly<Uint8ClampedArray>, options?: Readonly<BitmapGradientGlowOptions>): void;
|
|
36
|
+
//# sourceMappingURL=bitmapGradient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapGradient.d.ts","sourceRoot":"","sources":["../src/bitmapGradient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAIpH;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,iBAAiB,EACtB,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,GAC5B,IAAI,CAqCN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,iBAAiB,EACtB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,IAAI,EAAE,QAAQ,CAAC,iBAAiB,CAAC,EACjC,OAAO,GAAE,QAAQ,CAAC,0BAA0B,CAAM,GACjD,IAAI,CAyCN;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,iBAAiB,EACtB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,IAAI,EAAE,QAAQ,CAAC,iBAAiB,CAAC,EACjC,OAAO,GAAE,QAAQ,CAAC,yBAAyB,CAAM,GAChD,IAAI,CA0BN"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { blurBitmapPixelsHorizontal, blurBitmapPixelsVertical } from './bitmapBlur';
|
|
2
|
+
/**
|
|
3
|
+
* Fills `out` (256 RGBA entries, 1024 bytes) with a gradient lookup table built
|
|
4
|
+
* from parallel `colors` (packed 0xRRGGBB), `alphas` (0..1), and `ratios`
|
|
5
|
+
* (0..255, ascending) arrays. Indices below the first ratio take the first stop;
|
|
6
|
+
* indices above the last take the last stop; in between, channels are linearly
|
|
7
|
+
* interpolated.
|
|
8
|
+
*/
|
|
9
|
+
export function buildBitmapGradientRamp(out, colors, alphas, ratios) {
|
|
10
|
+
const n = ratios.length;
|
|
11
|
+
if (n === 0) {
|
|
12
|
+
out.fill(0);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
for (let i = 0; i < 256; i++) {
|
|
16
|
+
let r;
|
|
17
|
+
let g;
|
|
18
|
+
let b;
|
|
19
|
+
let a;
|
|
20
|
+
if (i <= ratios[0]) {
|
|
21
|
+
r = (colors[0] >> 16) & 0xff;
|
|
22
|
+
g = (colors[0] >> 8) & 0xff;
|
|
23
|
+
b = colors[0] & 0xff;
|
|
24
|
+
a = alphas[0];
|
|
25
|
+
}
|
|
26
|
+
else if (i >= ratios[n - 1]) {
|
|
27
|
+
r = (colors[n - 1] >> 16) & 0xff;
|
|
28
|
+
g = (colors[n - 1] >> 8) & 0xff;
|
|
29
|
+
b = colors[n - 1] & 0xff;
|
|
30
|
+
a = alphas[n - 1];
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
let j = 0;
|
|
34
|
+
while (j < n - 1 && ratios[j + 1] < i)
|
|
35
|
+
j++;
|
|
36
|
+
const span = ratios[j + 1] - ratios[j];
|
|
37
|
+
const t = span > 0 ? (i - ratios[j]) / span : 0;
|
|
38
|
+
r = lerp((colors[j] >> 16) & 0xff, (colors[j + 1] >> 16) & 0xff, t);
|
|
39
|
+
g = lerp((colors[j] >> 8) & 0xff, (colors[j + 1] >> 8) & 0xff, t);
|
|
40
|
+
b = lerp(colors[j] & 0xff, colors[j + 1] & 0xff, t);
|
|
41
|
+
a = lerp(alphas[j], alphas[j + 1], t);
|
|
42
|
+
}
|
|
43
|
+
const oi = i * 4;
|
|
44
|
+
out[oi] = Math.round(r);
|
|
45
|
+
out[oi + 1] = Math.round(g);
|
|
46
|
+
out[oi + 2] = Math.round(b);
|
|
47
|
+
out[oi + 3] = Math.round(a * 255);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Produces a gradient bevel mask in `out`. Like `bevelBitmap`, but the signed
|
|
52
|
+
* edge gradient (-1..1) indexes the 256-entry `ramp` instead of selecting one of
|
|
53
|
+
* two flat colors: -1 maps to ramp index 0 (shadow side), 0 to 128 (flat,
|
|
54
|
+
* typically transparent), +1 to 255 (highlight side).
|
|
55
|
+
*
|
|
56
|
+
* `ramp` must be 256 RGBA entries (1024 bytes); build it with
|
|
57
|
+
* `buildBitmapGradientRamp`. `scratch` must be a distinct buffer from `out`,
|
|
58
|
+
* at least `source.width * source.height * 4` bytes; its contents are undefined
|
|
59
|
+
* after the call.
|
|
60
|
+
*
|
|
61
|
+
* `out` must NOT alias `source.bitmap.data`: `out` is used as the blur scratch,
|
|
62
|
+
* and the source alpha is read again afterward for `inner`/`outer` clipping.
|
|
63
|
+
*/
|
|
64
|
+
export function gradientBevelBitmap(out, scratch, source, ramp, options = {}) {
|
|
65
|
+
const w = source.width;
|
|
66
|
+
const h = source.height;
|
|
67
|
+
const angle = options.angle ?? Math.PI / 4;
|
|
68
|
+
const distance = options.distance ?? 4;
|
|
69
|
+
const offsetX = Math.round(Math.cos(angle) * distance);
|
|
70
|
+
const offsetY = Math.round(Math.sin(angle) * distance);
|
|
71
|
+
const type = options.type ?? 'inner';
|
|
72
|
+
const intensity = options.intensity ?? 1;
|
|
73
|
+
for (let py = 0; py < h; py++) {
|
|
74
|
+
for (let px = 0; px < w; px++) {
|
|
75
|
+
const di = (py * w + px) * 4;
|
|
76
|
+
scratch[di] = 0;
|
|
77
|
+
scratch[di + 1] = 0;
|
|
78
|
+
scratch[di + 2] = 0;
|
|
79
|
+
scratch[di + 3] = readSourceAlpha(source, px, py);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
blurAlphaField(scratch, out, w, h, options.radiusX, options.radiusY, options.passes);
|
|
83
|
+
for (let py = 0; py < h; py++) {
|
|
84
|
+
for (let px = 0; px < w; px++) {
|
|
85
|
+
const di = (py * w + px) * 4;
|
|
86
|
+
const lit = sampleField(scratch, w, h, px - offsetX, py - offsetY);
|
|
87
|
+
const shade = sampleField(scratch, w, h, px + offsetX, py + offsetY);
|
|
88
|
+
const gradient = lit - shade;
|
|
89
|
+
const idx = Math.max(0, Math.min(255, Math.round((gradient * 0.5 + 0.5) * 255)));
|
|
90
|
+
const ri = idx * 4;
|
|
91
|
+
const clip = type === 'inner'
|
|
92
|
+
? readSourceAlpha(source, px, py) / 255
|
|
93
|
+
: type === 'outer'
|
|
94
|
+
? 1 - readSourceAlpha(source, px, py) / 255
|
|
95
|
+
: 1;
|
|
96
|
+
out[di] = ramp[ri];
|
|
97
|
+
out[di + 1] = ramp[ri + 1];
|
|
98
|
+
out[di + 2] = ramp[ri + 2];
|
|
99
|
+
out[di + 3] = Math.min(255, Math.round(ramp[ri + 3] * intensity * clip));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Produces a gradient glow mask in `out`. Like `glowBitmap`, but the blurred
|
|
105
|
+
* source alpha (0..255) indexes the 256-entry `ramp` for both color and opacity,
|
|
106
|
+
* so the glow color varies with distance from the shape.
|
|
107
|
+
*
|
|
108
|
+
* `ramp` must be 256 RGBA entries (1024 bytes); build it with
|
|
109
|
+
* `buildBitmapGradientRamp`. `scratch` must be at least
|
|
110
|
+
* `source.width * source.height * 4` bytes; its contents are undefined after the
|
|
111
|
+
* call. Safe to pass `source.bitmap.data` as `out` for a full-bitmap region.
|
|
112
|
+
*/
|
|
113
|
+
export function gradientGlowBitmap(out, scratch, source, ramp, options = {}) {
|
|
114
|
+
const w = source.width;
|
|
115
|
+
const h = source.height;
|
|
116
|
+
const intensity = options.intensity ?? 1;
|
|
117
|
+
for (let py = 0; py < h; py++) {
|
|
118
|
+
for (let px = 0; px < w; px++) {
|
|
119
|
+
const di = (py * w + px) * 4;
|
|
120
|
+
out[di] = 0;
|
|
121
|
+
out[di + 1] = 0;
|
|
122
|
+
out[di + 2] = 0;
|
|
123
|
+
out[di + 3] = readSourceAlpha(source, px, py);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
blurAlphaField(out, scratch, w, h, options.radiusX, options.radiusY, options.passes);
|
|
127
|
+
for (let py = 0; py < h; py++) {
|
|
128
|
+
for (let px = 0; px < w; px++) {
|
|
129
|
+
const di = (py * w + px) * 4;
|
|
130
|
+
const ri = out[di + 3] * 4;
|
|
131
|
+
out[di] = ramp[ri];
|
|
132
|
+
out[di + 1] = ramp[ri + 1];
|
|
133
|
+
out[di + 2] = ramp[ri + 2];
|
|
134
|
+
out[di + 3] = Math.min(255, Math.round(ramp[ri + 3] * intensity));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function blurAlphaField(field, scratch, w, h, radiusX, radiusY, passes) {
|
|
139
|
+
const rx = Math.max(0, Math.round(radiusX ?? 2));
|
|
140
|
+
const ry = Math.max(0, Math.round(radiusY ?? 2));
|
|
141
|
+
const p = Math.max(1, Math.round(passes ?? 1));
|
|
142
|
+
let a = field;
|
|
143
|
+
let b = scratch;
|
|
144
|
+
for (let pass = 0; pass < p; pass++) {
|
|
145
|
+
if (rx > 0) {
|
|
146
|
+
blurBitmapPixelsHorizontal(b, a, w, h, rx);
|
|
147
|
+
const t = a;
|
|
148
|
+
a = b;
|
|
149
|
+
b = t;
|
|
150
|
+
}
|
|
151
|
+
if (ry > 0) {
|
|
152
|
+
blurBitmapPixelsVertical(b, a, w, h, ry);
|
|
153
|
+
const t = a;
|
|
154
|
+
a = b;
|
|
155
|
+
b = t;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (a !== field)
|
|
159
|
+
field.set(a.subarray(0, w * h * 4));
|
|
160
|
+
}
|
|
161
|
+
function lerp(from, to, t) {
|
|
162
|
+
return from + (to - from) * t;
|
|
163
|
+
}
|
|
164
|
+
function readSourceAlpha(source, px, py) {
|
|
165
|
+
const sx = source.x + px;
|
|
166
|
+
const sy = source.y + py;
|
|
167
|
+
if (sx < 0 || sx >= source.bitmap.width || sy < 0 || sy >= source.bitmap.height)
|
|
168
|
+
return 0;
|
|
169
|
+
return source.bitmap.data[(sy * source.bitmap.width + sx) * 4 + 3];
|
|
170
|
+
}
|
|
171
|
+
function sampleField(field, w, h, x, y) {
|
|
172
|
+
if (x < 0 || x >= w || y < 0 || y >= h)
|
|
173
|
+
return 0;
|
|
174
|
+
return field[(y * w + x) * 4 + 3] / 255;
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=bitmapGradient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapGradient.js","sourceRoot":"","sources":["../src/bitmapGradient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAEpF;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,GAAsB,EACtB,MAA6B,EAC7B,MAA6B,EAC7B,MAA6B;IAE7B,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACZ,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACZ,OAAO;IACT,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,IAAI,CAAS,CAAC;QACd,IAAI,CAAS,CAAC;QACd,IAAI,CAAS,CAAC;QACd,IAAI,CAAS,CAAC;QACd,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;YACnB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;YAC7B,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;YAC5B,CAAC,GAAG,MAAM,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AAM,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,WAAW,CAAC,KAAwB,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS;IACvF,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IACjD,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { GradientSpread, BitmapRegion } from '@flighthq/types/contract';
|
|
2
|
+
/**
|
|
3
|
+
* Fills the `dest` region with a linear gradient defined by two points `(x0, y0)`
|
|
4
|
+
* and `(x1, y1)` in region-local coordinates. Each pixel's position along the
|
|
5
|
+
* gradient axis maps to a ramp index (0–255), which is looked up in the 256-entry
|
|
6
|
+
* RGBA `ramp` (1024 bytes). Build the ramp with `buildBitmapGradientRamp`.
|
|
7
|
+
*
|
|
8
|
+
* `spread` controls what happens outside the axis span:
|
|
9
|
+
* - `'pad'` (default): extends the first or last stop color.
|
|
10
|
+
* - `'repeat'`: tiles the gradient.
|
|
11
|
+
* - `'reflect'`: mirrors the gradient alternately.
|
|
12
|
+
*
|
|
13
|
+
* Pixels outside the bitmap bounds are skipped.
|
|
14
|
+
*/
|
|
15
|
+
export declare function fillBitmapLinearGradient(dest: Readonly<BitmapRegion>, ramp: Readonly<Uint8ClampedArray>, x0: number, y0: number, x1: number, y1: number, spread?: GradientSpread): void;
|
|
16
|
+
/**
|
|
17
|
+
* Fills the `dest` region with a radial gradient centered at `(cx, cy)` in
|
|
18
|
+
* region-local coordinates with the given `radius`. An optional focal point
|
|
19
|
+
* `(focalX, focalY)` shifts the gradient origin (defaults to the center).
|
|
20
|
+
* Each pixel's normalized distance maps to a ramp index (0–255), looked up in
|
|
21
|
+
* the 256-entry RGBA `ramp` (1024 bytes). Build the ramp with
|
|
22
|
+
* `buildBitmapGradientRamp`.
|
|
23
|
+
*
|
|
24
|
+
* `spread` controls what happens outside the radius:
|
|
25
|
+
* - `'pad'` (default): extends the last stop color.
|
|
26
|
+
* - `'repeat'`: tiles the gradient.
|
|
27
|
+
* - `'reflect'`: mirrors the gradient alternately.
|
|
28
|
+
*
|
|
29
|
+
* Pixels outside the bitmap bounds are skipped.
|
|
30
|
+
*/
|
|
31
|
+
export declare function fillBitmapRadialGradient(dest: Readonly<BitmapRegion>, ramp: Readonly<Uint8ClampedArray>, cx: number, cy: number, radius: number, focalX?: number, focalY?: number, spread?: GradientSpread): void;
|
|
32
|
+
//# sourceMappingURL=bitmapGradientFill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapGradientFill.d.ts","sourceRoot":"","sources":["../src/bitmapGradientFill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAI7E;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC5B,IAAI,EAAE,QAAQ,CAAC,iBAAiB,CAAC,EACjC,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,MAAM,GAAE,cAAsB,GAC7B,IAAI,CA4BN;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC5B,IAAI,EAAE,QAAQ,CAAC,iBAAiB,CAAC,EACjC,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,MAAW,EACnB,MAAM,GAAE,MAAW,EACnB,MAAM,GAAE,cAAsB,GAC7B,IAAI,CAgCN"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { invalidateBitmap } from './bitmap';
|
|
2
|
+
/**
|
|
3
|
+
* Fills the `dest` region with a linear gradient defined by two points `(x0, y0)`
|
|
4
|
+
* and `(x1, y1)` in region-local coordinates. Each pixel's position along the
|
|
5
|
+
* gradient axis maps to a ramp index (0–255), which is looked up in the 256-entry
|
|
6
|
+
* RGBA `ramp` (1024 bytes). Build the ramp with `buildBitmapGradientRamp`.
|
|
7
|
+
*
|
|
8
|
+
* `spread` controls what happens outside the axis span:
|
|
9
|
+
* - `'pad'` (default): extends the first or last stop color.
|
|
10
|
+
* - `'repeat'`: tiles the gradient.
|
|
11
|
+
* - `'reflect'`: mirrors the gradient alternately.
|
|
12
|
+
*
|
|
13
|
+
* Pixels outside the bitmap bounds are skipped.
|
|
14
|
+
*/
|
|
15
|
+
export function fillBitmapLinearGradient(dest, ramp, x0, y0, x1, y1, spread = 'pad') {
|
|
16
|
+
const dw = dest.width;
|
|
17
|
+
const dh = dest.height;
|
|
18
|
+
const data = dest.bitmap.data;
|
|
19
|
+
const bitmapWidth = dest.bitmap.width;
|
|
20
|
+
const bitmapHeight = dest.bitmap.height;
|
|
21
|
+
const axisX = x1 - x0;
|
|
22
|
+
const axisY = y1 - y0;
|
|
23
|
+
const lenSq = axisX * axisX + axisY * axisY;
|
|
24
|
+
const invLen = lenSq > 0 ? 1 / lenSq : 0;
|
|
25
|
+
for (let py = 0; py < dh; py++) {
|
|
26
|
+
const y = dest.y + py;
|
|
27
|
+
if (y < 0 || y >= bitmapHeight)
|
|
28
|
+
continue;
|
|
29
|
+
for (let px = 0; px < dw; px++) {
|
|
30
|
+
const x = dest.x + px;
|
|
31
|
+
if (x < 0 || x >= bitmapWidth)
|
|
32
|
+
continue;
|
|
33
|
+
// Project pixel onto gradient axis → t in [0, 1] maps x0→x1.
|
|
34
|
+
const t = ((px - x0) * axisX + (py - y0) * axisY) * invLen;
|
|
35
|
+
const idx = spreadIndex(t, spread);
|
|
36
|
+
const ri = idx * 4;
|
|
37
|
+
const i = (y * bitmapWidth + x) * 4;
|
|
38
|
+
data[i] = ramp[ri];
|
|
39
|
+
data[i + 1] = ramp[ri + 1];
|
|
40
|
+
data[i + 2] = ramp[ri + 2];
|
|
41
|
+
data[i + 3] = ramp[ri + 3];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
invalidateBitmap(dest.bitmap);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Fills the `dest` region with a radial gradient centered at `(cx, cy)` in
|
|
48
|
+
* region-local coordinates with the given `radius`. An optional focal point
|
|
49
|
+
* `(focalX, focalY)` shifts the gradient origin (defaults to the center).
|
|
50
|
+
* Each pixel's normalized distance maps to a ramp index (0–255), looked up in
|
|
51
|
+
* the 256-entry RGBA `ramp` (1024 bytes). Build the ramp with
|
|
52
|
+
* `buildBitmapGradientRamp`.
|
|
53
|
+
*
|
|
54
|
+
* `spread` controls what happens outside the radius:
|
|
55
|
+
* - `'pad'` (default): extends the last stop color.
|
|
56
|
+
* - `'repeat'`: tiles the gradient.
|
|
57
|
+
* - `'reflect'`: mirrors the gradient alternately.
|
|
58
|
+
*
|
|
59
|
+
* Pixels outside the bitmap bounds are skipped.
|
|
60
|
+
*/
|
|
61
|
+
export function fillBitmapRadialGradient(dest, ramp, cx, cy, radius, focalX = cx, focalY = cy, spread = 'pad') {
|
|
62
|
+
const dw = dest.width;
|
|
63
|
+
const dh = dest.height;
|
|
64
|
+
const data = dest.bitmap.data;
|
|
65
|
+
const bitmapWidth = dest.bitmap.width;
|
|
66
|
+
const bitmapHeight = dest.bitmap.height;
|
|
67
|
+
const invRadius = radius > 0 ? 1 / radius : 0;
|
|
68
|
+
// Focal-point offset from center.
|
|
69
|
+
const fdx = focalX - cx;
|
|
70
|
+
const fdy = focalY - cy;
|
|
71
|
+
for (let py = 0; py < dh; py++) {
|
|
72
|
+
const y = dest.y + py;
|
|
73
|
+
if (y < 0 || y >= bitmapHeight)
|
|
74
|
+
continue;
|
|
75
|
+
for (let px = 0; px < dw; px++) {
|
|
76
|
+
const x = dest.x + px;
|
|
77
|
+
if (x < 0 || x >= bitmapWidth)
|
|
78
|
+
continue;
|
|
79
|
+
// Distance from focal point, normalized by radius → t in [0, 1].
|
|
80
|
+
const dx = px - focalX;
|
|
81
|
+
const dy = py - focalY;
|
|
82
|
+
// Use the cone-ray formula for two-point focal gradient (standard SVG model).
|
|
83
|
+
// When focal === center this simplifies to Euclidean distance / radius.
|
|
84
|
+
const t = Math.sqrt(dx * dx + dy * dy) * invRadius - (dx * fdx + dy * fdy) * invRadius * invRadius;
|
|
85
|
+
const idx = spreadIndex(t, spread);
|
|
86
|
+
const ri = idx * 4;
|
|
87
|
+
const i = (y * bitmapWidth + x) * 4;
|
|
88
|
+
data[i] = ramp[ri];
|
|
89
|
+
data[i + 1] = ramp[ri + 1];
|
|
90
|
+
data[i + 2] = ramp[ri + 2];
|
|
91
|
+
data[i + 3] = ramp[ri + 3];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
invalidateBitmap(dest.bitmap);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Converts a normalized gradient parameter `t` (range [0, 1]) into a ramp
|
|
98
|
+
* index (0–255), applying the requested `spread` mode for values outside [0, 1].
|
|
99
|
+
*/
|
|
100
|
+
function spreadIndex(t, spread) {
|
|
101
|
+
let s;
|
|
102
|
+
switch (spread) {
|
|
103
|
+
case 'repeat': {
|
|
104
|
+
s = t - Math.floor(t);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case 'reflect': {
|
|
108
|
+
const wrapped = t - Math.floor(t / 2) * 2;
|
|
109
|
+
s = wrapped <= 1 ? wrapped : 2 - wrapped;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
default: {
|
|
113
|
+
// 'pad'
|
|
114
|
+
s = Math.max(0, Math.min(1, t));
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return Math.min(255, Math.round(s * 255));
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=bitmapGradientFill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapGradientFill.js","sourceRoot":"","sources":["../src/bitmapGradientFill.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAA4B,EAC5B,IAAiC,EACjC,EAAU,EACV,EAAU,EACV,EAAU,EACV,EAAU,EACV,SAAyB,KAAK;IAE9B,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IACtB,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;IACvB,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC9B,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IACtC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IACxC,MAAM,KAAK,GAAG,EAAE,GAAG,EAAE,CAAC;IACtB,MAAM,KAAK,GAAG,EAAE,GAAG,EAAE,CAAC;IACtB,MAAM,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IAC5C,MAAM,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;QAC/B,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,YAAY;YAAE,SAAS;QACzC,KAAK,IAAI,EAAE,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,CAAC;YAChC,MAAM;QACR,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BitmapHistogram, BitmapRegion } from '@flighthq/types/contract';
|
|
2
|
+
/**
|
|
3
|
+
* Applies histogram equalization to `source`, writing into `dest`. Each RGB
|
|
4
|
+
* channel is equalized independently using its cumulative distribution function,
|
|
5
|
+
* spreading the tonal range across the full 0..255 output. The alpha channel is
|
|
6
|
+
* copied unchanged.
|
|
7
|
+
*
|
|
8
|
+
* Safe to pass the same bitmap and region in `dest` and `source` for in-place
|
|
9
|
+
* equalization (the palette map reads each pixel before writing it).
|
|
10
|
+
*/
|
|
11
|
+
export declare function equalizeBitmapHistogram(dest: Readonly<BitmapRegion>, source: Readonly<BitmapRegion>): void;
|
|
12
|
+
/**
|
|
13
|
+
* Counts how many pixels in the `source` region fall into each 0..255 value,
|
|
14
|
+
* per channel, and returns four 256-entry arrays. Region pixels outside the
|
|
15
|
+
* bitmap are skipped; an empty region yields all-zero bins.
|
|
16
|
+
*
|
|
17
|
+
* Allocates the result arrays; this is an analysis query, not a hot-path pass.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getBitmapHistogram(source: Readonly<BitmapRegion>): BitmapHistogram;
|
|
20
|
+
//# sourceMappingURL=bitmapHistogram.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapHistogram.d.ts","sourceRoot":"","sources":["../src/bitmapHistogram.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAK9E;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI,CAa1G;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,eAAe,CAqBlF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { invalidateBitmap } from './bitmap';
|
|
2
|
+
import { applyBitmapPaletteMap } from './bitmapPaletteMap';
|
|
3
|
+
/**
|
|
4
|
+
* Applies histogram equalization to `source`, writing into `dest`. Each RGB
|
|
5
|
+
* channel is equalized independently using its cumulative distribution function,
|
|
6
|
+
* spreading the tonal range across the full 0..255 output. The alpha channel is
|
|
7
|
+
* copied unchanged.
|
|
8
|
+
*
|
|
9
|
+
* Safe to pass the same bitmap and region in `dest` and `source` for in-place
|
|
10
|
+
* equalization (the palette map reads each pixel before writing it).
|
|
11
|
+
*/
|
|
12
|
+
export function equalizeBitmapHistogram(dest, source) {
|
|
13
|
+
const histogram = getBitmapHistogram(source);
|
|
14
|
+
const total = source.width * source.height;
|
|
15
|
+
applyBitmapPaletteMap(dest, source, buildEqualizeMap(histogram.red, total), buildEqualizeMap(histogram.green, total), buildEqualizeMap(histogram.blue, total), null);
|
|
16
|
+
invalidateBitmap(dest.bitmap);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Counts how many pixels in the `source` region fall into each 0..255 value,
|
|
20
|
+
* per channel, and returns four 256-entry arrays. Region pixels outside the
|
|
21
|
+
* bitmap are skipped; an empty region yields all-zero bins.
|
|
22
|
+
*
|
|
23
|
+
* Allocates the result arrays; this is an analysis query, not a hot-path pass.
|
|
24
|
+
*/
|
|
25
|
+
export function getBitmapHistogram(source) {
|
|
26
|
+
const red = new Array(256).fill(0);
|
|
27
|
+
const green = new Array(256).fill(0);
|
|
28
|
+
const blue = new Array(256).fill(0);
|
|
29
|
+
const alpha = new Array(256).fill(0);
|
|
30
|
+
const data = source.bitmap.data;
|
|
31
|
+
const bitmapWidth = source.bitmap.width;
|
|
32
|
+
for (let py = 0; py < source.height; py++) {
|
|
33
|
+
const y = source.y + py;
|
|
34
|
+
if (y < 0 || y >= source.bitmap.height)
|
|
35
|
+
continue;
|
|
36
|
+
for (let px = 0; px < source.width; px++) {
|
|
37
|
+
const x = source.x + px;
|
|
38
|
+
if (x < 0 || x >= bitmapWidth)
|
|
39
|
+
continue;
|
|
40
|
+
const i = (y * bitmapWidth + x) * 4;
|
|
41
|
+
red[data[i]]++;
|
|
42
|
+
green[data[i + 1]]++;
|
|
43
|
+
blue[data[i + 2]]++;
|
|
44
|
+
alpha[data[i + 3]]++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return { alpha, blue, green, red };
|
|
48
|
+
}
|
|
49
|
+
function buildEqualizeMap(bins, total) {
|
|
50
|
+
const map = new Array(256);
|
|
51
|
+
let cdf = 0;
|
|
52
|
+
let cdfMin = -1;
|
|
53
|
+
for (let i = 0; i < 256; i++) {
|
|
54
|
+
cdf += bins[i];
|
|
55
|
+
if (bins[i] > 0 && cdfMin === -1)
|
|
56
|
+
cdfMin = cdf;
|
|
57
|
+
map[i] = total === cdfMin ? i : Math.round(((cdf - cdfMin) / (total - cdfMin)) * 255);
|
|
58
|
+
}
|
|
59
|
+
return map;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=bitmapHistogram.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapHistogram.js","sourceRoot":"","sources":["../src/bitmapHistogram.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAA4B,EAAE,MAA8B;IAClG,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC;IAE3C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;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapImageChannel.d.ts","sourceRoot":"","sources":["../src/bitmapImageChannel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapImageChannel.js","sourceRoot":"","sources":["../src/bitmapImageChannel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BitmapRegion } from '@flighthq/types/contract';
|
|
2
|
+
/**
|
|
3
|
+
* Applies a median filter to `source`, writing into `out`. Each output channel
|
|
4
|
+
* is the median of that channel over the `(2 * radius + 1)²` neighborhood,
|
|
5
|
+
* clamped at the bitmap edges. Median filtering removes salt-and-pepper noise
|
|
6
|
+
* and despeckles while preserving edges — something a linear convolution blur
|
|
7
|
+
* cannot do.
|
|
8
|
+
*
|
|
9
|
+
* `out` must be at least `source.width * source.height * 4` bytes and must NOT
|
|
10
|
+
* alias `source.bitmap.data` — each output pixel reads a neighborhood of
|
|
11
|
+
* source pixels.
|
|
12
|
+
*/
|
|
13
|
+
export declare function medianBitmap(out: Uint8ClampedArray, source: Readonly<BitmapRegion>, radius: number): void;
|
|
14
|
+
//# sourceMappingURL=bitmapMedian.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapMedian.d.ts","sourceRoot":"","sources":["../src/bitmapMedian.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CA4CzG"}
|