pixel-data-js 0.34.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 +188 -56
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +30 -14
- package/dist/index.prod.js +184 -55
- 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/PaintRect.ts +4 -1
- package/src/Paint/Render/PaintCursorRenderer.ts +40 -28
- package/src/Paint/_paint-types.ts +5 -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;
|
|
@@ -1051,11 +1059,15 @@ interface PaintAlphaMask<T extends PaintMaskOutline = PaintMaskOutline> extends
|
|
|
1051
1059
|
interface PaintBinaryMask<T extends PaintMaskOutline = PaintMaskOutline> extends BasePaintMask<T>, BinaryMask {
|
|
1052
1060
|
}
|
|
1053
1061
|
type PaintMask = PaintAlphaMask<any> | PaintBinaryMask<any>;
|
|
1062
|
+
type PaintBrush = PaintMask | PaintRect;
|
|
1054
1063
|
interface PaintRect {
|
|
1064
|
+
type: null;
|
|
1065
|
+
readonly outlineType: PaintMaskOutline.RECT;
|
|
1055
1066
|
w: number;
|
|
1056
1067
|
h: number;
|
|
1057
1068
|
centerOffsetX: number;
|
|
1058
1069
|
centerOffsetY: number;
|
|
1070
|
+
data: null;
|
|
1059
1071
|
}
|
|
1060
1072
|
|
|
1061
1073
|
/**
|
|
@@ -1223,13 +1235,10 @@ type Deps$2 = Partial<typeof defaults$2>;
|
|
|
1223
1235
|
* @param deps - @hidden
|
|
1224
1236
|
*/
|
|
1225
1237
|
declare const mutatorFill: (writer: PixelWriter<any>, deps?: Deps$2) => {
|
|
1226
|
-
fill
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
*/
|
|
1231
|
-
declare const mutatorFillRect: (writer: PixelWriter<any>, deps?: Deps$2) => {
|
|
1232
|
-
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
|
+
};
|
|
1233
1242
|
};
|
|
1234
1243
|
|
|
1235
1244
|
/**
|
|
@@ -1804,14 +1813,15 @@ declare function makePaintRect(w: number, h: number): PaintRect;
|
|
|
1804
1813
|
|
|
1805
1814
|
type PaintCursorRenderer = ReturnType<typeof makePaintCursorRenderer>;
|
|
1806
1815
|
declare function makePaintCursorRenderer<T extends HTMLCanvasElement | OffscreenCanvas = OffscreenCanvas>(reusableCanvasFactory?: () => ReusableCanvasFactory<T>): {
|
|
1807
|
-
update: (paintMask?:
|
|
1816
|
+
update: (paintMask?: PaintBrush, scale?: number, color?: Color32, alphaThreshold?: number) => void;
|
|
1808
1817
|
getBounds: (centerX: number, centerY: number) => Rect;
|
|
1809
1818
|
getBoundsScaled: (centerX: number, centerY: number) => Rect;
|
|
1810
1819
|
draw: (drawCtx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, centerX: number, centerY: number) => void;
|
|
1820
|
+
drawRaw: (drawCtx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, x: number, y: number) => void;
|
|
1811
1821
|
getSettings: () => {
|
|
1812
1822
|
color: Color32;
|
|
1813
1823
|
scale: number;
|
|
1814
|
-
|
|
1824
|
+
currentBrush: PaintBrush;
|
|
1815
1825
|
};
|
|
1816
1826
|
};
|
|
1817
1827
|
|
|
@@ -1837,6 +1847,8 @@ declare function clearPixelDataFast(dst: PixelData32, rect?: Partial<BinaryMaskR
|
|
|
1837
1847
|
|
|
1838
1848
|
declare function copyPixelData<T extends ImageDataLike = ImageData>(target: PixelData<T>): PixelData;
|
|
1839
1849
|
|
|
1850
|
+
declare function cropPixelData(src: PixelData32, x: number, y: number, w: number, h: number, out?: MutablePixelData): PixelData;
|
|
1851
|
+
|
|
1840
1852
|
/**
|
|
1841
1853
|
* High-level extraction that returns a new PixelData instance.
|
|
1842
1854
|
* Leverages extractPixelDataBuffer for optimized 32-bit memory moves.
|
|
@@ -1923,6 +1935,10 @@ declare function makeReusablePixelData(): (width: number, height: number) => Pix
|
|
|
1923
1935
|
*/
|
|
1924
1936
|
declare function rotatePixelData(pixelData: PixelData): void;
|
|
1925
1937
|
|
|
1938
|
+
declare function getPixelDataTransparentTrimmedBounds(target: PixelData32): Rect | null;
|
|
1939
|
+
declare function trimTransparentPixelData(target: PixelData32): PixelData;
|
|
1940
|
+
declare function trimTransparentPixelDataInPlace(target: MutablePixelData): void;
|
|
1941
|
+
|
|
1926
1942
|
declare function uInt32ArrayToPixelData(data: Uint32Array, width: number, height: number): PixelData;
|
|
1927
1943
|
|
|
1928
1944
|
/**
|
|
@@ -1981,4 +1997,4 @@ declare const makeBinaryMaskTile: TileFactory<BinaryMaskTile>;
|
|
|
1981
1997
|
|
|
1982
1998
|
declare function makePixelTile(id: number, tx: number, ty: number, tileSize: number, tileArea: number): PixelTile;
|
|
1983
1999
|
|
|
1984
|
-
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 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
|
}
|
|
@@ -5896,6 +5942,9 @@ function makeRectFalloffPaintAlphaMask(width, height, fallOff = (d) => d) {
|
|
|
5896
5942
|
// src/Paint/PaintRect.ts
|
|
5897
5943
|
function makePaintRect(w, h) {
|
|
5898
5944
|
return {
|
|
5945
|
+
type: null,
|
|
5946
|
+
outlineType: 2 /* RECT */,
|
|
5947
|
+
data: null,
|
|
5899
5948
|
w,
|
|
5900
5949
|
h,
|
|
5901
5950
|
centerOffsetX: -(w - 1 >> 1),
|
|
@@ -5932,31 +5981,34 @@ function makePaintCursorRenderer(reusableCanvasFactory) {
|
|
|
5932
5981
|
const getPixelData = makeReusablePixelData();
|
|
5933
5982
|
let _color = packColor(0, 255, 255, 255);
|
|
5934
5983
|
let _scale = 1;
|
|
5935
|
-
let
|
|
5936
|
-
type:
|
|
5984
|
+
let currentBrush = {
|
|
5985
|
+
type: null,
|
|
5937
5986
|
outlineType: 2 /* RECT */,
|
|
5938
5987
|
w: 1,
|
|
5939
5988
|
h: 1,
|
|
5940
5989
|
centerOffsetX: -(10 - 1 >> 1),
|
|
5941
|
-
centerOffsetY: -(10 - 1 >> 1)
|
|
5990
|
+
centerOffsetY: -(10 - 1 >> 1),
|
|
5991
|
+
data: null
|
|
5942
5992
|
};
|
|
5943
5993
|
let outline;
|
|
5944
5994
|
function update(paintMask, scale, color, alphaThreshold = 127) {
|
|
5945
|
-
|
|
5995
|
+
currentBrush = paintMask ?? currentBrush;
|
|
5946
5996
|
_scale = scale ?? _scale;
|
|
5947
5997
|
_color = color ?? _color;
|
|
5948
|
-
updateBuffer(
|
|
5949
|
-
if (
|
|
5950
|
-
if (
|
|
5951
|
-
outline = makeCircleBinaryMaskOutline(
|
|
5952
|
-
} else if (
|
|
5953
|
-
outline = makeRectBinaryMaskOutline(
|
|
5954
|
-
} else if (
|
|
5955
|
-
outline = makeBinaryMaskOutline(
|
|
5998
|
+
updateBuffer(currentBrush.w * _scale + 2 * _scale, currentBrush.h * _scale + 2 * _scale);
|
|
5999
|
+
if (currentBrush.type === 1 /* BINARY */) {
|
|
6000
|
+
if (currentBrush.outlineType === 1 /* CIRCLE */) {
|
|
6001
|
+
outline = makeCircleBinaryMaskOutline(currentBrush.w, _scale);
|
|
6002
|
+
} else if (currentBrush.outlineType === 2 /* RECT */) {
|
|
6003
|
+
outline = makeRectBinaryMaskOutline(currentBrush.w, currentBrush.h, _scale);
|
|
6004
|
+
} else if (currentBrush.outlineType === 0 /* MASKED */) {
|
|
6005
|
+
outline = makeBinaryMaskOutline(currentBrush, _scale);
|
|
5956
6006
|
}
|
|
5957
|
-
} else if (
|
|
5958
|
-
const mask = makeBinaryMaskFromAlphaMask(
|
|
6007
|
+
} else if (currentBrush.type === 0 /* ALPHA */) {
|
|
6008
|
+
const mask = makeBinaryMaskFromAlphaMask(currentBrush, alphaThreshold);
|
|
5959
6009
|
outline = makeBinaryMaskOutline(mask, _scale);
|
|
6010
|
+
} else {
|
|
6011
|
+
outline = makeRectBinaryMaskOutline(currentBrush.w, currentBrush.h, _scale);
|
|
5960
6012
|
}
|
|
5961
6013
|
const pixelData = getPixelData(outline.w, outline.h);
|
|
5962
6014
|
fillPixelDataBinaryMask(pixelData, _color, outline);
|
|
@@ -5969,10 +6021,10 @@ function makePaintCursorRenderer(reusableCanvasFactory) {
|
|
|
5969
6021
|
h: 0
|
|
5970
6022
|
};
|
|
5971
6023
|
function getBounds(centerX, centerY) {
|
|
5972
|
-
boundsScratch.x = centerX +
|
|
5973
|
-
boundsScratch.y = centerY +
|
|
5974
|
-
boundsScratch.w =
|
|
5975
|
-
boundsScratch.h =
|
|
6024
|
+
boundsScratch.x = centerX + currentBrush.centerOffsetX;
|
|
6025
|
+
boundsScratch.y = centerY + currentBrush.centerOffsetY;
|
|
6026
|
+
boundsScratch.w = currentBrush.w;
|
|
6027
|
+
boundsScratch.h = currentBrush.h;
|
|
5976
6028
|
return boundsScratch;
|
|
5977
6029
|
}
|
|
5978
6030
|
const boundsScaledScratch = {
|
|
@@ -5982,22 +6034,25 @@ function makePaintCursorRenderer(reusableCanvasFactory) {
|
|
|
5982
6034
|
h: 0
|
|
5983
6035
|
};
|
|
5984
6036
|
function getOutlineBoundsScaled(centerX, centerY) {
|
|
5985
|
-
boundsScaledScratch.x = centerX * _scale +
|
|
5986
|
-
boundsScaledScratch.y = centerY * _scale +
|
|
5987
|
-
boundsScaledScratch.w =
|
|
5988
|
-
boundsScaledScratch.h =
|
|
6037
|
+
boundsScaledScratch.x = centerX * _scale + currentBrush.centerOffsetX * _scale - 1;
|
|
6038
|
+
boundsScaledScratch.y = centerY * _scale + currentBrush.centerOffsetY * _scale - 1;
|
|
6039
|
+
boundsScaledScratch.w = currentBrush.w * _scale;
|
|
6040
|
+
boundsScaledScratch.h = currentBrush.h * _scale;
|
|
5989
6041
|
return boundsScaledScratch;
|
|
5990
6042
|
}
|
|
5991
6043
|
function draw(drawCtx, centerX, centerY) {
|
|
5992
|
-
const dx = centerX * _scale +
|
|
5993
|
-
const dy = centerY * _scale +
|
|
6044
|
+
const dx = centerX * _scale + currentBrush.centerOffsetX * _scale - 1;
|
|
6045
|
+
const dy = centerY * _scale + currentBrush.centerOffsetY * _scale - 1;
|
|
5994
6046
|
drawCtx.drawImage(canvas, Math.floor(dx), Math.floor(dy));
|
|
5995
6047
|
}
|
|
6048
|
+
function drawRaw(drawCtx, x, y) {
|
|
6049
|
+
drawCtx.drawImage(canvas, Math.floor(x * _scale), Math.floor(y * _scale));
|
|
6050
|
+
}
|
|
5996
6051
|
function getSettings() {
|
|
5997
6052
|
return {
|
|
5998
6053
|
color: _color,
|
|
5999
6054
|
scale: _scale,
|
|
6000
|
-
|
|
6055
|
+
currentBrush
|
|
6001
6056
|
};
|
|
6002
6057
|
}
|
|
6003
6058
|
return {
|
|
@@ -6005,6 +6060,7 @@ function makePaintCursorRenderer(reusableCanvasFactory) {
|
|
|
6005
6060
|
getBounds,
|
|
6006
6061
|
getBoundsScaled: getOutlineBoundsScaled,
|
|
6007
6062
|
draw,
|
|
6063
|
+
drawRaw,
|
|
6008
6064
|
getSettings
|
|
6009
6065
|
};
|
|
6010
6066
|
}
|
|
@@ -6179,6 +6235,36 @@ function copyPixelData(target) {
|
|
|
6179
6235
|
return makePixelData(new ImageData(buffer, target.w, target.h));
|
|
6180
6236
|
}
|
|
6181
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
|
+
|
|
6182
6268
|
// src/PixelData/extractPixelDataBuffer.ts
|
|
6183
6269
|
function extractPixelDataBuffer(source, _x, _y, _w, _h) {
|
|
6184
6270
|
let x;
|
|
@@ -6394,6 +6480,46 @@ function rotateSquareInPlace(pixelData) {
|
|
|
6394
6480
|
}
|
|
6395
6481
|
}
|
|
6396
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
|
+
|
|
6397
6523
|
// src/PixelData/uInt32ArrayToPixelData.ts
|
|
6398
6524
|
function uInt32ArrayToPixelData(data, width, height) {
|
|
6399
6525
|
const buffer = data.buffer;
|
|
@@ -6552,6 +6678,7 @@ export {
|
|
|
6552
6678
|
copyImageDataLike,
|
|
6553
6679
|
copyMask,
|
|
6554
6680
|
copyPixelData,
|
|
6681
|
+
cropPixelData,
|
|
6555
6682
|
darkenFast,
|
|
6556
6683
|
darkenPerfect,
|
|
6557
6684
|
darkerFast,
|
|
@@ -6590,6 +6717,7 @@ export {
|
|
|
6590
6717
|
getImageDataFromClipboard,
|
|
6591
6718
|
getIndexedImageColor,
|
|
6592
6719
|
getIndexedImageColorCounts,
|
|
6720
|
+
getPixelDataTransparentTrimmedBounds,
|
|
6593
6721
|
getRectsBounds,
|
|
6594
6722
|
getSupportedPixelFormats,
|
|
6595
6723
|
hardLightFast,
|
|
@@ -6685,7 +6813,6 @@ export {
|
|
|
6685
6813
|
mutatorClear,
|
|
6686
6814
|
mutatorFill,
|
|
6687
6815
|
mutatorFillBinaryMask,
|
|
6688
|
-
mutatorFillRect,
|
|
6689
6816
|
mutatorInvert,
|
|
6690
6817
|
overlayFast,
|
|
6691
6818
|
overlayPerfect,
|
|
@@ -6729,6 +6856,8 @@ export {
|
|
|
6729
6856
|
toBlendModeIndexAndName,
|
|
6730
6857
|
trimMaskRectBounds,
|
|
6731
6858
|
trimRectBounds,
|
|
6859
|
+
trimTransparentPixelData,
|
|
6860
|
+
trimTransparentPixelDataInPlace,
|
|
6732
6861
|
uInt32ArrayToImageData,
|
|
6733
6862
|
uInt32ArrayToImageDataLike,
|
|
6734
6863
|
uInt32ArrayToPixelData,
|