pixel-data-js 0.27.0 → 0.29.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 (148) hide show
  1. package/README.md +12 -2
  2. package/dist/index.prod.cjs +2355 -1124
  3. package/dist/index.prod.cjs.map +1 -1
  4. package/dist/index.prod.d.ts +558 -424
  5. package/dist/index.prod.js +2304 -1115
  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/_constants.ts +3 -0
  59. package/src/Internal/_errors.ts +2 -0
  60. package/src/Internal/macros.ts +14 -0
  61. package/src/Mask/AlphaMask.ts +1 -1
  62. package/src/Mask/BinaryMask/makeBinaryMaskFromAlphaMask.ts +23 -0
  63. package/src/Mask/BinaryMask/makeBinaryMaskOutline.ts +88 -0
  64. package/src/Mask/BinaryMask/makeCircleBinaryMaskOutline.ts +104 -0
  65. package/src/Mask/BinaryMask/makeRectBinaryMaskOutline.ts +34 -0
  66. package/src/Mask/BinaryMask.ts +1 -1
  67. package/src/Mask/_mask-types.ts +73 -0
  68. package/src/Mask/applyBinaryMaskToAlphaMask.ts +2 -1
  69. package/src/Mask/copyMask.ts +1 -1
  70. package/src/Mask/extractMask.ts +2 -1
  71. package/src/Mask/extractMaskBuffer.ts +1 -1
  72. package/src/Mask/mergeAlphaMasks.ts +6 -3
  73. package/src/Mask/mergeBinaryMasks.ts +2 -1
  74. package/src/Mask/setMaskData.ts +1 -1
  75. package/src/MaskRect/merge2BinaryMaskRects.ts +2 -2
  76. package/src/MaskRect/mergeBinaryMaskRects.ts +1 -1
  77. package/src/MaskRect/subtractBinaryMaskRects.ts +1 -1
  78. package/src/Paint/AlphaMaskPaintBuffer.ts +283 -0
  79. package/src/Paint/BinaryMaskPaintBuffer.ts +198 -0
  80. package/src/Paint/{PaintBuffer.ts → ColorPaintBuffer.ts} +95 -77
  81. package/src/Paint/Commit/AlphaMaskPaintBufferCommitter.ts +26 -0
  82. package/src/Paint/Commit/AlphaMaskPaintBufferManager.ts +34 -0
  83. package/src/Paint/Commit/BinaryMaskPaintBufferCommitter.ts +26 -0
  84. package/src/Paint/Commit/BinaryMaskPaintBufferManager.ts +31 -0
  85. package/src/Paint/Commit/ColorPaintBufferCommitter.ts +23 -0
  86. package/src/Paint/Commit/ColorPaintBufferManager.ts +34 -0
  87. package/src/Paint/Commit/commitColorPaintBuffer.ts +55 -0
  88. package/src/Paint/Commit/commitMaskPaintBuffer.ts +78 -0
  89. package/src/Paint/Render/AlphaMaskPaintBufferCanvasRenderer.ts +78 -0
  90. package/src/Paint/Render/BinaryMaskPaintBufferCanvasRenderer.ts +67 -0
  91. package/src/Paint/{PaintBufferCanvasRenderer.ts → Render/ColorPaintBufferCanvasRenderer.ts} +13 -14
  92. package/src/Paint/Render/PaintCursorRenderer.ts +118 -0
  93. package/src/Paint/_paint-types.ts +22 -0
  94. package/src/Paint/eachTileInBounds.ts +45 -0
  95. package/src/Paint/makeCirclePaintMask.ts +74 -0
  96. package/src/Paint/makePaintMask.ts +5 -2
  97. package/src/Paint/makeRectFalloffPaintAlphaMask.ts +4 -2
  98. package/src/PixelData/PixelData.ts +15 -19
  99. package/src/PixelData/ReusablePixelData.ts +36 -0
  100. package/src/PixelData/_pixelData-types.ts +17 -0
  101. package/src/PixelData/applyAlphaMaskToPixelData.ts +80 -43
  102. package/src/PixelData/applyBinaryMaskToPixelData.ts +10 -8
  103. package/src/PixelData/applyMaskToPixelData.ts +4 -9
  104. package/src/PixelData/blendColorPixelData.ts +9 -8
  105. package/src/PixelData/blendColorPixelDataAlphaMask.ts +9 -7
  106. package/src/PixelData/blendColorPixelDataBinaryMask.ts +9 -7
  107. package/src/PixelData/blendColorPixelDataMask.ts +4 -2
  108. package/src/PixelData/blendColorPixelDataPaintAlphaMask.ts +4 -2
  109. package/src/PixelData/blendColorPixelDataPaintBinaryMask.ts +4 -2
  110. package/src/PixelData/blendColorPixelDataPaintMask.ts +5 -2
  111. package/src/PixelData/blendPixel.ts +6 -5
  112. package/src/PixelData/blendPixelData.ts +14 -13
  113. package/src/PixelData/blendPixelDataAlphaMask.ts +15 -13
  114. package/src/PixelData/blendPixelDataBinaryMask.ts +15 -13
  115. package/src/PixelData/blendPixelDataMask.ts +5 -3
  116. package/src/PixelData/blendPixelDataPaintBuffer.ts +5 -4
  117. package/src/PixelData/clearPixelDataFast.ts +4 -2
  118. package/src/PixelData/copyPixelData.ts +14 -0
  119. package/src/PixelData/extractPixelData.ts +8 -7
  120. package/src/PixelData/extractPixelDataBuffer.ts +9 -8
  121. package/src/PixelData/fillPixelData.ts +16 -14
  122. package/src/PixelData/fillPixelDataBinaryMask.ts +10 -8
  123. package/src/PixelData/fillPixelDataFast.ts +16 -14
  124. package/src/PixelData/invertPixelData.ts +9 -8
  125. package/src/PixelData/pixelDataToAlphaMask.ts +9 -8
  126. package/src/PixelData/reflectPixelData.ts +9 -9
  127. package/src/PixelData/resamplePixelData.ts +20 -9
  128. package/src/PixelData/rotatePixelData.ts +8 -7
  129. package/src/PixelData/uInt32ArrayToPixelData.ts +15 -0
  130. package/src/PixelData/writePaintBufferToPixelData.ts +5 -5
  131. package/src/PixelData/writePixelDataBuffer.ts +10 -9
  132. package/src/Rect/_rect-types.ts +7 -0
  133. package/src/Rect/getRectsBounds.ts +1 -1
  134. package/src/Rect/trimMaskRectBounds.ts +2 -1
  135. package/src/Rect/trimRectBounds.ts +1 -1
  136. package/src/Tile/MaskTile.ts +40 -0
  137. package/src/Tile/PixelTile.ts +23 -0
  138. package/src/{PixelTile/PixelTilePool.ts → Tile/TilePool.ts} +9 -9
  139. package/src/Tile/_tile-types.ts +33 -0
  140. package/src/_errors.ts +1 -0
  141. package/src/_types.ts +2 -118
  142. package/src/index.ts +57 -21
  143. package/src/ImageData/imageDataToUInt32Array.ts +0 -13
  144. package/src/Internal/helpers.ts +0 -5
  145. package/src/Paint/makeCirclePaintAlphaMask.ts +0 -41
  146. package/src/Paint/makeCirclePaintBinaryMask.ts +0 -29
  147. package/src/PixelTile/PixelTile.ts +0 -21
  148. /package/src/{Internal → Rect}/resolveClipping.ts +0 -0
