pixel-data-js 0.12.0 → 0.13.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.dev.cjs +56 -39
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +55 -39
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +56 -39
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +32 -20
- package/dist/index.prod.js +55 -39
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/BlendModes/blend-modes-fast.ts +2 -2
- package/src/BlendModes/blend-modes-perfect.ts +2 -2
- package/src/BlendModes/blend-modes.ts +4 -0
- package/src/ImageData/ReusableImageData.ts +33 -0
- package/src/PixelData/blendColorPixelData.ts +15 -23
- package/src/PixelData/blendPixelData.ts +8 -4
- package/src/_types.ts +5 -3
- package/src/index.ts +2 -1
package/dist/index.prod.d.ts
CHANGED
|
@@ -15,7 +15,10 @@ type Color32 = number & {
|
|
|
15
15
|
* @param dst - The existing color in the buffer (destination).
|
|
16
16
|
* @returns The resulting 32-bit color to be written to the buffer.
|
|
17
17
|
*/
|
|
18
|
-
type BlendColor32 =
|
|
18
|
+
type BlendColor32 = {
|
|
19
|
+
(src: Color32, dst: Color32): Color32;
|
|
20
|
+
isOverwrite?: true;
|
|
21
|
+
};
|
|
19
22
|
type ImageDataLike = {
|
|
20
23
|
width: number;
|
|
21
24
|
height: number;
|
|
@@ -108,7 +111,7 @@ interface PixelOptions {
|
|
|
108
111
|
/** An optional mask to restrict where pixels are written. */
|
|
109
112
|
mask?: AnyMask | null;
|
|
110
113
|
/** The interpretation logic for the provided mask.
|
|
111
|
-
* @default {@link MaskType.
|
|
114
|
+
* @default {@link MaskType.ALPHA}
|
|
112
115
|
*/
|
|
113
116
|
maskType?: MaskType;
|
|
114
117
|
/**
|
|
@@ -481,6 +484,15 @@ declare function writeImageDataToClipboard(imageData: ImageData): Promise<void>;
|
|
|
481
484
|
*/
|
|
482
485
|
declare function writeImgBlobToClipboard(blob: Blob): Promise<void>;
|
|
483
486
|
|
|
487
|
+
type ReusableImageData = ReturnType<typeof makeReusableImageData>;
|
|
488
|
+
/**
|
|
489
|
+
* Creates a factory function that manages a single, reusable ImageData instance.
|
|
490
|
+
* This is used to minimize garbage collection overhead by recycling the
|
|
491
|
+
* underlying pixel buffer across multiple operations.
|
|
492
|
+
* @returns A function that takes width and height and returns a pooled ImageData instance.
|
|
493
|
+
*/
|
|
494
|
+
declare function makeReusableImageData(): (width: number, height: number) => ImageData;
|
|
495
|
+
|
|
484
496
|
declare function copyImageData({ data, width, height }: ImageDataLike): ImageData;
|
|
485
497
|
declare function copyImageDataLike({ data, width, height }: ImageDataLike): ImageDataLike;
|
|
486
498
|
|
|
@@ -630,6 +642,22 @@ declare function deserializeRawImageData<T extends SerializedImageData>(serializ
|
|
|
630
642
|
declare function deserializeImageData<T extends SerializedImageData>(serialized: T): ImageData;
|
|
631
643
|
declare function deserializeNullableImageData<T extends SerializedImageData | null>(serialized: T): T extends null ? null : ImageData;
|
|
632
644
|
|
|
645
|
+
/**
|
|
646
|
+
* Writes image data from a source to a target with support for clipping and alpha masking.
|
|
647
|
+
*
|
|
648
|
+
* @param target - The destination ImageData to write to.
|
|
649
|
+
* @param source - The source ImageData to read from.
|
|
650
|
+
* @param x - The x-coordinate in the target where drawing starts.
|
|
651
|
+
* @param y - The y-coordinate in the target where drawing starts.
|
|
652
|
+
* @param sx - The x-coordinate in the source to start copying from.
|
|
653
|
+
* @param sy - The y-coordinate in the source to start copying from.
|
|
654
|
+
* @param sw - The width of the rectangle to copy.
|
|
655
|
+
* @param sh - The height of the rectangle to copy.
|
|
656
|
+
* @param mask - An optional Uint8Array mask (0-255). 0 is transparent, 255 is opaque.
|
|
657
|
+
* @param maskType - type of mask
|
|
658
|
+
*/
|
|
659
|
+
declare function writeImageData(target: ImageData, source: ImageData, x: number, y: number, sx?: number, sy?: number, sw?: number, sh?: number, mask?: Uint8Array | null, maskType?: MaskType): void;
|
|
660
|
+
|
|
633
661
|
/**
|
|
634
662
|
* Copies a pixel buffer into a specific region of an {@link ImageData} object.
|
|
635
663
|
*
|
|
@@ -652,22 +680,6 @@ declare function writeImageDataPixels(imageData: ImageData, data: Uint8ClampedAr
|
|
|
652
680
|
*/
|
|
653
681
|
declare function writeImageDataPixels(imageData: ImageData, data: Uint8ClampedArray, x: number, y: number, w: number, h: number): void;
|
|
654
682
|
|
|
655
|
-
/**
|
|
656
|
-
* Writes image data from a source to a target with support for clipping and alpha masking.
|
|
657
|
-
*
|
|
658
|
-
* @param target - The destination ImageData to write to.
|
|
659
|
-
* @param source - The source ImageData to read from.
|
|
660
|
-
* @param x - The x-coordinate in the target where drawing starts.
|
|
661
|
-
* @param y - The y-coordinate in the target where drawing starts.
|
|
662
|
-
* @param sx - The x-coordinate in the source to start copying from.
|
|
663
|
-
* @param sy - The y-coordinate in the source to start copying from.
|
|
664
|
-
* @param sw - The width of the rectangle to copy.
|
|
665
|
-
* @param sh - The height of the rectangle to copy.
|
|
666
|
-
* @param mask - An optional Uint8Array mask (0-255). 0 is transparent, 255 is opaque.
|
|
667
|
-
* @param maskType - type of mask
|
|
668
|
-
*/
|
|
669
|
-
declare function writeImageData(target: ImageData, source: ImageData, x: number, y: number, sx?: number, sy?: number, sw?: number, sh?: number, mask?: Uint8Array | null, maskType?: MaskType): void;
|
|
670
|
-
|
|
671
683
|
/**
|
|
672
684
|
* Represents an image using a palette-based indexing system.
|
|
673
685
|
* Instead of storing 4 bytes (RGBA) per pixel, this class stores a single index
|
|
@@ -889,7 +901,7 @@ declare function applyMaskToPixelData(dst: PixelData, mask: AnyMask, opts: Apply
|
|
|
889
901
|
* Fills a rectangle in the destination PixelData with a single color,
|
|
890
902
|
* supporting blend modes, global alpha, and masking.
|
|
891
903
|
*/
|
|
892
|
-
declare function blendColorPixelData(dst: PixelData, color: Color32, opts
|
|
904
|
+
declare function blendColorPixelData(dst: PixelData, color: Color32, opts?: ColorBlendOptions): void;
|
|
893
905
|
|
|
894
906
|
/**
|
|
895
907
|
* Blits source PixelData into a destination PixelData using 32-bit integer bitwise blending.
|
|
@@ -977,4 +989,4 @@ declare function rotatePixelData(pixelData: PixelData): void;
|
|
|
977
989
|
*/
|
|
978
990
|
declare function trimRectBounds<T extends Rect | SelectionRect>(target: T, bounds: Rect): void;
|
|
979
991
|
|
|
980
|
-
export { type AlphaMask, type AnyMask, type ApplyMaskOptions, type Base64EncodedUInt8Array, type BinaryMask, type BlendColor32, BlendMode, type BlendModeIndex, type BlendToIndexGetter, type Color32, type ColorBlendOptions, FAST_BLENDER_REGISTRY, FAST_BLEND_MODES, FAST_BLEND_MODE_BY_NAME, FAST_BLEND_TO_INDEX, type FastBlendModes, type FloodFillImageDataOptions, type FloodFillResult, INDEX_TO_FAST_BLEND, INDEX_TO_PERFECT_BLEND, type ImageDataLike, type IndexToBlendGetter, IndexedImage, MaskType, PERFECT_BLENDER_REGISTRY, PERFECT_BLEND_MODES, PERFECT_BLEND_MODE_BY_NAME, PERFECT_BLEND_TO_INDEX, type PerfectBlendModes, type PixelBlendOptions, type PixelCanvas, PixelData, type PixelOptions, type Point, type RGBA, type Rect, type RegisteredFastBlender, type RegisteredPerfectBlender, type ReusableCanvas, type SelectionRect, type SerializedImageData, UnsupportedFormatError, applyMaskToPixelData, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendPixelData, clearPixelData, color32ToCssRGBA, color32ToHex, colorBurnFast, colorBurnPerfect, colorDistance, colorDodgeFast, colorDodgePerfect, copyImageData, copyImageDataLike, copyMask, darkenFast, darkenPerfect, darkerFast, darkerPerfect, deserializeImageData, deserializeNullableImageData, deserializeRawImageData, differenceFast, differencePerfect, divideFast, dividePerfect, exclusionFast, exclusionPerfect, extractImageDataPixels, extractMask, fileInputChangeToImageData, fileToImageData, fillPixelData, floodFillSelection, getImageDataFromClipboard, getIndexedImageColorCounts, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMask, imageDataToDataUrl, imageDataToImgBlob, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makePixelCanvas, makeReusableCanvas, mergeMasks, multiplyFast, multiplyPerfect, overlayFast, overlayPerfect, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resizeImageData, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, softLightFast, softLightPerfect, sourceOverFast, sourceOverPerfect, subtractFast, subtractPerfect, trimRectBounds, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataPixels, writeImageDataToClipboard, writeImgBlobToClipboard };
|
|
992
|
+
export { type AlphaMask, type AnyMask, type ApplyMaskOptions, type Base64EncodedUInt8Array, type BinaryMask, type BlendColor32, BlendMode, type BlendModeIndex, type BlendToIndexGetter, type Color32, type ColorBlendOptions, FAST_BLENDER_REGISTRY, FAST_BLEND_MODES, FAST_BLEND_MODE_BY_NAME, FAST_BLEND_TO_INDEX, type FastBlendModes, type FloodFillImageDataOptions, type FloodFillResult, INDEX_TO_FAST_BLEND, INDEX_TO_PERFECT_BLEND, type ImageDataLike, type IndexToBlendGetter, IndexedImage, MaskType, PERFECT_BLENDER_REGISTRY, PERFECT_BLEND_MODES, PERFECT_BLEND_MODE_BY_NAME, PERFECT_BLEND_TO_INDEX, type PerfectBlendModes, type PixelBlendOptions, type PixelCanvas, PixelData, type PixelOptions, type Point, type RGBA, type Rect, type RegisteredFastBlender, type RegisteredPerfectBlender, type ReusableCanvas, type ReusableImageData, type SelectionRect, type SerializedImageData, UnsupportedFormatError, applyMaskToPixelData, base64DecodeArrayBuffer, base64EncodeArrayBuffer, blendColorPixelData, blendPixelData, clearPixelData, color32ToCssRGBA, color32ToHex, colorBurnFast, colorBurnPerfect, colorDistance, colorDodgeFast, colorDodgePerfect, copyImageData, copyImageDataLike, copyMask, darkenFast, darkenPerfect, darkerFast, darkerPerfect, deserializeImageData, deserializeNullableImageData, deserializeRawImageData, differenceFast, differencePerfect, divideFast, dividePerfect, exclusionFast, exclusionPerfect, extractImageDataPixels, extractMask, fileInputChangeToImageData, fileToImageData, fillPixelData, floodFillSelection, getImageDataFromClipboard, getIndexedImageColorCounts, getSupportedPixelFormats, hardLightFast, hardLightPerfect, hardMixFast, hardMixPerfect, imageDataToAlphaMask, imageDataToDataUrl, imageDataToImgBlob, imgBlobToImageData, indexedImageToAverageColor, indexedImageToImageData, invertAlphaMask, invertBinaryMask, invertImageData, invertPixelData, lerpColor32, lerpColor32Fast, lightenFast, lightenPerfect, lighterFast, lighterPerfect, linearBurnFast, linearBurnPerfect, linearDodgeFast, linearDodgePerfect, linearLightFast, linearLightPerfect, makePixelCanvas, makeReusableCanvas, makeReusableImageData, mergeMasks, multiplyFast, multiplyPerfect, overlayFast, overlayPerfect, overwriteFast, overwritePerfect, packColor, packRGBA, pinLightFast, pinLightPerfect, pixelDataToAlphaMask, reflectPixelDataHorizontal, reflectPixelDataVertical, resampleImageData, resampleIndexedImage, resamplePixelData, resizeImageData, rotatePixelData, screenFast, screenPerfect, serializeImageData, serializeNullableImageData, softLightFast, softLightPerfect, sourceOverFast, sourceOverPerfect, subtractFast, subtractPerfect, trimRectBounds, unpackAlpha, unpackBlue, unpackColor, unpackColorTo, unpackGreen, unpackRed, vividLightFast, vividLightPerfect, writeImageData, writeImageDataPixels, writeImageDataToClipboard, writeImgBlobToClipboard };
|
package/dist/index.prod.js
CHANGED
|
@@ -25,9 +25,11 @@ var BlendMode = /* @__PURE__ */ ((BlendMode2) => {
|
|
|
25
25
|
BlendMode2[BlendMode2["divide"] = 22] = "divide";
|
|
26
26
|
return BlendMode2;
|
|
27
27
|
})(BlendMode || {});
|
|
28
|
+
var overwriteBase = (src, _dst) => src;
|
|
29
|
+
overwriteBase.isOverwrite = true;
|
|
28
30
|
|
|
29
31
|
// src/BlendModes/blend-modes-fast.ts
|
|
30
|
-
var overwriteFast =
|
|
32
|
+
var overwriteFast = overwriteBase;
|
|
31
33
|
var sourceOverFast = (src, dst) => {
|
|
32
34
|
const sa = src >>> 24 & 255;
|
|
33
35
|
if (sa === 255) return src;
|
|
@@ -842,7 +844,7 @@ function floodFillSelection(img, startX, startY, {
|
|
|
842
844
|
}
|
|
843
845
|
|
|
844
846
|
// src/BlendModes/blend-modes-perfect.ts
|
|
845
|
-
var overwritePerfect =
|
|
847
|
+
var overwritePerfect = overwriteBase;
|
|
846
848
|
var sourceOverPerfect = (src, dst) => {
|
|
847
849
|
const sa = src >>> 24 & 255;
|
|
848
850
|
if (sa === 255) return src;
|
|
@@ -1425,6 +1427,22 @@ async function writeImageDataToClipboard(imageData) {
|
|
|
1425
1427
|
return writeImgBlobToClipboard(blob);
|
|
1426
1428
|
}
|
|
1427
1429
|
|
|
1430
|
+
// src/ImageData/ReusableImageData.ts
|
|
1431
|
+
function makeReusableImageData() {
|
|
1432
|
+
let imageData = null;
|
|
1433
|
+
let buffer = null;
|
|
1434
|
+
return function getReusableImageData(width, height) {
|
|
1435
|
+
const hasInstance = !!imageData;
|
|
1436
|
+
const widthMatches = hasInstance && imageData.width === width;
|
|
1437
|
+
const heightMatches = hasInstance && imageData.height === height;
|
|
1438
|
+
if (!widthMatches || !heightMatches) {
|
|
1439
|
+
const buffer2 = new Uint8ClampedArray(width * height * 4);
|
|
1440
|
+
imageData = new ImageData(buffer2, width, height);
|
|
1441
|
+
}
|
|
1442
|
+
return imageData;
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1428
1446
|
// src/ImageData/copyImageData.ts
|
|
1429
1447
|
function copyImageData({ data, width, height }) {
|
|
1430
1448
|
return new ImageData(data.slice(), width, height);
|
|
@@ -1604,27 +1622,6 @@ function deserializeNullableImageData(serialized) {
|
|
|
1604
1622
|
return deserializeImageData(serialized);
|
|
1605
1623
|
}
|
|
1606
1624
|
|
|
1607
|
-
// src/ImageData/writeImageDataPixels.ts
|
|
1608
|
-
function writeImageDataPixels(imageData, data, _x, _y, _w, _h) {
|
|
1609
|
-
const { x, y, w, h } = typeof _x === "object" ? _x : { x: _x, y: _y, w: _w, h: _h };
|
|
1610
|
-
const { width: dstW, height: dstH, data: dst } = imageData;
|
|
1611
|
-
const x0 = Math.max(0, x);
|
|
1612
|
-
const y0 = Math.max(0, y);
|
|
1613
|
-
const x1 = Math.min(dstW, x + w);
|
|
1614
|
-
const y1 = Math.min(dstH, y + h);
|
|
1615
|
-
if (x1 <= x0 || y1 <= y0) return;
|
|
1616
|
-
const rowLen = (x1 - x0) * 4;
|
|
1617
|
-
const srcCol = x0 - x;
|
|
1618
|
-
const srcYOffset = y0 - y;
|
|
1619
|
-
const actualH = y1 - y0;
|
|
1620
|
-
for (let row = 0; row < actualH; row++) {
|
|
1621
|
-
const dstStart = ((y0 + row) * dstW + x0) * 4;
|
|
1622
|
-
const srcRow = srcYOffset + row;
|
|
1623
|
-
const o = (srcRow * w + srcCol) * 4;
|
|
1624
|
-
dst.set(data.subarray(o, o + rowLen), dstStart);
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
|
|
1628
1625
|
// src/ImageData/writeImageData.ts
|
|
1629
1626
|
function writeImageData(target, source, x, y, sx = 0, sy = 0, sw = source.width, sh = source.height, mask = null, maskType = 1 /* BINARY */) {
|
|
1630
1627
|
const dstW = target.width;
|
|
@@ -1679,6 +1676,27 @@ function writeImageData(target, source, x, y, sx = 0, sy = 0, sw = source.width,
|
|
|
1679
1676
|
}
|
|
1680
1677
|
}
|
|
1681
1678
|
|
|
1679
|
+
// src/ImageData/writeImageDataPixels.ts
|
|
1680
|
+
function writeImageDataPixels(imageData, data, _x, _y, _w, _h) {
|
|
1681
|
+
const { x, y, w, h } = typeof _x === "object" ? _x : { x: _x, y: _y, w: _w, h: _h };
|
|
1682
|
+
const { width: dstW, height: dstH, data: dst } = imageData;
|
|
1683
|
+
const x0 = Math.max(0, x);
|
|
1684
|
+
const y0 = Math.max(0, y);
|
|
1685
|
+
const x1 = Math.min(dstW, x + w);
|
|
1686
|
+
const y1 = Math.min(dstH, y + h);
|
|
1687
|
+
if (x1 <= x0 || y1 <= y0) return;
|
|
1688
|
+
const rowLen = (x1 - x0) * 4;
|
|
1689
|
+
const srcCol = x0 - x;
|
|
1690
|
+
const srcYOffset = y0 - y;
|
|
1691
|
+
const actualH = y1 - y0;
|
|
1692
|
+
for (let row = 0; row < actualH; row++) {
|
|
1693
|
+
const dstStart = ((y0 + row) * dstW + x0) * 4;
|
|
1694
|
+
const srcRow = srcYOffset + row;
|
|
1695
|
+
const o = (srcRow * w + srcCol) * 4;
|
|
1696
|
+
dst.set(data.subarray(o, o + rowLen), dstStart);
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1682
1700
|
// src/IndexedImage/IndexedImage.ts
|
|
1683
1701
|
var IndexedImage = class _IndexedImage {
|
|
1684
1702
|
/** The width of the image in pixels. */
|
|
@@ -2131,14 +2149,14 @@ function applyMaskToPixelData(dst, mask, opts) {
|
|
|
2131
2149
|
}
|
|
2132
2150
|
|
|
2133
2151
|
// src/PixelData/blendColorPixelData.ts
|
|
2134
|
-
function blendColorPixelData(dst, color, opts) {
|
|
2152
|
+
function blendColorPixelData(dst, color, opts = {}) {
|
|
2135
2153
|
const {
|
|
2136
2154
|
x: targetX = 0,
|
|
2137
2155
|
y: targetY = 0,
|
|
2138
2156
|
w: width = dst.width,
|
|
2139
2157
|
h: height = dst.height,
|
|
2140
2158
|
alpha: globalAlpha = 255,
|
|
2141
|
-
blendFn =
|
|
2159
|
+
blendFn = sourceOverFast,
|
|
2142
2160
|
mask,
|
|
2143
2161
|
maskType = 0 /* ALPHA */,
|
|
2144
2162
|
mw,
|
|
@@ -2147,6 +2165,9 @@ function blendColorPixelData(dst, color, opts) {
|
|
|
2147
2165
|
invertMask = false
|
|
2148
2166
|
} = opts;
|
|
2149
2167
|
if (globalAlpha === 0) return;
|
|
2168
|
+
const baseSrcAlpha = color >>> 24;
|
|
2169
|
+
const isOverwrite = blendFn.isOverwrite;
|
|
2170
|
+
if (baseSrcAlpha === 0 && !isOverwrite) return;
|
|
2150
2171
|
let x = targetX;
|
|
2151
2172
|
let y = targetY;
|
|
2152
2173
|
let w = width;
|
|
@@ -2172,15 +2193,8 @@ function blendColorPixelData(dst, color, opts) {
|
|
|
2172
2193
|
let mIdx = (my + dy) * mPitch + (mx + dx);
|
|
2173
2194
|
const dStride = dw - actualW;
|
|
2174
2195
|
const mStride = mPitch - actualW;
|
|
2175
|
-
const baseSrcColor = color;
|
|
2176
|
-
const baseSrcAlpha = baseSrcColor >>> 24;
|
|
2177
2196
|
for (let iy = 0; iy < actualH; iy++) {
|
|
2178
2197
|
for (let ix = 0; ix < actualW; ix++) {
|
|
2179
|
-
if (baseSrcAlpha === 0) {
|
|
2180
|
-
dIdx++;
|
|
2181
|
-
mIdx++;
|
|
2182
|
-
continue;
|
|
2183
|
-
}
|
|
2184
2198
|
let weight = globalAlpha;
|
|
2185
2199
|
if (mask) {
|
|
2186
2200
|
const mVal = mask[mIdx];
|
|
@@ -2213,20 +2227,20 @@ function blendColorPixelData(dst, color, opts) {
|
|
|
2213
2227
|
continue;
|
|
2214
2228
|
}
|
|
2215
2229
|
}
|
|
2216
|
-
let
|
|
2217
|
-
let currentSrcColor = baseSrcColor;
|
|
2230
|
+
let currentSrcColor = color;
|
|
2218
2231
|
if (weight < 255) {
|
|
2232
|
+
let currentSrcAlpha = baseSrcAlpha;
|
|
2219
2233
|
if (baseSrcAlpha === 255) {
|
|
2220
2234
|
currentSrcAlpha = weight;
|
|
2221
2235
|
} else {
|
|
2222
2236
|
currentSrcAlpha = baseSrcAlpha * weight + 128 >> 8;
|
|
2223
2237
|
}
|
|
2224
|
-
if (currentSrcAlpha === 0) {
|
|
2238
|
+
if (!isOverwrite && currentSrcAlpha === 0) {
|
|
2225
2239
|
dIdx++;
|
|
2226
2240
|
mIdx++;
|
|
2227
2241
|
continue;
|
|
2228
2242
|
}
|
|
2229
|
-
currentSrcColor = (
|
|
2243
|
+
currentSrcColor = (color & 16777215 | currentSrcAlpha << 24) >>> 0;
|
|
2230
2244
|
}
|
|
2231
2245
|
dst32[dIdx] = blendFn(currentSrcColor, dst32[dIdx]);
|
|
2232
2246
|
dIdx++;
|
|
@@ -2301,11 +2315,12 @@ function blendPixelData(dst, src, opts) {
|
|
|
2301
2315
|
const dStride = dw - actualW;
|
|
2302
2316
|
const sStride = sw - actualW;
|
|
2303
2317
|
const mStride = mPitch - actualW;
|
|
2318
|
+
const isOverwrite = blendFn.isOverwrite;
|
|
2304
2319
|
for (let iy = 0; iy < actualH; iy++) {
|
|
2305
2320
|
for (let ix = 0; ix < actualW; ix++) {
|
|
2306
2321
|
const baseSrcColor = src32[sIdx];
|
|
2307
2322
|
const baseSrcAlpha = baseSrcColor >>> 24;
|
|
2308
|
-
if (baseSrcAlpha === 0) {
|
|
2323
|
+
if (baseSrcAlpha === 0 && !isOverwrite) {
|
|
2309
2324
|
dIdx++;
|
|
2310
2325
|
sIdx++;
|
|
2311
2326
|
mIdx++;
|
|
@@ -2346,15 +2361,15 @@ function blendPixelData(dst, src, opts) {
|
|
|
2346
2361
|
continue;
|
|
2347
2362
|
}
|
|
2348
2363
|
}
|
|
2349
|
-
let currentSrcAlpha = baseSrcAlpha;
|
|
2350
2364
|
let currentSrcColor = baseSrcColor;
|
|
2351
2365
|
if (weight < 255) {
|
|
2366
|
+
let currentSrcAlpha = baseSrcAlpha;
|
|
2352
2367
|
if (baseSrcAlpha === 255) {
|
|
2353
2368
|
currentSrcAlpha = weight;
|
|
2354
2369
|
} else {
|
|
2355
2370
|
currentSrcAlpha = baseSrcAlpha * weight + 128 >> 8;
|
|
2356
2371
|
}
|
|
2357
|
-
if (currentSrcAlpha === 0) {
|
|
2372
|
+
if (!isOverwrite && currentSrcAlpha === 0) {
|
|
2358
2373
|
dIdx++;
|
|
2359
2374
|
sIdx++;
|
|
2360
2375
|
mIdx++;
|
|
@@ -2605,6 +2620,7 @@ export {
|
|
|
2605
2620
|
linearLightPerfect,
|
|
2606
2621
|
makePixelCanvas,
|
|
2607
2622
|
makeReusableCanvas,
|
|
2623
|
+
makeReusableImageData,
|
|
2608
2624
|
mergeMasks,
|
|
2609
2625
|
multiplyFast,
|
|
2610
2626
|
multiplyPerfect,
|