mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-09-14 21:46:35 +00:00
feat: add slider field
This commit is contained in:
@@ -1,7 +1,18 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { brightnessContrast, grayscale, invert } from './color';
|
||||
import { brightnessContrast, grayscale, invert, rgbToHex } from './color';
|
||||
import { makeImage } from './test-helpers';
|
||||
|
||||
describe('rgbToHex', () => {
|
||||
it('форматирует базовые цвета', () => {
|
||||
expect(rgbToHex(255, 0, 0)).toBe('#ff0000');
|
||||
expect(rgbToHex(1, 2, 3)).toBe('#010203');
|
||||
});
|
||||
|
||||
it('округляет дробные значения и клампит диапазон', () => {
|
||||
expect(rgbToHex(127.6, -5, 300)).toBe('#8000ff');
|
||||
});
|
||||
});
|
||||
|
||||
describe('grayscale', () => {
|
||||
it('считает luma по весам BT.601 с округлением', () => {
|
||||
const out = grayscale(
|
||||
|
||||
@@ -42,6 +42,11 @@ export function brightnessContrast(
|
||||
return out;
|
||||
}
|
||||
|
||||
export function rgbToHex(r: number, g: number, b: number): string {
|
||||
const byte = (v: number) => clamp(Math.round(v), 0, 255).toString(16).padStart(2, '0');
|
||||
return `#${byte(r)}${byte(g)}${byte(b)}`;
|
||||
}
|
||||
|
||||
function clamp(value: number, min: number, max: number): number {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user