pixel-data-js 0.27.0 → 0.28.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.
Files changed (139) hide show
  1. package/README.md +12 -2
  2. package/dist/index.prod.cjs +2222 -1045
  3. package/dist/index.prod.cjs.map +1 -1
  4. package/dist/index.prod.d.ts +542 -417
  5. package/dist/index.prod.js +2167 -1024
  6. package/dist/index.prod.js.map +1 -1
  7. package/package.json +11 -11
  8. package/src/Algorithm/floodFillSelection.ts +8 -6
  9. package/src/Algorithm/forEachLinePoint.ts +6 -6
  10. package/src/{Internal/resample32.ts → Algorithm/resampleUint32Array.ts} +11 -21
  11. package/src/BlendModes/blend-modes-fast.ts +169 -0
  12. package/src/BlendModes/blend-modes-perfect.ts +207 -0
  13. package/src/BlendModes/blend-modes.ts +9 -0
  14. package/src/Canvas/CanvasFrameRenderer.ts +20 -28
  15. package/src/Canvas/CanvasPixelDataRenderer.ts +23 -0
  16. package/src/Canvas/PixelCanvas.ts +2 -7
  17. package/src/Canvas/ReusableCanvas.ts +4 -12
  18. package/src/Canvas/_canvas-types.ts +26 -0
  19. package/src/History/PixelAccumulator.ts +17 -17
  20. package/src/History/PixelEngineConfig.ts +3 -3
  21. package/src/History/PixelMutator/mutatorApplyAlphaMask.ts +4 -3
  22. package/src/History/PixelMutator/mutatorApplyBinaryMask.ts +4 -3
  23. package/src/History/PixelMutator/mutatorApplyMask.ts +4 -3
  24. package/src/History/PixelMutator/mutatorBlendAlphaMask.ts +6 -4
  25. package/src/History/PixelMutator/mutatorBlendBinaryMask.ts +6 -4
  26. package/src/History/PixelMutator/mutatorBlendColor.ts +2 -2
  27. package/src/History/PixelMutator/mutatorBlendColorPaintAlphaMask.ts +2 -1
  28. package/src/History/PixelMutator/mutatorBlendColorPaintBinaryMask.ts +2 -1
  29. package/src/History/PixelMutator/mutatorBlendColorPaintMask.ts +3 -1
  30. package/src/History/PixelMutator/mutatorBlendColorPaintRect.ts +3 -3
  31. package/src/History/PixelMutator/mutatorBlendMask.ts +6 -4
  32. package/src/History/PixelMutator/mutatorBlendPixelData.ts +5 -4
  33. package/src/History/PixelMutator/mutatorClear.ts +4 -3
  34. package/src/History/PixelMutator/mutatorFill.ts +5 -4
  35. package/src/History/PixelMutator/mutatorFillBinaryMask.ts +2 -1
  36. package/src/History/PixelMutator/mutatorInvert.ts +2 -2
  37. package/src/History/PixelMutator.ts +1 -1
  38. package/src/History/PixelPatchTiles.ts +7 -7
  39. package/src/History/PixelWriter.ts +12 -63
  40. package/src/ImageData/ImageDataLike.ts +1 -1
  41. package/src/ImageData/_ImageData-types.ts +13 -0
  42. package/src/ImageData/copyImageData.ts +1 -1
  43. package/src/ImageData/extractImageDataBuffer.ts +3 -2
  44. package/src/ImageData/imageDataToUint32Array.ts +18 -0
  45. package/src/ImageData/resampleImageData.ts +3 -3
  46. package/src/ImageData/resizeImageData.ts +1 -1
  47. package/src/ImageData/serialization.ts +1 -1
  48. package/src/ImageData/uInt32ArrayToImageData.ts +1 -1
  49. package/src/ImageData/writeImageData.ts +2 -2
  50. package/src/ImageData/writeImageDataBuffer.ts +2 -2
  51. package/src/IndexedImage/IndexedImage.ts +56 -98
  52. package/src/IndexedImage/_indexedImage-types.ts +18 -0
  53. package/src/IndexedImage/getIndexedImageColorCounts.ts +3 -3
  54. package/src/IndexedImage/indexedImageToAverageColor.ts +1 -1
  55. package/src/IndexedImage/indexedImageToImageData.ts +4 -6
  56. package/src/IndexedImage/resampleIndexedImage.ts +7 -15
  57. package/src/Input/fileToImageData.ts +1 -1
  58. package/src/Internal/_errors.ts +2 -0
  59. package/src/Internal/macros.ts +14 -0
  60. package/src/Mask/AlphaMask.ts +1 -1
  61. package/src/Mask/BinaryMask/makeBinaryMaskFromAlphaMask.ts +23 -0
  62. package/src/Mask/BinaryMask/makeBinaryMaskOutline.ts +88 -0
  63. package/src/Mask/BinaryMask/makeCircleBinaryMaskOutline.ts +104 -0
  64. package/src/Mask/BinaryMask/makeRectBinaryMaskOutline.ts +34 -0
  65. package/src/Mask/BinaryMask.ts +1 -1
  66. package/src/Mask/_mask-types.ts +73 -0
  67. package/src/Mask/applyBinaryMaskToAlphaMask.ts +2 -1
  68. package/src/Mask/copyMask.ts +1 -1
  69. package/src/Mask/extractMask.ts +2 -1
  70. package/src/Mask/extractMaskBuffer.ts +1 -1
  71. package/src/Mask/mergeAlphaMasks.ts +6 -3
  72. package/src/Mask/mergeBinaryMasks.ts +2 -1
  73. package/src/Mask/setMaskData.ts +1 -1
  74. package/src/MaskRect/merge2BinaryMaskRects.ts +2 -2
  75. package/src/MaskRect/mergeBinaryMaskRects.ts +1 -1
  76. package/src/MaskRect/subtractBinaryMaskRects.ts +1 -1
  77. package/src/Paint/AlphaMaskPaintBuffer.ts +339 -0
  78. package/src/Paint/AlphaMaskPaintBufferCanvasRenderer.ts +78 -0
  79. package/src/Paint/BinaryMaskPaintBuffer.ts +254 -0
  80. package/src/Paint/BinaryMaskPaintBufferCanvasRenderer.ts +67 -0
  81. package/src/Paint/{PaintBuffer.ts → ColorPaintBuffer.ts} +148 -77
  82. package/src/Paint/{PaintBufferCanvasRenderer.ts → ColorPaintBufferCanvasRenderer.ts} +6 -5
  83. package/src/Paint/PaintCursorRenderer.ts +117 -0
  84. package/src/Paint/_paint-types.ts +22 -0
  85. package/src/Paint/eachTileInBounds.ts +45 -0
  86. package/src/Paint/makeCirclePaintMask.ts +74 -0
  87. package/src/Paint/makePaintMask.ts +5 -2
  88. package/src/Paint/makeRectFalloffPaintAlphaMask.ts +4 -2
  89. package/src/PixelData/PixelData.ts +15 -19
  90. package/src/PixelData/ReusablePixelData.ts +36 -0
  91. package/src/PixelData/_pixelData-types.ts +17 -0
  92. package/src/PixelData/applyAlphaMaskToPixelData.ts +80 -43
  93. package/src/PixelData/applyBinaryMaskToPixelData.ts +10 -8
  94. package/src/PixelData/applyMaskToPixelData.ts +4 -9
  95. package/src/PixelData/blendColorPixelData.ts +9 -8
  96. package/src/PixelData/blendColorPixelDataAlphaMask.ts +9 -7
  97. package/src/PixelData/blendColorPixelDataBinaryMask.ts +9 -7
  98. package/src/PixelData/blendColorPixelDataMask.ts +4 -2
  99. package/src/PixelData/blendColorPixelDataPaintAlphaMask.ts +4 -2
  100. package/src/PixelData/blendColorPixelDataPaintBinaryMask.ts +4 -2
  101. package/src/PixelData/blendColorPixelDataPaintMask.ts +5 -2
  102. package/src/PixelData/blendPixel.ts +6 -5
  103. package/src/PixelData/blendPixelData.ts +14 -13
  104. package/src/PixelData/blendPixelDataAlphaMask.ts +15 -13
  105. package/src/PixelData/blendPixelDataBinaryMask.ts +15 -13
  106. package/src/PixelData/blendPixelDataMask.ts +5 -3
  107. package/src/PixelData/blendPixelDataPaintBuffer.ts +5 -4
  108. package/src/PixelData/clearPixelDataFast.ts +4 -2
  109. package/src/PixelData/copyPixelData.ts +14 -0
  110. package/src/PixelData/extractPixelData.ts +8 -7
  111. package/src/PixelData/extractPixelDataBuffer.ts +9 -8
  112. package/src/PixelData/fillPixelData.ts +16 -14
  113. package/src/PixelData/fillPixelDataBinaryMask.ts +10 -8
  114. package/src/PixelData/fillPixelDataFast.ts +16 -14
  115. package/src/PixelData/invertPixelData.ts +9 -8
  116. package/src/PixelData/pixelDataToAlphaMask.ts +9 -8
  117. package/src/PixelData/reflectPixelData.ts +9 -9
  118. package/src/PixelData/resamplePixelData.ts +20 -9
  119. package/src/PixelData/rotatePixelData.ts +8 -7
  120. package/src/PixelData/uInt32ArrayToPixelData.ts +15 -0
  121. package/src/PixelData/writePaintBufferToPixelData.ts +5 -5
  122. package/src/PixelData/writePixelDataBuffer.ts +10 -9
  123. package/src/Rect/_rect-types.ts +7 -0
  124. package/src/Rect/getRectsBounds.ts +1 -1
  125. package/src/Rect/trimMaskRectBounds.ts +2 -1
  126. package/src/Rect/trimRectBounds.ts +1 -1
  127. package/src/Tile/MaskTile.ts +40 -0
  128. package/src/Tile/PixelTile.ts +23 -0
  129. package/src/{PixelTile/PixelTilePool.ts → Tile/TilePool.ts} +9 -9
  130. package/src/Tile/_tile-types.ts +33 -0
  131. package/src/_errors.ts +1 -0
  132. package/src/_types.ts +2 -118
  133. package/src/index.ts +46 -21
  134. package/src/ImageData/imageDataToUInt32Array.ts +0 -13
  135. package/src/Internal/helpers.ts +0 -5
  136. package/src/Paint/makeCirclePaintAlphaMask.ts +0 -41
  137. package/src/Paint/makeCirclePaintBinaryMask.ts +0 -29
  138. package/src/PixelTile/PixelTile.ts +0 -21
  139. /package/src/{Internal → Rect}/resolveClipping.ts +0 -0
@@ -1,40 +1,12 @@
1
- /** ALL values are 0-255 (including alpha which in CSS is 0-1) */
2
- type RGBA = {
3
- r: number;
4
- g: number;
5
- b: number;
6
- a: number;
7
- };
8
- /** Represents a 32-bit color in 0xAABBGGRR (Little endian) */
9
- type Color32 = number & {
10
- readonly __brandColor32: unique symbol;
11
- };
12
- /**
13
- * A function that defines how to combine a source color with a destination color.
14
- * @param src - The incoming color (source).
15
- * @param dst - The existing color in the buffer (destination).
16
- * @returns The resulting 32-bit color to be written to the buffer.
17
- */
18
- type BlendColor32 = {
19
- (src: Color32, dst: Color32): Color32;
20
- isOverwrite?: true;
21
- };
22
- type ImageDataLike = {
23
- width: number;
24
- height: number;
25
- data: Uint8ClampedArray<ArrayBufferLike>;
26
- };
27
- type ImageDataLikeConstructor<T extends ImageDataLike = ImageDataLike> = {
28
- new (data: Uint8ClampedArray, width: number, height: number): T;
29
- };
30
- type SerializedImageData = {
31
- width: number;
32
- height: number;
33
- data: string;
34
- };
35
- type Base64EncodedUInt8Array = string & {
36
- readonly __brandBase64UInt8Array: unique symbol;
37
- };
1
+ declare const OFFSCREEN_CANVAS_CTX_FAILED = "Failed to create OffscreenCanvas context";
2
+ declare const CANVAS_CTX_FAILED = "Failed to create Canvas context";
3
+
4
+ declare const _errors_CANVAS_CTX_FAILED: typeof CANVAS_CTX_FAILED;
5
+ declare const _errors_OFFSCREEN_CANVAS_CTX_FAILED: typeof OFFSCREEN_CANVAS_CTX_FAILED;
6
+ declare namespace _errors {
7
+ export { _errors_CANVAS_CTX_FAILED as CANVAS_CTX_FAILED, _errors_OFFSCREEN_CANVAS_CTX_FAILED as OFFSCREEN_CANVAS_CTX_FAILED };
8
+ }
9
+
38
10
  /** Rectangle definition */
