pixel-data-js 0.32.0 → 0.33.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 +51 -27
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +13 -4
- package/dist/index.prod.js +50 -27
- 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/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 +1 -0
package/dist/index.prod.cjs
CHANGED
|
@@ -263,6 +263,7 @@ __export(src_exports, {
|
|
|
263
263
|
writeImageDataToClipboard: () => writeImageDataToClipboard,
|
|
264
264
|
writeImgBlobToClipboard: () => writeImgBlobToClipboard,
|
|
265
265
|
writePaintBufferToPixelData: () => writePaintBufferToPixelData,
|
|
266
|
+
writePixelData: () => writePixelData,
|
|
266
267
|
writePixelDataBuffer: () => writePixelDataBuffer,
|
|
267
268
|
xorFast: () => xorFast,
|
|
268
269
|
xorPerfect: () => xorPerfect
|
|
@@ -364,8 +365,7 @@ function extractImageDataBuffer(imageData, _x, _y, _w, _h) {
|
|
|
364
365
|
w: _w,
|
|
365
366
|
h: _h
|
|
366
367
|
};
|
|
367
|
-
if (w <= 0) return new Uint8ClampedArray(0);
|
|
368
|
-
if (h <= 0) return new Uint8ClampedArray(0);
|
|
368
|
+
if (w <= 0 || h <= 0) return new Uint8ClampedArray(0);
|
|
369
369
|
const srcW = imageData.width;
|
|
370
370
|
const srcH = imageData.height;
|
|
371
371
|
const src = imageData.data;
|
|
@@ -389,8 +389,7 @@ function extractImageDataBuffer(imageData, _x, _y, _w, _h) {
|
|
|
389
389
|
}
|
|
390
390
|
copyW = Math.min(copyW, srcW - srcX);
|
|
391
391
|
copyH = Math.min(copyH, srcH - srcY);
|
|
392
|
-
if (copyW <= 0) return out;
|
|
393
|
-
if (copyH <= 0) return out;
|
|
392
|
+
if (copyW <= 0 || copyH <= 0) return out;
|
|
394
393
|
const isAligned = src.byteOffset % 4 === 0;
|
|
395
394
|
if (isAligned) {
|
|
396
395
|
const srcLen32 = src.byteLength / 4;
|
|
@@ -3887,8 +3886,7 @@ function fillPixelData(dst, color, _x, _y, _w, _h) {
|
|
|
3887
3886
|
}
|
|
3888
3887
|
fillW = Math.min(fillW, dstW - dstX);
|
|
3889
3888
|
fillH = Math.min(fillH, dstH - dstY);
|
|
3890
|
-
if (fillW <= 0) return false;
|
|
3891
|
-
if (fillH <= 0) return false;
|
|
3889
|
+
if (fillW <= 0 || fillH <= 0) return false;
|
|
3892
3890
|
const dst32 = dst.data;
|
|
3893
3891
|
let hasChanged = false;
|
|
3894
3892
|
if (dstX === 0 && fillW === dstW) {
|
|
@@ -4139,12 +4137,9 @@ function makeFullPixelMutator(writer) {
|
|
|
4139
4137
|
}
|
|
4140
4138
|
|
|
4141
4139
|
// src/ImageData/copyImageData.ts
|
|
4142
|
-
function copyImageData({
|
|
4143
|
-
data
|
|
4144
|
-
width,
|
|
4145
|
-
height
|
|
4146
|
-
}) {
|
|
4147
|
-
return new ImageData(data.slice(), width, height);
|
|
4140
|
+
function copyImageData(source) {
|
|
4141
|
+
const dataCopy = new Uint8ClampedArray(source.data);
|
|
4142
|
+
return new ImageData(dataCopy, source.width, source.height);
|
|
4148
4143
|
}
|
|
4149
4144
|
function copyImageDataLike({
|
|
4150
4145
|
data,
|
|
@@ -4171,8 +4166,7 @@ function extractImageData(imageData, _x, _y, _w, _h) {
|
|
|
4171
4166
|
w: _w,
|
|
4172
4167
|
h: _h
|
|
4173
4168
|
};
|
|
4174
|
-
if (w <= 0) return null;
|
|
4175
|
-
if (h <= 0) return null;
|
|
4169
|
+
if (w <= 0 || h <= 0) return null;
|
|
4176
4170
|
const result = new ImageData(w, h);
|
|
4177
4171
|
const buffer = extractImageDataBuffer(imageData, x, y, w, h);
|
|
4178
4172
|
result.data.set(buffer);
|
|
@@ -4329,7 +4323,7 @@ function uInt32ArrayToImageDataLike(data, width, height) {
|
|
|
4329
4323
|
}
|
|
4330
4324
|
|
|
4331
4325
|
// src/ImageData/writeImageData.ts
|
|
4332
|
-
function writeImageData(target, source, x, y) {
|
|
4326
|
+
function writeImageData(target, source, x = 0, y = 0) {
|
|
4333
4327
|
const dstW = target.width;
|
|
4334
4328
|
const dstH = target.height;
|
|
4335
4329
|
const dst = target.data;
|
|
@@ -4354,8 +4348,7 @@ function writeImageData(target, source, x, y) {
|
|
|
4354
4348
|
}
|
|
4355
4349
|
copyW = Math.min(copyW, dstW - dstX);
|
|
4356
4350
|
copyH = Math.min(copyH, dstH - dstY);
|
|
4357
|
-
if (copyW <= 0) return;
|
|
4358
|
-
if (copyH <= 0) return;
|
|
4351
|
+
if (copyW <= 0 || copyH <= 0) return;
|
|
4359
4352
|
const isDstAligned = dst.byteOffset % 4 === 0;
|
|
4360
4353
|
const isSrcAligned = src.byteOffset % 4 === 0;
|
|
4361
4354
|
if (isDstAligned && isSrcAligned) {
|
|
@@ -4397,8 +4390,7 @@ function writeImageDataBuffer(target, data, _x, _y, _w, _h) {
|
|
|
4397
4390
|
w = _w;
|
|
4398
4391
|
h = _h;
|
|
4399
4392
|
}
|
|
4400
|
-
if (w <= 0) return;
|
|
4401
|
-
if (h <= 0) return;
|
|
4393
|
+
if (w <= 0 || h <= 0) return;
|
|
4402
4394
|
const dstW = target.width;
|
|
4403
4395
|
const dstH = target.height;
|
|
4404
4396
|
const dst = target.data;
|
|
@@ -4420,8 +4412,7 @@ function writeImageDataBuffer(target, data, _x, _y, _w, _h) {
|
|
|
4420
4412
|
}
|
|
4421
4413
|
copyW = Math.min(copyW, dstW - dstX);
|
|
4422
4414
|
copyH = Math.min(copyH, dstH - dstY);
|
|
4423
|
-
if (copyW <= 0) return;
|
|
4424
|
-
if (copyH <= 0) return;
|
|
4415
|
+
if (copyW <= 0 || copyH <= 0) return;
|
|
4425
4416
|
const isDstAligned = dst.byteOffset % 4 === 0;
|
|
4426
4417
|
const isSrcAligned = data.byteOffset % 4 === 0;
|
|
4427
4418
|
if (isDstAligned && isSrcAligned) {
|
|
@@ -6412,8 +6403,7 @@ function fillPixelDataFast(dst, color, _x, _y, _w, _h) {
|
|
|
6412
6403
|
}
|
|
6413
6404
|
fillW = Math.min(fillW, dstW - dstX);
|
|
6414
6405
|
fillH = Math.min(fillH, dstH - dstY);
|
|
6415
|
-
if (fillW <= 0) return;
|
|
6416
|
-
if (fillH <= 0) return;
|
|
6406
|
+
if (fillW <= 0 || fillH <= 0) return;
|
|
6417
6407
|
const dst32 = dst.data;
|
|
6418
6408
|
const dw = dst.w;
|
|
6419
6409
|
if (fillW === dw && fillH === dst.h && dstX === 0 && dstY === 0) {
|
|
@@ -6459,8 +6449,7 @@ function extractPixelDataBuffer(source, _x, _y, _w, _h) {
|
|
|
6459
6449
|
const srcW = source.w;
|
|
6460
6450
|
const srcH = source.h;
|
|
6461
6451
|
const srcData = source.data;
|
|
6462
|
-
if (w <= 0) return new Uint32Array(0);
|
|
6463
|
-
if (h <= 0) return new Uint32Array(0);
|
|
6452
|
+
if (w <= 0 || h <= 0) return new Uint32Array(0);
|
|
6464
6453
|
const dstData = new Uint32Array(w * h);
|
|
6465
6454
|
let srcX = x;
|
|
6466
6455
|
let srcY = y;
|
|
@@ -6480,8 +6469,7 @@ function extractPixelDataBuffer(source, _x, _y, _w, _h) {
|
|
|
6480
6469
|
}
|
|
6481
6470
|
copyW = Math.min(copyW, srcW - srcX);
|
|
6482
6471
|
copyH = Math.min(copyH, srcH - srcY);
|
|
6483
|
-
if (copyW <= 0) return dstData;
|
|
6484
|
-
if (copyH <= 0) return dstData;
|
|
6472
|
+
if (copyW <= 0 || copyH <= 0) return dstData;
|
|
6485
6473
|
for (let row = 0; row < copyH; row++) {
|
|
6486
6474
|
const srcStart = (srcY + row) * srcW + srcX;
|
|
6487
6475
|
const dstStart = (dstY + row) * w + dstX;
|
|
@@ -6727,6 +6715,41 @@ function writePaintBufferToPixelData(target, paintBuffer, writePixelDataBufferFn
|
|
|
6727
6715
|
}
|
|
6728
6716
|
}
|
|
6729
6717
|
}
|
|
6718
|
+
|
|
6719
|
+
// src/PixelData/writePixelData.ts
|
|
6720
|
+
function writePixelData(target, source, x = 0, y = 0) {
|
|
6721
|
+
const dstW = target.w;
|
|
6722
|
+
const dstH = target.h;
|
|
6723
|
+
const dst = target.data;
|
|
6724
|
+
const srcW = source.w;
|
|
6725
|
+
const srcH = source.h;
|
|
6726
|
+
const src = source.data;
|
|
6727
|
+
let dstX = x;
|
|
6728
|
+
let dstY = y;
|
|
6729
|
+
let srcX = 0;
|
|
6730
|
+
let srcY = 0;
|
|
6731
|
+
let copyW = srcW;
|
|
6732
|
+
let copyH = srcH;
|
|
6733
|
+
if (dstX < 0) {
|
|
6734
|
+
srcX = -dstX;
|
|
6735
|
+
copyW += dstX;
|
|
6736
|
+
dstX = 0;
|
|
6737
|
+
}
|
|
6738
|
+
if (dstY < 0) {
|
|
6739
|
+
srcY = -dstY;
|
|
6740
|
+
copyH += dstY;
|
|
6741
|
+
dstY = 0;
|
|
6742
|
+
}
|
|
6743
|
+
copyW = Math.min(copyW, dstW - dstX);
|
|
6744
|
+
copyH = Math.min(copyH, dstH - dstY);
|
|
6745
|
+
if (copyW <= 0 || copyH <= 0) return;
|
|
6746
|
+
for (let row = 0; row < copyH; row++) {
|
|
6747
|
+
const dstStart = (dstY + row) * dstW + dstX;
|
|
6748
|
+
const srcStart = (srcY + row) * srcW + srcX;
|
|
6749
|
+
const chunk = src.subarray(srcStart, srcStart + copyW);
|
|
6750
|
+
dst.set(chunk, dstStart);
|
|
6751
|
+
}
|
|
6752
|
+
}
|
|
6730
6753
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6731
6754
|
0 && (module.exports = {
|
|
6732
6755
|
AlphaMaskPaintBuffer,
|
|
@@ -6972,6 +6995,7 @@ function writePaintBufferToPixelData(target, paintBuffer, writePixelDataBufferFn
|
|
|
6972
6995
|
writeImageDataToClipboard,
|
|
6973
6996
|
writeImgBlobToClipboard,
|
|
6974
6997
|
writePaintBufferToPixelData,
|
|
6998
|
+
writePixelData,
|
|
6975
6999
|
writePixelDataBuffer,
|
|
6976
7000
|
xorFast,
|
|
6977
7001
|
xorPerfect
|