pixel-data-js 0.9.0 → 0.9.1
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 +84 -0
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.dev.js +81 -0
- package/dist/index.dev.js.map +1 -1
- package/dist/index.prod.cjs +84 -0
- package/dist/index.prod.cjs.map +1 -1
- package/dist/index.prod.d.ts +29 -19
- package/dist/index.prod.js +81 -0
- package/dist/index.prod.js.map +1 -1
- package/package.json +3 -2
- package/src/BlendModes/blend-mode-getters.ts +14 -0
- package/src/BlendModes/blend-modes-fast.ts +9 -13
- package/src/BlendModes/blend-modes-perfect.ts +7 -7
- package/src/BlendModes/blend-modes.ts +3 -0
- package/src/IndexedImage/getIndexedImageColorCounts.ts +20 -0
- package/src/_types.ts +6 -0
- package/src/index.ts +11 -2
package/dist/index.dev.cjs
CHANGED
|
@@ -111,7 +111,10 @@ __export(src_exports, {
|
|
|
111
111
|
pinLightFast: () => pinLightFast,
|
|
112
112
|
pinLightPerfect: () => pinLightPerfect,
|
|
113
113
|
pixelDataToAlphaMask: () => pixelDataToAlphaMask,
|
|
114
|
+
reflectPixelDataHorizontal: () => reflectPixelDataHorizontal,
|
|
115
|
+
reflectPixelDataVertical: () => reflectPixelDataVertical,
|
|
114
116
|
resizeImageData: () => resizeImageData,
|
|
117
|
+
rotatePixelData: () => rotatePixelData,
|
|
115
118
|
screenFast: () => screenFast,
|
|
116
119
|
screenPerfect: () => screenPerfect,
|
|
117
120
|
serializeImageData: () => serializeImageData,
|
|
@@ -2389,6 +2392,84 @@ function invertPixelData(pixelData) {
|
|
|
2389
2392
|
}
|
|
2390
2393
|
return pixelData;
|
|
2391
2394
|
}
|
|
2395
|
+
|
|
2396
|
+
// src/PixelData/reflectPixelData.ts
|
|
2397
|
+
function reflectPixelDataHorizontal(pixelData) {
|
|
2398
|
+
const width = pixelData.width;
|
|
2399
|
+
const height = pixelData.height;
|
|
2400
|
+
const data = pixelData.data32;
|
|
2401
|
+
const halfWidth = Math.floor(width / 2);
|
|
2402
|
+
for (let y = 0; y < height; y++) {
|
|
2403
|
+
const rowOffset = y * width;
|
|
2404
|
+
for (let x = 0; x < halfWidth; x++) {
|
|
2405
|
+
const leftIdx = rowOffset + x;
|
|
2406
|
+
const rightIdx = rowOffset + (width - 1 - x);
|
|
2407
|
+
const temp = data[leftIdx];
|
|
2408
|
+
data[leftIdx] = data[rightIdx];
|
|
2409
|
+
data[rightIdx] = temp;
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
function reflectPixelDataVertical(pixelData) {
|
|
2414
|
+
const width = pixelData.width;
|
|
2415
|
+
const height = pixelData.height;
|
|
2416
|
+
const data = pixelData.data32;
|
|
2417
|
+
const halfHeight = Math.floor(height / 2);
|
|
2418
|
+
for (let y = 0; y < halfHeight; y++) {
|
|
2419
|
+
const topRowOffset = y * width;
|
|
2420
|
+
const bottomRowOffset = (height - 1 - y) * width;
|
|
2421
|
+
for (let x = 0; x < width; x++) {
|
|
2422
|
+
const topIdx = topRowOffset + x;
|
|
2423
|
+
const bottomIdx = bottomRowOffset + x;
|
|
2424
|
+
const temp = data[topIdx];
|
|
2425
|
+
data[topIdx] = data[bottomIdx];
|
|
2426
|
+
data[bottomIdx] = temp;
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
// src/PixelData/rotatePixelData.ts
|
|
2432
|
+
function rotatePixelData(pixelData) {
|
|
2433
|
+
const width = pixelData.width;
|
|
2434
|
+
const height = pixelData.height;
|
|
2435
|
+
const data = pixelData.data32;
|
|
2436
|
+
if (width === height) {
|
|
2437
|
+
rotateSquareInPlace(pixelData);
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
const newWidth = height;
|
|
2441
|
+
const newHeight = width;
|
|
2442
|
+
const newData = new Uint32Array(data.length);
|
|
2443
|
+
for (let y = 0; y < height; y++) {
|
|
2444
|
+
for (let x = 0; x < width; x++) {
|
|
2445
|
+
const oldIdx = y * width + x;
|
|
2446
|
+
const newX = height - 1 - y;
|
|
2447
|
+
const newY = x;
|
|
2448
|
+
const newIdx = newY * newWidth + newX;
|
|
2449
|
+
newData[newIdx] = data[oldIdx];
|
|
2450
|
+
}
|
|
2451
|
+
}
|
|
2452
|
+
pixelData.width = newWidth;
|
|
2453
|
+
pixelData.height = newHeight;
|
|
2454
|
+
pixelData.data32 = newData;
|
|
2455
|
+
}
|
|
2456
|
+
function rotateSquareInPlace(pixelData) {
|
|
2457
|
+
const n = pixelData.width;
|
|
2458
|
+
const data = pixelData.data32;
|
|
2459
|
+
for (let i = 0; i < n / 2; i++) {
|
|
2460
|
+
for (let j = i; j < n - i - 1; j++) {
|
|
2461
|
+
const temp = data[i * n + j];
|
|
2462
|
+
const top = i * n + j;
|
|
2463
|
+
const right = j * n + (n - 1 - i);
|
|
2464
|
+
const bottom = (n - 1 - i) * n + (n - 1 - j);
|
|
2465
|
+
const left = (n - 1 - j) * n + i;
|
|
2466
|
+
data[top] = data[left];
|
|
2467
|
+
data[left] = data[bottom];
|
|
2468
|
+
data[bottom] = data[right];
|
|
2469
|
+
data[right] = temp;
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2392
2473
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2393
2474
|
0 && (module.exports = {
|
|
2394
2475
|
BlendMode,
|
|
@@ -2482,7 +2563,10 @@ function invertPixelData(pixelData) {
|
|
|
2482
2563
|
pinLightFast,
|
|
2483
2564
|
pinLightPerfect,
|
|
2484
2565
|
pixelDataToAlphaMask,
|
|
2566
|
+
reflectPixelDataHorizontal,
|
|
2567
|
+
reflectPixelDataVertical,
|
|
2485
2568
|
resizeImageData,
|
|
2569
|
+
rotatePixelData,
|
|
2486
2570
|
screenFast,
|
|
2487
2571
|
screenPerfect,
|
|
2488
2572
|
serializeImageData,
|