pixel-data-js 0.18.0 → 0.19.1

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 (77) hide show
  1. package/README.md +6 -1
  2. package/dist/index.dev.cjs +2723 -1487
  3. package/dist/index.dev.cjs.map +1 -1
  4. package/dist/index.dev.js +2690 -1481
  5. package/dist/index.dev.js.map +1 -1
  6. package/dist/index.prod.cjs +2723 -1487
  7. package/dist/index.prod.cjs.map +1 -1
  8. package/dist/index.prod.d.ts +400 -246
  9. package/dist/index.prod.js +2690 -1481
  10. package/dist/index.prod.js.map +1 -1
  11. package/package.json +22 -7
  12. package/src/Algorithm/forEachLinePoint.ts +36 -0
  13. package/src/BlendModes/BlendModeRegistry.ts +2 -0
  14. package/src/BlendModes/blend-modes-fast.ts +2 -2
  15. package/src/BlendModes/blend-modes-perfect.ts +5 -4
  16. package/src/BlendModes/toBlendModeIndexAndName.ts +41 -0
  17. package/src/History/PixelAccumulator.ts +2 -2
  18. package/src/History/PixelMutator/mutatorApplyAlphaMask.ts +30 -0
  19. package/src/History/PixelMutator/mutatorApplyBinaryMask.ts +30 -0
  20. package/src/History/PixelMutator/mutatorApplyCircleBrush.ts +23 -9
  21. package/src/History/PixelMutator/mutatorApplyCircleBrushStroke.ts +138 -0
  22. package/src/History/PixelMutator/mutatorApplyCirclePencil.ts +59 -0
  23. package/src/History/PixelMutator/mutatorApplyCirclePencilStroke.ts +131 -0
  24. package/src/History/PixelMutator/mutatorApplyRectBrush.ts +20 -7
  25. package/src/History/PixelMutator/mutatorApplyRectBrushStroke.ts +169 -0
  26. package/src/History/PixelMutator/mutatorApplyRectPencil.ts +62 -0
  27. package/src/History/PixelMutator/mutatorApplyRectPencilStroke.ts +149 -0
  28. package/src/History/PixelMutator/mutatorBlendColor.ts +9 -4
  29. package/src/History/PixelMutator/mutatorBlendPixelData.ts +10 -5
  30. package/src/History/PixelMutator/mutatorClear.ts +27 -0
  31. package/src/History/PixelMutator/{mutatorFillPixelData.ts → mutatorFill.ts} +9 -3
  32. package/src/History/PixelMutator/mutatorInvert.ts +10 -3
  33. package/src/History/PixelMutator.ts +23 -3
  34. package/src/History/PixelPatchTiles.ts +2 -2
  35. package/src/History/PixelWriter.ts +3 -3
  36. package/src/ImageData/ImageDataLike.ts +13 -0
  37. package/src/ImageData/extractImageDataBuffer.ts +22 -15
  38. package/src/ImageData/serialization.ts +4 -4
  39. package/src/ImageData/uInt32ArrayToImageData.ts +29 -0
  40. package/src/ImageData/writeImageData.ts +26 -18
  41. package/src/ImageData/writeImageDataBuffer.ts +30 -18
  42. package/src/IndexedImage/indexedImageToAverageColor.ts +1 -1
  43. package/src/Internal/resolveClipping.ts +140 -0
  44. package/src/Mask/applyBinaryMaskToAlphaMask.ts +89 -0
  45. package/src/Mask/copyMask.ts +1 -3
  46. package/src/Mask/mergeAlphaMasks.ts +81 -0
  47. package/src/Mask/mergeBinaryMasks.ts +89 -0
  48. package/src/PixelData/PixelBuffer32.ts +28 -0
  49. package/src/PixelData/PixelData.ts +38 -33
  50. package/src/PixelData/applyAlphaMaskToPixelData.ts +119 -0
  51. package/src/PixelData/applyBinaryMaskToPixelData.ts +111 -0
  52. package/src/PixelData/applyCircleBrushToPixelData.ts +31 -56
  53. package/src/PixelData/applyRectBrushToPixelData.ts +39 -71
  54. package/src/PixelData/blendColorPixelData.ts +18 -111
  55. package/src/PixelData/blendColorPixelDataAlphaMask.ts +111 -0
  56. package/src/PixelData/blendColorPixelDataBinaryMask.ts +89 -0
  57. package/src/PixelData/blendPixelData.ts +19 -107
  58. package/src/PixelData/blendPixelDataAlphaMask.ts +149 -0
  59. package/src/PixelData/blendPixelDataBinaryMask.ts +133 -0
  60. package/src/PixelData/clearPixelData.ts +2 -3
  61. package/src/PixelData/extractPixelData.ts +4 -4
  62. package/src/PixelData/extractPixelDataBuffer.ts +38 -26
  63. package/src/PixelData/fillPixelData.ts +18 -20
  64. package/src/PixelData/invertPixelData.ts +13 -21
  65. package/src/PixelData/pixelDataToAlphaMask.ts +2 -3
  66. package/src/PixelData/reflectPixelData.ts +3 -3
  67. package/src/PixelData/resamplePixelData.ts +2 -6
  68. package/src/PixelData/writePixelDataBuffer.ts +34 -20
  69. package/src/Rect/getCircleBrushOrPencilBounds.ts +43 -0
  70. package/src/Rect/getCircleBrushOrPencilStrokeBounds.ts +24 -0
  71. package/src/Rect/getRectBrushOrPencilBounds.ts +38 -0
  72. package/src/Rect/getRectBrushOrPencilStrokeBounds.ts +26 -0
  73. package/src/_types.ts +49 -33
  74. package/src/index.ts +47 -11
  75. package/src/History/PixelMutator/mutatorApplyMask.ts +0 -20
  76. package/src/Mask/mergeMasks.ts +0 -100
  77. package/src/PixelData/applyMaskToPixelData.ts +0 -129
@@ -24,6 +24,9 @@ type ImageDataLike = {
24
24
  height: number;
25
25
  data: Uint8ClampedArray<ArrayBufferLike>;
26
26
  };
