feat: add instruments registry

This commit is contained in:
2026-08-22 10:06:49 +05:00
parent 9ccc9f94ac
commit 719bda2e22
4 changed files with 368 additions and 2 deletions
+18 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { parseHex, removeColorToAlpha } from './alpha';
import { flattenOntoColor, parseHex, removeColorToAlpha } from './alpha';
import { makeImage } from './test-helpers';
describe('removeColorToAlpha', () => {
@@ -55,6 +55,23 @@ describe('removeColorToAlpha', () => {
});
});
describe('flattenOntoColor', () => {
it('непрозрачный пиксель не меняется, альфа становится 255', () => {
const out = flattenOntoColor(makeImage(1, 1, [[10, 20, 30, 255]]), '#ffffff');
expect([...out.data]).toEqual([10, 20, 30, 255]);
});
it('полностью прозрачный пиксель становится цветом подложки', () => {
const out = flattenOntoColor(makeImage(1, 1, [[99, 99, 99, 0]]), '#ff8040');
expect([...out.data]).toEqual([255, 128, 64, 255]);
});
it('полупрозрачный пиксель смешивается с подложкой', () => {
const out = flattenOntoColor(makeImage(1, 1, [[10, 20, 30, 128]]), '#ffffff');
expect([...out.data]).toEqual([132, 137, 142, 255]);
});
});
describe('parseHex', () => {
it('разбирает #rrggbb, rrggbb, #rgb', () => {
expect(parseHex('#ff8040')).toEqual([255, 128, 64]);