feat: core instruments

This commit is contained in:
2026-08-22 09:49:53 +05:00
parent 4ec2b418fd
commit 9ccc9f94ac
13 changed files with 829 additions and 2 deletions
+26
View File
@@ -0,0 +1,26 @@
import type { PixelImage } from './types';
export type ImageInfo = {
width: number;
height: number;
hasAlpha: boolean;
colorCount: number;
};
export function imageInfo(img: PixelImage): ImageInfo {
let hasAlpha = false;
const seen = new Set<number>();
for (let i = 0; i < img.data.length; i += 4) {
if (!hasAlpha && img.data[i + 3] !== 255) {
hasAlpha = true;
}
const key =
((img.data[i] << 24) |
(img.data[i + 1] << 16) |
(img.data[i + 2] << 8) |
img.data[i + 3]) >>>
0;
seen.add(key);
}
return { width: img.width, height: img.height, hasAlpha, colorCount: seen.size };
}