2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-02-10 04:53:22 +01:00
|
|
|
const colorspace = zrequire("colorspace");
|
2017-05-25 09:17:18 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("sRGB_to_linear", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let srgb_color = 0.0042;
|
2020-10-07 11:54:18 +02:00
|
|
|
let expected_value = 0.0042 / 255 / 12.92;
|
2019-11-02 00:06:25 +01:00
|
|
|
let actual_value = colorspace.sRGB_to_linear(srgb_color);
|
2017-05-25 09:17:18 +02:00
|
|
|
assert.equal(actual_value, expected_value);
|
|
|
|
|
2020-10-07 11:54:18 +02:00
|
|
|
srgb_color = 255;
|
2017-05-25 09:17:18 +02:00
|
|
|
expected_value = 1;
|
|
|
|
actual_value = colorspace.sRGB_to_linear(srgb_color);
|
|
|
|
assert.equal(actual_value, expected_value);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 09:17:18 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("rgb_luminance", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const channel = [1, 1, 1];
|
|
|
|
const expected_value = 1;
|
|
|
|
const actual_value = colorspace.rgb_luminance(channel);
|
2017-05-25 09:17:18 +02:00
|
|
|
assert.equal(actual_value, expected_value);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-05-25 09:17:18 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("luminance_to_lightness", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let luminance = 0;
|
2020-07-15 00:34:28 +02:00
|
|
|
let expected_value = (116 * 4) / 29 - 16;
|
2019-11-02 00:06:25 +01:00
|
|
|
let actual_value = colorspace.luminance_to_lightness(luminance);
|
2017-05-25 09:17:18 +02:00
|
|
|
assert.equal(actual_value, expected_value);
|
|
|
|
|
|
|
|
luminance = 1;
|
|
|
|
expected_value = 100;
|
|
|
|
actual_value = colorspace.luminance_to_lightness(luminance);
|
|
|
|
assert.equal(actual_value, expected_value);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|