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.js CHANGED
@@ -2426,19 +2426,50 @@ var mutatorApplyCircleBrushStroke = ((writer, deps = defaults4) => {
2426
2426
  };
2427
2427
  });
2428
2428
 
2429
- // src/History/PixelMutator/mutatorApplyCirclePencilStroke.ts
2429
+ // src/History/PixelMutator/mutatorApplyCirclePencil.ts
2430
2430
  var defaults5 = {
2431
+ applyCircleBrushToPixelData,
2432
+ getCircleBrushOrPencilBounds
2433
+ };
2434
+ var mutatorApplyCirclePencil = ((writer, deps = defaults5) => {
2435
+ const {
2436
+ applyCircleBrushToPixelData: applyCircleBrushToPixelData2 = defaults5.applyCircleBrushToPixelData,
2437
+ getCircleBrushOrPencilBounds: getCircleBrushOrPencilBounds2 = defaults5.getCircleBrushOrPencilBounds
2438
+ } = deps;
2439
+ const boundsOut = {
2440
+ x: 0,
2441
+ y: 0,
2442
+ w: 0,
2443
+ h: 0
2444
+ };
2445
+ return {
2446
+ applyCirclePencil(color, centerX, centerY, brush, alpha = 255, blendFn) {
2447
+ const bounds = getCircleBrushOrPencilBounds2(centerX, centerY, brush.size, writer.target.width, writer.target.height, boundsOut);
2448
+ const {
2449
+ x,
2450
+ y,
2451
+ w,
2452
+ h
2453
+ } = bounds;
2454
+ writer.accumulator.storeRegionBeforeState(x, y, w, h);
2455
+ applyCircleBrushToPixelData2(writer.target, color, centerX, centerY, brush, alpha, blendFn, bounds);
2456
+ }
2457
+ };
2458
+ });
2459
+
2460
+ // src/History/PixelMutator/mutatorApplyCirclePencilStroke.ts
2461
+ var defaults6 = {
2431
2462
  forEachLinePoint,
2432
2463
  blendColorPixelDataBinaryMask,
2433
2464
  getCircleBrushOrPencilBounds,
2434
2465
  getCircleBrushOrPencilStrokeBounds
2435
2466
  };
