@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,36 @@
|
|
|
1
|
+
import { invalidateBitmap } from './bitmap';
|
|
2
|
+
// W3C luma coefficients for perceptual luminance (same as CSS saturate/grayscale).
|
|
3
|
+
const LUMA_R = 0.2126;
|
|
4
|
+
const LUMA_G = 0.7152;
|
|
5
|
+
const LUMA_B = 0.0722;
|
|
6
|
+
export function getBitmapPixel(source, x, y) {
|
|
7
|
+
const i = (y * source.width + x) * 4;
|
|
8
|
+
return ((source.data[i] << 24) | (source.data[i + 1] << 16) | (source.data[i + 2] << 8) | source.data[i + 3]) >>> 0;
|
|
9
|
+
}
|
|
10
|
+
export function getBitmapPixelChannel(source, x, y, channel) {
|
|
11
|
+
return source.data[(y * source.width + x) * 4 + channel];
|
|
12
|
+
}
|
|
13
|
+
export function getBitmapPixelLuminance(source, x, y) {
|
|
14
|
+
const i = (y * source.width + x) * 4;
|
|
15
|
+
return Math.round(source.data[i] * LUMA_R + source.data[i + 1] * LUMA_G + source.data[i + 2] * LUMA_B);
|
|
16
|
+
}
|
|
17
|
+
export function getBitmapPixelRgb(source, x, y) {
|
|
18
|
+
const i = (y * source.width + x) * 4;
|
|
19
|
+
return ((source.data[i] << 16) | (source.data[i + 1] << 8) | source.data[i + 2]) >>> 0;
|
|
20
|
+
}
|
|
21
|
+
export function setBitmapPixel(out, x, y, color) {
|
|
22
|
+
const i = (y * out.width + x) * 4;
|
|
23
|
+
out.data[i] = (color >>> 24) & 0xff;
|
|
24
|
+
out.data[i + 1] = (color >> 16) & 0xff;
|
|
25
|
+
out.data[i + 2] = (color >> 8) & 0xff;
|
|
26
|
+
out.data[i + 3] = color & 0xff;
|
|
27
|
+
invalidateBitmap(out);
|
|
28
|
+
}
|
|
29
|
+
export function setBitmapPixelRgb(out, x, y, color) {
|
|
30
|
+
const i = (y * out.width + x) * 4;
|
|
31
|
+
out.data[i] = (color >> 16) & 0xff;
|
|
32
|
+
out.data[i + 1] = (color >> 8) & 0xff;
|
|
33
|
+
out.data[i + 2] = color & 0xff;
|
|
34
|
+
invalidateBitmap(out);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=bitmapPixel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapPixel.js","sourceRoot":"","sources":["../src/bitmapPixel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C,mFAAmF;AACnF,MAAM,MAAM,GAAG,MAAM,CAAC;AACtB,MAAM,MAAM,GAAG,MAAM,CAAC;AACtB,MAAM,MAAM,GAAG,MAAM,CAAC;AAEtB,MAAM,UAAU,cAAc,CAAC,MAAwB,EAAE,CAAS,EAAE,CAAS;IAC3E,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACtH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,MAAwB,EAAE,CAAS,EAAE,CAAS,EAAE,OAAqB;IACzG,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;AAC3D,CAAC;AA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AAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IACtC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC;IAC/B,gBAAgB,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,GAAW,EAAE,CAAS,EAAE,CAAS,EAAE,KAAa;IAChF,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAClC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACnC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IACtC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC;IAC/B,gBAAgB,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BitmapRegion } from '@flighthq/types/contract';
|
|
2
|
+
/**
|
|
3
|
+
* Pixelates (mosaics) `source` into `out`: the region is divided into
|
|
4
|
+
* `blockSize × blockSize` cells, each cell is averaged, and every output pixel
|
|
5
|
+
* in the cell takes that average color. `blockSize` is clamped to at least 1
|
|
6
|
+
* (a no-op copy at 1). Edge cells are clipped to the region.
|
|
7
|
+
*
|
|
8
|
+
* `out` must be at least `source.width * source.height * 4` bytes. Safe to pass
|
|
9
|
+
* `source.bitmap.data` as `out` for a full-bitmap region — each cell is fully
|
|
10
|
+
* read before it is written, and cells do not overlap.
|
|
11
|
+
*/
|
|
12
|
+
export declare function pixelateBitmap(out: Uint8ClampedArray, source: Readonly<BitmapRegion>, blockSize: number): void;
|
|
13
|
+
//# sourceMappingURL=bitmapPixelate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapPixelate.d.ts","sourceRoot":"","sources":["../src/bitmapPixelate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,iBAAiB,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CA+C9G"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pixelates (mosaics) `source` into `out`: the region is divided into
|
|
3
|
+
* `blockSize × blockSize` cells, each cell is averaged, and every output pixel
|
|
4
|
+
* in the cell takes that average color. `blockSize` is clamped to at least 1
|
|
5
|
+
* (a no-op copy at 1). Edge cells are clipped to the region.
|
|
6
|
+
*
|
|
7
|
+
* `out` must be at least `source.width * source.height * 4` bytes. Safe to pass
|
|
8
|
+
* `source.bitmap.data` as `out` for a full-bitmap region — each cell is fully
|
|
9
|
+
* read before it is written, and cells do not overlap.
|
|
10
|
+
*/
|
|
11
|
+
export function pixelateBitmap(out, source, blockSize) {
|
|
12
|
+
const block = Math.max(1, Math.round(blockSize));
|
|
13
|
+
const w = source.width;
|
|
14
|
+
const h = source.height;
|
|
15
|
+
const bitmapWidth = source.bitmap.width;
|
|
16
|
+
const bitmapHeight = source.bitmap.height;
|
|
17
|
+
const data = source.bitmap.data;
|
|
18
|
+
for (let by = 0; by < h; by += block) {
|
|
19
|
+
const yEnd = Math.min(by + block, h);
|
|
20
|
+
for (let bx = 0; bx < w; bx += block) {
|
|
21
|
+
const xEnd = Math.min(bx + block, w);
|
|
22
|
+
let r = 0;
|
|
23
|
+
let g = 0;
|
|
24
|
+
let b = 0;
|
|
25
|
+
let a = 0;
|
|
26
|
+
let count = 0;
|
|
27
|
+
for (let py = by; py < yEnd; py++) {
|
|
28
|
+
const sy = source.y + py;
|
|
29
|
+
if (sy < 0 || sy >= bitmapHeight)
|
|
30
|
+
continue;
|
|
31
|
+
for (let px = bx; px < xEnd; px++) {
|
|
32
|
+
const sx = source.x + px;
|
|
33
|
+
if (sx < 0 || sx >= bitmapWidth)
|
|
34
|
+
continue;
|
|
35
|
+
const si = (sy * bitmapWidth + sx) * 4;
|
|
36
|
+
r += data[si];
|
|
37
|
+
g += data[si + 1];
|
|
38
|
+
b += data[si + 2];
|
|
39
|
+
a += data[si + 3];
|
|
40
|
+
count++;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (count === 0)
|
|
44
|
+
continue;
|
|
45
|
+
const ar = Math.round(r / count);
|
|
46
|
+
const ag = Math.round(g / count);
|
|
47
|
+
const ab = Math.round(b / count);
|
|
48
|
+
const aa = Math.round(a / count);
|
|
49
|
+
for (let py = by; py < yEnd; py++) {
|
|
50
|
+
for (let px = bx; px < xEnd; px++) {
|
|
51
|
+
const di = (py * w + px) * 4;
|
|
52
|
+
out[di] = ar;
|
|
53
|
+
out[di + 1] = ag;
|
|
54
|
+
out[di + 2] = ab;
|
|
55
|
+
out[di + 3] = aa;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=bitmapPixelate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapPixelate.js","sourceRoot":"","sources":["../src/bitmapPixelate.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,GAAsB,EAAE,MAA8B,EAAE,SAAiB;IACtG,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;IACjD,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IACvB,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;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-0,0 +1,13 @@
|
|
|
1
|
+
import type { RectangleLike, BitmapRegion } from '@flighthq/types/contract';
|
|
2
|
+
/**
|
|
3
|
+
* Scans the `source` region for pixels matching `color` under `mask`
|
|
4
|
+
* (`findColor` true) or not matching it (false), and returns the tightest
|
|
5
|
+
* bounding rectangle of those pixels in bitmap-absolute coordinates, or `null`
|
|
6
|
+
* if none match. Region pixels outside the bitmap are skipped.
|
|
7
|
+
*
|
|
8
|
+
* The comparison is performed on the full packed 0xRRGGBBAA pixel value. To
|
|
9
|
+
* match by a subset of channels, supply a `mask` that isolates the relevant
|
|
10
|
+
* bytes — e.g. 0xffffff00 to ignore alpha.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getBitmapColorBoundsRectangle(source: Readonly<BitmapRegion>, mask: number, color: number, findColor?: boolean): RectangleLike | null;
|
|
13
|
+
//# sourceMappingURL=bitmapQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapQuery.d.ts","sourceRoot":"","sources":["../src/bitmapQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE5E;;;;;;;;;GASG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,OAAc,GACxB,aAAa,GAAG,IAAI,CA6BtB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scans the `source` region for pixels matching `color` under `mask`
|
|
3
|
+
* (`findColor` true) or not matching it (false), and returns the tightest
|
|
4
|
+
* bounding rectangle of those pixels in bitmap-absolute coordinates, or `null`
|
|
5
|
+
* if none match. Region pixels outside the bitmap are skipped.
|
|
6
|
+
*
|
|
7
|
+
* The comparison is performed on the full packed 0xRRGGBBAA pixel value. To
|
|
8
|
+
* match by a subset of channels, supply a `mask` that isolates the relevant
|
|
9
|
+
* bytes — e.g. 0xffffff00 to ignore alpha.
|
|
10
|
+
*/
|
|
11
|
+
export function getBitmapColorBoundsRectangle(source, mask, color, findColor = true) {
|
|
12
|
+
const data = source.bitmap.data;
|
|
13
|
+
const bitmapWidth = source.bitmap.width;
|
|
14
|
+
const maskedColor = (color >>> 0) & (mask >>> 0);
|
|
15
|
+
let minX = Infinity;
|
|
16
|
+
let minY = Infinity;
|
|
17
|
+
let maxX = -1;
|
|
18
|
+
let maxY = -1;
|
|
19
|
+
for (let py = 0; py < source.height; py++) {
|
|
20
|
+
const y = source.y + py;
|
|
21
|
+
if (y < 0 || y >= source.bitmap.height)
|
|
22
|
+
continue;
|
|
23
|
+
for (let px = 0; px < source.width; px++) {
|
|
24
|
+
const x = source.x + px;
|
|
25
|
+
if (x < 0 || x >= bitmapWidth)
|
|
26
|
+
continue;
|
|
27
|
+
const i = (y * bitmapWidth + x) * 4;
|
|
28
|
+
const pixel = (((data[i] << 24) | (data[i + 1] << 16) | (data[i + 2] << 8) | data[i + 3]) >>> 0) & (mask >>> 0);
|
|
29
|
+
const matches = pixel === maskedColor;
|
|
30
|
+
if (matches === findColor) {
|
|
31
|
+
if (x < minX)
|
|
32
|
+
minX = x;
|
|
33
|
+
if (x > maxX)
|
|
34
|
+
maxX = x;
|
|
35
|
+
if (y < minY)
|
|
36
|
+
minY = y;
|
|
37
|
+
if (y > maxY)
|
|
38
|
+
maxY = y;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (maxX === -1)
|
|
43
|
+
return null;
|
|
44
|
+
return { x: minX, y: minY, width: maxX - minX + 1, height: maxY - minY + 1 };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=bitmapQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapQuery.js","sourceRoot":"","sources":["../src/bitmapQuery.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG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CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;YAChH,MAAM,OAAO,GAAG,KAAK,KAAK,WAAW,CAAC;YACtC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,IAAI,CAAC,GAAG,IAAI;oBAAE,IAAI,GAAG,CAAC,CAAC;gBACvB,IAAI,CAAC,GAAG,IAAI;oBAAE,IAAI,GAAG,CAAC,CAAC;gBACvB,IAAI,CAAC,GAAG,IAAI;oBAAE,IAAI,GAAG,CAAC,CAAC;gBACvB,IAAI,CAAC,GAAG,IAAI;oBAAE,IAAI,GAAG,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,IAAI,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7B,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Bitmap, BitmapRegion } from '@flighthq/types/contract';
|
|
2
|
+
/**
|
|
3
|
+
* Allocates a `BitmapRegion`. With no bounds it covers the whole bitmap, so
|
|
4
|
+
* `createBitmapRegion(bitmap)` is the fast path for "operate on everything".
|
|
5
|
+
*
|
|
6
|
+
* Region functions read these fields synchronously and never retain the object,
|
|
7
|
+
* so in a hot loop you can allocate one region up front and reuse it with
|
|
8
|
+
* `setBitmapRegion` instead of building a literal per call.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createBitmapRegion(bitmap: Bitmap, x?: number, y?: number, width?: number, height?: number): BitmapRegion;
|
|
11
|
+
/**
|
|
12
|
+
* Writes region fields into an existing `out` region without allocating, and
|
|
13
|
+
* returns `out`. With no bounds it covers the whole bitmap. Use this to thread
|
|
14
|
+
* a single reusable region through a hot loop:
|
|
15
|
+
*
|
|
16
|
+
* const r = createBitmapRegion(bitmap);
|
|
17
|
+
* for (…) fillBitmapRectangle(setBitmapRegion(r, bitmap, x, y, w, h), color);
|
|
18
|
+
*/
|
|
19
|
+
export declare function setBitmapRegion(out: BitmapRegion, bitmap: Bitmap, x?: number, y?: number, width?: number, height?: number): BitmapRegion;
|
|
20
|
+
//# sourceMappingURL=bitmapRegion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapRegion.d.ts","sourceRoot":"","sources":["../src/bitmapRegion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAErE;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,CAAC,GAAE,MAAU,EACb,CAAC,GAAE,MAAU,EACb,KAAK,GAAE,MAAqB,EAC5B,MAAM,GAAE,MAAsB,GAC7B,YAAY,CAEd;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,YAAY,EACjB,MAAM,EAAE,MAAM,EACd,CAAC,GAAE,MAAU,EACb,CAAC,GAAE,MAAU,EACb,KAAK,GAAE,MAAqB,EAC5B,MAAM,GAAE,MAAsB,GAC7B,YAAY,CAOd"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allocates a `BitmapRegion`. With no bounds it covers the whole bitmap, so
|
|
3
|
+
* `createBitmapRegion(bitmap)` is the fast path for "operate on everything".
|
|
4
|
+
*
|
|
5
|
+
* Region functions read these fields synchronously and never retain the object,
|
|
6
|
+
* so in a hot loop you can allocate one region up front and reuse it with
|
|
7
|
+
* `setBitmapRegion` instead of building a literal per call.
|
|
8
|
+
*/
|
|
9
|
+
export function createBitmapRegion(bitmap, x = 0, y = 0, width = bitmap.width, height = bitmap.height) {
|
|
10
|
+
return { bitmap, x, y, width, height };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Writes region fields into an existing `out` region without allocating, and
|
|
14
|
+
* returns `out`. With no bounds it covers the whole bitmap. Use this to thread
|
|
15
|
+
* a single reusable region through a hot loop:
|
|
16
|
+
*
|
|
17
|
+
* const r = createBitmapRegion(bitmap);
|
|
18
|
+
* for (…) fillBitmapRectangle(setBitmapRegion(r, bitmap, x, y, w, h), color);
|
|
19
|
+
*/
|
|
20
|
+
export function setBitmapRegion(out, bitmap, x = 0, y = 0, width = bitmap.width, height = bitmap.height) {
|
|
21
|
+
out.bitmap = bitmap;
|
|
22
|
+
out.x = x;
|
|
23
|
+
out.y = y;
|
|
24
|
+
out.width = width;
|
|
25
|
+
out.height = height;
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=bitmapRegion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapRegion.js","sourceRoot":"","sources":["../src/bitmapRegion.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,IAAY,CAAC,EACb,IAAY,CAAC,EACb,QAAgB,MAAM,CAAC,KAAK,EAC5B,SAAiB,MAAM,CAAC,MAAM;IAE9B,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,GAAiB,EACjB,MAAc,EACd,IAAY,CAAC,EACb,IAAY,CAAC,EACb,QAAgB,MAAM,CAAC,KAAK,EAC5B,SAAiB,MAAM,CAAC,MAAM;IAE9B,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IACpB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACV,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACV,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC;IAClB,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IACpB,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BitmapRegion, BitmapResizeMode, BitmapResizeOptions } from '@flighthq/types/contract';
|
|
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 declare function resizeBitmap(dest: Readonly<BitmapRegion>, source: Readonly<BitmapRegion>, options?: BitmapResizeMode | Readonly<BitmapResizeOptions>): void;
|
|
17
|
+
//# sourceMappingURL=bitmapResize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapResize.d.ts","sourceRoot":"","sources":["../src/bitmapResize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAIpH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC5B,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,OAAO,GAAE,gBAAgB,GAAG,QAAQ,CAAC,mBAAmB,CAAc,GACrE,IAAI,CA8IN"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { invalidateBitmap } from './bitmap';
|
|
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 resizeBitmap(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.bitmap.data;
|
|
28
|
+
const dd = dest.bitmap.data;
|
|
29
|
+
const sStride = source.bitmap.width;
|
|
30
|
+
const dStride = dest.bitmap.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.bitmap.height)
|
|
35
|
+
continue;
|
|
36
|
+
const sy = source.y + Math.min(sh - 1, Math.floor((dy * sh) / dh));
|
|
37
|
+
if (sy < 0 || sy >= source.bitmap.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.bitmap.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.bitmap.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
|
+
invalidateBitmap(dest.bitmap);
|
|
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=bitmapResize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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@@
|
|
|
1
|
+
import type { BitmapEdgeMode, BitmapRegion, BitmapResizeMode } from '@flighthq/types/contract';
|
|
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 rotateBitmap(dest: Readonly<BitmapRegion>, source: Readonly<BitmapRegion>, angle: number, pivotX?: number, pivotY?: number, edgeMode?: BitmapEdgeMode, sampleMode?: BitmapResizeMode): 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 bitmap 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 rotateBitmap180(dest: Readonly<BitmapRegion>, source: Readonly<BitmapRegion>): 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 rotateBitmapClockwise(dest: Readonly<BitmapRegion>, source: Readonly<BitmapRegion>): 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 rotateBitmapCounterClockwise(dest: Readonly<BitmapRegion>, source: Readonly<BitmapRegion>): void;
|
|
32
|
+
//# sourceMappingURL=bitmapRotate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmapRotate.d.ts","sourceRoot":"","sources":["../src/bitmapRotate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAK/F;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC5B,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAA+B,EACvC,MAAM,GAAE,MAAgC,EACxC,QAAQ,GAAE,cAAwB,EAClC,UAAU,GAAE,gBAA6B,GACxC,IAAI,CAQN;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI,CAkClG;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI,CAoBxG;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI,CAoB/G"}
|