@flighthq/bitmap 0.3.0-next.1021.f5f1ee0

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.
Files changed (214) hide show
  1. package/dist/bitmap.d.ts +17 -0
  2. package/dist/bitmap.d.ts.map +1 -0
  3. package/dist/bitmap.js +87 -0
  4. package/dist/bitmap.js.map +1 -0
  5. package/dist/bitmapAffine.d.ts +27 -0
  6. package/dist/bitmapAffine.d.ts.map +1 -0
  7. package/dist/bitmapAffine.js +159 -0
  8. package/dist/bitmapAffine.js.map +1 -0
  9. package/dist/bitmapAlpha.d.ts +27 -0
  10. package/dist/bitmapAlpha.d.ts.map +1 -0
  11. package/dist/bitmapAlpha.js +83 -0
  12. package/dist/bitmapAlpha.js.map +1 -0
  13. package/dist/bitmapBevel.d.ts +24 -0
  14. package/dist/bitmapBevel.d.ts.map +1 -0
  15. package/dist/bitmapBevel.js +102 -0
  16. package/dist/bitmapBevel.js.map +1 -0
  17. package/dist/bitmapBlur.d.ts +57 -0
  18. package/dist/bitmapBlur.d.ts.map +1 -0
  19. package/dist/bitmapBlur.js +263 -0
  20. package/dist/bitmapBlur.js.map +1 -0
  21. package/dist/bitmapChannel.d.ts +24 -0
  22. package/dist/bitmapChannel.d.ts.map +1 -0
  23. package/dist/bitmapChannel.js +127 -0
  24. package/dist/bitmapChannel.js.map +1 -0
  25. package/dist/bitmapColorMatrix.d.ts +57 -0
  26. package/dist/bitmapColorMatrix.d.ts.map +1 -0
  27. package/dist/bitmapColorMatrix.js +127 -0
  28. package/dist/bitmapColorMatrix.js.map +1 -0
  29. package/dist/bitmapCompare.d.ts +18 -0
  30. package/dist/bitmapCompare.d.ts.map +1 -0
  31. package/dist/bitmapCompare.js +64 -0
  32. package/dist/bitmapCompare.js.map +1 -0
  33. package/dist/bitmapComposite.d.ts +54 -0
  34. package/dist/bitmapComposite.d.ts.map +1 -0
  35. package/dist/bitmapComposite.js +262 -0
  36. package/dist/bitmapComposite.js.map +1 -0
  37. package/dist/bitmapConvolution.d.ts +17 -0
  38. package/dist/bitmapConvolution.d.ts.map +1 -0
  39. package/dist/bitmapConvolution.js +103 -0
  40. package/dist/bitmapConvolution.js.map +1 -0
  41. package/dist/bitmapCopy.d.ts +23 -0
  42. package/dist/bitmapCopy.d.ts.map +1 -0
  43. package/dist/bitmapCopy.js +78 -0
  44. package/dist/bitmapCopy.js.map +1 -0
  45. package/dist/bitmapCoverage.d.ts +11 -0
  46. package/dist/bitmapCoverage.d.ts.map +1 -0
  47. package/dist/bitmapCoverage.js +29 -0
  48. package/dist/bitmapCoverage.js.map +1 -0
  49. package/dist/bitmapCrop.d.ts +33 -0
  50. package/dist/bitmapCrop.d.ts.map +1 -0
  51. package/dist/bitmapCrop.js +175 -0
  52. package/dist/bitmapCrop.js.map +1 -0
  53. package/dist/bitmapDisplacement.d.ts +22 -0
  54. package/dist/bitmapDisplacement.d.ts.map +1 -0
  55. package/dist/bitmapDisplacement.js +131 -0
  56. package/dist/bitmapDisplacement.js.map +1 -0
  57. package/dist/bitmapDissolve.d.ts +21 -0
  58. package/dist/bitmapDissolve.d.ts.map +1 -0
  59. package/dist/bitmapDissolve.js +97 -0
  60. package/dist/bitmapDissolve.js.map +1 -0
  61. package/dist/bitmapDraw.d.ts +8 -0
  62. package/dist/bitmapDraw.d.ts.map +1 -0
  63. package/dist/bitmapDraw.js +14 -0
  64. package/dist/bitmapDraw.js.map +1 -0
  65. package/dist/bitmapEncode.d.ts +3 -0
  66. package/dist/bitmapEncode.d.ts.map +1 -0
  67. package/dist/bitmapEncode.js +18 -0
  68. package/dist/bitmapEncode.js.map +1 -0
  69. package/dist/bitmapFill.d.ts +12 -0
  70. package/dist/bitmapFill.d.ts.map +1 -0
  71. package/dist/bitmapFill.js +85 -0
  72. package/dist/bitmapFill.js.map +1 -0
  73. package/dist/bitmapFingerprint.d.ts +26 -0
  74. package/dist/bitmapFingerprint.d.ts.map +1 -0
  75. package/dist/bitmapFingerprint.js +99 -0
  76. package/dist/bitmapFingerprint.js.map +1 -0
  77. package/dist/bitmapFlip.d.ts +16 -0
  78. package/dist/bitmapFlip.d.ts.map +1 -0
  79. package/dist/bitmapFlip.js +98 -0
  80. package/dist/bitmapFlip.js.map +1 -0
  81. package/dist/bitmapFormat.d.ts +26 -0
  82. package/dist/bitmapFormat.d.ts.map +1 -0
  83. package/dist/bitmapFormat.js +80 -0
  84. package/dist/bitmapFormat.js.map +1 -0
  85. package/dist/bitmapFrom.d.ts +17 -0
  86. package/dist/bitmapFrom.d.ts.map +1 -0
  87. package/dist/bitmapFrom.js +67 -0
  88. package/dist/bitmapFrom.js.map +1 -0
  89. package/dist/bitmapGradient.d.ts +36 -0
  90. package/dist/bitmapGradient.d.ts.map +1 -0
  91. package/dist/bitmapGradient.js +176 -0
  92. package/dist/bitmapGradient.js.map +1 -0
  93. package/dist/bitmapGradientFill.d.ts +32 -0
  94. package/dist/bitmapGradientFill.d.ts.map +1 -0
  95. package/dist/bitmapGradientFill.js +120 -0
  96. package/dist/bitmapGradientFill.js.map +1 -0
  97. package/dist/bitmapHistogram.d.ts +20 -0
  98. package/dist/bitmapHistogram.d.ts.map +1 -0
  99. package/dist/bitmapHistogram.js +61 -0
  100. package/dist/bitmapHistogram.js.map +1 -0
  101. package/dist/bitmapImageChannel.d.ts +2 -0
  102. package/dist/bitmapImageChannel.d.ts.map +1 -0
  103. package/dist/bitmapImageChannel.js +2 -0
  104. package/dist/bitmapImageChannel.js.map +1 -0
  105. package/dist/bitmapMedian.d.ts +14 -0
  106. package/dist/bitmapMedian.d.ts.map +1 -0
  107. package/dist/bitmapMedian.js +77 -0
  108. package/dist/bitmapMedian.js.map +1 -0
  109. package/dist/bitmapMorphological.d.ts +29 -0
  110. package/dist/bitmapMorphological.d.ts.map +1 -0
  111. package/dist/bitmapMorphological.js +81 -0
  112. package/dist/bitmapMorphological.js.map +1 -0
  113. package/dist/bitmapNoise.d.ts +48 -0
  114. package/dist/bitmapNoise.d.ts.map +1 -0
  115. package/dist/bitmapNoise.js +245 -0
  116. package/dist/bitmapNoise.js.map +1 -0
  117. package/dist/bitmapPaletteMap.d.ts +17 -0
  118. package/dist/bitmapPaletteMap.d.ts.map +1 -0
  119. package/dist/bitmapPaletteMap.js +45 -0
  120. package/dist/bitmapPaletteMap.js.map +1 -0
  121. package/dist/bitmapPixel.d.ts +9 -0
  122. package/dist/bitmapPixel.d.ts.map +1 -0
  123. package/dist/bitmapPixel.js +36 -0
  124. package/dist/bitmapPixel.js.map +1 -0
  125. package/dist/bitmapPixelate.d.ts +13 -0
  126. package/dist/bitmapPixelate.d.ts.map +1 -0
  127. package/dist/bitmapPixelate.js +61 -0
  128. package/dist/bitmapPixelate.js.map +1 -0
  129. package/dist/bitmapQuery.d.ts +13 -0
  130. package/dist/bitmapQuery.d.ts.map +1 -0
  131. package/dist/bitmapQuery.js +46 -0
  132. package/dist/bitmapQuery.js.map +1 -0
  133. package/dist/bitmapRegion.d.ts +20 -0
  134. package/dist/bitmapRegion.d.ts.map +1 -0
  135. package/dist/bitmapRegion.js +28 -0
  136. package/dist/bitmapRegion.js.map +1 -0
  137. package/dist/bitmapResize.d.ts +17 -0
  138. package/dist/bitmapResize.d.ts.map +1 -0
  139. package/dist/bitmapResize.js +191 -0
  140. package/dist/bitmapResize.js.map +1 -0
  141. package/dist/bitmapRotate.d.ts +32 -0
  142. package/dist/bitmapRotate.d.ts.map +1 -0
  143. package/dist/bitmapRotate.js +143 -0
  144. package/dist/bitmapRotate.js.map +1 -0
  145. package/dist/bitmapShadow.d.ts +72 -0
  146. package/dist/bitmapShadow.d.ts.map +1 -0
  147. package/dist/bitmapShadow.js +175 -0
  148. package/dist/bitmapShadow.js.map +1 -0
  149. package/dist/bitmapSharpen.d.ts +16 -0
  150. package/dist/bitmapSharpen.d.ts.map +1 -0
  151. package/dist/bitmapSharpen.js +47 -0
  152. package/dist/bitmapSharpen.js.map +1 -0
  153. package/dist/bitmapTone.d.ts +28 -0
  154. package/dist/bitmapTone.d.ts.map +1 -0
  155. package/dist/bitmapTone.js +69 -0
  156. package/dist/bitmapTone.js.map +1 -0
  157. package/dist/bitmapTransform.d.ts +40 -0
  158. package/dist/bitmapTransform.d.ts.map +1 -0
  159. package/dist/bitmapTransform.js +163 -0
  160. package/dist/bitmapTransform.js.map +1 -0
  161. package/dist/bitmapWarp.d.ts +48 -0
  162. package/dist/bitmapWarp.d.ts.map +1 -0
  163. package/dist/bitmapWarp.js +284 -0
  164. package/dist/bitmapWarp.js.map +1 -0
  165. package/dist/contract.d.ts +42 -0
  166. package/dist/contract.d.ts.map +1 -0
  167. package/dist/contract.js +42 -0
  168. package/dist/contract.js.map +1 -0
  169. package/dist/index.d.ts +2 -0
  170. package/dist/index.d.ts.map +1 -0
  171. package/dist/index.js +2 -0
  172. package/dist/index.js.map +1 -0
  173. package/package.json +48 -0
  174. package/src/bitmap.test.ts +88 -0
  175. package/src/bitmapAffine.test.ts +98 -0
  176. package/src/bitmapAlpha.test.ts +110 -0
  177. package/src/bitmapBevel.test.ts +61 -0
  178. package/src/bitmapBlur.test.ts +234 -0
  179. package/src/bitmapChannel.test.ts +97 -0
  180. package/src/bitmapColorMatrix.test.ts +214 -0
  181. package/src/bitmapCompare.test.ts +92 -0
  182. package/src/bitmapComposite.test.ts +259 -0
  183. package/src/bitmapConvolution.test.ts +130 -0
  184. package/src/bitmapCopy.test.ts +48 -0
  185. package/src/bitmapCoverage.test.ts +39 -0
  186. package/src/bitmapCrop.test.ts +116 -0
  187. package/src/bitmapDisplacement.test.ts +136 -0
  188. package/src/bitmapDissolve.test.ts +99 -0
  189. package/src/bitmapDraw.test.ts +68 -0
  190. package/src/bitmapEncode.test.ts +18 -0
  191. package/src/bitmapFill.test.ts +83 -0
  192. package/src/bitmapFingerprint.test.ts +103 -0
  193. package/src/bitmapFlip.test.ts +53 -0
  194. package/src/bitmapFormat.test.ts +124 -0
  195. package/src/bitmapFrom.test.ts +57 -0
  196. package/src/bitmapGradient.test.ts +85 -0
  197. package/src/bitmapGradientFill.test.ts +107 -0
  198. package/src/bitmapHistogram.test.ts +64 -0
  199. package/src/bitmapImageChannel.test.ts +19 -0
  200. package/src/bitmapMedian.test.ts +39 -0
  201. package/src/bitmapMorphological.test.ts +69 -0
  202. package/src/bitmapNoise.test.ts +163 -0
  203. package/src/bitmapPaletteMap.test.ts +49 -0
  204. package/src/bitmapPixel.test.ts +117 -0
  205. package/src/bitmapPixelate.test.ts +40 -0
  206. package/src/bitmapQuery.test.ts +42 -0
  207. package/src/bitmapRegion.test.ts +34 -0
  208. package/src/bitmapResize.test.ts +106 -0
  209. package/src/bitmapRotate.test.ts +108 -0
  210. package/src/bitmapShadow.test.ts +159 -0
  211. package/src/bitmapSharpen.test.ts +44 -0
  212. package/src/bitmapTone.test.ts +104 -0
  213. package/src/bitmapTransform.test.ts +128 -0
  214. package/src/bitmapWarp.test.ts +118 -0