2436
- var mutatorApplyCirclePencilStroke = ((writer, deps = defaults5) => {
2467
+ var mutatorApplyCirclePencilStroke = ((writer, deps = defaults6) => {
2437
2468
  const {
2438
- forEachLinePoint: forEachLinePoint2 = defaults5.forEachLinePoint,
2439
- blendColorPixelDataBinaryMask: blendColorPixelDataBinaryMask2 = defaults5.blendColorPixelDataBinaryMask,
2440
- getCircleBrushOrPencilStrokeBounds: getCircleBrushOrPencilStrokeBounds2 = defaults5.getCircleBrushOrPencilStrokeBounds,
2441
- getCircleBrushOrPencilBounds: getCircleBrushOrPencilBounds2 = defaults5.getCircleBrushOrPencilBounds
2469
+ forEachLinePoint: forEachLinePoint2 = defaults6.forEachLinePoint,
2470
+ blendColorPixelDataBinaryMask: blendColorPixelDataBinaryMask2 = defaults6.blendColorPixelDataBinaryMask,
2471
+ getCircleBrushOrPencilStrokeBounds: getCircleBrushOrPencilStrokeBounds2 = defaults6.getCircleBrushOrPencilStrokeBounds,
2472
+ getCircleBrushOrPencilBounds: getCircleBrushOrPencilBounds2 = defaults6.getCircleBrushOrPencilBounds
2442
2473
  } = deps;
2443
2474
  const strokeBoundsOut = {
2444
2475
  x: 0,
@@ -2592,14 +2623,14 @@ function applyRectBrushToPixelData(target, color, centerX, centerY, brushWidth,
2592
2623
  }
2593
2624
 
2594
2625
  // src/History/PixelMutator/mutatorApplyRectBrush.ts
2595
- var defaults6 = {
2626
+ var defaults7 = {
2596
2627
  applyRectBrushToPixelData,
2597
2628
  getRectBrushOrPencilBounds
2598
2629
  };
2599
- var mutatorApplyRectBrush = ((writer, deps = defaults6) => {
2630
+ var mutatorApplyRectBrush = ((writer, deps = defaults7) => {
2600
2631
  const {
2601
- applyRectBrushToPixelData: applyRectBrushToPixelData2 = defaults6.applyRectBrushToPixelData,
2602
- getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults6.getRectBrushOrPencilBounds
2632
+ applyRectBrushToPixelData: applyRectBrushToPixelData2 = defaults7.applyRectBrushToPixelData,
2633
+ getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults7.getRectBrushOrPencilBounds
2603
2634
  } = deps;
2604
2635
  const boundsOut = {
2605
2636
  x: 0,
@@ -2638,18 +2669,18 @@ function getRectBrushOrPencilStrokeBounds(x0, y0, x1, y1, brushWidth, brushHeigh
2638
2669
  }
2639
2670
 
2640
2671
  // src/History/PixelMutator/mutatorApplyRectBrushStroke.ts
2641
- var defaults7 = {
2672
+ var defaults8 = {
2642
2673
  forEachLinePoint,
2643
2674
  blendColorPixelDataAlphaMask,
2644
2675
  getRectBrushOrPencilBounds,
2645
2676
  getRectBrushOrPencilStrokeBounds
2646
2677
  };
2647
- var mutatorApplyRectBrushStroke = ((writer, deps = defaults7) => {
2678
+ var mutatorApplyRectBrushStroke = ((writer, deps = defaults8) => {
2648
2679
  const {
2649
- forEachLinePoint: forEachLinePoint2 = defaults7.forEachLinePoint,
2650
- blendColorPixelDataAlphaMask: blendColorPixelDataAlphaMask2 = defaults7.blendColorPixelDataAlphaMask,
2651
- getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults7.getRectBrushOrPencilBounds,
2652
- getRectBrushOrPencilStrokeBounds: getRectBrushOrPencilStrokeBounds2 = defaults7.getRectBrushOrPencilStrokeBounds
2680
+ forEachLinePoint: forEachLinePoint2 = defaults8.forEachLinePoint,
2681
+ blendColorPixelDataAlphaMask: blendColorPixelDataAlphaMask2 = defaults8.blendColorPixelDataAlphaMask,
2682
+ getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults8.getRectBrushOrPencilBounds,
2683
+ getRectBrushOrPencilStrokeBounds: getRectBrushOrPencilStrokeBounds2 = defaults8.getRectBrushOrPencilStrokeBounds
2653
2684
  } = deps;
2654
2685
  const strokeBoundsOut = {
2655
2686
  x: 0,
@@ -2741,16 +2772,16 @@ var mutatorApplyRectBrushStroke = ((writer, deps = defaults7) => {
2741
2772
  });
2742
2773
 
2743
2774
  // src/History/PixelMutator/mutatorApplyRectPencil.ts
2744
- var defaults8 = {
2775
+ var defaults9 = {
2745
2776
  applyRectBrushToPixelData,
2746
2777
  getRectBrushOrPencilBounds,
2747
2778
  fallOff: () => 1
2748
2779
  };
2749
- var mutatorApplyRectPencil = ((writer, deps = defaults8) => {
2780
+ var mutatorApplyRectPencil = ((writer, deps = defaults9) => {
2750
2781
  const {
2751
- applyRectBrushToPixelData: applyRectBrushToPixelData2 = defaults8.applyRectBrushToPixelData,
2752
- getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults8.getRectBrushOrPencilBounds,
2753
- fallOff = defaults8.fallOff
2782
+ applyRectBrushToPixelData: applyRectBrushToPixelData2 = defaults9.applyRectBrushToPixelData,
2783
+ getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults9.getRectBrushOrPencilBounds,
2784
+ fallOff = defaults9.fallOff
2754
2785
  } = deps;
2755
2786
  const boundsOut = {
2756
2787
  x: 0,
@@ -2774,18 +2805,18 @@ var mutatorApplyRectPencil = ((writer, deps = defaults8) => {
2774
2805
  });
2775
2806
 
2776
2807
  // src/History/PixelMutator/mutatorApplyRectPencilStroke.ts
2777
- var defaults9 = {
2808
+ var defaults10 = {
2778
2809
  forEachLinePoint,
2779
2810
  getRectBrushOrPencilBounds,
2780
2811
  getRectBrushOrPencilStrokeBounds,
2781
2812
  blendColorPixelDataBinaryMask
2782
2813
  };
2783
- var mutatorApplyRectPencilStroke = ((writer, deps = defaults9) => {
2814
+ var mutatorApplyRectPencilStroke = ((writer, deps = defaults10) => {
2784
2815
  const {
2785
- forEachLinePoint: forEachLinePoint2 = defaults9.forEachLinePoint,
2786
- blendColorPixelDataBinaryMask: blendColorPixelDataBinaryMask2 = defaults9.blendColorPixelDataBinaryMask,
2787
- getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults9.getRectBrushOrPencilBounds,
2788
- getRectBrushOrPencilStrokeBounds: getRectBrushOrPencilStrokeBounds2 = defaults9.getRectBrushOrPencilStrokeBounds
2816
+ forEachLinePoint: forEachLinePoint2 = defaults10.forEachLinePoint,
2817
+ blendColorPixelDataBinaryMask: blendColorPixelDataBinaryMask2 = defaults10.blendColorPixelDataBinaryMask,
2818
+ getRectBrushOrPencilBounds: getRectBrushOrPencilBounds2 = defaults10.getRectBrushOrPencilBounds,
2819
+ getRectBrushOrPencilStrokeBounds: getRectBrushOrPencilStrokeBounds2 = defaults10.getRectBrushOrPencilStrokeBounds
2789
2820
  } = deps;
2790
2821
  const strokeBoundsOut = {
2791
2822
  x: 0,
@@ -2914,12 +2945,12 @@ function blendColorPixelData(dst, color, opts = {}) {
2914
2945
  }
2915
2946
 
2916
2947
  // src/History/PixelMutator/mutatorBlendColor.ts
2917
- var defaults10 = {
2948
+ var defaults11 = {
2918
2949
  blendColorPixelData
2919
2950
  };
2920
- var mutatorBlendColor = ((writer, deps = defaults10) => {
2951
+ var mutatorBlendColor = ((writer, deps = defaults11) => {
2921
2952
  const {
2922
- blendColorPixelData: blendColorPixelData2 = defaults10.blendColorPixelData
2953
+ blendColorPixelData: blendColorPixelData2 = defaults11.blendColorPixelData
2923
2954
  } = deps;
2924
2955
  return {
2925
2956
  blendColor(color, opts = {}) {
@@ -2958,7 +2989,7 @@ function mutatorBlendPixel(writer) {
2958
2989
  }
2959
2990
 
2960
2991
  // src/PixelData/blendPixelData.ts
2961
- function blendPixelData(dst, src, opts) {
2992
+ function blendPixelData(dst, src, opts = {}) {
2962
2993
  const {
2963
2994
  x: targetX = 0,
2964
2995
  y: targetY = 0,
@@ -3040,15 +3071,15 @@ function blendPixelData(dst, src, opts) {
3040
3071
  }
3041
3072
 
3042
3073
  // src/History/PixelMutator/mutatorBlendPixelData.ts
3043
- var defaults11 = {
3074
+ var defaults12 = {
3044
3075
  blendPixelData
3045
3076
  };
3046
- var mutatorBlendPixelData = ((writer, deps = defaults11) => {
3077
+ var mutatorBlendPixelData = ((writer, deps = defaults12) => {
3047
3078
  const {
3048
- blendPixelData: blendPixelData2 = defaults11.blendPixelData
3079
+ blendPixelData: blendPixelData2 = defaults12.blendPixelData
3049
3080
  } = deps;
3050
3081
  return {
3051
- blendPixelData(src, opts) {
3082
+ blendPixelData(src, opts = {}) {
3052
3083
  const {
3053
3084
  x = 0,
3054
3085
  y = 0,
@@ -3061,6 +3092,263 @@ var mutatorBlendPixelData = ((writer, deps = defaults11) => {
3061
3092
  };
3062
3093
  });
3063
3094
 
3095
+ // src/PixelData/blendPixelDataAlphaMask.ts
3096
+ function blendPixelDataAlphaMask(dst, src, alphaMask, opts = {}) {
3097
+ const {
3098
+ x: targetX = 0,
3099
+ y: targetY = 0,
3100
+ sx: sourceX = 0,
3101
+ sy: sourceY = 0,
3102
+ w: width = src.width,
3103
+ h: height = src.height,
3104
+ alpha: globalAlpha = 255,
3105
+ blendFn = sourceOverPerfect,
3106
+ mx = 0,
3107
+ my = 0,
3108
+ invertMask = false
3109
+ } = opts;
3110
+ if (globalAlpha === 0) return;
3111
+ let x = targetX;
3112
+ let y = targetY;
3113
+ let sx = sourceX;
3114
+ let sy = sourceY;
3115
+ let w = width;
3116
+ let h = height;
3117
+ if (sx < 0) {
3118
+ x -= sx;
3119
+ w += sx;
3120
+ sx = 0;
3121
+ }
3122
+ if (sy < 0) {
3123
+ y -= sy;
3124
+ h += sy;
3125
+ sy = 0;
3126
+ }
3127
+ w = Math.min(w, src.width - sx);
3128
+ h = Math.min(h, src.height - sy);
3129
+ if (x < 0) {
3130
+ sx -= x;
3131
+ w += x;
3132
+ x = 0;
3133
+ }
3134
+ if (y < 0) {
3135
+ sy -= y;
3136
+ h += y;
3137
+ y = 0;
3138
+ }
3139
+ const actualW = Math.min(w, dst.width - x);
3140
+ const actualH = Math.min(h, dst.height - y);
3141
+ if (actualW <= 0 || actualH <= 0) return;
3142
+ const dw = dst.width;
3143
+ const sw = src.width;
3144
+ const mPitch = alphaMask.w;
3145
+ const maskData = alphaMask.data;
3146
+ const dx = x - targetX | 0;
3147
+ const dy = y - targetY | 0;
3148
+ const dst32 = dst.data32;
3149
+ const src32 = src.data32;
3150
+ let dIdx = y * dw + x | 0;
3151
+ let sIdx = sy * sw + sx | 0;
3152
+ let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
3153
+ const dStride = dw - actualW | 0;
3154
+ const sStride = sw - actualW | 0;
3155
+ const mStride = mPitch - actualW | 0;
3156
+ const isOpaque = globalAlpha === 255;
3157
+ const isOverwrite = blendFn.isOverwrite || false;
3158
+ for (let iy = 0; iy < actualH; iy++) {
3159
+ for (let ix = 0; ix < actualW; ix++) {
3160
+ const mVal = maskData[mIdx];
3161
+ const effM = invertMask ? 255 - mVal : mVal;
3162
+ if (effM === 0) {
3163
+ dIdx++;
3164
+ sIdx++;
3165
+ mIdx++;
3166
+ continue;
3167
+ }
3168
+ const srcCol = src32[sIdx];
3169
+ const srcAlpha = srcCol >>> 24;
3170
+ if (srcAlpha === 0 && !isOverwrite) {
3171
+ dIdx++;
3172
+ sIdx++;
3173
+ mIdx++;
3174
+ continue;
3175
+ }
3176
+ let weight = globalAlpha;
3177
+ if (isOpaque) {
3178
+ weight = effM;
3179
+ } else if (effM !== 255) {
3180
+ weight = effM * globalAlpha + 128 >> 8;
3181
+ }
3182
+ if (weight === 0) {
3183
+ dIdx++;
3184
+ sIdx++;
3185
+ mIdx++;
3186
+ continue;
3187
+ }
3188
+ let finalCol = srcCol;
3189
+ if (weight < 255) {
3190
+ const a = srcAlpha * weight + 128 >> 8;
3191
+ if (a === 0 && !isOverwrite) {
3192
+ dIdx++;
3193
+ sIdx++;
3194
+ mIdx++;
3195
+ continue;
3196
+ }
3197
+ finalCol = (srcCol & 16777215 | a << 24) >>> 0;
3198
+ }
3199
+ dst32[dIdx] = blendFn(finalCol, dst32[dIdx]);
3200
+ dIdx++;
3201
+ sIdx++;
3202
+ mIdx++;
3203
+ }
3204
+ dIdx += dStride;
3205
+ sIdx += sStride;
3206
+ mIdx += mStride;
3207
+ }
3208
+ }
3209
+
3210
+ // src/History/PixelMutator/mutatorBlendPixelDataAlphaMask.ts
3211
+ var defaults13 = {
3212
+ blendPixelDataAlphaMask
3213
+ };
3214
+ var mutatorBlendPixelDataAlphaMask = ((writer, deps = defaults13) => {
3215
+ const {
3216
+ blendPixelDataAlphaMask: blendPixelDataAlphaMask2 = defaults13.blendPixelDataAlphaMask
3217
+ } = deps;
3218
+ return {
3219
+ blendPixelDataAlphaMask(src, mask, opts = {}) {
3220
+ const x = opts.x ?? 0;
3221
+ const y = opts.y ?? 0;
3222
+ const w = opts.w ?? src.width;
3223
+ const h = opts.h ?? src.height;
3224
+ writer.accumulator.storeRegionBeforeState(x, y, w, h);
3225
+ blendPixelDataAlphaMask2(writer.target, src, mask, opts);
3226
+ }
3227
+ };
3228
+ });
3229
+
3230
+ // src/PixelData/blendPixelDataBinaryMask.ts
3231
+ function blendPixelDataBinaryMask(dst, src, binaryMask, opts = {}) {
3232
+ const {
3233
+ x: targetX = 0,
3234
+ y: targetY = 0,
3235
+ sx: sourceX = 0,
3236
+ sy: sourceY = 0,
3237
+ w: width = src.width,
3238
+ h: height = src.height,
3239
+ alpha: globalAlpha = 255,
3240
+ blendFn = sourceOverPerfect,
3241
+ mx = 0,
3242
+ my = 0,
3243
+ invertMask = false
3244
+ } = opts;
3245
+ if (globalAlpha === 0) return;
3246
+ let x = targetX;
3247
+ let y = targetY;
3248
+ let sx = sourceX;
3249
+ let sy = sourceY;
3250
+ let w = width;
3251
+ let h = height;
3252
+ if (sx < 0) {
3253
+ x -= sx;
3254
+ w += sx;
3255
+ sx = 0;
3256
+ }
3257
+ if (sy < 0) {
3258
+ y -= sy;
3259
+ h += sy;
3260
+ sy = 0;
3261
+ }
3262
+ w = Math.min(w, src.width - sx);
3263
+ h = Math.min(h, src.height - sy);
3264
+ if (x < 0) {
3265
+ sx -= x;
3266
+ w += x;
3267
+ x = 0;
3268
+ }
3269
+ if (y < 0) {
3270
+ sy -= y;
3271
+ h += y;
3272
+ y = 0;
3273
+ }
3274
+ const actualW = Math.min(w, dst.width - x);
3275
+ const actualH = Math.min(h, dst.height - y);
3276
+ if (actualW <= 0 || actualH <= 0) return;
3277
+ const dx = x - targetX | 0;
3278
+ const dy = y - targetY | 0;
3279
+ const dst32 = dst.data32;
3280
+ const src32 = src.data32;
3281
+ const dw = dst.width;
3282
+ const sw = src.width;
3283
+ const mPitch = binaryMask.w;
3284
+ const maskData = binaryMask.data;
3285
+ let dIdx = y * dw + x | 0;
3286
+ let sIdx = sy * sw + sx | 0;
3287
+ let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
3288
+ const dStride = dw - actualW | 0;
3289
+ const sStride = sw - actualW | 0;
3290
+ const mStride = mPitch - actualW | 0;
3291
+ const skipVal = invertMask ? 1 : 0;
3292
+ const isOpaque = globalAlpha === 255;
3293
+ const isOverwrite = blendFn.isOverwrite || false;
3294
+ for (let iy = 0; iy < actualH; iy++) {
3295
+ for (let ix = 0; ix < actualW; ix++) {
3296
+ if (maskData[mIdx] === skipVal) {
3297
+ dIdx++;
3298
+ sIdx++;
3299
+ mIdx++;
3300
+ continue;
3301
+ }
3302
+ const srcCol = src32[sIdx];
3303
+ const srcAlpha = srcCol >>> 24;
3304
+ if (srcAlpha === 0 && !isOverwrite) {
3305
+ dIdx++;
3306
+ sIdx++;
3307
+ mIdx++;
3308
+ continue;
3309
+ }
3310
+ let finalCol = srcCol;
3311
+ if (!isOpaque) {
3312
+ const a = srcAlpha * globalAlpha + 128 >> 8;
3313
+ if (a === 0 && !isOverwrite) {
3314
+ dIdx++;
3315
+ sIdx++;
3316
+ mIdx++;
3317
+ continue;
3318
+ }
3319
+ finalCol = (srcCol & 16777215 | a << 24) >>> 0;
3320
+ }
3321
+ dst32[dIdx] = blendFn(finalCol, dst32[dIdx]);
3322
+ dIdx++;
3323
+ sIdx++;
3324
+ mIdx++;
3325
+ }
3326
+ dIdx += dStride;
3327
+ sIdx += sStride;
3328
+ mIdx += mStride;
3329
+ }
3330
+ }
3331
+
3332
+ // src/History/PixelMutator/mutatorBlendPixelDataBinaryMask.ts
3333
+ var defaults14 = {
3334
+ blendPixelDataBinaryMask
3335
+ };
3336
+ var mutatorBlendPixelDataBinaryMask = ((writer, deps = defaults14) => {
3337
+ const {
3338
+ blendPixelDataBinaryMask: blendPixelDataBinaryMask2 = defaults14.blendPixelDataBinaryMask
3339
+ } = deps;
3340
+ return {
3341
+ blendPixelDataBinaryMask(src, mask, opts = {}) {
3342
+ const x = opts.x ?? 0;
3343
+ const y = opts.y ?? 0;
3344
+ const w = opts.w ?? src.width;
3345
+ const h = opts.h ?? src.height;
3346
+ writer.accumulator.storeRegionBeforeState(x, y, w, h);
3347
+ blendPixelDataBinaryMask2(writer.target, src, mask, opts);
3348
+ }
3349
+ };
3350
+ });
3351
+
3064
3352
  // src/PixelData/fillPixelData.ts
3065
3353
  var SCRATCH_RECT = makeClippedRect();
3066
3354
  function fillPixelData(dst, color, _x, _y, _w, _h) {
@@ -3106,12 +3394,12 @@ function fillPixelData(dst, color, _x, _y, _w, _h) {
3106
3394
  }
3107
3395
 
3108
3396
  // src/History/PixelMutator/mutatorClear.ts
3109
- var defaults12 = {
3397
+ var defaults15 = {
3110
3398
  fillPixelData
3111
3399
  };
3112
- var mutatorClear = ((writer, deps = defaults12) => {
3400
+ var mutatorClear = ((writer, deps = defaults15) => {
3113
3401
  const {
3114
- fillPixelData: fillPixelData2 = defaults12.fillPixelData
3402
+ fillPixelData: fillPixelData2 = defaults15.fillPixelData
3115
3403
  } = deps;
3116
3404
  return {
3117
3405
  clear(rect = {}) {
@@ -3126,12 +3414,12 @@ var mutatorClear = ((writer, deps = defaults12) => {
3126
3414
  });
3127
3415
 
3128
3416
  // src/History/PixelMutator/mutatorFill.ts
3129
- var defaults13 = {
3417
+ var defaults16 = {
3130
3418
  fillPixelData
3131
3419
  };
3132
- var mutatorFill = ((writer, deps = defaults13) => {
3420
+ var mutatorFill = ((writer, deps = defaults16) => {
3133
3421
  const {
3134
- fillPixelData: fillPixelData2 = defaults13.fillPixelData
3422
+ fillPixelData: fillPixelData2 = defaults16.fillPixelData
3135
3423
  } = deps;
3136
3424
  return {
3137
3425
  fill(color, rect = {}) {
@@ -3147,8 +3435,64 @@ var mutatorFill = ((writer, deps = defaults13) => {
3147
3435
  };
3148
3436
  });
3149
3437
 
3150
- // src/PixelData/invertPixelData.ts
3438
+ // src/PixelData/fillPixelDataBinaryMask.ts
3151
3439
  var SCRATCH_RECT2 = makeClippedRect();
3440
+ function fillPixelDataBinaryMask(dst, color, mask, alpha = 255, x = 0, y = 0) {
3441
+ if (alpha === 0) return;
3442
+ const maskW = mask.w;
3443
+ const maskH = mask.h;
3444
+ const clip = resolveRectClipping(x, y, maskW, maskH, dst.width, dst.height, SCRATCH_RECT2);
3445
+ if (!clip.inBounds) return;
3446
+ const {
3447
+ x: finalX,
3448
+ y: finalY,
3449
+ w: actualW,
3450
+ h: actualH
3451
+ } = clip;
3452
+ const maskData = mask.data;
3453
+ const dst32 = dst.data32;
3454
+ const dw = dst.width;
3455
+ let finalCol = color;
3456
+ if (alpha < 255) {
3457
+ const baseSrcAlpha = color >>> 24;
3458
+ const colorRGB = color & 16777215;
3459
+ const a = baseSrcAlpha * alpha + 128 >> 8;
3460
+ finalCol = (colorRGB | a << 24) >>> 0;
3461
+ }
3462
+ for (let iy = 0; iy < actualH; iy++) {
3463
+ const currentY = finalY + iy;
3464
+ const maskY = currentY - y;
3465
+ const maskOffset = maskY * maskW;
3466
+ const dstRowOffset = currentY * dw;
3467
+ for (let ix = 0; ix < actualW; ix++) {
3468
+ const currentX = finalX + ix;
3469
+ const maskX = currentX - x;
3470
+ const maskIndex = maskOffset + maskX;
3471
+ if (maskData[maskIndex]) {
3472
+ dst32[dstRowOffset + currentX] = finalCol;
3473
+ }
3474
+ }
3475
+ }
3476
+ }
3477
+
3478
+ // src/History/PixelMutator/mutatorFillBinaryMask.ts
3479
+ var defaults17 = {
3480
+ fillPixelDataBinaryMask
3481
+ };
3482
+ var mutatorFillBinaryMask = ((writer, deps = defaults17) => {
3483
+ const {
3484
+ fillPixelDataBinaryMask: fillPixelDataBinaryMask2 = defaults17.fillPixelDataBinaryMask
3485
+ } = deps;
3486
+ return {
3487
+ fillBinaryMask(color, mask, alpha = 255, x = 0, y = 0) {
3488
+ writer.accumulator.storeRegionBeforeState(x, y, mask.w, mask.h);
3489
+ fillPixelDataBinaryMask2(writer.target, color, mask, alpha, x, y);
3490
+ }
3491
+ };
3492
+ });
3493
+
3494
+ // src/PixelData/invertPixelData.ts
3495
+ var SCRATCH_RECT3 = makeClippedRect();
3152
3496
  function invertPixelData(pixelData, opts = {}) {
3153
3497
  const dst = pixelData;
3154
3498
  const {
@@ -3161,7 +3505,7 @@ function invertPixelData(pixelData, opts = {}) {
3161
3505
  my = 0,
3162
3506
  invertMask = false
3163
3507
  } = opts;
3164
- const clip = resolveRectClipping(targetX, targetY, width, height, dst.width, dst.height, SCRATCH_RECT2);
3508
+ const clip = resolveRectClipping(targetX, targetY, width, height, dst.width, dst.height, SCRATCH_RECT3);
3165
3509
  if (!clip.inBounds) return;
3166
3510
  const {
3167
3511
  x,
@@ -3205,12 +3549,12 @@ function invertPixelData(pixelData, opts = {}) {
3205
3549
  }
3206
3550
 
3207
3551
  // src/History/PixelMutator/mutatorInvert.ts
3208
- var defaults14 = {
3552
+ var defaults18 = {
3209
3553
  invertPixelData
3210
3554
  };
3211
- var mutatorInvert = ((writer, deps = defaults14) => {
3555
+ var mutatorInvert = ((writer, deps = defaults18) => {
3212
3556
  const {
3213
- invertPixelData: invertPixelData2 = defaults14.invertPixelData
3557
+ invertPixelData: invertPixelData2 = defaults18.invertPixelData
3214
3558
  } = deps;
3215
3559
  return {
3216
3560
  invert(opts = {}) {
@@ -3229,21 +3573,26 @@ var mutatorInvert = ((writer, deps = defaults14) => {
3229
3573
  // src/History/PixelMutator.ts
3230
3574
  function makeFullPixelMutator(writer) {
3231
3575
  return {
3576
+ // @sort
3232
3577
  ...mutatorApplyAlphaMask(writer),
3233
3578
  ...mutatorApplyBinaryMask(writer),
3234
- ...mutatorBlendPixelData(writer),
3235
- ...mutatorBlendColor(writer),
3236
- ...mutatorBlendPixel(writer),
3237
- ...mutatorFill(writer),
3238
- ...mutatorInvert(writer),
3239
3579
  ...mutatorApplyCircleBrush(writer),
3240
3580
  ...mutatorApplyCircleBrushStroke(writer),
3581
+ ...mutatorApplyCirclePencil(writer),
3241
3582
  ...mutatorApplyCirclePencilStroke(writer),
3242
3583
  ...mutatorApplyRectBrush(writer),
3243
3584
  ...mutatorApplyRectBrushStroke(writer),
3244
3585
  ...mutatorApplyRectPencil(writer),
3245
3586
  ...mutatorApplyRectPencilStroke(writer),
3246
- ...mutatorClear(writer)
3587
+ ...mutatorBlendColor(writer),
3588
+ ...mutatorBlendPixel(writer),
3589
+ ...mutatorBlendPixelData(writer),
3590
+ ...mutatorBlendPixelDataAlphaMask(writer),
3591
+ ...mutatorBlendPixelDataBinaryMask(writer),
3592
+ ...mutatorClear(writer),
3593
+ ...mutatorFill(writer),
3594
+ ...mutatorFillBinaryMask(writer),
3595
+ ...mutatorInvert(writer)
3247
3596
  };
3248
3597
  }
3249
3598
 
@@ -3261,121 +3610,34 @@ var PixelWriter = class {
3261
3610
  } = {}) {
3262
3611
  this.target = target;
3263
3612
  this.config = new PixelEngineConfig(tileSize);
3264
- this.historyManager = historyManager;
3265
- this.accumulator = new PixelAccumulator(target, this.config);
3266
- this.mutator = mutatorFactory(this);
3267
- }
3268
- withHistory(cb) {
3269
- cb(this.mutator);
3270
- this.captureHistory();
3271
- }
3272
- captureHistory() {
3273
- const beforeTiles = this.accumulator.beforeTiles;
3274
- if (beforeTiles.length === 0) return;
3275
- const afterTiles = this.accumulator.extractAfterTiles();
3276
- const patch = {
3277
- beforeTiles,
3278
- afterTiles
3279
- };
3280
- const target = this.target;
3281
- const tileSize = this.config.tileSize;
3282
- const accumulator = this.accumulator;
3283
- const action = {
3284
- undo: () => applyPatchTiles(target, patch.beforeTiles, tileSize),
3285
- redo: () => applyPatchTiles(target, patch.afterTiles, tileSize),
3286
- dispose: () => accumulator.recyclePatch(patch)
3287
- };
3288
- this.historyManager.commit(action);
3289
- this.accumulator.reset();
3290
- }
3291
- };
3292
-
3293
- // src/History/PixelMutator/mutatorApplyCirclePencil.ts
3294
- var defaults15 = {
3295
- applyCircleBrushToPixelData,
3296
- getCircleBrushOrPencilBounds
3297
- };
3298
- var mutatorApplyCirclePencil = ((writer, deps = defaults15) => {
3299
- const {
3300
- applyCircleBrushToPixelData: applyCircleBrushToPixelData2 = defaults15.applyCircleBrushToPixelData,
3301
- getCircleBrushOrPencilBounds: getCircleBrushOrPencilBounds2 = defaults15.getCircleBrushOrPencilBounds
3302
- } = deps;
3303
- const boundsOut = {
3304
- x: 0,
3305
- y: 0,
3306
- w: 0,
3307
- h: 0
3308
- };
3309
- return {
3310
- applyCirclePencil(color, centerX, centerY, brush, alpha = 255, blendFn) {
3311
- const bounds = getCircleBrushOrPencilBounds2(centerX, centerY, brush.size, writer.target.width, writer.target.height, boundsOut);
3312
- const {
3313
- x,
3314
- y,
3315
- w,
3316
- h
3317
- } = bounds;
3318
- writer.accumulator.storeRegionBeforeState(x, y, w, h);
3319
- applyCircleBrushToPixelData2(writer.target, color, centerX, centerY, brush, alpha, blendFn, bounds);
3320
- }
3321
- };
3322
- });
3323
-
3324
- // src/PixelData/fillPixelDataBinaryMask.ts
3325
- var SCRATCH_RECT3 = makeClippedRect();
3326
- function fillPixelDataBinaryMask(dst, color, mask, alpha = 255, x = 0, y = 0) {
3327
- if (alpha === 0) return;
3328
- const maskW = mask.w;
3329
- const maskH = mask.h;
3330
- const clip = resolveRectClipping(x, y, maskW, maskH, dst.width, dst.height, SCRATCH_RECT3);
3331
- if (!clip.inBounds) return;
3332
- const {
3333
- x: finalX,
3334
- y: finalY,
3335
- w: actualW,
3336
- h: actualH
3337
- } = clip;
3338
- const maskData = mask.data;
3339
- const dst32 = dst.data32;
3340
- const dw = dst.width;
3341
- let finalCol = color;
3342
- if (alpha < 255) {
3343
- const baseSrcAlpha = color >>> 24;
3344
- const colorRGB = color & 16777215;
3345
- const a = baseSrcAlpha * alpha + 128 >> 8;
3346
- finalCol = (colorRGB | a << 24) >>> 0;
3347
- }
3348
- for (let iy = 0; iy < actualH; iy++) {
3349
- const currentY = finalY + iy;
3350
- const maskY = currentY - y;
3351
- const maskOffset = maskY * maskW;
3352
- const dstRowOffset = currentY * dw;
3353
- for (let ix = 0; ix < actualW; ix++) {
3354
- const currentX = finalX + ix;
3355
- const maskX = currentX - x;
3356
- const maskIndex = maskOffset + maskX;
3357
- if (maskData[maskIndex]) {
3358
- dst32[dstRowOffset + currentX] = finalCol;
3359
- }
3360
- }
3613
+ this.historyManager = historyManager;
3614
+ this.accumulator = new PixelAccumulator(target, this.config);
3615
+ this.mutator = mutatorFactory(this);
3616
+ }
3617
+ withHistory(cb) {
3618
+ cb(this.mutator);
3619
+ this.captureHistory();
3620
+ }
3621
+ captureHistory() {
3622
+ const beforeTiles = this.accumulator.beforeTiles;
3623
+ if (beforeTiles.length === 0) return;
3624
+ const afterTiles = this.accumulator.extractAfterTiles();
3625
+ const patch = {
3626
+ beforeTiles,
3627
+ afterTiles
3628
+ };
3629
+ const target = this.target;
3630
+ const tileSize = this.config.tileSize;
3631
+ const accumulator = this.accumulator;
3632
+ const action = {
3633
+ undo: () => applyPatchTiles(target, patch.beforeTiles, tileSize),
3634
+ redo: () => applyPatchTiles(target, patch.afterTiles, tileSize),
3635
+ dispose: () => accumulator.recyclePatch(patch)
3636
+ };
3637
+ this.historyManager.commit(action);
3638
+ this.accumulator.reset();
3361
3639
  }
3362
- }
3363
-
3364
- // src/History/PixelMutator/mutatorFillBinaryMask.ts
3365
- var defaults16 = {
3366
- fillPixelDataBinaryMask
3367
3640
  };
3368
- var mutatorFillBinaryMask = ((writer, deps = defaults16) => {
3369
- const {
3370
- fillPixelDataBinaryMask: fillPixelDataBinaryMask2 = defaults16.fillPixelDataBinaryMask
3371
- } = deps;
3372
- return {
3373
- fillBinaryMask(color, mask, alpha = 255, x = 0, y = 0) {
3374
- writer.accumulator.storeRegionBeforeState(x, y, mask.w, mask.h);
3375
- fillPixelDataBinaryMask2(writer.target, color, mask, alpha, x, y);
3376
- }
3377
- };
3378
- });
3379
3641
 
3380
3642
  // src/ImageData/copyImageData.ts
3381
3643
  function copyImageData({
@@ -4471,223 +4733,6 @@ var PixelData = class _PixelData {
4471
4733
  }
4472
4734
  };
4473
4735
 
4474
- // src/PixelData/blendPixelDataAlphaMask.ts
4475
- function blendPixelDataAlphaMask(dst, src, alphaMask, opts = {}) {
4476
- const {
4477
- x: targetX = 0,
4478
- y: targetY = 0,
4479
- sx: sourceX = 0,
4480
- sy: sourceY = 0,
4481
- w: width = src.width,
4482
- h: height = src.height,
4483
- alpha: globalAlpha = 255,
4484
- blendFn = sourceOverPerfect,
4485
- mx = 0,
4486
- my = 0,
4487
- invertMask = false
4488
- } = opts;
4489
- if (globalAlpha === 0) return;
4490
- let x = targetX;
4491
- let y = targetY;
4492
- let sx = sourceX;
4493
- let sy = sourceY;
4494
- let w = width;
4495
- let h = height;
4496
- if (sx < 0) {
4497
- x -= sx;
4498
- w += sx;
4499
- sx = 0;
4500
- }
4501
- if (sy < 0) {
4502
- y -= sy;
4503
- h += sy;
4504
- sy = 0;
4505
- }
4506
- w = Math.min(w, src.width - sx);
4507
- h = Math.min(h, src.height - sy);
4508
- if (x < 0) {
4509
- sx -= x;
4510
- w += x;
4511
- x = 0;
4512
- }
4513
- if (y < 0) {
4514
- sy -= y;
4515
- h += y;
4516
- y = 0;
4517
- }
4518
- const actualW = Math.min(w, dst.width - x);
4519
- const actualH = Math.min(h, dst.height - y);
4520
- if (actualW <= 0 || actualH <= 0) return;
4521
- const dw = dst.width;
4522
- const sw = src.width;
4523
- const mPitch = alphaMask.w;
4524
- const maskData = alphaMask.data;
4525
- const dx = x - targetX | 0;
4526
- const dy = y - targetY | 0;
4527
- const dst32 = dst.data32;
4528
- const src32 = src.data32;
4529
- let dIdx = y * dw + x | 0;
4530
- let sIdx = sy * sw + sx | 0;
4531
- let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
4532
- const dStride = dw - actualW | 0;
4533
- const sStride = sw - actualW | 0;
4534
- const mStride = mPitch - actualW | 0;
4535
- const isOpaque = globalAlpha === 255;
4536
- const isOverwrite = blendFn.isOverwrite || false;
4537
- for (let iy = 0; iy < actualH; iy++) {
4538
- for (let ix = 0; ix < actualW; ix++) {
4539
- const mVal = maskData[mIdx];
4540
- const effM = invertMask ? 255 - mVal : mVal;
4541
- if (effM === 0) {
4542
- dIdx++;
4543
- sIdx++;
4544
- mIdx++;
4545
- continue;
4546
- }
4547
- const srcCol = src32[sIdx];
4548
- const srcAlpha = srcCol >>> 24;
4549
- if (srcAlpha === 0 && !isOverwrite) {
4550
- dIdx++;
4551
- sIdx++;
4552
- mIdx++;
4553
- continue;
4554
- }
4555
- let weight = globalAlpha;
4556
- if (isOpaque) {
4557
- weight = effM;
4558
- } else if (effM !== 255) {
4559
- weight = effM * globalAlpha + 128 >> 8;
4560
- }
4561
- if (weight === 0) {
4562
- dIdx++;
4563
- sIdx++;
4564
- mIdx++;
4565
- continue;
4566
- }
4567
- let finalCol = srcCol;
4568
- if (weight < 255) {
4569
- const a = srcAlpha * weight + 128 >> 8;
4570
- if (a === 0 && !isOverwrite) {
4571
- dIdx++;
4572
- sIdx++;
4573
- mIdx++;
4574
- continue;
4575
- }
4576
- finalCol = (srcCol & 16777215 | a << 24) >>> 0;
4577
- }
4578
- dst32[dIdx] = blendFn(finalCol, dst32[dIdx]);
4579
- dIdx++;
4580
- sIdx++;
4581
- mIdx++;
4582
- }
4583
- dIdx += dStride;
4584
- sIdx += sStride;
4585
- mIdx += mStride;
4586
- }
4587
- }
4588
-
4589
- // src/PixelData/blendPixelDataBinaryMask.ts
4590
- function blendPixelDataBinaryMask(dst, src, binaryMask, opts) {
4591
- const {
4592
- x: targetX = 0,
4593
- y: targetY = 0,
4594
- sx: sourceX = 0,
4595
- sy: sourceY = 0,
4596
- w: width = src.width,
4597
- h: height = src.height,
4598
- alpha: globalAlpha = 255,
4599
- blendFn = sourceOverPerfect,
4600
- mx = 0,
4601
- my = 0,
4602
- invertMask = false
4603
- } = opts;
4604
- if (globalAlpha === 0) return;
4605
- let x = targetX;
4606
- let y = targetY;
4607
- let sx = sourceX;
4608
- let sy = sourceY;
4609
- let w = width;
4610
- let h = height;
4611
- if (sx < 0) {
4612
- x -= sx;
4613
- w += sx;
4614
- sx = 0;
4615
- }
4616
- if (sy < 0) {
4617
- y -= sy;
4618
- h += sy;
4619
- sy = 0;
4620
- }
4621
- w = Math.min(w, src.width - sx);
4622
- h = Math.min(h, src.height - sy);
4623
- if (x < 0) {
4624
- sx -= x;
4625
- w += x;
4626
- x = 0;
4627
- }
4628
- if (y < 0) {
4629
- sy -= y;
4630
- h += y;
4631
- y = 0;
4632
- }
4633
- const actualW = Math.min(w, dst.width - x);
4634
- const actualH = Math.min(h, dst.height - y);
4635
- if (actualW <= 0 || actualH <= 0) return;
4636
- const dx = x - targetX | 0;
4637
- const dy = y - targetY | 0;
4638
- const dst32 = dst.data32;
4639
- const src32 = src.data32;
4640
- const dw = dst.width;
4641
- const sw = src.width;
4642
- const mPitch = binaryMask.w;
4643
- const maskData = binaryMask.data;
4644
- let dIdx = y * dw + x | 0;
4645
- let sIdx = sy * sw + sx | 0;
4646
- let mIdx = (my + dy) * mPitch + (mx + dx) | 0;
4647
- const dStride = dw - actualW | 0;
4648
- const sStride = sw - actualW | 0;
4649
- const mStride = mPitch - actualW | 0;
4650
- const skipVal = invertMask ? 1 : 0;
4651
- const isOpaque = globalAlpha === 255;
4652
- const isOverwrite = blendFn.isOverwrite || false;
4653
- for (let iy = 0; iy < actualH; iy++) {
4654
- for (let ix = 0; ix < actualW; ix++) {
4655
- if (maskData[mIdx] === skipVal) {
4656
- dIdx++;
4657
- sIdx++;
4658
- mIdx++;
4659
- continue;
4660
- }
4661
- const srcCol = src32[sIdx];
4662
- const srcAlpha = srcCol >>> 24;
4663
- if (srcAlpha === 0 && !isOverwrite) {
4664
- dIdx++;
4665
- sIdx++;
4666
- mIdx++;
4667
- continue;
4668
- }
4669
- let finalCol = srcCol;
4670
- if (!isOpaque) {
4671
- const a = srcAlpha * globalAlpha + 128 >> 8;
4672
- if (a === 0 && !isOverwrite) {
4673
- dIdx++;
4674
- sIdx++;
4675
- mIdx++;
4676
- continue;
4677
- }
4678
- finalCol = (srcCol & 16777215 | a << 24) >>> 0;
4679
- }
4680
- dst32[dIdx] = blendFn(finalCol, dst32[dIdx]);
4681
- dIdx++;
4682
- sIdx++;
4683
- mIdx++;
4684
- }
4685
- dIdx += dStride;
4686
- sIdx += sStride;
4687
- mIdx += mStride;
4688
- }
4689
- }
4690
-
4691
4736
  // src/PixelData/clearPixelData.ts
4692
4737
  function clearPixelData(dst, rect) {
4693
4738
  fillPixelData(dst, 0, rect);
@@ -5040,6 +5085,8 @@ export {
5040
5085
  mutatorBlendColor,
5041
5086
  mutatorBlendPixel,
5042
5087
  mutatorBlendPixelData,
5088
+ mutatorBlendPixelDataAlphaMask,
5089
+ mutatorBlendPixelDataBinaryMask,
5043
5090
  mutatorClear,
5044
5091
  mutatorFill,
5045
5092
  mutatorFillBinaryMask,