just use srgb for consistency with the pngs

This commit is contained in:
Brooke Vibber 2023-03-24 00:28:07 -07:00
parent 1d3712be5c
commit fe6314e2a0

View file

@ -13,6 +13,7 @@ function zeroes(n) {
return arr;
}
/*
function toLinear(val) {
// use a 2.4 gamma approximation
// this is BT.1886 compatible
@ -27,6 +28,18 @@ function fromLinear(val) {
unit **= (1 / 2.4);
return unit * 255;
}
*/
function fromSRGB(val) {
val /= 255;
if (val <= 0.04045) {
val /= 12.92;
} else {
val = ((val + 0.055) / 1.055) ** 2.4;
}
val *= 255;
return val;
}
function toSRGB(val) {
val /= 255;
@ -65,6 +78,7 @@ class RGB {
);
}
/*
toLinear() {
return this.map(toLinear);
}
@ -72,6 +86,11 @@ class RGB {
fromLinear() {
return this.map(fromLinear);
}
*/
fromSRGB() {
return this.map(fromSRGB);
}
toSRGB() {
return this.map(toSRGB);
@ -410,7 +429,7 @@ let atariRGB = [
0xf6e46f,
0xfffa84,
0xffff99,
].map((hex) => RGB.fromHex(hex).toLinear());
].map((hex) => RGB.fromHex(hex).fromSRGB());
//].map((hex) => RGB.fromHex(hex));
/**
@ -667,7 +686,7 @@ function imageToLinearRGB(rgba) {
rgba[i + 0],
rgba[i + 1],
rgba[i + 2]
).toLinear());
).fromSRGB());
}
return input;
}