@@ -0,0 +1,17 @@
1
+ import type { AlphaType, Bitmap } from '@flighthq/types/contract';
2
+ export declare function cloneBitmap(source: Readonly<Bitmap>): Bitmap;
3
+ /**
4
+ * Converts the alpha representation of `out` in place between `'straight'` and
5
+ * `'premultiplied'`. If `out.alphaType` already matches `target`, this is a
6
+ * no-op (neither pixel data nor the metadata field changes).
7
+ *
8
+ * - `'straight' → 'premultiplied'`: RGB channels are multiplied by alpha/255.
9
+ * - `'premultiplied' → 'straight'`: RGB channels are divided by alpha/255.
10
+ * Pixels with alpha=0 are left as `(0,0,0,0)`.
11
+ *
12
+ * Updates `out.alphaType` to `target` after conversion.
13
+ */
14
+ export declare function convertBitmapAlphaType(out: Bitmap, target: AlphaType): void;
15
+ export declare function createBitmap(width: number, height: number, color?: number): Bitmap;
16
+ export declare function invalidateBitmap(bitmap: Bitmap): void;
17
+ //# sourceMappingURL=bitmap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitmap.d.ts","sourceRoot":"","sources":["../src/bitmap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAGlE,wBAAgB,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,CAW5D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,IAAI,CA6B3E;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM,CAwBrF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAErD"}
package/dist/bitmap.js ADDED
@@ -0,0 +1,87 @@
1
+ import { createEntity } from '@flighthq/entity/contract';
2
+ import { BitmapTextureBackingKind } from '@flighthq/types/contract';
3
+ export function cloneBitmap(source) {
4
+ return createEntity({
5
+ alphaType: source.alphaType,
6
+ colorSpace: source.colorSpace,
7
+ data: new Uint8ClampedArray(source.data),
8
+ format: source.format,
9
+ height: source.height,
10
+ kind: source.kind,
11
+ version: 0,
12
+ width: source.width,
13
+ });
14
+ }
15
+ /**
16
+ * Converts the alpha representation of `out` in place between `'straight'` and
17
+ * `'premultiplied'`. If `out.alphaType` already matches `target`, this is a
18
+ * no-op (neither pixel data nor the metadata field changes).
19
+ *
20
+ * - `'straight' → 'premultiplied'`: RGB channels are multiplied by alpha/255.
21
+ * - `'premultiplied' → 'straight'`: RGB channels are divided by alpha/255.
22
+ * Pixels with alpha=0 are left as `(0,0,0,0)`.
23
+ *
24
+ * Updates `out.alphaType` to `target` after conversion.
25
+ */
26
+ export function convertBitmapAlphaType(out, target) {
27
+ if (out.alphaType === target)
28
+ return;
29
+ const data = out.data;
30
+ const len = out.width * out.height * 4;
31
+ if (target === 'premultiplied') {
32
+ for (let i = 0; i < len; i += 4) {
33
+ const a = data[i + 3] / 255;
34
+ data[i] = Math.round(data[i] * a);
35
+ data[i + 1] = Math.round(data[i + 1] * a);
36
+ data[i + 2] = Math.round(data[i + 2] * a);
37
+ }
38
+ }
39
+ else {
40
+ for (let i = 0; i < len; i += 4) {
41
+ const a = data[i + 3];
42
+ if (a === 0) {
43
+ data[i] = 0;
44
+ data[i + 1] = 0;
45
+ data[i + 2] = 0;
46
+ }
47
+ else {
48
+ const inv = 255 / a;
49
+ data[i] = Math.min(255, Math.round(data[i] * inv));
50
+ data[i + 1] = Math.min(255, Math.round(data[i + 1] * inv));
51
+ data[i + 2] = Math.min(255, Math.round(data[i + 2] * inv));
52
+ }
53
+ }
54
+ }
55
+ // Mutate the alphaType metadata field.
56
+ out.alphaType = target;
57
+ invalidateBitmap(out);
58
+ }
59
+ export function createBitmap(width, height, color = 0) {
60
+ const data = new Uint8ClampedArray(width * height * 4);
61
+ if (color !== 0) {
62
+ const r = (color >>> 24) & 0xff;
63
+ const g = (color >> 16) & 0xff;
64
+ const b = (color >> 8) & 0xff;
65
+ const a = color & 0xff;
66
+ for (let i = 0; i < data.length; i += 4) {
67
+ data[i] = r;
68
+ data[i + 1] = g;
69
+ data[i + 2] = b;
70
+ data[i + 3] = a;
71
+ }
72
+ }
73
+ return createEntity({
74
+ alphaType: 'straight',
75
+ colorSpace: 'srgb',
76
+ data,
77
+ format: 'rgba8unorm',
78
+ height,
79
+ kind: BitmapTextureBackingKind,
80
+ version: 0,
81
+ width,
82
+ });
83
+ }
84
+ export function invalidateBitmap(bitmap) {
85
+ bitmap.version = (bitmap.version + 1) >>> 0;
86
+ }
87
+ //# sourceMappingURL=bitmap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitmap.js","sourceRoot":"","sources":["../src/bitmap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,MAAM,UAAU,WAAW,CAAC,MAAwB;IAClD,OAAO,YAAY,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC,SA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C,EAAE,CAAC;QAChB,MAAM,CAAC,GAAG,CAAC,KAAK,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;QAChC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;QAC/B,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;QAC9B,MAAM,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC;QACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACZ,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YAChB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YAChB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;QAClB,SAAS,EAAE,UAAU;QACrB,UAAU,EAAE,MAAe;QAC3B,IAAI;QACJ,MAAM,EAAE,YAAY;QACpB,MAAM;QACN,IAAI,EAAE,wBAAwB;QAC9B,OAAO,EAAE,CAAC;QACV,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,MAAM,CAAC,OAAO,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { BitmapEdgeMode, BitmapRegion, BitmapResizeMode } from '@flighthq/types/contract';
2
+ /**
3
+ * Applies a full 2×3 affine transform to the `source` region, writing into
4
+ * `dest`. The `matrix` is a 6-element array `[a, b, c, d, e, f]` representing:
5
+ *
6
+ * ```
7
+ * [ a c e ]
8
+ * [ b d f ]
9
+ * ```
10
+ *
11
+ * Maps each `dest` pixel `(x, y)` back to source coordinates by the inverse
12
+ * transform:
13
+ *
14
+ * ```
15
+ * srcX = a * x + c * y + e
16
+ * srcY = b * x + d * y + f
17
+ * ```
18
+ *
19
+ * This is a forward-mapping: for each output pixel the source position is
20
+ * computed, then sampled according to `sampleMode` (default `'bilinear'`).
21
+ * Out-of-bounds source positions are resolved with `edgeMode` (default
22
+ * `'transparent'`).
23
+ *
24
+ * `dest` must not alias `source` when their regions overlap.
25
+ */
26
+ export declare function transformBitmap(dest: Readonly<BitmapRegion>, source: Readonly<BitmapRegion>, matrix: Readonly<[number, number, number, number, number, number]>, edgeMode?: BitmapEdgeMode, sampleMode?: BitmapResizeMode): void;
27
+ //# sourceMappingURL=bitmapAffine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitmapAffine.d.ts","sourceRoot":"","sources":["../src/bitmapAffine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAI/F;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC5B,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,MAAM,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAClE,QAAQ,GAAE,cAA8B,EACxC,UAAU,GAAE,gBAA6B,GACxC,IAAI,CAyBN"}
@@ -0,0 +1,159 @@
1
+ import { invalidateBitmap } from './bitmap';
2
+ /**
3
+ * Applies a full 2×3 affine transform to the `source` region, writing into
4
+ * `dest`. The `matrix` is a 6-element array `[a, b, c, d, e, f]` representing:
5
+ *
6
+ * ```
7
+ * [ a c e ]
8
+ * [ b d f ]
9
+ * ```
10
+ *
11
+ * Maps each `dest` pixel `(x, y)` back to source coordinates by the inverse
12
+ * transform:
13
+ *
14
+ * ```
15
+ * srcX = a * x + c * y + e
16
+ * srcY = b * x + d * y + f
17
+ * ```
18
+ *
19
+ * This is a forward-mapping: for each output pixel the source position is
20
+ * computed, then sampled according to `sampleMode` (default `'bilinear'`).
21
+ * Out-of-bounds source positions are resolved with `edgeMode` (default
22
+ * `'transparent'`).
23
+ *
24
+ * `dest` must not alias `source` when their regions overlap.
25
+ */
26
+ export function transformBitmap(dest, source, matrix, edgeMode = 'transparent', sampleMode = 'bilinear') {
27
+ const dw = dest.width;
28
+ const dh = dest.height;
29
+ const sw = source.width;
30
+ const sh = source.height;
31
+ if (dw === 0 || dh === 0 || sw === 0 || sh === 0)
32
+ return;
33
+ const [a, b, c, d, e, f] = matrix;
34
+ const sd = source.bitmap.data;
35
+ const dd = dest.bitmap.data;
36
+ const sStride = source.bitmap.width;
37
+ const dStride = dest.bitmap.width;
38
+ for (let dy = 0; dy < dh; dy++) {
39
+ const oy = dest.y + dy;
40
+ if (oy < 0 || oy >= dest.bitmap.height)
41
+ continue;
42
+ for (let dx = 0; dx < dw; dx++) {
43
+ const ox = dest.x + dx;
44
+ if (ox < 0 || ox >= dStride)
45
+ continue;
46
+ // Map dest pixel to source coordinates.
47
+ const sx = a * dx + c * dy + e;
48
+ const sy = b * dx + d * dy + f;
49
+ const di = (oy * dStride + ox) * 4;
50
+ sampleBitmap(dd, di, sd, sw, sh, source.x, source.y, sStride, source.bitmap.height, sx, sy, sampleMode, edgeMode);
51
+ }
52
+ }
53
+ invalidateBitmap(dest.bitmap);
54
+ }
55
+ /**
56
+ * Samples the source bitmap at fractional coordinates `(sx, sy)` in
57
+ * source-region-local space, writing the result into `dd[di..di+3]`. Edge
58
+ * behaviour is controlled by `edgeMode`; sampling quality by `sampleMode`.
59
+ */
60
+ function sampleBitmap(dd, di, sd, sw, sh, originX, originY, sStride, sHeight, sx, sy, sampleMode, edgeMode) {
61
+ if (sampleMode === 'nearest') {
62
+ const ix = Math.round(sx);
63
+ const iy = Math.round(sy);
64
+ const cx = resolveEdge(ix, sw, edgeMode);
65
+ const cy = resolveEdge(iy, sh, edgeMode);
66
+ if (cx === null || cy === null) {
67
+ writeTransparent(dd, di);
68
+ return;
69
+ }
70
+ const si = ((originY + cy) * sStride + (originX + cx)) * 4;
71
+ dd[di] = sd[si];
72
+ dd[di + 1] = sd[si + 1];
73
+ dd[di + 2] = sd[si + 2];
74
+ dd[di + 3] = sd[si + 3];
75
+ return;
76
+ }
77
+ if (sampleMode === 'bicubic') {
78
+ sampleBicubic(dd, di, sd, sw, sh, originX, originY, sStride, sHeight, sx, sy, edgeMode);
79
+ return;
80
+ }
81
+ // bilinear (default)
82
+ sampleBilinear(dd, di, sd, sw, sh, originX, originY, sStride, sHeight, sx, sy, edgeMode);
83
+ }
84
+ function sampleBilinear(dd, di, sd, sw, sh, originX, originY, sStride, _sHeight, sx, sy, edgeMode) {
85
+ const x0 = Math.floor(sx);
86
+ const y0 = Math.floor(sy);
87
+ const tx = sx - x0;
88
+ const ty = sy - y0;
89
+ const cx00 = resolveEdge(x0, sw, edgeMode);
90
+ const cx10 = resolveEdge(x0 + 1, sw, edgeMode);
91
+ const cy00 = resolveEdge(y0, sh, edgeMode);
92
+ const cy10 = resolveEdge(y0 + 1, sh, edgeMode);
93
+ for (let c = 0; c < 4; c++) {
94
+ const v00 = cx00 !== null && cy00 !== null ? sd[((originY + cy00) * sStride + originX + cx00) * 4 + c] : 0;
95
+ const v10 = cx10 !== null && cy00 !== null ? sd[((originY + cy00) * sStride + originX + cx10) * 4 + c] : 0;
96
+ const v01 = cx00 !== null && cy10 !== null ? sd[((originY + cy10) * sStride + originX + cx00) * 4 + c] : 0;
97
+ const v11 = cx10 !== null && cy10 !== null ? sd[((originY + cy10) * sStride + originX + cx10) * 4 + c] : 0;
98
+ const top = v00 * (1 - tx) + v10 * tx;
99
+ const bottom = v01 * (1 - tx) + v11 * tx;
100
+ dd[di + c] = Math.round(top * (1 - ty) + bottom * ty);
101
+ }
102
+ }
103
+ function sampleBicubic(dd, di, sd, sw, sh, originX, originY, sStride, _sHeight, sx, sy, edgeMode) {
104
+ const x1 = Math.floor(sx);
105
+ const y1 = Math.floor(sy);
106
+ const tx = sx - x1;
107
+ const ty = sy - y1;
108
+ for (let c = 0; c < 4; c++) {
109
+ let sum = 0;
110
+ for (let m = -1; m <= 2; m++) {
111
+ const wy = catmullRomWeight(ty - m);
112
+ const ry = resolveEdge(y1 + m, sh, edgeMode);
113
+ for (let n = -1; n <= 2; n++) {
114
+ const wx = catmullRomWeight(tx - n);
115
+ const rx = resolveEdge(x1 + n, sw, edgeMode);
116
+ const v = rx !== null && ry !== null ? sd[((originY + ry) * sStride + originX + rx) * 4 + c] : 0;
117
+ sum += v * wy * wx;
118
+ }
119
+ }
120
+ dd[di + c] = Math.max(0, Math.min(255, Math.round(sum)));
121
+ }
122
+ }
123
+ /**
124
+ * Maps a local coordinate `v` in `[0, size)` using the edge mode.
125
+ * Returns `null` for `'transparent'` when out of bounds.
126
+ */
127
+ function resolveEdge(v, size, mode) {
128
+ if (v >= 0 && v < size)
129
+ return v;
130
+ switch (mode) {
131
+ case 'clamp':
132
+ return Math.max(0, Math.min(size - 1, v));
133
+ case 'wrap':
134
+ return ((v % size) + size) % size;
135
+ case 'mirror': {
136
+ const period = 2 * size;
137
+ const wrapped = ((v % period) + period) % period;
138
+ return wrapped < size ? wrapped : period - 1 - wrapped;
139
+ }
140
+ default:
141
+ // 'transparent'
142
+ return null;
143
+ }
144
+ }
145
+ function catmullRomWeight(t) {
146
+ const a = Math.abs(t);
147
+ if (a >= 2)
148
+ return 0;
149
+ if (a >= 1)
150
+ return -0.5 * a * a * a + 2.5 * a * a - 4 * a + 2;
151
+ return 1.5 * a * a * a - 2.5 * a * a + 1;
152
+ }
153
+ function writeTransparent(dd, di) {
154
+ dd[di] = 0;
155
+ dd[di + 1] = 0;
156
+ dd[di + 2] = 0;
157
+ dd[di + 3] = 0;
158
+ }
159
+ //# sourceMappingURL=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,CAAC,GAAG,CAAC,CAAC;IACf,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACf,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AACjB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { BitmapRegion } from '@flighthq/types/contract';
2
+ /**
3
+ * Copies only the alpha channel from the `source` region into the `dest`
4
+ * region. RGB channels of `dest` are left unchanged. The copied size is the
5
+ * overlap of the two regions.
6
+ *
7
+ * Safe to pass the same bitmap and region in `dest` and `source` (no-op on
8
+ * alpha since each value is read and immediately written to the same location).
9
+ */
10
+ export declare function copyBitmapAlpha(dest: Readonly<BitmapRegion>, source: Readonly<BitmapRegion>): void;
11
+ /**
12
+ * Scales every alpha value in the `out` region by `factor` (0–1). RGB channels
13
+ * are unchanged. A `factor` of 0 makes the region fully transparent; a `factor`
14
+ * of 1 leaves it unchanged; values in between fade it proportionally.
15
+ *
16
+ * `factor` is clamped to [0, 1].
17
+ */
18
+ export declare function multiplyBitmapAlpha(out: Readonly<BitmapRegion>, factor: number): void;
19
+ /**
20
+ * Writes a constant `alpha` value (0–255) to every pixel in the `out` region.
21
+ * RGB channels are unchanged. Useful for making a region fully opaque or
22
+ * transparent in a single call.
23
+ *
24
+ * `alpha` is clamped to [0, 255].
25
+ */
26
+ export declare function setBitmapAlpha(out: Readonly<BitmapRegion>, alpha: number): void;
27
+ //# sourceMappingURL=bitmapAlpha.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitmapAlpha.d.ts","sourceRoot":"","sources":["../src/bitmapAlpha.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAI7D;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,IAAI,CAqBlG;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAerF;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAc/E"}
@@ -0,0 +1,83 @@
1
+ import { invalidateBitmap } from './bitmap';
2
+ /**
3
+ * Copies only the alpha channel from the `source` region into the `dest`
4
+ * region. RGB channels of `dest` are left unchanged. The copied size is the
5
+ * overlap of the two regions.
6
+ *
7
+ * Safe to pass the same bitmap and region in `dest` and `source` (no-op on
8
+ * alpha since each value is read and immediately written to the same location).
9
+ */
10
+ export function copyBitmapAlpha(dest, source) {
11
+ const w = Math.min(dest.width, source.width);
12
+ const h = Math.min(dest.height, source.height);
13
+ const sd = source.bitmap.data;
14
+ const dd = dest.bitmap.data;
15
+ for (let py = 0; py < h; py++) {
16
+ const sy = source.y + py;
17
+ const dy = dest.y + py;
18
+ if (sy < 0 || sy >= source.bitmap.height || dy < 0 || dy >= dest.bitmap.height)
19
+ continue;
20
+ for (let px = 0; px < w; px++) {
21
+ const sx = source.x + px;
22
+ const dx = dest.x + px;
23
+ if (sx < 0 || sx >= source.bitmap.width || dx < 0 || dx >= dest.bitmap.width)
24
+ continue;
25
+ const si = (sy * source.bitmap.width + sx) * 4;
26
+ const di = (dy * dest.bitmap.width + dx) * 4;
27
+ // Read alpha before writing — safe for the aliased case.
28
+ const alpha = sd[si + 3];
29
+ dd[di + 3] = alpha;
30
+ }
31
+ }
32
+ invalidateBitmap(dest.bitmap);
33
+ }
34
+ /**
35
+ * Scales every alpha value in the `out` region by `factor` (0–1). RGB channels
36
+ * are unchanged. A `factor` of 0 makes the region fully transparent; a `factor`
37
+ * of 1 leaves it unchanged; values in between fade it proportionally.
38
+ *
39
+ * `factor` is clamped to [0, 1].
40
+ */
41
+ export function multiplyBitmapAlpha(out, factor) {
42
+ const f = Math.max(0, Math.min(1, factor));
43
+ const data = out.bitmap.data;
44
+ const bitmapWidth = out.bitmap.width;
45
+ for (let py = 0; py < out.height; py++) {
46
+ const y = out.y + py;
47
+ if (y < 0 || y >= out.bitmap.height)
48
+ continue;
49
+ for (let px = 0; px < out.width; px++) {
50
+ const x = out.x + px;
51
+ if (x < 0 || x >= bitmapWidth)
52
+ continue;
53
+ const i = (y * bitmapWidth + x) * 4 + 3;
54
+ data[i] = Math.round(data[i] * f);
55
+ }
56
+ }
57
+ invalidateBitmap(out.bitmap);
58
+ }
59
+ /**
60
+ * Writes a constant `alpha` value (0–255) to every pixel in the `out` region.
61
+ * RGB channels are unchanged. Useful for making a region fully opaque or
62
+ * transparent in a single call.
63
+ *
64
+ * `alpha` is clamped to [0, 255].
65
+ */
66
+ export function setBitmapAlpha(out, alpha) {
67
+ const a = Math.max(0, Math.min(255, Math.round(alpha)));
68
+ const data = out.bitmap.data;
69
+ const bitmapWidth = out.bitmap.width;
70
+ for (let py = 0; py < out.height; py++) {
71
+ const y = out.y + py;
72
+ if (y < 0 || y >= out.bitmap.height)
73
+ continue;
74
+ for (let px = 0; px < out.width; px++) {
75
+ const x = out.x + px;
76
+ if (x < 0 || x >= bitmapWidth)
77
+ continue;
78
+ data[(y * bitmapWidth + x) * 4 + 3] = a;
79
+ }
80
+ }
81
+ invalidateBitmap(out.bitmap);
82
+ }
83
+ //# sourceMappingURL=bitmapAlpha.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitmapAlpha.js","sourceRoot":"","sources":["../src/bitmapAlpha.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,IAA4B,EAAE,MAA8B;IAC1F,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7C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AAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,GAA2B,EAAE,KAAa;IACvE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;IAC7B,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;IACrC,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC;QACvC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM;YAAE,SAAS;QAC9C,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,GAAG,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC;YACtC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;YACrB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,WAAW;gBAAE,SAAS;YACxC,IAAI,CAAC,CAAC,CAAC,GAAG,WAAW,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IACD,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { BitmapBevelOptions, BitmapRegion } from '@flighthq/types/contract';
2
+ /**
3
+ * Produces a bevel mask in `out`: a tinted highlight on the edge facing the
4
+ * light and a shadow on the opposite edge, derived from the directional
5
+ * gradient of the source's blurred alpha.
6
+ *
7
+ * The edge gradient is `m(p - L) - m(p + L)` where `m` is the blurred alpha and
8
+ * `L = (cos(angle), sin(angle)) * distance`. A positive gradient (edge facing the
9
+ * light) draws the highlight color; a negative gradient draws the shadow color.
10
+ *
11
+ * `type` clips the result: 'inner' keeps it inside the shape, 'outer' outside,
12
+ * 'both' applies no clipping.
13
+ *
14
+ * To complete the effect, composite `out` over the original source.
15
+ *
16
+ * `scratch` must be at least `source.width * source.height * 4` bytes; it must
17
+ * be a distinct buffer from `out` (the blurred alpha is sampled while `out` is
18
+ * written). Its contents are undefined after the call.
19
+ *
20
+ * `out` must NOT alias `source.bitmap.data`: `out` is used as the blur scratch,
21
+ * and the source alpha is read again afterward for `inner`/`outer` clipping.
22
+ */
23
+ export declare function bevelBitmap(out: Uint8ClampedArray, scratch: Uint8ClampedArray, source: Readonly<BitmapRegion>, options?: Readonly<BitmapBevelOptions>): void;
24
+ //# sourceMappingURL=bitmapBevel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitmapBevel.d.ts","sourceRoot":"","sources":["../src/bitmapBevel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAIjF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,iBAAiB,EACtB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,EAC9B,OAAO,GAAE,QAAQ,CAAC,kBAAkB,CAAM,GACzC,IAAI,CA+CN"}
@@ -0,0 +1,102 @@
1
+ import { blurBitmapPixelsHorizontal, blurBitmapPixelsVertical } from './bitmapBlur';
2
+ /**
3
+ * Produces a bevel mask in `out`: a tinted highlight on the edge facing the
4
+ * light and a shadow on the opposite edge, derived from the directional
5
+ * gradient of the source's blurred alpha.
6
+ *
7
+ * The edge gradient is `m(p - L) - m(p + L)` where `m` is the blurred alpha and
8
+ * `L = (cos(angle), sin(angle)) * distance`. A positive gradient (edge facing the
9
+ * light) draws the highlight color; a negative gradient draws the shadow color.
10
+ *
11
+ * `type` clips the result: 'inner' keeps it inside the shape, 'outer' outside,
12
+ * 'both' applies no clipping.
13
+ *
14
+ * To complete the effect, composite `out` over the original source.
15
+ *
16
+ * `scratch` must be at least `source.width * source.height * 4` bytes; it must
17
+ * be a distinct buffer from `out` (the blurred alpha is sampled while `out` is
18
+ * written). Its contents are undefined after the call.
19
+ *
20
+ * `out` must NOT alias `source.bitmap.data`: `out` is used as the blur scratch,
21
+ * and the source alpha is read again afterward for `inner`/`outer` clipping.
22
+ */
23
+ export function bevelBitmap(out, scratch, source, options = {}) {
24
+ const w = source.width;
25
+ const h = source.height;
26
+ const angle = options.angle ?? Math.PI / 4;
27
+ const distance = options.distance ?? 4;
28
+ const offsetX = Math.round(Math.cos(angle) * distance);
29
+ const offsetY = Math.round(Math.sin(angle) * distance);
30
+ const type = options.type ?? 'inner';
31
+ const intensity = options.intensity ?? 1;
32
+ const highlightColor = options.highlightColor ?? 0xffffffff;
33
+ const shadowColor = options.shadowColor ?? 0x000000ff;
34
+ // Build the blurred alpha field `m` in scratch, using out as ping-pong buffer.
35
+ for (let py = 0; py < h; py++) {
36
+ for (let px = 0; px < w; px++) {
37
+ const di = (py * w + px) * 4;
38
+ scratch[di] = 0;
39
+ scratch[di + 1] = 0;
40
+ scratch[di + 2] = 0;
41
+ scratch[di + 3] = readSourceAlpha(source, px, py);
42
+ }
43
+ }
44
+ blurField(scratch, out, w, h, options.radiusX, options.radiusY, options.passes);
45
+ for (let py = 0; py < h; py++) {
46
+ for (let px = 0; px < w; px++) {
47
+ const di = (py * w + px) * 4;
48
+ const lit = sampleField(scratch, w, h, px - offsetX, py - offsetY);
49
+ const shade = sampleField(scratch, w, h, px + offsetX, py + offsetY);
50
+ const gradient = lit - shade;
51
+ const color = gradient >= 0 ? highlightColor : shadowColor;
52
+ const colorAlpha = (color & 0xff) / 255;
53
+ const clip = type === 'inner'
54
+ ? readSourceAlpha(source, px, py) / 255
55
+ : type === 'outer'
56
+ ? 1 - readSourceAlpha(source, px, py) / 255
57
+ : 1;
58
+ const edgeIntensity = Math.min(1, Math.abs(gradient) * intensity);
59
+ out[di] = (color >>> 24) & 0xff;
60
+ out[di + 1] = (color >> 16) & 0xff;
61
+ out[di + 2] = (color >> 8) & 0xff;
62
+ out[di + 3] = Math.round(edgeIntensity * colorAlpha * clip * 255);
63
+ }
64
+ }
65
+ }
66
+ function blurField(field, scratch, w, h, radiusX, radiusY, passes) {
67
+ const rx = Math.max(0, Math.round(radiusX ?? 2));
68
+ const ry = Math.max(0, Math.round(radiusY ?? 2));
69
+ const p = Math.max(1, Math.round(passes ?? 1));
70
+ let a = field;
71
+ let b = scratch;
72
+ for (let pass = 0; pass < p; pass++) {
73
+ if (rx > 0) {
74
+ blurBitmapPixelsHorizontal(b, a, w, h, rx);
75
+ const t = a;
76
+ a = b;
77
+ b = t;
78
+ }
79
+ if (ry > 0) {
80
+ blurBitmapPixelsVertical(b, a, w, h, ry);
81
+ const t = a;
82
+ a = b;
83
+ b = t;
84
+ }
85
+ }
86
+ if (a !== field)
87
+ field.set(a.subarray(0, w * h * 4));
88
+ }
89
+ function readSourceAlpha(source, px, py) {
90
+ const sx = source.x + px;
91
+ const sy = source.y + py;
92
+ if (sx < 0 || sx >= source.bitmap.width || sy < 0 || sy >= source.bitmap.height)
93
+ return 0;
94
+ return source.bitmap.data[(sy * source.bitmap.width + sx) * 4 + 3];
95
+ }
96
+ // Returns the blurred alpha at (x, y) normalized to 0..1; 0 outside the field.
97
+ function sampleField(field, w, h, x, y) {
98
+ if (x < 0 || x >= w || y < 0 || y >= h)
99
+ return 0;
100
+ return field[(y * w + x) * 4 + 3] / 255;
101
+ }
102
+ //# sourceMappingURL=bitmapBevel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitmapBevel.js","sourceRoot":"","sources":["../src/bitmapBevel.ts"],"names":[],"mappings":"AAEA,OAAO,E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AAG,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,+EAA+E;AAC/E,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,57 @@
1
+ import type { BitmapBoxBlurOptions, BitmapRegion } from '@flighthq/types/contract';
2
+ /**
3
+ * Single horizontal box blur pass using a sliding-window accumulator — O(n)
4
+ * per row regardless of radius. Reads from `source`, writes to `out`.
5
+ * `out` must not alias `source`.
6
+ */
7
+ export declare function blurBitmapPixelsHorizontal(out: Uint8ClampedArray, source: Readonly<Uint8ClampedArray>, width: number, height: number, radius: number): void;
8
+ /**
9
+ * Single horizontal weighted blur pass. Kernel weights are applied at each
10
+ * position; `kernel.length` must be odd (2 * radius + 1). Reads from
11
+ * `source`, writes to `out`. `out` must not alias `source`.
12
+ */
13
+ export declare function blurBitmapPixelsHorizontalWeighted(out: Uint8ClampedArray, source: Readonly<Uint8ClampedArray>, width: number, height: number, kernel: Readonly<Float32Array>): void;
14
+ /**
15
+ * Single vertical box blur pass using a sliding-window accumulator — O(n)
16
+ * per column regardless of radius. Reads from `source`, writes to `out`.
17
+ * `out` must not alias `source`.
18
+ */
19
+ export declare function blurBitmapPixelsVertical(out: Uint8ClampedArray, source: Readonly<Uint8ClampedArray>, width: number, height: number, radius: number): void;
20
+ /**
21
+ * Single vertical weighted blur pass. Kernel weights are applied at each
22
+ * position; `kernel.length` must be odd (2 * radius + 1). Reads from
23
+ * `source`, writes to `out`. `out` must not alias `source`.
24
+ */
25
+ export declare function blurBitmapPixelsVerticalWeighted(out: Uint8ClampedArray, source: Readonly<Uint8ClampedArray>, width: number, height: number, kernel: Readonly<Float32Array>): void;
26
+ /**
27
+ * Applies a box blur to `source` and writes the result into `out`.
28
+ * `scratch` is a ping-pong buffer; its contents are undefined after the
29
+ * call. Both must be at least `source.width * source.height * 4` bytes.
30
+ *
31
+ * `radiusX` and `radiusY` are the blur radius in pixels (default 2). `passes`
32
+ * repeats the H+V pass pair (default 1); multiple passes approximate a Gaussian.
33
+ *
34
+ * Safe to pass `source.bitmap.data` as `out` when the region covers the
35
+ * full bitmap.
36
+ */
37
+ export declare function boxBlurBitmap(out: Uint8ClampedArray, scratch: Uint8ClampedArray, source: Readonly<BitmapRegion>, options?: Readonly<BitmapBoxBlurOptions>): void;
38
+ /**
39
+ * Fills `out` with a normalized 1-D Gaussian kernel of length `2 * radius + 1`.
40
+ * `out` must be a `Float32Array` of exactly that length. Caller allocates once
41
+ * and reuses across frames.
42
+ */
43
+ export declare function computeGaussianKernel(out: Float32Array, radius: number, sigma: number): void;
44
+ /**
45
+ * Applies a Gaussian blur to `source` and writes the result into `out`.
46
+ * `scratch` is a ping-pong buffer; its contents are undefined after the
47
+ * call. Both must be at least `source.width * source.height * 4` bytes.
48
+ *
49
+ * `sigmaX` and `sigmaY` are the standard deviation of the Gaussian (CSS
50
+ * `blur(Xpx)` uses sigma = X). `sigmaY` defaults to `sigmaX`. `passes`
51
+ * repeats the H+V pass pair (default 1).
52
+ *
53
+ * Safe to pass `source.bitmap.data` as `out` when the region covers the
54
+ * full bitmap.
55
+ */
56
+ export declare function gaussianBlurBitmap(out: Uint8ClampedArray, scratch: Uint8ClampedArray, source: Readonly<BitmapRegion>, sigmaX: number, sigmaY?: number, passes?: number): void;
57
+ //# sourceMappingURL=bitmapBlur.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitmapBlur.d.ts","sourceRoot":"","sources":["../src/bitmapBlur.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EA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