pixel-data-js 0.3.0 → 0.4.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.cjs +363 -2
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +353 -1
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +363 -2
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +47 -1
- package/dist/index.prod.js +353 -1
- package/dist/index.prod.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +11 -0
package/dist/index.dev.cjs
CHANGED
|
@@ -22,24 +22,32 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
COLOR_32_BLEND_MODES: () => COLOR_32_BLEND_MODES,
|
|
24
24
|
MaskType: () => MaskType,
|
|
25
|
+
applyMaskToPixelData: () => applyMaskToPixelData,
|
|
25
26
|
base64DecodeArrayBuffer: () => base64DecodeArrayBuffer,
|
|
26
27
|
base64EncodeArrayBuffer: () => base64EncodeArrayBuffer,
|
|
28
|
+
blendColorPixelData: () => blendColorPixelData,
|
|
27
29
|
blendPixelData: () => blendPixelData,
|
|
30
|
+
clearPixelData: () => clearPixelData,
|
|
28
31
|
color32ToCssRGBA: () => color32ToCssRGBA,
|
|
29
32
|
color32ToHex: () => color32ToHex,
|
|
30
33
|
colorBurnColor32: () => colorBurnColor32,
|
|
31
34
|
colorDistance: () => colorDistance,
|
|
32
35
|
copyImageData: () => copyImageData,
|
|
33
36
|
copyImageDataLike: () => copyImageDataLike,
|
|
37
|
+
copyMask: () => copyMask,
|
|
34
38
|
deserializeImageData: () => deserializeImageData,
|
|
35
39
|
deserializeNullableImageData: () => deserializeNullableImageData,
|
|
36
40
|
deserializeRawImageData: () => deserializeRawImageData,
|
|
37
41
|
differenceColor32: () => differenceColor32,
|
|
38
42
|
extractImageData: () => extractImageData,
|
|
43
|
+
fillPixelData: () => fillPixelData,
|
|
39
44
|
hardLightColor32: () => hardLightColor32,
|
|
45
|
+
invertAlphaMask: () => invertAlphaMask,
|
|
46
|
+
invertBinaryMask: () => invertBinaryMask,
|
|
40
47
|
lerpColor32: () => lerpColor32,
|
|
41
48
|
lerpColor32Fast: () => lerpColor32Fast,
|
|
42
49
|
linearDodgeColor32: () => linearDodgeColor32,
|
|
50
|
+
mergeMasks: () => mergeMasks,
|
|
43
51
|
multiplyColor32: () => multiplyColor32,
|
|
44
52
|
overlayColor32: () => overlayColor32,
|
|
45
53
|
packColor: () => packColor,
|
|
@@ -53,7 +61,8 @@ __export(src_exports, {
|
|
|
53
61
|
unpackColor: () => unpackColor,
|
|
54
62
|
unpackColorTo: () => unpackColorTo,
|
|
55
63
|
unpackGreen: () => unpackGreen,
|
|
56
|
-
unpackRed: () => unpackRed
|
|
64
|
+
unpackRed: () => unpackRed,
|
|
65
|
+
writeImageData: () => writeImageData
|
|
57
66
|
});
|
|
58
67
|
module.exports = __toCommonJS(src_exports);
|
|
59
68
|
|
|
@@ -338,6 +347,306 @@ function deserializeNullableImageData(serialized) {
|
|
|
338
347
|
return deserializeImageData(serialized);
|
|
339
348
|
}
|
|
340
349
|
|
|
350
|
+
// src/ImageData/writeImageData.ts
|
|
351
|
+
function writeImageData(imageData, data, _x, _y, _w, _h) {
|
|
352
|
+
const { x, y, w, h } = typeof _x === "object" ? _x : { x: _x, y: _y, w: _w, h: _h };
|
|
353
|
+
const { width: dstW, height: dstH, data: dst } = imageData;
|
|
354
|
+
const x0 = Math.max(0, x);
|
|
355
|
+
const y0 = Math.max(0, y);
|
|
356
|
+
const x1 = Math.min(dstW, x + w);
|
|
357
|
+
const y1 = Math.min(dstH, y + h);
|
|
358
|
+
if (x1 <= x0 || y1 <= y0) return;
|
|
359
|
+
const rowLen = (x1 - x0) * 4;
|
|
360
|
+
const srcCol = x0 - x;
|
|
361
|
+
const srcYOffset = y0 - y;
|
|
362
|
+
const actualH = y1 - y0;
|
|
363
|
+
for (let row = 0; row < actualH; row++) {
|
|
364
|
+
const dstStart = ((y0 + row) * dstW + x0) * 4;
|
|
365
|
+
const srcRow = srcYOffset + row;
|
|
366
|
+
const o = (srcRow * w + srcCol) * 4;
|
|
367
|
+
dst.set(data.subarray(o, o + rowLen), dstStart);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/Mask/copyMask.ts
|
|
372
|
+
function copyMask(src) {
|
|
373
|
+
return src.slice();
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// src/Mask/invertMask.ts
|
|
377
|
+
function invertBinaryMask(dst) {
|
|
378
|
+
const len = dst.length;
|
|
379
|
+
for (let i = 0; i < len; i++) {
|
|
380
|
+
dst[i] = dst[i] === 0 ? 1 : 0;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function invertAlphaMask(dst) {
|
|
384
|
+
const len = dst.length;
|
|
385
|
+
for (let i = 0; i < len; i++) {
|
|
386
|
+
dst[i] = 255 - dst[i];
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// src/Mask/mergeMasks.ts
|
|
391
|
+
function mergeMasks(dst, dstWidth, src, opts) {
|
|
392
|
+
const {
|
|
393
|
+
x: targetX = 0,
|
|
394
|
+
y: targetY = 0,
|
|
395
|
+
w: width = 0,
|
|
396
|
+
h: height = 0,
|
|
397
|
+
alpha: globalAlpha = 255,
|
|
398
|
+
maskType = 0 /* ALPHA */,
|
|
399
|
+
mw,
|
|
400
|
+
mx = 0,
|
|
401
|
+
my = 0,
|
|
402
|
+
invertMask = false
|
|
403
|
+
} = opts;
|
|
404
|
+
if (width <= 0 || height <= 0 || globalAlpha === 0) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const sPitch = mw ?? width;
|
|
408
|
+
const isAlpha = maskType === 0 /* ALPHA */;
|
|
409
|
+
for (let iy = 0; iy < height; iy++) {
|
|
410
|
+
const dy = targetY + iy;
|
|
411
|
+
const sy = my + iy;
|
|
412
|
+
if (dy < 0 || sy < 0) {
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
for (let ix = 0; ix < width; ix++) {
|
|
416
|
+
const dx = targetX + ix;
|
|
417
|
+
const sx = mx + ix;
|
|
418
|
+
if (dx < 0 || dx >= dstWidth || sx < 0 || sx >= sPitch) {
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
const dIdx = dy * dstWidth + dx;
|
|
422
|
+
const sIdx = sy * sPitch + sx;
|
|
423
|
+
const mVal = src[sIdx];
|
|
424
|
+
let weight = globalAlpha;
|
|
425
|
+
if (isAlpha) {
|
|
426
|
+
const effectiveM = invertMask ? 255 - mVal : mVal;
|
|
427
|
+
if (effectiveM === 0) {
|
|
428
|
+
dst[dIdx] = 0;
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
weight = globalAlpha === 255 ? effectiveM : effectiveM * globalAlpha + 128 >> 8;
|
|
432
|
+
} else {
|
|
433
|
+
const isHit = invertMask ? mVal === 0 : mVal === 1;
|
|
434
|
+
if (!isHit) {
|
|
435
|
+
dst[dIdx] = 0;
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
weight = globalAlpha;
|
|
439
|
+
}
|
|
440
|
+
if (weight === 0) {
|
|
441
|
+
dst[dIdx] = 0;
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
const da = dst[dIdx];
|
|
445
|
+
if (da === 0) {
|
|
446
|
+
} else if (weight === 255) {
|
|
447
|
+
} else if (da === 255) {
|
|
448
|
+
dst[dIdx] = weight;
|
|
449
|
+
} else {
|
|
450
|
+
dst[dIdx] = da * weight + 128 >> 8;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// src/PixelData/applyMaskToPixelData.ts
|
|
457
|
+
function applyMaskToPixelData(dst, mask, opts) {
|
|
458
|
+
const {
|
|
459
|
+
x: targetX = 0,
|
|
460
|
+
y: targetY = 0,
|
|
461
|
+
w: width = dst.width,
|
|
462
|
+
h: height = dst.height,
|
|
463
|
+
alpha: globalAlpha = 255,
|
|
464
|
+
maskType = 0 /* ALPHA */,
|
|
465
|
+
mw,
|
|
466
|
+
mx = 0,
|
|
467
|
+
my = 0,
|
|
468
|
+
invertMask = false
|
|
469
|
+
} = opts;
|
|
470
|
+
let x = targetX;
|
|
471
|
+
let y = targetY;
|
|
472
|
+
let w = width;
|
|
473
|
+
let h = height;
|
|
474
|
+
if (x < 0) {
|
|
475
|
+
w += x;
|
|
476
|
+
x = 0;
|
|
477
|
+
}
|
|
478
|
+
if (y < 0) {
|
|
479
|
+
h += y;
|
|
480
|
+
y = 0;
|
|
481
|
+
}
|
|
482
|
+
const actualW = Math.min(w, dst.width - x);
|
|
483
|
+
const actualH = Math.min(h, dst.height - y);
|
|
484
|
+
if (actualW <= 0 || actualH <= 0 || globalAlpha === 0) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const dst32 = dst.data32;
|
|
488
|
+
const dw = dst.width;
|
|
489
|
+
const mPitch = mw ?? width;
|
|
490
|
+
const isAlpha = maskType === 0 /* ALPHA */;
|
|
491
|
+
const dx = x - targetX;
|
|
492
|
+
const dy = y - targetY;
|
|
493
|
+
let dIdx = y * dw + x;
|
|
494
|
+
let mIdx = (my + dy) * mPitch + (mx + dx);
|
|
495
|
+
const dStride = dw - actualW;
|
|
496
|
+
const mStride = mPitch - actualW;
|
|
497
|
+
for (let iy = 0; iy < actualH; iy++) {
|
|
498
|
+
for (let ix = 0; ix < actualW; ix++) {
|
|
499
|
+
const mVal = mask[mIdx];
|
|
500
|
+
let weight = globalAlpha;
|
|
501
|
+
if (isAlpha) {
|
|
502
|
+
const effectiveM = invertMask ? 255 - mVal : mVal;
|
|
503
|
+
if (effectiveM === 0) {
|
|
504
|
+
dst32[dIdx] = (dst32[dIdx] & 16777215) >>> 0;
|
|
505
|
+
dIdx++;
|
|
506
|
+
mIdx++;
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
weight = globalAlpha === 255 ? effectiveM : effectiveM * globalAlpha + 128 >> 8;
|
|
510
|
+
} else {
|
|
511
|
+
const isHit = invertMask ? mVal === 0 : mVal === 1;
|
|
512
|
+
if (!isHit) {
|
|
513
|
+
dst32[dIdx] = (dst32[dIdx] & 16777215) >>> 0;
|
|
514
|
+
dIdx++;
|
|
515
|
+
mIdx++;
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
weight = globalAlpha;
|
|
519
|
+
}
|
|
520
|
+
if (weight === 0) {
|
|
521
|
+
dst32[dIdx] = (dst32[dIdx] & 16777215) >>> 0;
|
|
522
|
+
} else {
|
|
523
|
+
const d = dst32[dIdx];
|
|
524
|
+
const da = d >>> 24;
|
|
525
|
+
let finalAlpha = da;
|
|
526
|
+
if (da === 0) {
|
|
527
|
+
} else if (weight === 255) {
|
|
528
|
+
} else if (da === 255) {
|
|
529
|
+
finalAlpha = weight;
|
|
530
|
+
} else {
|
|
531
|
+
finalAlpha = da * weight + 128 >> 8;
|
|
532
|
+
}
|
|
533
|
+
dst32[dIdx] = (d & 16777215 | finalAlpha << 24) >>> 0;
|
|
534
|
+
}
|
|
535
|
+
dIdx++;
|
|
536
|
+
mIdx++;
|
|
537
|
+
}
|
|
538
|
+
dIdx += dStride;
|
|
539
|
+
mIdx += mStride;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// src/PixelData/blendColorPixelData.ts
|
|
544
|
+
function blendColorPixelData(dst, color, opts) {
|
|
545
|
+
const {
|
|
546
|
+
x: targetX = 0,
|
|
547
|
+
y: targetY = 0,
|
|
548
|
+
w: width = dst.width,
|
|
549
|
+
h: height = dst.height,
|
|
550
|
+
alpha: globalAlpha = 255,
|
|
551
|
+
blendFn = sourceOverColor32,
|
|
552
|
+
mask,
|
|
553
|
+
maskType = 0 /* ALPHA */,
|
|
554
|
+
mw,
|
|
555
|
+
mx = 0,
|
|
556
|
+
my = 0,
|
|
557
|
+
invertMask = false
|
|
558
|
+
} = opts;
|
|
559
|
+
if (globalAlpha === 0) return;
|
|
560
|
+
let x = targetX;
|
|
561
|
+
let y = targetY;
|
|
562
|
+
let w = width;
|
|
563
|
+
let h = height;
|
|
564
|
+
if (x < 0) {
|
|
565
|
+
w += x;
|
|
566
|
+
x = 0;
|
|
567
|
+
}
|
|
568
|
+
if (y < 0) {
|
|
569
|
+
h += y;
|
|
570
|
+
y = 0;
|
|
571
|
+
}
|
|
572
|
+
const actualW = Math.min(w, dst.width - x);
|
|
573
|
+
const actualH = Math.min(h, dst.height - y);
|
|
574
|
+
if (actualW <= 0 || actualH <= 0) return;
|
|
575
|
+
const dst32 = dst.data32;
|
|
576
|
+
const dw = dst.width;
|
|
577
|
+
const mPitch = mw ?? width;
|
|
578
|
+
const isAlphaMask = maskType === 0 /* ALPHA */;
|
|
579
|
+
const dx = x - targetX;
|
|
580
|
+
const dy = y - targetY;
|
|
581
|
+
let dIdx = y * dw + x;
|
|
582
|
+
let mIdx = (my + dy) * mPitch + (mx + dx);
|
|
583
|
+
const dStride = dw - actualW;
|
|
584
|
+
const mStride = mPitch - actualW;
|
|
585
|
+
const baseSrcColor = color;
|
|
586
|
+
const baseSrcAlpha = baseSrcColor >>> 24;
|
|
587
|
+
for (let iy = 0; iy < actualH; iy++) {
|
|
588
|
+
for (let ix = 0; ix < actualW; ix++) {
|
|
589
|
+
if (baseSrcAlpha === 0) {
|
|
590
|
+
dIdx++;
|
|
591
|
+
mIdx++;
|
|
592
|
+
continue;
|
|
593
|
+
}
|
|
594
|
+
let weight = globalAlpha;
|
|
595
|
+
if (mask) {
|
|
596
|
+
const mVal = mask[mIdx];
|
|
597
|
+
if (isAlphaMask) {
|
|
598
|
+
const effectiveM = invertMask ? 255 - mVal : mVal;
|
|
599
|
+
if (effectiveM === 0) {
|
|
600
|
+
dIdx++;
|
|
601
|
+
mIdx++;
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
if (globalAlpha === 255) {
|
|
605
|
+
weight = effectiveM;
|
|
606
|
+
} else if (effectiveM === 255) {
|
|
607
|
+
weight = globalAlpha;
|
|
608
|
+
} else {
|
|
609
|
+
weight = effectiveM * globalAlpha + 128 >> 8;
|
|
610
|
+
}
|
|
611
|
+
} else {
|
|
612
|
+
const isHit = invertMask ? mVal === 0 : mVal === 1;
|
|
613
|
+
if (!isHit) {
|
|
614
|
+
dIdx++;
|
|
615
|
+
mIdx++;
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
weight = globalAlpha;
|
|
619
|
+
}
|
|
620
|
+
if (weight === 0) {
|
|
621
|
+
dIdx++;
|
|
622
|
+
mIdx++;
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
let currentSrcAlpha = baseSrcAlpha;
|
|
627
|
+
let currentSrcColor = baseSrcColor;
|
|
628
|
+
if (weight < 255) {
|
|
629
|
+
if (baseSrcAlpha === 255) {
|
|
630
|
+
currentSrcAlpha = weight;
|
|
631
|
+
} else {
|
|
632
|
+
currentSrcAlpha = baseSrcAlpha * weight + 128 >> 8;
|
|
633
|
+
}
|
|
634
|
+
if (currentSrcAlpha === 0) {
|
|
635
|
+
dIdx++;
|
|
636
|
+
mIdx++;
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
currentSrcColor = (baseSrcColor & 16777215 | currentSrcAlpha << 24) >>> 0;
|
|
640
|
+
}
|
|
641
|
+
dst32[dIdx] = blendFn(currentSrcColor, dst32[dIdx]);
|
|
642
|
+
dIdx++;
|
|
643
|
+
mIdx++;
|
|
644
|
+
}
|
|
645
|
+
dIdx += dStride;
|
|
646
|
+
mIdx += mStride;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
341
650
|
// src/PixelData/blendPixelData.ts
|
|
342
651
|
function blendPixelData(dst, src, opts) {
|
|
343
652
|
const {
|
|
@@ -473,28 +782,79 @@ function blendPixelData(dst, src, opts) {
|
|
|
473
782
|
mIdx += mStride;
|
|
474
783
|
}
|
|
475
784
|
}
|
|
785
|
+
|
|
786
|
+
// src/PixelData/fillPixelData.ts
|
|
787
|
+
function fillPixelData(dst, color, rect) {
|
|
788
|
+
const {
|
|
789
|
+
x: targetX = 0,
|
|
790
|
+
y: targetY = 0,
|
|
791
|
+
w: width = dst.width,
|
|
792
|
+
h: height = dst.height
|
|
793
|
+
} = rect || {};
|
|
794
|
+
let x = targetX;
|
|
795
|
+
let y = targetY;
|
|
796
|
+
let w = width;
|
|
797
|
+
let h = height;
|
|
798
|
+
if (x < 0) {
|
|
799
|
+
w += x;
|
|
800
|
+
x = 0;
|
|
801
|
+
}
|
|
802
|
+
if (y < 0) {
|
|
803
|
+
h += y;
|
|
804
|
+
y = 0;
|
|
805
|
+
}
|
|
806
|
+
const actualW = Math.min(w, dst.width - x);
|
|
807
|
+
const actualH = Math.min(h, dst.height - y);
|
|
808
|
+
if (actualW <= 0 || actualH <= 0) {
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
const dst32 = dst.data32;
|
|
812
|
+
const dw = dst.width;
|
|
813
|
+
if (actualW === dw && actualH === dst.height && x === 0 && y === 0) {
|
|
814
|
+
dst32.fill(color);
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
for (let iy = 0; iy < actualH; iy++) {
|
|
818
|
+
const start = (y + iy) * dw + x;
|
|
819
|
+
const end = start + actualW;
|
|
820
|
+
dst32.fill(color, start, end);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// src/PixelData/clearPixelData.ts
|
|
825
|
+
function clearPixelData(dst, rect) {
|
|
826
|
+
fillPixelData(dst, 0, rect);
|
|
827
|
+
}
|
|
476
828
|
// Annotate the CommonJS export names for ESM import in node:
|
|
477
829
|
0 && (module.exports = {
|
|
478
830
|
COLOR_32_BLEND_MODES,
|
|
479
831
|
MaskType,
|
|
832
|
+
applyMaskToPixelData,
|
|
480
833
|
base64DecodeArrayBuffer,
|
|
481
834
|
base64EncodeArrayBuffer,
|
|
835
|
+
blendColorPixelData,
|
|
482
836
|
blendPixelData,
|
|
837
|
+
clearPixelData,
|
|
483
838
|
color32ToCssRGBA,
|
|
484
839
|
color32ToHex,
|
|
485
840
|
colorBurnColor32,
|
|
486
841
|
colorDistance,
|
|
487
842
|
copyImageData,
|
|
488
843
|
copyImageDataLike,
|
|
844
|
+
copyMask,
|
|
489
845
|
deserializeImageData,
|
|
490
846
|
deserializeNullableImageData,
|
|
491
847
|
deserializeRawImageData,
|
|
492
848
|
differenceColor32,
|
|
493
849
|
extractImageData,
|
|
850
|
+
fillPixelData,
|
|
494
851
|
hardLightColor32,
|
|
852
|
+
invertAlphaMask,
|
|
853
|
+
invertBinaryMask,
|
|
495
854
|
lerpColor32,
|
|
496
855
|
lerpColor32Fast,
|
|
497
856
|
linearDodgeColor32,
|
|
857
|
+
mergeMasks,
|
|
498
858
|
multiplyColor32,
|
|
499
859
|
overlayColor32,
|
|
500
860
|
packColor,
|
|
@@ -508,6 +868,7 @@ function blendPixelData(dst, src, opts) {
|
|
|
508
868
|
unpackColor,
|
|
509
869
|
unpackColorTo,
|
|
510
870
|
unpackGreen,
|
|
511
|
-
unpackRed
|
|
871
|
+
unpackRed,
|
|
872
|
+
writeImageData
|
|
512
873
|
});
|
|
513
874
|
//# sourceMappingURL=index.dev.cjs.map
|
package/dist/index.dev.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/_types.ts","../src/blend-modes.ts","../src/color.ts","../src/ImageData/copyImageData.ts","../src/ImageData/extractImageData.ts","../src/ImageData/serialization.ts","../src/PixelData/blendPixelData.ts"],"sourcesContent":["export * from './_types'\nexport * from './blend-modes'\nexport * from './color'\nexport * from './ImageData/copyImageData'\nexport * from './ImageData/extractImageData'\nexport * from './ImageData/serialization'\nexport * from './PixelData/blendPixelData'\n","/** ALL values are 0-255 (including alpha which in CSS is 0-1) */\nexport type RGBA = { r: number, g: number, b: number, a: number }\n\n/** Represents a 32-bit color in 0xAABBGGRR (Little endian) */\nexport type Color32 = number & { readonly __brandColor32: unique symbol }\n\n/**\n * A function that defines how to combine a source color with a destination color.\n * @param src - The incoming color (source).\n * @param dst - The existing color in the buffer (destination).\n * @returns The resulting 32-bit color to be written to the buffer.\n */\nexport type BlendColor32 = (src: Color32, dst: Color32) => Color32\n\nexport type ImageDataLike = {\n width: number\n height: number\n data: Uint8ClampedArray<ArrayBuffer>\n}\n\nexport type SerializedImageData = {\n width: number\n height: number\n data: string\n}\n\nexport type Base64EncodedUInt8Array = string & { readonly __brandBase64UInt8Array: unique symbol }\n\n/** Rectangle definition */\nexport type Rect = {\n x: number\n y: number\n w: number\n h: number\n}\n\n/**\n * Defines how mask values should be interpreted during a draw operation.\n */\nexport enum MaskType {\n /**\n * Values are treated as alpha weights.\n * 0 is skipped, values > 0 are processed.\n */\n ALPHA,\n /**\n * Values are treated as on/off.\n * 0 is fully transparent (skipped), any other value is fully opaque.\n */\n BINARY\n}\n\n/** Strictly 0 or 1 */\nexport type BinaryMask = Uint8Array & { readonly __brand: 'Binary' }\n/** Strictly 0-255 */\nexport type AlphaMask = Uint8Array & { readonly __brand: 'Alpha' }\n\nexport type AnyMask = BinaryMask | AlphaMask\n\n/**\n * Configuration for pixel manipulation operations.\n * Designed to be used by spreading a Rect object ({x, y, w, h}) directly.\n */\nexport interface PixelOptions {\n /**\n * The starting X coordinate in the destination buffer.\n * @Defaults 0.\n * */\n x?: number\n /**\n * The starting Y coordinate in the destination buffer.\n * @Default 0.\n * */\n y?: number\n /**\n * The width of the region to process.\n * @Default Source width.\n * */\n w?: number\n /**\n * The height of the region to process.\n * @Default Source height.\n * */\n h?: number\n\n /**\n * Overall layer opacity 0-255.\n * @default 255\n */\n alpha?: number\n\n /**\n * Mask width.\n * @default w\n * */\n mw?: number\n\n /**\n * X offset into the mask buffer.\n * @default 0\n * */\n mx?: number\n\n /**\n * Y offset into the mask buffer.\n * @default 0\n * */\n my?: number\n\n /** An optional mask to restrict where pixels are written. */\n mask?: AnyMask | null\n\n /** The interpretation logic for the provided mask. Defaults to MaskType.Binary. */\n maskType?: MaskType\n\n /** If true the inverse of the mask will be applied */\n invertMask?: boolean\n}\n\n/**\n * Configuration for blitting (copying/blending) one image into another.\n */\nexport interface PixelBlendOptions extends PixelOptions {\n /**\n * The source rectangle x-coordinate\n * @default 0\n */\n sx?: number\n\n /**\n * The source rectangle y-coordinate\n * @default 0\n */\n sy?: number\n\n /** The specific blending function/algorithm to use for pixel math. */\n blendFn?: BlendColor32\n}\n\n/**\n * Configuration for operations that require color blending.\n */\nexport interface ColorBlendOptions extends PixelOptions {\n /** The blending logic used to combine source and destination pixels. */\n blendFn?: BlendColor32\n}\n\nexport type ApplyMaskOptions = Omit<PixelOptions, 'mask'>\n\n// export function invertBinaryMask(dst: BinaryMask): void\n// export function invertAlphaMask(dst: AlphaMask): void\n\n","import type { BlendColor32, Color32 } from './_types'\n\nexport const sourceOverColor32: BlendColor32 = (src, dst) => {\n const a = (src >>> 24) & 0xFF\n if (a === 255) return src\n if (a === 0) return dst\n\n // Pattern: (src * a + dst * (255 - a)) >> 8\n // We process RB and G separately so they don't overflow into each other\n const rbMask = 0xFF00FF\n const gMask = 0x00FF00\n\n const sRB = src & rbMask\n const sG = src & gMask\n const dRB = dst & rbMask\n const dG = dst & gMask\n\n const invA = 255 - a\n\n const outRB = ((sRB * a + dRB * invA) >> 8) & rbMask\n const outG = ((sG * a + dG * invA) >> 8) & gMask\n\n // Re-pack with opaque alpha (or calculate combined alpha if needed)\n const outA = (a + (((dst >>> 24) & 0xFF) * invA >> 8))\n return ((outA << 24) | outRB | outG) >>> 0 as Color32\n}\n\n/**\n * Screen: Lightens the destination (inverse of Multiply).\n * Result = 1 - ((1 - Src) * (1 - Dst))\n */\nexport const screenColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math\n const br = 255 - (((255 - (src & 0xFF)) * (255 - dr)) >> 8)\n const bg = 255 - (((255 - ((src >> 8) & 0xFF)) * (255 - dg)) >> 8)\n const bb = 255 - (((255 - ((src >> 16) & 0xFF)) * (255 - db)) >> 8)\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Linear Dodge (Additive): Simply adds the source to the destination.\n * Clamps at 255.\n */\nexport const linearDodgeColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math (Additive with clamping)\n const br = Math.min(255, (src & 0xFF) + dr)\n const bg = Math.min(255, ((src >> 8) & 0xFF) + dg)\n const bb = Math.min(255, ((src >> 16) & 0xFF) + db)\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Multiply: Darkens the destination based on the source color.\n * Result = (Src * Dst) / 255\n */\nexport const multiplyColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math\n const br = ((src & 0xFF) * dr) >> 8\n const bg = (((src >> 8) & 0xFF) * dg) >> 8\n const bb = (((src >> 16) & 0xFF) * db) >> 8\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Difference: Subtracts the darker color from the lighter color.\n * Result = |Src - Dst|\n */\nexport const differenceColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math\n const br = Math.abs((src & 0xFF) - dr)\n const bg = Math.abs(((src >> 8) & 0xFF) - dg)\n const bb = Math.abs(((src >> 16) & 0xFF) - db)\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Hard Light: Decides Multiply vs Screen based on SOURCE brightness.\n * Acts like a harsh spotlight.\n */\nexport const hardLightColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const sr = src & 0xFF, sg = (src >> 8) & 0xFF, sb = (src >> 16) & 0xFF\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math\n const br = sr < 128 ? (2 * sr * dr) >> 8 : 255 - (2 * (255 - sr) * (255 - dr) >> 8)\n const bg = sg < 128 ? (2 * sg * dg) >> 8 : 255 - (2 * (255 - sg) * (255 - dg) >> 8)\n const bb = sb < 128 ? (2 * sb * db) >> 8 : 255 - (2 * (255 - sb) * (255 - db) >> 8)\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Color Burn: Darkens the destination to reflect the source color.\n * Intense saturation in the darks.\n */\nexport const colorBurnColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const sr = src & 0xFF, sg = (src >> 8) & 0xFF, sb = (src >> 16) & 0xFF\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math (Avoid division by zero)\n const br = dr === 255 ? 255 : Math.max(0, 255 - ((255 - dr) << 8) / (sr || 1))\n const bg = dg === 255 ? 255 : Math.max(0, 255 - ((255 - dg) << 8) / (sg || 1))\n const bb = db === 255 ? 255 : Math.max(0, 255 - ((255 - db) << 8) / (sb || 1))\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n/**\n * Overlay: The classic \"Contrast\" mode.\n * Decides Multiply vs Screen based on DESTINATION brightness.\n */\nexport const overlayColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const sr = src & 0xFF, sg = (src >> 8) & 0xFF, sb = (src >> 16) & 0xFF\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math\n const br = dr < 128 ? (2 * sr * dr) >> 8 : 255 - (2 * (255 - sr) * (255 - dr) >> 8)\n const bg = dg < 128 ? (2 * sg * dg) >> 8 : 255 - (2 * (255 - sg) * (255 - dg) >> 8)\n const bb = db < 128 ? (2 * sb * db) >> 8 : 255 - (2 * (255 - sb) * (255 - db) >> 8)\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\nexport const COLOR_32_BLEND_MODES = {\n sourceOver: sourceOverColor32,\n screen: screenColor32,\n linearDodge: linearDodgeColor32,\n multiply: multiplyColor32,\n difference: differenceColor32,\n overlay: overlayColor32,\n hardLight: hardLightColor32,\n colorBurn: colorBurnColor32,\n}\n","import type { Color32, RGBA } from './_types'\n\n/**\n * Packs RGBA into a 32-bit integer compatible with\n * Little-Endian Uint32Array views on ImageData.\n */\nexport function packColor(r: number, g: number, b: number, a: number): Color32 {\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\nexport function packRGBA({ r, g, b, a }: RGBA): Color32 {\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\nexport const unpackRed = (packed: Color32): number => (packed >>> 0) & 0xFF\nexport const unpackGreen = (packed: Color32): number => (packed >>> 8) & 0xFF\nexport const unpackBlue = (packed: Color32): number => (packed >>> 16) & 0xFF\nexport const unpackAlpha = (packed: Color32): number => (packed >>> 24) & 0xFF\n\nexport function unpackColor(packed: Color32): RGBA {\n return {\n r: (packed >>> 0) & 0xFF,\n g: (packed >>> 8) & 0xFF,\n b: (packed >>> 16) & 0xFF,\n a: (packed >>> 24) & 0xFF,\n }\n}\n\nconst SCRATCH_RGBA: RGBA = { r: 0, g: 0, b: 0, a: 0 }\n\n// uses a scratch arg for memory perf. Be careful about re-use.\nexport function unpackColorTo(packed: Color32, scratch = SCRATCH_RGBA): RGBA {\n scratch.r = (packed >>> 0) & 0xFF\n scratch.g = (packed >>> 8) & 0xFF\n scratch.b = (packed >>> 16) & 0xFF\n scratch.a = (packed >>> 24) & 0xFF\n return scratch\n}\n\nexport function colorDistance(a: Color32, b: Color32): number {\n const dr = (a & 0xFF) - (b & 0xFF)\n const dg = ((a >>> 8) & 0xFF) - ((b >>> 8) & 0xFF)\n const db = ((a >>> 16) & 0xFF) - ((b >>> 16) & 0xFF)\n const da = ((a >>> 24) & 0xFF) - ((b >>> 24) & 0xFF)\n return dr * dr + dg * dg + db * db + da * da\n}\n\n/**\n * Linearly interpolates between two 32-bit colors using a floating-point weight.\n * * This is the preferred method for UI animations or scenarios where high\n * precision is required. It uses the standard `a + t * (b - a)` formula\n * for each channel.\n * @param a - The starting color as a 32-bit integer (AABBGGRR).\n * @param b - The target color as a 32-bit integer (AABBGGRR).\n * @param t - The interpolation factor between 0.0 and 1.0.\n * @returns The interpolated 32-bit color.\n */\nexport function lerpColor32(a: Color32, b: Color32, t: number): Color32 {\n const r = (a & 0xFF) + t * ((b & 0xFF) - (a & 0xFF))\n const g = ((a >>> 8) & 0xFF) + t * (((b >>> 8) & 0xFF) - ((a >>> 8) & 0xFF))\n const b_ = ((a >>> 16) & 0xFF) + t * (((b >>> 16) & 0xFF) - ((a >>> 16) & 0xFF))\n const a_ = ((a >>> 24) & 0xFF) + t * (((b >>> 24) & 0xFF) - ((a >>> 24) & 0xFF))\n\n return ((a_ << 24) | (b_ << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Linearly interpolates between two 32-bit colors using integer fixed-point math.\n * Highly optimized for image processing and real-time blitting. It processes\n * channels in parallel using bitmasks (RB and GA pairs).\n * @note Subject to a 1-bit drift (rounding down) due to fast bit-shift division.\n * @param src - The source (foreground) color as a 32-bit integer.\n * @param dst - The destination (background) color as a 32-bit integer.\n * @param w - The blend weight as a byte value from 0 to 255. Where 0 is 100% dst and 255 is 100% src\n * @returns The blended 32-bit color.\n */export function lerpColor32Fast(src: Color32, dst: Color32, w: number): Color32 {\n const invA = 255 - w;\n\n // Masking Red and Blue: 0x00FF00FF\n // We process R and B in one go, then shift back down\n const rb = (((src & 0x00FF00FF) * w + (dst & 0x00FF00FF) * invA) >>> 8) & 0x00FF00FF;\n\n // Masking Green and Alpha: 0xFF00FF00\n // We shift down first to avoid overflow, then shift back up\n const ga = ((((src >>> 8) & 0x00FF00FF) * w + ((dst >>> 8) & 0x00FF00FF) * invA) >>> 8) & 0x00FF00FF;\n\n return (rb | (ga << 8)) >>> 0 as Color32;\n}\n\n// Convert 0xAABBGGRR to #RRGGBBAA\nexport function color32ToHex(color: Color32): string {\n const r = (color & 0xFF).toString(16).padStart(2, '0')\n const g = ((color >>> 8) & 0xFF).toString(16).padStart(2, '0')\n const b = ((color >>> 16) & 0xFF).toString(16).padStart(2, '0')\n const a = ((color >>> 24) & 0xFF).toString(16).padStart(2, '0')\n return `#${r}${g}${b}${a}`\n}\n\n/**\n * Converts a 32-bit integer (0xAABBGGRR) to a CSS rgba() string.\n * Example: 0xFF0000FF -> \"rgba(255,0,0,1)\"\n */\nexport function color32ToCssRGBA(color: Color32): string {\n const r = color & 0xFF\n const g = (color >>> 8) & 0xFF\n const b = (color >>> 16) & 0xFF\n const a = (color >>> 24) & 0xFF\n\n const alpha = Number((a / 255).toFixed(3))\n\n return `rgba(${r},${g},${b},${alpha})`\n}\n","import type { ImageDataLike } from '../_types'\n\nexport function copyImageData({ data, width, height }: ImageDataLike): ImageData {\n return new ImageData(data.slice(), width, height)\n}\n\nexport function copyImageDataLike({ data, width, height }: ImageDataLike): ImageDataLike {\n return {\n data: data.slice(),\n width,\n height,\n }\n}\n","import type { ImageDataLike, Rect } from '../_types'\n\nexport function extractImageData(\n imageData: ImageDataLike,\n rect: Rect,\n): Uint8ClampedArray\nexport function extractImageData(\n imageData: ImageDataLike,\n x: number,\n y: number,\n w: number,\n h: number,\n): Uint8ClampedArray\nexport function extractImageData(\n imageData: ImageDataLike,\n _x: Rect | number,\n _y?: number,\n _w?: number,\n _h?: number,\n): Uint8ClampedArray {\n const { x, y, w, h } = typeof _x === 'object'\n ? _x\n : { x: _x, y: _y!, w: _w!, h: _h! }\n\n const { width: srcW, height: srcH, data: src } = imageData\n // Safety check for invalid dimensions\n if (w <= 0 || h <= 0) return new Uint8ClampedArray(0)\n const out = new Uint8ClampedArray(w * h * 4)\n\n const x0 = Math.max(0, x)\n const y0 = Math.max(0, y)\n const x1 = Math.min(srcW, x + w)\n const y1 = Math.min(srcH, y + h)\n\n // If no intersection, return the empty\n if (x1 <= x0 || y1 <= y0) return out\n\n for (let row = 0; row < (y1 - y0); row++) {\n // Where to read from the source canvas\n const srcRow = y0 + row\n const srcStart = (srcRow * srcW + x0) * 4\n const rowLen = (x1 - x0) * 4\n\n // Where to write into the 'out' patch\n const dstRow = (y0 - y) + row\n const dstCol = (x0 - x)\n const dstStart = (dstRow * w + dstCol) * 4\n\n // Perform the high-speed bulk copy\n out.set(src.subarray(srcStart, srcStart + rowLen), dstStart)\n }\n\n return out\n}\n","import type { Base64EncodedUInt8Array, ImageDataLike, SerializedImageData } from '../_types'\n\nexport function base64EncodeArrayBuffer(buffer: ArrayBufferLike): Base64EncodedUInt8Array {\n const binary = String.fromCharCode(...new Uint8Array(buffer))\n return btoa(binary) as Base64EncodedUInt8Array\n}\n\nexport function base64DecodeArrayBuffer(encoded: Base64EncodedUInt8Array): Uint8ClampedArray<ArrayBuffer> {\n const binary = atob(encoded)\n const bytes = new Uint8ClampedArray(binary.length)\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i)\n }\n return bytes\n}\n\n/**\n * Serialize for use in JSON. Pixel data is stored as base64 encoded string.\n */\nexport function serializeImageData<T extends ImageDataLike>(imageData: T): SerializedImageData {\n return {\n width: imageData.width,\n height: imageData.height,\n data: base64EncodeArrayBuffer(imageData.data.buffer),\n }\n}\n\nexport function serializeNullableImageData<T extends ImageDataLike | null>(imageData: T): T extends null ? null : SerializedImageData {\n if (!imageData) return null as any\n\n return serializeImageData(imageData) as any\n}\n\nexport function deserializeRawImageData<T extends SerializedImageData>(serialized: T): ImageDataLike {\n return {\n width: serialized.width,\n height: serialized.height,\n data: base64DecodeArrayBuffer(serialized.data as Base64EncodedUInt8Array),\n }\n}\n\nexport function deserializeImageData<T extends SerializedImageData>(serialized: T): ImageData {\n const data = base64DecodeArrayBuffer(serialized.data as Base64EncodedUInt8Array)\n\n return new ImageData(data as ImageDataArray, serialized.width, serialized.height) as any\n}\n\nexport function deserializeNullableImageData<T extends SerializedImageData | null>(serialized: T): T extends null ? null : ImageData {\n if (!serialized) return null as any\n return deserializeImageData(serialized) as any\n}\n","import { type Color32, MaskType, type PixelBlendOptions } from '../_types'\nimport { sourceOverColor32 } from '../blend-modes'\nimport type { PixelData } from '../PixelData'\n\n/**\n * Blits source PixelData into a destination PixelData using 32-bit integer bitwise blending.\n * This function bypasses standard ImageData limitations by operating directly on\n * Uint32Array views. It supports various blend modes, binary/alpha masking, and\n * automatic clipping of both source and destination bounds.\n * @example\n *\n * const dst = new PixelData(ctx.getImageData(0,0,100,100))\n * blendImageData32(dst, sprite, {\n * blendFn: COLOR_32_BLEND_MODES.multiply,\n * mask: brushMask,\n * maskType: MaskType.ALPHA\n * });\n */\nexport function blendPixelData(\n dst: PixelData,\n src: PixelData,\n opts: PixelBlendOptions,\n) {\n const {\n x: targetX = 0,\n y: targetY = 0,\n sx: sourceX = 0,\n sy: sourceY = 0,\n w: width = src.width,\n h: height = src.height,\n alpha: globalAlpha = 255,\n blendFn = sourceOverColor32,\n mask,\n maskType = MaskType.ALPHA,\n mw,\n mx = 0,\n my = 0,\n invertMask = false,\n } = opts\n\n if (globalAlpha === 0) return\n\n let x = targetX\n let y = targetY\n let sx = sourceX\n let sy = sourceY\n let w = width\n let h = height\n\n // 1. Source Clipping\n if (sx < 0) {\n x -= sx\n w += sx\n sx = 0\n }\n if (sy < 0) {\n y -= sy\n h += sy\n sy = 0\n }\n w = Math.min(w, src.width - sx)\n h = Math.min(h, src.height - sy)\n\n // 2. Destination Clipping\n if (x < 0) {\n sx -= x\n w += x\n x = 0\n }\n if (y < 0) {\n sy -= y\n h += y\n y = 0\n }\n\n const actualW = Math.min(w, dst.width - x)\n const actualH = Math.min(h, dst.height - y)\n\n if (actualW <= 0 || actualH <= 0) return\n\n const dst32 = dst.data32\n const src32 = src.data32\n const dw = dst.width\n const sw = src.width\n const mPitch = mw ?? width\n const isAlphaMask = maskType === MaskType.ALPHA\n\n const dx = x - targetX\n const dy = y - targetY\n\n let dIdx = y * dw + x\n let sIdx = sy * sw + sx\n let mIdx = (my + dy) * mPitch + (mx + dx)\n\n const dStride = dw - actualW\n const sStride = sw - actualW\n const mStride = mPitch - actualW\n\n for (let iy = 0; iy < actualH; iy++) {\n for (let ix = 0; ix < actualW; ix++) {\n const baseSrcColor = src32[sIdx] as Color32\n const baseSrcAlpha = (baseSrcColor >>> 24)\n\n // Early exit if source pixel is already transparent\n if (baseSrcAlpha === 0) {\n dIdx++\n sIdx++\n mIdx++\n continue\n }\n\n let weight = globalAlpha\n\n if (mask) {\n const mVal = mask[mIdx]\n\n if (isAlphaMask) {\n const effectiveM = invertMask\n ? 255 - mVal\n : mVal\n\n // If mask is transparent, skip\n if (effectiveM === 0) {\n dIdx++\n sIdx++\n mIdx++\n continue\n }\n\n // globalAlpha is not a factor\n if (globalAlpha === 255) {\n weight = effectiveM\n // mask is not a factor\n } else if (effectiveM === 255) {\n weight = globalAlpha\n } else {\n // use rounding-corrected multiplication\n weight = (effectiveM * globalAlpha + 128) >> 8\n }\n } else {\n const isHit = invertMask\n ? mVal === 0\n : mVal === 1\n\n if (!isHit) {\n dIdx++\n sIdx++\n mIdx++\n continue\n }\n\n weight = globalAlpha\n }\n\n // Final safety check for weight (can be 0 if globalAlpha or alphaMask rounds down)\n if (weight === 0) {\n dIdx++\n sIdx++\n mIdx++\n continue\n }\n }\n\n // Apply Weight to Source Alpha\n let currentSrcAlpha = baseSrcAlpha\n let currentSrcColor = baseSrcColor\n\n if (weight < 255) {\n if (baseSrcAlpha === 255) {\n currentSrcAlpha = weight\n } else {\n currentSrcAlpha = (baseSrcAlpha * weight + 128) >> 8\n }\n\n if (currentSrcAlpha === 0) {\n dIdx++\n sIdx++\n mIdx++\n continue\n }\n\n currentSrcColor = ((baseSrcColor & 0x00ffffff) | (currentSrcAlpha << 24)) >>> 0 as Color32\n }\n\n dst32[dIdx] = blendFn(currentSrcColor, dst32[dIdx] as Color32)\n\n dIdx++\n sIdx++\n mIdx++\n }\n\n dIdx += dStride\n sIdx += sStride\n mIdx += mStride\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACuCO,IAAK,WAAL,kBAAKA,cAAL;AAKL,EAAAA,oBAAA;AAKA,EAAAA,oBAAA;AAVU,SAAAA;AAAA,GAAA;;;ACrCL,IAAM,oBAAkC,CAAC,KAAK,QAAQ;AAC3D,QAAM,IAAK,QAAQ,KAAM;AACzB,MAAI,MAAM,IAAK,QAAO;AACtB,MAAI,MAAM,EAAG,QAAO;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AAG;AAChB;AACA;AACA;AACA;AAAA,QACF;AAAA,MACF;AAGA,UAAI,kBAAkB;AACtB,UAAI,kBAAkB;AAEtB,UAAI,SAAS,KAAK;AAChB,YAAI,iBAAiB,KAAK;AACxB,4BAAkB;AAAA,QACpB,OAAO;AACL,4BAAmB,eAAe,SAAS,OAAQ;AAAA,QACrD;AAEA,YAAI,oBAAoB,GAAG;AACzB;AACA;AACA;AACA;AAAA,QACF;AAEA,2BAAoB,eAAe,WAAe,mBAAmB,QAAS;AAAA,MAChF;AAEA,YAAM,IAAI,IAAI,QAAQ,iBAAiB,MAAM,IAAI,CAAY;AAE7D;AACA;AACA;AAAA,IACF;AAEA,YAAQ;AACR,YAAQ;AACR,YAAQ;AAAA,EACV;AACF;","names":["MaskType"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/_types.ts","../src/blend-modes.ts","../src/color.ts","../src/ImageData/copyImageData.ts","../src/ImageData/extractImageData.ts","../src/ImageData/serialization.ts","../src/ImageData/writeImageData.ts","../src/Mask/copyMask.ts","../src/Mask/invertMask.ts","../src/Mask/mergeMasks.ts","../src/PixelData/applyMaskToPixelData.ts","../src/PixelData/blendColorPixelData.ts","../src/PixelData/blendPixelData.ts","../src/PixelData/fillPixelData.ts","../src/PixelData/clearPixelData.ts"],"sourcesContent":["export * from './_types'\nexport * from './blend-modes'\nexport * from './color'\n\nexport * from './ImageData/copyImageData'\nexport * from './ImageData/extractImageData'\nexport * from './ImageData/serialization'\nexport * from './ImageData/writeImageData'\n\nexport * from './Mask/copyMask'\nexport * from './Mask/invertMask'\nexport * from './Mask/mergeMasks'\n\nexport * from './PixelData/applyMaskToPixelData'\nexport * from './PixelData/blendColorPixelData'\nexport * from './PixelData/blendPixelData'\nexport * from './PixelData/clearPixelData'\nexport * from './PixelData/fillPixelData'\n","/** ALL values are 0-255 (including alpha which in CSS is 0-1) */\nexport type RGBA = { r: number, g: number, b: number, a: number }\n\n/** Represents a 32-bit color in 0xAABBGGRR (Little endian) */\nexport type Color32 = number & { readonly __brandColor32: unique symbol }\n\n/**\n * A function that defines how to combine a source color with a destination color.\n * @param src - The incoming color (source).\n * @param dst - The existing color in the buffer (destination).\n * @returns The resulting 32-bit color to be written to the buffer.\n */\nexport type BlendColor32 = (src: Color32, dst: Color32) => Color32\n\nexport type ImageDataLike = {\n width: number\n height: number\n data: Uint8ClampedArray<ArrayBuffer>\n}\n\nexport type SerializedImageData = {\n width: number\n height: number\n data: string\n}\n\nexport type Base64EncodedUInt8Array = string & { readonly __brandBase64UInt8Array: unique symbol }\n\n/** Rectangle definition */\nexport type Rect = {\n x: number\n y: number\n w: number\n h: number\n}\n\n/**\n * Defines how mask values should be interpreted during a draw operation.\n */\nexport enum MaskType {\n /**\n * Values are treated as alpha weights.\n * 0 is skipped, values > 0 are processed.\n */\n ALPHA,\n /**\n * Values are treated as on/off.\n * 0 is fully transparent (skipped), any other value is fully opaque.\n */\n BINARY\n}\n\n/** Strictly 0 or 1 */\nexport type BinaryMask = Uint8Array & { readonly __brand: 'Binary' }\n/** Strictly 0-255 */\nexport type AlphaMask = Uint8Array & { readonly __brand: 'Alpha' }\n\nexport type AnyMask = BinaryMask | AlphaMask\n\n/**\n * Configuration for pixel manipulation operations.\n * Designed to be used by spreading a Rect object ({x, y, w, h}) directly.\n */\nexport interface PixelOptions {\n /**\n * The starting X coordinate in the destination buffer.\n * @Defaults 0.\n * */\n x?: number\n /**\n * The starting Y coordinate in the destination buffer.\n * @Default 0.\n * */\n y?: number\n /**\n * The width of the region to process.\n * @Default Source width.\n * */\n w?: number\n /**\n * The height of the region to process.\n * @Default Source height.\n * */\n h?: number\n\n /**\n * Overall layer opacity 0-255.\n * @default 255\n */\n alpha?: number\n\n /**\n * Mask width.\n * @default w\n * */\n mw?: number\n\n /**\n * X offset into the mask buffer.\n * @default 0\n * */\n mx?: number\n\n /**\n * Y offset into the mask buffer.\n * @default 0\n * */\n my?: number\n\n /** An optional mask to restrict where pixels are written. */\n mask?: AnyMask | null\n\n /** The interpretation logic for the provided mask. Defaults to MaskType.Binary. */\n maskType?: MaskType\n\n /** If true the inverse of the mask will be applied */\n invertMask?: boolean\n}\n\n/**\n * Configuration for blitting (copying/blending) one image into another.\n */\nexport interface PixelBlendOptions extends PixelOptions {\n /**\n * The source rectangle x-coordinate\n * @default 0\n */\n sx?: number\n\n /**\n * The source rectangle y-coordinate\n * @default 0\n */\n sy?: number\n\n /** The specific blending function/algorithm to use for pixel math. */\n blendFn?: BlendColor32\n}\n\n/**\n * Configuration for operations that require color blending.\n */\nexport interface ColorBlendOptions extends PixelOptions {\n /** The blending logic used to combine source and destination pixels. */\n blendFn?: BlendColor32\n}\n\nexport type ApplyMaskOptions = Omit<PixelOptions, 'mask'>\n\n// export function invertBinaryMask(dst: BinaryMask): void\n// export function invertAlphaMask(dst: AlphaMask): void\n\n","import type { BlendColor32, Color32 } from './_types'\n\nexport const sourceOverColor32: BlendColor32 = (src, dst) => {\n const a = (src >>> 24) & 0xFF\n if (a === 255) return src\n if (a === 0) return dst\n\n // Pattern: (src * a + dst * (255 - a)) >> 8\n // We process RB and G separately so they don't overflow into each other\n const rbMask = 0xFF00FF\n const gMask = 0x00FF00\n\n const sRB = src & rbMask\n const sG = src & gMask\n const dRB = dst & rbMask\n const dG = dst & gMask\n\n const invA = 255 - a\n\n const outRB = ((sRB * a + dRB * invA) >> 8) & rbMask\n const outG = ((sG * a + dG * invA) >> 8) & gMask\n\n // Re-pack with opaque alpha (or calculate combined alpha if needed)\n const outA = (a + (((dst >>> 24) & 0xFF) * invA >> 8))\n return ((outA << 24) | outRB | outG) >>> 0 as Color32\n}\n\n/**\n * Screen: Lightens the destination (inverse of Multiply).\n * Result = 1 - ((1 - Src) * (1 - Dst))\n */\nexport const screenColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math\n const br = 255 - (((255 - (src & 0xFF)) * (255 - dr)) >> 8)\n const bg = 255 - (((255 - ((src >> 8) & 0xFF)) * (255 - dg)) >> 8)\n const bb = 255 - (((255 - ((src >> 16) & 0xFF)) * (255 - db)) >> 8)\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Linear Dodge (Additive): Simply adds the source to the destination.\n * Clamps at 255.\n */\nexport const linearDodgeColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math (Additive with clamping)\n const br = Math.min(255, (src & 0xFF) + dr)\n const bg = Math.min(255, ((src >> 8) & 0xFF) + dg)\n const bb = Math.min(255, ((src >> 16) & 0xFF) + db)\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Multiply: Darkens the destination based on the source color.\n * Result = (Src * Dst) / 255\n */\nexport const multiplyColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math\n const br = ((src & 0xFF) * dr) >> 8\n const bg = (((src >> 8) & 0xFF) * dg) >> 8\n const bb = (((src >> 16) & 0xFF) * db) >> 8\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Difference: Subtracts the darker color from the lighter color.\n * Result = |Src - Dst|\n */\nexport const differenceColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math\n const br = Math.abs((src & 0xFF) - dr)\n const bg = Math.abs(((src >> 8) & 0xFF) - dg)\n const bb = Math.abs(((src >> 16) & 0xFF) - db)\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Hard Light: Decides Multiply vs Screen based on SOURCE brightness.\n * Acts like a harsh spotlight.\n */\nexport const hardLightColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const sr = src & 0xFF, sg = (src >> 8) & 0xFF, sb = (src >> 16) & 0xFF\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math\n const br = sr < 128 ? (2 * sr * dr) >> 8 : 255 - (2 * (255 - sr) * (255 - dr) >> 8)\n const bg = sg < 128 ? (2 * sg * dg) >> 8 : 255 - (2 * (255 - sg) * (255 - dg) >> 8)\n const bb = sb < 128 ? (2 * sb * db) >> 8 : 255 - (2 * (255 - sb) * (255 - db) >> 8)\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Color Burn: Darkens the destination to reflect the source color.\n * Intense saturation in the darks.\n */\nexport const colorBurnColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const sr = src & 0xFF, sg = (src >> 8) & 0xFF, sb = (src >> 16) & 0xFF\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math (Avoid division by zero)\n const br = dr === 255 ? 255 : Math.max(0, 255 - ((255 - dr) << 8) / (sr || 1))\n const bg = dg === 255 ? 255 : Math.max(0, 255 - ((255 - dg) << 8) / (sg || 1))\n const bb = db === 255 ? 255 : Math.max(0, 255 - ((255 - db) << 8) / (sb || 1))\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n/**\n * Overlay: The classic \"Contrast\" mode.\n * Decides Multiply vs Screen based on DESTINATION brightness.\n */\nexport const overlayColor32: BlendColor32 = (src, dst) => {\n const sa = (src >>> 24) & 0xFF\n if (sa === 0) return dst\n\n const sr = src & 0xFF, sg = (src >> 8) & 0xFF, sb = (src >> 16) & 0xFF\n const dr = dst & 0xFF, dg = (dst >> 8) & 0xFF, db = (dst >> 16) & 0xFF\n\n // 1. Core Math\n const br = dr < 128 ? (2 * sr * dr) >> 8 : 255 - (2 * (255 - sr) * (255 - dr) >> 8)\n const bg = dg < 128 ? (2 * sg * dg) >> 8 : 255 - (2 * (255 - sg) * (255 - dg) >> 8)\n const bb = db < 128 ? (2 * sb * db) >> 8 : 255 - (2 * (255 - sb) * (255 - db) >> 8)\n\n if (sa === 255) return (0xFF000000 | (bb << 16) | (bg << 8) | br) >>> 0 as Color32\n\n // 2. Alpha Lerp inlined\n const invA = 255 - sa\n const r = (br * sa + dr * invA) >> 8\n const g = (bg * sa + dg * invA) >> 8\n const b = (bb * sa + db * invA) >> 8\n const a = (255 * sa + ((dst >>> 24) & 0xFF) * invA) >> 8\n\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\nexport const COLOR_32_BLEND_MODES = {\n sourceOver: sourceOverColor32,\n screen: screenColor32,\n linearDodge: linearDodgeColor32,\n multiply: multiplyColor32,\n difference: differenceColor32,\n overlay: overlayColor32,\n hardLight: hardLightColor32,\n colorBurn: colorBurnColor32,\n}\n","import type { Color32, RGBA } from './_types'\n\n/**\n * Packs RGBA into a 32-bit integer compatible with\n * Little-Endian Uint32Array views on ImageData.\n */\nexport function packColor(r: number, g: number, b: number, a: number): Color32 {\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\nexport function packRGBA({ r, g, b, a }: RGBA): Color32 {\n return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\nexport const unpackRed = (packed: Color32): number => (packed >>> 0) & 0xFF\nexport const unpackGreen = (packed: Color32): number => (packed >>> 8) & 0xFF\nexport const unpackBlue = (packed: Color32): number => (packed >>> 16) & 0xFF\nexport const unpackAlpha = (packed: Color32): number => (packed >>> 24) & 0xFF\n\nexport function unpackColor(packed: Color32): RGBA {\n return {\n r: (packed >>> 0) & 0xFF,\n g: (packed >>> 8) & 0xFF,\n b: (packed >>> 16) & 0xFF,\n a: (packed >>> 24) & 0xFF,\n }\n}\n\nconst SCRATCH_RGBA: RGBA = { r: 0, g: 0, b: 0, a: 0 }\n\n// uses a scratch arg for memory perf. Be careful about re-use.\nexport function unpackColorTo(packed: Color32, scratch = SCRATCH_RGBA): RGBA {\n scratch.r = (packed >>> 0) & 0xFF\n scratch.g = (packed >>> 8) & 0xFF\n scratch.b = (packed >>> 16) & 0xFF\n scratch.a = (packed >>> 24) & 0xFF\n return scratch\n}\n\nexport function colorDistance(a: Color32, b: Color32): number {\n const dr = (a & 0xFF) - (b & 0xFF)\n const dg = ((a >>> 8) & 0xFF) - ((b >>> 8) & 0xFF)\n const db = ((a >>> 16) & 0xFF) - ((b >>> 16) & 0xFF)\n const da = ((a >>> 24) & 0xFF) - ((b >>> 24) & 0xFF)\n return dr * dr + dg * dg + db * db + da * da\n}\n\n/**\n * Linearly interpolates between two 32-bit colors using a floating-point weight.\n * * This is the preferred method for UI animations or scenarios where high\n * precision is required. It uses the standard `a + t * (b - a)` formula\n * for each channel.\n * @param a - The starting color as a 32-bit integer (AABBGGRR).\n * @param b - The target color as a 32-bit integer (AABBGGRR).\n * @param t - The interpolation factor between 0.0 and 1.0.\n * @returns The interpolated 32-bit color.\n */\nexport function lerpColor32(a: Color32, b: Color32, t: number): Color32 {\n const r = (a & 0xFF) + t * ((b & 0xFF) - (a & 0xFF))\n const g = ((a >>> 8) & 0xFF) + t * (((b >>> 8) & 0xFF) - ((a >>> 8) & 0xFF))\n const b_ = ((a >>> 16) & 0xFF) + t * (((b >>> 16) & 0xFF) - ((a >>> 16) & 0xFF))\n const a_ = ((a >>> 24) & 0xFF) + t * (((b >>> 24) & 0xFF) - ((a >>> 24) & 0xFF))\n\n return ((a_ << 24) | (b_ << 16) | (g << 8) | r) >>> 0 as Color32\n}\n\n/**\n * Linearly interpolates between two 32-bit colors using integer fixed-point math.\n * Highly optimized for image processing and real-time blitting. It processes\n * channels in parallel using bitmasks (RB and GA pairs).\n * @note Subject to a 1-bit drift (rounding down) due to fast bit-shift division.\n * @param src - The source (foreground) color as a 32-bit integer.\n * @param dst - The destination (background) color as a 32-bit integer.\n * @param w - The blend weight as a byte value from 0 to 255. Where 0 is 100% dst and 255 is 100% src\n * @returns The blended 32-bit color.\n */export function lerpColor32Fast(src: Color32, dst: Color32, w: number): Color32 {\n const invA = 255 - w;\n\n // Masking Red and Blue: 0x00FF00FF\n // We process R and B in one go, then shift back down\n const rb = (((src & 0x00FF00FF) * w + (dst & 0x00FF00FF) * invA) >>> 8) & 0x00FF00FF;\n\n // Masking Green and Alpha: 0xFF00FF00\n // We shift down first to avoid overflow, then shift back up\n const ga = ((((src >>> 8) & 0x00FF00FF) * w + ((dst >>> 8) & 0x00FF00FF) * invA) >>> 8) & 0x00FF00FF;\n\n return (rb | (ga << 8)) >>> 0 as Color32;\n}\n\n// Convert 0xAABBGGRR to #RRGGBBAA\nexport function color32ToHex(color: Color32): string {\n const r = (color & 0xFF).toString(16).padStart(2, '0')\n const g = ((color >>> 8) & 0xFF).toString(16).padStart(2, '0')\n const b = ((color >>> 16) & 0xFF).toString(16).padStart(2, '0')\n const a = ((color >>> 24) & 0xFF).toString(16).padStart(2, '0')\n return `#${r}${g}${b}${a}`\n}\n\n/**\n * Converts a 32-bit integer (0xAABBGGRR) to a CSS rgba() string.\n * Example: 0xFF0000FF -> \"rgba(255,0,0,1)\"\n */\nexport function color32ToCssRGBA(color: Color32): string {\n const r = color & 0xFF\n const g = (color >>> 8) & 0xFF\n const b = (color >>> 16) & 0xFF\n const a = (color >>> 24) & 0xFF\n\n const alpha = Number((a / 255).toFixed(3))\n\n return `rgba(${r},${g},${b},${alpha})`\n}\n","import type { ImageDataLike } from '../_types'\n\nexport function copyImageData({ data, width, height }: ImageDataLike): ImageData {\n return new ImageData(data.slice(), width, height)\n}\n\nexport function copyImageDataLike({ data, width, height }: ImageDataLike): ImageDataLike {\n return {\n data: data.slice(),\n width,\n height,\n }\n}\n","import type { ImageDataLike, Rect } from '../_types'\n\nexport function extractImageData(\n imageData: ImageDataLike,\n rect: Rect,\n): Uint8ClampedArray\nexport function extractImageData(\n imageData: ImageDataLike,\n x: number,\n y: number,\n w: number,\n h: number,\n): Uint8ClampedArray\nexport function extractImageData(\n imageData: ImageDataLike,\n _x: Rect | number,\n _y?: number,\n _w?: number,\n _h?: number,\n): Uint8ClampedArray {\n const { x, y, w, h } = typeof _x === 'object'\n ? _x\n : { x: _x, y: _y!, w: _w!, h: _h! }\n\n const { width: srcW, height: srcH, data: src } = imageData\n // Safety check for invalid dimensions\n if (w <= 0 || h <= 0) return new Uint8ClampedArray(0)\n const out = new Uint8ClampedArray(w * h * 4)\n\n const x0 = Math.max(0, x)\n const y0 = Math.max(0, y)\n const x1 = Math.min(srcW, x + w)\n const y1 = Math.min(srcH, y + h)\n\n // If no intersection, return the empty\n if (x1 <= x0 || y1 <= y0) return out\n\n for (let row = 0; row < (y1 - y0); row++) {\n // Where to read from the source canvas\n const srcRow = y0 + row\n const srcStart = (srcRow * srcW + x0) * 4\n const rowLen = (x1 - x0) * 4\n\n // Where to write into the 'out' patch\n const dstRow = (y0 - y) + row\n const dstCol = (x0 - x)\n const dstStart = (dstRow * w + dstCol) * 4\n\n // Perform the high-speed bulk copy\n out.set(src.subarray(srcStart, srcStart + rowLen), dstStart)\n }\n\n return out\n}\n","import type { Base64EncodedUInt8Array, ImageDataLike, SerializedImageData } from '../_types'\n\nexport function base64EncodeArrayBuffer(buffer: ArrayBufferLike): Base64EncodedUInt8Array {\n const binary = String.fromCharCode(...new Uint8Array(buffer))\n return btoa(binary) as Base64EncodedUInt8Array\n}\n\nexport function base64DecodeArrayBuffer(encoded: Base64EncodedUInt8Array): Uint8ClampedArray<ArrayBuffer> {\n const binary = atob(encoded)\n const bytes = new Uint8ClampedArray(binary.length)\n for (let i = 0; i < binary.length; i++) {\n bytes[i] = binary.charCodeAt(i)\n }\n return bytes\n}\n\n/**\n * Serialize for use in JSON. Pixel data is stored as base64 encoded string.\n */\nexport function serializeImageData<T extends ImageDataLike>(imageData: T): SerializedImageData {\n return {\n width: imageData.width,\n height: imageData.height,\n data: base64EncodeArrayBuffer(imageData.data.buffer),\n }\n}\n\nexport function serializeNullableImageData<T extends ImageDataLike | null>(imageData: T): T extends null ? null : SerializedImageData {\n if (!imageData) return null as any\n\n return serializeImageData(imageData) as any\n}\n\nexport function deserializeRawImageData<T extends SerializedImageData>(serialized: T): ImageDataLike {\n return {\n width: serialized.width,\n height: serialized.height,\n data: base64DecodeArrayBuffer(serialized.data as Base64EncodedUInt8Array),\n }\n}\n\nexport function deserializeImageData<T extends SerializedImageData>(serialized: T): ImageData {\n const data = base64DecodeArrayBuffer(serialized.data as Base64EncodedUInt8Array)\n\n return new ImageData(data as ImageDataArray, serialized.width, serialized.height) as any\n}\n\nexport function deserializeNullableImageData<T extends SerializedImageData | null>(serialized: T): T extends null ? null : ImageData {\n if (!serialized) return null as any\n return deserializeImageData(serialized) as any\n}\n","import type { Rect } from '../_types'\n\nexport function writeImageData(\n imageData: ImageData,\n data: Uint8ClampedArray,\n rect: Rect,\n): void\nexport function writeImageData(\n imageData: ImageData,\n data: Uint8ClampedArray,\n x: number,\n y: number,\n w: number,\n h: number,\n): void\nexport function writeImageData(\n imageData: ImageData,\n data: Uint8ClampedArray,\n _x: Rect | number,\n _y?: number,\n _w?: number,\n _h?: number,\n): void {\n const { x, y, w, h } = typeof _x === 'object'\n ? _x\n : { x: _x, y: _y!, w: _w!, h: _h! }\n\n const { width: dstW, height: dstH, data: dst } = imageData\n\n // 1. Calculate the intersection of the patch and the canvas\n const x0 = Math.max(0, x)\n const y0 = Math.max(0, y)\n const x1 = Math.min(dstW, x + w)\n const y1 = Math.min(dstH, y + h)\n\n // If the intersection is empty, do nothing\n if (x1 <= x0 || y1 <= y0) return\n\n const rowLen = (x1 - x0) * 4\n const srcCol = x0 - x\n const srcYOffset = y0 - y\n const actualH = y1 - y0\n\n for (let row = 0; row < actualH; row++) {\n // Target index\n const dstStart = ((y0 + row) * dstW + x0) * 4\n\n // Source data index (must account for the offset if the rect was partially OOB)\n const srcRow = srcYOffset + row\n const o = (srcRow * w + srcCol) * 4\n\n dst.set(data.subarray(o, o + rowLen), dstStart)\n }\n}\n","import type { AnyMask } from '../index'\n\n/**\n * Creates a new copy of a mask.\n * Uses the underlying buffer's slice method for high-performance memory copying.\n */\nexport function copyMask<T extends AnyMask>(src: T): T {\n // Uint8Array.slice() is highly optimized at the engine level\n return src.slice() as T\n}\n","import type { AlphaMask, BinaryMask } from '../index'\n\n/**\n * Inverts a BinaryMask in-place.\n */\nexport function invertBinaryMask(dst: BinaryMask): void {\n const len = dst.length\n\n for (let i = 0; i < len; i++) {\n dst[i] = dst[i] === 0\n ? 1\n : 0\n }\n}\n\n/**\n * Inverts an AlphaMask in-place.\n */\nexport function invertAlphaMask(dst: AlphaMask): void {\n const len = dst.length\n\n for (let i = 0; i < len; i++) {\n dst[i] = 255 - dst[i]\n }\n}\n","import {\n type AnyMask,\n type AlphaMask,\n type ApplyMaskOptions,\n MaskType,\n} from '../_types'\n\n/**\n * Merges a source mask into a destination AlphaMask.\n */\nexport function mergeMasks(\n dst: AlphaMask,\n dstWidth: number,\n src: AnyMask,\n opts: ApplyMaskOptions,\n): void {\n const {\n x: targetX = 0,\n y: targetY = 0,\n w: width = 0,\n h: height = 0,\n alpha: globalAlpha = 255,\n maskType = MaskType.ALPHA,\n mw,\n mx = 0,\n my = 0,\n invertMask = false,\n } = opts\n\n if (width <= 0 || height <= 0 || globalAlpha === 0) {\n return\n }\n\n const sPitch = mw ?? width\n const isAlpha = maskType === MaskType.ALPHA\n\n for (let iy = 0; iy < height; iy++) {\n const dy = targetY + iy\n const sy = my + iy\n\n if (dy < 0 || sy < 0) {\n continue\n }\n\n for (let ix = 0; ix < width; ix++) {\n const dx = targetX + ix\n const sx = mx + ix\n\n if (dx < 0 || dx >= dstWidth || sx < 0 || sx >= sPitch) {\n continue\n }\n\n const dIdx = dy * dstWidth + dx\n const sIdx = sy * sPitch + sx\n const mVal = src[sIdx]\n let weight = globalAlpha\n\n if (isAlpha) {\n const effectiveM = invertMask\n ? 255 - mVal\n : mVal\n\n if (effectiveM === 0) {\n dst[dIdx] = 0\n continue\n }\n\n weight = globalAlpha === 255\n ? effectiveM\n : (effectiveM * globalAlpha + 128) >> 8\n } else {\n // Strict Binary 1/0 Logic\n const isHit = invertMask\n ? mVal === 0\n : mVal === 1\n\n if (!isHit) {\n dst[dIdx] = 0\n continue\n }\n\n // If binary hit, weight is just the global alpha\n weight = globalAlpha\n }\n\n if (weight === 0) {\n dst[dIdx] = 0\n continue\n }\n\n const da = dst[dIdx]\n\n if (da === 0) {\n // Already transparent\n } else if (weight === 255) {\n // Identity: keep da\n } else if (da === 255) {\n // Identity: result is weight\n dst[dIdx] = weight\n } else {\n dst[dIdx] = (da * weight + 128) >> 8\n }\n }\n }\n}\n","import { type AnyMask, type ApplyMaskOptions, MaskType } from '../_types'\nimport type { PixelData } from '../PixelData'\n\n/**\n * Directly applies a mask to a region of PixelData,\n * modifying the destination's alpha channel in-place.\n */\nexport function applyMaskToPixelData(\n dst: PixelData,\n mask: AnyMask,\n opts: ApplyMaskOptions,\n): void {\n const {\n x: targetX = 0,\n y: targetY = 0,\n w: width = dst.width,\n h: height = dst.height,\n alpha: globalAlpha = 255,\n maskType = MaskType.ALPHA,\n mw,\n mx = 0,\n my = 0,\n invertMask = false,\n } = opts\n\n let x = targetX\n let y = targetY\n let w = width\n let h = height\n\n // Clipping Logic\n if (x < 0) {\n w += x\n x = 0\n }\n\n if (y < 0) {\n h += y\n y = 0\n }\n\n const actualW = Math.min(w, dst.width - x)\n const actualH = Math.min(h, dst.height - y)\n\n if (actualW <= 0 || actualH <= 0 || globalAlpha === 0) {\n return\n }\n\n const dst32 = dst.data32\n const dw = dst.width\n const mPitch = mw ?? width\n const isAlpha = maskType === MaskType.ALPHA\n const dx = x - targetX\n const dy = y - targetY\n\n let dIdx = y * dw + x\n let mIdx = (my + dy) * mPitch + (mx + dx)\n\n const dStride = dw - actualW\n const mStride = mPitch - actualW\n\n for (let iy = 0; iy < actualH; iy++) {\n for (let ix = 0; ix < actualW; ix++) {\n const mVal = mask[mIdx]\n let weight = globalAlpha\n\n if (isAlpha) {\n const effectiveM = invertMask\n ? 255 - mVal\n : mVal\n\n // Short-circuit: if source is 0, destination alpha becomes 0\n if (effectiveM === 0) {\n dst32[dIdx] = (dst32[dIdx] & 0x00ffffff) >>> 0\n dIdx++\n mIdx++\n continue\n }\n\n weight = globalAlpha === 255\n ? effectiveM\n : (effectiveM * globalAlpha + 128) >> 8\n } else {\n // Strict Binary 1/0 Logic\n const isHit = invertMask\n ? mVal === 0\n : mVal === 1\n\n if (!isHit) {\n dst32[dIdx] = (dst32[dIdx] & 0x00ffffff) >>> 0\n dIdx++\n mIdx++\n continue\n }\n\n weight = globalAlpha\n }\n\n // If calculated weight is 0, clear alpha\n if (weight === 0) {\n dst32[dIdx] = (dst32[dIdx] & 0x00ffffff) >>> 0\n } else {\n const d = dst32[dIdx]\n const da = (d >>> 24)\n\n let finalAlpha = da\n\n if (da === 0) {\n // Already transparent\n } else if (weight === 255) {\n // Identity: keep original da\n } else if (da === 255) {\n // Identity: result is just the weight\n finalAlpha = weight\n } else {\n finalAlpha = (da * weight + 128) >> 8\n }\n\n dst32[dIdx] = ((d & 0x00ffffff) | (finalAlpha << 24)) >>> 0\n }\n\n dIdx++\n mIdx++\n }\n\n dIdx += dStride\n mIdx += mStride\n }\n}\n","import { type Color32, type ColorBlendOptions, MaskType } from '../_types'\nimport { sourceOverColor32 } from '../blend-modes'\nimport type { PixelData } from '../PixelData'\n\n/**\n * Fills a rectangle in the destination PixelData with a single color,\n * supporting blend modes, global alpha, and masking.\n */\nexport function blendColorPixelData(\n dst: PixelData,\n color: Color32,\n opts: ColorBlendOptions,\n): void {\n const {\n x: targetX = 0,\n y: targetY = 0,\n w: width = dst.width,\n h: height = dst.height,\n alpha: globalAlpha = 255,\n blendFn = sourceOverColor32,\n mask,\n maskType = MaskType.ALPHA,\n mw,\n mx = 0,\n my = 0,\n invertMask = false,\n } = opts\n\n if (globalAlpha === 0) return\n\n let x = targetX\n let y = targetY\n let w = width\n let h = height\n\n // 1. Destination Clipping\n if (x < 0) {\n w += x\n x = 0\n }\n if (y < 0) {\n h += y\n y = 0\n }\n\n const actualW = Math.min(w, dst.width - x)\n const actualH = Math.min(h, dst.height - y)\n\n if (actualW <= 0 || actualH <= 0) return\n\n const dst32 = dst.data32\n const dw = dst.width\n const mPitch = mw ?? width\n const isAlphaMask = maskType === MaskType.ALPHA\n\n const dx = x - targetX\n const dy = y - targetY\n\n let dIdx = y * dw + x\n let mIdx = (my + dy) * mPitch + (mx + dx)\n\n const dStride = dw - actualW\n const mStride = mPitch - actualW\n\n // Pre-calculate the source color with global alpha\n const baseSrcColor = color\n const baseSrcAlpha = (baseSrcColor >>> 24)\n\n for (let iy = 0; iy < actualH; iy++) {\n for (let ix = 0; ix < actualW; ix++) {\n\n // Early exit if source pixel is already transparent\n if (baseSrcAlpha === 0) {\n dIdx++\n mIdx++\n continue\n }\n\n let weight = globalAlpha\n\n if (mask) {\n const mVal = mask[mIdx]\n\n if (isAlphaMask) {\n const effectiveM = invertMask\n ? 255 - mVal\n : mVal\n\n // If mask is transparent, skip\n if (effectiveM === 0) {\n dIdx++\n mIdx++\n continue\n }\n\n // globalAlpha is not a factor\n if (globalAlpha === 255) {\n weight = effectiveM\n // mask is not a factor\n } else if (effectiveM === 255) {\n weight = globalAlpha\n } else {\n // use rounding-corrected multiplication\n weight = (effectiveM * globalAlpha + 128) >> 8\n }\n } else {\n const isHit = invertMask\n ? mVal === 0\n : mVal === 1\n\n if (!isHit) {\n dIdx++\n mIdx++\n continue\n }\n\n weight = globalAlpha\n }\n\n // Final safety check for weight (can be 0 if globalAlpha or alphaMask rounds down)\n if (weight === 0) {\n dIdx++\n mIdx++\n continue\n }\n }\n\n // Apply Weight to Source Alpha\n let currentSrcAlpha = baseSrcAlpha\n let currentSrcColor = baseSrcColor\n\n if (weight < 255) {\n if (baseSrcAlpha === 255) {\n currentSrcAlpha = weight\n } else {\n currentSrcAlpha = (baseSrcAlpha * weight + 128) >> 8\n }\n\n if (currentSrcAlpha === 0) {\n dIdx++\n mIdx++\n continue\n }\n\n currentSrcColor = ((baseSrcColor & 0x00ffffff) | (currentSrcAlpha << 24)) >>> 0 as Color32\n }\n\n dst32[dIdx] = blendFn(currentSrcColor, dst32[dIdx] as Color32)\n\n dIdx++\n mIdx++\n }\n\n dIdx += dStride\n mIdx += mStride\n }\n}\n","import { type Color32, MaskType, type PixelBlendOptions } from '../_types'\nimport { sourceOverColor32 } from '../blend-modes'\nimport type { PixelData } from '../PixelData'\n\n/**\n * Blits source PixelData into a destination PixelData using 32-bit integer bitwise blending.\n * This function bypasses standard ImageData limitations by operating directly on\n * Uint32Array views. It supports various blend modes, binary/alpha masking, and\n * automatic clipping of both source and destination bounds.\n * @example\n *\n * const dst = new PixelData(ctx.getImageData(0,0,100,100))\n * blendImageData32(dst, sprite, {\n * blendFn: COLOR_32_BLEND_MODES.multiply,\n * mask: brushMask,\n * maskType: MaskType.ALPHA\n * });\n */\nexport function blendPixelData(\n dst: PixelData,\n src: PixelData,\n opts: PixelBlendOptions,\n) {\n const {\n x: targetX = 0,\n y: targetY = 0,\n sx: sourceX = 0,\n sy: sourceY = 0,\n w: width = src.width,\n h: height = src.height,\n alpha: globalAlpha = 255,\n blendFn = sourceOverColor32,\n mask,\n maskType = MaskType.ALPHA,\n mw,\n mx = 0,\n my = 0,\n invertMask = false,\n } = opts\n\n if (globalAlpha === 0) return\n\n let x = targetX\n let y = targetY\n let sx = sourceX\n let sy = sourceY\n let w = width\n let h = height\n\n // 1. Source Clipping\n if (sx < 0) {\n x -= sx\n w += sx\n sx = 0\n }\n if (sy < 0) {\n y -= sy\n h += sy\n sy = 0\n }\n w = Math.min(w, src.width - sx)\n h = Math.min(h, src.height - sy)\n\n // 2. Destination Clipping\n if (x < 0) {\n sx -= x\n w += x\n x = 0\n }\n if (y < 0) {\n sy -= y\n h += y\n y = 0\n }\n\n const actualW = Math.min(w, dst.width - x)\n const actualH = Math.min(h, dst.height - y)\n\n if (actualW <= 0 || actualH <= 0) return\n\n const dst32 = dst.data32\n const src32 = src.data32\n const dw = dst.width\n const sw = src.width\n const mPitch = mw ?? width\n const isAlphaMask = maskType === MaskType.ALPHA\n\n const dx = x - targetX\n const dy = y - targetY\n\n let dIdx = y * dw + x\n let sIdx = sy * sw + sx\n let mIdx = (my + dy) * mPitch + (mx + dx)\n\n const dStride = dw - actualW\n const sStride = sw - actualW\n const mStride = mPitch - actualW\n\n for (let iy = 0; iy < actualH; iy++) {\n for (let ix = 0; ix < actualW; ix++) {\n const baseSrcColor = src32[sIdx] as Color32\n const baseSrcAlpha = (baseSrcColor >>> 24)\n\n // Early exit if source pixel is already transparent\n if (baseSrcAlpha === 0) {\n dIdx++\n sIdx++\n mIdx++\n continue\n }\n\n let weight = globalAlpha\n\n if (mask) {\n const mVal = mask[mIdx]\n\n if (isAlphaMask) {\n const effectiveM = invertMask\n ? 255 - mVal\n : mVal\n\n // If mask is transparent, skip\n if (effectiveM === 0) {\n dIdx++\n sIdx++\n mIdx++\n continue\n }\n\n // globalAlpha is not a factor\n if (globalAlpha === 255) {\n weight = effectiveM\n // mask is not a factor\n } else if (effectiveM === 255) {\n weight = globalAlpha\n } else {\n // use rounding-corrected multiplication\n weight = (effectiveM * globalAlpha + 128) >> 8\n }\n } else {\n const isHit = invertMask\n ? mVal === 0\n : mVal === 1\n\n if (!isHit) {\n dIdx++\n sIdx++\n mIdx++\n continue\n }\n\n weight = globalAlpha\n }\n\n // Final safety check for weight (can be 0 if globalAlpha or alphaMask rounds down)\n if (weight === 0) {\n dIdx++\n sIdx++\n mIdx++\n continue\n }\n }\n\n // Apply Weight to Source Alpha\n let currentSrcAlpha = baseSrcAlpha\n let currentSrcColor = baseSrcColor\n\n if (weight < 255) {\n if (baseSrcAlpha === 255) {\n currentSrcAlpha = weight\n } else {\n currentSrcAlpha = (baseSrcAlpha * weight + 128) >> 8\n }\n\n if (currentSrcAlpha === 0) {\n dIdx++\n sIdx++\n mIdx++\n continue\n }\n\n currentSrcColor = ((baseSrcColor & 0x00ffffff) | (currentSrcAlpha << 24)) >>> 0 as Color32\n }\n\n dst32[dIdx] = blendFn(currentSrcColor, dst32[dIdx] as Color32)\n\n dIdx++\n sIdx++\n mIdx++\n }\n\n dIdx += dStride\n sIdx += sStride\n mIdx += mStride\n }\n}\n","import type { Color32, Rect } from '../_types'\nimport type { PixelData } from '../PixelData'\n\n/**\n * A high-performance solid fill for PixelData.\n */\nexport function fillPixelData(\n dst: PixelData,\n color: Color32,\n rect?: Partial<Rect>,\n): void {\n const {\n x: targetX = 0,\n y: targetY = 0,\n w: width = dst.width,\n h: height = dst.height,\n } = rect || {}\n\n let x = targetX\n let y = targetY\n let w = width\n let h = height\n\n // Destination Clipping\n if (x < 0) {\n w += x\n x = 0\n }\n if (y < 0) {\n h += y\n y = 0\n }\n\n const actualW = Math.min(w, dst.width - x)\n const actualH = Math.min(h, dst.height - y)\n\n if (actualW <= 0 || actualH <= 0) {\n return\n }\n\n const dst32 = dst.data32\n const dw = dst.width\n\n // Optimization: If filling the entire buffer, use the native .fill()\n if (actualW === dw && actualH === dst.height && x === 0 && y === 0) {\n dst32.fill(color)\n return\n }\n\n // Row-by-row fill for partial rectangles\n for (let iy = 0; iy < actualH; iy++) {\n const start = (y + iy) * dw + x\n const end = start + actualW\n dst32.fill(color, start, end)\n }\n}\n","import type { Color32, Rect } from '../_types'\nimport type { PixelData } from '../PixelData'\nimport { fillPixelData } from './fillPixelData'\n\n/**\n * Clears a region of the PixelData to transparent (0x00000000).\n * Internally uses the optimized fillPixelData.\n */\nexport function clearPixelData(\n dst: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