pixel-data-js 0.32.0 → 0.34.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.prod.cjs +78 -36
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +27 -10
- package/dist/index.prod.js +76 -36
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/ImageData/copyImageData.ts +4 -2
- package/src/ImageData/extractImageData.ts +1 -2
- package/src/ImageData/extractImageDataBuffer.ts +2 -4
- package/src/ImageData/writeImageData.ts +4 -5
- package/src/ImageData/writeImageDataBuffer.ts +2 -4
- package/src/Paint/AlphaMaskPaintBuffer.ts +8 -10
- package/src/Paint/BinaryMaskPaintBuffer.ts +8 -10
- package/src/Paint/ColorPaintBuffer.ts +8 -10
- package/src/Paint/PaintRect.ts +11 -0
- package/src/Paint/_paint-types.ts +6 -0
- package/src/PixelData/extractPixelDataBuffer.ts +2 -4
- package/src/PixelData/fillPixelData.ts +1 -2
- package/src/PixelData/fillPixelDataFast.ts +1 -2
- package/src/PixelData/writePixelData.ts +55 -0
- package/src/index.ts +2 -0
package/dist/index.prod.cjs
CHANGED
|
@@ -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,
|
|
@@ -263,6 +264,7 @@ __export(src_exports, {
|
|
|
263
264
|
writeImageDataToClipboard: () => writeImageDataToClipboard,
|
|
264
265
|
writeImgBlobToClipboard: () => writeImgBlobToClipboard,
|
|
265
266
|
writePaintBufferToPixelData: () => writePaintBufferToPixelData,
|
|
267
|
+
writePixelData: () => writePixelData,
|
|
266
268
|
writePixelDataBuffer: () => writePixelDataBuffer,
|
|
267
269
|
xorFast: () => xorFast,
|
|
268
270
|
xorPerfect: () => xorPerfect
|
|
@@ -364,8 +366,7 @@ function extractImageDataBuffer(imageData, _x, _y, _w, _h) {
|
|
|
364
366
|
w: _w,
|
|
365
367
|
h: _h
|
|
366
368
|
};
|
|
367
|
-
if (w <= 0) return new Uint8ClampedArray(0);
|
|
368
|
-
if (h <= 0) return new Uint8ClampedArray(0);
|
|
369
|
+
if (w <= 0 || h <= 0) return new Uint8ClampedArray(0);
|
|
369
370
|
const srcW = imageData.width;
|
|
370
371
|
const srcH = imageData.height;
|
|
371
372
|
const src = imageData.data;
|
|
@@ -389,8 +390,7 @@ function extractImageDataBuffer(imageData, _x, _y, _w, _h) {
|
|
|
389
390
|
}
|
|
390
391
|
copyW = Math.min(copyW, srcW - srcX);
|
|
391
392
|
copyH = Math.min(copyH, srcH - srcY);
|
|
392
|
-
if (copyW <= 0) return out;
|
|
393
|
-
if (copyH <= 0) return out;
|
|
393
|
+
if (copyW <= 0 || copyH <= 0) return out;
|
|
394
394
|
const isAligned = src.byteOffset % 4 === 0;
|
|
395
395
|
if (isAligned) {
|
|
396
396
|
const srcLen32 = src.byteLength / 4;
|
|
@@ -3887,8 +3887,7 @@ function fillPixelData(dst, color, _x, _y, _w, _h) {
|
|
|
3887
3887
|
}
|
|
3888
3888
|
fillW = Math.min(fillW, dstW - dstX);
|
|
3889
3889
|
fillH = Math.min(fillH, dstH - dstY);
|
|
3890
|
-
if (fillW <= 0) return false;
|
|
3891
|
-
if (fillH <= 0) return false;
|
|
3890
|
+
if (fillW <= 0 || fillH <= 0) return false;
|
|
3892
3891
|
const dst32 = dst.data;
|
|
3893
3892
|
let hasChanged = false;
|
|
3894
3893
|
if (dstX === 0 && fillW === dstW) {
|
|
@@ -4139,12 +4138,9 @@ function makeFullPixelMutator(writer) {
|
|
|
4139
4138
|
}
|
|
4140
4139
|
|
|
4141
4140
|
// src/ImageData/copyImageData.ts
|
|
4142
|
-
function copyImageData({
|
|
4143
|
-
data
|
|
4144
|
-
width,
|
|
4145
|
-
height
|
|
4146
|
-
}) {
|
|
4147
|
-
return new ImageData(data.slice(), width, height);
|
|
4141
|
+
function copyImageData(source) {
|
|
4142
|
+
const dataCopy = new Uint8ClampedArray(source.data);
|
|
4143
|
+
return new ImageData(dataCopy, source.width, source.height);
|
|
4148
4144
|
}
|
|
4149
4145
|
function copyImageDataLike({
|
|
4150
4146
|
data,
|
|
@@ -4171,8 +4167,7 @@ function extractImageData(imageData, _x, _y, _w, _h) {
|
|
|
4171
4167
|
w: _w,
|
|
4172
4168
|
h: _h
|
|
4173
4169
|
};
|
|
4174
|
-
if (w <= 0) return null;
|
|
4175
|
-
if (h <= 0) return null;
|
|
4170
|
+
if (w <= 0 || h <= 0) return null;
|
|
4176
4171
|
const result = new ImageData(w, h);
|
|
4177
4172
|
const buffer = extractImageDataBuffer(imageData, x, y, w, h);
|
|
4178
4173
|
result.data.set(buffer);
|
|
@@ -4329,7 +4324,7 @@ function uInt32ArrayToImageDataLike(data, width, height) {
|
|
|
4329
4324
|
}
|
|
4330
4325
|
|
|
4331
4326
|
// src/ImageData/writeImageData.ts
|
|
4332
|
-
function writeImageData(target, source, x, y) {
|
|
4327
|
+
function writeImageData(target, source, x = 0, y = 0) {
|
|
4333
4328
|
const dstW = target.width;
|
|
4334
4329
|
const dstH = target.height;
|
|
4335
4330
|
const dst = target.data;
|
|
@@ -4354,8 +4349,7 @@ function writeImageData(target, source, x, y) {
|
|
|
4354
4349
|
}
|
|
4355
4350
|
copyW = Math.min(copyW, dstW - dstX);
|
|
4356
4351
|
copyH = Math.min(copyH, dstH - dstY);
|
|
4357
|
-
if (copyW <= 0) return;
|
|
4358
|
-
if (copyH <= 0) return;
|
|
4352
|
+
if (copyW <= 0 || copyH <= 0) return;
|
|
4359
4353
|
const isDstAligned = dst.byteOffset % 4 === 0;
|
|
4360
4354
|
const isSrcAligned = src.byteOffset % 4 === 0;
|
|
4361
4355
|
if (isDstAligned && isSrcAligned) {
|
|
@@ -4397,8 +4391,7 @@ function writeImageDataBuffer(target, data, _x, _y, _w, _h) {
|
|
|
4397
4391
|
w = _w;
|
|
4398
4392
|
h = _h;
|
|
4399
4393
|
}
|
|
4400
|
-
if (w <= 0) return;
|
|
4401
|
-
if (h <= 0) return;
|
|
4394
|
+
if (w <= 0 || h <= 0) return;
|
|
4402
4395
|
const dstW = target.width;
|
|
4403
4396
|
const dstH = target.height;
|
|
4404
4397
|
const dst = target.data;
|
|
@@ -4420,8 +4413,7 @@ function writeImageDataBuffer(target, data, _x, _y, _w, _h) {
|
|
|
4420
4413
|
}
|
|
4421
4414
|
copyW = Math.min(copyW, dstW - dstX);
|
|
4422
4415
|
copyH = Math.min(copyH, dstH - dstY);
|
|
4423
|
-
if (copyW <= 0) return;
|
|
4424
|
-
if (copyH <= 0) return;
|
|
4416
|
+
if (copyW <= 0 || copyH <= 0) return;
|
|
4425
4417
|
const isDstAligned = dst.byteOffset % 4 === 0;
|
|
4426
4418
|
const isSrcAligned = data.byteOffset % 4 === 0;
|
|
4427
4419
|
if (isDstAligned && isSrcAligned) {
|
|
@@ -5459,7 +5451,7 @@ var AlphaMaskPaintBuffer = class {
|
|
|
5459
5451
|
});
|
|
5460
5452
|
return changed;
|
|
5461
5453
|
}
|
|
5462
|
-
paintRect(alpha,
|
|
5454
|
+
paintRect(alpha, brush, x0, y0, x1 = x0, y1 = y0) {
|
|
5463
5455
|
const scratch = this.scratchBounds;
|
|
5464
5456
|
const lookup = this.lookup;
|
|
5465
5457
|
const tilePool = this.tilePool;
|
|
@@ -5467,8 +5459,10 @@ var AlphaMaskPaintBuffer = class {
|
|
|
5467
5459
|
const tileShift = config.tileShift;
|
|
5468
5460
|
const tileMask = config.tileMask;
|
|
5469
5461
|
const target = config.target;
|
|
5470
|
-
const
|
|
5471
|
-
const
|
|
5462
|
+
const brushWidth = brush.w;
|
|
5463
|
+
const brushHeight = brush.h;
|
|
5464
|
+
const centerOffsetX = brush.centerOffsetX;
|
|
5465
|
+
const centerOffsetY = brush.centerOffsetY;
|
|
5472
5466
|
const trimRectBoundsFn = this.trimRectBoundsFn;
|
|
5473
5467
|
const eachTileInBoundsFn = this.eachTileInBoundsFn;
|
|
5474
5468
|
let changed = false;
|
|
@@ -5568,7 +5562,7 @@ var BinaryMaskPaintBuffer = class {
|
|
|
5568
5562
|
});
|
|
5569
5563
|
return changed;
|
|
5570
5564
|
}
|
|
5571
|
-
paintRect(
|
|
5565
|
+
paintRect(brush, x0, y0, x1 = x0, y1 = y0) {
|
|
5572
5566
|
const scratch = this.scratchBounds;
|
|
5573
5567
|
const lookup = this.lookup;
|
|
5574
5568
|
const tilePool = this.tilePool;
|
|
@@ -5576,8 +5570,10 @@ var BinaryMaskPaintBuffer = class {
|
|
|
5576
5570
|
const tileShift = config.tileShift;
|
|
5577
5571
|
const tileMask = config.tileMask;
|
|
5578
5572
|
const target = config.target;
|
|
5579
|
-
const
|
|
5580
|
-
const
|
|
5573
|
+
const brushWidth = brush.w;
|
|
5574
|
+
const brushHeight = brush.h;
|
|
5575
|
+
const centerOffsetX = brush.centerOffsetX;
|
|
5576
|
+
const centerOffsetY = brush.centerOffsetY;
|
|
5581
5577
|
const trimRectBoundsFn = this.trimRectBoundsFn;
|
|
5582
5578
|
const eachTileInBoundsFn = this.eachTileInBoundsFn;
|
|
5583
5579
|
let changed = false;
|
|
@@ -5728,7 +5724,7 @@ var ColorPaintBuffer = class {
|
|
|
5728
5724
|
});
|
|
5729
5725
|
return changed;
|
|
5730
5726
|
}
|
|
5731
|
-
paintRect(color,
|
|
5727
|
+
paintRect(color, brush, x0, y0, x1 = x0, y1 = y0) {
|
|
5732
5728
|
const alphaIsZero = color >>> 24 === 0;
|
|
5733
5729
|
if (alphaIsZero) return false;
|
|
5734
5730
|
const scratch = this.scratchBounds;
|
|
@@ -5738,8 +5734,10 @@ var ColorPaintBuffer = class {
|
|
|
5738
5734
|
const tileShift = config.tileShift;
|
|
5739
5735
|
const tileMask = config.tileMask;
|
|
5740
5736
|
const target = config.target;
|
|
5741
|
-
const
|
|
5742
|
-
const
|
|
5737
|
+
const brushWidth = brush.w;
|
|
5738
|
+
const brushHeight = brush.h;
|
|
5739
|
+
const centerOffsetX = brush.centerOffsetX;
|
|
5740
|
+
const centerOffsetY = brush.centerOffsetY;
|
|
5743
5741
|
let changed = false;
|
|
5744
5742
|
forEachLinePoint(x0, y0, x1, y1, (px, py) => {
|
|
5745
5743
|
const topLeftX = Math.floor(px + centerOffsetX);
|
|
@@ -6162,6 +6160,16 @@ function makeRectFalloffPaintAlphaMask(width, height, fallOff = (d) => d) {
|
|
|
6162
6160
|
};
|
|
6163
6161
|
}
|
|
6164
6162
|
|
|
6163
|
+
// src/Paint/PaintRect.ts
|
|
6164
|
+
function makePaintRect(w, h) {
|
|
6165
|
+
return {
|
|
6166
|
+
w,
|
|
6167
|
+
h,
|
|
6168
|
+
centerOffsetX: -(w - 1 >> 1),
|
|
6169
|
+
centerOffsetY: -(h - 1 >> 1)
|
|
6170
|
+
};
|
|
6171
|
+
}
|
|
6172
|
+
|
|
6165
6173
|
// src/PixelData/ReusablePixelData.ts
|
|
6166
6174
|
function makeReusablePixelData() {
|
|
6167
6175
|
const pixelData = {
|
|
@@ -6412,8 +6420,7 @@ function fillPixelDataFast(dst, color, _x, _y, _w, _h) {
|
|
|
6412
6420
|
}
|
|
6413
6421
|
fillW = Math.min(fillW, dstW - dstX);
|
|
6414
6422
|
fillH = Math.min(fillH, dstH - dstY);
|
|
6415
|
-
if (fillW <= 0) return;
|
|
6416
|
-
if (fillH <= 0) return;
|
|
6423
|
+
if (fillW <= 0 || fillH <= 0) return;
|
|
6417
6424
|
const dst32 = dst.data;
|
|
6418
6425
|
const dw = dst.w;
|
|
6419
6426
|
if (fillW === dw && fillH === dst.h && dstX === 0 && dstY === 0) {
|
|
@@ -6459,8 +6466,7 @@ function extractPixelDataBuffer(source, _x, _y, _w, _h) {
|
|
|
6459
6466
|
const srcW = source.w;
|
|
6460
6467
|
const srcH = source.h;
|
|
6461
6468
|
const srcData = source.data;
|
|
6462
|
-
if (w <= 0) return new Uint32Array(0);
|
|
6463
|
-
if (h <= 0) return new Uint32Array(0);
|
|
6469
|
+
if (w <= 0 || h <= 0) return new Uint32Array(0);
|
|
6464
6470
|
const dstData = new Uint32Array(w * h);
|
|
6465
6471
|
let srcX = x;
|
|
6466
6472
|
let srcY = y;
|
|
@@ -6480,8 +6486,7 @@ function extractPixelDataBuffer(source, _x, _y, _w, _h) {
|
|
|
6480
6486
|
}
|
|
6481
6487
|
copyW = Math.min(copyW, srcW - srcX);
|
|
6482
6488
|
copyH = Math.min(copyH, srcH - srcY);
|
|
6483
|
-
if (copyW <= 0) return dstData;
|
|
6484
|
-
if (copyH <= 0) return dstData;
|
|
6489
|
+
if (copyW <= 0 || copyH <= 0) return dstData;
|
|
6485
6490
|
for (let row = 0; row < copyH; row++) {
|
|
6486
6491
|
const srcStart = (srcY + row) * srcW + srcX;
|
|
6487
6492
|
const dstStart = (dstY + row) * w + dstX;
|
|
@@ -6727,6 +6732,41 @@ function writePaintBufferToPixelData(target, paintBuffer, writePixelDataBufferFn
|
|
|
6727
6732
|
}
|
|
6728
6733
|
}
|
|
6729
6734
|
}
|
|
6735
|
+
|
|
6736
|
+
// src/PixelData/writePixelData.ts
|
|
6737
|
+
function writePixelData(target, source, x = 0, y = 0) {
|
|
6738
|
+
const dstW = target.w;
|
|
6739
|
+
const dstH = target.h;
|
|
6740
|
+
const dst = target.data;
|
|
6741
|
+
const srcW = source.w;
|
|
6742
|
+
const srcH = source.h;
|
|
6743
|
+
const src = source.data;
|
|
6744
|
+
let dstX = x;
|
|
6745
|
+
let dstY = y;
|
|
6746
|
+
let srcX = 0;
|
|
6747
|
+
let srcY = 0;
|
|
6748
|
+
let copyW = srcW;
|
|
6749
|
+
let copyH = srcH;
|
|
6750
|
+
if (dstX < 0) {
|
|
6751
|
+
srcX = -dstX;
|
|
6752
|
+
copyW += dstX;
|
|
6753
|
+
dstX = 0;
|
|
6754
|
+
}
|
|
6755
|
+
if (dstY < 0) {
|
|
6756
|
+
srcY = -dstY;
|
|
6757
|
+
copyH += dstY;
|
|
6758
|
+
dstY = 0;
|
|
6759
|
+
}
|
|
6760
|
+
copyW = Math.min(copyW, dstW - dstX);
|
|
6761
|
+
copyH = Math.min(copyH, dstH - dstY);
|
|
6762
|
+
if (copyW <= 0 || copyH <= 0) return;
|
|
6763
|
+
for (let row = 0; row < copyH; row++) {
|
|
6764
|
+
const dstStart = (dstY + row) * dstW + dstX;
|
|
6765
|
+
const srcStart = (srcY + row) * srcW + srcX;
|
|
6766
|
+
const chunk = src.subarray(srcStart, srcStart + copyW);
|
|
6767
|
+
dst.set(chunk, dstStart);
|
|
6768
|
+
}
|
|
6769
|
+
}
|
|
6730
6770
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6731
6771
|
0 && (module.exports = {
|
|
6732
6772
|
AlphaMaskPaintBuffer,
|
|
@@ -6879,6 +6919,7 @@ function writePaintBufferToPixelData(target, paintBuffer, writePixelDataBufferFn
|
|
|
6879
6919
|
makePaintAlphaMask,
|
|
6880
6920
|
makePaintBinaryMask,
|
|
6881
6921
|
makePaintCursorRenderer,
|
|
6922
|
+
makePaintRect,
|
|
6882
6923
|
makePerfectBlendModeRegistry,
|
|
6883
6924
|
makePixelCanvas,
|
|
6884
6925
|
makePixelData,
|
|
@@ -6972,6 +7013,7 @@ function writePaintBufferToPixelData(target, paintBuffer, writePixelDataBufferFn
|
|
|
6972
7013
|
writeImageDataToClipboard,
|
|
6973
7014
|
writeImgBlobToClipboard,
|
|
6974
7015
|
writePaintBufferToPixelData,
|
|
7016
|
+
writePixelData,
|
|
6975
7017
|
writePixelDataBuffer,
|
|
6976
7018
|
xorFast,
|
|
6977
7019
|
xorPerfect
|