27
+ type ImageDataLikeConstructor<T extends ImageDataLike = ImageDataLike> = {
28
+ new (data: Uint8ClampedArray, width: number, height: number): T;
29
+ };
27
30
  type SerializedImageData = {
28
31
  width: number;
29
32
  height: number;
@@ -67,7 +70,7 @@ type AnyMask = BinaryMask | AlphaMask;
67
70
  * Configuration for pixel manipulation operations.
68
71
  * Designed to be used by spreading a Rect object ({x, y, w, h}) directly.
69
72
  */
70
- interface PixelRectOptions {
73
+ interface PixelRect {
71
74
  /**
72
75
  * The starting X coordinate in the destination buffer.
73
76
  * @default 0
@@ -79,22 +82,17 @@ interface PixelRectOptions {
79
82
  */
80
83
  y?: number;
81
84
  /**
82
- * The width of the region to process.
85
+ * The width of the region in the destination buffer.
83
86
  * @default Source width.
84
87
  */
85
88
  w?: number;
86
89
  /**
87
- * The height of the region to process.
90
+ * The height of the region in the destination buffer.
88
91
  * @default Source height.
89
92
  */
90
93
  h?: number;
91
94
  }
92
- interface PixelMaskRectOptions {
93
- /**
94
- * Mask width.
95
- * @default value of `w`
96
- */
97
- mw?: number;
95
+ interface MaskOffset {
98
96
  /**
99
97
  * X offset into the mask buffer.
100
98
  * @default 0
@@ -106,38 +104,39 @@ interface PixelMaskRectOptions {
106
104
  */
107
105
  my?: number;
108
106
  }
109
- interface PixelMaskInvertOptions {
107
+ interface MaskOffsetWidth {
108
+ /**
109
+ * Mask width.
110
+ * @default value of `w`
111
+ */
112
+ mw?: number;
113
+ }
114
+ interface InvertMask {
110
115
  /**
111
116
  * If true the inverse of the mask will be applied
112
117
  * @default false
113
118
  */
114
119
  invertMask?: boolean;
115
120
  }
116
- /**
117
- * Configuration for pixel manipulation operations.
118
- * Designed to be used by spreading a Rect object ({x, y, w, h}) directly.
119
- */
120
- interface PixelOptions extends PixelRectOptions, PixelMaskRectOptions, PixelMaskInvertOptions {
121
+ interface Alpha {
121
122
  /**
122
123
  * Overall layer opacity 0-255.
123
124
  * @default 255
124
125
  */
125
126
  alpha?: number;
126
- /** An optional mask to restrict where pixels are written. */
127
- mask?: AnyMask | null;
128
- /** The interpretation logic for the provided mask.
129
- * @default {@link MaskType.ALPHA}
130
- */
131
- maskType?: MaskType;
132
127
  }
133
- interface PixelMutateOptions extends PixelRectOptions, PixelMaskRectOptions, PixelMaskInvertOptions {
128
+ interface ApplyMaskToPixelDataOptions extends PixelRect, Alpha, MaskOffsetWidth, MaskOffset, InvertMask {
129
+ }
130
+ interface MergeAlphaMasksOptions extends PixelRect, Alpha, MaskOffset, InvertMask {
131
+ }
132
+ interface PixelMutateOptions extends PixelRect, MaskOffset, MaskOffsetWidth, InvertMask {
134
133
  /** An optional mask to restrict where pixels are mutated. */
135
134
  mask?: BinaryMask | null;
136
135
  }
137
136
  /**
138
137
  * Configuration for blitting (copying/blending) one image into another.
139
138
  */
140
- interface PixelBlendOptions extends PixelOptions {
139
+ interface BasePixelBlendOptions {
141
140
  /**
142
141
  * The source rectangle x-coordinate
143
142
  * @default 0
@@ -150,21 +149,26 @@ interface PixelBlendOptions extends PixelOptions {
150
149
  sy?: number;
151
150
  /**
152
151
  * The blending algorithm to use for blending pixels.
153
- * @default {@link sourceOverFast}
152
+ * @default {@link sourceOverPerfect}
154
153
  */
155
154
  blendFn?: BlendColor32;
156
155
  }
156
+ interface PixelBlendOptions extends PixelRect, Alpha, BasePixelBlendOptions {
157
+ }
158
+ interface PixelBlendMaskOptions extends PixelRect, Alpha, MaskOffsetWidth, MaskOffset, InvertMask, BasePixelBlendOptions {
159
+ }
157
160
  /**
158
161
  * Configuration for operations that require color blending.
159
162
  */
160
- interface ColorBlendOptions extends PixelOptions {
163
+ interface ColorBlendOptions extends PixelRect, Alpha {
161
164
  /**
162
165
  * The blending algorithm to use for blending pixels.
163
- * @default {@link sourceOverFast}
166
+ * @default {@link sourceOverPerfect}
164
167
  */
165
168
  blendFn?: BlendColor32;
166
169
  }
167
- type ApplyMaskOptions = Omit<PixelOptions, 'mask'>;
170
+ interface ColorBlendMaskOptions extends ColorBlendOptions, MaskOffset, MaskOffsetWidth, InvertMask {
171
+ }
168
172
  type SelectionRect = Rect & ({
169
173
  mask: Uint8Array;
170
174
  maskType: MaskType;
@@ -172,10 +176,12 @@ type SelectionRect = Rect & ({
172
176
  mask?: null;
173
177
  maskType?: null;
174
178
  });
175
- type Point = {
176
- x: number;
177
- y: number;
178
- };
179
+ type HistoryMutator<T extends {}, D extends {}> = (writer: PixelWriter<any>, deps?: Partial<D>) => T;
180
+ interface IPixelData {
181
+ readonly data32: Uint32Array;
182
+ readonly width: number;
183
+ readonly height: number;
184
+ }
179
185
 
180
186
  /**
181
187
  * Packs RGBA into a 32-bit integer compatible with
@@ -218,17 +224,14 @@ declare function color32ToHex(color: Color32): string;
218
224
  */
219
225
  declare function color32ToCssRGBA(color: Color32): string;
220
226
 
221
- declare class PixelData {
222
- data32: Uint32Array;
223
- imageData: ImageData;
224
- get width(): number;
225
- get height(): number;
226
- constructor(imageData: ImageData);
227
- set(imageData: ImageData): void;
228
- /**
229
- * Creates a deep copy of the PixelData using the environment's ImageData constructor.
230
- */
231
- copy(): PixelData;
227
+ declare class PixelData<T extends ImageDataLike = ImageData> implements IPixelData {
228
+ readonly data32: Uint32Array;
229
+ readonly imageData: T;
230
+ readonly width: number;
231
+ readonly height: number;
232
+ constructor(imageData: T);
233
+ set(imageData: T): void;
234
+ copy(): PixelData<T>;
232
235
  }
233
236
 
234
237
  type FloodFillImageDataOptions = {
@@ -276,49 +279,6 @@ type FloodFillResult = {
276
279
  */
277
280
  declare function floodFillSelection(img: ImageDataLike | PixelData, startX: number, startY: number, { contiguous, tolerance, bounds, }?: FloodFillImageDataOptions): FloodFillResult | null;
278
281
 
279
- declare const BaseBlendMode: {
280
- readonly overwrite: 0;
281
- readonly sourceOver: 1;
282
- readonly darken: 2;
283
- readonly multiply: 3;
284
- readonly colorBurn: 4;
285
- readonly linearBurn: 5;
286
- readonly darkerColor: 6;
287
- readonly lighten: 7;
288
- readonly screen: 8;
289
- readonly colorDodge: 9;
290
- readonly linearDodge: 10;
291
- readonly lighterColor: 11;
292
- readonly overlay: 12;
293
- readonly softLight: 13;
294
- readonly hardLight: 14;
295
- readonly vividLight: 15;
296
- readonly linearLight: 16;
297
- readonly pinLight: 17;
298
- readonly hardMix: 18;
299
- readonly difference: 19;
300
- readonly exclusion: 20;
301
- readonly subtract: 21;
302
- readonly divide: 22;
303
- };
304
- interface RequiredBlendModes {
305
- overwrite: 0;
306
- }
307
- type BaseBlendModes = RequiredBlendModes & Record<string, number>;
308
- declare const overwriteBase: BlendColor32;
309
-
310
- type BlendModeRegistry<BlendModes extends BaseBlendModes = BaseBlendModes, Name extends keyof BlendModes = keyof BlendModes, Index extends BlendModes[Name] = BlendModes[Name]> = ReturnType<typeof makeBlendModeRegistry<BlendModes, Name, Index>>;
311
- declare function makeBlendModeRegistry<BlendModes extends BaseBlendModes, Name extends keyof BlendModes = keyof BlendModes, Index extends BlendModes[Name] = BlendModes[Name]>(blendModes: BlendModes, initialEntries: Record<Index, BlendColor32>): {
312
- nameToBlend: { [K in keyof BlendModes]: BlendColor32; };
313
- nameToIndex: Record<Name, Index>;
314
- blendToIndex: Map<BlendColor32, Index>;
315
- blendToName: Map<BlendColor32, Name>;
316
- indexToBlend: BlendColor32[];
317
- indexToName: Name[];
318
- indexType: Index;
319
- nameType: Name;
320
- };
321
-
322
282
  declare const overwriteFast: BlendColor32;
323
283
  declare const sourceOverFast: BlendColor32;
324
284
  declare const darkenFast: BlendColor32;
@@ -366,7 +326,8 @@ declare const subtractFast: BlendColor32;
366
326
  /** sr === 0 ? 255 : Math.min(255, (dr << 8) / sr) */
367
327
  declare const divideFast: BlendColor32;
368
328
  declare const BASE_FAST_BLEND_MODE_FUNCTIONS: Record<number, BlendColor32>;
369
- declare function makeFastBlendModeRegistry(): {
329
+ declare function makeFastBlendModeRegistry(name?: string): {
330
+ registryName: string;
370
331
  nameToBlend: {
371
332
  readonly overwrite: BlendColor32;
372
333
  readonly sourceOver: BlendColor32;
@@ -392,12 +353,12 @@ declare function makeFastBlendModeRegistry(): {
392
353
  readonly subtract: BlendColor32;
393
354
  readonly divide: BlendColor32;
394
355
  };
395
- 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 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22>;
396
- blendToIndex: Map<BlendColor32, 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22>;
356
+ 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 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22>;
357
+ blendToIndex: Map<BlendColor32, 0 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22>;
397
358
  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">;
398
359
  indexToBlend: BlendColor32[];
399
360
  indexToName: ("overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide")[];
400
- indexType: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22;
361
+ indexType: 0 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22;
401
362
  nameType: "overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide";
402
363
  };
403
364
 
@@ -448,7 +409,8 @@ declare const subtractPerfect: BlendColor32;
448
409
  /** sr === 0 ? 255 : Math.min(255, (dr << 8) / sr) */
449
410
  declare const dividePerfect: BlendColor32;
450
411
  declare const BASE_PERFECT_BLEND_MODE_FUNCTIONS: Record<number, BlendColor32>;
451
- declare function makePerfectBlendModeRegistry(): {
412
+ declare function makePerfectBlendModeRegistry(name?: string): {
413
+ registryName: string;
452
414
  nameToBlend: {
453
415
  readonly overwrite: BlendColor32;
454
416
  readonly sourceOver: BlendColor32;
@@ -474,15 +436,67 @@ declare function makePerfectBlendModeRegistry(): {
474
436
  readonly subtract: BlendColor32;
475
437
  readonly divide: BlendColor32;
476
438
  };
477
- 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 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22>;
478
- blendToIndex: Map<BlendColor32, 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22>;
439
+ 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 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22>;
440
+ blendToIndex: Map<BlendColor32, 0 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22>;
479
441
  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">;
480
442
  indexToBlend: BlendColor32[];
481
443
  indexToName: ("overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide")[];
482
- indexType: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22;
444
+ indexType: 0 | 16 | 8 | 2 | 3 | 1 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22;
483
445
  nameType: "overwrite" | "sourceOver" | "darken" | "multiply" | "colorBurn" | "linearBurn" | "darkerColor" | "lighten" | "screen" | "colorDodge" | "linearDodge" | "lighterColor" | "overlay" | "softLight" | "hardLight" | "vividLight" | "linearLight" | "pinLight" | "hardMix" | "difference" | "exclusion" | "subtract" | "divide";
484
446
  };
485
447
 
448
+ declare const BaseBlendMode: {
449
+ readonly overwrite: 0;
450
+ readonly sourceOver: 1;
451
+ readonly darken: 2;
452
+ readonly multiply: 3;
453
+ readonly colorBurn: 4;
454
+ readonly linearBurn: 5;
455
+ readonly darkerColor: 6;
456
+ readonly lighten: 7;
457
+ readonly screen: 8;
458
+ readonly colorDodge: 9;
459
+ readonly linearDodge: 10;
460
+ readonly lighterColor: 11;
461
+ readonly overlay: 12;
462
+ readonly softLight: 13;
463
+ readonly hardLight: 14;
464
+ readonly vividLight: 15;
465
+ readonly linearLight: 16;
466
+ readonly pinLight: 17;
467
+ readonly hardMix: 18;
468
+ readonly difference: 19;
469
+ readonly exclusion: 20;
470
+ readonly subtract: 21;
471
+ readonly divide: 22;
472
+ };
473
+ interface RequiredBlendModes {
474
+ overwrite: 0;
475
+ }
476
+ type BaseBlendModes = RequiredBlendModes & Record<string, number>;
477
+ declare const overwriteBase: BlendColor32;
478
+
479
+ type BlendModeRegistry<BlendModes extends BaseBlendModes = BaseBlendModes, Name extends keyof BlendModes = keyof BlendModes, Index extends BlendModes[Name] = BlendModes[Name]> = ReturnType<typeof makeBlendModeRegistry<BlendModes, Name, Index>>;
480
+ 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): {
481
+ registryName: string;
482
+ nameToBlend: { [K in keyof BlendModes]: BlendColor32; };
483
+ nameToIndex: Record<Name, Index>;
484
+ blendToIndex: Map<BlendColor32, Index>;
485
+ blendToName: Map<BlendColor32, Name>;
486
+ indexToBlend: BlendColor32[];
487
+ indexToName: Name[];
488
+ indexType: Index;
489
+ nameType: Name;
490
+ };
491
+
492
+ declare function toBlendModeIndexAndName(input: string | number): {
493
+ blendIndex: number;
494
+ blendName: string;
495
+ };
496
+
497
+ declare const OFFSCREEN_CANVAS_CTX_FAILED = "Failed to create OffscreenCanvas context";
498
+ declare const CANVAS_CTX_FAILED = "Failed to create Canvas context";
499
+
486
500
  type PixelCanvas = {
487
501
  readonly canvas: HTMLCanvasElement;
488
502
  readonly ctx: CanvasRenderingContext2D;
@@ -561,6 +575,27 @@ declare function writeImageDataToClipboard(imageData: ImageData): Promise<void>;
561
575
  */
562
576
  declare function writeImgBlobToClipboard(blob: Blob): Promise<void>;
563
577
 
578
+ interface HistoryAction {
579
+ undo: () => void;
580
+ redo: () => void;
581
+ dispose?: () => void;
582
+ }
583
+ declare class HistoryManager {
584
+ maxSteps: number;
585
+ undoStack: HistoryAction[];
586
+ redoStack: HistoryAction[];
587
+ listeners: Set<() => void>;
588
+ constructor(maxSteps?: number);
589
+ get canUndo(): boolean;
590
+ get canRedo(): boolean;
591
+ subscribe(fn: () => void): () => boolean;
592
+ notify(): void;
593
+ commit(action: HistoryAction): void;
594
+ undo(): void;
595
+ redo(): void;
596
+ clearRedoStack(): void;
597
+ }
598
+
564
599
  declare class PixelEngineConfig {
565
600
  readonly tileSize: number;
566
601
  readonly tileShift: number;
@@ -580,15 +615,15 @@ declare class PixelTile {
580
615
  data32: Uint32Array;
581
616
  constructor(id: number, tx: number, ty: number, tileArea: number);
582
617
  }
583
- declare function applyPatchTiles(target: PixelData, tiles: PixelTile[], tileSize?: number): void;
618
+ declare function applyPatchTiles(target: IPixelData, tiles: PixelTile[], tileSize?: number): void;
584
619
 
585
620
  declare class PixelAccumulator {
586
- target: PixelData;
621
+ target: IPixelData;
587
622
  readonly config: PixelEngineConfig;
588
623
  lookup: (PixelTile | undefined)[];
589
624
  beforeTiles: PixelTile[];
590
625
  pool: PixelTile[];
591
- constructor(target: PixelData, config: PixelEngineConfig);
626
+ constructor(target: IPixelData, config: PixelEngineConfig);
592
627
  getTile(id: number, tx: number, ty: number): PixelTile;
593
628
  recyclePatch(patch: PixelPatchTiles): void;
594
629
  /**
@@ -609,27 +644,6 @@ declare class PixelAccumulator {
609
644
  reset(): void;
610
645
  }
611
646
 
612
- interface HistoryAction {
613
- undo: () => void;
614
- redo: () => void;
615
- dispose?: () => void;
616
- }
617
- declare class HistoryManager {
618
- maxSteps: number;
619
- undoStack: HistoryAction[];
620
- redoStack: HistoryAction[];
621
- listeners: Set<() => void>;
622
- constructor(maxSteps?: number);
623
- get canUndo(): boolean;
624
- get canRedo(): boolean;
625
- subscribe(fn: () => void): () => boolean;
626
- notify(): void;
627
- commit(action: HistoryAction): void;
628
- undo(): void;
629
- redo(): void;
630
- clearRedoStack(): void;
631
- }
632
-
633
647
  interface PixelWriterOptions {
634
648
  maxHistorySteps?: number;
635
649
  tileSize?: number;
@@ -657,32 +671,184 @@ interface PixelWriterOptions {
657
671
  * })
658
672
  */
659
673
  declare class PixelWriter<M> {
660
- target: PixelData;
674
+ target: IPixelData;
661
675
  historyManager: HistoryManager;
662
676
  accumulator: PixelAccumulator;
663
677
  protected config: PixelEngineConfig;
664
678
  readonly mutator: M;
665
- constructor(target: PixelData, mutatorFactory: (writer: PixelWriter<any>) => M, { tileSize, maxHistorySteps, historyManager, }?: PixelWriterOptions);
679
+ constructor(target: IPixelData, mutatorFactory: (writer: PixelWriter<any>) => M, { tileSize, maxHistorySteps, historyManager, }?: PixelWriterOptions);
666
680
  withHistory(cb: (mutator: M) => void): void;
667
681
  captureHistory(): void;
668
682
  }
669
683
 
670
684
  declare function makeFullPixelMutator(writer: PixelWriter<any>): {
671
- applyRectBrush(color: Color32, centerX: number, centerY: number, brushWidth: number, brushHeight: number, alpha?: number, fallOff?: (dist: number) => number, blendFn?: BlendColor32): void;
672
- applyCircleBrush(color: Color32, centerX: number, centerY: number, brushSize: number, alpha?: number, fallOff?: (dist: number) => number, blendFn?: BlendColor32): void;
685
+ clear(rect?: Partial<Rect>): void;
686
+ applyRectPencilStroke(color: Color32, x0: number, y0: number, x1: number, y1: number, brushWidth: number, brushHeight: number, alpha?: number, blendFn?: BlendColor32): void;
687
+ applyRectPencil(color: Color32, centerX: number, centerY: number, brushWidth: number, brushHeight: number, alpha?: number, blendFn?: BlendColor32): void;
688
+ applyRectBrushStroke(color: Color32, x0: number, y0: number, x1: number, y1: number, brushWidth: number, brushHeight: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32): void;
689
+ applyRectBrush(color: Color32, centerX: number, centerY: number, brushWidth: number, brushHeight: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32): void;
690
+ applyCirclePencilStroke(color: Color32, x0: number, y0: number, x1: number, y1: number, brushSize: number, alpha?: number, blendFn?: BlendColor32): void;
691
+ applyCircleBrushStroke(color: Color32, x0: number, y0: number, x1: number, y1: number, brushSize: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32): void;
692
+ applyCircleBrush(color: Color32, centerX: number, centerY: number, brushSize: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32): void;
673
693
  invert(opts?: PixelMutateOptions): void;
674
694
  fill(color: Color32, rect?: Partial<Rect>): void;
675
695
  blendPixel(x: number, y: number, color: Color32, alpha?: number, blendFn?: BlendColor32): void;
676
696
  blendColor(color: Color32, opts?: ColorBlendOptions): void;
677
- blendPixelData(src: PixelData, opts: PixelBlendOptions): void;
678
- applyMask: (mask: AnyMask, opts?: ApplyMaskOptions) => void;
697
+ blendPixelData(src: IPixelData, opts: PixelBlendOptions): void;
698
+ applyBinaryMask: (mask: BinaryMask, opts?: ApplyMaskToPixelDataOptions) => void;
699
+ applyAlphaMask: (mask: AlphaMask, opts?: ApplyMaskToPixelDataOptions) => void;
700
+ };
701
+
702
+ declare function applyAlphaMaskToPixelData(dst: IPixelData, mask: AlphaMask, opts?: ApplyMaskToPixelDataOptions): void;
703
+
704
+ declare const defaults$e: {
705
+ applyAlphaMaskToPixelData: typeof applyAlphaMaskToPixelData;
706
+ };
707
+ type Deps$e = Partial<typeof defaults$e>;
708
+ declare const mutatorApplyAlphaMask: (writer: PixelWriter<any>, deps?: Deps$e) => {
709
+ applyAlphaMask: (mask: AlphaMask, opts?: ApplyMaskToPixelDataOptions) => void;
679
710
  };
680
711
 
681
- declare function mutatorApplyMask(writer: PixelWriter<any>): {
682
- applyMask: (mask: AnyMask, opts?: ApplyMaskOptions) => void;
712
+ /**
713
+ * Directly applies a mask to a region of PixelData,
714
+ * modifying the destination's alpha channel in-place.
715
+ */
716
+ declare function applyBinaryMaskToPixelData(dst: IPixelData, mask: BinaryMask, opts?: ApplyMaskToPixelDataOptions): void;
717
+
718
+ declare const defaults$d: {
719
+ applyBinaryMaskToPixelData: typeof applyBinaryMaskToPixelData;
720
+ };
721
+ type Deps$d = Partial<typeof defaults$d>;
722
+ declare const mutatorApplyBinaryMask: (writer: PixelWriter<any>, deps?: Deps$d) => {
723
+ applyBinaryMask: (mask: BinaryMask, opts?: ApplyMaskToPixelDataOptions) => void;
683
724
  };
684
725
 
685
- declare function mutatorBlendColor(writer: PixelWriter<any>): {
726
+ /**
727
+ * Applies a circular brush to pixel data, blending a color with optional falloff.
728
+ *
729
+ * @param target The PixelData to modify.
730
+ * @param color The brush color.
731
+ * @param centerX The center x-coordinate of the brush.
732
+ * @param centerY The center y-coordinate of the brush.
733
+ * @param brushSize The diameter of the brush.
734
+ * @param alpha The overall opacity of the brush (0-255).
735
+ * @default 255
736
+ * @param fallOff A function that returns an alpha multiplier (0-1) based on the normalized distance (0-1) from the circle's center.
737
+ * @param blendFn
738
+ * @param bounds precalculated result from {@link getCircleBrushOrPencilBounds}
739
+ * @default sourceOverPerfect
740
+ */
741
+ declare function applyCircleBrushToPixelData(target: IPixelData, color: Color32, centerX: number, centerY: number, brushSize: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32, bounds?: Rect): void;
742
+
743
+ declare function getCircleBrushOrPencilBounds(centerX: number, centerY: number, brushSize: number, targetWidth: number, targetHeight: number, out?: Rect): Rect;
744
+
745
+ declare const defaults$c: {
746
+ applyCircleBrushToPixelData: typeof applyCircleBrushToPixelData;
747
+ getCircleBrushOrPencilBounds: typeof getCircleBrushOrPencilBounds;
748
+ };
749
+ type Deps$c = Partial<typeof defaults$c>;
750
+ declare const mutatorApplyCircleBrush: (writer: PixelWriter<any>, deps?: Deps$c) => {
751
+ applyCircleBrush(color: Color32, centerX: number, centerY: number, brushSize: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32): void;
752
+ };
753
+
754
+ /**
755
+ * Iterates through a line with sub-pixel precision.
756
+ * Guarantees that the first and last points are exactly (x0, y0) and (x1, y1).
757
+ */
758
+ declare function forEachLinePoint(x0: number, y0: number, x1: number, y1: number, callback: (x: number, y: number) => void): void;
759
+
760
+ declare function blendColorPixelDataAlphaMask(dst: IPixelData, color: Color32, mask: AlphaMask, opts: ColorBlendMaskOptions): void;
761
+
762
+ declare function getCircleBrushOrPencilStrokeBounds(x0: number, y0: number, x1: number, y1: number, brushSize: number, result: Rect): Rect;
763
+
764
+ declare const defaults$b: {
765
+ forEachLinePoint: typeof forEachLinePoint;
766
+ blendColorPixelDataAlphaMask: typeof blendColorPixelDataAlphaMask;
767
+ getCircleBrushOrPencilBounds: typeof getCircleBrushOrPencilBounds;
768
+ getCircleBrushOrPencilStrokeBounds: typeof getCircleBrushOrPencilStrokeBounds;
769
+ };
770
+ type Deps$b = Partial<typeof defaults$b>;
771
+ declare const mutatorApplyCircleBrushStroke: (writer: PixelWriter<any>, deps?: Deps$b) => {
772
+ applyCircleBrushStroke(color: Color32, x0: number, y0: number, x1: number, y1: number, brushSize: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32): void;
773
+ };
774
+
775
+ declare const defaults$a: {
776
+ applyCircleBrushToPixelData: typeof applyCircleBrushToPixelData;
777
+ getCircleBrushOrPencilBounds: typeof getCircleBrushOrPencilBounds;
778
+ fallOff: () => number;
779
+ };
780
+ type Deps$a = Partial<typeof defaults$a>;
781
+ declare const mutatorApplyCirclePencil: (writer: PixelWriter<any>, deps?: Deps$a) => {
782
+ applyCirclePencil(color: Color32, centerX: number, centerY: number, brushSize: number, alpha?: number, blendFn?: BlendColor32): void;
783
+ };
784
+
785
+ declare function blendColorPixelDataBinaryMask(dst: IPixelData, color: Color32, mask: BinaryMask, opts?: ColorBlendMaskOptions): void;
786
+
787
+ declare const defaults$9: {
788
+ forEachLinePoint: typeof forEachLinePoint;
789
+ blendColorPixelDataBinaryMask: typeof blendColorPixelDataBinaryMask;
790
+ getCircleBrushOrPencilBounds: typeof getCircleBrushOrPencilBounds;
791
+ getCircleBrushOrPencilStrokeBounds: typeof getCircleBrushOrPencilStrokeBounds;
792
+ };
793
+ type Deps$9 = Partial<typeof defaults$9>;
794
+ declare const mutatorApplyCirclePencilStroke: (writer: PixelWriter<any>, deps?: Deps$9) => {
795
+ applyCirclePencilStroke(color: Color32, x0: number, y0: number, x1: number, y1: number, brushSize: number, alpha?: number, blendFn?: BlendColor32): void;
796
+ };
797
+
798
+ declare function applyRectBrushToPixelData(target: IPixelData, color: Color32, centerX: number, centerY: number, brushWidth: number, brushHeight: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32, bounds?: Rect): void;
799
+
800
+ declare function getRectBrushOrPencilBounds(centerX: number, centerY: number, brushWidth: number, brushHeight: number, targetWidth: number, targetHeight: number, out?: Rect): Rect;
801
+
802
+ declare const defaults$8: {
803
+ applyRectBrushToPixelData: typeof applyRectBrushToPixelData;
804
+ getRectBrushOrPencilBounds: typeof getRectBrushOrPencilBounds;
805
+ fallOff: () => number;
806
+ };
807
+ type Deps$8 = Partial<typeof defaults$8>;
808
+ declare const mutatorApplyRectPencil: (writer: PixelWriter<any>, deps?: Deps$8) => {
809
+ applyRectPencil(color: Color32, centerX: number, centerY: number, brushWidth: number, brushHeight: number, alpha?: number, blendFn?: BlendColor32): void;
810
+ };
811
+
812
+ declare function getRectBrushOrPencilStrokeBounds(x0: number, y0: number, x1: number, y1: number, brushWidth: number, brushHeight: number, result: Rect): Rect;
813
+
814
+ declare const defaults$7: {
815
+ forEachLinePoint: typeof forEachLinePoint;
816
+ getRectBrushOrPencilBounds: typeof getRectBrushOrPencilBounds;
817
+ getRectBrushOrPencilStrokeBounds: typeof getRectBrushOrPencilStrokeBounds;
818
+ blendColorPixelDataBinaryMask: typeof blendColorPixelDataBinaryMask;
819
+ };
820
+ type Deps$7 = Partial<typeof defaults$7>;
821
+ declare const mutatorApplyRectPencilStroke: (writer: PixelWriter<any>, deps?: Deps$7) => {
822
+ applyRectPencilStroke(color: Color32, x0: number, y0: number, x1: number, y1: number, brushWidth: number, brushHeight: number, alpha?: number, blendFn?: BlendColor32): void;
823
+ };
824
+
825
+ declare const defaults$6: {
826
+ applyRectBrushToPixelData: typeof applyRectBrushToPixelData;
827
+ getRectBrushOrPencilBounds: typeof getRectBrushOrPencilBounds;
828
+ };
829
+ type Deps$6 = Partial<typeof defaults$6>;
830
+ declare const mutatorApplyRectBrush: (writer: PixelWriter<any>, deps?: Deps$6) => {
831
+ applyRectBrush(color: Color32, centerX: number, centerY: number, brushWidth: number, brushHeight: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32): void;
832
+ };
833
+
834
+ declare const defaults$5: {
835
+ forEachLinePoint: typeof forEachLinePoint;
836
+ blendColorPixelDataAlphaMask: typeof blendColorPixelDataAlphaMask;
837
+ getRectBrushOrPencilBounds: typeof getRectBrushOrPencilBounds;
838
+ getRectBrushOrPencilStrokeBounds: typeof getRectBrushOrPencilStrokeBounds;
839
+ };
840
+ type Deps$5 = Partial<typeof defaults$5>;
841
+ declare const mutatorApplyRectBrushStroke: (writer: PixelWriter<any>, deps?: Deps$5) => {
842
+ applyRectBrushStroke(color: Color32, x0: number, y0: number, x1: number, y1: number, brushWidth: number, brushHeight: number, alpha: number | undefined, fallOff: (dist: number) => number, blendFn?: BlendColor32): void;
843
+ };
844
+
845
+ declare function blendColorPixelData(dst: IPixelData, color: Color32, opts?: ColorBlendOptions): void;
846
+
847
+ declare const defaults$4: {
848
+ blendColorPixelData: typeof blendColorPixelData;
849
+ };
850
+ type Deps$4 = Partial<typeof defaults$4>;
851
+ declare const mutatorBlendColor: (writer: PixelWriter<any>, deps?: Deps$4) => {
686
852
  blendColor(color: Color32, opts?: ColorBlendOptions): void;
687
853
  };
688
854
 
@@ -690,27 +856,75 @@ declare function mutatorBlendPixel(writer: PixelWriter<any>): {
690
856
  blendPixel(x: number, y: number, color: Color32, alpha?: number, blendFn?: BlendColor32): void;
691
857
  };
692
858
 
693
- declare function mutatorBlendPixelData(writer: PixelWriter<any>): {
694
- blendPixelData(src: PixelData, opts: PixelBlendOptions): void;
859
+ /**
860
+ * Blits source PixelData into a destination PixelData using 32-bit integer bitwise blending.
861
+ * This function bypasses standard ImageData limitations by operating directly on
862
+ * Uint32Array views. It supports various blend modes, binary/alpha masking, and
863
+ * automatic clipping of both source and destination bounds.
864
+ * @example
865
+ *
866
+ * const dst = new PixelData(ctx.getImageData(0,0,100,100))
867
+ * blendImageData32(dst, sprite, {
868
+ * blendFn: COLOR_32_BLEND_MODES.multiply,
869
+ * mask: brushMask,
870
+ * maskType: MaskType.ALPHA
871
+ * });
872
+ */
873
+ declare function blendPixelData(dst: IPixelData, src: IPixelData, opts: PixelBlendOptions): void;
874
+
875
+ declare const defaults$3: {
876
+ blendPixelData: typeof blendPixelData;
877
+ };
878
+ type Deps$3 = Partial<typeof defaults$3>;
879
+ declare const mutatorBlendPixelData: (writer: PixelWriter<any>, deps?: Partial<Deps$3>) => {
880
+ blendPixelData(src: IPixelData, opts: PixelBlendOptions): void;
695
881
  };
696
882
 
697
- declare function mutatorFill(writer: PixelWriter<any>): {
883
+ /**
884
+ * Fills a region or the {@link PixelData} buffer with a solid color.
885
+ *
886
+ * @param dst - The target {@link PixelData} to modify.
887
+ * @param color - The {@link Color32} value to apply.
888
+ * @param rect - A {@link Rect} defining the area to fill. If omitted, the entire
889
+ * buffer is filled.
890
+ */
891
+ declare function fillPixelData(dst: IPixelData, color: Color32, rect?: Partial<Rect>): void;
892
+ /**
893
+ * @param dst - The target {@link PixelData} to modify.
894
+ * @param color - The {@link Color32} value to apply.
895
+ * @param x - Starting horizontal coordinate.
896
+ * @param y - Starting vertical coordinate.
897
+ * @param w - Width of the fill area.
898
+ * @param h - Height of the fill area.
899
+ */
900
+ declare function fillPixelData(dst: IPixelData, color: Color32, x: number, y: number, w: number, h: number): void;
901
+
902
+ declare const defaults$2: {
903
+ fillPixelData: typeof fillPixelData;
904
+ };
905
+ type Deps$2 = Partial<typeof defaults$2>;
906
+ declare const mutatorClear: (writer: PixelWriter<any>, deps?: Deps$2) => {
907
+ clear(rect?: Partial<Rect>): void;
908
+ };
909
+
910
+ declare const defaults$1: {
911
+ fillPixelData: typeof fillPixelData;
912
+ };
913
+ type Deps$1 = Partial<typeof defaults$1>;
914
+ declare const mutatorFill: (writer: PixelWriter<any>, deps?: Deps$1) => {
698
915
  fill(color: Color32, rect?: Partial<Rect>): void;
699
916
  };
700
917
 
701
- declare function mutatorInvert(writer: PixelWriter<any>): {
918
+ declare function invertPixelData(pixelData: IPixelData, opts?: PixelMutateOptions): void;
919
+
920
+ declare const defaults: {
921
+ invertPixelData: typeof invertPixelData;
922
+ };
923
+ type Deps = Partial<typeof defaults>;
924
+ declare const mutatorInvert: (writer: PixelWriter<any>, deps?: Deps) => {
702
925
  invert(opts?: PixelMutateOptions): void;
703
926
  };
704
927
 
705
- type ReusableImageData = ReturnType<typeof makeReusableImageData>;
706
- /**
707
- * Creates a factory function that manages a single, reusable ImageData instance.
708
- * This is used to minimize garbage collection overhead by recycling the
709
- * underlying pixel buffer across multiple operations.
710
- * @returns A function that takes width and height and returns a pooled ImageData instance.
711
- */
712
- declare function makeReusableImageData(): (width: number, height: number) => ImageData;
713
-
714
928
  declare function copyImageData({ data, width, height }: ImageDataLike): ImageData;
715
929
  declare function copyImageDataLike({ data, width, height }: ImageDataLike): ImageDataLike;
716
930
 
@@ -735,6 +949,8 @@ declare function extractImageDataBuffer(imageData: ImageDataLike, rect: Rect): U
735
949
  */
736
950
  declare function extractImageDataBuffer(imageData: ImageDataLike, x: number, y: number, w: number, h: number): Uint8ClampedArray;
737
951
 
952
+ declare function makeImageDataLike(width: number, height: number, data?: Buffer): ImageDataLike;
953
+
738
954
  /**
739
955
  * Extracts the alpha channel from raw ImageData into an AlphaMask.
740
956
  * When possible use {@link pixelDataToAlphaMask} instead.
@@ -854,6 +1070,15 @@ declare function resampleImageData(source: ImageData, factor: number): ImageData
854
1070
  */
855
1071
  declare function resizeImageData(current: ImageDataLike, newWidth: number, newHeight: number, offsetX?: number, offsetY?: number): ImageData;
856
1072
 
1073
+ type ReusableImageData = ReturnType<typeof makeReusableImageData>;
1074
+ /**
1075
+ * Creates a factory function that manages a single, reusable ImageData instance.
1076
+ * This is used to minimize garbage collection overhead by recycling the
1077
+ * underlying pixel buffer across multiple operations.
1078
+ * @returns A function that takes width and height and returns a pooled ImageData instance.
1079
+ */
1080
+ declare function makeReusableImageData(): (width: number, height: number) => ImageData;
1081
+
857
1082
  declare function base64EncodeArrayBuffer(buffer: ArrayBufferLike): Base64EncodedUInt8Array;
858
1083
  declare function base64DecodeArrayBuffer(encoded: Base64EncodedUInt8Array): Uint8ClampedArray<ArrayBuffer>;
859
1084
  /**
@@ -865,6 +1090,9 @@ declare function deserializeRawImageData<T extends SerializedImageData>(serializ
865
1090
  declare function deserializeImageData<T extends SerializedImageData>(serialized: T): ImageData;
866
1091
  declare function deserializeNullableImageData<T extends SerializedImageData | null>(serialized: T): T extends null ? null : ImageData;
867
1092
 
1093
+ declare function uInt32ArrayToImageData(data: Uint32Array, width: number, height: number): ImageData;
1094
+ declare function uInt32ArrayToImageDataLike(data: Uint32Array, width: number, height: number): ImageDataLike;
1095
+
868
1096
  /**
869
1097
  * Writes image data from a source to a target with support for clipping and alpha masking.
870
1098
  *
@@ -970,20 +1198,20 @@ declare function getIndexedImageColorCounts(indexedImage: IndexedImage): Int32Ar
970
1198
  declare function indexedImageToAverageColor(indexedImage: IndexedImage, includeTransparent?: boolean): Color32;
971
1199
 
972
1200
  /**
973
- * Resamples an IndexedImage by a specific factor using nearest neighbor
974
- * Factor > 1 upscales, Factor < 1 downscales.
1201
+ * Converts an IndexedImage back into standard ImageData.
975
1202
  */
1203
+ declare function indexedImageToImageData(indexedImage: IndexedImage): ImageData;
976
1204
 
977
1205
  /**
978
1206
  * Resamples an IndexedImage by a specific factor using nearest neighbor
979
1207
  * Factor > 1 upscales, Factor < 1 downscales.
980
1208
  */
981
- declare function resampleIndexedImage(source: IndexedImage, factor: number): IndexedImage;
982
1209
 
983
1210
  /**
984
- * Converts an IndexedImage back into standard ImageData.
1211
+ * Resamples an IndexedImage by a specific factor using nearest neighbor
1212
+ * Factor > 1 upscales, Factor < 1 downscales.
985
1213
  */
986
- declare function indexedImageToImageData(indexedImage: IndexedImage): ImageData;
1214
+ declare function resampleIndexedImage(source: IndexedImage, factor: number): IndexedImage;
987
1215
 
988
1216
  /**
989
1217
  * A convenience wrapper that extracts the first {@link File} from an
@@ -1072,11 +1300,13 @@ declare function fileToImageData(file: File | null | undefined): Promise<ImageDa
1072
1300
  */
1073
1301
  declare function getSupportedPixelFormats(rasterMimes?: string[]): Promise<string[]>;
1074
1302
 
1303
+ declare function applyBinaryMaskToAlphaMask(alphaMaskDst: AlphaMask, dstWidth: number, binaryMaskSrc: BinaryMask, srcWidth: number, opts?: ApplyMaskToPixelDataOptions): void;
1304
+
1075
1305
  /**
1076
1306
  * Creates a new copy of a mask.
1077
1307
  * Uses the underlying buffer's slice method for high-performance memory copying.
1078
1308
  */
1079
- declare function copyMask<T extends AnyMask>(src: T): T;
1309
+ declare function copyMask<T extends Uint8Array>(src: T): T;
1080
1310
 
1081
1311
  /**
1082
1312
  * Extracts a rectangular region from a 1D {@link Uint8Array} mask.
@@ -1110,135 +1340,59 @@ declare function invertBinaryMask(dst: BinaryMask): void;
1110
1340
  declare function invertAlphaMask(dst: AlphaMask): void;
1111
1341
 
1112
1342
  /**
1113
- * Merges a source mask into a destination AlphaMask.
1343
+ * Merges 2 alpha masks values are 0-255
1114
1344
  */
1115
- declare function mergeMasks(dst: AlphaMask, dstWidth: number, src: AnyMask, opts: ApplyMaskOptions): void;
1345
+ declare function mergeAlphaMasks(dst: AlphaMask, dstWidth: number, src: AlphaMask, srcWidth: number, opts: MergeAlphaMasksOptions): void;
1116
1346
 
1117
- /**
1118
- * Applies a circular brush to pixel data, blending a color with optional falloff.
1119
- *
1120
- * @param target The PixelData to modify.
1121
- * @param color The brush color.
1122
- * @param centerX The center x-coordinate of the brush.
1123
- * @param centerY The center y-coordinate of the brush.
1124
- * @param brushSize The diameter of the brush.
1125
- * @param alpha The overall opacity of the brush (0-255).
1126
- * @default 255
1127
- * @param fallOff A function that returns an alpha multiplier (0-1) based on the normalized distance (0-1) from the circle's center.
1128
- * @param blendFn
1129
- * @param bounds precalculated result from {@link getCircleBrushBounds}
1130
- * @default sourceOverPerfect
1131
- */
1132
- declare function applyCircleBrushToPixelData(target: PixelData, color: Color32, centerX: number, centerY: number, brushSize: number, alpha?: number, fallOff?: (dist: number) => number, blendFn?: BlendColor32, bounds?: Rect): void;
1133
- declare function getCircleBrushBounds(centerX: number, centerY: number, brushSize: number, targetWidth?: number, targetHeight?: number, out?: Rect): Rect;
1347
+ declare function mergeBinaryMasks(dst: BinaryMask, dstWidth: number, src: BinaryMask, srcWidth: number, opts: MergeAlphaMasksOptions): void;
1134
1348
 
1135
- /**
1136
- * Directly applies a mask to a region of PixelData,
1137
- * modifying the destination's alpha channel in-place.
1138
- */
1139
- declare function applyMaskToPixelData(dst: PixelData, mask: AnyMask, opts?: ApplyMaskOptions): void;
1349
+ declare function blendPixelDataAlphaMask(dst: IPixelData, src: IPixelData, alphaMask: AlphaMask, opts?: PixelBlendMaskOptions): void;
1140
1350
 
1141
- /**
1142
- * Applies a rectangular brush to pixel data, blending a color with optional falloff.
1143
- *
1144
- * @param target The PixelData to modify.
1145
- * @param color The brush color.
1146
- * @param centerX The center x-coordinate of the brush.
1147
- * @param centerY The center y-coordinate of the brush.
1148
- * @param brushWidth
1149
- * @param brushHeight
1150
- * @param alpha The overall opacity of the brush (0-255).
1151
- * @default 255
1152
- * @param fallOff A function that returns an alpha multiplier (0-1) based on the normalized distance (0-1) from the circle's center.
1153
- * @param blendFn
1154
- * @param bounds precalculated result from {@link getRectBrushBounds}
1155
- * @default sourceOverPerfect
1156
- */
1157
- declare function applyRectBrushToPixelData(target: PixelData, color: Color32, centerX: number, centerY: number, brushWidth: number, brushHeight: number, alpha?: number, fallOff?: (dist: number) => number, blendFn?: BlendColor32, bounds?: Rect): void;
1158
- declare function getRectBrushBounds(centerX: number, centerY: number, brushWidth: number, brushHeight: number, targetWidth?: number, targetHeight?: number, out?: Rect): Rect;
1159
-
1160
- /**
1161
- * Fills a rectangle in the destination PixelData with a single color,
1162
- * supporting blend modes, global alpha, and masking.
1163
- */
1164
- declare function blendColorPixelData(dst: PixelData, color: Color32, opts?: ColorBlendOptions): void;
1165
-
1166
- /**
1167
- * Blits source PixelData into a destination PixelData using 32-bit integer bitwise blending.
1168
- * This function bypasses standard ImageData limitations by operating directly on
1169
- * Uint32Array views. It supports various blend modes, binary/alpha masking, and
1170
- * automatic clipping of both source and destination bounds.
1171
- * @example
1172
- *
1173
- * const dst = new PixelData(ctx.getImageData(0,0,100,100))
1174
- * blendImageData32(dst, sprite, {
1175
- * blendFn: COLOR_32_BLEND_MODES.multiply,
1176
- * mask: brushMask,
1177
- * maskType: MaskType.ALPHA
1178
- * });
1179
- */
1180
- declare function blendPixelData(dst: PixelData, src: PixelData, opts: PixelBlendOptions): void;
1351
+ declare function blendPixelDataBinaryMask(dst: IPixelData, src: IPixelData, binaryMask: BinaryMask, opts: PixelBlendMaskOptions): void;
1181
1352
 
1182
1353
  /**
1183
1354
  * Clears a region of the PixelData to transparent (0x00000000).
1184
1355
  * Internally uses the optimized fillPixelData.
1185
1356
  */
1186
- declare function clearPixelData(dst: PixelData, rect?: Partial<Rect>): void;
1357
+ declare function clearPixelData(dst: IPixelData, rect?: Partial<Rect>): void;
1187
1358
 
1188
1359
  /**
1189
1360
  * High-level extraction that returns a new PixelData instance.
1190
1361
  * Leverages extractPixelDataBuffer for optimized 32-bit memory moves.
1191
1362
  */
1192
- declare function extractPixelData(source: PixelData, rect: Rect): PixelData;
1193
- declare function extractPixelData(source: PixelData, x: number, y: number, w: number, h: number): PixelData;
1363
+ declare function extractPixelData(source: IPixelData, rect: Rect): PixelData;
1364
+ declare function extractPixelData(source: IPixelData, x: number, y: number, w: number, h: number): PixelData;
1194
1365
 
1195
1366
  /**
1196
1367
  * Extracts a rectangular region of pixels from PixelData.
1197
1368
  * Returns a new Uint32Array containing the extracted pixels.
1198
1369
  */
1199
- declare function extractPixelDataBuffer(source: PixelData, rect: Rect): Uint32Array;
1200
- declare function extractPixelDataBuffer(source: PixelData, x: number, y: number, w: number, h: number): Uint32Array;
1370
+ declare function extractPixelDataBuffer(source: IPixelData, rect: Rect): Uint32Array;
1371
+ declare function extractPixelDataBuffer(source: IPixelData, x: number, y: number, w: number, h: number): Uint32Array;
1201
1372
 
1202
- /**
1203
- * Fills a region or the {@link PixelData} buffer with a solid color.
1204
- *
1205
- * @param dst - The target {@link PixelData} to modify.
1206
- * @param color - The {@link Color32} value to apply.
1207
- * @param rect - A {@link Rect} defining the area to fill. If omitted, the entire
1208
- * buffer is filled.
1209
- */
1210
- declare function fillPixelData(dst: PixelData, color: Color32, rect?: Partial<Rect>): void;
1211
- /**
1212
- * @param dst - The target {@link PixelData} to modify.
1213
- * @param color - The {@link Color32} value to apply.
1214
- * @param x - Starting horizontal coordinate.
1215
- * @param y - Starting vertical coordinate.
1216
- * @param w - Width of the fill area.
1217
- * @param h - Height of the fill area.
1218
- */
1219
- declare function fillPixelData(dst: PixelData, color: Color32, x: number, y: number, w: number, h: number): void;
1220
-
1221
- declare function invertPixelData(pixelData: PixelData, opts?: PixelMutateOptions): void;
1373
+ declare class PixelBuffer32 implements IPixelData {
1374
+ readonly width: number;
1375
+ readonly height: number;
1376
+ readonly data32: Uint32Array;
1377
+ constructor(width: number, height: number, data32?: Uint32Array);
1378
+ set(width: number, height: number, data32?: Uint32Array): void;
1379
+ copy(): PixelBuffer32;
1380
+ }
1222
1381
 
1223
1382
  /**
1224
1383
  * Extracts the alpha channel from PixelData into a single-channel mask.
1225
1384
  * Returns a Uint8Array branded as AlphaMask.
1226
1385
  */
1227
- declare function pixelDataToAlphaMask(pixelData: PixelData): AlphaMask;
1228
-
1229
- declare function reflectPixelDataHorizontal(pixelData: PixelData): void;
1230
- declare function reflectPixelDataVertical(pixelData: PixelData): void;
1386
+ declare function pixelDataToAlphaMask(pixelData: IPixelData): AlphaMask;
1231
1387
 
1232
- /**
1233
- * Resamples an PixelData by a specific factor using nearest neighbor
1234
- * Factor > 1 upscales, Factor < 1 downscales.
1235
- */
1388
+ declare function reflectPixelDataHorizontal(pixelData: IPixelData): void;
1389
+ declare function reflectPixelDataVertical(pixelData: IPixelData): void;
1236
1390
 
1237
1391
  /**
1238
1392
  * Resamples PixelData by a specific factor using nearest neighbor.
1239
1393
  * Factor > 1 upscales, Factor < 1 downscales.
1240
1394
  */
1241
- declare function resamplePixelData(pixelData: PixelData, factor: number): PixelData;
1395
+ declare function resamplePixelData(pixelData: IPixelData, factor: number): PixelData;
1242
1396
 
1243
1397
  /**
1244
1398
  * Rotates pixel data 90 degrees clockwise.
@@ -1253,8 +1407,8 @@ declare function rotatePixelData(pixelData: PixelData): void;
1253
1407
  * This function performs a direct memory copy from a {@link Uint32Array}
1254
1408
  * into the target {@link PixelData} buffer.
1255
1409
  */
1256
- declare function writePixelDataBuffer(target: PixelData, data: Uint32Array, rect: Rect): void;
1257
- declare function writePixelDataBuffer(target: PixelData, data: Uint32Array, x: number, y: number, w: number, h: number): void;
1410
+ declare function writePixelDataBuffer(target: IPixelData, data: Uint32Array, rect: Rect): void;
1411
+ declare function writePixelDataBuffer(target: IPixelData, data: Uint32Array, x: number, y: number, w: number, h: number): void;
1258
1412
 
1259
1413
  /**
1260
1414
  * Intersects a target rectangle with a boundary, trimming dimensions and masks in-place.
@@ -1272,4 +1426,4 @@ declare function writePixelDataBuffer(target: PixelData, data: Uint32Array, x: n
1272
1426
  */
1273
1427
  declare function trimRectBounds<T extends Rect | SelectionRect>(target: T, bounds: Rect): void;
1274
1428
 
1275
- export { type AlphaMask, type AnyMask, type ApplyMaskOptions, BASE_FAST_BLEND_MODE_FUNCTIONS, BASE_PERFECT_BLEND_MODE_FUNCTIONS, type Base64EncodedUInt8Array, BaseBlendMode, type BaseBlendModes, type BinaryMask, type BlendColor32, type BlendModeRegistry, type Color32, type ColorBlendOptions, type FloodFillImageDataOptions, type FloodFillResult, type HistoryAction, HistoryManager, type ImageDataLike, IndexedImage, MaskType, PixelAccumulator, type PixelBlendOptions, type PixelCanvas, PixelData, PixelEngineConfig, type PixelMaskInvertOptions, type PixelMaskRectOptions, type PixelMutateOptions, type PixelOptions, type PixelPatchTiles, type PixelRectOptions, PixelTile, PixelWriter, type PixelWriterOptions, type Point, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableImageData, type SelectionRect, type SerializedImageData, UnsupportedFormatError, applyCircleBrushToPixelData, applyMaskToPixelData, applyPatchTiles, applyRectBrushToPixelData, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendPixelData, clearPixelData, 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, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, floodFillSelection, getCircleBrushBounds, getImageDataFromClipboard, getIndexedImageColorCounts, getRectBrushBounds, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMask, imageDataToDataUrl, imageDataToImgBlob, imageDataToUInt32Array, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makeBlendModeRegistry, makeFastBlendModeRegistry, makeFullPixelMutator, makePerfectBlendModeRegistry, makePixelCanvas, makeReusableCanvas, makeReusableImageData, mergeMasks, multiplyFast, multiplyPerfect, mutatorApplyMask, mutatorBlendColor, mutatorBlendPixel, mutatorBlendPixelData, mutatorFill, mutatorInvert, overlayFast, overlayPerfect, overwriteBase, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resizeImageData, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, softLightFast, softLightPerfect, sourceOverFast, sourceOverPerfect, subtractFast, subtractPerfect, trimRectBounds, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataBuffer, writeImageDataToClipboard, writeImgBlobToClipboard, writePixelDataBuffer };
1429
+ export { type Alpha, type AlphaMask, type AnyMask, type ApplyMaskToPixelDataOptions, BASE_FAST_BLEND_MODE_FUNCTIONS, BASE_PERFECT_BLEND_MODE_FUNCTIONS, type Base64EncodedUInt8Array, BaseBlendMode, type BaseBlendModes, type BasePixelBlendOptions, type BinaryMask, type BlendColor32, type BlendModeRegistry, CANVAS_CTX_FAILED, type Color32, type ColorBlendMaskOptions, type ColorBlendOptions, type FloodFillImageDataOptions, type FloodFillResult, type HistoryAction, HistoryManager, type HistoryMutator, type IPixelData, type ImageDataLike, type ImageDataLikeConstructor, IndexedImage, type InvertMask, type MaskOffset, type MaskOffsetWidth, MaskType, type MergeAlphaMasksOptions, OFFSCREEN_CANVAS_CTX_FAILED, PixelAccumulator, type PixelBlendMaskOptions, type PixelBlendOptions, PixelBuffer32, type PixelCanvas, PixelData, PixelEngineConfig, type PixelMutateOptions, type PixelPatchTiles, type PixelRect, PixelTile, PixelWriter, type PixelWriterOptions, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableImageData, type SelectionRect, type SerializedImageData, UnsupportedFormatError, applyAlphaMaskToPixelData, applyBinaryMaskToAlphaMask, applyBinaryMaskToPixelData, applyCircleBrushToPixelData, applyPatchTiles, applyRectBrushToPixelData, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendColorPixelDataAlphaMask, blendColorPixelDataBinaryMask, blendPixelData, blendPixelDataAlphaMask, blendPixelDataBinaryMask, clearPixelData, 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, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, floodFillSelection, forEachLinePoint, getCircleBrushOrPencilBounds, getCircleBrushOrPencilStrokeBounds, getImageDataFromClipboard, getIndexedImageColorCounts, getRectBrushOrPencilBounds, getRectBrushOrPencilStrokeBounds, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMask, imageDataToDataUrl, imageDataToImgBlob, imageDataToUInt32Array, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makeBlendModeRegistry, makeFastBlendModeRegistry, makeFullPixelMutator, makeImageDataLike, makePerfectBlendModeRegistry, makePixelCanvas, makeReusableCanvas, makeReusableImageData, mergeAlphaMasks, mergeBinaryMasks, multiplyFast, multiplyPerfect, mutatorApplyAlphaMask, mutatorApplyBinaryMask, mutatorApplyCircleBrush, mutatorApplyCircleBrushStroke, mutatorApplyCirclePencil, mutatorApplyCirclePencilStroke, mutatorApplyRectBrush, mutatorApplyRectBrushStroke, mutatorApplyRectPencil, mutatorApplyRectPencilStroke, mutatorBlendColor, mutatorBlendPixel, mutatorBlendPixelData, mutatorClear, mutatorFill, mutatorInvert, overlayFast, overlayPerfect, overwriteBase, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resizeImageData, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, softLightFast, softLightPerfect, sourceOverFast, sourceOverPerfect, subtractFast, subtractPerfect, toBlendModeIndexAndName, trimRectBounds, uInt32ArrayToImageData, uInt32ArrayToImageDataLike, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataBuffer, writeImageDataToClipboard, writeImgBlobToClipboard, writePixelDataBuffer };