@@ -1,4 +1,6 @@
1
- import { type ApplyMaskToPixelDataOptions, type BinaryMask, type IPixelData32 } from '../_types'
1
+ import { type ApplyMaskToPixelDataOptions } from '../_types'
2
+ import type { BinaryMask } from '../Mask/_mask-types'
3
+ import type { PixelData32 } from './_pixelData-types'
2
4
 
3
5
  /**
4
6
  * Directly applies a mask to a region of PixelData,
@@ -6,14 +8,14 @@ import { type ApplyMaskToPixelDataOptions, type BinaryMask, type IPixelData32 }
6
8
  * @returns true if any pixels were actually modified.
7
9
  */
8
10
  export function applyBinaryMaskToPixelData(
9
- target: IPixelData32,
11
+ target: PixelData32,
10
12
  mask: BinaryMask,
11
13
  opts?: ApplyMaskToPixelDataOptions,
12
14
  ): boolean {
13
15
  const targetX = opts?.x ?? 0
14
16
  const targetY = opts?.y ?? 0
15
- const width = opts?.w ?? target.width
16
- const height = opts?.h ?? target.height
17
+ const width = opts?.w ?? target.w
18
+ const height = opts?.h ?? target.h
17
19
  const globalAlpha = opts?.alpha ?? 255
18
20
  const mx = opts?.mx ?? 0
19
21
  const my = opts?.my ?? 0
@@ -36,8 +38,8 @@ export function applyBinaryMaskToPixelData(
36
38
  y = 0
37
39
  }
38
40
 
39
- w = Math.min(w, target.width - x)
40
- h = Math.min(h, target.height - y)
41
+ w = Math.min(w, target.w - x)
42
+ h = Math.min(h, target.h - y)
41
43
 
42
44
  if (w <= 0 || h <= 0) return false
43
45
 
@@ -67,8 +69,8 @@ export function applyBinaryMaskToPixelData(
67
69
  const xShift = sX0 - startX
68
70
  const yShift = sY0 - startY
69
71
 
70
- const dst32 = target.data32
71
- const dw = target.width
72
+ const dst32 = target.data
73
+ const dw = target.w
72
74
  const dStride = dw - finalW
73
75
  const mStride = mPitch - finalW
74
76
  const maskData = mask.data
@@ -1,16 +1,11 @@
1
- import {
2
- type AlphaMask,
3
- type ApplyMaskToPixelDataOptions,
4
- type BinaryMask,
5
- type IPixelData32,
6
- type Mask,
7
- MaskType,
8
- } from '../_types'
1
+ import { type ApplyMaskToPixelDataOptions } from '../_types'
2
+ import { type AlphaMask, type BinaryMask, type Mask, MaskType } from '../Mask/_mask-types'
3
+ import type { PixelData32 } from './_pixelData-types'
9
4
  import { applyAlphaMaskToPixelData } from './applyAlphaMaskToPixelData'
10
5
  import { applyBinaryMaskToPixelData } from './applyBinaryMaskToPixelData'
11
6
 
12
7
  export function applyMaskToPixelData(
13
- dst: IPixelData32,
8
+ dst: PixelData32,
14
9
  mask: Mask,
15
10
  opts?: ApplyMaskToPixelDataOptions,
16
11
  ): boolean {
@@ -1,19 +1,20 @@
1
- import { type Color32, type ColorBlendOptions, type IPixelData32 } from '../_types'
1
+ import { type Color32, type ColorBlendOptions } from '../_types'
2
2
  import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
3
+ import type { PixelData32 } from './_pixelData-types'
3
4
 
4
5
  /**
5
6
  * Blends a solid color into a target pixel buffer.
6
7
  * @returns true if any pixels were actually modified.
7
8
  */
8
9
  export function blendColorPixelData(
9
- target: IPixelData32,
10
+ target: PixelData32,
10
11
  color: Color32,
11
12
  opts?: ColorBlendOptions,
12
13
  ): boolean {
13
14
  const targetX = opts?.x ?? 0
14
15
  const targetY = opts?.y ?? 0
15
- const width = opts?.w ?? target.width
16
- const height = opts?.h ?? target.height
16
+ const width = opts?.w ?? target.w
17
+ const height = opts?.h ?? target.h
17
18
  const globalAlpha = opts?.alpha ?? 255
18
19
  const blendFn = opts?.blendFn ?? sourceOverPerfect
19
20
  if (globalAlpha === 0) return false
@@ -39,8 +40,8 @@ export function blendColorPixelData(
39
40
  y = 0
40
41
  }
41
42
 
42
- const actualW = Math.min(w, target.width - x)
43
- const actualH = Math.min(h, target.height - y)
43
+ const actualW = Math.min(w, target.w - x)
44
+ const actualH = Math.min(h, target.h - y)
44
45
 
45
46
  if (actualW <= 0 || actualH <= 0) return false
46
47
 
@@ -53,8 +54,8 @@ export function blendColorPixelData(
53
54
  finalSrcColor = ((color & 0x00ffffff) | (a << 24)) >>> 0 as Color32
54
55
  }
55
56
 
56
- const dst32 = target.data32
57
- const dw = target.width
57
+ const dst32 = target.data
58
+ const dw = target.w
58
59
  let dIdx = (y * dw + x) | 0
59
60
  const dStride = (dw - actualW) | 0
60
61
  let didChange = false
@@ -1,5 +1,7 @@
1
- import type { AlphaMask, Color32, ColorBlendMaskOptions, IPixelData32 } from '../_types'
1
+ import type { Color32, ColorBlendMaskOptions } from '../_types'
2
2
  import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
3
+ import type { AlphaMask } from '../Mask/_mask-types'
4
+ import type { PixelData32 } from './_pixelData-types'
3
5
 
4
6
  /**
5
7
  * Blends a solid color into a target pixel buffer using an alpha mask.
@@ -8,14 +10,14 @@ import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
8
10
  * If the width (`w`) or height (`h`) are omitted from the options, they will safely
9
11
  * default to the dimensions of the provided mask to prevent out-of-bounds memory access.
10
12
  *
11
- * @param target - The destination {@link IPixelData32} buffer to modify.
13
+ * @param target - The destination {@link PixelData32} buffer to modify.
12
14
  * @param color - The solid color to apply.
13
15
  * @param mask - The mask defining the per-pixel opacity of the target area.
14
16
  * @param opts - Configuration options including placement coordinates, bounds, global alpha, and mask offsets.
15
17
  * @returns true if any pixels were actually modified.
16
18
  */
17
19
  export function blendColorPixelDataAlphaMask(
18
- target: IPixelData32,
20
+ target: PixelData32,
19
21
  color: Color32,
20
22
  mask: AlphaMask,
21
23
  opts?: ColorBlendMaskOptions,
@@ -52,16 +54,16 @@ export function blendColorPixelDataAlphaMask(
52
54
  y = 0
53
55
  }
54
56
 
55
- actualW = Math.min(actualW, target.width - x)
56
- actualH = Math.min(actualH, target.height - y)
57
+ actualW = Math.min(actualW, target.w - x)
58
+ actualH = Math.min(actualH, target.h - y)
57
59
 
58
60
  if (actualW <= 0 || actualH <= 0) return false
59
61
 
60
62
  const dx = (x - targetX) | 0
61
63
  const dy = (y - targetY) | 0
62
64
 
63
- const dst32 = target.data32
64
- const dw = target.width
65
+ const dst32 = target.data
66
+ const dw = target.w
65
67
  const mPitch = mask.w
66
68
  const maskData = mask.data
67
69
 
@@ -1,5 +1,7 @@
1
- import type { BinaryMask, Color32, ColorBlendMaskOptions, IPixelData32 } from '../_types'
1
+ import type { Color32, ColorBlendMaskOptions } from '../_types'
2
2
  import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
3
+ import type { BinaryMask } from '../Mask/_mask-types'
4
+ import type { PixelData32 } from './_pixelData-types'
3
5
 
4
6
  /**
5
7
  * Blends a solid color into a target pixel buffer using a binary mask.
@@ -8,14 +10,14 @@ import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
8
10
  * If the width (`w`) or height (`h`) are omitted from the options, they will safely
9
11
  * default to the dimensions of the provided mask to prevent out-of-bounds memory access.
10
12
  *
11
- * @param target - The destination {@link IPixelData32} buffer to modify.
13
+ * @param target - The destination {@link PixelData32} buffer to modify.
12
14
  * @param color - The solid color to apply.
13
15
  * @param mask - The mask defining the per-pixel opacity of the target area.
14
16
  * @param opts - Configuration options including placement coordinates, bounds, global alpha, and mask offsets.
15
17
  * @returns true if any pixels were actually modified.
16
18
  */
17
19
  export function blendColorPixelDataBinaryMask(
18
- target: IPixelData32,
20
+ target: PixelData32,
19
21
  color: Color32,
20
22
  mask: BinaryMask,
21
23
  opts?: ColorBlendMaskOptions,
@@ -50,8 +52,8 @@ export function blendColorPixelDataBinaryMask(
50
52
  y = 0
51
53
  }
52
54
 
53
- const actualW = Math.min(w, target.width - x)
54
- const actualH = Math.min(h, target.height - y)
55
+ const actualW = Math.min(w, target.w - x)
56
+ const actualH = Math.min(h, target.h - y)
55
57
 
56
58
  if (actualW <= 0 || actualH <= 0) return false
57
59
 
@@ -65,8 +67,8 @@ export function blendColorPixelDataBinaryMask(
65
67
 
66
68
  const dx = (x - targetX) | 0
67
69
  const dy = (y - targetY) | 0
68
- const dst32 = target.data32
69
- const dw = target.width
70
+ const dst32 = target.data
71
+ const dw = target.w
70
72
  const mPitch = mask.w
71
73
  const maskData = mask.data
72
74
  let dIdx = (y * dw + x) | 0
@@ -1,9 +1,11 @@
1
- import { type Color32, type ColorBlendMaskOptions, type IPixelData32, type Mask, MaskType } from '../_types'
1
+ import { type Color32, type ColorBlendMaskOptions } from '../_types'
2
+ import { type Mask, MaskType } from '../Mask/_mask-types'
3
+ import type { PixelData32 } from './_pixelData-types'
2
4
  import { blendColorPixelDataAlphaMask } from './blendColorPixelDataAlphaMask'
3
5
  import { blendColorPixelDataBinaryMask } from './blendColorPixelDataBinaryMask'
4
6
 
5
7
  export function blendColorPixelDataMask(
6
- dst: IPixelData32,
8
+ dst: PixelData32,
7
9
  color: Color32,
8
10
  mask: Mask,
9
11
  opts?: ColorBlendMaskOptions,
@@ -1,5 +1,7 @@
1
- import { type Color32, type IPixelData32, type PaintAlphaMask } from '../_types'
1
+ import { type Color32 } from '../_types'
2
2
  import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
3
+ import type { PaintAlphaMask } from '../Paint/_paint-types'
4
+ import type { PixelData32 } from './_pixelData-types'
3
5
  import { blendColorPixelDataAlphaMask } from './blendColorPixelDataAlphaMask'
4
6
 
5
7
  const SCRATCH_OPTS = {
@@ -10,7 +12,7 @@ const SCRATCH_OPTS = {
10
12
  }
11
13
 
12
14
  export function blendColorPixelDataPaintAlphaMask(
13
- dst: IPixelData32,
15
+ dst: PixelData32,
14
16
  color: Color32,
15
17
  mask: PaintAlphaMask,
16
18
  x: number,
@@ -1,5 +1,7 @@
1
- import { type Color32, type IPixelData32, type PaintBinaryMask } from '../_types'
1
+ import { type Color32 } from '../_types'
2
2
  import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
3
+ import type { PaintBinaryMask } from '../Paint/_paint-types'
4
+ import type { PixelData32 } from './_pixelData-types'
3
5
  import { blendColorPixelDataBinaryMask } from './blendColorPixelDataBinaryMask'
4
6
 
5
7
  const SCRATCH_OPTS = {
@@ -10,7 +12,7 @@ const SCRATCH_OPTS = {
10
12
  }
11
13
 
12
14
  export function blendColorPixelDataPaintBinaryMask(
13
- dst: IPixelData32,
15
+ dst: PixelData32,
14
16
  color: Color32,
15
17
  mask: PaintBinaryMask,
16
18
  x: number,
@@ -1,5 +1,8 @@
1
- import { type Color32, type IPixelData32, MaskType, type PaintMask } from '../_types'
1
+ import { type Color32 } from '../_types'
2
2
  import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
3
+ import { MaskType } from '../Mask/_mask-types'
4
+ import type { PaintMask } from '../Paint/_paint-types'
5
+ import type { PixelData32 } from './_pixelData-types'
3
6
  import { blendColorPixelDataAlphaMask } from './blendColorPixelDataAlphaMask'
4
7
  import { blendColorPixelDataBinaryMask } from './blendColorPixelDataBinaryMask'
5
8
 
@@ -11,7 +14,7 @@ const SCRATCH_OPTS = {
11
14
  }
12
15
 
13
16
  export function blendColorPixelDataPaintMask(
14
- dst: IPixelData32,
17
+ dst: PixelData32,
15
18
  color: Color32,
16
19
  mask: PaintMask,
17
20
  x: number,
@@ -1,8 +1,9 @@
1
- import type { BlendColor32, Color32, IPixelData32 } from '../_types'
1
+ import type { BlendColor32, Color32 } from '../_types'
2
2
  import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
3
+ import type { PixelData32 } from './_pixelData-types'
3
4
 
4
5
  export function blendPixel(
5
- target: IPixelData32,
6
+ target: PixelData32,
6
7
  x: number,
7
8
  y: number,
8
9
  color: Color32,
@@ -11,8 +12,8 @@ export function blendPixel(
11
12
  ): boolean {
12
13
  if (alpha === 0) return false
13
14
 
14
- let width = target.width
15
- let height = target.height
15
+ let width = target.w
16
+ let height = target.h
16
17
 
17
18
  if (x < 0 || x >= width || y < 0 || y >= height) return false
18
19
 
@@ -22,7 +23,7 @@ export function blendPixel(
22
23
  // Early exit for transparent source unless we are in an overwrite mode
23
24
  if (srcAlpha === 0 && !isOverwrite) return false
24
25
 
25
- let dst32 = target.data32
26
+ let dst32 = target.data
26
27
  let index = y * width + x
27
28
  let finalColor = color
28
29
 
@@ -1,5 +1,6 @@
1
- import { type Color32, type IPixelData32, type PixelBlendOptions } from '../_types'
1
+ import { type Color32, type PixelBlendOptions } from '../_types'
2
2
  import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
3
+ import type { PixelData32 } from './_pixelData-types'
3
4
 
4
5
  /**
5
6
  * Blits source PixelData into a destination PixelData using 32-bit integer bitwise blending.
@@ -16,16 +17,16 @@ import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
16
17
  * });
17
18
  */
18
19
  export function blendPixelData(
19
- target: IPixelData32,
20
- src: IPixelData32,
20
+ target: PixelData32,
21
+ src: PixelData32,
21
22
  opts?: PixelBlendOptions,
22
23
  ): boolean {
23
24
  const targetX = opts?.x ?? 0
24
25
  const targetY = opts?.y ?? 0
25
26
  const sourceX = opts?.sx ?? 0
26
27
  const sourceY = opts?.sy ?? 0
27
- const width = opts?.w ?? src.width
28
- const height = opts?.h ?? src.height
28
+ const width = opts?.w ?? src.w
29
+ const height = opts?.h ?? src.h
29
30
  const globalAlpha = opts?.alpha ?? 255
30
31
  const blendFn = opts?.blendFn ?? sourceOverPerfect
31
32
 
@@ -48,8 +49,8 @@ export function blendPixelData(
48
49
  h += sy
49
50
  sy = 0
50
51
  }
51
- w = Math.min(w, src.width - sx)
52
- h = Math.min(h, src.height - sy)
52
+ w = Math.min(w, src.w - sx)
53
+ h = Math.min(h, src.h - sy)
53
54
  if (x < 0) {
54
55
  sx -= x
55
56
  w += x
@@ -61,14 +62,14 @@ export function blendPixelData(
61
62
  y = 0
62
63
  }
63
64
 
64
- const actualW = Math.min(w, target.width - x)
65
- const actualH = Math.min(h, target.height - y)
65
+ const actualW = Math.min(w, target.w - x)
66
+ const actualH = Math.min(h, target.h - y)
66
67
  if (actualW <= 0 || actualH <= 0) return false
67
68
 
68
- const dst32 = target.data32
69
- const src32 = src.data32
70
- const dw = target.width
71
- const sw = src.width
69
+ const dst32 = target.data
70
+ const src32 = src.data
71
+ const dw = target.w
72
+ const sw = src.w
72
73
 
73
74
  let dIdx = (y * dw + x) | 0
74
75
  let sIdx = (sy * sw + sx) | 0
@@ -1,9 +1,11 @@
1
- import { type AlphaMask, type Color32, type IPixelData32, type PixelBlendMaskOptions } from '../_types'
1
+ import { type Color32, type PixelBlendMaskOptions } from '../_types'
2
2
  import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
3
+ import type { AlphaMask } from '../Mask/_mask-types'
4
+ import type { PixelData32 } from './_pixelData-types'
3
5
 
4
6
  export function blendPixelDataAlphaMask(
5
- target: IPixelData32,
6
- src: IPixelData32,
7
+ target: PixelData32,
8
+ src: PixelData32,
7
9
  alphaMask: AlphaMask,
8
10
  opts?: PixelBlendMaskOptions,
9
11
  ): boolean {
@@ -11,8 +13,8 @@ export function blendPixelDataAlphaMask(
11
13
  const targetY = opts?.y ?? 0
12
14
  const sourceX = opts?.sx ?? 0
13
15
  const sourceY = opts?.sy ?? 0
14
- const width = opts?.w ?? src.width
15
- const height = opts?.h ?? src.height
16
+ const width = opts?.w ?? src.w
17
+ const height = opts?.h ?? src.h
16
18
  const globalAlpha = opts?.alpha ?? 255
17
19
  const blendFn = opts?.blendFn ?? sourceOverPerfect
18
20
  const mx = opts?.mx ?? 0
@@ -39,8 +41,8 @@ export function blendPixelDataAlphaMask(
39
41
  h += sy
40
42
  sy = 0
41
43
  }
42
- w = Math.min(w, src.width - sx)
43
- h = Math.min(h, src.height - sy)
44
+ w = Math.min(w, src.w - sx)
45
+ h = Math.min(h, src.h - sy)
44
46
  if (x < 0) {
45
47
  sx -= x
46
48
  w += x
@@ -52,13 +54,13 @@ export function blendPixelDataAlphaMask(
52
54
  y = 0
53
55
  }
54
56
 
55
- const actualW = Math.min(w, target.width - x)
56
- const actualH = Math.min(h, target.height - y)
57
+ const actualW = Math.min(w, target.w - x)
58
+ const actualH = Math.min(h, target.h - y)
57
59
  if (actualW <= 0 || actualH <= 0) return false
58
60
 
59
61
  // 2. Index Setup
60
- const dw = target.width
61
- const sw = src.width
62
+ const dw = target.w
63
+ const sw = src.w
62
64
  const mPitch = alphaMask.w
63
65
  const maskData = alphaMask.data
64
66
 
@@ -67,8 +69,8 @@ export function blendPixelDataAlphaMask(
67
69
  const dx = (x - targetX) | 0
68
70
  const dy = (y - targetY) | 0
69
71
 
70
- const dst32 = target.data32
71
- const src32 = src.data32
72
+ const dst32 = target.data
73
+ const src32 = src.data
72
74
 
73
75
  let dIdx = (y * dw + x) | 0
74
76
  let sIdx = (sy * sw + sx) | 0
@@ -1,9 +1,11 @@
1
- import type { BinaryMask, Color32, IPixelData32, PixelBlendMaskOptions } from '../_types'
1
+ import type { Color32, PixelBlendMaskOptions } from '../_types'
2
2
  import { sourceOverPerfect } from '../BlendModes/blend-modes-perfect'
3
+ import type { BinaryMask } from '../Mask/_mask-types'
4
+ import type { PixelData32 } from './_pixelData-types'
3
5
 
4
6
  export function blendPixelDataBinaryMask(
5
- target: IPixelData32,
6
- src: IPixelData32,
7
+ target: PixelData32,
8
+ src: PixelData32,
7
9
  binaryMask: BinaryMask,
8
10
  opts?: PixelBlendMaskOptions,
9
11
  ): boolean {
@@ -11,8 +13,8 @@ export function blendPixelDataBinaryMask(
11
13
  const targetY = opts?.y ?? 0
12
14
  const sourceX = opts?.sx ?? 0
13
15
  const sourceY = opts?.sy ?? 0
14
- const width = opts?.w ?? src.width
15
- const height = opts?.h ?? src.height
16
+ const width = opts?.w ?? src.w
17
+ const height = opts?.h ?? src.h
16
18
  const globalAlpha = opts?.alpha ?? 255
17
19
  const blendFn = opts?.blendFn ?? sourceOverPerfect
18
20
  const mx = opts?.mx ?? 0
@@ -39,8 +41,8 @@ export function blendPixelDataBinaryMask(
39
41
  h += sy
40
42
  sy = 0
41
43
  }
42
- w = Math.min(w, src.width - sx)
43
- h = Math.min(h, src.height - sy)
44
+ w = Math.min(w, src.w - sx)
45
+ h = Math.min(h, src.h - sy)
44
46
 
45
47
  // 2. Destination Clipping
46
48
  if (x < 0) {
@@ -54,8 +56,8 @@ export function blendPixelDataBinaryMask(
54
56
  y = 0
55
57
  }
56
58
 
57
- const actualW = Math.min(w, target.width - x)
58
- const actualH = Math.min(h, target.height - y)
59
+ const actualW = Math.min(w, target.w - x)
60
+ const actualH = Math.min(h, target.h - y)
59
61
 
60
62
  if (actualW <= 0 || actualH <= 0) return false
61
63
 
@@ -65,10 +67,10 @@ export function blendPixelDataBinaryMask(
65
67
  const dx = (x - targetX) | 0
66
68
  const dy = (y - targetY) | 0
67
69
 
68
- const dst32 = target.data32
69
- const src32 = src.data32
70
- const dw = target.width
71
- const sw = src.width
70
+ const dst32 = target.data
71
+ const src32 = src.data
72
+ const dw = target.w
73
+ const sw = src.w
72
74
  const mPitch = binaryMask.w
73
75
  const maskData = binaryMask.data
74
76
 
@@ -1,10 +1,12 @@
1
- import { type IPixelData32, type Mask, MaskType, type PixelBlendMaskOptions } from '../_types'
1
+ import { type PixelBlendMaskOptions } from '../_types'
2
+ import { type Mask, MaskType } from '../Mask/_mask-types'
3
+ import type { PixelData32 } from './_pixelData-types'
2
4
  import { blendPixelDataAlphaMask } from './blendPixelDataAlphaMask'
3
5
  import { blendPixelDataBinaryMask } from './blendPixelDataBinaryMask'
4
6
 
5
7
  export function blendPixelDataMask(
6
- target: IPixelData32,
7
- src: IPixelData32,
8
+ target: PixelData32,
9
+ src: PixelData32,
8
10
  mask: Mask,
9
11
  opts?: PixelBlendMaskOptions,
10
12
  ): boolean {
@@ -1,6 +1,7 @@
1
- import type { BlendColor32, IPixelData32 } from '../_types'
1
+ import type { BlendColor32 } from '../_types'
2
+ import type { ColorPaintBuffer } from '../Paint/ColorPaintBuffer'
3
+ import type { PixelData32 } from './_pixelData-types'
2
4
  import { blendPixelData } from './blendPixelData'
3
- import type { PaintBuffer } from '../Paint/PaintBuffer'
4
5
 
5
6
  const SCRATCH_OPTS = {
6
7
  x: 0,
@@ -10,8 +11,8 @@ const SCRATCH_OPTS = {
10
11
  }
11
12
 
12
13
  export function blendPixelDataPaintBuffer(
13
- target: IPixelData32,
14
- paintBuffer: PaintBuffer,
14
+ target: PixelData32,
15
+ paintBuffer: ColorPaintBuffer,
15
16
  alpha = 255,
16
17
  blendFn?: BlendColor32,
17
18
  blendPixelDataFn = blendPixelData,
@@ -1,4 +1,6 @@
1
- import type { BinaryMaskRect, Color32, IPixelData32 } from '../_types'
1
+ import type { Color32 } from '../_types'
2
+ import type { BinaryMaskRect } from '../Mask/_mask-types'
3
+ import type { PixelData32 } from './_pixelData-types'
2
4
  import { fillPixelDataFast } from './fillPixelDataFast'
3
5
 
4
6
  /**
@@ -6,7 +8,7 @@ import { fillPixelDataFast } from './fillPixelDataFast'
6
8
  * Internally uses the optimized fillPixelDataFast.
7
9
  */
8
10
  export function clearPixelDataFast(
9
- dst: IPixelData32,
11
+ dst: PixelData32,
10
12
  rect?: Partial<BinaryMaskRect>,
11
13
  ): void {
12
14
  fillPixelDataFast(dst, 0 as Color32, rect)
@@ -0,0 +1,14 @@
1
+ import type { ImageDataLike } from '../ImageData/_ImageData-types'
2
+ import type { PixelData } from './_pixelData-types'
3
+ import { makePixelData } from './PixelData'
4
+
5
+ export function copyPixelData<T extends ImageDataLike = ImageData>(target: PixelData<T>): PixelData {
6
+ const data = target.imageData.data
7
+ const buffer = new Uint8ClampedArray(data)
8
+
9
+ return makePixelData(new ImageData(
10
+ buffer,
11
+ target.w,
12
+ target.h,
13
+ ))
14
+ }
@@ -1,15 +1,16 @@
1
- import type { IPixelData32, Rect } from '../_types'
1
+ import type { Rect } from '../Rect/_rect-types'
2
+ import type { PixelData, PixelData32 } from './_pixelData-types'
2
3
  import { extractPixelDataBuffer } from './extractPixelDataBuffer'
3
- import { PixelData } from './PixelData'
4
+ import { makePixelData } from './PixelData'
4
5
 
5
6
  /**
6
7
  * High-level extraction that returns a new PixelData instance.
7
8
  * Leverages extractPixelDataBuffer for optimized 32-bit memory moves.
8
9
  */
9
- export function extractPixelData(source: IPixelData32, rect: Rect): PixelData
10
- export function extractPixelData(source: IPixelData32, x: number, y: number, w: number, h: number): PixelData
10
+ export function extractPixelData(source: PixelData32, rect: Rect): PixelData
11
+ export function extractPixelData(source: PixelData32, x: number, y: number, w: number, h: number): PixelData
11
12
  export function extractPixelData(
12
- source: IPixelData32,
13
+ source: PixelData32,
13
14
  _x: Rect | number,
14
15
  _y?: number,
15
16
  _w?: number,
@@ -19,10 +20,10 @@ export function extractPixelData(
19
20
  ? _x
20
21
  : { x: _x, y: _y!, w: _w!, h: _h! }
21
22
 
22
- const result = new PixelData(new ImageData(w, h))
23
+ const result = makePixelData(new ImageData(w, h))
23
24
 
24
25
  const buffer = extractPixelDataBuffer(source, x, y, w, h)
25
- result.data32.set(buffer)
26
+ result.data.set(buffer)
26
27
 
27
28
  return result
28
29
  }
@@ -1,5 +1,6 @@
1
- import type { IPixelData32, Rect } from '../_types'
2
- import { makeClippedBlit, resolveBlitClipping } from '../Internal/resolveClipping'
1
+ import type { Rect } from '../Rect/_rect-types'
2
+ import { makeClippedBlit, resolveBlitClipping } from '../Rect/resolveClipping'
3
+ import type { PixelData32 } from './_pixelData-types'
3
4
 
4
5
  const SCRATCH_BLIT = makeClippedBlit()
5
6
 
@@ -7,10 +8,10 @@ const SCRATCH_BLIT = makeClippedBlit()
7
8
  * Extracts a rectangular region of pixels from PixelData.
8
9
  * Returns a new Uint32Array containing the extracted pixels.
9
10
  */
10
- export function extractPixelDataBuffer(source: IPixelData32, rect: Rect): Uint32Array
11
- export function extractPixelDataBuffer(source: IPixelData32, x: number, y: number, w: number, h: number): Uint32Array
11
+ export function extractPixelDataBuffer(source: PixelData32, rect: Rect): Uint32Array
12
+ export function extractPixelDataBuffer(source: PixelData32, x: number, y: number, w: number, h: number): Uint32Array
12
13
  export function extractPixelDataBuffer(
13
- source: IPixelData32,
14
+ source: PixelData32,
14
15
  _x: Rect | number,
15
16
  _y?: number,
16
17
  _w?: number,
@@ -20,9 +21,9 @@ export function extractPixelDataBuffer(
20
21
  ? _x
21
22
  : { x: _x, y: _y!, w: _w!, h: _h! }
22
23
 
23
- const srcW = source.width
24
- const srcH = source.height
25
- const srcData = source.data32
24
+ const srcW = source.w
25
+ const srcH = source.h
26
+ const srcData = source.data
26
27
 
27
28
  // Safety check for empty or invalid dimensions
28
29
  if (w <= 0 || h <= 0) {