pixel-data-js 0.22.2 → 0.23.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 +431 -382
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +429 -382
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +431 -382
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +75 -49
- package/dist/index.prod.js +429 -382
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/History/PixelMutator/mutatorBlendPixelData.ts +1 -1
- package/src/History/PixelMutator/mutatorBlendPixelDataAlphaMask.ts +33 -0
- package/src/History/PixelMutator/mutatorBlendPixelDataBinaryMask.ts +33 -0
- package/src/History/PixelMutator/mutatorClear.ts +2 -2
- package/src/History/PixelMutator.ts +14 -11
- package/src/PixelData/blendPixelData.ts +1 -1
- package/src/PixelData/blendPixelDataBinaryMask.ts +1 -1
- package/src/index.ts +2 -0
package/dist/index.dev.cjs
CHANGED
|
@@ -150,6 +150,8 @@ __export(src_exports, {
|
|
|
150
150
|
mutatorBlendColor: () => mutatorBlendColor,
|
|
151
151
|
mutatorBlendPixel: () => mutatorBlendPixel,
|
|
152
152
|
mutatorBlendPixelData: () => mutatorBlendPixelData,
|
|
153
|
+
mutatorBlendPixelDataAlphaMask: () => mutatorBlendPixelDataAlphaMask,
|
|
154
|
+
mutatorBlendPixelDataBinaryMask: () => mutatorBlendPixelDataBinaryMask,
|
|
153
155
|
mutatorClear: () => mutatorClear,
|
|
154
156
|
mutatorFill: () => mutatorFill,
|
|
155
157
|
mutatorFillBinaryMask: () => mutatorFillBinaryMask,
|
|
@@ -2631,19 +2633,50 @@ var mutatorApplyCircleBrushStroke = ((writer, deps = defaults4) => {
|
|
|
2631
2633
|
};
|
|
2632
2634
|
});
|
|
2633
2635
|
|
|
2634
|
-
// src/History/PixelMutator/
|
|
2636
|
+
// src/History/PixelMutator/mutatorApplyCirclePencil.ts
|
|
2635
2637
|
var defaults5 = {
|
|
2638
|
+
applyCircleBrushToPixelData,
|
|
2639
|
+
getCircleBrushOrPencilBounds
|
|
2640
|
+
};
|
|
2641
|
+
var mutatorApplyCirclePencil = ((writer, deps = defaults5) => {
|
|
2642
|
+
const {
|
|
2643
|
+
applyCircleBrushToPixelData: applyCircleBrushToPixelData2 = defaults5.applyCircleBrushToPixelData,
|
|
2644
|
+
getCircleBrushOrPencilBounds: getCircleBrushOrPencilBounds2 = defaults5.getCircleBrushOrPencilBounds
|
|
2645
|
+
} = deps;
|
|
2646
|
+
const boundsOut = {
|
|
2647
|
+
x: 0,
|
|
2648
|
+
y: 0,
|
|
2649
|
+
w: 0,
|
|
2650
|
+
h: 0
|
|
2651
|
+
};
|
|
2652
|
+
return {
|
|
2653
|
+
applyCirclePencil(color, centerX, centerY, brush, alpha = 255, blendFn) {
|
|
2654
|
+
const bounds = getCircleBrushOrPencilBounds2(centerX, centerY, brush.size, writer.target.width, writer.target.height, boundsOut);
|
|
2655
|
+
const {
|
|
2656
|
+
x,
|
|
2657
|
+
y,
|
|
2658
|
+
w,
|
|
2659
|
+
h
|
|
2660
|
+
} = bounds;
|
|
2661
|
+
writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
2662
|
+
applyCircleBrushToPixelData2(writer.target, color, centerX, centerY, brush, alpha, blendFn, bounds);
|
|
2663
|
+
}
|
|
2664
|
+
};
|
|
2665
|
+
});
|
|
2666
|
+
|
|
2667
|
+
// src/History/PixelMutator/mutatorApplyCirclePencilStroke.ts
|
|
2668
|
+
var defaults6 = {
|
|
2636
2669
|
forEachLinePoint,
|
|
2637
2670
|
blendColorPixelDataBinaryMask,
|
|
2638
2671
|
getCircleBrushOrPencilBounds,
|
|
2639
2672
|
getCircleBrushOrPencilStrokeBounds
|
|
2640
2673
|
};
|
|
2641
|
-
var mutatorApplyCirclePencilStroke = ((writer, deps =
|
|
2674
|
+
var mutatorApplyCirclePencilStroke = ((writer, deps = defaults6) => {
|
|
2642
2675
|
const {
|
|
2643
|
-
forEachLinePoint: forEachLinePoint2 =
|
|
2644
|
-
blendColorPixelDataBinaryMask: blendColorPixelDataBinaryMask2 =
|
|
2645
|
-
getCircleBrushOrPencilStrokeBounds: getCircleBrushOrPencilStrokeBounds2 =
|
|
2646
|
-
getCircleBrushOrPencilBounds: getCircleBrushOrPencilBounds2 =
|
|
2676
|
+
forEachLinePoint: forEachLinePoint2 = defaults6.forEachLinePoint,
|
|
2677
|
+
blendColorPixelDataBinaryMask: blendColorPixelDataBinaryMask2 = defaults6.blendColorPixelDataBinaryMask,
|
|
2678
|
+
getCircleBrushOrPencilStrokeBounds: getCircleBrushOrPencilStrokeBounds2 = defaults6.getCircleBrushOrPencilStrokeBounds,
|
|
2679
|
+
getCircleBrushOrPencilBounds: getCircleBrushOrPencilBounds2 = defaults6.getCircleBrushOrPencilBounds
|
|
2647
2680
|
} = deps;
|
|
2648
2681
|
const strokeBoundsOut = {
|
|
2649
2682
|
x: 0,
|
|
@@ -2797,14 +2830,14 @@ function applyRectBrushToPixelData(target, color, centerX, centerY, brushWidth,
|
|
|
2797
2830
|
}
|
|
2798
2831
|
|
|
2799
2832
|
// src/History/PixelMutator/mutatorApplyRectBrush.ts
|
|
2800
|
-
var
|
|
2833
|
+
var defaults7 = {
|
|
2801
2834
|
applyRectBrushToPixelData,
|
|
2802
2835
|
getRectBrushOrPencilBounds
|
|
2803
2836
|
};
|
|
2804
|
-
var mutatorApplyRectBrush = ((writer, deps =
|
|
2837
|
+
var mutatorApplyRectBrush = ((writer, deps = defaults7) => {
|
|
2805
2838
|
const {
|
|
2806
|
-
applyRectBrushToPixelData: applyRectBrushToPixelData2 =
|
|
2807
|
-
getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 =
|
|
2839
|
+
applyRectBrushToPixelData: applyRectBrushToPixelData2 = defaults7.applyRectBrushToPixelData,
|
|
2840
|
+
getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults7.getRectBrushOrPencilBounds
|
|
2808
2841
|
} = deps;
|
|
2809
2842
|
const boundsOut = {
|
|
2810
2843
|
x: 0,
|
|
@@ -2843,18 +2876,18 @@ function getRectBrushOrPencilStrokeBounds(x0, y0, x1, y1, brushWidth, brushHeigh
|
|
|
2843
2876
|
}
|
|
2844
2877
|
|
|
2845
2878
|
// src/History/PixelMutator/mutatorApplyRectBrushStroke.ts
|
|
2846
|
-
var
|
|
2879
|
+
var defaults8 = {
|
|
2847
2880
|
forEachLinePoint,
|
|
2848
2881
|
blendColorPixelDataAlphaMask,
|
|
2849
2882
|
getRectBrushOrPencilBounds,
|
|
2850
2883
|
getRectBrushOrPencilStrokeBounds
|
|
2851
2884
|
};
|
|
2852
|
-
var mutatorApplyRectBrushStroke = ((writer, deps =
|
|
2885
|
+
var mutatorApplyRectBrushStroke = ((writer, deps = defaults8) => {
|
|
2853
2886
|
const {
|
|
2854
|
-
forEachLinePoint: forEachLinePoint2 =
|
|
2855
|
-
blendColorPixelDataAlphaMask: blendColorPixelDataAlphaMask2 =
|
|
2856
|
-
getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 =
|
|
2857
|
-
getRectBrushOrPencilStrokeBounds: getRectBrushOrPencilStrokeBounds2 =
|
|
2887
|
+
forEachLinePoint: forEachLinePoint2 = defaults8.forEachLinePoint,
|
|
2888
|
+
blendColorPixelDataAlphaMask: blendColorPixelDataAlphaMask2 = defaults8.blendColorPixelDataAlphaMask,
|
|
2889
|
+
getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults8.getRectBrushOrPencilBounds,
|
|
2890
|
+
getRectBrushOrPencilStrokeBounds: getRectBrushOrPencilStrokeBounds2 = defaults8.getRectBrushOrPencilStrokeBounds
|
|
2858
2891
|
} = deps;
|
|
2859
2892
|
const strokeBoundsOut = {
|
|
2860
2893
|
x: 0,
|
|
@@ -2946,16 +2979,16 @@ var mutatorApplyRectBrushStroke = ((writer, deps = defaults7) => {
|
|
|
2946
2979
|
});
|
|
2947
2980
|
|
|
2948
2981
|
// src/History/PixelMutator/mutatorApplyRectPencil.ts
|
|
2949
|
-
var
|
|
2982
|
+
var defaults9 = {
|
|
2950
2983
|
applyRectBrushToPixelData,
|
|
2951
2984
|
getRectBrushOrPencilBounds,
|
|
2952
2985
|
fallOff: () => 1
|
|
2953
2986
|
};
|
|
2954
|
-
var mutatorApplyRectPencil = ((writer, deps =
|
|
2987
|
+
var mutatorApplyRectPencil = ((writer, deps = defaults9) => {
|
|
2955
2988
|
const {
|
|
2956
|
-
applyRectBrushToPixelData: applyRectBrushToPixelData2 =
|
|
2957
|
-
getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 =
|
|
2958
|
-
fallOff =
|
|
2989
|
+
applyRectBrushToPixelData: applyRectBrushToPixelData2 = defaults9.applyRectBrushToPixelData,
|
|
2990
|
+
getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults9.getRectBrushOrPencilBounds,
|
|
2991
|
+
fallOff = defaults9.fallOff
|
|
2959
2992
|
} = deps;
|
|
2960
2993
|
const boundsOut = {
|
|
2961
2994
|
x: 0,
|
|
@@ -2979,18 +3012,18 @@ var mutatorApplyRectPencil = ((writer, deps = defaults8) => {
|
|
|
2979
3012
|
});
|
|
2980
3013
|
|
|
2981
3014
|
// src/History/PixelMutator/mutatorApplyRectPencilStroke.ts
|
|
2982
|
-
var
|
|
3015
|
+
var defaults10 = {
|
|
2983
3016
|
forEachLinePoint,
|
|
2984
3017
|
getRectBrushOrPencilBounds,
|
|
2985
3018
|
getRectBrushOrPencilStrokeBounds,
|
|
2986
3019
|
blendColorPixelDataBinaryMask
|
|
2987
3020
|
};
|
|
2988
|
-
var mutatorApplyRectPencilStroke = ((writer, deps =
|
|
3021
|
+
var mutatorApplyRectPencilStroke = ((writer, deps = defaults10) => {
|
|
2989
3022
|
const {
|
|
2990
|
-
forEachLinePoint: forEachLinePoint2 =
|
|
2991
|
-
blendColorPixelDataBinaryMask: blendColorPixelDataBinaryMask2 =
|
|
2992
|
-
getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 =
|
|
2993
|
-
getRectBrushOrPencilStrokeBounds: getRectBrushOrPencilStrokeBounds2 =
|
|
3023
|
+
forEachLinePoint: forEachLinePoint2 = defaults10.forEachLinePoint,
|
|
3024
|
+
blendColorPixelDataBinaryMask: blendColorPixelDataBinaryMask2 = defaults10.blendColorPixelDataBinaryMask,
|
|
3025
|
+
getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults10.getRectBrushOrPencilBounds,
|
|
3026
|
+
getRectBrushOrPencilStrokeBounds: getRectBrushOrPencilStrokeBounds2 = defaults10.getRectBrushOrPencilStrokeBounds
|
|
2994
3027
|
} = deps;
|
|
2995
3028
|
const strokeBoundsOut = {
|
|
2996
3029
|
x: 0,
|
|
@@ -3119,12 +3152,12 @@ function blendColorPixelData(dst, color, opts = {}) {
|
|
|
3119
3152
|
}
|
|
3120
3153
|
|
|
3121
3154
|
// src/History/PixelMutator/mutatorBlendColor.ts
|
|
3122
|
-
var
|
|
3155
|
+
var defaults11 = {
|
|
3123
3156
|
blendColorPixelData
|
|
3124
3157
|
};
|
|
3125
|
-
var mutatorBlendColor = ((writer, deps =
|
|
3158
|
+
var mutatorBlendColor = ((writer, deps = defaults11) => {
|
|
3126
3159
|
const {
|
|
3127
|
-
blendColorPixelData: blendColorPixelData2 =
|
|
3160
|
+
blendColorPixelData: blendColorPixelData2 = defaults11.blendColorPixelData
|
|
3128
3161
|
} = deps;
|
|
3129
3162
|
return {
|
|
3130
3163
|
blendColor(color, opts = {}) {
|
|
@@ -3163,7 +3196,7 @@ function mutatorBlendPixel(writer) {
|
|
|
3163
3196
|
}
|
|
3164
3197
|
|
|
3165
3198
|
// src/PixelData/blendPixelData.ts
|
|
3166
|
-
function blendPixelData(dst, src, opts) {
|
|
3199
|
+
function blendPixelData(dst, src, opts = {}) {
|
|
3167
3200
|
const {
|
|
3168
3201
|
x: targetX = 0,
|
|
3169
3202
|
y: targetY = 0,
|
|
@@ -3245,15 +3278,15 @@ function blendPixelData(dst, src, opts) {
|
|
|
3245
3278
|
}
|
|
3246
3279
|
|
|
3247
3280
|
// src/History/PixelMutator/mutatorBlendPixelData.ts
|
|
3248
|
-
var
|
|
3281
|
+
var defaults12 = {
|
|
3249
3282
|
blendPixelData
|
|
3250
3283
|
};
|
|
3251
|
-
var mutatorBlendPixelData = ((writer, deps =
|
|
3284
|
+
var mutatorBlendPixelData = ((writer, deps = defaults12) => {
|
|
3252
3285
|
const {
|
|
3253
|
-
blendPixelData: blendPixelData2 =
|
|
3286
|
+
blendPixelData: blendPixelData2 = defaults12.blendPixelData
|
|
3254
3287
|
} = deps;
|
|
3255
3288
|
return {
|
|
3256
|
-
blendPixelData(src, opts) {
|
|
3289
|
+
blendPixelData(src, opts = {}) {
|
|
3257
3290
|
const {
|
|
3258
3291
|
x = 0,
|
|
3259
3292
|
y = 0,
|
|
@@ -3266,6 +3299,263 @@ var mutatorBlendPixelData = ((writer, deps = defaults11) => {
|
|
|
3266
3299
|
};
|
|
3267
3300
|
});
|
|
3268
3301
|
|
|
3302
|
+
// src/PixelData/blendPixelDataAlphaMask.ts
|
|
3303
|
+
function blendPixelDataAlphaMask(dst, src, alphaMask, opts = {}) {
|
|
3304
|
+
const {
|
|
3305
|
+
x: targetX = 0,
|
|
3306
|
+
y: targetY = 0,
|
|
3307
|
+
sx: sourceX = 0,
|
|
3308
|
+
sy: sourceY = 0,
|
|
3309
|
+
w: width = src.width,
|
|
3310
|
+
h: height = src.height,
|
|
3311
|
+
alpha: globalAlpha = 255,
|
|
3312
|
+
blendFn = sourceOverPerfect,
|
|
3313
|
+
mx = 0,
|
|
3314
|
+
my = 0,
|
|
3315
|
+
invertMask = false
|
|
3316
|
+
} = opts;
|
|
3317
|
+
if (globalAlpha === 0) return;
|
|
3318
|
+
let x = targetX;
|
|
3319
|
+
let y = targetY;
|
|
3320
|
+
let sx = sourceX;
|
|
3321
|
+
let sy = sourceY;
|
|
3322
|
+
let w = width;
|
|
3323
|
+
let h = height;
|
|
3324
|
+
if (sx < 0) {
|
|
3325
|
+
x -= sx;
|
|
3326
|
+
w += sx;
|
|
3327
|
+
sx = 0;
|
|
3328
|
+
}
|
|
3329
|
+
if (sy < 0) {
|
|
3330
|
+
y -= sy;
|
|
3331
|
+
h += sy;
|
|
3332
|
+
sy = 0;
|
|
3333
|
+
}
|
|
3334
|
+
w = Math.min(w, src.width - sx);
|
|
3335
|
+
h = Math.min(h, src.height - sy);
|
|
3336
|
+
if (x < 0) {
|
|
3337
|
+
sx -= x;
|
|
3338
|
+
w += x;
|
|
3339
|
+
x = 0;
|
|
3340
|
+
}
|
|
3341
|
+
if (y < 0) {
|
|
3342
|
+
sy -= y;
|
|
3343
|
+
h += y;
|
|
3344
|
+
y = 0;
|
|
3345
|
+
}
|
|
3346
|
+
const actualW = Math.min(w, dst.width - x);
|
|
3347
|
+
const actualH = Math.min(h, dst.height - y);
|
|
3348
|
+
if (actualW <= 0 || actualH <= 0) return;
|
|
3349
|
+
const dw = dst.width;
|
|
3350
|
+
const sw = src.width;
|
|
3351
|
+
const mPitch = alphaMask.w;
|
|
3352
|
+
const maskData = alphaMask.data;
|
|
3353
|
+
const dx = x - targetX | 0;
|
|
3354
|
+
const dy = y - targetY | 0;
|
|
3355
|
+
const dst32 = dst.data32;
|
|
3356
|
+
const src32 = src.data32;
|
|
3357
|
+
let dIdx = y * dw + x | 0;
|
|
3358
|
+
let sIdx = sy * sw + sx | 0;
|
|
3359
|
+
let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
|
|
3360
|
+
const dStride = dw - actualW | 0;
|
|
3361
|
+
const sStride = sw - actualW | 0;
|
|
3362
|
+
const mStride = mPitch - actualW | 0;
|
|
3363
|
+
const isOpaque = globalAlpha === 255;
|
|
3364
|
+
const isOverwrite = blendFn.isOverwrite || false;
|
|
3365
|
+
for (let iy = 0; iy < actualH; iy++) {
|
|
3366
|
+
for (let ix = 0; ix < actualW; ix++) {
|
|
3367
|
+
const mVal = maskData[mIdx];
|
|
3368
|
+
const effM = invertMask ? 255 - mVal : mVal;
|
|
3369
|
+
if (effM === 0) {
|
|
3370
|
+
dIdx++;
|
|
3371
|
+
sIdx++;
|
|
3372
|
+
mIdx++;
|
|
3373
|
+
continue;
|
|
3374
|
+
}
|
|
3375
|
+
const srcCol = src32[sIdx];
|
|
3376
|
+
const srcAlpha = srcCol >>> 24;
|
|
3377
|
+
if (srcAlpha === 0 && !isOverwrite) {
|
|
3378
|
+
dIdx++;
|
|
3379
|
+
sIdx++;
|
|
3380
|
+
mIdx++;
|
|
3381
|
+
continue;
|
|
3382
|
+
}
|
|
3383
|
+
let weight = globalAlpha;
|
|
3384
|
+
if (isOpaque) {
|
|
3385
|
+
weight = effM;
|
|
3386
|
+
} else if (effM !== 255) {
|
|
3387
|
+
weight = effM * globalAlpha + 128 >> 8;
|
|
3388
|
+
}
|
|
3389
|
+
if (weight === 0) {
|
|
3390
|
+
dIdx++;
|
|
3391
|
+
sIdx++;
|
|
3392
|
+
mIdx++;
|
|
3393
|
+
continue;
|
|
3394
|
+
}
|
|
3395
|
+
let finalCol = srcCol;
|
|
3396
|
+
if (weight < 255) {
|
|
3397
|
+
const a = srcAlpha * weight + 128 >> 8;
|
|
3398
|
+
if (a === 0 && !isOverwrite) {
|
|
3399
|
+
dIdx++;
|
|
3400
|
+
sIdx++;
|
|
3401
|
+
mIdx++;
|
|
3402
|
+
continue;
|
|
3403
|
+
}
|
|
3404
|
+
finalCol = (srcCol & 16777215 | a << 24) >>> 0;
|
|
3405
|
+
}
|
|
3406
|
+
dst32[dIdx] = blendFn(finalCol, dst32[dIdx]);
|
|
3407
|
+
dIdx++;
|
|
3408
|
+
sIdx++;
|
|
3409
|
+
mIdx++;
|
|
3410
|
+
}
|
|
3411
|
+
dIdx += dStride;
|
|
3412
|
+
sIdx += sStride;
|
|
3413
|
+
mIdx += mStride;
|
|
3414
|
+
}
|
|
3415
|
+
}
|
|
3416
|
+
|
|
3417
|
+
// src/History/PixelMutator/mutatorBlendPixelDataAlphaMask.ts
|
|
3418
|
+
var defaults13 = {
|
|
3419
|
+
blendPixelDataAlphaMask
|
|
3420
|
+
};
|
|
3421
|
+
var mutatorBlendPixelDataAlphaMask = ((writer, deps = defaults13) => {
|
|
3422
|
+
const {
|
|
3423
|
+
blendPixelDataAlphaMask: blendPixelDataAlphaMask2 = defaults13.blendPixelDataAlphaMask
|
|
3424
|
+
} = deps;
|
|
3425
|
+
return {
|
|
3426
|
+
blendPixelDataAlphaMask(src, mask, opts = {}) {
|
|
3427
|
+
const x = opts.x ?? 0;
|
|
3428
|
+
const y = opts.y ?? 0;
|
|
3429
|
+
const w = opts.w ?? src.width;
|
|
3430
|
+
const h = opts.h ?? src.height;
|
|
3431
|
+
writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
3432
|
+
blendPixelDataAlphaMask2(writer.target, src, mask, opts);
|
|
3433
|
+
}
|
|
3434
|
+
};
|
|
3435
|
+
});
|
|
3436
|
+
|
|
3437
|
+
// src/PixelData/blendPixelDataBinaryMask.ts
|
|
3438
|
+
function blendPixelDataBinaryMask(dst, src, binaryMask, opts = {}) {
|
|
3439
|
+
const {
|
|
3440
|
+
x: targetX = 0,
|
|
3441
|
+
y: targetY = 0,
|
|
3442
|
+
sx: sourceX = 0,
|
|
3443
|
+
sy: sourceY = 0,
|
|
3444
|
+
w: width = src.width,
|
|
3445
|
+
h: height = src.height,
|
|
3446
|
+
alpha: globalAlpha = 255,
|
|
3447
|
+
blendFn = sourceOverPerfect,
|
|
3448
|
+
mx = 0,
|
|
3449
|
+
my = 0,
|
|
3450
|
+
invertMask = false
|
|
3451
|
+
} = opts;
|
|
3452
|
+
if (globalAlpha === 0) return;
|
|
3453
|
+
let x = targetX;
|
|
3454
|
+
let y = targetY;
|
|
3455
|
+
let sx = sourceX;
|
|
3456
|
+
let sy = sourceY;
|
|
3457
|
+
let w = width;
|
|
3458
|
+
let h = height;
|
|
3459
|
+
if (sx < 0) {
|
|
3460
|
+
x -= sx;
|
|
3461
|
+
w += sx;
|
|
3462
|
+
sx = 0;
|
|
3463
|
+
}
|
|
3464
|
+
if (sy < 0) {
|
|
3465
|
+
y -= sy;
|
|
3466
|
+
h += sy;
|
|
3467
|
+
sy = 0;
|
|
3468
|
+
}
|
|
3469
|
+
w = Math.min(w, src.width - sx);
|
|
3470
|
+
h = Math.min(h, src.height - sy);
|
|
3471
|
+
if (x < 0) {
|
|
3472
|
+
sx -= x;
|
|
3473
|
+
w += x;
|
|
3474
|
+
x = 0;
|
|
3475
|
+
}
|
|
3476
|
+
if (y < 0) {
|
|
3477
|
+
sy -= y;
|
|
3478
|
+
h += y;
|
|
3479
|
+
y = 0;
|
|
3480
|
+
}
|
|
3481
|
+
const actualW = Math.min(w, dst.width - x);
|
|
3482
|
+
const actualH = Math.min(h, dst.height - y);
|
|
3483
|
+
if (actualW <= 0 || actualH <= 0) return;
|
|
3484
|
+
const dx = x - targetX | 0;
|
|
3485
|
+
const dy = y - targetY | 0;
|
|
3486
|
+
const dst32 = dst.data32;
|
|
3487
|
+
const src32 = src.data32;
|
|
3488
|
+
const dw = dst.width;
|
|
3489
|
+
const sw = src.width;
|
|
3490
|
+
const mPitch = binaryMask.w;
|
|
3491
|
+
const maskData = binaryMask.data;
|
|
3492
|
+
let dIdx = y * dw + x | 0;
|
|
3493
|
+
let sIdx = sy * sw + sx | 0;
|
|
3494
|
+
let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
|
|
3495
|
+
const dStride = dw - actualW | 0;
|
|
3496
|
+
const sStride = sw - actualW | 0;
|
|
3497
|
+
const mStride = mPitch - actualW | 0;
|
|
3498
|
+
const skipVal = invertMask ? 1 : 0;
|
|
3499
|
+
const isOpaque = globalAlpha === 255;
|
|
3500
|
+
const isOverwrite = blendFn.isOverwrite || false;
|
|
3501
|
+
for (let iy = 0; iy < actualH; iy++) {
|
|
3502
|
+
for (let ix = 0; ix < actualW; ix++) {
|
|
3503
|
+
if (maskData[mIdx] === skipVal) {
|
|
3504
|
+
dIdx++;
|
|
3505
|
+
sIdx++;
|
|
3506
|
+
mIdx++;
|
|
3507
|
+
continue;
|
|
3508
|
+
}
|
|
3509
|
+
const srcCol = src32[sIdx];
|
|
3510
|
+
const srcAlpha = srcCol >>> 24;
|
|
3511
|
+
if (srcAlpha === 0 && !isOverwrite) {
|
|
3512
|
+
dIdx++;
|
|
3513
|
+
sIdx++;
|
|
3514
|
+
mIdx++;
|
|
3515
|
+
continue;
|
|
3516
|
+
}
|
|
3517
|
+
let finalCol = srcCol;
|
|
3518
|
+
if (!isOpaque) {
|
|
3519
|
+
const a = srcAlpha * globalAlpha + 128 >> 8;
|
|
3520
|
+
if (a === 0 && !isOverwrite) {
|
|
3521
|
+
dIdx++;
|
|
3522
|
+
sIdx++;
|
|
3523
|
+
mIdx++;
|
|
3524
|
+
continue;
|
|
3525
|
+
}
|
|
3526
|
+
finalCol = (srcCol & 16777215 | a << 24) >>> 0;
|
|
3527
|
+
}
|
|
3528
|
+
dst32[dIdx] = blendFn(finalCol, dst32[dIdx]);
|
|
3529
|
+
dIdx++;
|
|
3530
|
+
sIdx++;
|
|
3531
|
+
mIdx++;
|
|
3532
|
+
}
|
|
3533
|
+
dIdx += dStride;
|
|
3534
|
+
sIdx += sStride;
|
|
3535
|
+
mIdx += mStride;
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
|
|
3539
|
+
// src/History/PixelMutator/mutatorBlendPixelDataBinaryMask.ts
|
|
3540
|
+
var defaults14 = {
|
|
3541
|
+
blendPixelDataBinaryMask
|
|
3542
|
+
};
|
|
3543
|
+
var mutatorBlendPixelDataBinaryMask = ((writer, deps = defaults14) => {
|
|
3544
|
+
const {
|
|
3545
|
+
blendPixelDataBinaryMask: blendPixelDataBinaryMask2 = defaults14.blendPixelDataBinaryMask
|
|
3546
|
+
} = deps;
|
|
3547
|
+
return {
|
|
3548
|
+
blendPixelDataBinaryMask(src, mask, opts = {}) {
|
|
3549
|
+
const x = opts.x ?? 0;
|
|
3550
|
+
const y = opts.y ?? 0;
|
|
3551
|
+
const w = opts.w ?? src.width;
|
|
3552
|
+
const h = opts.h ?? src.height;
|
|
3553
|
+
writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
3554
|
+
blendPixelDataBinaryMask2(writer.target, src, mask, opts);
|
|
3555
|
+
}
|
|
3556
|
+
};
|
|
3557
|
+
});
|
|
3558
|
+
|
|
3269
3559
|
// src/PixelData/fillPixelData.ts
|
|
3270
3560
|
var SCRATCH_RECT = makeClippedRect();
|
|
3271
3561
|
function fillPixelData(dst, color, _x, _y, _w, _h) {
|
|
@@ -3311,12 +3601,12 @@ function fillPixelData(dst, color, _x, _y, _w, _h) {
|
|
|
3311
3601
|
}
|
|
3312
3602
|
|
|
3313
3603
|
// src/History/PixelMutator/mutatorClear.ts
|
|
3314
|
-
var
|
|
3604
|
+
var defaults15 = {
|
|
3315
3605
|
fillPixelData
|
|
3316
3606
|
};
|
|
3317
|
-
var mutatorClear = ((writer, deps =
|
|
3607
|
+
var mutatorClear = ((writer, deps = defaults15) => {
|
|
3318
3608
|
const {
|
|
3319
|
-
fillPixelData: fillPixelData2 =
|
|
3609
|
+
fillPixelData: fillPixelData2 = defaults15.fillPixelData
|
|
3320
3610
|
} = deps;
|
|
3321
3611
|
return {
|
|
3322
3612
|
clear(rect = {}) {
|
|
@@ -3331,12 +3621,12 @@ var mutatorClear = ((writer, deps = defaults12) => {
|
|
|
3331
3621
|
});
|
|
3332
3622
|
|
|
3333
3623
|
// src/History/PixelMutator/mutatorFill.ts
|
|
3334
|
-
var
|
|
3624
|
+
var defaults16 = {
|
|
3335
3625
|
fillPixelData
|
|
3336
3626
|
};
|
|
3337
|
-
var mutatorFill = ((writer, deps =
|
|
3627
|
+
var mutatorFill = ((writer, deps = defaults16) => {
|
|
3338
3628
|
const {
|
|
3339
|
-
fillPixelData: fillPixelData2 =
|
|
3629
|
+
fillPixelData: fillPixelData2 = defaults16.fillPixelData
|
|
3340
3630
|
} = deps;
|
|
3341
3631
|
return {
|
|
3342
3632
|
fill(color, rect = {}) {
|
|
@@ -3352,8 +3642,64 @@ var mutatorFill = ((writer, deps = defaults13) => {
|
|
|
3352
3642
|
};
|
|
3353
3643
|
});
|
|
3354
3644
|
|
|
3355
|
-
// src/PixelData/
|
|
3645
|
+
// src/PixelData/fillPixelDataBinaryMask.ts
|
|
3356
3646
|
var SCRATCH_RECT2 = makeClippedRect();
|
|
3647
|
+
function fillPixelDataBinaryMask(dst, color, mask, alpha = 255, x = 0, y = 0) {
|
|
3648
|
+
if (alpha === 0) return;
|
|
3649
|
+
const maskW = mask.w;
|
|
3650
|
+
const maskH = mask.h;
|
|
3651
|
+
const clip = resolveRectClipping(x, y, maskW, maskH, dst.width, dst.height, SCRATCH_RECT2);
|
|
3652
|
+
if (!clip.inBounds) return;
|
|
3653
|
+
const {
|
|
3654
|
+
x: finalX,
|
|
3655
|
+
y: finalY,
|
|
3656
|
+
w: actualW,
|
|
3657
|
+
h: actualH
|
|
3658
|
+
} = clip;
|
|
3659
|
+
const maskData = mask.data;
|
|
3660
|
+
const dst32 = dst.data32;
|
|
3661
|
+
const dw = dst.width;
|
|
3662
|
+
let finalCol = color;
|
|
3663
|
+
if (alpha < 255) {
|
|
3664
|
+
const baseSrcAlpha = color >>> 24;
|
|
3665
|
+
const colorRGB = color & 16777215;
|
|
3666
|
+
const a = baseSrcAlpha * alpha + 128 >> 8;
|
|
3667
|
+
finalCol = (colorRGB | a << 24) >>> 0;
|
|
3668
|
+
}
|
|
3669
|
+
for (let iy = 0; iy < actualH; iy++) {
|
|
3670
|
+
const currentY = finalY + iy;
|
|
3671
|
+
const maskY = currentY - y;
|
|
3672
|
+
const maskOffset = maskY * maskW;
|
|
3673
|
+
const dstRowOffset = currentY * dw;
|
|
3674
|
+
for (let ix = 0; ix < actualW; ix++) {
|
|
3675
|
+
const currentX = finalX + ix;
|
|
3676
|
+
const maskX = currentX - x;
|
|
3677
|
+
const maskIndex = maskOffset + maskX;
|
|
3678
|
+
if (maskData[maskIndex]) {
|
|
3679
|
+
dst32[dstRowOffset + currentX] = finalCol;
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3684
|
+
|
|
3685
|
+
// src/History/PixelMutator/mutatorFillBinaryMask.ts
|
|
3686
|
+
var defaults17 = {
|
|
3687
|
+
fillPixelDataBinaryMask
|
|
3688
|
+
};
|
|
3689
|
+
var mutatorFillBinaryMask = ((writer, deps = defaults17) => {
|
|
3690
|
+
const {
|
|
3691
|
+
fillPixelDataBinaryMask: fillPixelDataBinaryMask2 = defaults17.fillPixelDataBinaryMask
|
|
3692
|
+
} = deps;
|
|
3693
|
+
return {
|
|
3694
|
+
fillBinaryMask(color, mask, alpha = 255, x = 0, y = 0) {
|
|
3695
|
+
writer.accumulator.storeRegionBeforeState(x, y, mask.w, mask.h);
|
|
3696
|
+
fillPixelDataBinaryMask2(writer.target, color, mask, alpha, x, y);
|
|
3697
|
+
}
|
|
3698
|
+
};
|
|
3699
|
+
});
|
|
3700
|
+
|
|
3701
|
+
// src/PixelData/invertPixelData.ts
|
|
3702
|
+
var SCRATCH_RECT3 = makeClippedRect();
|
|
3357
3703
|
function invertPixelData(pixelData, opts = {}) {
|
|
3358
3704
|
const dst = pixelData;
|
|
3359
3705
|
const {
|
|
@@ -3366,7 +3712,7 @@ function invertPixelData(pixelData, opts = {}) {
|
|
|
3366
3712
|
my = 0,
|
|
3367
3713
|
invertMask = false
|
|
3368
3714
|
} = opts;
|
|
3369
|
-
const clip = resolveRectClipping(targetX, targetY, width, height, dst.width, dst.height,
|
|
3715
|
+
const clip = resolveRectClipping(targetX, targetY, width, height, dst.width, dst.height, SCRATCH_RECT3);
|
|
3370
3716
|
if (!clip.inBounds) return;
|
|
3371
3717
|
const {
|
|
3372
3718
|
x,
|
|
@@ -3410,12 +3756,12 @@ function invertPixelData(pixelData, opts = {}) {
|
|
|
3410
3756
|
}
|
|
3411
3757
|
|
|
3412
3758
|
// src/History/PixelMutator/mutatorInvert.ts
|
|
3413
|
-
var
|
|
3759
|
+
var defaults18 = {
|
|
3414
3760
|
invertPixelData
|
|
3415
3761
|
};
|
|
3416
|
-
var mutatorInvert = ((writer, deps =
|
|
3762
|
+
var mutatorInvert = ((writer, deps = defaults18) => {
|
|
3417
3763
|
const {
|
|
3418
|
-
invertPixelData: invertPixelData2 =
|
|
3764
|
+
invertPixelData: invertPixelData2 = defaults18.invertPixelData
|
|
3419
3765
|
} = deps;
|
|
3420
3766
|
return {
|
|
3421
3767
|
invert(opts = {}) {
|
|
@@ -3434,21 +3780,26 @@ var mutatorInvert = ((writer, deps = defaults14) => {
|
|
|
3434
3780
|
// src/History/PixelMutator.ts
|
|
3435
3781
|
function makeFullPixelMutator(writer) {
|
|
3436
3782
|
return {
|
|
3783
|
+
// @sort
|
|
3437
3784
|
...mutatorApplyAlphaMask(writer),
|
|
3438
3785
|
...mutatorApplyBinaryMask(writer),
|
|
3439
|
-
...mutatorBlendPixelData(writer),
|
|
3440
|
-
...mutatorBlendColor(writer),
|
|
3441
|
-
...mutatorBlendPixel(writer),
|
|
3442
|
-
...mutatorFill(writer),
|
|
3443
|
-
...mutatorInvert(writer),
|
|
3444
3786
|
...mutatorApplyCircleBrush(writer),
|
|
3445
3787
|
...mutatorApplyCircleBrushStroke(writer),
|
|
3788
|
+
...mutatorApplyCirclePencil(writer),
|
|
3446
3789
|
...mutatorApplyCirclePencilStroke(writer),
|
|
3447
3790
|
...mutatorApplyRectBrush(writer),
|
|
3448
3791
|
...mutatorApplyRectBrushStroke(writer),
|
|
3449
3792
|
...mutatorApplyRectPencil(writer),
|
|
3450
3793
|
...mutatorApplyRectPencilStroke(writer),
|
|
3451
|
-
...
|
|
3794
|
+
...mutatorBlendColor(writer),
|
|
3795
|
+
...mutatorBlendPixel(writer),
|
|
3796
|
+
...mutatorBlendPixelData(writer),
|
|
3797
|
+
...mutatorBlendPixelDataAlphaMask(writer),
|
|
3798
|
+
...mutatorBlendPixelDataBinaryMask(writer),
|
|
3799
|
+
...mutatorClear(writer),
|
|
3800
|
+
...mutatorFill(writer),
|
|
3801
|
+
...mutatorFillBinaryMask(writer),
|
|
3802
|
+
...mutatorInvert(writer)
|
|
3452
3803
|
};
|
|
3453
3804
|
}
|
|
3454
3805
|
|
|
@@ -3466,121 +3817,34 @@ var PixelWriter = class {
|
|
|
3466
3817
|
} = {}) {
|
|
3467
3818
|
this.target = target;
|
|
3468
3819
|
this.config = new PixelEngineConfig(tileSize);
|
|
3469
|
-
this.historyManager = historyManager;
|
|
3470
|
-
this.accumulator = new PixelAccumulator(target, this.config);
|
|
3471
|
-
this.mutator = mutatorFactory(this);
|
|
3472
|
-
}
|
|
3473
|
-
withHistory(cb) {
|
|
3474
|
-
cb(this.mutator);
|
|
3475
|
-
this.captureHistory();
|
|
3476
|
-
}
|
|
3477
|
-
captureHistory() {
|
|
3478
|
-
const beforeTiles = this.accumulator.beforeTiles;
|
|
3479
|
-
if (beforeTiles.length === 0) return;
|
|
3480
|
-
const afterTiles = this.accumulator.extractAfterTiles();
|
|
3481
|
-
const patch = {
|
|
3482
|
-
beforeTiles,
|
|
3483
|
-
afterTiles
|
|
3484
|
-
};
|
|
3485
|
-
const target = this.target;
|
|
3486
|
-
const tileSize = this.config.tileSize;
|
|
3487
|
-
const accumulator = this.accumulator;
|
|
3488
|
-
const action = {
|
|
3489
|
-
undo: () => applyPatchTiles(target, patch.beforeTiles, tileSize),
|
|
3490
|
-
redo: () => applyPatchTiles(target, patch.afterTiles, tileSize),
|
|
3491
|
-
dispose: () => accumulator.recyclePatch(patch)
|
|
3492
|
-
};
|
|
3493
|
-
this.historyManager.commit(action);
|
|
3494
|
-
this.accumulator.reset();
|
|
3495
|
-
}
|
|
3496
|
-
};
|
|
3497
|
-
|
|
3498
|
-
// src/History/PixelMutator/mutatorApplyCirclePencil.ts
|
|
3499
|
-
var defaults15 = {
|
|
3500
|
-
applyCircleBrushToPixelData,
|
|
3501
|
-
getCircleBrushOrPencilBounds
|
|
3502
|
-
};
|
|
3503
|
-
var mutatorApplyCirclePencil = ((writer, deps = defaults15) => {
|
|
3504
|
-
const {
|
|
3505
|
-
applyCircleBrushToPixelData: applyCircleBrushToPixelData2 = defaults15.applyCircleBrushToPixelData,
|
|
3506
|
-
getCircleBrushOrPencilBounds: getCircleBrushOrPencilBounds2 = defaults15.getCircleBrushOrPencilBounds
|
|
3507
|
-
} = deps;
|
|
3508
|
-
const boundsOut = {
|
|
3509
|
-
x: 0,
|
|
3510
|
-
y: 0,
|
|
3511
|
-
w: 0,
|
|
3512
|
-
h: 0
|
|
3513
|
-
};
|
|
3514
|
-
return {
|
|
3515
|
-
applyCirclePencil(color, centerX, centerY, brush, alpha = 255, blendFn) {
|
|
3516
|
-
const bounds = getCircleBrushOrPencilBounds2(centerX, centerY, brush.size, writer.target.width, writer.target.height, boundsOut);
|
|
3517
|
-
const {
|
|
3518
|
-
x,
|
|
3519
|
-
y,
|
|
3520
|
-
w,
|
|
3521
|
-
h
|
|
3522
|
-
} = bounds;
|
|
3523
|
-
writer.accumulator.storeRegionBeforeState(x, y, w, h);
|
|
3524
|
-
applyCircleBrushToPixelData2(writer.target, color, centerX, centerY, brush, alpha, blendFn, bounds);
|
|
3525
|
-
}
|
|
3526
|
-
};
|
|
3527
|
-
});
|
|
3528
|
-
|
|
3529
|
-
// src/PixelData/fillPixelDataBinaryMask.ts
|
|
3530
|
-
var SCRATCH_RECT3 = makeClippedRect();
|
|
3531
|
-
function fillPixelDataBinaryMask(dst, color, mask, alpha = 255, x = 0, y = 0) {
|
|
3532
|
-
if (alpha === 0) return;
|
|
3533
|
-
const maskW = mask.w;
|
|
3534
|
-
const maskH = mask.h;
|
|
3535
|
-
const clip = resolveRectClipping(x, y, maskW, maskH, dst.width, dst.height, SCRATCH_RECT3);
|
|
3536
|
-
if (!clip.inBounds) return;
|
|
3537
|
-
const {
|
|
3538
|
-
x: finalX,
|
|
3539
|
-
y: finalY,
|
|
3540
|
-
w: actualW,
|
|
3541
|
-
h: actualH
|
|
3542
|
-
} = clip;
|
|
3543
|
-
const maskData = mask.data;
|
|
3544
|
-
const dst32 = dst.data32;
|
|
3545
|
-
const dw = dst.width;
|
|
3546
|
-
let finalCol = color;
|
|
3547
|
-
if (alpha < 255) {
|
|
3548
|
-
const baseSrcAlpha = color >>> 24;
|
|
3549
|
-
const colorRGB = color & 16777215;
|
|
3550
|
-
const a = baseSrcAlpha * alpha + 128 >> 8;
|
|
3551
|
-
finalCol = (colorRGB | a << 24) >>> 0;
|
|
3552
|
-
}
|
|
3553
|
-
for (let iy = 0; iy < actualH; iy++) {
|
|
3554
|
-
const currentY = finalY + iy;
|
|
3555
|
-
const maskY = currentY - y;
|
|
3556
|
-
const maskOffset = maskY * maskW;
|
|
3557
|
-
const dstRowOffset = currentY * dw;
|
|
3558
|
-
for (let ix = 0; ix < actualW; ix++) {
|
|
3559
|
-
const currentX = finalX + ix;
|
|
3560
|
-
const maskX = currentX - x;
|
|
3561
|
-
const maskIndex = maskOffset + maskX;
|
|
3562
|
-
if (maskData[maskIndex]) {
|
|
3563
|
-
dst32[dstRowOffset + currentX] = finalCol;
|
|
3564
|
-
}
|
|
3565
|
-
}
|
|
3820
|
+
this.historyManager = historyManager;
|
|
3821
|
+
this.accumulator = new PixelAccumulator(target, this.config);
|
|
3822
|
+
this.mutator = mutatorFactory(this);
|
|
3823
|
+
}
|
|
3824
|
+
withHistory(cb) {
|
|
3825
|
+
cb(this.mutator);
|
|
3826
|
+
this.captureHistory();
|
|
3827
|
+
}
|
|
3828
|
+
captureHistory() {
|
|
3829
|
+
const beforeTiles = this.accumulator.beforeTiles;
|
|
3830
|
+
if (beforeTiles.length === 0) return;
|
|
3831
|
+
const afterTiles = this.accumulator.extractAfterTiles();
|
|
3832
|
+
const patch = {
|
|
3833
|
+
beforeTiles,
|
|
3834
|
+
afterTiles
|
|
3835
|
+
};
|
|
3836
|
+
const target = this.target;
|
|
3837
|
+
const tileSize = this.config.tileSize;
|
|
3838
|
+
const accumulator = this.accumulator;
|
|
3839
|
+
const action = {
|
|
3840
|
+
undo: () => applyPatchTiles(target, patch.beforeTiles, tileSize),
|
|
3841
|
+
redo: () => applyPatchTiles(target, patch.afterTiles, tileSize),
|
|
3842
|
+
dispose: () => accumulator.recyclePatch(patch)
|
|
3843
|
+
};
|
|
3844
|
+
this.historyManager.commit(action);
|
|
3845
|
+
this.accumulator.reset();
|
|
3566
3846
|
}
|
|
3567
|
-
}
|
|
3568
|
-
|
|
3569
|
-
// src/History/PixelMutator/mutatorFillBinaryMask.ts
|
|
3570
|
-
var defaults16 = {
|
|
3571
|
-
fillPixelDataBinaryMask
|
|
3572
3847
|
};
|
|
3573
|
-
var mutatorFillBinaryMask = ((writer, deps = defaults16) => {
|
|
3574
|
-
const {
|
|
3575
|
-
fillPixelDataBinaryMask: fillPixelDataBinaryMask2 = defaults16.fillPixelDataBinaryMask
|
|
3576
|
-
} = deps;
|
|
3577
|
-
return {
|
|
3578
|
-
fillBinaryMask(color, mask, alpha = 255, x = 0, y = 0) {
|
|
3579
|
-
writer.accumulator.storeRegionBeforeState(x, y, mask.w, mask.h);
|
|
3580
|
-
fillPixelDataBinaryMask2(writer.target, color, mask, alpha, x, y);
|
|
3581
|
-
}
|
|
3582
|
-
};
|
|
3583
|
-
});
|
|
3584
3848
|
|
|
3585
3849
|
// src/ImageData/copyImageData.ts
|
|
3586
3850
|
function copyImageData({
|
|
@@ -4676,223 +4940,6 @@ var PixelData = class _PixelData {
|
|
|
4676
4940
|
}
|
|
4677
4941
|
};
|
|
4678
4942
|
|
|
4679
|
-
// src/PixelData/blendPixelDataAlphaMask.ts
|
|
4680
|
-
function blendPixelDataAlphaMask(dst, src, alphaMask, opts = {}) {
|
|
4681
|
-
const {
|
|
4682
|
-
x: targetX = 0,
|
|
4683
|
-
y: targetY = 0,
|
|
4684
|
-
sx: sourceX = 0,
|
|
4685
|
-
sy: sourceY = 0,
|
|
4686
|
-
w: width = src.width,
|
|
4687
|
-
h: height = src.height,
|
|
4688
|
-
alpha: globalAlpha = 255,
|
|
4689
|
-
blendFn = sourceOverPerfect,
|
|
4690
|
-
mx = 0,
|
|
4691
|
-
my = 0,
|
|
4692
|
-
invertMask = false
|
|
4693
|
-
} = opts;
|
|
4694
|
-
if (globalAlpha === 0) return;
|
|
4695
|
-
let x = targetX;
|
|
4696
|
-
let y = targetY;
|
|
4697
|
-
let sx = sourceX;
|
|
4698
|
-
let sy = sourceY;
|
|
4699
|
-
let w = width;
|
|
4700
|
-
let h = height;
|
|
4701
|
-
if (sx < 0) {
|
|
4702
|
-
x -= sx;
|
|
4703
|
-
w += sx;
|
|
4704
|
-
sx = 0;
|
|
4705
|
-
}
|
|
4706
|
-
if (sy < 0) {
|
|
4707
|
-
y -= sy;
|
|
4708
|
-
h += sy;
|
|
4709
|
-
sy = 0;
|
|
4710
|
-
}
|
|
4711
|
-
w = Math.min(w, src.width - sx);
|
|
4712
|
-
h = Math.min(h, src.height - sy);
|
|
4713
|
-
if (x < 0) {
|
|
4714
|
-
sx -= x;
|
|
4715
|
-
w += x;
|
|
4716
|
-
x = 0;
|
|
4717
|
-
}
|
|
4718
|
-
if (y < 0) {
|
|
4719
|
-
sy -= y;
|
|
4720
|
-
h += y;
|
|
4721
|
-
y = 0;
|
|
4722
|
-
}
|
|
4723
|
-
const actualW = Math.min(w, dst.width - x);
|
|
4724
|
-
const actualH = Math.min(h, dst.height - y);
|
|
4725
|
-
if (actualW <= 0 || actualH <= 0) return;
|
|
4726
|
-
const dw = dst.width;
|
|
4727
|
-
const sw = src.width;
|
|
4728
|
-
const mPitch = alphaMask.w;
|
|
4729
|
-
const maskData = alphaMask.data;
|
|
4730
|
-
const dx = x - targetX | 0;
|
|
4731
|
-
const dy = y - targetY | 0;
|
|
4732
|
-
const dst32 = dst.data32;
|
|
4733
|
-
const src32 = src.data32;
|
|
4734
|
-
let dIdx = y * dw + x | 0;
|
|
4735
|
-
let sIdx = sy * sw + sx | 0;
|
|
4736
|
-
let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
|
|
4737
|
-
const dStride = dw - actualW | 0;
|
|
4738
|
-
const sStride = sw - actualW | 0;
|
|
4739
|
-
const mStride = mPitch - actualW | 0;
|
|
4740
|
-
const isOpaque = globalAlpha === 255;
|
|
4741
|
-
const isOverwrite = blendFn.isOverwrite || false;
|
|
4742
|
-
for (let iy = 0; iy < actualH; iy++) {
|
|
4743
|
-
for (let ix = 0; ix < actualW; ix++) {
|
|
4744
|
-
const mVal = maskData[mIdx];
|
|
4745
|
-
const effM = invertMask ? 255 - mVal : mVal;
|
|
4746
|
-
if (effM === 0) {
|
|
4747
|
-
dIdx++;
|
|
4748
|
-
sIdx++;
|
|
4749
|
-
mIdx++;
|
|
4750
|
-
continue;
|
|
4751
|
-
}
|
|
4752
|
-
const srcCol = src32[sIdx];
|
|
4753
|
-
const srcAlpha = srcCol >>> 24;
|
|
4754
|
-
if (srcAlpha === 0 && !isOverwrite) {
|
|
4755
|
-
dIdx++;
|
|
4756
|
-
sIdx++;
|
|
4757
|
-
mIdx++;
|
|
4758
|
-
continue;
|
|
4759
|
-
}
|
|
4760
|
-
let weight = globalAlpha;
|
|
4761
|
-
if (isOpaque) {
|
|
4762
|
-
weight = effM;
|
|
4763
|
-
} else if (effM !== 255) {
|
|
4764
|
-
weight = effM * globalAlpha + 128 >> 8;
|
|
4765
|
-
}
|
|
4766
|
-
if (weight === 0) {
|
|
4767
|
-
dIdx++;
|
|
4768
|
-
sIdx++;
|
|
4769
|
-
mIdx++;
|
|
4770
|
-
continue;
|
|
4771
|
-
}
|
|
4772
|
-
let finalCol = srcCol;
|
|
4773
|
-
if (weight < 255) {
|
|
4774
|
-
const a = srcAlpha * weight + 128 >> 8;
|
|
4775
|
-
if (a === 0 && !isOverwrite) {
|
|
4776
|
-
dIdx++;
|
|
4777
|
-
sIdx++;
|
|
4778
|
-
mIdx++;
|
|
4779
|
-
continue;
|
|
4780
|
-
}
|
|
4781
|
-
finalCol = (srcCol & 16777215 | a << 24) >>> 0;
|
|
4782
|
-
}
|
|
4783
|
-
dst32[dIdx] = blendFn(finalCol, dst32[dIdx]);
|
|
4784
|
-
dIdx++;
|
|
4785
|
-
sIdx++;
|
|
4786
|
-
mIdx++;
|
|
4787
|
-
}
|
|
4788
|
-
dIdx += dStride;
|
|
4789
|
-
sIdx += sStride;
|
|
4790
|
-
mIdx += mStride;
|
|
4791
|
-
}
|
|
4792
|
-
}
|
|
4793
|
-
|
|
4794
|
-
// src/PixelData/blendPixelDataBinaryMask.ts
|
|
4795
|
-
function blendPixelDataBinaryMask(dst, src, binaryMask, opts) {
|
|
4796
|
-
const {
|
|
4797
|
-
x: targetX = 0,
|
|
4798
|
-
y: targetY = 0,
|
|
4799
|
-
sx: sourceX = 0,
|
|
4800
|
-
sy: sourceY = 0,
|
|
4801
|
-
w: width = src.width,
|
|
4802
|
-
h: height = src.height,
|
|
4803
|
-
alpha: globalAlpha = 255,
|
|
4804
|
-
blendFn = sourceOverPerfect,
|
|
4805
|
-
mx = 0,
|
|
4806
|
-
my = 0,
|
|
4807
|
-
invertMask = false
|
|
4808
|
-
} = opts;
|
|
4809
|
-
if (globalAlpha === 0) return;
|
|
4810
|
-
let x = targetX;
|
|
4811
|
-
let y = targetY;
|
|
4812
|
-
let sx = sourceX;
|
|
4813
|
-
let sy = sourceY;
|
|
4814
|
-
let w = width;
|
|
4815
|
-
let h = height;
|
|
4816
|
-
if (sx < 0) {
|
|
4817
|
-
x -= sx;
|
|
4818
|
-
w += sx;
|
|
4819
|
-
sx = 0;
|
|
4820
|
-
}
|
|
4821
|
-
if (sy < 0) {
|
|
4822
|
-
y -= sy;
|
|
4823
|
-
h += sy;
|
|
4824
|
-
sy = 0;
|
|
4825
|
-
}
|
|
4826
|
-
w = Math.min(w, src.width - sx);
|
|
4827
|
-
h = Math.min(h, src.height - sy);
|
|
4828
|
-
if (x < 0) {
|
|
4829
|
-
sx -= x;
|
|
4830
|
-
w += x;
|
|
4831
|
-
x = 0;
|
|
4832
|
-
}
|
|
4833
|
-
if (y < 0) {
|
|
4834
|
-
sy -= y;
|
|
4835
|
-
h += y;
|
|
4836
|
-
y = 0;
|
|
4837
|
-
}
|
|
4838
|
-
const actualW = Math.min(w, dst.width - x);
|
|
4839
|
-
const actualH = Math.min(h, dst.height - y);
|
|
4840
|
-
if (actualW <= 0 || actualH <= 0) return;
|
|
4841
|
-
const dx = x - targetX | 0;
|
|
4842
|
-
const dy = y - targetY | 0;
|
|
4843
|
-
const dst32 = dst.data32;
|
|
4844
|
-
const src32 = src.data32;
|
|
4845
|
-
const dw = dst.width;
|
|
4846
|
-
const sw = src.width;
|
|
4847
|
-
const mPitch = binaryMask.w;
|
|
4848
|
-
const maskData = binaryMask.data;
|
|
4849
|
-
let dIdx = y * dw + x | 0;
|
|
4850
|
-
let sIdx = sy * sw + sx | 0;
|
|
4851
|
-
let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
|
|
4852
|
-
const dStride = dw - actualW | 0;
|
|
4853
|
-
const sStride = sw - actualW | 0;
|
|
4854
|
-
const mStride = mPitch - actualW | 0;
|
|
4855
|
-
const skipVal = invertMask ? 1 : 0;
|
|
4856
|
-
const isOpaque = globalAlpha === 255;
|
|
4857
|
-
const isOverwrite = blendFn.isOverwrite || false;
|
|
4858
|
-
for (let iy = 0; iy < actualH; iy++) {
|
|
4859
|
-
for (let ix = 0; ix < actualW; ix++) {
|
|
4860
|
-
if (maskData[mIdx] === skipVal) {
|
|
4861
|
-
dIdx++;
|
|
4862
|
-
sIdx++;
|
|
4863
|
-
mIdx++;
|
|
4864
|
-
continue;
|
|
4865
|
-
}
|
|
4866
|
-
const srcCol = src32[sIdx];
|
|
4867
|
-
const srcAlpha = srcCol >>> 24;
|
|
4868
|
-
if (srcAlpha === 0 && !isOverwrite) {
|
|
4869
|
-
dIdx++;
|
|
4870
|
-
sIdx++;
|
|
4871
|
-
mIdx++;
|
|
4872
|
-
continue;
|
|
4873
|
-
}
|
|
4874
|
-
let finalCol = srcCol;
|
|
4875
|
-
if (!isOpaque) {
|
|
4876
|
-
const a = srcAlpha * globalAlpha + 128 >> 8;
|
|
4877
|
-
if (a === 0 && !isOverwrite) {
|
|
4878
|
-
dIdx++;
|
|
4879
|
-
sIdx++;
|
|
4880
|
-
mIdx++;
|
|
4881
|
-
continue;
|
|
4882
|
-
}
|
|
4883
|
-
finalCol = (srcCol & 16777215 | a << 24) >>> 0;
|
|
4884
|
-
}
|
|
4885
|
-
dst32[dIdx] = blendFn(finalCol, dst32[dIdx]);
|
|
4886
|
-
dIdx++;
|
|
4887
|
-
sIdx++;
|
|
4888
|
-
mIdx++;
|
|
4889
|
-
}
|
|
4890
|
-
dIdx += dStride;
|
|
4891
|
-
sIdx += sStride;
|
|
4892
|
-
mIdx += mStride;
|
|
4893
|
-
}
|
|
4894
|
-
}
|
|
4895
|
-
|
|
4896
4943
|
// src/PixelData/clearPixelData.ts
|
|
4897
4944
|
function clearPixelData(dst, rect) {
|
|
4898
4945
|
fillPixelData(dst, 0, rect);
|
|
@@ -5246,6 +5293,8 @@ function writePixelDataBuffer(target, data, _x, _y, _w, _h) {
|
|
|
5246
5293
|
mutatorBlendColor,
|
|
5247
5294
|
mutatorBlendPixel,
|
|
5248
5295
|
mutatorBlendPixelData,
|
|
5296
|
+
mutatorBlendPixelDataAlphaMask,
|
|
5297
|
+
mutatorBlendPixelDataBinaryMask,
|
|
5249
5298
|
mutatorClear,
|
|
5250
5299
|
mutatorFill,
|
|
5251
5300
|
mutatorFillBinaryMask,
|