Spaces:
Sleeping
Sleeping
File size: 2,413 Bytes
3530df7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | import { expect, test, describe } from "vitest";
import { makeTestImage } from "@jimp/test-utils";
import { createJimp } from "@jimp/core";
import { methods } from "./index.js";
const jimp = createJimp({ plugins: [methods] });
describe("Mask", () => {
const imgSrcOpaq = jimp.fromBitmap(
// prettier-ignore
makeTestImage(
"▴□▾□■□",
"■▴■▾■□",
"■□▴□▾□",
"■□■▴■▾"
),
);
const imgSrcAlpa = jimp.fromBitmap(
// prettier-ignore
makeTestImage(
"▴▵▾▿",
"▴▵▾▿",
"▴▵▾▿"
),
);
const maskGrayBig = jimp.fromBitmap(
// prettier-ignore
makeTestImage(
"048840",
"8CFFC8",
"8CFFC8",
"048840"
),
);
const maskGraySmall = jimp.fromBitmap(
// prettier-ignore
makeTestImage(
"0369",
"369C",
"69CF"
),
);
const maskColor = jimp.fromBitmap(
// prettier-ignore
makeTestImage(
"▴▴▾▾",
"▪▪▰▰",
"□□□□"
),
);
test("Affect opaque image with a gray mask with the same size", () => {
expect(imgSrcOpaq.clone().mask(maskGrayBig)).toMatchSnapshot();
});
test("Affect opaque image with a gray mask with the same size, blited", () => {
expect(
imgSrcOpaq.clone().mask({ src: maskGrayBig, x: 1, y: 1 }),
).toMatchSnapshot();
});
test("Affect opaque image with a gray mask with the same size, blited negative", () => {
expect(
imgSrcOpaq.clone().mask({ src: maskGrayBig, x: -1, y: -1 }),
).toMatchSnapshot();
});
test("Affect opaque image with a smaller gray mask", () => {
expect(imgSrcOpaq.clone().mask(maskGraySmall)).toMatchSnapshot();
});
test("Affect opaque image with a smaller gray mask, blited", () => {
expect(
imgSrcOpaq.clone().mask({ src: maskGraySmall, x: 1, y: 1 }),
).toMatchSnapshot();
});
test("Affect alpha image with a bigger gray mask", () => {
expect(imgSrcAlpa.clone().mask(maskGrayBig)).toMatchSnapshot();
});
test("Affect alpha image with a bigger gray mask, blited", () => {
expect(
imgSrcAlpa.clone().mask({ src: maskGrayBig, x: -1, y: -1 }),
).toMatchSnapshot();
});
test("Affect opaque image with a colored mask", () => {
expect(
imgSrcOpaq.clone().mask({ src: maskColor, x: 1, y: 1 }),
).toMatchSnapshot();
});
});
|