39
11
  type Rect = {
40
12
  x: number;
@@ -42,6 +14,7 @@ type Rect = {
42
14
  w: number;
43
15
  h: number;
44
16
  };
17
+
45
18
  /**
46
19
  * Defines how mask values should be interpreted during a draw operation.
47
20
  */
@@ -72,15 +45,58 @@ interface BinaryMask extends BaseMask {
72
45
  interface AlphaMask extends BaseMask {
73
46
  readonly type: MaskType.ALPHA;
74
47
  }
75
- interface BasePaintMask {
76
- readonly centerOffsetX: number;
77
- readonly centerOffsetY: number;
48
+ interface MutableMask<T extends MaskType> {
49
+ readonly type: T;
50
+ data: Uint8Array;
51
+ w: number;
52
+ h: number;
78
53
  }
79
- interface PaintAlphaMask extends BasePaintMask, AlphaMask {
54
+ interface MutableAlphaMask extends MutableMask<MaskType.ALPHA> {
80
55
  }
81
- interface PaintBinaryMask extends BasePaintMask, BinaryMask {
56
+ interface MutableBinaryMask extends MutableMask<MaskType.BINARY> {
82
57
  }
83
- type PaintMask = PaintAlphaMask | PaintBinaryMask;
58
+ type MaskRect<T extends MaskType> = Rect & {
59
+ type: T;
60
+ data: Uint8Array;
61
+ };
62
+ type BinaryMaskRect = MaskRect<MaskType.BINARY>;
63
+ type AlphaMaskRect = MaskRect<MaskType.ALPHA>;
64
+ type NullableBinaryMaskRect = Rect & ({
65
+ type: MaskType.BINARY;
66
+ data: Uint8Array;
67
+ } | {
68
+ type?: null;
69
+ data?: null;
70
+ });
71
+ type NullableMaskRect = Rect & ({
72
+ type: MaskType;
73
+ data: Uint8Array;
74
+ } | {
75
+ type?: null;
76
+ data?: null;
77
+ });
78
+
79
+ /** ALL values are 0-255 (including alpha which in CSS is 0-1) */
80
+ type RGBA = {
81
+ r: number;
82
+ g: number;
83
+ b: number;
84
+ a: number;
85
+ };
86
+ /** Represents a 32-bit color in 0xAABBGGRR (Little endian) */
87
+ type Color32 = number & {
88
+ readonly __brandColor32: unique symbol;
89
+ };
90
+ /**
91
+ * A function that defines how to combine a source color with a destination color.
92
+ * @param src - The incoming color (source).
93
+ * @param dst - The existing color in the buffer (destination).
94
+ * @returns The resulting 32-bit color to be written to the buffer.
95
+ */
96
+ type BlendColor32 = {
97
+ (src: Color32, dst: Color32): Color32;
98
+ isOverwrite?: true;
99
+ };
84
100
  /**
85
101
  * Configuration for pixel manipulation operations.
86
102
  * Designed to be used by spreading a Rect object ({x, y, w, h}) directly.
@@ -177,44 +193,33 @@ interface ColorBlendOptions extends PixelRect, Alpha {
177
193
  }
178
194
  interface ColorBlendMaskOptions extends ColorBlendOptions, MaskOffset, InvertMask {
179
195
  }
180
- interface ColorBlendPaintMaskOptions extends Omit<ColorBlendOptions, 'w' | 'h'> {
196
+
197
+ interface ImageDataLike {
198
+ width: number;
199
+ height: number;
200
+ data: Uint8ClampedArray<ArrayBufferLike>;
181
201
  }
182
- type MaskRect<T extends MaskType> = Rect & {
183
- type: T;
184
- data: Uint8Array;
202
+ type SerializedImageData = {
203
+ width: number;
204
+ height: number;
205
+ data: string;
185
206
  };
186
- type BinaryMaskRect = MaskRect<MaskType.BINARY>;
187
- type AlphaMaskRect = MaskRect<MaskType.ALPHA>;
188
- type NullableBinaryMaskRect = Rect & ({
189
- type: MaskType.BINARY;
190
- data: Uint8Array;
191
- } | {
192
- type?: null;
193
- data?: null;
194
- });
195
- type NullableMaskRect = Rect & ({
196
- type: MaskType;
197
- data: Uint8Array;
198
- } | {
199
- type?: null;
200
- data?: null;
201
- });
202
- interface IPixelData32 {
203
- readonly data32: Uint32Array;
204
- readonly width: number;
205
- readonly height: number;
207
+ type Base64EncodedUInt8Array = string & {
208
+ readonly __brandBase64UInt8Array: unique symbol;
209
+ };
210
+
211
+ interface PixelData32 {
212
+ readonly data: Uint32Array;
213
+ readonly w: number;
214
+ readonly h: number;
206
215
  }
207
- interface IPixelData<T extends ImageDataLike = ImageData> extends IPixelData32 {
208
- readonly imageData: T;
216
+ interface MutablePixelData32 {
217
+ data: Uint32Array;
218
+ w: number;
219
+ h: number;
209
220
  }
210
-
211
- declare class PixelData<T extends ImageDataLike = ImageData> implements IPixelData<T> {
212
- readonly data32: Uint32Array;
221
+ interface PixelData<T extends ImageDataLike = ImageData> extends PixelData32 {
213
222
  readonly imageData: T;
214
- readonly width: number;
215
- readonly height: number;
216
- constructor(imageData: T);
217
- set(imageData: T): void;
218
223
  }
219
224
 
220
225
  type FloodFillResult = BinaryMaskRect & {
@@ -223,7 +228,7 @@ type FloodFillResult = BinaryMaskRect & {
223
228
  pixels: Uint8ClampedArray;
224
229
  };
225
230
  /**
226
- * Performs a color-based flood fill selection on {@link ImageData} or {@link PixelData}.
231
+ * Performs a color-based flood fill selection {@link PixelData}.
227
232
  * This utility identifies pixels starting from a specific coordinate that fall within a
228
233
  * color tolerance. It can operate in "contiguous" mode (classic bucket fill) or
229
234
  * "non-contiguous" mode (selects all matching pixels in the buffer).
@@ -261,51 +266,17 @@ declare function floodFillSelection(target: PixelData, startX: number, startY: n
261
266
  */
262
267
  declare function forEachLinePoint(x0: number, y0: number, x1: number, y1: number, callback: (x: number, y: number) => void): void;
263
268
 
264
- declare const BaseBlendMode: {
265
- readonly overwrite: 0;
266
- readonly sourceOver: 1;
267
- readonly darken: 2;
268
- readonly multiply: 3;
269
- readonly colorBurn: 4;
270
- readonly linearBurn: 5;
271
- readonly darkerColor: 6;
272
- readonly lighten: 7;
273
- readonly screen: 8;
274
- readonly colorDodge: 9;
275
- readonly linearDodge: 10;
276
- readonly lighterColor: 11;
277
- readonly overlay: 12;
278
- readonly softLight: 13;
279
- readonly hardLight: 14;
280
- readonly vividLight: 15;
281
- readonly linearLight: 16;
282
- readonly pinLight: 17;
283
- readonly hardMix: 18;
284
- readonly difference: 19;
285
- readonly exclusion: 20;
286
- readonly subtract: 21;
287
- readonly divide: 22;
288
- };
289
- interface RequiredBlendModes {
290
- overwrite: 0;
291
- }
292
- type BaseBlendModes = RequiredBlendModes & Record<string, number>;
293
- declare const overwriteBase: BlendColor32;
294
-
295
- type BlendModeRegistry<BlendModes extends BaseBlendModes = BaseBlendModes, Name extends keyof BlendModes = keyof BlendModes, Index extends BlendModes[Name] = BlendModes[Name]> = ReturnType<typeof makeBlendModeRegistry<BlendModes, Name, Index>>;
296
- declare function makeBlendModeRegistry<BlendModes extends BaseBlendModes, Name extends keyof BlendModes = keyof BlendModes, Index extends BlendModes[Name] = BlendModes[Name]>(blendModes: BlendModes, initialEntries: Record<Index, BlendColor32>, registryName?: string): {
297
- registryName: string;
298
- nameToBlend: { [K in keyof BlendModes]: BlendColor32; };
299
- nameToIndex: Record<Name, Index>;
300
- blendToIndex: Map<BlendColor32, Index>;
301
- blendToName: Map<BlendColor32, Name>;
302
- indexToBlend: BlendColor32[];
303
- indexToName: Name[];
304
- indexType: Index;
305
- nameType: Name;
306
- };
269
+ declare function resampleUint32Array<T extends PixelData32, M extends MutablePixelData32>(srcData32: Uint32Array, srcW: number, srcH: number, factor: number, out?: M): T;
307
270
 
308
271
  declare const overwriteFast: BlendColor32;
272
+ declare const sourceInFast: BlendColor32;
273
+ declare const sourceOutFast: BlendColor32;
274
+ declare const sourceAtopFast: BlendColor32;
275
+ declare const destinationOverFast: BlendColor32;
276
+ declare const destinationInFast: BlendColor32;
277
+ declare const destinationOutFast: BlendColor32;
278
+ declare const destinationAtopFast: BlendColor32;
279
+ declare const xorFast: BlendColor32;
309
280
  declare const sourceOverFast: BlendColor32;
310
281
  declare const darkenFast: BlendColor32;
311
282
  /** (src * dst) / 255 */
@@ -378,17 +349,33 @@ declare function makeFastBlendModeRegistry(name?: string): {
378
349
  readonly exclusion: BlendColor32;
379
350
  readonly subtract: BlendColor32;
380
351
  readonly divide: BlendColor32;
352
+ readonly sourceIn: BlendColor32;
353
+ readonly sourceOut: BlendColor32;
354
+ readonly sourceAtop: BlendColor32;
355
+ readonly destinationOver: BlendColor32;
356
+ readonly destinationIn: BlendColor32;
357
+ readonly destinationOut: BlendColor32;
358
+ readonly destinationAtop: BlendColor32;
359
+ readonly xor: BlendColor32;
381
360
  };
382
- nameToIndex: Record<"overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide", 0 | 2 | 16 | 8 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22>;
383
- blendToIndex: Map<BlendColor32, 0 | 2 | 16 | 8 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22>;
384
- blendToName: Map<BlendColor32, "overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide">;
361
+ nameToIndex: Record<"overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide" | "sourceIn" | "sourceOut" | "sourceAtop" | "destinationOver" | "destinationIn" | "destinationOut" | "destinationAtop" | "xor", 0 | 24 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30>;
362
+ blendToIndex: Map<BlendColor32, 0 | 24 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30>;
363
+ blendToName: Map<BlendColor32, "overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide" | "sourceIn" | "sourceOut" | "sourceAtop" | "destinationOver" | "destinationIn" | "destinationOut" | "destinationAtop" | "xor">;
385
364
  indexToBlend: BlendColor32[];
386
- indexToName: ("overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide")[];
387
- indexType: 0 | 2 | 16 | 8 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22;
388
- nameType: "overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide";
365
+ indexToName: ("overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide" | "sourceIn" | "sourceOut" | "sourceAtop" | "destinationOver" | "destinationIn" | "destinationOut" | "destinationAtop" | "xor")[];
366
+ indexType: 0 | 24 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30;
367
+ nameType: "overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide" | "sourceIn" | "sourceOut" | "sourceAtop" | "destinationOver" | "destinationIn" | "destinationOut" | "destinationAtop" | "xor";
389
368
  };
390
369
 
391
370
  declare const overwritePerfect: BlendColor32;
371
+ declare const sourceInPerfect: BlendColor32;
372
+ declare const sourceOutPerfect: BlendColor32;
373
+ declare const sourceAtopPerfect: BlendColor32;
374
+ declare const destinationOverPerfect: BlendColor32;
375
+ declare const destinationInPerfect: BlendColor32;
376
+ declare const destinationOutPerfect: BlendColor32;
377
+ declare const destinationAtopPerfect: BlendColor32;
378
+ declare const xorPerfect: BlendColor32;
392
379
  declare const sourceOverPerfect: BlendColor32;
393
380
  declare const darkenPerfect: BlendColor32;
394
381
  /** (src * dst) / 255 */
@@ -461,14 +448,74 @@ declare function makePerfectBlendModeRegistry(name?: string): {
461
448
  readonly exclusion: BlendColor32;
462
449
  readonly subtract: BlendColor32;
463
450
  readonly divide: BlendColor32;
451
+ readonly sourceIn: BlendColor32;
452
+ readonly sourceOut: BlendColor32;
453
+ readonly sourceAtop: BlendColor32;
454
+ readonly destinationOver: BlendColor32;
455
+ readonly destinationIn: BlendColor32;
456
+ readonly destinationOut: BlendColor32;
457
+ readonly destinationAtop: BlendColor32;
458
+ readonly xor: BlendColor32;
464
459
  };
465
- nameToIndex: Record<"overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide", 0 | 2 | 16 | 8 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22>;
466
- blendToIndex: Map<BlendColor32, 0 | 2 | 16 | 8 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22>;
467
- blendToName: Map<BlendColor32, "overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide">;
460
+ nameToIndex: Record<"overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide" | "sourceIn" | "sourceOut" | "sourceAtop" | "destinationOver" | "destinationIn" | "destinationOut" | "destinationAtop" | "xor", 0 | 24 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30>;
461
+ blendToIndex: Map<BlendColor32, 0 | 24 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30>;
462
+ blendToName: Map<BlendColor32, "overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide" | "sourceIn" | "sourceOut" | "sourceAtop" | "destinationOver" | "destinationIn" | "destinationOut" | "destinationAtop" | "xor">;
468
463
  indexToBlend: BlendColor32[];
469
- indexToName: ("overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide")[];
470
- indexType: 0 | 2 | 16 | 8 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22;
471
- nameType: "overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide";
464
+ indexToName: ("overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide" | "sourceIn" | "sourceOut" | "sourceAtop" | "destinationOver" | "destinationIn" | "destinationOut" | "destinationAtop" | "xor")[];
465
+ indexType: 0 | 24 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30;
466
+ nameType: "overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide" | "sourceIn" | "sourceOut" | "sourceAtop" | "destinationOver" | "destinationIn" | "destinationOut" | "destinationAtop" | "xor";
467
+ };
468
+
469
+ declare const BaseBlendMode: {
470
+ readonly overwrite: 0;
471
+ readonly sourceOver: 1;
472
+ readonly darken: 2;
473
+ readonly multiply: 3;
474
+ readonly colorBurn: 4;
475
+ readonly linearBurn: 5;
476
+ readonly darkerColor: 6;
477
+ readonly lighten: 7;
478
+ readonly screen: 8;
479
+ readonly colorDodge: 9;
480
+ readonly linearDodge: 10;
481
+ readonly lighterColor: 11;
482
+ readonly overlay: 12;
483
+ readonly softLight: 13;
484
+ readonly hardLight: 14;
485
+ readonly vividLight: 15;
486
+ readonly linearLight: 16;
487
+ readonly pinLight: 17;
488
+ readonly hardMix: 18;
489
+ readonly difference: 19;
490
+ readonly exclusion: 20;
491
+ readonly subtract: 21;
492
+ readonly divide: 22;
493
+ readonly sourceIn: 23;
494
+ readonly sourceOut: 24;
495
+ readonly sourceAtop: 25;
496
+ readonly destinationOver: 26;
497
+ readonly destinationIn: 27;
498
+ readonly destinationOut: 28;
499
+ readonly destinationAtop: 29;
500
+ readonly xor: 30;
501
+ };
502
+ interface RequiredBlendModes {
503
+ overwrite: 0;
504
+ }
505
+ type BaseBlendModes = RequiredBlendModes & Record<string, number>;
506
+ declare const overwriteBase: BlendColor32;
507
+
508
+ type BlendModeRegistry<BlendModes extends BaseBlendModes = BaseBlendModes, Name extends keyof BlendModes = keyof BlendModes, Index extends BlendModes[Name] = BlendModes[Name]> = ReturnType<typeof makeBlendModeRegistry<BlendModes, Name, Index>>;
509
+ declare function makeBlendModeRegistry<BlendModes extends BaseBlendModes, Name extends keyof BlendModes = keyof BlendModes, Index extends BlendModes[Name] = BlendModes[Name]>(blendModes: BlendModes, initialEntries: Record<Index, BlendColor32>, registryName?: string): {
510
+ registryName: string;
511
+ nameToBlend: { [K in keyof BlendModes]: BlendColor32; };
512
+ nameToIndex: Record<Name, Index>;
513
+ blendToIndex: Map<BlendColor32, Index>;
514
+ blendToName: Map<BlendColor32, Name>;
515
+ indexToBlend: BlendColor32[];
516
+ indexToName: Name[];
517
+ indexType: Index;
518
+ nameType: Name;
472
519
  };
473
520
 
474
521
  declare function toBlendModeIndexAndName(input: string | number): {
@@ -476,56 +523,23 @@ declare function toBlendModeIndexAndName(input: string | number): {
476
523
  blendName: string;
477
524
  };
478
525
 
479
- type PixelCanvas = {
480
- readonly canvas: HTMLCanvasElement;
481
- readonly ctx: CanvasRenderingContext2D;
482
- readonly resize: (w: number, h: number) => void;
483
- };
484
- /**
485
- * Ensures the canvas ctx is always set to imageSmoothingEnabled = false.
486
- * Intended for canvas elements that are already part of the DOM.
487
- * @see makeReusableCanvas
488
- * @throws {Error} If the {@link HTMLCanvasElement} context cannot be initialized.
489
- */
490
- declare function makePixelCanvas(canvas: HTMLCanvasElement): PixelCanvas;
491
-
492
526
  type CanvasContext<T> = T extends HTMLCanvasElement ? CanvasRenderingContext2D : OffscreenCanvasRenderingContext2D;
493
- type ReusableCanvas<T extends HTMLCanvasElement | OffscreenCanvas> = {
527
+ interface ReusableCanvas<T extends HTMLCanvasElement | OffscreenCanvas> {
494
528
  readonly canvas: T;
495
529
  readonly ctx: CanvasContext<T>;
496
- };
497
- /**
498
- * Creates a reusable HTMLCanvasElement and context that are not part of the DOM.
499
- * Ensures it is always set to `context.imageSmoothingEnabled = false`
500
- * @see makePixelCanvas
501
- * @throws {Error} If the {@link HTMLCanvasElement} context cannot be initialized.
502
- */
503
- declare function makeReusableCanvas(): {
504
- (width: number, height: number): ReusableCanvas<HTMLCanvasElement>;
505
- reset(): void;
506
- };
507
- /**
508
- * Creates a reusable OffscreenCanvas and context.
509
- * Ensures it is always set to `context.imageSmoothingEnabled = false`
510
- * @see makePixelCanvas
511
- * @throws {Error} If the {@link OffscreenCanvasRenderingContext2D} context cannot be initialized.
512
- */
513
- declare function makeReusableOffscreenCanvas(): {
514
- (width: number, height: number): ReusableCanvas<OffscreenCanvas>;
530
+ }
531
+ type ReusableCanvasFactory<T extends HTMLCanvasElement | OffscreenCanvas> = {
532
+ (w: number, h: number): ReusableCanvas<T>;
515
533
  reset(): void;
516
534
  };
517
-
518
- type DrawPixelLayer = (ctx: CanvasRenderingContext2D) => void;
535
+ type DrawPixelLayer<T extends HTMLCanvasElement | OffscreenCanvas> = (ctx: CanvasContext<T>) => void;
519
536
  type DrawScreenLayer = (ctx: CanvasRenderingContext2D, scale: number) => void;
520
- type CanvasFrameRenderer = ReturnType<typeof makeCanvasFrameRenderer>;
521
- declare const defaults$h: {
522
- makeReusableCanvas: typeof makeReusableCanvas;
523
- };
524
- type Deps$h = Partial<typeof defaults$h>;
525
- /**
526
- * @param deps - @hidden
527
- */
528
- declare function makeCanvasFrameRenderer(deps?: Deps$h): (pixelCanvas: PixelCanvas, scale: number, getImageData: () => ImageData | undefined | null, drawPixelLayer?: DrawPixelLayer, drawScreenLayer?: DrawScreenLayer) => void;
537
+ interface PixelCanvas {
538
+ readonly canvas: HTMLCanvasElement;
539
+ readonly ctx: CanvasRenderingContext2D;
540
+ readonly resize: (w: number, h: number) => void;
541
+ }
542
+ type CanvasObjectFactory<T extends HTMLCanvasElement | OffscreenCanvas> = (w: number, h: number) => T;
529
543
 
530
544
  declare const CANVAS_COMPOSITE_MAP: {
531
545
  readonly 0: "copy";
@@ -546,6 +560,35 @@ declare const CANVAS_COMPOSITE_MAP: {
546
560
  type CanvasBlendModeIndex = keyof typeof CANVAS_COMPOSITE_MAP;
547
561
  type CanvasCompositeOperation = typeof CANVAS_COMPOSITE_MAP[CanvasBlendModeIndex];
548
562
 
563
+ type CanvasFrameRenderer<T extends HTMLCanvasElement | OffscreenCanvas = OffscreenCanvas> = ReturnType<typeof makeCanvasFrameRenderer<T>>;
564
+ declare function makeCanvasFrameRenderer<T extends HTMLCanvasElement | OffscreenCanvas = OffscreenCanvas>(reusableCanvasFactory?: () => ReusableCanvasFactory<T>): (pixelCanvas: PixelCanvas, scale: number, getImageData: () => ImageData | undefined | null, drawPixelLayer?: DrawPixelLayer<T>, drawScreenLayer?: DrawScreenLayer) => void;
565
+
566
+ type CanvasPixelDataRenderer = ReturnType<typeof makeCanvasPixelDataRenderer>;
567
+ declare function makeCanvasPixelDataRenderer<T extends HTMLCanvasElement | OffscreenCanvas = OffscreenCanvas>(reusableCanvasFactory?: () => ReusableCanvasFactory<T>): (targetCtx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, pixelData: PixelData, x?: number, y?: number) => void;
568
+
569
+ /**
570
+ * Ensures the canvas ctx is always set to imageSmoothingEnabled = false.
571
+ * Intended for canvas elements that are already part of the DOM.
572
+ * @see makeReusableCanvas
573
+ * @throws {Error} If the {@link HTMLCanvasElement} context cannot be initialized.
574
+ */
575
+ declare function makePixelCanvas(canvas: HTMLCanvasElement): PixelCanvas;
576
+
577
+ /**
578
+ * Creates a reusable HTMLCanvasElement and context that are not part of the DOM.
579
+ * Ensures it is always set to `context.imageSmoothingEnabled = false`
580
+ * @see makePixelCanvas
581
+ * @throws {Error} If the {@link HTMLCanvasElement} context cannot be initialized.
582
+ */
583
+ declare function makeReusableCanvas(): ReusableCanvasFactory<HTMLCanvasElement>;
584
+ /**
585
+ * Creates a reusable OffscreenCanvas and context.
586
+ * Ensures it is always set to `context.imageSmoothingEnabled = false`
587
+ * @see makePixelCanvas
588
+ * @throws {Error} If the {@link OffscreenCanvasRenderingContext2D} context cannot be initialized.
589
+ */
590
+ declare function makeReusableOffscreenCanvas(): ReusableCanvasFactory<OffscreenCanvas>;
591
+
549
592
  /**
550
593
  * Extracts {@link ImageData} from a clipboard event if an image is present.
551
594
  *
@@ -589,23 +632,72 @@ declare function getImageDataFromClipboard(clipboardEvent: ClipboardEvent): Prom
589
632
  declare function writeImageDataToClipboard(imageData: ImageData): Promise<void>;
590
633
 
591
634
  /**
592
- * Writes a {@link Blob} image to the system clipboard.
593
- *
594
- * @param blob - The image blob (typically `image/png`) to copy.
595
- * @returns A promise that resolves when the clipboard has been updated.
635
+ * Writes a {@link Blob} image to the system clipboard.
636
+ *
637
+ * @param blob - The image blob (typically `image/png`) to copy.
638
+ * @returns A promise that resolves when the clipboard has been updated.
639
+ */
640
+ declare function writeImgBlobToClipboard(blob: Blob): Promise<void>;
641
+
642
+ /**
643
+ * Packs RGBA into a 32-bit integer compatible with
644
+ * Little-Endian Uint32Array views on ImageData.
645
+ */
646
+ declare function packColor(r: number, g: number, b: number, a: number): Color32;
647
+ declare function packRGBA({ r, g, b, a }: RGBA): Color32;
648
+ declare const unpackRed: (packed: Color32) => number;
649
+ declare const unpackGreen: (packed: Color32) => number;
650
+ declare const unpackBlue: (packed: Color32) => number;
651
+ declare const unpackAlpha: (packed: Color32) => number;
652
+ declare function unpackColor(packed: Color32): RGBA;
653
+ declare function unpackColorTo(packed: Color32, scratch?: RGBA): RGBA;
654
+ declare function colorDistance(a: Color32, b: Color32): number;
655
+ /**
656
+ * Linearly interpolates between two 32-bit colors using a floating-point weight.
657
+ * * This is the preferred method for UI animations or scenarios where high
658
+ * precision is required. It uses the standard `a + t * (b - a)` formula
659
+ * for each channel.
660
+ * @param a - The starting color as a 32-bit integer (AABBGGRR).
661
+ * @param b - The target color as a 32-bit integer (AABBGGRR).
662
+ * @param t - The interpolation factor between 0.0 and 1.0.
663
+ * @returns The interpolated 32-bit color.
664
+ */
665
+ declare function lerpColor32(a: Color32, b: Color32, t: number): Color32;
666
+ /**
667
+ * Linearly interpolates between two 32-bit colors using integer fixed-point math.
668
+ * Highly optimized for image processing and real-time blitting. It processes
669
+ * channels in parallel using bitmasks (RB and GA pairs).
670
+ * **Note:** Subject to a 1-bit drift (rounding down) due to fast bit-shift division.
671
+ * @param src - The source (foreground) color as a 32-bit integer.
672
+ * @param dst - The destination (background) color as a 32-bit integer.
673
+ * @param w - The blend weight as a byte value from 0 to 255. Where 0 is 100% dst and 255 is 100% src
674
+ * @returns The blended 32-bit color.
675
+ */ declare function lerpColor32Fast(src: Color32, dst: Color32, w: number): Color32;
676
+ declare function color32ToHex(color: Color32): string;
677
+ /**
678
+ * Converts a 32-bit integer (0xAABBGGRR) to a CSS rgba() string.
679
+ * Example: 0xFF0000FF -> "rgba(255,0,0,1)"
596
680
  */
597
- declare function writeImgBlobToClipboard(blob: Blob): Promise<void>;
681
+ declare function color32ToCssRGBA(color: Color32): string;
598
682
 
599
- declare class PixelTile implements IPixelData {
683
+ declare const enum TileType {
684
+ PIXEL = 0,
685
+ MASK = 1
686
+ }
687
+ interface BaseTile {
688
+ tileType: TileType;
600
689
  id: number;
601
690
  tx: number;
602
691
  ty: number;
603
- readonly data32: Uint32Array;
604
- readonly width: number;
605
- readonly height: number;
606
- readonly imageData: ImageData;
607
- constructor(id: number, tx: number, ty: number, tileSize: number, tileArea: number);
608
692
  }
693
+ interface PixelTile extends PixelData, BaseTile {
694
+ }
695
+ interface AlphaMaskTile extends AlphaMask, BaseTile {
696
+ }
697
+ interface BinaryMaskTile extends BinaryMask, BaseTile {
698
+ }
699
+ type Tile = PixelTile | AlphaMaskTile | BinaryMaskTile;
700
+ type TileFactory<T extends Tile> = (id: number, tx: number, ty: number, tileSize: number, tileArea: number) => T;
609
701
 
610
702
  declare class PixelEngineConfig {
611
703
  readonly tileSize: number;
@@ -618,29 +710,30 @@ declare class PixelEngineConfig {
618
710
  constructor(tileSize: number, target: PixelData);
619
711
  }
620
712
 
621
- declare class PixelTilePool {
622
- pool: PixelTile[];
713
+ declare class TilePool<T extends Tile> {
714
+ private tileFactory;
715
+ pool: T[];
623
716
  private tileSize;
624
717
  private tileArea;
625
- constructor(config: PixelEngineConfig);
626
- getTile(id: number, tx: number, ty: number): PixelTile;
627
- releaseTile(tile: PixelTile): void;
628
- releaseTiles(tiles: (PixelTile | undefined)[]): void;
718
+ constructor(config: PixelEngineConfig, tileFactory: TileFactory<T>);
719
+ getTile(id: number, tx: number, ty: number): T;
720
+ releaseTile(tile: T): void;
721
+ releaseTiles(tiles: (T | undefined)[]): void;
629
722
  }
630
723
 
631
724
  type PixelPatchTiles = {
632
725
  beforeTiles: PixelTile[];
633
726
  afterTiles: PixelTile[];
634
727
  };
635
- declare function applyPatchTiles(target: IPixelData32, tiles: PixelTile[], tileSize: number): void;
728
+ declare function applyPatchTiles(target: PixelData32, tiles: PixelTile[], tileSize: number): void;
636
729
 
637
730
  type DidChangeFn = (didChange: boolean) => boolean;
638
731
  declare class PixelAccumulator {
639
732
  readonly config: PixelEngineConfig;
640
- readonly tilePool: PixelTilePool;
733
+ readonly pixelTilePool: TilePool<PixelTile>;
641
734
  lookup: (PixelTile | undefined)[];
642
735
  beforeTiles: PixelTile[];
643
- constructor(config: PixelEngineConfig, tilePool: PixelTilePool);
736
+ constructor(config: PixelEngineConfig, pixelTilePool: TilePool<PixelTile>);
644
737
  recyclePatch(patch: PixelPatchTiles): void;
645
738
  /**
646
739
  * @param x pixel x coordinate
@@ -715,41 +808,12 @@ declare class HistoryManager {
715
808
  */
716
809
  declare function resizeImageData(target: ImageDataLike, newWidth: number, newHeight: number, offsetX?: number, offsetY?: number): ImageData;
717
810
 
718
- declare class PaintBuffer {
719
- readonly config: PixelEngineConfig;
720
- readonly tilePool: PixelTilePool;
721
- readonly lookup: (PixelTile | undefined)[];
722
- private readonly scratchBounds;
723
- constructor(config: PixelEngineConfig, tilePool: PixelTilePool);
724
- private eachTileInBounds;
725
- writePaintAlphaMaskStroke(color: Color32, brush: PaintAlphaMask, x0: number, y0: number, x1: number, y1: number): boolean;
726
- writePaintBinaryMaskStroke(color: Color32, brush: PaintBinaryMask, x0: number, y0: number, x1: number, y1: number): boolean;
727
- writeRectStroke(color: Color32, brushWidth: number, brushHeight: number, x0: number, y0: number, x1: number, y1: number): boolean;
728
- clear(): void;
729
- }
730
-
731
- /**
732
- * Blits source PixelData into a destination PixelData using 32-bit integer bitwise blending.
733
- * This function bypasses standard ImageData limitations by operating directly on
734
- * Uint32Array views. It supports various blend modes, binary/alpha masking, and
735
- * automatic clipping of both source and destination bounds.
736
- * @example
737
- *
738
- * const dst = new PixelData(ctx.getImageData(0,0,100,100))
739
- * blendImageData32(dst, sprite, {
740
- * blendFn: COLOR_32_BLEND_MODES.multiply,
741
- * mask: brushMask,
742
- * maskType: MaskType.ALPHA
743
- * });
744
- */
745
- declare function blendPixelData(target: IPixelData32, src: IPixelData32, opts?: PixelBlendOptions): boolean;
746
-
747
811
  interface PixelWriterOptions {
748
812
  maxHistorySteps?: number;
749
813
  tileSize?: number;
750
814
  historyManager?: HistoryManager;
751
815
  historyActionFactory?: HistoryActionFactory;
752
- pixelTilePool?: PixelTilePool;
816
+ pixelTilePool?: TilePool<PixelTile>;
753
817
  accumulator?: PixelAccumulator;
754
818
  }
755
819
  /**
@@ -778,10 +842,8 @@ declare class PixelWriter<M> {
778
842
  readonly accumulator: PixelAccumulator;
779
843
  readonly historyActionFactory: HistoryActionFactory;
780
844
  readonly config: PixelEngineConfig;
781
- readonly pixelTilePool: PixelTilePool;
782
- readonly paintBuffer: PaintBuffer;
845
+ readonly pixelTilePool: TilePool<PixelTile>;
783
846
  readonly mutator: M;
784
- private blendPixelDataOpts;
785
847
  private _inProgress;
786
848
  constructor(target: PixelData, mutatorFactory: (writer: PixelWriter<any>) => M, options?: PixelWriterOptions);
787
849
  /**
@@ -801,7 +863,6 @@ declare class PixelWriter<M> {
801
863
  */
802
864
  withHistory(transaction: (mutator: M) => void, after?: () => void, afterUndo?: () => void, afterRedo?: () => void): void;
803
865
  resize(newWidth: number, newHeight: number, offsetX?: number, offsetY?: number, after?: (target: ImageData) => void, afterUndo?: (target: ImageData) => void, afterRedo?: (target: ImageData) => void, resizeImageDataFn?: typeof resizeImageData): void;
804
- commitPaintBuffer(alpha?: number, blendFn?: BlendColor32, blendPixelDataFn?: typeof blendPixelData): void;
805
866
  }
806
867
  type HistoryMutator<T extends {}, D extends {}> = (writer: PixelWriter<any>, deps?: Partial<D>) => T;
807
868
 
@@ -811,16 +872,16 @@ declare function makeFullPixelMutator(writer: PixelWriter<any>): {
811
872
  fillBinaryMask(color: Color32, mask: BinaryMask, x?: number, y?: number): boolean;
812
873
  fill(color: Color32, x?: number, y?: number, w?: number, h?: number): boolean;
813
874
  clear(rect?: Partial<Rect>): boolean;
814
- blendPixelData(src: IPixelData32, opts?: PixelBlendOptions): boolean;
875
+ blendPixelData(src: PixelData32, opts?: PixelBlendOptions): boolean;
815
876
  blendPixel(x: number, y: number, color: Color32, alpha?: number, blendFn?: BlendColor32): boolean;
816
- blendMask(src: IPixelData32, mask: Mask, opts?: PixelBlendMaskOptions): boolean;
877
+ blendMask(src: PixelData32, mask: Mask, opts?: PixelBlendMaskOptions): boolean;
817
878
  blendColorPaintRect(color: Color32, centerX: number, centerY: number, brushWidth: number, brushHeight: number, alpha?: number, blendFn?: BlendColor32): boolean;
818
879
  blendColorPaintMask(color: Color32, mask: PaintMask, x: number, y: number, alpha?: number, blendFn?: BlendColor32): boolean;
819
880
  blendColorPaintBinaryMask(color: Color32, mask: PaintBinaryMask, x: number, y: number, alpha?: number, blendFn?: BlendColor32): boolean;
820
881
  blendColorPaintAlphaMask(color: Color32, mask: PaintAlphaMask, x: number, y: number, alpha?: number, blendFn?: BlendColor32): boolean;
821
882
  blendColor(color: Color32, opts?: ColorBlendOptions): boolean;
822
- blendBinaryMask(src: IPixelData32, mask: BinaryMask, opts?: PixelBlendMaskOptions): boolean;
823
- blendAlphaMask(src: IPixelData32, mask: AlphaMask, opts?: PixelBlendMaskOptions): boolean;
883
+ blendBinaryMask(src: PixelData32, mask: BinaryMask, opts?: PixelBlendMaskOptions): boolean;
884
+ blendAlphaMask(src: PixelData32, mask: AlphaMask, opts?: PixelBlendMaskOptions): boolean;
824
885
  applyMask(mask: Mask, opts?: ApplyMaskToPixelDataOptions): boolean;
825
886
  applyBinaryMask(mask: BinaryMask, opts?: ApplyMaskToPixelDataOptions): boolean;
826
887
  applyAlphaMask(mask: AlphaMask, opts?: ApplyMaskToPixelDataOptions): boolean;
@@ -831,7 +892,7 @@ declare function makeFullPixelMutator(writer: PixelWriter<any>): {
831
892
  * modifying the destination's alpha channel in-place.
832
893
  * @returns true if any pixels were actually modified.
833
894
  */
834
- declare function applyAlphaMaskToPixelData(target: IPixelData32, mask: AlphaMask, opts?: ApplyMaskToPixelDataOptions): boolean;
895
+ declare function applyAlphaMaskToPixelData(target: PixelData32, mask: AlphaMask, opts?: ApplyMaskToPixelDataOptions): boolean;
835
896
 
836
897
  declare const defaults$g: {
837
898
  applyAlphaMaskToPixelData: typeof applyAlphaMaskToPixelData;
@@ -849,7 +910,7 @@ declare const mutatorApplyAlphaMask: (writer: PixelWriter<any>, deps?: Deps$g) =
849
910
  * modifying the destination's alpha channel in-place.
850
911
  * @returns true if any pixels were actually modified.
851
912
  */
852
- declare function applyBinaryMaskToPixelData(target: IPixelData32, mask: BinaryMask, opts?: ApplyMaskToPixelDataOptions): boolean;
913
+ declare function applyBinaryMaskToPixelData(target: PixelData32, mask: BinaryMask, opts?: ApplyMaskToPixelDataOptions): boolean;
853
914
 
854
915
  declare const defaults$f: {
855
916
  applyBinaryMaskToPixelData: typeof applyBinaryMaskToPixelData;
@@ -874,7 +935,7 @@ declare const mutatorApplyMask: (writer: PixelWriter<any>, deps?: Deps$e) => {
874
935
  applyMask(mask: Mask, opts?: ApplyMaskToPixelDataOptions): boolean;
875
936
  };
876
937
 
877
- declare function blendPixelDataAlphaMask(target: IPixelData32, src: IPixelData32, alphaMask: AlphaMask, opts?: PixelBlendMaskOptions): boolean;
938
+ declare function blendPixelDataAlphaMask(target: PixelData32, src: PixelData32, alphaMask: AlphaMask, opts?: PixelBlendMaskOptions): boolean;
878
939
 
879
940
  declare const defaults$d: {
880
941
  blendPixelDataAlphaMask: typeof blendPixelDataAlphaMask;
@@ -884,10 +945,10 @@ type Deps$d = Partial<typeof defaults$d>;
884
945
  * @param deps - @hidden
885
946
  */
886
947
  declare const mutatorBlendAlphaMask: (writer: PixelWriter<any>, deps?: Partial<Deps$d>) => {
887
- blendAlphaMask(src: IPixelData32, mask: AlphaMask, opts?: PixelBlendMaskOptions): boolean;
948
+ blendAlphaMask(src: PixelData32, mask: AlphaMask, opts?: PixelBlendMaskOptions): boolean;
888
949
  };
889
950
 
890
- declare function blendPixelDataBinaryMask(target: IPixelData32, src: IPixelData32, binaryMask: BinaryMask, opts?: PixelBlendMaskOptions): boolean;
951
+ declare function blendPixelDataBinaryMask(target: PixelData32, src: PixelData32, binaryMask: BinaryMask, opts?: PixelBlendMaskOptions): boolean;
891
952
 
892
953
  declare const defaults$c: {
893
954
  blendPixelDataBinaryMask: typeof blendPixelDataBinaryMask;
@@ -897,14 +958,14 @@ type Deps$c = Partial<typeof defaults$c>;
897
958
  * @param deps - @hidden
898
959
  */
899
960
  declare const mutatorBlendBinaryMask: (writer: PixelWriter<any>, deps?: Partial<Deps$c>) => {
900
- blendBinaryMask(src: IPixelData32, mask: BinaryMask, opts?: PixelBlendMaskOptions): boolean;
961
+ blendBinaryMask(src: PixelData32, mask: BinaryMask, opts?: PixelBlendMaskOptions): boolean;
901
962
  };
902
963
 
903
964
  /**
904
965
  * Blends a solid color into a target pixel buffer.
905
966
  * @returns true if any pixels were actually modified.
906
967
  */
907
- declare function blendColorPixelData(target: IPixelData32, color: Color32, opts?: ColorBlendOptions): boolean;
968
+ declare function blendColorPixelData(target: PixelData32, color: Color32, opts?: ColorBlendOptions): boolean;
908
969
 
909
970
  declare const defaults$b: {
910
971
  blendColorPixelData: typeof blendColorPixelData;
@@ -917,6 +978,22 @@ declare const mutatorBlendColor: (writer: PixelWriter<any>, deps?: Deps$b) => {
917
978
  blendColor(color: Color32, opts?: ColorBlendOptions): boolean;
918
979
  };
919
980
 
981
+ declare enum PaintMaskOutline {
982
+ MASKED = 0,
983
+ CIRCLE = 1,
984
+ RECT = 2
985
+ }
986
+ interface BasePaintMask<T extends PaintMaskOutline = PaintMaskOutline> {
987
+ readonly outlineType: T;
988
+ readonly centerOffsetX: number;
989
+ readonly centerOffsetY: number;
990
+ }
991
+ interface PaintAlphaMask<T extends PaintMaskOutline = PaintMaskOutline> extends BasePaintMask<T>, AlphaMask {
992
+ }
993
+ interface PaintBinaryMask<T extends PaintMaskOutline = PaintMaskOutline> extends BasePaintMask<T>, BinaryMask {
994
+ }
995
+ type PaintMask = PaintAlphaMask<any> | PaintBinaryMask<any>;
996
+
920
997
  /**
921
998
  * Blends a solid color into a target pixel buffer using an alpha mask.
922
999
  *
@@ -924,13 +1001,13 @@ declare const mutatorBlendColor: (writer: PixelWriter<any>, deps?: Deps$b) => {
924
1001
  * If the width (`w`) or height (`h`) are omitted from the options, they will safely
925
1002
  * default to the dimensions of the provided mask to prevent out-of-bounds memory access.
926
1003
  *
927
- * @param target - The destination {@link IPixelData32} buffer to modify.
1004
+ * @param target - The destination {@link PixelData32} buffer to modify.
928
1005
  * @param color - The solid color to apply.
929
1006
  * @param mask - The mask defining the per-pixel opacity of the target area.
930
1007
  * @param opts - Configuration options including placement coordinates, bounds, global alpha, and mask offsets.
931
1008
  * @returns true if any pixels were actually modified.
932
1009
  */
933
- declare function blendColorPixelDataAlphaMask(target: IPixelData32, color: Color32, mask: AlphaMask, opts?: ColorBlendMaskOptions): boolean;
1010
+ declare function blendColorPixelDataAlphaMask(target: PixelData32, color: Color32, mask: AlphaMask, opts?: ColorBlendMaskOptions): boolean;
934
1011
 
935
1012
  declare const defaults$a: {
936
1013
  blendColorPixelDataAlphaMask: typeof blendColorPixelDataAlphaMask;
@@ -950,13 +1027,13 @@ declare const mutatorBlendColorPaintAlphaMask: (writer: PixelWriter<any>, deps?:
950
1027
  * If the width (`w`) or height (`h`) are omitted from the options, they will safely
951
1028
  * default to the dimensions of the provided mask to prevent out-of-bounds memory access.
952
1029
  *
953
- * @param target - The destination {@link IPixelData32} buffer to modify.
1030
+ * @param target - The destination {@link PixelData32} buffer to modify.
954
1031
  * @param color - The solid color to apply.
955
1032
  * @param mask - The mask defining the per-pixel opacity of the target area.
956
1033
  * @param opts - Configuration options including placement coordinates, bounds, global alpha, and mask offsets.
957
1034
  * @returns true if any pixels were actually modified.
958
1035
  */
959
- declare function blendColorPixelDataBinaryMask(target: IPixelData32, color: Color32, mask: BinaryMask, opts?: ColorBlendMaskOptions): boolean;
1036
+ declare function blendColorPixelDataBinaryMask(target: PixelData32, color: Color32, mask: BinaryMask, opts?: ColorBlendMaskOptions): boolean;
960
1037
 
961
1038
  declare const defaults$9: {
962
1039
  blendColorPixelDataBinaryMask: typeof blendColorPixelDataBinaryMask;
@@ -1001,10 +1078,10 @@ type Deps$6 = Partial<typeof defaults$6>;
1001
1078
  * @param deps - @hidden
1002
1079
  */
1003
1080
  declare const mutatorBlendMask: (writer: PixelWriter<any>, deps?: Partial<Deps$6>) => {
1004
- blendMask(src: IPixelData32, mask: Mask, opts?: PixelBlendMaskOptions): boolean;
1081
+ blendMask(src: PixelData32, mask: Mask, opts?: PixelBlendMaskOptions): boolean;
1005
1082
  };
1006
1083
 
1007
- declare function blendPixel(target: IPixelData32, x: number, y: number, color: Color32, alpha?: number, blendFn?: BlendColor32): boolean;
1084
+ declare function blendPixel(target: PixelData32, x: number, y: number, color: Color32, alpha?: number, blendFn?: BlendColor32): boolean;
1008
1085
 
1009
1086
  declare const defaults$5: {
1010
1087
  blendPixel: typeof blendPixel;
@@ -1017,6 +1094,22 @@ declare const mutatorBlendPixel: (writer: PixelWriter<any>, deps?: Partial<Deps$
1017
1094
  blendPixel(x: number, y: number, color: Color32, alpha?: number, blendFn?: BlendColor32): boolean;
1018
1095
  };
1019
1096
 
1097
+ /**
1098
+ * Blits source PixelData into a destination PixelData using 32-bit integer bitwise blending.
1099
+ * This function bypasses standard ImageData limitations by operating directly on
1100
+ * Uint32Array views. It supports various blend modes, binary/alpha masking, and
1101
+ * automatic clipping of both source and destination bounds.
1102
+ * @example
1103
+ *
1104
+ * const dst = new PixelData(ctx.getImageData(0,0,100,100))
1105
+ * blendImageData32(dst, sprite, {
1106
+ * blendFn: COLOR_32_BLEND_MODES.multiply,
1107
+ * mask: brushMask,
1108
+ * maskType: MaskType.ALPHA
1109
+ * });
1110
+ */
1111
+ declare function blendPixelData(target: PixelData32, src: PixelData32, opts?: PixelBlendOptions): boolean;
1112
+
1020
1113
  declare const defaults$4: {
1021
1114
  blendPixelData: typeof blendPixelData;
1022
1115
  };
@@ -1025,18 +1118,18 @@ type Deps$4 = Partial<typeof defaults$4>;
1025
1118
  * @param deps - @hidden
1026
1119
  */
1027
1120
  declare const mutatorBlendPixelData: (writer: PixelWriter<any>, deps?: Partial<Deps$4>) => {
1028
- blendPixelData(src: IPixelData32, opts?: PixelBlendOptions): boolean;
1121
+ blendPixelData(src: PixelData32, opts?: PixelBlendOptions): boolean;
1029
1122
  };
1030
1123
 
1031
1124
  /**
1032
- * Fills a region or the {@link IPixelData32} buffer with a solid color.
1125
+ * Fills a region or the {@link PixelData32} buffer with a solid color.
1033
1126
  *
1034
1127
  * @param dst - The target to modify.
1035
1128
  * @param color - The color to apply.
1036
1129
  * @param rect - Defines the area to fill. If omitted, the entire
1037
1130
  * @returns true if any pixels were actually modified.
1038
1131
  */
1039
- declare function fillPixelData(dst: IPixelData32, color: Color32, rect?: Partial<Rect>): boolean;
1132
+ declare function fillPixelData(dst: PixelData32, color: Color32, rect?: Partial<Rect>): boolean;
1040
1133
  /**
1041
1134
  * @param dst - The target to modify.
1042
1135
  * @param color - The color to apply.
@@ -1045,7 +1138,7 @@ declare function fillPixelData(dst: IPixelData32, color: Color32, rect?: Partial
1045
1138
  * @param w - Width of the fill area.
1046
1139
  * @param h - Height of the fill area.
1047
1140
  */
1048
- declare function fillPixelData(dst: IPixelData32, color: Color32, x: number, y: number, w: number, h: number): boolean;
1141
+ declare function fillPixelData(dst: PixelData32, color: Color32, x: number, y: number, w: number, h: number): boolean;
1049
1142
 
1050
1143
  declare const defaults$3: {
1051
1144
  fillPixelData: typeof fillPixelData;
@@ -1076,14 +1169,14 @@ declare const mutatorFillRect: (writer: PixelWriter<any>, deps?: Deps$2) => {
1076
1169
  };
1077
1170
 
1078
1171
  /**
1079
- * Fills a region of the {@link IPixelData32} buffer with a solid color using a mask.
1172
+ * Fills a region of the {@link PixelData32} buffer with a solid color using a mask.
1080
1173
  * @param target - The target to modify.
1081
1174
  * @param color - The color to apply.
1082
1175
  * @param mask - The mask defining the area to fill.
1083
1176
  * @param x - Starting horizontal coordinate for the mask placement.
1084
1177
  * @param y - Starting vertical coordinate for the mask placement.
1085
1178
  */
1086
- declare function fillPixelDataBinaryMask(target: IPixelData32, color: Color32, mask: BinaryMask, x?: number, y?: number): boolean;
1179
+ declare function fillPixelDataBinaryMask(target: PixelData32, color: Color32, mask: BinaryMask, x?: number, y?: number): boolean;
1087
1180
 
1088
1181
  declare const defaults$1: {
1089
1182
  fillPixelDataBinaryMask: typeof fillPixelDataBinaryMask;
@@ -1096,7 +1189,7 @@ declare const mutatorFillBinaryMask: (writer: PixelWriter<any>, deps?: Deps$1) =
1096
1189
  fillBinaryMask(color: Color32, mask: BinaryMask, x?: number, y?: number): boolean;
1097
1190
  };
1098
1191
 
1099
- declare function invertPixelData(target: IPixelData32, opts?: PixelMutateOptions): boolean;
1192
+ declare function invertPixelData(target: PixelData32, opts?: PixelMutateOptions): boolean;
1100
1193
 
1101
1194
  declare const defaults: {
1102
1195
  invertPixelData: typeof invertPixelData;
@@ -1109,17 +1202,6 @@ declare const mutatorInvert: (writer: PixelWriter<any>, deps?: Deps) => {
1109
1202
  invert(opts?: PixelMutateOptions): boolean;
1110
1203
  };
1111
1204
 
1112
- declare function makeImageDataLike(width: number, height: number, data?: Buffer): ImageDataLike;
1113
-
1114
- type ReusableImageData = ReturnType<typeof makeReusableImageData>;
1115
- /**
1116
- * Creates a factory function that manages a single, reusable ImageData instance.
1117
- * This is used to minimize garbage collection overhead by recycling the
1118
- * underlying pixel buffer across multiple operations.
1119
- * @returns A function that takes width and height and returns a pooled ImageData instance.
1120
- */
1121
- declare function makeReusableImageData(): (width: number, height: number) => ImageData;
1122
-
1123
1205
  declare function copyImageData({ data, width, height }: ImageDataLike): ImageData;
1124
1206
  declare function copyImageDataLike({ data, width, height }: ImageDataLike): ImageDataLike;
1125
1207
 
@@ -1144,6 +1226,8 @@ declare function extractImageDataBuffer(imageData: ImageDataLike, rect: Rect): U
1144
1226
  */
1145
1227
  declare function extractImageDataBuffer(imageData: ImageDataLike, x: number, y: number, w: number, h: number): Uint8ClampedArray;
1146
1228
 
1229
+ declare function makeImageDataLike(width: number, height: number, data?: Buffer): ImageDataLike;
1230
+
1147
1231
  /**
1148
1232
  * Extracts the alpha channel from raw ImageData into an AlphaMask.
1149
1233
  * When possible use {@link pixelDataToAlphaMask} instead.
@@ -1197,7 +1281,8 @@ declare function imageDataToImgBlob(imageData: ImageData): Promise<Blob>;
1197
1281
  /**
1198
1282
  * converts {@link ImageData} to a faster Uint32Array
1199
1283
  */
1200
- declare function imageDataToUInt32Array(imageData: ImageDataLike): Uint32Array;
1284
+ declare function imageDataToUint32Array(imageData: ImageDataLike): Uint32Array;
1285
+ declare function _macro_imageDataToUint32Array(imageData: ImageDataLike): Uint32Array;
1201
1286
 
1202
1287
  /**
1203
1288
  * Decodes a {@link Blob} (typically PNG) back into an {@link ImageData} object.
@@ -1230,6 +1315,15 @@ declare function invertImageData(imageData: ImageData): ImageData;
1230
1315
  */
1231
1316
  declare function resampleImageData(source: ImageData, factor: number): ImageData;
1232
1317
 
1318
+ type ReusableImageData = ReturnType<typeof makeReusableImageData>;
1319
+ /**
1320
+ * Creates a factory function that manages a single, reusable ImageData instance.
1321
+ * This is used to minimize garbage collection overhead by recycling the
1322
+ * underlying pixel buffer across multiple operations.
1323
+ * @returns A function that takes width and height and returns a pooled ImageData instance.
1324
+ */
1325
+ declare function makeReusableImageData(): (width: number, height: number) => ImageData;
1326
+
1233
1327
  declare function base64EncodeArrayBuffer(buffer: ArrayBufferLike): Base64EncodedUInt8Array;
1234
1328
  declare function base64DecodeArrayBuffer(encoded: Base64EncodedUInt8Array): Uint8ClampedArray<ArrayBuffer>;
1235
1329
  /**
@@ -1288,47 +1382,17 @@ declare function writeImageDataBuffer(target: ImageData, data: Uint8ClampedArray
1288
1382
  * into a color palette. This format is optimized for memory efficiency and
1289
1383
  * high-speed pattern matching or recoloring operations.
1290
1384
  */
1291
- declare class IndexedImage {
1385
+ interface IndexedImage {
1292
1386
  /** The width of the image in pixels. */
1293
- readonly width: number;
1387
+ readonly w: number;
1294
1388
  /** The height of the image in pixels. */
1295
- readonly height: number;
1389
+ readonly h: number;
1296
1390
  /** Flat array of palette indices. Index = x + (y * width). */
1297
- readonly data: Int32Array;
1391
+ readonly data: Uint32Array;
1298
1392
  /** The palette of unique 32-bit colors (ABGR/RGBA packed) found in the image. */
1299
1393
  readonly palette: Uint32Array;
1300
1394
  /** The specific index in the palette reserved for fully transparent pixels. */
1301
1395
  readonly transparentPalletIndex: number;
1302
- /**
1303
- * @param width - Image width.
1304
- * @param height - Image height.
1305
- * @param data - The indexed pixel data.
1306
- * @param palette - The array of packed colors.
1307
- * @param transparentPalletIndex - The index representing alpha 0.
1308
- */
1309
- constructor(width: number, height: number, data: Int32Array, palette: Uint32Array, transparentPalletIndex: number);
1310
- /**
1311
- * Creates an IndexedImage from standard browser ImageData.
1312
- * @param imageData - The source ImageData to convert.
1313
- * @returns A new IndexedImage instance.
1314
- */
1315
- static fromImageData(imageData: ImageData): IndexedImage;
1316
- /**
1317
- * Creates an IndexedImage from a raw byte buffer and dimensions.
1318
- * Any pixel with an alpha channel of 0 is normalized to the transparent palette index.
1319
- * @param data - Raw RGBA byte data.
1320
- * @param width - Image width.
1321
- * @param height - Image height.
1322
- * @returns A new IndexedImage instance.
1323
- */
1324
- static fromRaw(data: Uint8ClampedArray, width: number, height: number): IndexedImage;
1325
- /**
1326
- * Retrieves the 32-bit packed color value at the given coordinates.
1327
- * @param x - X coordinate.
1328
- * @param y - Y coordinate.
1329
- * @returns The packed color from the palette.
1330
- */
1331
- getColorAt(x: number, y: number): Color32;
1332
1396
  }
1333
1397
 
1334
1398
  /**
@@ -1337,7 +1401,12 @@ declare class IndexedImage {
1337
1401
  * @param indexedImage - The source image containing data and palette definitions.
1338
1402
  * @returns A typed array where each entry represents the total count of that palette index.
1339
1403
  */
1340
- declare function getIndexedImageColorCounts(indexedImage: IndexedImage): Int32Array;
1404
+ declare function getIndexedImageColorCounts(indexedImage: IndexedImage): Uint32Array;
1405
+
1406
+ declare function makeIndexedImage(width: number, height: number, data: Uint32Array, palette: Uint32Array, transparentPalletIndex: number): IndexedImage;
1407
+ declare function makeIndexedImageFromImageDataRaw(data: Uint8ClampedArray, width: number, height: number): IndexedImage;
1408
+ declare function makeIndexedImageFromImageData(imageData: ImageData): IndexedImage;
1409
+ declare function getIndexedImageColor(target: IndexedImage, x: number, y: number): Color32;
1341
1410
 
1342
1411
  /**
1343
1412
  * Calculates the area-weighted average color of an IndexedImage.
@@ -1353,11 +1422,6 @@ declare function indexedImageToAverageColor(indexedImage: IndexedImage, includeT
1353
1422
  */
1354
1423
  declare function indexedImageToImageData(indexedImage: IndexedImage): ImageData;
1355
1424
 
1356
- /**
1357
- * Resamples an IndexedImage by a specific factor using nearest neighbor
1358
- * Factor > 1 upscales, Factor < 1 downscales.
1359
- */
1360
-
1361
1425
  /**
1362
1426
  * Resamples an IndexedImage by a specific factor using nearest neighbor
1363
1427
  * Factor > 1 upscales, Factor < 1 downscales.
@@ -1451,49 +1515,6 @@ declare function fileToImageData(file: File | null | undefined): Promise<ImageDa
1451
1515
  */
1452
1516
  declare function getSupportedPixelFormats(rasterMimes?: string[]): Promise<string[]>;
1453
1517
 
1454
- /**
1455
- * @internal
1456
- */
1457
- type Resample32Result = {
1458
- data: Int32Array;
1459
- width: number;
1460
- height: number;
1461
- };
1462
- /**
1463
- * @internal
1464
- */
1465
- declare function resample32(srcData32: Uint32Array | Int32Array, srcW: number, srcH: number, factor: number): Resample32Result;
1466
-
1467
- type ClippedRect = {
1468
- x: number;
1469
- y: number;
1470
- w: number;
1471
- h: number;
1472
- inBounds: boolean;
1473
- };
1474
- type ClippedBlit = {
1475
- x: number;
1476
- y: number;
1477
- sx: number;
1478
- sy: number;
1479
- w: number;
1480
- h: number;
1481
- inBounds: boolean;
1482
- };
1483
- declare const makeClippedRect: () => ClippedRect;
1484
- declare const makeClippedBlit: () => ClippedBlit;
1485
- /**
1486
- * Calculates the intersection of a target rectangle and a bounding box (usually 0,0 -> width,height).
1487
- * Handles negative offsets by shrinking dimensions.
1488
- */
1489
- declare function resolveRectClipping(x: number, y: number, w: number, h: number, boundaryW: number, boundaryH: number, out: ClippedRect): ClippedRect;
1490
- /**
1491
- * Calculates the clipping for transferring data from a Source to a Destination.
1492
- * Handles cases where the source is out of bounds (shifting the destination target)
1493
- * AND cases where the destination is out of bounds (shifting the source target).
1494
- */
1495
- declare function resolveBlitClipping(x: number, y: number, sx: number, sy: number, w: number, h: number, dstW: number, dstH: number, srcW: number, srcH: number, out: ClippedBlit): ClippedBlit;
1496
-
1497
1518
  /**
1498
1519
  * Creates an Alpha Mask
1499
1520
  * @param w - width
@@ -1502,6 +1523,8 @@ declare function resolveBlitClipping(x: number, y: number, sx: number, sy: numbe
1502
1523
  */
1503
1524
  declare function makeAlphaMask(w: number, h: number, data?: Uint8Array): AlphaMask;
1504
1525
 
1526
+ declare function applyBinaryMaskToAlphaMask(alphaMaskDst: AlphaMask, binaryMaskSrc: BinaryMask, opts?: ApplyMaskToPixelDataOptions): void;
1527
+
1505
1528
  /**
1506
1529
  * Creates a Binary Mask
1507
1530
  * @param w - width
@@ -1510,7 +1533,13 @@ declare function makeAlphaMask(w: number, h: number, data?: Uint8Array): AlphaMa
1510
1533
  */
1511
1534
  declare function makeBinaryMask(w: number, h: number, data?: Uint8Array): BinaryMask;
1512
1535
 
1513
- declare function applyBinaryMaskToAlphaMask(alphaMaskDst: AlphaMask, binaryMaskSrc: BinaryMask, opts?: ApplyMaskToPixelDataOptions): void;
1536
+ declare function makeBinaryMaskFromAlphaMask(mask: AlphaMask, threshold: number, out?: MutableBinaryMask): BinaryMask;
1537
+
1538
+ declare function makeBinaryMaskOutline(mask: BinaryMask, scale?: number): BinaryMask;
1539
+
1540
+ declare function makeCircleBinaryMaskOutline(size: number, scale: number): BinaryMask;
1541
+
1542
+ declare function makeRectBinaryMaskOutline(w: number, h: number, scale?: number): BinaryMask;
1514
1543
 
1515
1544
  /**
1516
1545
  * Creates a new copy of a mask.
@@ -1584,18 +1613,90 @@ declare function mergeBinaryMaskRects(current: NullableBinaryMaskRect[], adding:
1584
1613
 
1585
1614
  declare function subtractBinaryMaskRects(current: NullableBinaryMaskRect[], subtracting: NullableBinaryMaskRect[]): NullableBinaryMaskRect[];
1586
1615
 
1587
- type PaintBufferCanvasRenderer = ReturnType<typeof makePaintBufferCanvasRenderer>;
1616
+ declare class AlphaMaskPaintBuffer {
1617
+ readonly config: PixelEngineConfig;
1618
+ readonly tilePool: TilePool<AlphaMaskTile>;
1619
+ readonly lookup: (AlphaMaskTile | undefined)[];
1620
+ private readonly scratchBounds;
1621
+ private blendColorPixelDataAlphaMaskFn;
1622
+ private forEachLinePointFn;
1623
+ private trimRectBoundsFn;
1624
+ private eachTileInBoundsFn;
1625
+ constructor(config: PixelEngineConfig, tilePool: TilePool<AlphaMaskTile>);
1626
+ paintAlphaMask(brush: PaintAlphaMask, x: number, y: number): boolean;
1627
+ paintAlphaMask(brush: PaintAlphaMask, startX: number, startY: number, endX: number, endY: number): boolean;
1628
+ paintBinaryMask(brush: PaintBinaryMask, alpha: number, x: number, y: number): boolean;
1629
+ paintBinaryMask(brush: PaintBinaryMask, alpha: number, startX: number, startY: number, endX: number, endY: number): boolean;
1630
+ paintRect(alpha: number, brushWidth: number, brushHeight: number, x: number, y: number): boolean;
1631
+ paintRect(alpha: number, brushWidth: number, brushHeight: number, startX: number, startY: number, endX: number, endY: number): boolean;
1632
+ private opts;
1633
+ commit(accumulator: PixelAccumulator, color: Color32, alpha?: number, blendFn?: BlendColor32): void;
1634
+ clear(): void;
1635
+ }
1636
+
1637
+ type AlphaMaskPaintBufferCanvasRenderer = ReturnType<typeof makeAlphaMaskPaintBufferCanvasRenderer>;
1638
+ declare function makeAlphaMaskPaintBufferCanvasRenderer(paintBuffer: AlphaMaskPaintBuffer, offscreenCanvasClass?: {
1639
+ new (width: number, height: number): OffscreenCanvas;
1640
+ prototype: OffscreenCanvas;
1641
+ }): (targetCtx: CanvasRenderingContext2D, color: Color32, alpha?: number, compOperation?: GlobalCompositeOperation) => void;
1642
+
1643
+ declare class BinaryMaskPaintBuffer {
1644
+ readonly config: PixelEngineConfig;
1645
+ readonly tilePool: TilePool<BinaryMaskTile>;
1646
+ readonly lookup: (BinaryMaskTile | undefined)[];
1647
+ private readonly scratchBounds;
1648
+ private blendColorPixelDataBinaryMaskFn;
1649
+ private forEachLinePointFn;
1650
+ private trimRectBoundsFn;
1651
+ private eachTileInBoundsFn;
1652
+ constructor(config: PixelEngineConfig, tilePool: TilePool<BinaryMaskTile>);
1653
+ paintBinaryMask(brush: PaintBinaryMask, x: number, y: number): boolean;
1654
+ paintBinaryMask(brush: PaintBinaryMask, startX: number, startY: number, endX: number, endY: number): boolean;
1655
+ paintRect(brushWidth: number, brushHeight: number, x: number, y: number): boolean;
1656
+ paintRect(brushWidth: number, brushHeight: number, startX: number, startY: number, endX: number, endY: number): boolean;
1657
+ private opts;
1658
+ commit(accumulator: PixelAccumulator, color: Color32, alpha?: number, blendFn?: BlendColor32): void;
1659
+ clear(): void;
1660
+ }
1661
+
1662
+ type BinaryMaskPaintBufferCanvasRenderer = ReturnType<typeof makeBinaryMaskPaintBufferCanvasRenderer>;
1663
+ declare function makeBinaryMaskPaintBufferCanvasRenderer(paintBuffer: BinaryMaskPaintBuffer, offscreenCanvasClass?: {
1664
+ new (width: number, height: number): OffscreenCanvas;
1665
+ prototype: OffscreenCanvas;
1666
+ }): (targetCtx: CanvasRenderingContext2D, color: Color32, alpha?: number, compOperation?: GlobalCompositeOperation) => void;
1667
+
1668
+ declare class ColorPaintBuffer {
1669
+ readonly config: PixelEngineConfig;
1670
+ readonly tilePool: TilePool<PixelTile>;
1671
+ private blendPixelDataFn;
1672
+ readonly lookup: (PixelTile | undefined)[];
1673
+ private readonly scratchBounds;
1674
+ constructor(config: PixelEngineConfig, tilePool: TilePool<PixelTile>, blendPixelDataFn?: typeof blendPixelData);
1675
+ paintAlphaMask(color: Color32, brush: PaintAlphaMask, x: number, y: number): boolean;
1676
+ paintAlphaMask(color: Color32, brush: PaintAlphaMask, startX: number, startY: number, endX: number, endY: number): boolean;
1677
+ paintBinaryMask(color: Color32, brush: PaintBinaryMask, x: number, y: number): boolean;
1678
+ paintBinaryMask(color: Color32, brush: PaintBinaryMask, startX: number, startY: number, endX: number, endY: number): boolean;
1679
+ paintRect(color: Color32, brushWidth: number, brushHeight: number, x: number, y: number): boolean;
1680
+ paintRect(color: Color32, brushWidth: number, brushHeight: number, startX: number, startY: number, endX: number, endY: number): boolean;
1681
+ private opts;
1682
+ commit(accumulator: PixelAccumulator, alpha?: number, blendFn?: BlendColor32): void;
1683
+ clear(): void;
1684
+ }
1685
+
1686
+ type ColorPaintBufferCanvasRenderer = ReturnType<typeof makeColorPaintBufferCanvasRenderer>;
1588
1687
  /**
1589
1688
  *
1689
+ * @param paintBuffer
1590
1690
  * @param offscreenCanvasClass - @internal
1591
1691
  */
1592
- declare function makePaintBufferCanvasRenderer(paintBuffer: PaintBuffer, offscreenCanvasClass?: {
1692
+ declare function makeColorPaintBufferCanvasRenderer(paintBuffer: ColorPaintBuffer, offscreenCanvasClass?: {
1593
1693
  new (width: number, height: number): OffscreenCanvas;
1594
1694
  prototype: OffscreenCanvas;
1595
1695
  }): (targetCtx: CanvasRenderingContext2D, alpha?: number, compOperation?: GlobalCompositeOperation) => void;
1596
1696
 
1597
- declare function makeCirclePaintAlphaMask(size: number, fallOff?: (d: number) => number): PaintAlphaMask;
1697
+ declare function eachTileInBounds<T extends Tile>(config: PixelEngineConfig, lookup: (T | undefined)[], tilePool: TilePool<T>, bounds: Rect, callback: (tile: T, bX: number, bY: number, bW: number, bH: number) => void): void;
1598
1698
 
1699
+ declare function makeCirclePaintAlphaMask(size: number, fallOff?: (d: number) => number): PaintAlphaMask;
1599
1700
  declare function makeCirclePaintBinaryMask(size: number): PaintBinaryMask;
1600
1701
 
1601
1702
  declare function makePaintBinaryMask(mask: BinaryMask): PaintBinaryMask;
@@ -1603,42 +1704,57 @@ declare function makePaintAlphaMask(mask: AlphaMask): PaintAlphaMask;
1603
1704
 
1604
1705
  declare function makeRectFalloffPaintAlphaMask(width: number, height: number, fallOff?: (d: number) => number): PaintAlphaMask;
1605
1706
 
1606
- declare function applyMaskToPixelData(dst: IPixelData32, mask: Mask, opts?: ApplyMaskToPixelDataOptions): boolean;
1707
+ type PaintCursorRenderer = ReturnType<typeof makePaintCursorRenderer>;
1708
+ declare function makePaintCursorRenderer<T extends HTMLCanvasElement | OffscreenCanvas>(factory?: CanvasObjectFactory<T>): {
1709
+ update: (paintMask?: PaintMask, scale?: number, color?: Color32, alphaThreshold?: number) => void;
1710
+ getBounds: (centerX: number, centerY: number) => Rect;
1711
+ getBoundsScaled: (centerX: number, centerY: number) => Rect;
1712
+ draw: (drawCtx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, centerX: number, centerY: number) => void;
1713
+ getSettings: () => {
1714
+ color: Color32;
1715
+ scale: number;
1716
+ currentMask: PaintMask;
1717
+ };
1718
+ };
1719
+
1720
+ declare function applyMaskToPixelData(dst: PixelData32, mask: Mask, opts?: ApplyMaskToPixelDataOptions): boolean;
1607
1721
 
1608
- declare function blendColorPixelDataMask(dst: IPixelData32, color: Color32, mask: Mask, opts?: ColorBlendMaskOptions): boolean;
1722
+ declare function blendColorPixelDataMask(dst: PixelData32, color: Color32, mask: Mask, opts?: ColorBlendMaskOptions): boolean;
1609
1723
 
1610
- declare function blendColorPixelDataPaintAlphaMask(dst: IPixelData32, color: Color32, mask: PaintAlphaMask, x: number, y: number, alpha?: number, blendFn?: BlendColor32): boolean;
1724
+ declare function blendColorPixelDataPaintAlphaMask(dst: PixelData32, color: Color32, mask: PaintAlphaMask, x: number, y: number, alpha?: number, blendFn?: BlendColor32): boolean;
1611
1725
 
1612
- declare function blendColorPixelDataPaintBinaryMask(dst: IPixelData32, color: Color32, mask: PaintBinaryMask, x: number, y: number, alpha?: number, blendFn?: BlendColor32): boolean;
1726
+ declare function blendColorPixelDataPaintBinaryMask(dst: PixelData32, color: Color32, mask: PaintBinaryMask, x: number, y: number, alpha?: number, blendFn?: BlendColor32): boolean;
1613
1727
 
1614
- declare function blendColorPixelDataPaintMask(dst: IPixelData32, color: Color32, mask: PaintMask, x: number, y: number, alpha?: number, blendFn?: BlendColor32): boolean;
1728
+ declare function blendColorPixelDataPaintMask(dst: PixelData32, color: Color32, mask: PaintMask, x: number, y: number, alpha?: number, blendFn?: BlendColor32): boolean;
1615
1729
 
1616
- declare function blendPixelDataMask(target: IPixelData32, src: IPixelData32, mask: Mask, opts?: PixelBlendMaskOptions): boolean;
1730
+ declare function blendPixelDataMask(target: PixelData32, src: PixelData32, mask: Mask, opts?: PixelBlendMaskOptions): boolean;
1617
1731
 
1618
- declare function blendPixelDataPaintBuffer(target: IPixelData32, paintBuffer: PaintBuffer, alpha?: number, blendFn?: BlendColor32, blendPixelDataFn?: typeof blendPixelData): void;
1732
+ declare function blendPixelDataPaintBuffer(target: PixelData32, paintBuffer: ColorPaintBuffer, alpha?: number, blendFn?: BlendColor32, blendPixelDataFn?: typeof blendPixelData): void;
1619
1733
 
1620
1734
  /**
1621
1735
  * Clears a region of the PixelData to transparent (0x00000000).
1622
1736
  * Internally uses the optimized fillPixelDataFast.
1623
1737
  */
1624
- declare function clearPixelDataFast(dst: IPixelData32, rect?: Partial<BinaryMaskRect>): void;
1738
+ declare function clearPixelDataFast(dst: PixelData32, rect?: Partial<BinaryMaskRect>): void;
1739
+
1740
+ declare function copyPixelData<T extends ImageDataLike = ImageData>(target: PixelData<T>): PixelData;
1625
1741
 
1626
1742
  /**
1627
1743
  * High-level extraction that returns a new PixelData instance.
1628
1744
  * Leverages extractPixelDataBuffer for optimized 32-bit memory moves.
1629
1745
  */
1630
- declare function extractPixelData(source: IPixelData32, rect: Rect): PixelData;
1631
- declare function extractPixelData(source: IPixelData32, x: number, y: number, w: number, h: number): PixelData;
1746
+ declare function extractPixelData(source: PixelData32, rect: Rect): PixelData;
1747
+ declare function extractPixelData(source: PixelData32, x: number, y: number, w: number, h: number): PixelData;
1632
1748
 
1633
1749
  /**
1634
1750
  * Extracts a rectangular region of pixels from PixelData.
1635
1751
  * Returns a new Uint32Array containing the extracted pixels.
1636
1752
  */
1637
- declare function extractPixelDataBuffer(source: IPixelData32, rect: Rect): Uint32Array;
1638
- declare function extractPixelDataBuffer(source: IPixelData32, x: number, y: number, w: number, h: number): Uint32Array;
1753
+ declare function extractPixelDataBuffer(source: PixelData32, rect: Rect): Uint32Array;
1754
+ declare function extractPixelDataBuffer(source: PixelData32, x: number, y: number, w: number, h: number): Uint32Array;
1639
1755
 
1640
1756
  /**
1641
- * Fills a region or the {@link IPixelData32} buffer with a solid color.
1757
+ * Fills a region or the {@link PixelData32} buffer with a solid color.
1642
1758
  * This function is faster than {@link fillPixelData} but does not
1643
1759
  * return a boolean value indicating changes were made.
1644
1760
  *
@@ -1647,7 +1763,7 @@ declare function extractPixelDataBuffer(source: IPixelData32, x: number, y: numb
1647
1763
  * @param rect - Defines the area to fill. If omitted, the entire
1648
1764
  * buffer is filled.
1649
1765
  */
1650
- declare function fillPixelDataFast(target: IPixelData32, color: Color32, rect?: Partial<Rect>): void;
1766
+ declare function fillPixelDataFast(target: PixelData32, color: Color32, rect?: Partial<Rect>): void;
1651
1767
  /**
1652
1768
  * @param dst - The target to modify.
1653
1769
  * @param color - The color to apply.
@@ -1656,22 +1772,35 @@ declare function fillPixelDataFast(target: IPixelData32, color: Color32, rect?:
1656
1772
  * @param w - Width of the fill area.
1657
1773
  * @param h - Height of the fill area.
1658
1774
  */
1659
- declare function fillPixelDataFast(dst: IPixelData32, color: Color32, x: number, y: number, w: number, h: number): void;
1775
+ declare function fillPixelDataFast(dst: PixelData32, color: Color32, x: number, y: number, w: number, h: number): void;
1776
+
1777
+ declare function makePixelData<T extends ImageDataLike = ImageData>(imageData: T): PixelData<T>;
1778
+ declare function setPixelData(target: PixelData, imageData: ImageData): void;
1660
1779
 
1661
1780
  /**
1662
1781
  * Extracts the alpha channel from PixelData into a single-channel mask.
1663
1782
  * Returns a Uint8Array branded as AlphaMask.
1664
1783
  */
1665
- declare function pixelDataToAlphaMask(pixelData: IPixelData32): AlphaMask;
1784
+ declare function pixelDataToAlphaMask(pixelData: PixelData32): AlphaMask;
1666
1785
 
1667
- declare function reflectPixelDataHorizontal(pixelData: IPixelData32): void;
1668
- declare function reflectPixelDataVertical(pixelData: IPixelData32): void;
1786
+ declare function reflectPixelDataHorizontal(pixelData: PixelData32): void;
1787
+ declare function reflectPixelDataVertical(pixelData: PixelData32): void;
1669
1788
 
1670
1789
  /**
1671
1790
  * Resamples PixelData by a specific factor using nearest neighbor.
1672
1791
  * Factor > 1 upscales, Factor < 1 downscales.
1673
1792
  */
1674
- declare function resamplePixelData(pixelData: IPixelData32, factor: number): PixelData;
1793
+ declare function resamplePixelData(pixelData: PixelData32, factor: number): PixelData;
1794
+ declare function resamplePixelDataInPlace(pixelData: PixelData32, factor: number): void;
1795
+
1796
+ type ReusablePixelData = ReturnType<typeof makeReusablePixelData>;
1797
+ /**
1798
+ * Creates a factory function that manages a single, reusable PixelData instance.
1799
+ * This is used to minimize garbage collection overhead by recycling the
1800
+ * underlying pixel buffer across multiple operations.
1801
+ * @returns A function that takes width and height and returns a pooled PixelData instance.
1802
+ */
1803
+ declare function makeReusablePixelData(): (width: number, height: number) => PixelData;
1675
1804
 
1676
1805
  /**
1677
1806
  * Rotates pixel data 90 degrees clockwise.
@@ -1680,22 +1809,54 @@ declare function resamplePixelData(pixelData: IPixelData32, factor: number): Pix
1680
1809
  */
1681
1810
  declare function rotatePixelData(pixelData: PixelData): void;
1682
1811
 
1812
+ declare function uInt32ArrayToPixelData(data: Uint32Array, width: number, height: number): PixelData;
1813
+
1683
1814
  /**
1684
- * Copies a pixel buffer into a specific region of a {@link IPixelData32} object.
1815
+ * Copies a pixel buffer into a specific region of a {@link PixelData32} object.
1685
1816
  *
1686
1817
  * This function performs a direct memory copy from a {@link Uint32Array}
1687
1818
  * into the target buffer.
1688
1819
  */
1689
- declare function writePixelDataBuffer(target: IPixelData32, data: Uint32Array, rect: Rect): void;
1690
- declare function writePixelDataBuffer(target: IPixelData32, data: Uint32Array, x: number, y: number, w: number, h: number): void;
1820
+ declare function writePixelDataBuffer(target: PixelData32, data: Uint32Array, rect: Rect): void;
1821
+ declare function writePixelDataBuffer(target: PixelData32, data: Uint32Array, x: number, y: number, w: number, h: number): void;
1691
1822
 
1692
1823
  /**
1693
1824
  * @param writePixelDataBufferFn - @hidden
1694
1825
  */
1695
- declare function writePaintBufferToPixelData(target: IPixelData, paintBuffer: PaintBuffer, writePixelDataBufferFn?: typeof writePixelDataBuffer): void;
1826
+ declare function writePaintBufferToPixelData(target: PixelData, paintBuffer: ColorPaintBuffer, writePixelDataBufferFn?: typeof writePixelDataBuffer): void;
1696
1827
 
1697
1828
  declare function getRectsBounds<T extends Rect>(rects: T[]): T;
1698
1829
 
1830
+ type ClippedRect = {
1831
+ x: number;
1832
+ y: number;
1833
+ w: number;
1834
+ h: number;
1835
+ inBounds: boolean;
1836
+ };
1837
+ type ClippedBlit = {
1838
+ x: number;
1839
+ y: number;
1840
+ sx: number;
1841
+ sy: number;
1842
+ w: number;
1843
+ h: number;
1844
+ inBounds: boolean;
1845
+ };
1846
+ declare const makeClippedRect: () => ClippedRect;
1847
+ declare const makeClippedBlit: () => ClippedBlit;
1848
+ /**
1849
+ * Calculates the intersection of a target rectangle and a bounding box (usually 0,0 -> width,height).
1850
+ * Handles negative offsets by shrinking dimensions.
1851
+ */
1852
+ declare function resolveRectClipping(x: number, y: number, w: number, h: number, boundaryW: number, boundaryH: number, out: ClippedRect): ClippedRect;
1853
+ /**
1854
+ * Calculates the clipping for transferring data from a Source to a Destination.
1855
+ * Handles cases where the source is out of bounds (shifting the destination target)
1856
+ * AND cases where the destination is out of bounds (shifting the source target).
1857
+ */
1858
+ declare function resolveBlitClipping(x: number, y: number, sx: number, sy: number, w: number, h: number, dstW: number, dstH: number, srcW: number, srcH: number, out: ClippedBlit): ClippedBlit;
1859
+
1699
1860
  /**
1700
1861
  * Intersects a target rectangle with a boundary, trimming dimensions and masks in-place.
1701
1862
  * This utility calculates the axis-aligned intersection between the `target` and `bounds`.
@@ -1714,45 +1875,9 @@ declare function trimMaskRectBounds<T extends NullableMaskRect>(target: T, bound
1714
1875
 
1715
1876
  declare function trimRectBounds(x: number, y: number, w: number, h: number, targetWidth: number, targetHeight: number, out?: Rect): Rect;
1716
1877
 
1717
- /**
1718
- * Packs RGBA into a 32-bit integer compatible with
1719
- * Little-Endian Uint32Array views on ImageData.
1720
- */
1721
- declare function packColor(r: number, g: number, b: number, a: number): Color32;
1722
- declare function packRGBA({ r, g, b, a }: RGBA): Color32;
1723
- declare const unpackRed: (packed: Color32) => number;
1724
- declare const unpackGreen: (packed: Color32) => number;
1725
- declare const unpackBlue: (packed: Color32) => number;
1726
- declare const unpackAlpha: (packed: Color32) => number;
1727
- declare function unpackColor(packed: Color32): RGBA;
1728
- declare function unpackColorTo(packed: Color32, scratch?: RGBA): RGBA;
1729
- declare function colorDistance(a: Color32, b: Color32): number;
1730
- /**
1731
- * Linearly interpolates between two 32-bit colors using a floating-point weight.
1732
- * * This is the preferred method for UI animations or scenarios where high
1733
- * precision is required. It uses the standard `a + t * (b - a)` formula
1734
- * for each channel.
1735
- * @param a - The starting color as a 32-bit integer (AABBGGRR).
1736
- * @param b - The target color as a 32-bit integer (AABBGGRR).
1737
- * @param t - The interpolation factor between 0.0 and 1.0.
1738
- * @returns The interpolated 32-bit color.
1739
- */
1740
- declare function lerpColor32(a: Color32, b: Color32, t: number): Color32;
1741
- /**
1742
- * Linearly interpolates between two 32-bit colors using integer fixed-point math.
1743
- * Highly optimized for image processing and real-time blitting. It processes
1744
- * channels in parallel using bitmasks (RB and GA pairs).
1745
- * **Note:** Subject to a 1-bit drift (rounding down) due to fast bit-shift division.
1746
- * @param src - The source (foreground) color as a 32-bit integer.
1747
- * @param dst - The destination (background) color as a 32-bit integer.
1748
- * @param w - The blend weight as a byte value from 0 to 255. Where 0 is 100% dst and 255 is 100% src
1749
- * @returns The blended 32-bit color.
1750
- */ declare function lerpColor32Fast(src: Color32, dst: Color32, w: number): Color32;
1751
- declare function color32ToHex(color: Color32): string;
1752
- /**
1753
- * Converts a 32-bit integer (0xAABBGGRR) to a CSS rgba() string.
1754
- * Example: 0xFF0000FF -> "rgba(255,0,0,1)"
1755
- */
1756
- declare function color32ToCssRGBA(color: Color32): string;
1878
+ declare const makeAlphaMaskTile: TileFactory<AlphaMaskTile>;
1879
+ declare const makeBinaryMaskTile: TileFactory<BinaryMaskTile>;
1880
+
1881
+ declare function makePixelTile(id: number, tx: number, ty: number, tileSize: number, tileArea: number): PixelTile;
1757
1882
 
1758
- export { type AlphaMask, type AlphaMaskRect, type ApplyMaskToPixelDataOptions, BASE_FAST_BLEND_MODE_FUNCTIONS, BASE_PERFECT_BLEND_MODE_FUNCTIONS, type Base64EncodedUInt8Array, BaseBlendMode, type BaseBlendModes, type BaseMask, type BasePixelBlendOptions, type BinaryMask, type BinaryMaskRect, type BlendColor32, type BlendModeRegistry, CANVAS_COMPOSITE_MAP, type CanvasBlendModeIndex, type CanvasCompositeOperation, type CanvasContext, type CanvasFrameRenderer, type ClippedBlit, type ClippedRect, type Color32, type ColorBlendMaskOptions, type ColorBlendOptions, type ColorBlendPaintMaskOptions, type DidChangeFn, type DrawPixelLayer, type DrawScreenLayer, type FloodFillResult, type HistoryAction, type HistoryActionFactory, HistoryManager, type HistoryMutator, type IPixelData, type IPixelData32, type ImageDataLike, type ImageDataLikeConstructor, IndexedImage, type InvertMask, type Mask, type MaskOffset, type MaskRect, MaskType, type MergeAlphaMasksOptions, type NullableBinaryMaskRect, type NullableMaskRect, type PaintAlphaMask, type PaintBinaryMask, PaintBuffer, type PaintBufferCanvasRenderer, type PaintMask, PixelAccumulator, type PixelBlendMaskOptions, type PixelBlendOptions, type PixelCanvas, PixelData, PixelEngineConfig, type PixelMutateOptions, type PixelPatchTiles, type PixelRect, PixelTile, PixelTilePool, PixelWriter, type PixelWriterOptions, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableImageData, type SerializedImageData, UnsupportedFormatError, applyAlphaMaskToPixelData, applyBinaryMaskToAlphaMask, applyBinaryMaskToPixelData, applyMaskToPixelData, applyPatchTiles, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendColorPixelDataAlphaMask, blendColorPixelDataBinaryMask, blendColorPixelDataMask, blendColorPixelDataPaintAlphaMask, blendColorPixelDataPaintBinaryMask, blendColorPixelDataPaintMask, blendPixel, blendPixelData, blendPixelDataAlphaMask, blendPixelDataBinaryMask, blendPixelDataMask, blendPixelDataPaintBuffer, clearPixelDataFast, color32ToCssRGBA, color32ToHex, colorBurnFast, colorBurnPerfect, colorDistance, colorDodgeFast, colorDodgePerfect, copyImageData, copyImageDataLike, copyMask, darkenFast, darkenPerfect, darkerFast, darkerPerfect, deserializeImageData, deserializeNullableImageData, deserializeRawImageData, differenceFast, differencePerfect, divideFast, dividePerfect, exclusionFast, exclusionPerfect, extractImageDataBuffer, extractMask, extractMaskBuffer, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, fillPixelDataBinaryMask, fillPixelDataFast, floodFillSelection, forEachLinePoint, getImageDataFromClipboard, getIndexedImageColorCounts, getRectsBounds, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMaskBuffer, imageDataToDataUrl, imageDataToImgBlob, imageDataToUInt32Array, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makeAlphaMask, makeBinaryMask, makeBlendModeRegistry, makeCanvasFrameRenderer, makeCirclePaintAlphaMask, makeCirclePaintBinaryMask, makeClippedBlit, makeClippedRect, makeFastBlendModeRegistry, makeFullPixelMutator, makeHistoryAction, makeImageDataLike, makePaintAlphaMask, makePaintBinaryMask, makePaintBufferCanvasRenderer, makePerfectBlendModeRegistry, makePixelCanvas, makeRectFalloffPaintAlphaMask, makeReusableCanvas, makeReusableImageData, makeReusableOffscreenCanvas, merge2BinaryMaskRects, mergeAlphaMasks, mergeBinaryMaskRects, mergeBinaryMasks, multiplyFast, multiplyPerfect, mutatorApplyAlphaMask, mutatorApplyBinaryMask, mutatorApplyMask, mutatorBlendAlphaMask, mutatorBlendBinaryMask, mutatorBlendColor, mutatorBlendColorPaintAlphaMask, mutatorBlendColorPaintBinaryMask, mutatorBlendColorPaintMask, mutatorBlendColorPaintRect, mutatorBlendMask, mutatorBlendPixel, mutatorBlendPixelData, mutatorClear, mutatorFill, mutatorFillBinaryMask, mutatorFillRect, mutatorInvert, overlayFast, overlayPerfect, overwriteBase, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resample32, resampleImageData, resampleIndexedImage, resamplePixelData, resizeImageData, resolveBlitClipping, resolveRectClipping, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, setMaskData, softLightFast, softLightPerfect, sourceOverFast, sourceOverPerfect, subtractBinaryMaskRects, subtractFast, subtractPerfect, toBlendModeIndexAndName, trimMaskRectBounds, trimRectBounds, uInt32ArrayToImageData, uInt32ArrayToImageDataLike, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataBuffer, writeImageDataToClipboard, writeImgBlobToClipboard, writePaintBufferToPixelData, writePixelDataBuffer };
1883
+ export { type AlphaMask, AlphaMaskPaintBuffer, type AlphaMaskPaintBufferCanvasRenderer, type AlphaMaskRect, type AlphaMaskTile, type ApplyMaskToPixelDataOptions, BASE_FAST_BLEND_MODE_FUNCTIONS, BASE_PERFECT_BLEND_MODE_FUNCTIONS, type Base64EncodedUInt8Array, BaseBlendMode, type BaseBlendModes, type BaseMask, type BasePixelBlendOptions, type BinaryMask, BinaryMaskPaintBuffer, type BinaryMaskPaintBufferCanvasRenderer, type BinaryMaskRect, type BinaryMaskTile, type BlendColor32, type BlendModeRegistry, CANVAS_COMPOSITE_MAP, type CanvasBlendModeIndex, type CanvasCompositeOperation, type CanvasContext, type CanvasFrameRenderer, type CanvasObjectFactory, type CanvasPixelDataRenderer, type ClippedBlit, type ClippedRect, type Color32, type ColorBlendMaskOptions, type ColorBlendOptions, ColorPaintBuffer, type ColorPaintBufferCanvasRenderer, type DidChangeFn, type DrawPixelLayer, type DrawScreenLayer, _errors as ERRORS, type FloodFillResult, type HistoryAction, type HistoryActionFactory, HistoryManager, type HistoryMutator, type ImageDataLike, type IndexedImage, type InvertMask, type Mask, type MaskOffset, type MaskRect, MaskType, type MergeAlphaMasksOptions, type MutableAlphaMask, type MutableBinaryMask, type MutableMask, type MutablePixelData32, type NullableBinaryMaskRect, type NullableMaskRect, type PaintAlphaMask, type PaintBinaryMask, type PaintCursorRenderer, type PaintMask, PaintMaskOutline, PixelAccumulator, type PixelBlendMaskOptions, type PixelBlendOptions, type PixelCanvas, type PixelData, type PixelData32, PixelEngineConfig, type PixelMutateOptions, type PixelPatchTiles, type PixelRect, type PixelTile, PixelWriter, type PixelWriterOptions, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableCanvasFactory, type ReusableImageData, type ReusablePixelData, type SerializedImageData, type Tile, type TileFactory, TilePool, TileType, UnsupportedFormatError, _macro_imageDataToUint32Array, applyAlphaMaskToPixelData, applyBinaryMaskToAlphaMask, applyBinaryMaskToPixelData, applyMaskToPixelData, applyPatchTiles, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendColorPixelDataAlphaMask, blendColorPixelDataBinaryMask, blendColorPixelDataMask, blendColorPixelDataPaintAlphaMask, blendColorPixelDataPaintBinaryMask, blendColorPixelDataPaintMask, blendPixel, blendPixelData, blendPixelDataAlphaMask, blendPixelDataBinaryMask, blendPixelDataMask, blendPixelDataPaintBuffer, clearPixelDataFast, color32ToCssRGBA, color32ToHex, colorBurnFast, colorBurnPerfect, colorDistance, colorDodgeFast, colorDodgePerfect, copyImageData, copyImageDataLike, copyMask, copyPixelData, darkenFast, darkenPerfect, darkerFast, darkerPerfect, deserializeImageData, deserializeNullableImageData, deserializeRawImageData, destinationAtopFast, destinationAtopPerfect, destinationInFast, destinationInPerfect, destinationOutFast, destinationOutPerfect, destinationOverFast, destinationOverPerfect, differenceFast, differencePerfect, divideFast, dividePerfect, eachTileInBounds, exclusionFast, exclusionPerfect, extractImageDataBuffer, extractMask, extractMaskBuffer, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, fillPixelDataBinaryMask, fillPixelDataFast, floodFillSelection, forEachLinePoint, getImageDataFromClipboard, getIndexedImageColor, getIndexedImageColorCounts, getRectsBounds, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMaskBuffer, imageDataToDataUrl, imageDataToImgBlob, imageDataToUint32Array, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makeAlphaMask, makeAlphaMaskPaintBufferCanvasRenderer, makeAlphaMaskTile, makeBinaryMask, makeBinaryMaskFromAlphaMask, makeBinaryMaskOutline, makeBinaryMaskPaintBufferCanvasRenderer, makeBinaryMaskTile, makeBlendModeRegistry, makeCanvasFrameRenderer, makeCanvasPixelDataRenderer, makeCircleBinaryMaskOutline, makeCirclePaintAlphaMask, makeCirclePaintBinaryMask, makeClippedBlit, makeClippedRect, makeColorPaintBufferCanvasRenderer, makeFastBlendModeRegistry, makeFullPixelMutator, makeHistoryAction, makeImageDataLike, makeIndexedImage, makeIndexedImageFromImageData, makeIndexedImageFromImageDataRaw, makePaintAlphaMask, makePaintBinaryMask, makePaintCursorRenderer, makePerfectBlendModeRegistry, makePixelCanvas, makePixelData, makePixelTile, makeRectBinaryMaskOutline, makeRectFalloffPaintAlphaMask, makeReusableCanvas, makeReusableImageData, makeReusableOffscreenCanvas, makeReusablePixelData, merge2BinaryMaskRects, mergeAlphaMasks, mergeBinaryMaskRects, mergeBinaryMasks, multiplyFast, multiplyPerfect, mutatorApplyAlphaMask, mutatorApplyBinaryMask, mutatorApplyMask, mutatorBlendAlphaMask, mutatorBlendBinaryMask, mutatorBlendColor, mutatorBlendColorPaintAlphaMask, mutatorBlendColorPaintBinaryMask, mutatorBlendColorPaintMask, mutatorBlendColorPaintRect, mutatorBlendMask, mutatorBlendPixel, mutatorBlendPixelData, mutatorClear, mutatorFill, mutatorFillBinaryMask, mutatorFillRect, mutatorInvert, overlayFast, overlayPerfect, overwriteBase, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resamplePixelDataInPlace, resampleUint32Array, resizeImageData, resolveBlitClipping, resolveRectClipping, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, setMaskData, setPixelData, softLightFast, softLightPerfect, sourceAtopFast, sourceAtopPerfect, sourceInFast, sourceInPerfect, sourceOutFast, sourceOutPerfect, sourceOverFast, sourceOverPerfect, subtractBinaryMaskRects, subtractFast, subtractPerfect, toBlendModeIndexAndName, trimMaskRectBounds, trimRectBounds, uInt32ArrayToImageData, uInt32ArrayToImageDataLike, uInt32ArrayToPixelData, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataBuffer, writeImageDataToClipboard, writeImgBlobToClipboard, writePaintBufferToPixelData, writePixelDataBuffer, xorFast, xorPerfect };