pixel-data-js 0.35.0 → 0.37.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.
- package/dist/index.prod.cjs +521 -326
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +132 -78
- package/dist/index.prod.js +513 -324
- package/dist/index.prod.js.map +1 -1
- package/package.json +2 -2
- package/src/Algorithm/floodFillSelection.ts +3 -2
- package/src/BlendModes/blend-modes-fast.ts +2 -1
- package/src/BlendModes/blend-modes-perfect.ts +2 -1
- package/src/Canvas/ReusableCanvas.ts +0 -5
- package/src/Color/_color-types.ts +8 -0
- package/src/Color/colorDistance.ts +9 -0
- package/src/Color/convert-color.ts +43 -0
- package/src/Color/lerpColor32.ts +44 -0
- package/src/Color/pack-color.ts +38 -0
- package/src/History/HistoryAction.ts +2 -2
- package/src/History/PixelAccumulator.ts +32 -13
- package/src/History/PixelMutator/mutatorApplyAlphaMask.ts +2 -0
- package/src/History/PixelMutator/mutatorApplyBinaryMask.ts +5 -1
- package/src/History/PixelMutator/mutatorApplyMask.ts +1 -0
- package/src/History/PixelMutator/mutatorBlendAlphaMask.ts +1 -0
- package/src/History/PixelMutator/mutatorBlendBinaryMask.ts +1 -0
- package/src/History/PixelMutator/mutatorBlendColor.ts +4 -1
- package/src/History/PixelMutator/mutatorBlendColorPaintAlphaMask.ts +2 -1
- package/src/History/PixelMutator/mutatorBlendColorPaintBinaryMask.ts +2 -1
- package/src/History/PixelMutator/mutatorBlendColorPaintMask.ts +24 -8
- package/src/History/PixelMutator/mutatorBlendColorPaintRect.ts +4 -1
- package/src/History/PixelMutator/mutatorBlendMask.ts +1 -0
- package/src/History/PixelMutator/mutatorBlendPixel.ts +3 -1
- package/src/History/PixelMutator/mutatorBlendPixelData.ts +1 -0
- package/src/History/PixelMutator/mutatorClear.ts +3 -2
- package/src/History/PixelMutator/mutatorFill.ts +54 -38
- package/src/History/PixelMutator/mutatorFillBinaryMask.ts +3 -2
- package/src/History/PixelMutator/mutatorInvert.ts +3 -2
- package/src/History/PixelMutator.ts +1 -2
- package/src/History/PixelWriter.ts +5 -5
- package/src/IndexedImage/IndexedImage.ts +1 -1
- package/src/IndexedImage/indexedImageToAverageColor.ts +3 -2
- package/src/Mask/_mask-types.ts +9 -0
- package/src/Paint/AlphaMaskPaintBuffer.ts +26 -26
- package/src/Paint/BinaryMaskPaintBuffer.ts +19 -19
- package/src/Paint/ColorPaintBuffer.ts +40 -42
- package/src/Paint/Commit/AlphaMaskPaintBufferCommitter.ts +1 -1
- package/src/Paint/Commit/AlphaMaskPaintBufferManager.ts +6 -7
- package/src/Paint/Commit/BinaryMaskPaintBufferCommitter.ts +1 -1
- package/src/Paint/Commit/BinaryMaskPaintBufferManager.ts +6 -7
- package/src/Paint/Commit/ColorPaintBufferManager.ts +6 -7
- package/src/Paint/Commit/commitColorPaintBuffer.ts +2 -6
- package/src/Paint/Commit/commitMaskPaintBuffer.ts +3 -7
- package/src/Paint/Render/AlphaMaskPaintBufferCanvasRenderer.ts +42 -25
- package/src/Paint/Render/BinaryMaskPaintBufferCanvasRenderer.ts +40 -24
- package/src/Paint/Render/ColorPaintBufferCanvasRenderer.ts +21 -21
- package/src/Paint/Render/PaintCursorRenderer.ts +12 -2
- package/src/Paint/eachTileInBounds.ts +9 -10
- package/src/PixelData/_pixelData-types.ts +7 -0
- package/src/PixelData/blendColorPixelData.ts +2 -1
- package/src/PixelData/blendColorPixelDataAlphaMask.ts +2 -1
- package/src/PixelData/blendColorPixelDataBinaryMask.ts +2 -1
- package/src/PixelData/blendColorPixelDataMask.ts +2 -1
- package/src/PixelData/blendColorPixelDataPaintAlphaMask.ts +1 -1
- package/src/PixelData/blendColorPixelDataPaintBinaryMask.ts +1 -1
- package/src/PixelData/blendColorPixelDataPaintMask.ts +19 -8
- package/src/PixelData/blendPixel.ts +2 -1
- package/src/PixelData/blendPixelData.ts +2 -1
- package/src/PixelData/blendPixelDataAlphaMask.ts +2 -1
- package/src/PixelData/blendPixelDataBinaryMask.ts +2 -1
- package/src/PixelData/blendPixelDataPaintBuffer.ts +2 -3
- package/src/PixelData/clearPixelDataFast.ts +1 -1
- package/src/PixelData/cropPixelData.ts +36 -0
- package/src/PixelData/fillPixelData.ts +7 -7
- package/src/PixelData/fillPixelDataBinaryMask.ts +1 -1
- package/src/PixelData/fillPixelDataFast.ts +1 -1
- package/src/PixelData/trimPixelData.ts +49 -0
- package/src/PixelData/writePaintBufferToPixelData.ts +1 -5
- package/src/Tile/MaskTile.ts +4 -0
- package/src/Tile/PixelTile.ts +2 -0
- package/src/Tile/TilePool.ts +9 -8
- package/src/Tile/TileTargetConfig.ts +27 -0
- package/src/Tile/_tile-types.ts +16 -0
- package/src/_types.ts +1 -6
- package/src/index.ts +9 -3
- package/src/History/PixelEngineConfig.ts +0 -28
- package/src/Internal/_constants.ts +0 -3
- package/src/color.ts +0 -112
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Color32 } from '../../
|
|
1
|
+
import type { Color32 } from '../../Color/_color-types'
|
|
2
2
|
import type { BinaryMask } from '../../Mask/_mask-types'
|
|
3
3
|
import { fillPixelDataBinaryMask } from '../../PixelData/fillPixelDataBinaryMask'
|
|
4
4
|
import { type HistoryMutator, PixelWriter } from '../PixelWriter'
|
|
@@ -20,8 +20,9 @@ export const mutatorFillBinaryMask = ((writer: PixelWriter<any>, deps: Deps = de
|
|
|
20
20
|
mask: BinaryMask,
|
|
21
21
|
x = 0,
|
|
22
22
|
y = 0,
|
|
23
|
-
) {
|
|
23
|
+
): boolean {
|
|
24
24
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, mask.w, mask.h)
|
|
25
|
+
if (!didChange) return false
|
|
25
26
|
return didChange(
|
|
26
27
|
fillPixelDataBinaryMask(writer.config.target, color, mask, x, y),
|
|
27
28
|
)
|
|
@@ -14,7 +14,7 @@ export const mutatorInvert = ((writer: PixelWriter<any>, deps: Deps = defaults)
|
|
|
14
14
|
} = deps
|
|
15
15
|
|
|
16
16
|
return {
|
|
17
|
-
invert(opts?: PixelMutateOptions) {
|
|
17
|
+
invert(opts?: PixelMutateOptions): boolean {
|
|
18
18
|
const target = writer.config.target
|
|
19
19
|
const x = opts?.x ?? 0
|
|
20
20
|
const y = opts?.y ?? 0
|
|
@@ -22,8 +22,9 @@ export const mutatorInvert = ((writer: PixelWriter<any>, deps: Deps = defaults)
|
|
|
22
22
|
const h = opts?.h ?? target.h
|
|
23
23
|
|
|
24
24
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h)
|
|
25
|
+
if (!didChange) return false
|
|
25
26
|
|
|
26
|
-
return didChange(
|
|
27
|
+
return didChange?.(
|
|
27
28
|
invertPixelData(target, opts),
|
|
28
29
|
)
|
|
29
30
|
},
|
|
@@ -12,7 +12,7 @@ import { mutatorBlendMask } from './PixelMutator/mutatorBlendMask'
|
|
|
12
12
|
import { mutatorBlendPixel } from './PixelMutator/mutatorBlendPixel'
|
|
13
13
|
import { mutatorBlendPixelData } from './PixelMutator/mutatorBlendPixelData'
|
|
14
14
|
import { mutatorClear } from './PixelMutator/mutatorClear'
|
|
15
|
-
import { mutatorFill
|
|
15
|
+
import { mutatorFill } from './PixelMutator/mutatorFill'
|
|
16
16
|
import { mutatorFillBinaryMask } from './PixelMutator/mutatorFillBinaryMask'
|
|
17
17
|
import { mutatorInvert } from './PixelMutator/mutatorInvert'
|
|
18
18
|
import type { PixelWriter } from './PixelWriter'
|
|
@@ -36,7 +36,6 @@ export function makeFullPixelMutator(writer: PixelWriter<any>) {
|
|
|
36
36
|
...mutatorClear(writer),
|
|
37
37
|
...mutatorFill(writer),
|
|
38
38
|
...mutatorFillBinaryMask(writer),
|
|
39
|
-
...mutatorFillRect(writer),
|
|
40
39
|
...mutatorInvert(writer),
|
|
41
40
|
}
|
|
42
41
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { resizeImageData } from '../ImageData/resizeImageData'
|
|
2
2
|
import type { PixelData } from '../PixelData/_pixelData-types'
|
|
3
3
|
import { setPixelData } from '../PixelData/PixelData'
|
|
4
|
-
import type { PixelTile } from '../Tile/_tile-types'
|
|
4
|
+
import type { PixelTile, TileTargetConfig } from '../Tile/_tile-types'
|
|
5
5
|
import { makePixelTile } from '../Tile/PixelTile'
|
|
6
6
|
import { TilePool } from '../Tile/TilePool'
|
|
7
|
+
import { makeTileTargetConfig } from '../Tile/TileTargetConfig'
|
|
7
8
|
import { type HistoryActionFactory, makeHistoryAction } from './HistoryAction'
|
|
8
9
|
import { HistoryManager } from './HistoryManager'
|
|
9
10
|
import { PixelAccumulator } from './PixelAccumulator'
|
|
10
|
-
import { PixelEngineConfig } from './PixelEngineConfig'
|
|
11
11
|
import type { PixelPatchTiles } from './PixelPatchTiles'
|
|
12
12
|
|
|
13
13
|
export interface PixelWriterOptions {
|
|
@@ -44,7 +44,7 @@ export class PixelWriter<M> {
|
|
|
44
44
|
readonly historyManager: HistoryManager
|
|
45
45
|
readonly accumulator: PixelAccumulator
|
|
46
46
|
readonly historyActionFactory: HistoryActionFactory
|
|
47
|
-
readonly config:
|
|
47
|
+
readonly config: TileTargetConfig
|
|
48
48
|
readonly pixelTilePool: TilePool<PixelTile>
|
|
49
49
|
readonly mutator: M
|
|
50
50
|
|
|
@@ -54,10 +54,10 @@ export class PixelWriter<M> {
|
|
|
54
54
|
const tileSize = options?.tileSize ?? 256
|
|
55
55
|
const maxHistorySteps = options?.maxHistorySteps ?? 50
|
|
56
56
|
|
|
57
|
-
this.config =
|
|
57
|
+
this.config = makeTileTargetConfig(tileSize, target)
|
|
58
58
|
this.historyManager = options?.historyManager ?? new HistoryManager(maxHistorySteps)
|
|
59
59
|
this.historyActionFactory = options?.historyActionFactory ?? makeHistoryAction
|
|
60
|
-
this.pixelTilePool = options?.pixelTilePool ?? new TilePool(this.config, makePixelTile)
|
|
60
|
+
this.pixelTilePool = options?.pixelTilePool ?? new TilePool(this.config.tileSize, makePixelTile)
|
|
61
61
|
this.accumulator = options?.accumulator ?? new PixelAccumulator(this.config, this.pixelTilePool)
|
|
62
62
|
this.mutator = mutatorFactory(this)
|
|
63
63
|
}
|
package/src/Mask/_mask-types.ts
CHANGED
|
@@ -64,6 +64,15 @@ export type NullableBinaryMaskRect = Rect & ({
|
|
|
64
64
|
type?: null
|
|
65
65
|
data?: null
|
|
66
66
|
})
|
|
67
|
+
|
|
68
|
+
export type NullableAlphaMaskRect = Rect & ({
|
|
69
|
+
type: MaskType.ALPHA
|
|
70
|
+
data: Uint8Array
|
|
71
|
+
} | {
|
|
72
|
+
type?: null
|
|
73
|
+
data?: null
|
|
74
|
+
})
|
|
75
|
+
|
|
67
76
|
export type NullableMaskRect = Rect & ({
|
|
68
77
|
type: MaskType
|
|
69
78
|
data: Uint8Array
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { forEachLinePoint } from '../Algorithm/forEachLinePoint'
|
|
2
|
-
import type { PixelEngineConfig } from '../History/PixelEngineConfig'
|
|
3
2
|
import type { Rect } from '../Rect/_rect-types'
|
|
4
3
|
import { trimRectBounds } from '../Rect/trimRectBounds'
|
|
5
|
-
import type { AlphaMaskTile } from '../Tile/_tile-types'
|
|
6
|
-
import
|
|
4
|
+
import type { AlphaMaskTile, TileTargetMeta } from '../Tile/_tile-types'
|
|
5
|
+
import { makeAlphaMaskTile } from '../Tile/MaskTile'
|
|
6
|
+
import { TilePool } from '../Tile/TilePool'
|
|
7
7
|
import type { PaintAlphaMask, PaintBinaryMask, PaintRect } from './_paint-types'
|
|
8
8
|
import { eachTileInBounds } from './eachTileInBounds'
|
|
9
9
|
|
|
@@ -16,8 +16,8 @@ export class AlphaMaskPaintBuffer {
|
|
|
16
16
|
private eachTileInBoundsFn = eachTileInBounds
|
|
17
17
|
|
|
18
18
|
constructor(
|
|
19
|
-
readonly config:
|
|
20
|
-
readonly tilePool: TilePool<AlphaMaskTile
|
|
19
|
+
readonly config: TileTargetMeta,
|
|
20
|
+
readonly tilePool: TilePool<AlphaMaskTile> = new TilePool(config.tileSize, makeAlphaMaskTile),
|
|
21
21
|
) {
|
|
22
22
|
this.lookup = []
|
|
23
23
|
}
|
|
@@ -46,9 +46,9 @@ export class AlphaMaskPaintBuffer {
|
|
|
46
46
|
const lookup = this.lookup
|
|
47
47
|
const tilePool = this.tilePool
|
|
48
48
|
const config = this.config
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
49
|
+
const targetW = config.targetWidth
|
|
50
|
+
const targetH = config.targetHeight
|
|
51
|
+
const tileSize = config.tileSize
|
|
52
52
|
|
|
53
53
|
const { w: bW, h: bH, data: bD, centerOffsetX, centerOffsetY } = brush
|
|
54
54
|
|
|
@@ -66,8 +66,8 @@ export class AlphaMaskPaintBuffer {
|
|
|
66
66
|
topLeftY,
|
|
67
67
|
bW,
|
|
68
68
|
bH,
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
targetW,
|
|
70
|
+
targetH,
|
|
71
71
|
scratch,
|
|
72
72
|
)
|
|
73
73
|
|
|
@@ -80,8 +80,8 @@ export class AlphaMaskPaintBuffer {
|
|
|
80
80
|
for (let i = 0; i < bH_t; i++) {
|
|
81
81
|
const canvasY = bY + i
|
|
82
82
|
const bOff = (canvasY - topLeftY) * bW
|
|
83
|
-
const tOff = (canvasY
|
|
84
|
-
const dS = tOff + (bX
|
|
83
|
+
const tOff = (canvasY - tile.y) * tileSize
|
|
84
|
+
const dS = tOff + (bX - tile.x)
|
|
85
85
|
|
|
86
86
|
for (let j = 0; j < bW_t; j++) {
|
|
87
87
|
const canvasX = bX + j
|
|
@@ -130,9 +130,9 @@ export class AlphaMaskPaintBuffer {
|
|
|
130
130
|
const lookup = this.lookup
|
|
131
131
|
const tilePool = this.tilePool
|
|
132
132
|
const config = this.config
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
const
|
|
133
|
+
const targetW = config.targetWidth
|
|
134
|
+
const targetH = config.targetHeight
|
|
135
|
+
const tileSize = config.tileSize
|
|
136
136
|
|
|
137
137
|
const { w: bW, h: bH, data: bD, centerOffsetX, centerOffsetY } = brush
|
|
138
138
|
let changed = false
|
|
@@ -149,8 +149,8 @@ export class AlphaMaskPaintBuffer {
|
|
|
149
149
|
topLeftY,
|
|
150
150
|
bW,
|
|
151
151
|
bH,
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
targetW,
|
|
153
|
+
targetH,
|
|
154
154
|
scratch,
|
|
155
155
|
)
|
|
156
156
|
|
|
@@ -163,8 +163,8 @@ export class AlphaMaskPaintBuffer {
|
|
|
163
163
|
for (let i = 0; i < bH_t; i++) {
|
|
164
164
|
const canvasY = bY + i
|
|
165
165
|
const bOff = (canvasY - topLeftY) * bW
|
|
166
|
-
const tOff = (canvasY
|
|
167
|
-
const dS = tOff + (bX
|
|
166
|
+
const tOff = (canvasY - tile.y) * tileSize
|
|
167
|
+
const dS = tOff + (bX - tile.x)
|
|
168
168
|
|
|
169
169
|
for (let j = 0; j < bW_t; j++) {
|
|
170
170
|
const canvasX = bX + j
|
|
@@ -210,9 +210,9 @@ export class AlphaMaskPaintBuffer {
|
|
|
210
210
|
const lookup = this.lookup
|
|
211
211
|
const tilePool = this.tilePool
|
|
212
212
|
const config = this.config
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
const
|
|
213
|
+
const targetW = config.targetWidth
|
|
214
|
+
const targetH = config.targetHeight
|
|
215
|
+
const tileSize = config.tileSize
|
|
216
216
|
|
|
217
217
|
const brushWidth = brush.w
|
|
218
218
|
const brushHeight = brush.h
|
|
@@ -237,8 +237,8 @@ export class AlphaMaskPaintBuffer {
|
|
|
237
237
|
topLeftY,
|
|
238
238
|
brushWidth,
|
|
239
239
|
brushHeight,
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
targetW,
|
|
241
|
+
targetH,
|
|
242
242
|
scratch,
|
|
243
243
|
)
|
|
244
244
|
|
|
@@ -250,8 +250,8 @@ export class AlphaMaskPaintBuffer {
|
|
|
250
250
|
|
|
251
251
|
for (let i = 0; i < bH_t; i++) {
|
|
252
252
|
const canvasY = bY + i
|
|
253
|
-
const tOff = (canvasY
|
|
254
|
-
const dS = tOff + (bX
|
|
253
|
+
const tOff = (canvasY - tile.y) * tileSize
|
|
254
|
+
const dS = tOff + (bX - tile.x)
|
|
255
255
|
|
|
256
256
|
for (let j = 0; j < bW_t; j++) {
|
|
257
257
|
const idx = dS + j
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { forEachLinePoint } from '../Algorithm/forEachLinePoint'
|
|
2
|
-
import type { PixelEngineConfig } from '../History/PixelEngineConfig'
|
|
3
2
|
import type { Rect } from '../Rect/_rect-types'
|
|
4
3
|
import { trimRectBounds } from '../Rect/trimRectBounds'
|
|
5
|
-
import type { BinaryMaskTile } from '../Tile/_tile-types'
|
|
6
|
-
import
|
|
4
|
+
import type { BinaryMaskTile, TileTargetMeta } from '../Tile/_tile-types'
|
|
5
|
+
import { makeBinaryMaskTile } from '../Tile/MaskTile'
|
|
6
|
+
import { TilePool } from '../Tile/TilePool'
|
|
7
7
|
import type { PaintBinaryMask, PaintRect } from './_paint-types'
|
|
8
8
|
import { eachTileInBounds } from './eachTileInBounds'
|
|
9
9
|
|
|
@@ -16,8 +16,8 @@ export class BinaryMaskPaintBuffer {
|
|
|
16
16
|
private eachTileInBoundsFn = eachTileInBounds
|
|
17
17
|
|
|
18
18
|
constructor(
|
|
19
|
-
readonly config:
|
|
20
|
-
readonly tilePool: TilePool<BinaryMaskTile
|
|
19
|
+
readonly config: TileTargetMeta,
|
|
20
|
+
readonly tilePool: TilePool<BinaryMaskTile> = new TilePool(config.tileSize, makeBinaryMaskTile),
|
|
21
21
|
) {
|
|
22
22
|
this.lookup = []
|
|
23
23
|
}
|
|
@@ -45,9 +45,9 @@ export class BinaryMaskPaintBuffer {
|
|
|
45
45
|
const lookup = this.lookup
|
|
46
46
|
const tilePool = this.tilePool
|
|
47
47
|
const config = this.config
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
48
|
+
const targetW = config.targetWidth
|
|
49
|
+
const targetH = config.targetHeight
|
|
50
|
+
const tileSize = config.tileSize
|
|
51
51
|
|
|
52
52
|
const { w: bW, h: bH, data: bD, centerOffsetX, centerOffsetY } = brush
|
|
53
53
|
let changed = false
|
|
@@ -64,8 +64,8 @@ export class BinaryMaskPaintBuffer {
|
|
|
64
64
|
topLeftY,
|
|
65
65
|
bW,
|
|
66
66
|
bH,
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
targetW,
|
|
68
|
+
targetH,
|
|
69
69
|
scratch,
|
|
70
70
|
)
|
|
71
71
|
|
|
@@ -78,8 +78,8 @@ export class BinaryMaskPaintBuffer {
|
|
|
78
78
|
for (let i = 0; i < bH_t; i++) {
|
|
79
79
|
const canvasY = bY + i
|
|
80
80
|
const bOff = (canvasY - topLeftY) * bW
|
|
81
|
-
const tOff = (canvasY
|
|
82
|
-
const dS = tOff + (bX
|
|
81
|
+
const tOff = (canvasY - tile.y) * tileSize
|
|
82
|
+
const dS = tOff + (bX - tile.x)
|
|
83
83
|
|
|
84
84
|
for (let j = 0; j < bW_t; j++) {
|
|
85
85
|
const canvasX = bX + j
|
|
@@ -125,9 +125,9 @@ export class BinaryMaskPaintBuffer {
|
|
|
125
125
|
const lookup = this.lookup
|
|
126
126
|
const tilePool = this.tilePool
|
|
127
127
|
const config = this.config
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
const
|
|
128
|
+
const targetW = config.targetWidth
|
|
129
|
+
const targetH = config.targetHeight
|
|
130
|
+
const tileSize = config.tileSize
|
|
131
131
|
|
|
132
132
|
const brushWidth = brush.w
|
|
133
133
|
const brushHeight = brush.h
|
|
@@ -152,8 +152,8 @@ export class BinaryMaskPaintBuffer {
|
|
|
152
152
|
topLeftY,
|
|
153
153
|
brushWidth,
|
|
154
154
|
brushHeight,
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
targetW,
|
|
156
|
+
targetH,
|
|
157
157
|
scratch,
|
|
158
158
|
)
|
|
159
159
|
|
|
@@ -165,8 +165,8 @@ export class BinaryMaskPaintBuffer {
|
|
|
165
165
|
|
|
166
166
|
for (let i = 0; i < bH_t; i++) {
|
|
167
167
|
const canvasY = bY + i
|
|
168
|
-
const tOff = (canvasY
|
|
169
|
-
const dS = tOff + (bX
|
|
168
|
+
const tOff = (canvasY - tile.y) * tileSize
|
|
169
|
+
const dS = tOff + (bX - tile.x)
|
|
170
170
|
|
|
171
171
|
for (let j = 0; j < bW_t; j++) {
|
|
172
172
|
const idx = dS + j
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { Color32 } from '../_types'
|
|
2
1
|
import { forEachLinePoint } from '../Algorithm/forEachLinePoint'
|
|
3
|
-
import type {
|
|
2
|
+
import type { Color32 } from '../Color/_color-types'
|
|
4
3
|
import type { Rect } from '../Rect/_rect-types'
|
|
5
4
|
import { trimRectBounds } from '../Rect/trimRectBounds'
|
|
6
|
-
import type { PixelTile } from '../Tile/_tile-types'
|
|
5
|
+
import type { PixelTile, TileTargetMeta } from '../Tile/_tile-types'
|
|
7
6
|
import type { TilePool } from '../Tile/TilePool'
|
|
8
7
|
import type { PaintAlphaMask, PaintBinaryMask, PaintRect } from './_paint-types'
|
|
9
8
|
import { eachTileInBounds } from './eachTileInBounds'
|
|
@@ -13,7 +12,7 @@ export class ColorPaintBuffer {
|
|
|
13
12
|
private readonly scratchBounds: Rect = { x: 0, y: 0, w: 0, h: 0 }
|
|
14
13
|
|
|
15
14
|
constructor(
|
|
16
|
-
readonly config:
|
|
15
|
+
readonly config: TileTargetMeta,
|
|
17
16
|
readonly tilePool: TilePool<PixelTile>,
|
|
18
17
|
) {
|
|
19
18
|
this.lookup = []
|
|
@@ -48,9 +47,9 @@ export class ColorPaintBuffer {
|
|
|
48
47
|
const lookup = this.lookup
|
|
49
48
|
const tilePool = this.tilePool
|
|
50
49
|
const config = this.config
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
50
|
+
const tileSize = config.tileSize
|
|
51
|
+
const targetW = config.targetWidth
|
|
52
|
+
const targetH = config.targetHeight
|
|
54
53
|
|
|
55
54
|
const { w: bW, h: bH, data: bD, centerOffsetX, centerOffsetY } = brush
|
|
56
55
|
const cRGB = color & 0x00ffffff
|
|
@@ -66,8 +65,8 @@ export class ColorPaintBuffer {
|
|
|
66
65
|
topLeftY,
|
|
67
66
|
bW,
|
|
68
67
|
bH,
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
targetW,
|
|
69
|
+
targetH,
|
|
71
70
|
scratch,
|
|
72
71
|
)
|
|
73
72
|
|
|
@@ -80,8 +79,8 @@ export class ColorPaintBuffer {
|
|
|
80
79
|
for (let i = 0; i < bH_t; i++) {
|
|
81
80
|
const canvasY = bY + i
|
|
82
81
|
const bOff = (canvasY - topLeftY) * bW
|
|
83
|
-
const tOff = (canvasY
|
|
84
|
-
const dS = tOff + (bX
|
|
82
|
+
const tOff = (canvasY - tile.y) * tileSize
|
|
83
|
+
const dS = tOff + (bX - tile.x)
|
|
85
84
|
|
|
86
85
|
for (let j = 0; j < bW_t; j++) {
|
|
87
86
|
const canvasX = bX + j
|
|
@@ -137,9 +136,9 @@ export class ColorPaintBuffer {
|
|
|
137
136
|
const lookup = this.lookup
|
|
138
137
|
const tilePool = this.tilePool
|
|
139
138
|
const config = this.config
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
139
|
+
const tileSize = config.tileSize
|
|
140
|
+
const targetW = config.targetWidth
|
|
141
|
+
const targetH = config.targetHeight
|
|
143
142
|
|
|
144
143
|
const { w: bW, h: bH, data: bD, centerOffsetX, centerOffsetY } = brush
|
|
145
144
|
let changed = false
|
|
@@ -153,8 +152,8 @@ export class ColorPaintBuffer {
|
|
|
153
152
|
topLeftY,
|
|
154
153
|
bW,
|
|
155
154
|
bH,
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
targetW,
|
|
156
|
+
targetH,
|
|
158
157
|
scratch,
|
|
159
158
|
)
|
|
160
159
|
|
|
@@ -167,8 +166,9 @@ export class ColorPaintBuffer {
|
|
|
167
166
|
for (let i = 0; i < bH_t; i++) {
|
|
168
167
|
const canvasY = bY + i
|
|
169
168
|
const bOff = (canvasY - topLeftY) * bW
|
|
170
|
-
|
|
171
|
-
const
|
|
169
|
+
|
|
170
|
+
const tOff = (canvasY - tile.y) * tileSize
|
|
171
|
+
const dS = tOff + (bX - tile.x)
|
|
172
172
|
|
|
173
173
|
for (let j = 0; j < bW_t; j++) {
|
|
174
174
|
const canvasX = bX + j
|
|
@@ -217,9 +217,9 @@ export class ColorPaintBuffer {
|
|
|
217
217
|
const lookup = this.lookup
|
|
218
218
|
const tilePool = this.tilePool
|
|
219
219
|
const config = this.config
|
|
220
|
-
const
|
|
221
|
-
const
|
|
222
|
-
const
|
|
220
|
+
const targetW = config.targetWidth
|
|
221
|
+
const targetH = config.targetHeight
|
|
222
|
+
const tileSize = config.tileSize
|
|
223
223
|
|
|
224
224
|
const brushWidth = brush.w
|
|
225
225
|
const brushHeight = brush.h
|
|
@@ -242,39 +242,37 @@ export class ColorPaintBuffer {
|
|
|
242
242
|
topLeftY,
|
|
243
243
|
brushWidth,
|
|
244
244
|
brushHeight,
|
|
245
|
-
|
|
246
|
-
|
|
245
|
+
targetW,
|
|
246
|
+
targetH,
|
|
247
247
|
scratch,
|
|
248
248
|
)
|
|
249
249
|
|
|
250
250
|
if (scratch.w <= 0 || scratch.h <= 0) return
|
|
251
251
|
|
|
252
252
|
eachTileInBounds(config, lookup, tilePool, scratch, (tile, bX, bY, bW_t, bH_t) => {
|
|
253
|
-
|
|
254
|
-
|
|
253
|
+
const d32 = tile.data
|
|
254
|
+
let tileChanged = false
|
|
255
255
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
256
|
+
for (let i = 0; i < bH_t; i++) {
|
|
257
|
+
const canvasY = bY + i
|
|
258
|
+
const tOff = (canvasY - tile.y) * tileSize
|
|
259
|
+
const dS = tOff + (bX - tile.x)
|
|
260
260
|
|
|
261
|
-
|
|
262
|
-
|
|
261
|
+
for (let j = 0; j < bW_t; j++) {
|
|
262
|
+
const idx = dS + j
|
|
263
263
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
264
|
+
if (d32[idx] !== color) {
|
|
265
|
+
d32[idx] = color
|
|
266
|
+
tileChanged = true
|
|
268
267
|
}
|
|
269
268
|
}
|
|
269
|
+
}
|
|
270
270
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
},
|
|
277
|
-
)
|
|
271
|
+
if (tileChanged) {
|
|
272
|
+
changed = true
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
})
|
|
278
276
|
|
|
279
277
|
return changed
|
|
280
278
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Color32 } from '../../_types'
|
|
2
1
|
import { sourceOverPerfect } from '../../BlendModes/blend-modes-perfect'
|
|
2
|
+
import type { Color32 } from '../../Color/_color-types'
|
|
3
3
|
import type { PixelAccumulator } from '../../History/PixelAccumulator'
|
|
4
4
|
import { blendColorPixelDataAlphaMask } from '../../PixelData/blendColorPixelDataAlphaMask'
|
|
5
5
|
import type { AlphaMaskPaintBuffer } from '../AlphaMaskPaintBuffer'
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReusableCanvasFactory } from '../../Canvas/_canvas-types'
|
|
2
2
|
import type { PixelWriter } from '../../History/PixelWriter'
|
|
3
|
-
import { DEFAULT_CANVAS_FACTORY } from '../../Internal/_constants'
|
|
4
3
|
import { makeAlphaMaskTile } from '../../Tile/MaskTile'
|
|
5
4
|
import { TilePool } from '../../Tile/TilePool'
|
|
6
5
|
import { AlphaMaskPaintBuffer } from '../AlphaMaskPaintBuffer'
|
|
@@ -11,17 +10,17 @@ export type AlphaMaskPaintBufferManager =
|
|
|
11
10
|
Pick<AlphaMaskPaintBuffer, 'paintAlphaMask' | 'paintBinaryMask' | 'paintRect'>
|
|
12
11
|
& {
|
|
13
12
|
commit: ReturnType<typeof makeAlphaMaskPaintBufferCommitter>
|
|
14
|
-
|
|
13
|
+
renderer: ReturnType<typeof makeAlphaMaskPaintBufferCanvasRenderer>
|
|
15
14
|
clear: () => void
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
export function makeAlphaMaskPaintBufferManager(
|
|
19
18
|
writer: Pick<PixelWriter<any>, 'accumulator' | 'config'>,
|
|
20
|
-
|
|
19
|
+
reusableCanvasFactory?: () => ReusableCanvasFactory<any>,
|
|
21
20
|
): AlphaMaskPaintBufferManager {
|
|
22
|
-
const pool = new TilePool(writer.config, makeAlphaMaskTile)
|
|
21
|
+
const pool = new TilePool(writer.config.tileSize, makeAlphaMaskTile)
|
|
23
22
|
const buffer = new AlphaMaskPaintBuffer(writer.config, pool)
|
|
24
|
-
const
|
|
23
|
+
const renderer = makeAlphaMaskPaintBufferCanvasRenderer(buffer, reusableCanvasFactory)
|
|
25
24
|
|
|
26
25
|
return {
|
|
27
26
|
clear: buffer.clear.bind(buffer),
|
|
@@ -29,6 +28,6 @@ export function makeAlphaMaskPaintBufferManager(
|
|
|
29
28
|
paintAlphaMask: buffer.paintAlphaMask.bind(buffer),
|
|
30
29
|
paintBinaryMask: buffer.paintBinaryMask.bind(buffer),
|
|
31
30
|
commit: makeAlphaMaskPaintBufferCommitter(writer.accumulator, buffer),
|
|
32
|
-
|
|
31
|
+
renderer,
|
|
33
32
|
}
|
|
34
33
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Color32 } from '../../_types'
|
|
2
1
|
import { sourceOverPerfect } from '../../BlendModes/blend-modes-perfect'
|
|
2
|
+
import type { Color32 } from '../../Color/_color-types'
|
|
3
3
|
import type { PixelAccumulator } from '../../History/PixelAccumulator'
|
|
4
4
|
import { blendColorPixelDataBinaryMask } from '../../PixelData/blendColorPixelDataBinaryMask'
|
|
5
5
|
import type { BinaryMaskPaintBuffer } from '../BinaryMaskPaintBuffer'
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReusableCanvasFactory } from '../../Canvas/_canvas-types'
|
|
2
2
|
import type { PixelWriter } from '../../History/PixelWriter'
|
|
3
|
-
import { DEFAULT_CANVAS_FACTORY } from '../../Internal/_constants'
|
|
4
3
|
import { makeBinaryMaskTile } from '../../Tile/MaskTile'
|
|
5
4
|
import { TilePool } from '../../Tile/TilePool'
|
|
6
5
|
import { BinaryMaskPaintBuffer } from '../BinaryMaskPaintBuffer'
|
|
@@ -9,23 +8,23 @@ import { makeBinaryMaskPaintBufferCommitter } from './BinaryMaskPaintBufferCommi
|
|
|
9
8
|
|
|
10
9
|
export type BinaryMaskPaintBufferManager = Pick<BinaryMaskPaintBuffer, 'paintBinaryMask' | 'paintRect'> & {
|
|
11
10
|
commit: ReturnType<typeof makeBinaryMaskPaintBufferCommitter>
|
|
12
|
-
|
|
11
|
+
renderer: ReturnType<typeof makeBinaryMaskPaintBufferCanvasRenderer>
|
|
13
12
|
clear: () => void
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
export function makeBinaryMaskPaintBufferManager(
|
|
17
16
|
writer: Pick<PixelWriter<any>, 'accumulator' | 'config'>,
|
|
18
|
-
|
|
17
|
+
reusableCanvasFactory?: () => ReusableCanvasFactory<any>,
|
|
19
18
|
): BinaryMaskPaintBufferManager {
|
|
20
|
-
const pool = new TilePool(writer.config, makeBinaryMaskTile)
|
|
19
|
+
const pool = new TilePool(writer.config.tileSize, makeBinaryMaskTile)
|
|
21
20
|
const buffer = new BinaryMaskPaintBuffer(writer.config, pool)
|
|
22
|
-
const
|
|
21
|
+
const renderer = makeBinaryMaskPaintBufferCanvasRenderer(buffer, reusableCanvasFactory)
|
|
23
22
|
|
|
24
23
|
return {
|
|
25
24
|
clear: buffer.clear.bind(buffer),
|
|
26
25
|
paintRect: buffer.paintRect.bind(buffer),
|
|
27
26
|
paintBinaryMask: buffer.paintBinaryMask.bind(buffer),
|
|
28
27
|
commit: makeBinaryMaskPaintBufferCommitter(writer.accumulator, buffer),
|
|
29
|
-
|
|
28
|
+
renderer,
|
|
30
29
|
}
|
|
31
30
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ReusableCanvasFactory } from '../../Canvas/_canvas-types'
|
|
2
2
|
import type { PixelWriter } from '../../History/PixelWriter'
|
|
3
|
-
import { DEFAULT_CANVAS_FACTORY } from '../../Internal/_constants'
|
|
4
3
|
import { makePixelTile } from '../../Tile/PixelTile'
|
|
5
4
|
import { TilePool } from '../../Tile/TilePool'
|
|
6
5
|
import { ColorPaintBuffer } from '../ColorPaintBuffer'
|
|
@@ -11,17 +10,17 @@ export type ColorPaintBufferManager =
|
|
|
11
10
|
Pick<ColorPaintBuffer, 'paintAlphaMask' | 'paintBinaryMask' | 'paintRect'>
|
|
12
11
|
& {
|
|
13
12
|
commit: ReturnType<typeof makeColorPaintBufferCommitter>
|
|
14
|
-
|
|
13
|
+
renderer: ReturnType<typeof makeColorPaintBufferCanvasRenderer>
|
|
15
14
|
clear: () => void
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
export function makeColorPaintBufferManager(
|
|
19
18
|
writer: Pick<PixelWriter<any>, 'accumulator' | 'config'>,
|
|
20
|
-
|
|
19
|
+
reusableCanvasFactory?: () => ReusableCanvasFactory<any>,
|
|
21
20
|
): ColorPaintBufferManager {
|
|
22
|
-
const pool = new TilePool(writer.config, makePixelTile)
|
|
21
|
+
const pool = new TilePool(writer.config.tileSize, makePixelTile)
|
|
23
22
|
const buffer = new ColorPaintBuffer(writer.config, pool)
|
|
24
|
-
const
|
|
23
|
+
const renderer = makeColorPaintBufferCanvasRenderer(buffer, reusableCanvasFactory)
|
|
25
24
|
|
|
26
25
|
return {
|
|
27
26
|
clear: buffer.clear.bind(buffer),
|
|
@@ -29,6 +28,6 @@ export function makeColorPaintBufferManager(
|
|
|
29
28
|
paintAlphaMask: buffer.paintAlphaMask.bind(buffer),
|
|
30
29
|
paintBinaryMask: buffer.paintBinaryMask.bind(buffer),
|
|
31
30
|
commit: makeColorPaintBufferCommitter(writer.accumulator, buffer),
|
|
32
|
-
|
|
31
|
+
renderer,
|
|
33
32
|
}
|
|
34
33
|
}
|
|
@@ -20,7 +20,6 @@ export function commitColorPaintBuffer(
|
|
|
20
20
|
blendPixelDataFn = blendPixelData,
|
|
21
21
|
) {
|
|
22
22
|
const config = accumulator.config
|
|
23
|
-
const tileShift = config.tileShift
|
|
24
23
|
const lookup = paintBuffer.lookup
|
|
25
24
|
|
|
26
25
|
SCRATCH_OPTS.alpha = alpha
|
|
@@ -32,11 +31,8 @@ export function commitColorPaintBuffer(
|
|
|
32
31
|
if (tile) {
|
|
33
32
|
const didChange = accumulator.storeTileBeforeState(tile.id, tile.tx, tile.ty)
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
SCRATCH_OPTS.x = dx
|
|
39
|
-
SCRATCH_OPTS.y = dy
|
|
34
|
+
SCRATCH_OPTS.x = tile.x
|
|
35
|
+
SCRATCH_OPTS.y = tile.y
|
|
40
36
|
SCRATCH_OPTS.w = tile.w
|
|
41
37
|
SCRATCH_OPTS.h = tile.h
|
|
42
38
|
|