import { describe, expect, test } from "bun:test"; import { applyMaskedContentModeToRgba } from "./inpaintPrep"; describe("inpaint prep", () => { test("converts only masked original pixels to grayscale", () => { const pixels = new Uint8ClampedArray([ 255, 0, 0, 255, 0, 0, 255, 255, ]); const mask = new Uint8ClampedArray([255, 0]); const next = applyMaskedContentModeToRgba(pixels, 2, 1, mask, "original"); expect(next[0]).toBe(next[1]); expect(next[1]).toBe(next[2]); expect(Array.from(next.slice(4, 8))).toEqual([0, 0, 255, 255]); }); test("uses an edge map inside the mask without recoloring unmasked context", () => { const pixels = new Uint8ClampedArray([ 255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 0, 255, ]); const mask = new Uint8ClampedArray([255, 0, 0, 0]); const next = applyMaskedContentModeToRgba(pixels, 2, 2, mask, "edges"); expect(next[0]).toBe(next[1]); expect(next[1]).toBe(next[2]); expect(Array.from(next.slice(4, 8))).toEqual([0, 255, 0, 255]); expect(Array.from(next.slice(8, 12))).toEqual([0, 0, 255, 255]); expect(Array.from(next.slice(12, 16))).toEqual([255, 255, 0, 255]); }); });