29 lines
951 B
TypeScript
29 lines
951 B
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { perspectiveCorrectPixels } from "../../src/scan/render";
|
|
import { defaultAdjustments } from "../../src/scan/types";
|
|
|
|
class TestImageData {
|
|
data: Uint8ClampedArray;
|
|
width: number;
|
|
height: number;
|
|
constructor(width: number, height: number) {
|
|
this.width = width;
|
|
this.height = height;
|
|
this.data = new Uint8ClampedArray(width * height * 4);
|
|
}
|
|
}
|
|
|
|
describe("scan render core", () => {
|
|
afterEach(() => vi.unstubAllGlobals());
|
|
|
|
it("maps an identity quad without changing corner colours", () => {
|
|
vi.stubGlobal("ImageData", TestImageData);
|
|
const source = new TestImageData(2, 2) as unknown as ImageData;
|
|
source.data.set([
|
|
255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 255, 255,
|
|
]);
|
|
const result = perspectiveCorrectPixels(source, 2, 2, defaultAdjustments());
|
|
expect([...result.data]).toEqual([...source.data]);
|
|
});
|
|
});
|