@flighthq/surface 0.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.
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/surface.d.ts +16 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +84 -0
- package/dist/surface.js.map +1 -0
- package/dist/surfaceAffine.d.ts +27 -0
- package/dist/surfaceAffine.d.ts.map +1 -0
- package/dist/surfaceAffine.js +159 -0
- package/dist/surfaceAffine.js.map +1 -0
- package/dist/surfaceAlpha.d.ts +27 -0
- package/dist/surfaceAlpha.d.ts.map +1 -0
- package/dist/surfaceAlpha.js +83 -0
- package/dist/surfaceAlpha.js.map +1 -0
- package/dist/surfaceBevel.d.ts +42 -0
- package/dist/surfaceBevel.d.ts.map +1 -0
- package/dist/surfaceBevel.js +102 -0
- package/dist/surfaceBevel.js.map +1 -0
- package/dist/surfaceBlur.d.ts +62 -0
- package/dist/surfaceBlur.d.ts.map +1 -0
- package/dist/surfaceBlur.js +263 -0
- package/dist/surfaceBlur.js.map +1 -0
- package/dist/surfaceChannel.d.ts +24 -0
- package/dist/surfaceChannel.d.ts.map +1 -0
- package/dist/surfaceChannel.js +126 -0
- package/dist/surfaceChannel.js.map +1 -0
- package/dist/surfaceColorMatrix.d.ts +57 -0
- package/dist/surfaceColorMatrix.d.ts.map +1 -0
- package/dist/surfaceColorMatrix.js +127 -0
- package/dist/surfaceColorMatrix.js.map +1 -0
- package/dist/surfaceCompare.d.ts +18 -0
- package/dist/surfaceCompare.d.ts.map +1 -0
- package/dist/surfaceCompare.js +64 -0
- package/dist/surfaceCompare.js.map +1 -0
- package/dist/surfaceComposite.d.ts +53 -0
- package/dist/surfaceComposite.d.ts.map +1 -0
- package/dist/surfaceComposite.js +230 -0
- package/dist/surfaceComposite.js.map +1 -0
- package/dist/surfaceConvolution.d.ts +27 -0
- package/dist/surfaceConvolution.d.ts.map +1 -0
- package/dist/surfaceConvolution.js +103 -0
- package/dist/surfaceConvolution.js.map +1 -0
- package/dist/surfaceCopy.d.ts +23 -0
- package/dist/surfaceCopy.d.ts.map +1 -0
- package/dist/surfaceCopy.js +78 -0
- package/dist/surfaceCopy.js.map +1 -0
- package/dist/surfaceCoverage.d.ts +11 -0
- package/dist/surfaceCoverage.d.ts.map +1 -0
- package/dist/surfaceCoverage.js +29 -0
- package/dist/surfaceCoverage.js.map +1 -0
- package/dist/surfaceCrop.d.ts +33 -0
- package/dist/surfaceCrop.d.ts.map +1 -0
- package/dist/surfaceCrop.js +174 -0
- package/dist/surfaceCrop.js.map +1 -0
- package/dist/surfaceDisplacement.d.ts +48 -0
- package/dist/surfaceDisplacement.d.ts.map +1 -0
- package/dist/surfaceDisplacement.js +131 -0
- package/dist/surfaceDisplacement.js.map +1 -0
- package/dist/surfaceDissolve.d.ts +21 -0
- package/dist/surfaceDissolve.d.ts.map +1 -0
- package/dist/surfaceDissolve.js +97 -0
- package/dist/surfaceDissolve.js.map +1 -0
- package/dist/surfaceDraw.d.ts +8 -0
- package/dist/surfaceDraw.d.ts.map +1 -0
- package/dist/surfaceDraw.js +14 -0
- package/dist/surfaceDraw.js.map +1 -0
- package/dist/surfaceEncode.d.ts +3 -0
- package/dist/surfaceEncode.d.ts.map +1 -0
- package/dist/surfaceEncode.js +18 -0
- package/dist/surfaceEncode.js.map +1 -0
- package/dist/surfaceFill.d.ts +12 -0
- package/dist/surfaceFill.d.ts.map +1 -0
- package/dist/surfaceFill.js +85 -0
- package/dist/surfaceFill.js.map +1 -0
- package/dist/surfaceFingerprint.d.ts +26 -0
- package/dist/surfaceFingerprint.d.ts.map +1 -0
- package/dist/surfaceFingerprint.js +99 -0
- package/dist/surfaceFingerprint.js.map +1 -0
- package/dist/surfaceFlip.d.ts +16 -0
- package/dist/surfaceFlip.d.ts.map +1 -0
- package/dist/surfaceFlip.js +98 -0
- package/dist/surfaceFlip.js.map +1 -0
- package/dist/surfaceFormat.d.ts +26 -0
- package/dist/surfaceFormat.d.ts.map +1 -0
- package/dist/surfaceFormat.js +80 -0
- package/dist/surfaceFormat.js.map +1 -0
- package/dist/surfaceFrom.d.ts +14 -0
- package/dist/surfaceFrom.d.ts.map +1 -0
- package/dist/surfaceFrom.js +87 -0
- package/dist/surfaceFrom.js.map +1 -0
- package/dist/surfaceGradient.d.ts +57 -0
- package/dist/surfaceGradient.d.ts.map +1 -0
- package/dist/surfaceGradient.js +176 -0
- package/dist/surfaceGradient.js.map +1 -0
- package/dist/surfaceGradientFill.d.ts +32 -0
- package/dist/surfaceGradientFill.d.ts.map +1 -0
- package/dist/surfaceGradientFill.js +120 -0
- package/dist/surfaceGradientFill.js.map +1 -0
- package/dist/surfaceHistogram.d.ts +20 -0
- package/dist/surfaceHistogram.d.ts.map +1 -0
- package/dist/surfaceHistogram.js +61 -0
- package/dist/surfaceHistogram.js.map +1 -0
- package/dist/surfaceImageChannel.d.ts +2 -0
- package/dist/surfaceImageChannel.d.ts.map +1 -0
- package/dist/surfaceImageChannel.js +2 -0
- package/dist/surfaceImageChannel.js.map +1 -0
- package/dist/surfaceMedian.d.ts +14 -0
- package/dist/surfaceMedian.d.ts.map +1 -0
- package/dist/surfaceMedian.js +77 -0
- package/dist/surfaceMedian.js.map +1 -0
- package/dist/surfaceMorphological.d.ts +29 -0
- package/dist/surfaceMorphological.d.ts.map +1 -0
- package/dist/surfaceMorphological.js +81 -0
- package/dist/surfaceMorphological.js.map +1 -0
- package/dist/surfaceNoise.d.ts +48 -0
- package/dist/surfaceNoise.d.ts.map +1 -0
- package/dist/surfaceNoise.js +245 -0
- package/dist/surfaceNoise.js.map +1 -0
- package/dist/surfacePaletteMap.d.ts +17 -0
- package/dist/surfacePaletteMap.d.ts.map +1 -0
- package/dist/surfacePaletteMap.js +45 -0
- package/dist/surfacePaletteMap.js.map +1 -0
- package/dist/surfacePixel.d.ts +9 -0
- package/dist/surfacePixel.d.ts.map +1 -0
- package/dist/surfacePixel.js +36 -0
- package/dist/surfacePixel.js.map +1 -0
- package/dist/surfacePixelate.d.ts +13 -0
- package/dist/surfacePixelate.d.ts.map +1 -0
- package/dist/surfacePixelate.js +61 -0
- package/dist/surfacePixelate.js.map +1 -0
- package/dist/surfaceQuery.d.ts +13 -0
- package/dist/surfaceQuery.d.ts.map +1 -0
- package/dist/surfaceQuery.js +46 -0
- package/dist/surfaceQuery.js.map +1 -0
- package/dist/surfaceRegion.d.ts +20 -0
- package/dist/surfaceRegion.d.ts.map +1 -0
- package/dist/surfaceRegion.js +28 -0
- package/dist/surfaceRegion.js.map +1 -0
- package/dist/surfaceResize.d.ts +27 -0
- package/dist/surfaceResize.d.ts.map +1 -0
- package/dist/surfaceResize.js +191 -0
- package/dist/surfaceResize.js.map +1 -0
- package/dist/surfaceRotate.d.ts +32 -0
- package/dist/surfaceRotate.d.ts.map +1 -0
- package/dist/surfaceRotate.js +143 -0
- package/dist/surfaceRotate.js.map +1 -0
- package/dist/surfaceShadow.d.ts +107 -0
- package/dist/surfaceShadow.d.ts.map +1 -0
- package/dist/surfaceShadow.js +173 -0
- package/dist/surfaceShadow.js.map +1 -0
- package/dist/surfaceSharpen.d.ts +25 -0
- package/dist/surfaceSharpen.d.ts.map +1 -0
- package/dist/surfaceSharpen.js +47 -0
- package/dist/surfaceSharpen.js.map +1 -0
- package/dist/surfaceTone.d.ts +28 -0
- package/dist/surfaceTone.d.ts.map +1 -0
- package/dist/surfaceTone.js +69 -0
- package/dist/surfaceTone.js.map +1 -0
- package/dist/surfaceTransform.d.ts +40 -0
- package/dist/surfaceTransform.d.ts.map +1 -0
- package/dist/surfaceTransform.js +163 -0
- package/dist/surfaceTransform.js.map +1 -0
- package/dist/surfaceWarp.d.ts +48 -0
- package/dist/surfaceWarp.d.ts.map +1 -0
- package/dist/surfaceWarp.js +284 -0
- package/dist/surfaceWarp.js.map +1 -0
- package/package.json +39 -0
- package/src/surface.test.ts +78 -0
- package/src/surfaceAffine.test.ts +98 -0
- package/src/surfaceAlpha.test.ts +113 -0
- package/src/surfaceBevel.test.ts +67 -0
- package/src/surfaceBlur.test.ts +240 -0
- package/src/surfaceChannel.test.ts +97 -0
- package/src/surfaceColorMatrix.test.ts +220 -0
- package/src/surfaceCompare.test.ts +92 -0
- package/src/surfaceComposite.test.ts +256 -0
- package/src/surfaceConvolution.test.ts +136 -0
- package/src/surfaceCopy.test.ts +54 -0
- package/src/surfaceCoverage.test.ts +39 -0
- package/src/surfaceCrop.test.ts +116 -0
- package/src/surfaceDisplacement.test.ts +142 -0
- package/src/surfaceDissolve.test.ts +99 -0
- package/src/surfaceDraw.test.ts +38 -0
- package/src/surfaceEncode.test.ts +18 -0
- package/src/surfaceFill.test.ts +89 -0
- package/src/surfaceFingerprint.test.ts +103 -0
- package/src/surfaceFlip.test.ts +59 -0
- package/src/surfaceFormat.test.ts +124 -0
- package/src/surfaceFrom.test.ts +62 -0
- package/src/surfaceGradient.test.ts +91 -0
- package/src/surfaceGradientFill.test.ts +107 -0
- package/src/surfaceHistogram.test.ts +70 -0
- package/src/surfaceImageChannel.test.ts +19 -0
- package/src/surfaceMedian.test.ts +45 -0
- package/src/surfaceMorphological.test.ts +75 -0
- package/src/surfaceNoise.test.ts +169 -0
- package/src/surfacePaletteMap.test.ts +55 -0
- package/src/surfacePixel.test.ts +99 -0
- package/src/surfacePixelate.test.ts +46 -0
- package/src/surfaceQuery.test.ts +48 -0
- package/src/surfaceRegion.test.ts +34 -0
- package/src/surfaceResize.test.ts +112 -0
- package/src/surfaceRotate.test.ts +119 -0
- package/src/surfaceShadow.test.ts +165 -0
- package/src/surfaceSharpen.test.ts +50 -0
- package/src/surfaceTone.test.ts +104 -0
- package/src/surfaceTransform.test.ts +134 -0
- package/src/surfaceWarp.test.ts +124 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SurfaceEdgeMode, SurfaceRegion, SurfaceResizeMode } from '@flighthq/types';
|
|
2
|
+
export interface SurfaceResizeOptions {
|
|
3
|
+
mode?: SurfaceResizeMode;
|
|
4
|
+
edgeMode?: SurfaceEdgeMode;
|
|
5
|
+
/**
|
|
6
|
+
* When true, pre-multiplies alpha before interpolation and unpremultiplies
|
|
7
|
+
* after. This prevents the dark-halo bleed that bilinear and bicubic sampling
|
|
8
|
+
* produce at semi-transparent edges when blending in straight-alpha space.
|
|
9
|
+
*/
|
|
10
|
+
premultiplied?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resamples the `source` region into the `dest` region; `dest`'s dimensions
|
|
14
|
+
* define the target size. Modes:
|
|
15
|
+
* - `'nearest'`: fast, preserves hard edges (pixel art)
|
|
16
|
+
* - `'bilinear'` (default): smooth, interpolates four surrounding pixels
|
|
17
|
+
* - `'bicubic'`: high quality, Catmull-Rom interpolation over 4×4 neighbourhood
|
|
18
|
+
*
|
|
19
|
+
* `edgeMode` controls how boundary interpolation handles out-of-bounds
|
|
20
|
+
* coordinates (default `'clamp'`).
|
|
21
|
+
*
|
|
22
|
+
* Set `premultiplied: true` to avoid dark-halo bleed at transparent edges.
|
|
23
|
+
*
|
|
24
|
+
* `dest` must not alias `source` — output pixels read arbitrary source positions.
|
|
25
|
+
*/
|
|
26
|
+
export declare function resizeSurface(dest: Readonly<SurfaceRegion>, source: Readonly<SurfaceRegion>, options?: SurfaceResizeMode | Readonly<SurfaceResizeOptions>): void;
|
|
27
|
+
//# sourceMappingURL=surfaceResize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surfaceResize.d.ts","sourceRoot":"","sources":["../src/surfaceResize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzF,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,QAAQ,CAAC,aAAa,CAAC,EAC7B,MAAM,EAAE,QAAQ,CAAC,aAAa,CAAC,EAC/B,OAAO,GAAE,iBAAiB,GAAG,QAAQ,CAAC,oBAAoB,CAAc,GACvE,IAAI,CA8IN"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { invalidateImageResource } from '@flighthq/image';
|
|
2
|
+
/**
|
|
3
|
+
* Resamples the `source` region into the `dest` region; `dest`'s dimensions
|
|
4
|
+
* define the target size. Modes:
|
|
5
|
+
* - `'nearest'`: fast, preserves hard edges (pixel art)
|
|
6
|
+
* - `'bilinear'` (default): smooth, interpolates four surrounding pixels
|
|
7
|
+
* - `'bicubic'`: high quality, Catmull-Rom interpolation over 4×4 neighbourhood
|
|
8
|
+
*
|
|
9
|
+
* `edgeMode` controls how boundary interpolation handles out-of-bounds
|
|
10
|
+
* coordinates (default `'clamp'`).
|
|
11
|
+
*
|
|
12
|
+
* Set `premultiplied: true` to avoid dark-halo bleed at transparent edges.
|
|
13
|
+
*
|
|
14
|
+
* `dest` must not alias `source` — output pixels read arbitrary source positions.
|
|
15
|
+
*/
|
|
16
|
+
export function resizeSurface(dest, source, options = 'bilinear') {
|
|
17
|
+
const opts = typeof options === 'string' ? { mode: options } : options;
|
|
18
|
+
const mode = opts.mode ?? 'bilinear';
|
|
19
|
+
const edgeMode = opts.edgeMode ?? 'clamp';
|
|
20
|
+
const premultiplied = opts.premultiplied ?? false;
|
|
21
|
+
const sw = source.width;
|
|
22
|
+
const sh = source.height;
|
|
23
|
+
const dw = dest.width;
|
|
24
|
+
const dh = dest.height;
|
|
25
|
+
if (sw === 0 || sh === 0 || dw === 0 || dh === 0)
|
|
26
|
+
return;
|
|
27
|
+
const sd = source.surface.data;
|
|
28
|
+
const dd = dest.surface.data;
|
|
29
|
+
const sStride = source.surface.width;
|
|
30
|
+
const dStride = dest.surface.width;
|
|
31
|
+
if (mode === 'nearest') {
|
|
32
|
+
for (let dy = 0; dy < dh; dy++) {
|
|
33
|
+
const oy = dest.y + dy;
|
|
34
|
+
if (oy < 0 || oy >= dest.surface.height)
|
|
35
|
+
continue;
|
|
36
|
+
const sy = source.y + Math.min(sh - 1, Math.floor((dy * sh) / dh));
|
|
37
|
+
if (sy < 0 || sy >= source.surface.height)
|
|
38
|
+
continue;
|
|
39
|
+
for (let dx = 0; dx < dw; dx++) {
|
|
40
|
+
const ox = dest.x + dx;
|
|
41
|
+
if (ox < 0 || ox >= dStride)
|
|
42
|
+
continue;
|
|
43
|
+
const sx = source.x + Math.min(sw - 1, Math.floor((dx * sw) / dw));
|
|
44
|
+
if (sx < 0 || sx >= sStride)
|
|
45
|
+
continue;
|
|
46
|
+
const si = (sy * sStride + sx) * 4;
|
|
47
|
+
const di = (oy * dStride + ox) * 4;
|
|
48
|
+
dd[di] = sd[si];
|
|
49
|
+
dd[di + 1] = sd[si + 1];
|
|
50
|
+
dd[di + 2] = sd[si + 2];
|
|
51
|
+
dd[di + 3] = sd[si + 3];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const scaleX = sw / dw;
|
|
57
|
+
const scaleY = sh / dh;
|
|
58
|
+
if (mode === 'bicubic') {
|
|
59
|
+
for (let dy = 0; dy < dh; dy++) {
|
|
60
|
+
const oy = dest.y + dy;
|
|
61
|
+
if (oy < 0 || oy >= dest.surface.height)
|
|
62
|
+
continue;
|
|
63
|
+
const fy = (dy + 0.5) * scaleY - 0.5;
|
|
64
|
+
const y1 = Math.floor(fy);
|
|
65
|
+
const ty = fy - y1;
|
|
66
|
+
for (let dx = 0; dx < dw; dx++) {
|
|
67
|
+
const ox = dest.x + dx;
|
|
68
|
+
if (ox < 0 || ox >= dStride)
|
|
69
|
+
continue;
|
|
70
|
+
const fx = (dx + 0.5) * scaleX - 0.5;
|
|
71
|
+
const x1 = Math.floor(fx);
|
|
72
|
+
const tx = fx - x1;
|
|
73
|
+
const di = (oy * dStride + ox) * 4;
|
|
74
|
+
for (let c = 0; c < 4; c++) {
|
|
75
|
+
let sum = 0;
|
|
76
|
+
for (let m = -1; m <= 2; m++) {
|
|
77
|
+
const wy = catmullRomWeight(ty - m);
|
|
78
|
+
const ry = resolveResizeEdge(y1 + m, sh, edgeMode);
|
|
79
|
+
for (let n = -1; n <= 2; n++) {
|
|
80
|
+
const wx = catmullRomWeight(tx - n);
|
|
81
|
+
const rx = resolveResizeEdge(x1 + n, sw, edgeMode);
|
|
82
|
+
if (rx === null || ry === null)
|
|
83
|
+
continue;
|
|
84
|
+
const sy = source.y + ry;
|
|
85
|
+
const sx = source.x + rx;
|
|
86
|
+
const si = (sy * sStride + sx) * 4;
|
|
87
|
+
const v = premultiplied && c < 3 ? (sd[si + c] * sd[si + 3]) / 255 : sd[si + c];
|
|
88
|
+
sum += v * wy * wx;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
dd[di + c] = Math.max(0, Math.min(255, Math.round(sum)));
|
|
92
|
+
}
|
|
93
|
+
if (premultiplied) {
|
|
94
|
+
const a = dd[di + 3];
|
|
95
|
+
if (a > 0) {
|
|
96
|
+
dd[di] = Math.min(255, Math.round((dd[di] * 255) / a));
|
|
97
|
+
dd[di + 1] = Math.min(255, Math.round((dd[di + 1] * 255) / a));
|
|
98
|
+
dd[di + 2] = Math.min(255, Math.round((dd[di + 2] * 255) / a));
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
dd[di] = 0;
|
|
102
|
+
dd[di + 1] = 0;
|
|
103
|
+
dd[di + 2] = 0;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// bilinear
|
|
111
|
+
for (let dy = 0; dy < dh; dy++) {
|
|
112
|
+
const oy = dest.y + dy;
|
|
113
|
+
if (oy < 0 || oy >= dest.surface.height)
|
|
114
|
+
continue;
|
|
115
|
+
const fy = (dy + 0.5) * scaleY - 0.5;
|
|
116
|
+
const y0 = Math.floor(fy);
|
|
117
|
+
const ty = fy - y0;
|
|
118
|
+
const ry0 = resolveResizeEdge(y0, sh, edgeMode);
|
|
119
|
+
const ry1 = resolveResizeEdge(y0 + 1, sh, edgeMode);
|
|
120
|
+
for (let dx = 0; dx < dw; dx++) {
|
|
121
|
+
const ox = dest.x + dx;
|
|
122
|
+
if (ox < 0 || ox >= dStride)
|
|
123
|
+
continue;
|
|
124
|
+
const fx = (dx + 0.5) * scaleX - 0.5;
|
|
125
|
+
const x0 = Math.floor(fx);
|
|
126
|
+
const tx = fx - x0;
|
|
127
|
+
const rx0 = resolveResizeEdge(x0, sw, edgeMode);
|
|
128
|
+
const rx1 = resolveResizeEdge(x0 + 1, sw, edgeMode);
|
|
129
|
+
const di = (oy * dStride + ox) * 4;
|
|
130
|
+
const i00 = rx0 !== null && ry0 !== null ? ((source.y + ry0) * sStride + source.x + rx0) * 4 : -1;
|
|
131
|
+
const i10 = rx1 !== null && ry0 !== null ? ((source.y + ry0) * sStride + source.x + rx1) * 4 : -1;
|
|
132
|
+
const i01 = rx0 !== null && ry1 !== null ? ((source.y + ry1) * sStride + source.x + rx0) * 4 : -1;
|
|
133
|
+
const i11 = rx1 !== null && ry1 !== null ? ((source.y + ry1) * sStride + source.x + rx1) * 4 : -1;
|
|
134
|
+
for (let c = 0; c < 4; c++) {
|
|
135
|
+
let v00 = i00 >= 0 ? sd[i00 + c] : 0;
|
|
136
|
+
let v10 = i10 >= 0 ? sd[i10 + c] : 0;
|
|
137
|
+
let v01 = i01 >= 0 ? sd[i01 + c] : 0;
|
|
138
|
+
let v11 = i11 >= 0 ? sd[i11 + c] : 0;
|
|
139
|
+
if (premultiplied && c < 3) {
|
|
140
|
+
v00 = i00 >= 0 ? (v00 * sd[i00 + 3]) / 255 : 0;
|
|
141
|
+
v10 = i10 >= 0 ? (v10 * sd[i10 + 3]) / 255 : 0;
|
|
142
|
+
v01 = i01 >= 0 ? (v01 * sd[i01 + 3]) / 255 : 0;
|
|
143
|
+
v11 = i11 >= 0 ? (v11 * sd[i11 + 3]) / 255 : 0;
|
|
144
|
+
}
|
|
145
|
+
const top = v00 * (1 - tx) + v10 * tx;
|
|
146
|
+
const bottom = v01 * (1 - tx) + v11 * tx;
|
|
147
|
+
dd[di + c] = Math.round(top * (1 - ty) + bottom * ty);
|
|
148
|
+
}
|
|
149
|
+
if (premultiplied) {
|
|
150
|
+
const a = dd[di + 3];
|
|
151
|
+
if (a > 0) {
|
|
152
|
+
dd[di] = Math.min(255, Math.round((dd[di] * 255) / a));
|
|
153
|
+
dd[di + 1] = Math.min(255, Math.round((dd[di + 1] * 255) / a));
|
|
154
|
+
dd[di + 2] = Math.min(255, Math.round((dd[di + 2] * 255) / a));
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
dd[di] = 0;
|
|
158
|
+
dd[di + 1] = 0;
|
|
159
|
+
dd[di + 2] = 0;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
invalidateImageResource(dest.surface);
|
|
165
|
+
}
|
|
166
|
+
function catmullRomWeight(t) {
|
|
167
|
+
const a = Math.abs(t);
|
|
168
|
+
if (a >= 2)
|
|
169
|
+
return 0;
|
|
170
|
+
if (a >= 1)
|
|
171
|
+
return -0.5 * a * a * a + 2.5 * a * a - 4 * a + 2;
|
|
172
|
+
return 1.5 * a * a * a - 2.5 * a * a + 1;
|
|
173
|
+
}
|
|
174
|
+
function resolveResizeEdge(v, size, mode) {
|
|
175
|
+
if (v >= 0 && v < size)
|
|
176
|
+
return v;
|
|
177
|
+
switch (mode) {
|
|
178
|
+
case 'clamp':
|
|
179
|
+
return Math.max(0, Math.min(size - 1, v));
|
|
180
|
+
case 'wrap':
|
|
181
|
+
return ((v % size) + size) % size;
|
|
182
|
+
case 'mirror': {
|
|
183
|
+
const period = 2 * size;
|
|
184
|
+
const wrapped = ((v % period) + period) % period;
|
|
185
|
+
return wrapped < size ? wrapped : period - 1 - wrapped;
|
|
186
|
+
}
|
|
187
|
+
default:
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=surfaceResize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surfaceResize.js","sourceRoot":"","sources":["../src/surfaceResize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAc1D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAC3B,IAA6B,EAC7B,MAA+B,EAC/B,UAA8D,UAAU;IAExE,MAAM,IAAI,GAAmC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IACvG,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,UAAU,CAAC;IACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC;IAC1C,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,KAAK,CAAC;IAElD,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC;IACxB,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC;IACzB,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;IACtB,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;IACvB,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;QAAE,OAAO;IACzD,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/B,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC7B,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAA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AAM,CAAC,GAAG,MAAM,CAAC;YACjD,OAAO,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC;QACzD,CAAC;QACD;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { SurfaceEdgeMode, SurfaceRegion, SurfaceResizeMode } from '@flighthq/types';
|
|
2
|
+
/**
|
|
3
|
+
* Rotates the `source` region by `angle` radians into the `dest` region, around
|
|
4
|
+
* a pivot point in source coordinates. `pivotX` and `pivotY` default to the
|
|
5
|
+
* source region centre. `edgeMode` controls out-of-bounds source positions
|
|
6
|
+
* (default `'clamp'`). `sampleMode` controls interpolation quality (default
|
|
7
|
+
* `'bilinear'`).
|
|
8
|
+
*
|
|
9
|
+
* `dest` must not alias `source`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function rotateSurface(dest: Readonly<SurfaceRegion>, source: Readonly<SurfaceRegion>, angle: number, pivotX?: number, pivotY?: number, edgeMode?: SurfaceEdgeMode, sampleMode?: SurfaceResizeMode): void;
|
|
12
|
+
/**
|
|
13
|
+
* Rotates the `source` region 180° into the `dest` region. `dest` and `source`
|
|
14
|
+
* must have the same dimensions. Safe to pass the same surface and region in
|
|
15
|
+
* `dest` and `source` for an in-place rotation — when aliased, opposite pixels
|
|
16
|
+
* are swapped in pairs; otherwise the regions must not overlap.
|
|
17
|
+
*/
|
|
18
|
+
export declare function rotateSurface180(dest: Readonly<SurfaceRegion>, source: Readonly<SurfaceRegion>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Rotates the `source` region 90° clockwise into the `dest` region. `dest`'s
|
|
21
|
+
* dimensions must be swapped relative to `source` (`dest.width === source.height`,
|
|
22
|
+
* `dest.height === source.width`). `dest` must not alias `source`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function rotateSurfaceClockwise(dest: Readonly<SurfaceRegion>, source: Readonly<SurfaceRegion>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Rotates the `source` region 90° counter-clockwise into the `dest` region.
|
|
27
|
+
* `dest`'s dimensions must be swapped relative to `source`
|
|
28
|
+
* (`dest.width === source.height`, `dest.height === source.width`). `dest` must
|
|
29
|
+
* not alias `source`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function rotateSurfaceCounterClockwise(dest: Readonly<SurfaceRegion>, source: Readonly<SurfaceRegion>): void;
|
|
32
|
+
//# sourceMappingURL=surfaceRotate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surfaceRotate.d.ts","sourceRoot":"","sources":["../src/surfaceRotate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAIzF;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,QAAQ,CAAC,aAAa,CAAC,EAC7B,MAAM,EAAE,QAAQ,CAAC,aAAa,CAAC,EAC/B,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAA+B,EACvC,MAAM,GAAE,MAAgC,EACxC,QAAQ,GAAE,eAAyB,EACnC,UAAU,GAAE,iBAA8B,GACzC,IAAI,CAQN;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,IAAI,CAkCrG;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,IAAI,CAoB3G;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,aAAa,CAAC,GAAG,IAAI,CAoBlH"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { invalidateImageResource } from '@flighthq/image';
|
|
2
|
+
import { transformSurface } from './surfaceAffine';
|
|
3
|
+
/**
|
|
4
|
+
* Rotates the `source` region by `angle` radians into the `dest` region, around
|
|
5
|
+
* a pivot point in source coordinates. `pivotX` and `pivotY` default to the
|
|
6
|
+
* source region centre. `edgeMode` controls out-of-bounds source positions
|
|
7
|
+
* (default `'clamp'`). `sampleMode` controls interpolation quality (default
|
|
8
|
+
* `'bilinear'`).
|
|
9
|
+
*
|
|
10
|
+
* `dest` must not alias `source`.
|
|
11
|
+
*/
|
|
12
|
+
export function rotateSurface(dest, source, angle, pivotX = (source.width - 1) / 2, pivotY = (source.height - 1) / 2, edgeMode = 'clamp', sampleMode = 'bilinear') {
|
|
13
|
+
const cosA = Math.cos(-angle);
|
|
14
|
+
const sinA = Math.sin(-angle);
|
|
15
|
+
const destPivotX = (dest.width - 1) / 2;
|
|
16
|
+
const destPivotY = (dest.height - 1) / 2;
|
|
17
|
+
const e = pivotX - cosA * destPivotX + sinA * destPivotY;
|
|
18
|
+
const f = pivotY - sinA * destPivotX - cosA * destPivotY;
|
|
19
|
+
transformSurface(dest, source, [cosA, sinA, -sinA, cosA, e, f], edgeMode, sampleMode);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Rotates the `source` region 180° into the `dest` region. `dest` and `source`
|
|
23
|
+
* must have the same dimensions. Safe to pass the same surface and region in
|
|
24
|
+
* `dest` and `source` for an in-place rotation — when aliased, opposite pixels
|
|
25
|
+
* are swapped in pairs; otherwise the regions must not overlap.
|
|
26
|
+
*/
|
|
27
|
+
export function rotateSurface180(dest, source) {
|
|
28
|
+
const w = Math.min(dest.width, source.width);
|
|
29
|
+
const h = Math.min(dest.height, source.height);
|
|
30
|
+
if (isSameRegion(dest, source)) {
|
|
31
|
+
const data = dest.surface.data;
|
|
32
|
+
const stride = dest.surface.width;
|
|
33
|
+
const total = w * h;
|
|
34
|
+
const half = total >> 1;
|
|
35
|
+
for (let k = 0; k < half; k++) {
|
|
36
|
+
const ax = dest.x + (k % w);
|
|
37
|
+
const ay = dest.y + Math.floor(k / w);
|
|
38
|
+
const bx = dest.x + (w - 1 - (k % w));
|
|
39
|
+
const by = dest.y + (h - 1 - Math.floor(k / w));
|
|
40
|
+
if (!inBounds(ax, ay, stride, dest.surface.height) || !inBounds(bx, by, stride, dest.surface.height))
|
|
41
|
+
continue;
|
|
42
|
+
swapPixels(data, (ay * stride + ax) * 4, (by * stride + bx) * 4);
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const sd = source.surface.data;
|
|
47
|
+
const dd = dest.surface.data;
|
|
48
|
+
const sStride = source.surface.width;
|
|
49
|
+
const dStride = dest.surface.width;
|
|
50
|
+
for (let py = 0; py < h; py++) {
|
|
51
|
+
const sy = source.y + (h - 1 - py);
|
|
52
|
+
const dy = dest.y + py;
|
|
53
|
+
if (!inBounds(0, sy, sStride, source.surface.height) || !inBounds(0, dy, dStride, dest.surface.height))
|
|
54
|
+
continue;
|
|
55
|
+
for (let px = 0; px < w; px++) {
|
|
56
|
+
const sx = source.x + (w - 1 - px);
|
|
57
|
+
const dx = dest.x + px;
|
|
58
|
+
if (sx < 0 || sx >= sStride || dx < 0 || dx >= dStride)
|
|
59
|
+
continue;
|
|
60
|
+
copyPixel(dd, (dy * dStride + dx) * 4, sd, (sy * sStride + sx) * 4);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
invalidateImageResource(dest.surface);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Rotates the `source` region 90° clockwise into the `dest` region. `dest`'s
|
|
67
|
+
* dimensions must be swapped relative to `source` (`dest.width === source.height`,
|
|
68
|
+
* `dest.height === source.width`). `dest` must not alias `source`.
|
|
69
|
+
*/
|
|
70
|
+
export function rotateSurfaceClockwise(dest, source) {
|
|
71
|
+
const sw = source.width;
|
|
72
|
+
const sh = source.height;
|
|
73
|
+
const sd = source.surface.data;
|
|
74
|
+
const dd = dest.surface.data;
|
|
75
|
+
const sStride = source.surface.width;
|
|
76
|
+
const dStride = dest.surface.width;
|
|
77
|
+
for (let py = 0; py < sh; py++) {
|
|
78
|
+
const sy = source.y + py;
|
|
79
|
+
if (sy < 0 || sy >= source.surface.height)
|
|
80
|
+
continue;
|
|
81
|
+
for (let px = 0; px < sw; px++) {
|
|
82
|
+
const sx = source.x + px;
|
|
83
|
+
if (sx < 0 || sx >= sStride)
|
|
84
|
+
continue;
|
|
85
|
+
const dx = dest.x + (sh - 1 - py);
|
|
86
|
+
const dy = dest.y + px;
|
|
87
|
+
if (dx < 0 || dx >= dStride || dy < 0 || dy >= dest.surface.height)
|
|
88
|
+
continue;
|
|
89
|
+
copyPixel(dd, (dy * dStride + dx) * 4, sd, (sy * sStride + sx) * 4);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
invalidateImageResource(dest.surface);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Rotates the `source` region 90° counter-clockwise into the `dest` region.
|
|
96
|
+
* `dest`'s dimensions must be swapped relative to `source`
|
|
97
|
+
* (`dest.width === source.height`, `dest.height === source.width`). `dest` must
|
|
98
|
+
* not alias `source`.
|
|
99
|
+
*/
|
|
100
|
+
export function rotateSurfaceCounterClockwise(dest, source) {
|
|
101
|
+
const sw = source.width;
|
|
102
|
+
const sh = source.height;
|
|
103
|
+
const sd = source.surface.data;
|
|
104
|
+
const dd = dest.surface.data;
|
|
105
|
+
const sStride = source.surface.width;
|
|
106
|
+
const dStride = dest.surface.width;
|
|
107
|
+
for (let py = 0; py < sh; py++) {
|
|
108
|
+
const sy = source.y + py;
|
|
109
|
+
if (sy < 0 || sy >= source.surface.height)
|
|
110
|
+
continue;
|
|
111
|
+
for (let px = 0; px < sw; px++) {
|
|
112
|
+
const sx = source.x + px;
|
|
113
|
+
if (sx < 0 || sx >= sStride)
|
|
114
|
+
continue;
|
|
115
|
+
const dx = dest.x + py;
|
|
116
|
+
const dy = dest.y + (sw - 1 - px);
|
|
117
|
+
if (dx < 0 || dx >= dStride || dy < 0 || dy >= dest.surface.height)
|
|
118
|
+
continue;
|
|
119
|
+
copyPixel(dd, (dy * dStride + dx) * 4, sd, (sy * sStride + sx) * 4);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
invalidateImageResource(dest.surface);
|
|
123
|
+
}
|
|
124
|
+
function copyPixel(dest, di, source, si) {
|
|
125
|
+
dest[di] = source[si];
|
|
126
|
+
dest[di + 1] = source[si + 1];
|
|
127
|
+
dest[di + 2] = source[si + 2];
|
|
128
|
+
dest[di + 3] = source[si + 3];
|
|
129
|
+
}
|
|
130
|
+
function inBounds(x, y, width, height) {
|
|
131
|
+
return x >= 0 && x < width && y >= 0 && y < height;
|
|
132
|
+
}
|
|
133
|
+
function isSameRegion(a, b) {
|
|
134
|
+
return a.surface === b.surface && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
135
|
+
}
|
|
136
|
+
function swapPixels(data, a, b) {
|
|
137
|
+
for (let c = 0; c < 4; c++) {
|
|
138
|
+
const t = data[a + c];
|
|
139
|
+
data[a + c] = data[b + c];
|
|
140
|
+
data[b + c] = t;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=surfaceRotate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surfaceRotate.js","sourceRoot":"","sources":["../src/surfaceRotate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC3B,IAA6B,EAC7B,MAA+B,EAC/B,KAAa,EACb,SAAiB,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,EACvC,SAAiB,CAAC,MAAM,CAAC,MAA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EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { SurfaceRegion } from '@flighthq/types';
|
|
2
|
+
export interface SurfaceShadowBlurOptions {
|
|
3
|
+
radiusX?: number;
|
|
4
|
+
radiusY?: number;
|
|
5
|
+
passes?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SurfaceDropShadowOptions extends SurfaceShadowBlurOptions {
|
|
8
|
+
/** Packed 0xRRGGBBAA shadow color. Default 0x000000ff (opaque black). */
|
|
9
|
+
color?: number;
|
|
10
|
+
/** Overall intensity multiplier applied to the shadow alpha. Default 1. */
|
|
11
|
+
intensity?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface SurfaceGlowOptions extends SurfaceShadowBlurOptions {
|
|
14
|
+
/** Packed 0xRRGGBBAA glow color. Default 0xff0000ff (opaque red). */
|
|
15
|
+
color?: number;
|
|
16
|
+
/** Overall intensity multiplier applied to the glow alpha. Default 1. */
|
|
17
|
+
intensity?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface SurfaceInnerGlowOptions extends SurfaceShadowBlurOptions {
|
|
20
|
+
/** Packed 0xRRGGBBAA inner glow color. Default 0xff0000ff (opaque red). */
|
|
21
|
+
color?: number;
|
|
22
|
+
/** Overall intensity multiplier applied to the glow alpha. Default 1. */
|
|
23
|
+
intensity?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface SurfaceInnerShadowOptions extends SurfaceShadowBlurOptions {
|
|
26
|
+
/** Packed 0xRRGGBBAA inner shadow color. Default 0x000000ff (opaque black). */
|
|
27
|
+
color?: number;
|
|
28
|
+
/** Overall intensity multiplier applied to the shadow alpha. Default 1. */
|
|
29
|
+
intensity?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Pixel offset of the shadow inside the shape, from the filter's angle+distance (dx = cos(angle) *
|
|
32
|
+
* distance, dy = sin(angle) * distance; see getShadowFilterOffset). The inverted-alpha field is
|
|
33
|
+
* sampled shifted by (offsetX, offsetY) before the blur, so the shadow lands off-center against the
|
|
34
|
+
* boundary — the Photoshop/OpenFL inner-shadow construction. Default 0 (shadow centered on the edge).
|
|
35
|
+
*/
|
|
36
|
+
offsetX?: number;
|
|
37
|
+
offsetY?: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Produces the blurred shadow mask for a drop shadow effect, writing into
|
|
41
|
+
* `out`. The result is a tinted, blurred alpha mask derived from `source`.
|
|
42
|
+
*
|
|
43
|
+
* To complete the effect, composite `out` onto the destination at the shadow
|
|
44
|
+
* offset, then optionally composite the original source on top:
|
|
45
|
+
*
|
|
46
|
+
* compositeSurfacePixels(destRegion, out); // shadow at (dx+offsetX, dy+offsetY)
|
|
47
|
+
* compositeSurfaceRegion(destRegion, source); // omit if hideObject
|
|
48
|
+
*
|
|
49
|
+
* `scratch` must be at least `source.width * source.height * 4` bytes.
|
|
50
|
+
* Its contents are undefined after the call.
|
|
51
|
+
*
|
|
52
|
+
* Safe to pass `source.surface.data` as `out` when the region covers the
|
|
53
|
+
* full surface.
|
|
54
|
+
*/
|
|
55
|
+
export declare function dropShadowSurface(out: Uint8ClampedArray, scratch: Uint8ClampedArray, source: Readonly<SurfaceRegion>, options?: Readonly<SurfaceDropShadowOptions>): void;
|
|
56
|
+
/**
|
|
57
|
+
* Produces the blurred glow mask for a glow effect, writing into `out`.
|
|
58
|
+
* The result is a tinted, blurred alpha mask derived from `source`.
|
|
59
|
+
*
|
|
60
|
+
* To complete the effect, composite `out` onto the destination, then
|
|
61
|
+
* optionally composite the original source on top:
|
|
62
|
+
*
|
|
63
|
+
* compositeSurfacePixels(destRegion, out); // glow
|
|
64
|
+
* compositeSurfaceRegion(destRegion, source); // omit if knockout
|
|
65
|
+
*
|
|
66
|
+
* `scratch` must be at least `source.width * source.height * 4` bytes.
|
|
67
|
+
* Its contents are undefined after the call.
|
|
68
|
+
*
|
|
69
|
+
* Safe to pass `source.surface.data` as `out` when the region covers the
|
|
70
|
+
* full surface.
|
|
71
|
+
*/
|
|
72
|
+
export declare function glowSurface(out: Uint8ClampedArray, scratch: Uint8ClampedArray, source: Readonly<SurfaceRegion>, options?: Readonly<SurfaceGlowOptions>): void;
|
|
73
|
+
/**
|
|
74
|
+
* Produces the inner glow mask for a glow that hugs the inside of the source's
|
|
75
|
+
* alpha boundary, writing into `out`. The inverted source alpha is blurred so
|
|
76
|
+
* that the "outside" bleeds inward, then clipped by the original source alpha so
|
|
77
|
+
* the effect stays within the shape, then tinted.
|
|
78
|
+
*
|
|
79
|
+
* To complete the effect, composite `out` over the original source:
|
|
80
|
+
*
|
|
81
|
+
* compositeSurfaceRegion(destRegion, source);
|
|
82
|
+
* compositeSurfacePixels(destRegion, out); // glow on top, inside the shape
|
|
83
|
+
*
|
|
84
|
+
* `scratch` must be at least `source.width * source.height * 4` bytes; its
|
|
85
|
+
* contents are undefined after the call.
|
|
86
|
+
*
|
|
87
|
+
* `out` must NOT alias `source.surface.data`: the original source alpha is read
|
|
88
|
+
* again after blurring, so overwriting the source destroys the clip mask.
|
|
89
|
+
*/
|
|
90
|
+
export declare function innerGlowSurface(out: Uint8ClampedArray, scratch: Uint8ClampedArray, source: Readonly<SurfaceRegion>, options?: Readonly<SurfaceInnerGlowOptions>): void;
|
|
91
|
+
/**
|
|
92
|
+
* Produces the inner shadow mask for a shadow that hugs the inside of the
|
|
93
|
+
* source's alpha boundary, writing into `out`. Like `innerGlowSurface` but with
|
|
94
|
+
* an opaque-black default color and a directional `offsetX`/`offsetY`: the
|
|
95
|
+
* inverted-alpha field is sampled shifted by the offset before blurring, so the
|
|
96
|
+
* shadow gathers toward one edge instead of ringing the boundary evenly.
|
|
97
|
+
*
|
|
98
|
+
* To complete the effect, composite `out` over the original source.
|
|
99
|
+
*
|
|
100
|
+
* `scratch` must be at least `source.width * source.height * 4` bytes; its
|
|
101
|
+
* contents are undefined after the call.
|
|
102
|
+
*
|
|
103
|
+
* `out` must NOT alias `source.surface.data` — the original source alpha is read
|
|
104
|
+
* again after blurring to clip the result.
|
|
105
|
+
*/
|
|
106
|
+
export declare function innerShadowSurface(out: Uint8ClampedArray, scratch: Uint8ClampedArray, source: Readonly<SurfaceRegion>, options?: Readonly<SurfaceInnerShadowOptions>): void;
|
|
107
|
+
//# sourceMappingURL=surfaceShadow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"surfaceShadow.d.ts","sourceRoot":"","sources":["../src/surfaceShadow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIrD,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,wBAAyB,SAAQ,wBAAwB;IACxE,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAmB,SAAQ,wBAAwB;IAClE,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB;IACvE,2EAA2E;IAC3E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,yBAA0B,SAAQ,wBAAwB;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