pixel-data-js 0.19.2 → 0.21.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
@@ -3056,21 +3056,24 @@ var mutatorBlendPixelData = ((writer, deps = defaults11) => {
3056
3056
 
3057
3057
  // src/PixelData/fillPixelData.ts
3058
3058
  var SCRATCH_RECT = makeClippedRect();
3059
- function fillPixelData(dst, color, _x, _y, _w, _h) {
3059
+ function fillPixelData(dst, color, _x, _y, _w, _h, _mask) {
3060
3060
  let x;
3061
3061
  let y;
3062
3062
  let w;
3063
3063
  let h;
3064
+ let mask;
3064
3065
  if (typeof _x === "object") {
3065
3066
  x = _x.x ?? 0;
3066
3067
  y = _x.y ?? 0;
3067
3068
  w = _x.w ?? dst.width;
3068
3069
  h = _x.h ?? dst.height;
3070
+ mask = _x.mask;
3069
3071
  } else if (typeof _x === "number") {
3070
3072
  x = _x;
3071
3073
  y = _y;
3072
3074
  w = _w;
3073
3075
  h = _h;
3076
+ mask = _mask;
3074
3077
  } else {
3075
3078
  x = 0;
3076
3079
  y = 0;
@@ -3091,10 +3094,28 @@ function fillPixelData(dst, color, _x, _y, _w, _h) {
3091
3094
  dst32.fill(color);
3092
3095
  return;
3093
3096
  }
3094
- for (let iy = 0; iy < actualH; iy++) {
3095
- const start = (finalY + iy) * dw + finalX;
3096
- const end = start + actualW;
3097
- dst32.fill(color, start, end);
3097
+ if (mask) {
3098
+ for (let iy = 0; iy < actualH; iy++) {
3099
+ const currentY = finalY + iy;
3100
+ const maskY = currentY - y;
3101
+ const maskOffset = maskY * w;
3102
+ for (let ix = 0; ix < actualW; ix++) {
3103
+ const currentX = finalX + ix;
3104
+ const maskX = currentX - x;
3105
+ const maskIndex = maskOffset + maskX;
3106
+ const isMasked = mask[maskIndex];
3107
+ if (isMasked) {
3108
+ const dstIndex = currentY * dw + currentX;
3109
+ dst32[dstIndex] = color;
3110
+ }
3111
+ }
3112
+ }
3113
+ } else {
3114
+ for (let iy = 0; iy < actualH; iy++) {
3115
+ const start = (finalY + iy) * dw + finalX;
3116
+ const end = start + actualW;
3117
+ dst32.fill(color, start, end);
3118
+ }
3098
3119
  }
3099
3120
  }
3100
3121
 
@@ -3112,10 +3133,11 @@ var mutatorClear = ((writer, deps = defaults12) => {
3112
3133
  x = 0,
3113
3134
  y = 0,
3114
3135
  w = writer.target.width,
3115
- h = writer.target.height
3136
+ h = writer.target.height,
3137
+ mask = void 0
3116
3138
  } = rect;
3117
3139
  writer.accumulator.storeRegionBeforeState(x, y, w, h);
3118
- fillPixelData2(writer.target, 0, x, y, w, h);
3140
+ fillPixelData2(writer.target, 0, x, y, w, h, mask);
3119
3141
  }
3120
3142
  };
3121
3143
  });
@@ -3134,10 +3156,11 @@ var mutatorFill = ((writer, deps = defaults13) => {
3134
3156
  x = 0,
3135
3157
  y = 0,
3136
3158
  w = writer.target.width,
3137
- h = writer.target.height
3159
+ h = writer.target.height,
3160
+ mask = void 0
3138
3161
  } = rect;
3139
3162
  writer.accumulator.storeRegionBeforeState(x, y, w, h);
3140
- fillPixelData2(writer.target, color, x, y, w, h);
3163
+ fillPixelData2(writer.target, color, x, y, w, h, mask);
3141
3164
  }
3142
3165
  };
3143
3166
  });