pixel-data-js 0.33.0 → 0.35.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.
@@ -170,6 +170,7 @@ __export(src_exports, {
170
170
  makePaintAlphaMask: () => makePaintAlphaMask,
171
171
  makePaintBinaryMask: () => makePaintBinaryMask,
172
172
  makePaintCursorRenderer: () => makePaintCursorRenderer,
173
+ makePaintRect: () => makePaintRect,
173
174
  makePerfectBlendModeRegistry: () => makePerfectBlendModeRegistry,
174
175
  makePixelCanvas: () => makePixelCanvas,
175
176
  makePixelData: () => makePixelData,
@@ -5450,7 +5451,7 @@ var AlphaMaskPaintBuffer = class {
5450
5451
  });
5451
5452
  return changed;
5452
5453
  }
5453
- paintRect(alpha, brushWidth, brushHeight, x0, y0, x1 = x0, y1 = y0) {
5454
+ paintRect(alpha, brush, x0, y0, x1 = x0, y1 = y0) {
5454
5455
  const scratch = this.scratchBounds;
5455
5456
  const lookup = this.lookup;
5456
5457
  const tilePool = this.tilePool;
@@ -5458,8 +5459,10 @@ var AlphaMaskPaintBuffer = class {
5458
5459
  const tileShift = config.tileShift;
5459
5460
  const tileMask = config.tileMask;
5460
5461
  const target = config.target;
5461
- const centerOffsetX = -(brushWidth - 1 >> 1);
5462
- const centerOffsetY = -(brushHeight - 1 >> 1);
5462
+ const brushWidth = brush.w;
5463
+ const brushHeight = brush.h;
5464
+ const centerOffsetX = brush.centerOffsetX;
5465
+ const centerOffsetY = brush.centerOffsetY;
5463
5466
  const trimRectBoundsFn = this.trimRectBoundsFn;
5464
5467
  const eachTileInBoundsFn = this.eachTileInBoundsFn;
5465
5468
  let changed = false;
@@ -5559,7 +5562,7 @@ var BinaryMaskPaintBuffer = class {
5559
5562
  });
5560
5563
  return changed;
5561
5564
  }
5562
- paintRect(brushWidth, brushHeight, x0, y0, x1 = x0, y1 = y0) {
5565
+ paintRect(brush, x0, y0, x1 = x0, y1 = y0) {
5563
5566
  const scratch = this.scratchBounds;
5564
5567
  const lookup = this.lookup;
5565
5568
  const tilePool = this.tilePool;
@@ -5567,8 +5570,10 @@ var BinaryMaskPaintBuffer = class {
5567
5570
  const tileShift = config.tileShift;
5568
5571
  const tileMask = config.tileMask;
5569
5572
  const target = config.target;
5570
- const centerOffsetX = -(brushWidth - 1 >> 1);
5571
- const centerOffsetY = -(brushHeight - 1 >> 1);
5573
+ const brushWidth = brush.w;
5574
+ const brushHeight = brush.h;
5575
+ const centerOffsetX = brush.centerOffsetX;
5576
+ const centerOffsetY = brush.centerOffsetY;
5572
5577
  const trimRectBoundsFn = this.trimRectBoundsFn;
5573
5578
  const eachTileInBoundsFn = this.eachTileInBoundsFn;
5574
5579
  let changed = false;
@@ -5719,7 +5724,7 @@ var ColorPaintBuffer = class {
5719
5724
  });
5720
5725
  return changed;
5721
5726
  }
5722
- paintRect(color, brushWidth, brushHeight, x0, y0, x1 = x0, y1 = y0) {
5727
+ paintRect(color, brush, x0, y0, x1 = x0, y1 = y0) {
5723
5728
  const alphaIsZero = color >>> 24 === 0;
5724
5729
  if (alphaIsZero) return false;
5725
5730
  const scratch = this.scratchBounds;
@@ -5729,8 +5734,10 @@ var ColorPaintBuffer = class {
5729
5734
  const tileShift = config.tileShift;
5730
5735
  const tileMask = config.tileMask;
5731
5736
  const target = config.target;
5732
- const centerOffsetX = -(brushWidth - 1 >> 1);
5733
- const centerOffsetY = -(brushHeight - 1 >> 1);
5737
+ const brushWidth = brush.w;
5738
+ const brushHeight = brush.h;
5739
+ const centerOffsetX = brush.centerOffsetX;
5740
+ const centerOffsetY = brush.centerOffsetY;
5734
5741
  let changed = false;
5735
5742
  forEachLinePoint(x0, y0, x1, y1, (px, py) => {
5736
5743
  const topLeftX = Math.floor(px + centerOffsetX);
@@ -6153,6 +6160,19 @@ function makeRectFalloffPaintAlphaMask(width, height, fallOff = (d) => d) {
6153
6160
  };
6154
6161
  }
6155
6162
 
6163
+ // src/Paint/PaintRect.ts
6164
+ function makePaintRect(w, h) {
6165
+ return {
6166
+ type: null,
6167
+ outlineType: 2 /* RECT */,
6168
+ data: null,
6169
+ w,
6170
+ h,
6171
+ centerOffsetX: -(w - 1 >> 1),
6172
+ centerOffsetY: -(h - 1 >> 1)
6173
+ };
6174
+ }
6175
+
6156
6176
  // src/PixelData/ReusablePixelData.ts
6157
6177
  function makeReusablePixelData() {
6158
6178
  const pixelData = {
@@ -6182,31 +6202,34 @@ function makePaintCursorRenderer(reusableCanvasFactory) {
6182
6202
  const getPixelData = makeReusablePixelData();
6183
6203
  let _color = packColor(0, 255, 255, 255);
6184
6204
  let _scale = 1;
6185
- let currentMask = {
6186
- type: 1 /* BINARY */,
6205
+ let currentBrush = {
6206
+ type: null,
6187
6207
  outlineType: 2 /* RECT */,
6188
6208
  w: 1,
6189
6209
  h: 1,
6190
6210
  centerOffsetX: -(10 - 1 >> 1),
6191
- centerOffsetY: -(10 - 1 >> 1)
6211
+ centerOffsetY: -(10 - 1 >> 1),
6212
+ data: null
6192
6213
  };
6193
6214
  let outline;
6194
6215
  function update(paintMask, scale, color, alphaThreshold = 127) {
6195
- currentMask = paintMask ?? currentMask;
6216
+ currentBrush = paintMask ?? currentBrush;
6196
6217
  _scale = scale ?? _scale;
6197
6218
  _color = color ?? _color;
6198
- updateBuffer(currentMask.w * _scale + 2 * _scale, currentMask.h * _scale + 2 * _scale);
6199
- if (currentMask.type === 1 /* BINARY */) {
6200
- if (currentMask.outlineType === 1 /* CIRCLE */) {
6201
- outline = makeCircleBinaryMaskOutline(currentMask.w, _scale);
6202
- } else if (currentMask.outlineType === 2 /* RECT */) {
6203
- outline = makeRectBinaryMaskOutline(currentMask.w, currentMask.h, _scale);
6204
- } else if (currentMask.outlineType === 0 /* MASKED */) {
6205
- outline = makeBinaryMaskOutline(currentMask, _scale);
6219
+ updateBuffer(currentBrush.w * _scale + 2 * _scale, currentBrush.h * _scale + 2 * _scale);
6220
+ if (currentBrush.type === 1 /* BINARY */) {
6221
+ if (currentBrush.outlineType === 1 /* CIRCLE */) {
6222
+ outline = makeCircleBinaryMaskOutline(currentBrush.w, _scale);
6223
+ } else if (currentBrush.outlineType === 2 /* RECT */) {
6224
+ outline = makeRectBinaryMaskOutline(currentBrush.w, currentBrush.h, _scale);
6225
+ } else if (currentBrush.outlineType === 0 /* MASKED */) {
6226
+ outline = makeBinaryMaskOutline(currentBrush, _scale);
6206
6227
  }
6207
- } else if (currentMask.type === 0 /* ALPHA */) {
6208
- const mask = makeBinaryMaskFromAlphaMask(currentMask, alphaThreshold);
6228
+ } else if (currentBrush.type === 0 /* ALPHA */) {
6229
+ const mask = makeBinaryMaskFromAlphaMask(currentBrush, alphaThreshold);
6209
6230
  outline = makeBinaryMaskOutline(mask, _scale);
6231
+ } else {
6232
+ outline = makeRectBinaryMaskOutline(currentBrush.w, currentBrush.h, _scale);
6210
6233
  }
6211
6234
  const pixelData = getPixelData(outline.w, outline.h);
6212
6235
  fillPixelDataBinaryMask(pixelData, _color, outline);
@@ -6219,10 +6242,10 @@ function makePaintCursorRenderer(reusableCanvasFactory) {
6219
6242
  h: 0
6220
6243
  };
6221
6244
  function getBounds(centerX, centerY) {
6222
- boundsScratch.x = centerX + currentMask.centerOffsetX;
6223
- boundsScratch.y = centerY + currentMask.centerOffsetY;
6224
- boundsScratch.w = currentMask.w;
6225
- boundsScratch.h = currentMask.h;
6245
+ boundsScratch.x = centerX + currentBrush.centerOffsetX;
6246
+ boundsScratch.y = centerY + currentBrush.centerOffsetY;
6247
+ boundsScratch.w = currentBrush.w;
6248
+ boundsScratch.h = currentBrush.h;
6226
6249
  return boundsScratch;
6227
6250
  }
6228
6251
  const boundsScaledScratch = {
@@ -6232,22 +6255,22 @@ function makePaintCursorRenderer(reusableCanvasFactory) {
6232
6255
  h: 0
6233
6256
  };
6234
6257
  function getOutlineBoundsScaled(centerX, centerY) {
6235
- boundsScaledScratch.x = centerX * _scale + currentMask.centerOffsetX * _scale - 1;
6236
- boundsScaledScratch.y = centerY * _scale + currentMask.centerOffsetY * _scale - 1;
6237
- boundsScaledScratch.w = currentMask.w * _scale;
6238
- boundsScaledScratch.h = currentMask.h * _scale;
6258
+ boundsScaledScratch.x = centerX * _scale + currentBrush.centerOffsetX * _scale - 1;
6259
+ boundsScaledScratch.y = centerY * _scale + currentBrush.centerOffsetY * _scale - 1;
6260
+ boundsScaledScratch.w = currentBrush.w * _scale;
6261
+ boundsScaledScratch.h = currentBrush.h * _scale;
6239
6262
  return boundsScaledScratch;
6240
6263
  }
6241
6264
  function draw(drawCtx, centerX, centerY) {
6242
- const dx = centerX * _scale + currentMask.centerOffsetX * _scale - 1;
6243
- const dy = centerY * _scale + currentMask.centerOffsetY * _scale - 1;
6265
+ const dx = centerX * _scale + currentBrush.centerOffsetX * _scale - 1;
6266
+ const dy = centerY * _scale + currentBrush.centerOffsetY * _scale - 1;
6244
6267
  drawCtx.drawImage(canvas, Math.floor(dx), Math.floor(dy));
6245
6268
  }
6246
6269
  function getSettings() {
6247
6270
  return {
6248
6271
  color: _color,
6249
6272
  scale: _scale,
6250
- currentMask
6273
+ currentBrush
6251
6274
  };
6252
6275
  }
6253
6276
  return {
@@ -6902,6 +6925,7 @@ function writePixelData(target, source, x = 0, y = 0) {
6902
6925
  makePaintAlphaMask,
6903
6926
  makePaintBinaryMask,
6904
6927
  makePaintCursorRenderer,
6928
+ makePaintRect,
6905
6929
  makePerfectBlendModeRegistry,
6906
6930
  makePixelCanvas,
6907
6931
  makePixelData,