feat: add alpha and morphology core tools
This commit is contained in:
@@ -73,6 +73,18 @@ export function invertAlpha(img: PixelImage): PixelImage {
|
||||
return out;
|
||||
}
|
||||
|
||||
export function hardenAlpha(img: PixelImage, thresholdPercent: number): PixelImage {
|
||||
const threshold = (clamp(thresholdPercent, 0, 100) / 100) * 255;
|
||||
const out = createPixelImage(img.width, img.height);
|
||||
for (let i = 0; i < out.data.length; i += 4) {
|
||||
out.data[i] = img.data[i];
|
||||
out.data[i + 1] = img.data[i + 1];
|
||||
out.data[i + 2] = img.data[i + 2];
|
||||
out.data[i + 3] = img.data[i + 3] >= threshold ? 255 : 0;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function colorMask(img: PixelImage, hex: string, tolerancePercent = 0): PixelImage {
|
||||
const [targetR, targetG, targetB] = parseHex(hex);
|
||||
const tolerance = (clamp(tolerancePercent, 0, 100) / 100) * MAX_COLOR_DISTANCE;
|
||||
|
||||
Reference in New Issue
Block a user