pixel-data-js 0.35.0 → 0.36.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 +157 -31
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +24 -12
- package/dist/index.prod.js +153 -30
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/History/PixelAccumulator.ts +27 -6
- 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 +2 -0
- package/src/History/PixelMutator/mutatorBlendColorPaintAlphaMask.ts +1 -0
- package/src/History/PixelMutator/mutatorBlendColorPaintBinaryMask.ts +1 -0
- package/src/History/PixelMutator/mutatorBlendColorPaintMask.ts +1 -0
- package/src/History/PixelMutator/mutatorBlendColorPaintRect.ts +2 -0
- package/src/History/PixelMutator/mutatorBlendMask.ts +1 -0
- package/src/History/PixelMutator/mutatorBlendPixel.ts +1 -0
- package/src/History/PixelMutator/mutatorBlendPixelData.ts +1 -0
- package/src/History/PixelMutator/mutatorClear.ts +2 -1
- package/src/History/PixelMutator/mutatorFill.ts +53 -37
- package/src/History/PixelMutator/mutatorFillBinaryMask.ts +2 -1
- package/src/History/PixelMutator/mutatorInvert.ts +3 -2
- package/src/History/PixelMutator.ts +1 -2
- package/src/Paint/Render/PaintCursorRenderer.ts +9 -0
- package/src/PixelData/_pixelData-types.ts +7 -0
- package/src/PixelData/cropPixelData.ts +36 -0
- package/src/PixelData/fillPixelData.ts +6 -6
- package/src/PixelData/trimPixelData.ts +49 -0
- package/src/index.ts +2 -0
package/dist/index.prod.d.ts
CHANGED
|
@@ -221,6 +221,12 @@ interface MutablePixelData32 {
|
|
|
221
221
|
interface PixelData<T extends ImageDataLike = ImageData> extends PixelData32 {
|
|
222
222
|
readonly imageData: T;
|
|
223
223
|
}
|
|
224
|
+
interface MutablePixelData<T extends ImageDataLike = ImageData> extends PixelData32 {
|
|
225
|
+
imageData: T;
|
|
226
|
+
data: Uint32Array;
|
|
227
|
+
w: number;
|
|
228
|
+
h: number;
|
|
229
|
+
}
|
|
224
230
|
|
|
225
231
|
type FloodFillResult = BinaryMaskRect & {
|
|
226
232
|
startX: number;
|
|
@@ -798,14 +804,14 @@ declare class PixelAccumulator {
|
|
|
798
804
|
* @param x pixel x coordinate
|
|
799
805
|
* @param y pixel y coordinate
|
|
800
806
|
*/
|
|
801
|
-
storePixelBeforeState(x: number, y: number): DidChangeFn;
|
|
807
|
+
storePixelBeforeState(x: number, y: number): DidChangeFn | null;
|
|
802
808
|
/**
|
|
803
809
|
* @param x pixel x coordinate
|
|
804
810
|
* @param y pixel y coordinate
|
|
805
811
|
* @param w pixel width
|
|
806
812
|
* @param h pixel height
|
|
807
813
|
*/
|
|
808
|
-
storeRegionBeforeState(x: number, y: number, w: number, h: number): DidChangeFn;
|
|
814
|
+
storeRegionBeforeState(x: number, y: number, w: number, h: number): DidChangeFn | null;
|
|
809
815
|
storeTileBeforeState(id: number, tx: number, ty: number): DidChangeFn;
|
|
810
816
|
extractState(tile: PixelTile): void;
|
|
811
817
|
extractPatch(): PixelPatchTiles;
|
|
@@ -926,9 +932,11 @@ type HistoryMutator<T extends {}, D extends {}> = (writer: PixelWriter<any>, dep
|
|
|
926
932
|
|
|
927
933
|
declare function makeFullPixelMutator(writer: PixelWriter<any>): {
|
|
928
934
|
invert(opts?: PixelMutateOptions): boolean;
|
|
929
|
-
fillRect(color: Color32, rect: Rect): boolean;
|
|
930
935
|
fillBinaryMask(color: Color32, mask: BinaryMask, x?: number, y?: number): boolean;
|
|
931
|
-
fill
|
|
936
|
+
fill: {
|
|
937
|
+
(color: Color32, rect?: Partial<Rect>): boolean;
|
|
938
|
+
(color: Color32, x: number, y: number, w: number, h: number): boolean;
|
|
939
|
+
};
|
|
932
940
|
clear(rect?: Partial<Rect>): boolean;
|
|
933
941
|
blendPixelData(src: PixelData32, opts?: PixelBlendOptions): boolean;
|
|
934
942
|
blendPixel(x: number, y: number, color: Color32, alpha?: number, blendFn?: BlendColor32): boolean;
|
|
@@ -1227,13 +1235,10 @@ type Deps$2 = Partial<typeof defaults$2>;
|
|
|
1227
1235
|
* @param deps - @hidden
|
|
1228
1236
|
*/
|
|
1229
1237
|
declare const mutatorFill: (writer: PixelWriter<any>, deps?: Deps$2) => {
|
|
1230
|
-
fill
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
*/
|
|
1235
|
-
declare const mutatorFillRect: (writer: PixelWriter<any>, deps?: Deps$2) => {
|
|
1236
|
-
fillRect(color: Color32, rect: Rect): boolean;
|
|
1238
|
+
fill: {
|
|
1239
|
+
(color: Color32, rect?: Partial<Rect>): boolean;
|
|
1240
|
+
(color: Color32, x: number, y: number, w: number, h: number): boolean;
|
|
1241
|
+
};
|
|
1237
1242
|
};
|
|
1238
1243
|
|
|
1239
1244
|
/**
|
|
@@ -1812,6 +1817,7 @@ declare function makePaintCursorRenderer<T extends HTMLCanvasElement | Offscreen
|
|
|
1812
1817
|
getBounds: (centerX: number, centerY: number) => Rect;
|
|
1813
1818
|
getBoundsScaled: (centerX: number, centerY: number) => Rect;
|
|
1814
1819
|
draw: (drawCtx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, centerX: number, centerY: number) => void;
|
|
1820
|
+
drawRaw: (drawCtx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, x: number, y: number) => void;
|
|
1815
1821
|
getSettings: () => {
|
|
1816
1822
|
color: Color32;
|
|
1817
1823
|
scale: number;
|
|
@@ -1841,6 +1847,8 @@ declare function clearPixelDataFast(dst: PixelData32, rect?: Partial<BinaryMaskR
|
|
|
1841
1847
|
|
|
1842
1848
|
declare function copyPixelData<T extends ImageDataLike = ImageData>(target: PixelData<T>): PixelData;
|
|
1843
1849
|
|
|
1850
|
+
declare function cropPixelData(src: PixelData32, x: number, y: number, w: number, h: number, out?: MutablePixelData): PixelData;
|
|
1851
|
+
|
|
1844
1852
|
/**
|
|
1845
1853
|
* High-level extraction that returns a new PixelData instance.
|
|
1846
1854
|
* Leverages extractPixelDataBuffer for optimized 32-bit memory moves.
|
|
@@ -1927,6 +1935,10 @@ declare function makeReusablePixelData(): (width: number, height: number) => Pix
|
|
|
1927
1935
|
*/
|
|
1928
1936
|
declare function rotatePixelData(pixelData: PixelData): void;
|
|
1929
1937
|
|
|
1938
|
+
declare function getPixelDataTransparentTrimmedBounds(target: PixelData32): Rect | null;
|
|
1939
|
+
declare function trimTransparentPixelData(target: PixelData32): PixelData;
|
|
1940
|
+
declare function trimTransparentPixelDataInPlace(target: MutablePixelData): void;
|
|
1941
|
+
|
|
1930
1942
|
declare function uInt32ArrayToPixelData(data: Uint32Array, width: number, height: number): PixelData;
|
|
1931
1943
|
|
|
1932
1944
|
/**
|
|
@@ -1985,4 +1997,4 @@ declare const makeBinaryMaskTile: TileFactory<BinaryMaskTile>;
|
|
|
1985
1997
|
|
|
1986
1998
|
declare function makePixelTile(id: number, tx: number, ty: number, tileSize: number, tileArea: number): PixelTile;
|
|
1987
1999
|
|
|
1988
|
-
export { type AlphaMask, AlphaMaskPaintBuffer, type AlphaMaskPaintBufferCanvasRenderer, type AlphaMaskPaintBufferManager, type AlphaMaskRect, type AlphaMaskTile, type ApplyMaskToPixelDataOptions, BASE_FAST_BLEND_MODE_FUNCTIONS, BASE_PERFECT_BLEND_MODE_FUNCTIONS, type Base64EncodedUInt8Array, BaseBlendMode, type BaseBlendModes, type BaseMask, type BasePixelBlendOptions, type BatchedQueue, type BatchedQueueFn, type BinaryMask, BinaryMaskPaintBuffer, type BinaryMaskPaintBufferCanvasRenderer, type BinaryMaskPaintBufferManager, type BinaryMaskRect, type BinaryMaskTile, type BlendColor32, type BlendModeRegistry, CANVAS_COMPOSITE_MAP, type CanvasBlendModeIndex, type CanvasCompositeOperation, type CanvasContext, type CanvasFrameRenderer, type CanvasObjectFactory, type CanvasPixelDataRenderer, type Color32, type ColorBlendMaskOptions, type ColorBlendOptions, ColorPaintBuffer, type ColorPaintBufferCanvasRenderer, type ColorPaintBufferManager, type DidChangeFn, type DrawPixelLayer, type DrawScreenLayer, _errors as ERRORS, type FloodFillResult, type HistoryAction, type HistoryActionFactory, HistoryManager, type HistoryMutator, type ImageDataLike, type IndexedImage, type InvertMask, type Mask, type MaskOffset, type MaskRect, MaskType, type MergeAlphaMasksOptions, type MutableAlphaMask, type MutableBinaryMask, type MutableMask, type MutablePixelData32, type NullableBinaryMaskRect, type NullableMaskRect, type PaintAlphaMask, type PaintBinaryMask, type PaintBrush, type PaintCursorRenderer, type PaintMask, PaintMaskOutline, type PaintRect, PixelAccumulator, type PixelBlendMaskOptions, type PixelBlendOptions, type PixelCanvas, type PixelData, type PixelData32, PixelEngineConfig, type PixelMutateOptions, type PixelPatchTiles, type PixelRect, type PixelTile, PixelWriter, type PixelWriterOptions, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableCanvasFactory, type ReusableImageData, type ReusablePixelData, type SerializedImageData, type Tile, type TileFactory, TilePool, TileType, UnsupportedFormatError, _macro_imageDataToUint32Array, applyAlphaMaskToPixelData, applyBinaryMaskToAlphaMask, applyBinaryMaskToPixelData, applyMaskToPixelData, applyPatchTiles, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendColorPixelDataAlphaMask, blendColorPixelDataBinaryMask, blendColorPixelDataMask, blendColorPixelDataPaintAlphaMask, blendColorPixelDataPaintBinaryMask, blendColorPixelDataPaintMask, blendPixel, blendPixelData, blendPixelDataAlphaMask, blendPixelDataBinaryMask, blendPixelDataMask, blendPixelDataPaintBuffer, clearPixelDataFast, color32ToCssRGBA, color32ToHex, colorBurnFast, colorBurnPerfect, colorDistance, colorDodgeFast, colorDodgePerfect, commitColorPaintBuffer, commitMaskPaintBuffer, copyImageData, copyImageDataLike, copyMask, copyPixelData, darkenFast, darkenPerfect, darkerFast, darkerPerfect, deserializeImageData, deserializeNullableImageData, deserializeRawImageData, destinationAtopFast, destinationAtopPerfect, destinationInFast, destinationInPerfect, destinationOutFast, destinationOutPerfect, destinationOverFast, destinationOverPerfect, differenceFast, differencePerfect, divideFast, dividePerfect, eachTileInBounds, exclusionFast, exclusionPerfect, extractImageData, extractImageDataBuffer, extractMask, extractMaskBuffer, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, fillPixelDataBinaryMask, fillPixelDataFast, floodFillSelection, forEachLinePoint, getImageDataFromClipboard, getIndexedImageColor, getIndexedImageColorCounts, getRectsBounds, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMaskBuffer, imageDataToDataUrl, imageDataToImgBlob, imageDataToUint32Array, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makeAlphaMask, makeAlphaMaskPaintBufferCanvasRenderer, makeAlphaMaskPaintBufferCommitter, makeAlphaMaskPaintBufferManager, makeAlphaMaskTile, makeBatchedQueue, makeBinaryMask, makeBinaryMaskFromAlphaMask, makeBinaryMaskOutline, makeBinaryMaskPaintBufferCanvasRenderer, makeBinaryMaskPaintBufferCommitter, makeBinaryMaskPaintBufferManager, makeBinaryMaskTile, makeBlendModeRegistry, makeCanvasFrameRenderer, makeCanvasPixelDataRenderer, makeCircleBinaryMaskOutline, makeCirclePaintAlphaMask, makeCirclePaintBinaryMask, makeColorPaintBufferCanvasRenderer, makeColorPaintBufferCommitter, makeColorPaintBufferManager, makeFastBlendModeRegistry, makeFullPixelMutator, makeHistoryAction, makeImageDataLike, makeIndexedImage, makeIndexedImageFromImageData, makeIndexedImageFromImageDataRaw, makePaintAlphaMask, makePaintBinaryMask, makePaintCursorRenderer, makePaintRect, makePerfectBlendModeRegistry, makePixelCanvas, makePixelData, makePixelTile, makeRectBinaryMaskOutline, makeRectFalloffPaintAlphaMask, makeRenderQueue, makeReusableCanvas, makeReusableImageData, makeReusableOffscreenCanvas, makeReusablePixelData, merge2BinaryMaskRects, mergeAlphaMasks, mergeBinaryMaskRects, mergeBinaryMasks, multiplyFast, multiplyPerfect, mutatorApplyAlphaMask, mutatorApplyBinaryMask, mutatorApplyMask, mutatorBlendAlphaMask, mutatorBlendBinaryMask, mutatorBlendColor, mutatorBlendColorPaintAlphaMask, mutatorBlendColorPaintBinaryMask, mutatorBlendColorPaintMask, mutatorBlendColorPaintRect, mutatorBlendMask, mutatorBlendPixel, mutatorBlendPixelData, mutatorClear, mutatorFill, mutatorFillBinaryMask,
|
|
2000
|
+
export { type AlphaMask, AlphaMaskPaintBuffer, type AlphaMaskPaintBufferCanvasRenderer, type AlphaMaskPaintBufferManager, type AlphaMaskRect, type AlphaMaskTile, type ApplyMaskToPixelDataOptions, BASE_FAST_BLEND_MODE_FUNCTIONS, BASE_PERFECT_BLEND_MODE_FUNCTIONS, type Base64EncodedUInt8Array, BaseBlendMode, type BaseBlendModes, type BaseMask, type BasePixelBlendOptions, type BatchedQueue, type BatchedQueueFn, type BinaryMask, BinaryMaskPaintBuffer, type BinaryMaskPaintBufferCanvasRenderer, type BinaryMaskPaintBufferManager, type BinaryMaskRect, type BinaryMaskTile, type BlendColor32, type BlendModeRegistry, CANVAS_COMPOSITE_MAP, type CanvasBlendModeIndex, type CanvasCompositeOperation, type CanvasContext, type CanvasFrameRenderer, type CanvasObjectFactory, type CanvasPixelDataRenderer, type Color32, type ColorBlendMaskOptions, type ColorBlendOptions, ColorPaintBuffer, type ColorPaintBufferCanvasRenderer, type ColorPaintBufferManager, type DidChangeFn, type DrawPixelLayer, type DrawScreenLayer, _errors as ERRORS, type FloodFillResult, type HistoryAction, type HistoryActionFactory, HistoryManager, type HistoryMutator, type ImageDataLike, type IndexedImage, type InvertMask, type Mask, type MaskOffset, type MaskRect, MaskType, type MergeAlphaMasksOptions, type MutableAlphaMask, type MutableBinaryMask, type MutableMask, type MutablePixelData, type MutablePixelData32, type NullableBinaryMaskRect, type NullableMaskRect, type PaintAlphaMask, type PaintBinaryMask, type PaintBrush, type PaintCursorRenderer, type PaintMask, PaintMaskOutline, type PaintRect, PixelAccumulator, type PixelBlendMaskOptions, type PixelBlendOptions, type PixelCanvas, type PixelData, type PixelData32, PixelEngineConfig, type PixelMutateOptions, type PixelPatchTiles, type PixelRect, type PixelTile, PixelWriter, type PixelWriterOptions, type RGBA, type Rect, type RequiredBlendModes, type ReusableCanvas, type ReusableCanvasFactory, type ReusableImageData, type ReusablePixelData, type SerializedImageData, type Tile, type TileFactory, TilePool, TileType, UnsupportedFormatError, _macro_imageDataToUint32Array, applyAlphaMaskToPixelData, applyBinaryMaskToAlphaMask, applyBinaryMaskToPixelData, applyMaskToPixelData, applyPatchTiles, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendColorPixelDataAlphaMask, blendColorPixelDataBinaryMask, blendColorPixelDataMask, blendColorPixelDataPaintAlphaMask, blendColorPixelDataPaintBinaryMask, blendColorPixelDataPaintMask, blendPixel, blendPixelData, blendPixelDataAlphaMask, blendPixelDataBinaryMask, blendPixelDataMask, blendPixelDataPaintBuffer, clearPixelDataFast, color32ToCssRGBA, color32ToHex, colorBurnFast, colorBurnPerfect, colorDistance, colorDodgeFast, colorDodgePerfect, commitColorPaintBuffer, commitMaskPaintBuffer, copyImageData, copyImageDataLike, copyMask, copyPixelData, cropPixelData, darkenFast, darkenPerfect, darkerFast, darkerPerfect, deserializeImageData, deserializeNullableImageData, deserializeRawImageData, destinationAtopFast, destinationAtopPerfect, destinationInFast, destinationInPerfect, destinationOutFast, destinationOutPerfect, destinationOverFast, destinationOverPerfect, differenceFast, differencePerfect, divideFast, dividePerfect, eachTileInBounds, exclusionFast, exclusionPerfect, extractImageData, extractImageDataBuffer, extractMask, extractMaskBuffer, extractPixelData, extractPixelDataBuffer, fileInputChangeToImageData, fileToImageData, fillPixelData, fillPixelDataBinaryMask, fillPixelDataFast, floodFillSelection, forEachLinePoint, getImageDataFromClipboard, getIndexedImageColor, getIndexedImageColorCounts, getPixelDataTransparentTrimmedBounds, getRectsBounds, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMaskBuffer, imageDataToDataUrl, imageDataToImgBlob, imageDataToUint32Array, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makeAlphaMask, makeAlphaMaskPaintBufferCanvasRenderer, makeAlphaMaskPaintBufferCommitter, makeAlphaMaskPaintBufferManager, makeAlphaMaskTile, makeBatchedQueue, makeBinaryMask, makeBinaryMaskFromAlphaMask, makeBinaryMaskOutline, makeBinaryMaskPaintBufferCanvasRenderer, makeBinaryMaskPaintBufferCommitter, makeBinaryMaskPaintBufferManager, makeBinaryMaskTile, makeBlendModeRegistry, makeCanvasFrameRenderer, makeCanvasPixelDataRenderer, makeCircleBinaryMaskOutline, makeCirclePaintAlphaMask, makeCirclePaintBinaryMask, makeColorPaintBufferCanvasRenderer, makeColorPaintBufferCommitter, makeColorPaintBufferManager, makeFastBlendModeRegistry, makeFullPixelMutator, makeHistoryAction, makeImageDataLike, makeIndexedImage, makeIndexedImageFromImageData, makeIndexedImageFromImageDataRaw, makePaintAlphaMask, makePaintBinaryMask, makePaintCursorRenderer, makePaintRect, makePerfectBlendModeRegistry, makePixelCanvas, makePixelData, makePixelTile, makeRectBinaryMaskOutline, makeRectFalloffPaintAlphaMask, makeRenderQueue, makeReusableCanvas, makeReusableImageData, makeReusableOffscreenCanvas, makeReusablePixelData, merge2BinaryMaskRects, mergeAlphaMasks, mergeBinaryMaskRects, mergeBinaryMasks, multiplyFast, multiplyPerfect, mutatorApplyAlphaMask, mutatorApplyBinaryMask, mutatorApplyMask, mutatorBlendAlphaMask, mutatorBlendBinaryMask, mutatorBlendColor, mutatorBlendColorPaintAlphaMask, mutatorBlendColorPaintBinaryMask, mutatorBlendColorPaintMask, mutatorBlendColorPaintRect, mutatorBlendMask, mutatorBlendPixel, mutatorBlendPixelData, mutatorClear, mutatorFill, mutatorFillBinaryMask, mutatorInvert, overlayFast, overlayPerfect, overwriteBase, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resamplePixelDataInPlace, resampleUint32Array, resizeImageData, resizePixelData, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, setMaskData, setPixelData, softLightFast, softLightPerfect, sourceAtopFast, sourceAtopPerfect, sourceInFast, sourceInPerfect, sourceOutFast, sourceOutPerfect, sourceOverFast, sourceOverPerfect, subtractBinaryMaskRects, subtractFast, subtractPerfect, toBlendModeIndexAndName, trimMaskRectBounds, trimRectBounds, trimTransparentPixelData, trimTransparentPixelDataInPlace, uInt32ArrayToImageData, uInt32ArrayToImageDataLike, uInt32ArrayToPixelData, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataBuffer, writeImageDataToClipboard, writeImgBlobToClipboard, writePaintBufferToPixelData, writePixelData, writePixelDataBuffer, xorFast, xorPerfect };
|
package/dist/index.prod.js
CHANGED
|
@@ -2149,6 +2149,11 @@ var PixelAccumulator = class {
|
|
|
2149
2149
|
storePixelBeforeState(x, y) {
|
|
2150
2150
|
const shift = this.config.tileShift;
|
|
2151
2151
|
const columns = this.config.targetColumns;
|
|
2152
|
+
const targetWidth = this.config.target.w;
|
|
2153
|
+
const targetHeight = this.config.target.h;
|
|
2154
|
+
if (x < 0 || x >= targetWidth || y < 0 || y >= targetHeight) {
|
|
2155
|
+
return null;
|
|
2156
|
+
}
|
|
2152
2157
|
const tx = x >> shift;
|
|
2153
2158
|
const ty = y >> shift;
|
|
2154
2159
|
const id = ty * columns + tx;
|
|
@@ -2179,10 +2184,19 @@ var PixelAccumulator = class {
|
|
|
2179
2184
|
storeRegionBeforeState(x, y, w, h) {
|
|
2180
2185
|
const shift = this.config.tileShift;
|
|
2181
2186
|
const columns = this.config.targetColumns;
|
|
2182
|
-
const
|
|
2183
|
-
const
|
|
2184
|
-
const
|
|
2185
|
-
const
|
|
2187
|
+
const targetWidth = this.config.target.w;
|
|
2188
|
+
const targetHeight = this.config.target.h;
|
|
2189
|
+
const clipX1 = Math.max(0, x);
|
|
2190
|
+
const clipY1 = Math.max(0, y);
|
|
2191
|
+
const clipX2 = Math.min(targetWidth - 1, x + w - 1);
|
|
2192
|
+
const clipY2 = Math.min(targetHeight - 1, y + h - 1);
|
|
2193
|
+
if (clipX2 < clipX1 || clipY2 < clipY1) {
|
|
2194
|
+
return null;
|
|
2195
|
+
}
|
|
2196
|
+
const startX = clipX1 >> shift;
|
|
2197
|
+
const startY = clipY1 >> shift;
|
|
2198
|
+
const endX = clipX2 >> shift;
|
|
2199
|
+
const endY = clipY2 >> shift;
|
|
2186
2200
|
const startIndex = this.beforeTiles.length;
|
|
2187
2201
|
for (let ty = startY; ty <= endY; ty++) {
|
|
2188
2202
|
for (let tx = startX; tx <= endX; tx++) {
|
|
@@ -2653,6 +2667,7 @@ var mutatorApplyAlphaMask = ((writer, deps = defaults) => {
|
|
|
2653
2667
|
const w = opts?.w ?? target.w;
|
|
2654
2668
|
const h = opts?.h ?? target.h;
|
|
2655
2669
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
2670
|
+
if (!didChange) return false;
|
|
2656
2671
|
return didChange(applyAlphaMaskToPixelData2(target, mask, opts));
|
|
2657
2672
|
}
|
|
2658
2673
|
};
|
|
@@ -2755,7 +2770,12 @@ var mutatorApplyBinaryMask = ((writer, deps = defaults2) => {
|
|
|
2755
2770
|
const w = opts?.w ?? target.w;
|
|
2756
2771
|
const h = opts?.h ?? target.h;
|
|
2757
2772
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
2758
|
-
|
|
2773
|
+
if (!didChange) return false;
|
|
2774
|
+
const b = applyBinaryMaskToPixelData2(target, mask, opts);
|
|
2775
|
+
console.log({
|
|
2776
|
+
b
|
|
2777
|
+
});
|
|
2778
|
+
return didChange(b);
|
|
2759
2779
|
}
|
|
2760
2780
|
};
|
|
2761
2781
|
});
|
|
@@ -2778,6 +2798,7 @@ var mutatorApplyMask = ((writer, deps = defaults3) => {
|
|
|
2778
2798
|
const w = opts?.w ?? target.w;
|
|
2779
2799
|
const h = opts?.h ?? target.h;
|
|
2780
2800
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
2801
|
+
if (!didChange) return false;
|
|
2781
2802
|
if (mask.type === 1 /* BINARY */) {
|
|
2782
2803
|
return didChange(applyBinaryMaskToPixelData2(target, mask, opts));
|
|
2783
2804
|
} else {
|
|
@@ -2922,6 +2943,7 @@ var mutatorBlendAlphaMask = ((writer, deps = defaults4) => {
|
|
|
2922
2943
|
const w = opts?.w ?? src.w;
|
|
2923
2944
|
const h = opts?.h ?? src.h;
|
|
2924
2945
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
2946
|
+
if (!didChange) return false;
|
|
2925
2947
|
return didChange(blendPixelDataAlphaMask2(writer.config.target, src, mask, opts));
|
|
2926
2948
|
}
|
|
2927
2949
|
};
|
|
@@ -3049,6 +3071,7 @@ var mutatorBlendBinaryMask = ((writer, deps = defaults5) => {
|
|
|
3049
3071
|
const w = opts?.w ?? src.w;
|
|
3050
3072
|
const h = opts?.h ?? src.h;
|
|
3051
3073
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
3074
|
+
if (!didChange) return false;
|
|
3052
3075
|
return didChange(blendPixelDataBinaryMask2(writer.config.target, src, mask, opts));
|
|
3053
3076
|
}
|
|
3054
3077
|
};
|
|
@@ -3123,6 +3146,7 @@ var mutatorBlendColor = ((writer, deps = defaults6) => {
|
|
|
3123
3146
|
const w = opts?.w ?? target.w;
|
|
3124
3147
|
const h = opts?.h ?? target.h;
|
|
3125
3148
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
3149
|
+
if (!didChange) return false;
|
|
3126
3150
|
return didChange(blendColorPixelData2(target, color, opts));
|
|
3127
3151
|
}
|
|
3128
3152
|
};
|
|
@@ -3235,6 +3259,7 @@ var mutatorBlendColorPaintAlphaMask = ((writer, deps = defaults7) => {
|
|
|
3235
3259
|
const tx = x + mask.centerOffsetX;
|
|
3236
3260
|
const ty = y + mask.centerOffsetY;
|
|
3237
3261
|
const didChange = writer.accumulator.storeRegionBeforeState(tx, ty, mask.w, mask.h);
|
|
3262
|
+
if (!didChange) return false;
|
|
3238
3263
|
OPTS.x = tx;
|
|
3239
3264
|
OPTS.y = ty;
|
|
3240
3265
|
OPTS.alpha = alpha;
|
|
@@ -3331,6 +3356,7 @@ var mutatorBlendColorPaintBinaryMask = ((writer, deps = defaults8) => {
|
|
|
3331
3356
|
const tx = x + mask.centerOffsetX;
|
|
3332
3357
|
const ty = y + mask.centerOffsetY;
|
|
3333
3358
|
const didChange = writer.accumulator.storeRegionBeforeState(tx, ty, mask.w, mask.h);
|
|
3359
|
+
if (!didChange) return false;
|
|
3334
3360
|
OPTS.x = tx;
|
|
3335
3361
|
OPTS.y = ty;
|
|
3336
3362
|
OPTS.alpha = alpha;
|
|
@@ -3361,6 +3387,7 @@ var mutatorBlendColorPaintMask = ((writer, deps = defaults9) => {
|
|
|
3361
3387
|
const tx = x + mask.centerOffsetX;
|
|
3362
3388
|
const ty = y + mask.centerOffsetY;
|
|
3363
3389
|
const didChange = writer.accumulator.storeRegionBeforeState(tx, ty, mask.w, mask.h);
|
|
3390
|
+
if (!didChange) return false;
|
|
3364
3391
|
OPTS.x = tx;
|
|
3365
3392
|
OPTS.y = ty;
|
|
3366
3393
|
OPTS.alpha = alpha;
|
|
@@ -3402,6 +3429,7 @@ var mutatorBlendColorPaintRect = ((writer, deps = defaults10) => {
|
|
|
3402
3429
|
OPTS.blendFn = blendFn;
|
|
3403
3430
|
OPTS.alpha = alpha;
|
|
3404
3431
|
const didChange = writer.accumulator.storeRegionBeforeState(topLeftX, topLeftY, brushWidth, brushHeight);
|
|
3432
|
+
if (!didChange) return false;
|
|
3405
3433
|
return didChange(blendColorPixelData2(target, color, OPTS));
|
|
3406
3434
|
}
|
|
3407
3435
|
};
|
|
@@ -3424,6 +3452,7 @@ var mutatorBlendMask = ((writer, deps = defaults11) => {
|
|
|
3424
3452
|
const w = opts?.w ?? src.w;
|
|
3425
3453
|
const h = opts?.h ?? src.h;
|
|
3426
3454
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
3455
|
+
if (!didChange) return false;
|
|
3427
3456
|
if (mask.type === 1 /* BINARY */) {
|
|
3428
3457
|
return didChange(blendPixelDataBinaryMask2(writer.config.target, src, mask, opts));
|
|
3429
3458
|
} else {
|
|
@@ -3470,6 +3499,7 @@ var mutatorBlendPixel = ((writer, deps = defaults12) => {
|
|
|
3470
3499
|
return {
|
|
3471
3500
|
blendPixel(x, y, color, alpha, blendFn) {
|
|
3472
3501
|
const didChange = writer.accumulator.storePixelBeforeState(x, y);
|
|
3502
|
+
if (!didChange) return false;
|
|
3473
3503
|
return didChange(blendPixel2(writer.config.target, x, y, color, alpha, blendFn));
|
|
3474
3504
|
}
|
|
3475
3505
|
};
|
|
@@ -3577,6 +3607,7 @@ var mutatorBlendPixelData = ((writer, deps = defaults13) => {
|
|
|
3577
3607
|
const w = opts?.w ?? src.w;
|
|
3578
3608
|
const h = opts?.h ?? src.h;
|
|
3579
3609
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
3610
|
+
if (!didChange) return false;
|
|
3580
3611
|
return didChange(blendPixelData2(writer.config.target, src, opts));
|
|
3581
3612
|
}
|
|
3582
3613
|
};
|
|
@@ -3590,16 +3621,16 @@ function fillPixelData(dst, color, _x, _y, _w, _h) {
|
|
|
3590
3621
|
let y;
|
|
3591
3622
|
let w;
|
|
3592
3623
|
let h;
|
|
3593
|
-
if (typeof _x === "
|
|
3594
|
-
x = _x.x ?? 0;
|
|
3595
|
-
y = _x.y ?? 0;
|
|
3596
|
-
w = _x.w ?? dstW;
|
|
3597
|
-
h = _x.h ?? dstH;
|
|
3598
|
-
} else if (typeof _x === "number") {
|
|
3624
|
+
if (typeof _x === "number") {
|
|
3599
3625
|
x = _x;
|
|
3600
3626
|
y = _y;
|
|
3601
3627
|
w = _w;
|
|
3602
3628
|
h = _h;
|
|
3629
|
+
} else if (typeof _x === "object") {
|
|
3630
|
+
x = _x.x ?? 0;
|
|
3631
|
+
y = _x.y ?? 0;
|
|
3632
|
+
w = _x.w ?? dstW;
|
|
3633
|
+
h = _x.h ?? dstH;
|
|
3603
3634
|
} else {
|
|
3604
3635
|
x = 0;
|
|
3605
3636
|
y = 0;
|
|
@@ -3664,6 +3695,7 @@ var mutatorClear = ((writer, deps = defaults14) => {
|
|
|
3664
3695
|
const w = rect?.w ?? target.w;
|
|
3665
3696
|
const h = rect?.h ?? target.h;
|
|
3666
3697
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
3698
|
+
if (!didChange) return false;
|
|
3667
3699
|
return didChange(fillPixelData2(target, 0, x, y, w, h));
|
|
3668
3700
|
}
|
|
3669
3701
|
};
|
|
@@ -3677,24 +3709,37 @@ var mutatorFill = ((writer, deps = defaults15) => {
|
|
|
3677
3709
|
const {
|
|
3678
3710
|
fillPixelData: fillPixelData2 = defaults15.fillPixelData
|
|
3679
3711
|
} = deps;
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3712
|
+
const config = writer.config;
|
|
3713
|
+
function fill(color, _x, _y, _w, _h) {
|
|
3714
|
+
const target = config.target;
|
|
3715
|
+
const dstW = target.w;
|
|
3716
|
+
const dstH = target.h;
|
|
3717
|
+
let x;
|
|
3718
|
+
let y;
|
|
3719
|
+
let w;
|
|
3720
|
+
let h;
|
|
3721
|
+
if (typeof _x === "number") {
|
|
3722
|
+
x = _x;
|
|
3723
|
+
y = _y;
|
|
3724
|
+
w = _w;
|
|
3725
|
+
h = _h;
|
|
3726
|
+
} else if (typeof _x === "object") {
|
|
3727
|
+
x = _x.x ?? 0;
|
|
3728
|
+
y = _x.y ?? 0;
|
|
3729
|
+
w = _x.w ?? dstW;
|
|
3730
|
+
h = _x.h ?? dstH;
|
|
3731
|
+
} else {
|
|
3732
|
+
x = 0;
|
|
3733
|
+
y = 0;
|
|
3734
|
+
w = dstW;
|
|
3735
|
+
h = dstH;
|
|
3685
3736
|
}
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
fillPixelData: fillPixelData2 = defaults15.fillPixelData
|
|
3691
|
-
} = deps;
|
|
3737
|
+
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
3738
|
+
if (!didChange) return false;
|
|
3739
|
+
return didChange(fillPixelData2(target, color, x, y, w, h));
|
|
3740
|
+
}
|
|
3692
3741
|
return {
|
|
3693
|
-
|
|
3694
|
-
const target = writer.config.target;
|
|
3695
|
-
const didChange = writer.accumulator.storeRegionBeforeState(rect.x, rect.y, rect.w, rect.h);
|
|
3696
|
-
return didChange(fillPixelData2(target, color, rect.x, rect.y, rect.w, rect.h));
|
|
3697
|
-
}
|
|
3742
|
+
fill
|
|
3698
3743
|
};
|
|
3699
3744
|
});
|
|
3700
3745
|
|
|
@@ -3756,6 +3801,7 @@ var mutatorFillBinaryMask = ((writer, deps = defaults16) => {
|
|
|
3756
3801
|
return {
|
|
3757
3802
|
fillBinaryMask(color, mask, x = 0, y = 0) {
|
|
3758
3803
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, mask.w, mask.h);
|
|
3804
|
+
if (!didChange) return false;
|
|
3759
3805
|
return didChange(fillPixelDataBinaryMask2(writer.config.target, color, mask, x, y));
|
|
3760
3806
|
}
|
|
3761
3807
|
};
|
|
@@ -3840,7 +3886,8 @@ var mutatorInvert = ((writer, deps = defaults17) => {
|
|
|
3840
3886
|
const w = opts?.w ?? target.w;
|
|
3841
3887
|
const h = opts?.h ?? target.h;
|
|
3842
3888
|
const didChange = writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
3843
|
-
|
|
3889
|
+
if (!didChange) return false;
|
|
3890
|
+
return didChange?.(invertPixelData2(target, opts));
|
|
3844
3891
|
}
|
|
3845
3892
|
};
|
|
3846
3893
|
});
|
|
@@ -3865,7 +3912,6 @@ function makeFullPixelMutator(writer) {
|
|
|
3865
3912
|
...mutatorClear(writer),
|
|
3866
3913
|
...mutatorFill(writer),
|
|
3867
3914
|
...mutatorFillBinaryMask(writer),
|
|
3868
|
-
...mutatorFillRect(writer),
|
|
3869
3915
|
...mutatorInvert(writer)
|
|
3870
3916
|
};
|
|
3871
3917
|
}
|
|
@@ -5999,6 +6045,9 @@ function makePaintCursorRenderer(reusableCanvasFactory) {
|
|
|
5999
6045
|
const dy = centerY * _scale + currentBrush.centerOffsetY * _scale - 1;
|
|
6000
6046
|
drawCtx.drawImage(canvas, Math.floor(dx), Math.floor(dy));
|
|
6001
6047
|
}
|
|
6048
|
+
function drawRaw(drawCtx, x, y) {
|
|
6049
|
+
drawCtx.drawImage(canvas, Math.floor(x * _scale), Math.floor(y * _scale));
|
|
6050
|
+
}
|
|
6002
6051
|
function getSettings() {
|
|
6003
6052
|
return {
|
|
6004
6053
|
color: _color,
|
|
@@ -6011,6 +6060,7 @@ function makePaintCursorRenderer(reusableCanvasFactory) {
|
|
|
6011
6060
|
getBounds,
|
|
6012
6061
|
getBoundsScaled: getOutlineBoundsScaled,
|
|
6013
6062
|
draw,
|
|
6063
|
+
drawRaw,
|
|
6014
6064
|
getSettings
|
|
6015
6065
|
};
|
|
6016
6066
|
}
|
|
@@ -6185,6 +6235,36 @@ function copyPixelData(target) {
|
|
|
6185
6235
|
return makePixelData(new ImageData(buffer, target.w, target.h));
|
|
6186
6236
|
}
|
|
6187
6237
|
|
|
6238
|
+
// src/PixelData/cropPixelData.ts
|
|
6239
|
+
function cropPixelData(src, x, y, w, h, out) {
|
|
6240
|
+
const cx = Math.max(x, 0);
|
|
6241
|
+
const cy = Math.max(y, 0);
|
|
6242
|
+
const cw = Math.min(x + w, src.w) - cx;
|
|
6243
|
+
const ch = Math.min(y + h, src.h) - cy;
|
|
6244
|
+
if (cw <= 0 || ch <= 0) {
|
|
6245
|
+
throw new Error(`Crop [${x},${y} ${w}x${h}] does not overlap PixelData [${src.w}x${src.h}]`);
|
|
6246
|
+
}
|
|
6247
|
+
const cropped = new ImageData(cw, ch);
|
|
6248
|
+
let dst32;
|
|
6249
|
+
if (out) {
|
|
6250
|
+
setPixelData(out, cropped);
|
|
6251
|
+
dst32 = out.data;
|
|
6252
|
+
} else {
|
|
6253
|
+
dst32 = new Uint32Array(cropped.data.buffer);
|
|
6254
|
+
}
|
|
6255
|
+
for (let row = 0; row < ch; row++) {
|
|
6256
|
+
const srcOffset = (cy + row) * src.w + cx;
|
|
6257
|
+
const dstOffset = row * cw;
|
|
6258
|
+
dst32.set(src.data.subarray(srcOffset, srcOffset + cw), dstOffset);
|
|
6259
|
+
}
|
|
6260
|
+
return out ?? {
|
|
6261
|
+
data: dst32,
|
|
6262
|
+
imageData: cropped,
|
|
6263
|
+
w: cw,
|
|
6264
|
+
h: ch
|
|
6265
|
+
};
|
|
6266
|
+
}
|
|
6267
|
+
|
|
6188
6268
|
// src/PixelData/extractPixelDataBuffer.ts
|
|
6189
6269
|
function extractPixelDataBuffer(source, _x, _y, _w, _h) {
|
|
6190
6270
|
let x;
|
|
@@ -6400,6 +6480,46 @@ function rotateSquareInPlace(pixelData) {
|
|
|
6400
6480
|
}
|
|
6401
6481
|
}
|
|
6402
6482
|
|
|
6483
|
+
// src/PixelData/trimPixelData.ts
|
|
6484
|
+
function getPixelDataTransparentTrimmedBounds(target) {
|
|
6485
|
+
let minX = target.w;
|
|
6486
|
+
let minY = target.h;
|
|
6487
|
+
let maxX = -1;
|
|
6488
|
+
let maxY = -1;
|
|
6489
|
+
for (let y = 0; y < target.h; y++) {
|
|
6490
|
+
for (let x = 0; x < target.w; x++) {
|
|
6491
|
+
const alpha = target.data[y * target.w + x] >>> 24;
|
|
6492
|
+
if (alpha !== 0) {
|
|
6493
|
+
if (x < minX) minX = x;
|
|
6494
|
+
if (x > maxX) maxX = x;
|
|
6495
|
+
if (y < minY) minY = y;
|
|
6496
|
+
if (y > maxY) maxY = y;
|
|
6497
|
+
}
|
|
6498
|
+
}
|
|
6499
|
+
}
|
|
6500
|
+
if (maxX === -1) return null;
|
|
6501
|
+
return {
|
|
6502
|
+
x: minX,
|
|
6503
|
+
y: minY,
|
|
6504
|
+
w: maxX - minX + 1,
|
|
6505
|
+
h: maxY - minY + 1
|
|
6506
|
+
};
|
|
6507
|
+
}
|
|
6508
|
+
function trimTransparentPixelData(target) {
|
|
6509
|
+
const r = getPixelDataTransparentTrimmedBounds(target);
|
|
6510
|
+
if (!r) {
|
|
6511
|
+
throw new Error("PixelData is fully transparent \u2014 no crop bounds found");
|
|
6512
|
+
}
|
|
6513
|
+
return cropPixelData(target, r.x, r.y, r.w, r.h);
|
|
6514
|
+
}
|
|
6515
|
+
function trimTransparentPixelDataInPlace(target) {
|
|
6516
|
+
const r = getPixelDataTransparentTrimmedBounds(target);
|
|
6517
|
+
if (!r) {
|
|
6518
|
+
throw new Error("PixelData is fully transparent \u2014 no crop bounds found");
|
|
6519
|
+
}
|
|
6520
|
+
cropPixelData(target, r.x, r.y, r.w, r.h, target);
|
|
6521
|
+
}
|
|
6522
|
+
|
|
6403
6523
|
// src/PixelData/uInt32ArrayToPixelData.ts
|
|
6404
6524
|
function uInt32ArrayToPixelData(data, width, height) {
|
|
6405
6525
|
const buffer = data.buffer;
|
|
@@ -6558,6 +6678,7 @@ export {
|
|
|
6558
6678
|
copyImageDataLike,
|
|
6559
6679
|
copyMask,
|
|
6560
6680
|
copyPixelData,
|
|
6681
|
+
cropPixelData,
|
|
6561
6682
|
darkenFast,
|
|
6562
6683
|
darkenPerfect,
|
|
6563
6684
|
darkerFast,
|
|
@@ -6596,6 +6717,7 @@ export {
|
|
|
6596
6717
|
getImageDataFromClipboard,
|
|
6597
6718
|
getIndexedImageColor,
|
|
6598
6719
|
getIndexedImageColorCounts,
|
|
6720
|
+
getPixelDataTransparentTrimmedBounds,
|
|
6599
6721
|
getRectsBounds,
|
|
6600
6722
|
getSupportedPixelFormats,
|
|
6601
6723
|
hardLightFast,
|
|
@@ -6691,7 +6813,6 @@ export {
|
|
|
6691
6813
|
mutatorClear,
|
|
6692
6814
|
mutatorFill,
|
|
6693
6815
|
mutatorFillBinaryMask,
|
|
6694
|
-
mutatorFillRect,
|
|
6695
6816
|
mutatorInvert,
|
|
6696
6817
|
overlayFast,
|
|
6697
6818
|
overlayPerfect,
|
|
@@ -6735,6 +6856,8 @@ export {
|
|
|
6735
6856
|
toBlendModeIndexAndName,
|
|
6736
6857
|
trimMaskRectBounds,
|
|
6737
6858
|
trimRectBounds,
|
|
6859
|
+
trimTransparentPixelData,
|
|
6860
|
+
trimTransparentPixelDataInPlace,
|
|
6738
6861
|
uInt32ArrayToImageData,
|
|
6739
6862
|
uInt32ArrayToImageDataLike,
|
|
6740
6863
|
uInt32ArrayToPixelData,
|