using the 'pal' colors is closer? why????

This commit is contained in:
Brooke Vibber 2023-03-24 01:18:49 -07:00
parent 325102021b
commit 1d3908410b

View file

@ -68,6 +68,39 @@ class RGB {
return new RGB(r,g,b); return new RGB(r,g,b);
} }
static fromGTIA(val) {
// This seems off from what Atari800 does
// https://forums.atariage.com/topic/107853-need-the-256-colors/page/2/#comment-1312467
let cr = (val >> 4) & 15;
let lm = val & 15;
let crlv = cr ? 50 : 0;
/*
let phase = ((cr - 1) * 25 - 58) * (2 * Math.PI / 360);
let y = 255 * (lm + 1) / 16;
let i = crlv * Math.cos(phase);
let q = crlv * Math.sin(phase);
let r = y + 0.956 * i + 0.621 * q;
let g = y - 0.272 * i - 0.647 * q;
let b = y - 1.107 * i + 1.704 * q;
*/
// PAL
let phase = ((cr - 1) * 25.7 - 15) * (2 * Math.PI / 360);
let y = 255 * (lm + 1) / 16;
let i = crlv * Math.cos(phase);
let q = crlv * Math.sin(phase);
let r = y + 0.956 * i + 0.621 * q;
let g = y - 0.272 * i - 0.647 * q;
let b = y - 1.107 * i + 1.704 * q;
return new RGB(r, g, b).clamp().fromSRGB();
}
map(callback) { map(callback) {
return new RGB( return new RGB(
callback(this.r), callback(this.r),
@ -166,6 +199,7 @@ class RGB {
} }
} }
/*
// snarfed from https://lospec.com/palette-list/atari-8-bit-family-gtia // snarfed from https://lospec.com/palette-list/atari-8-bit-family-gtia
// which was calculated with Retrospecs App's Atari 800 emulator // which was calculated with Retrospecs App's Atari 800 emulator
let atariRGB = [ let atariRGB = [
@ -427,6 +461,14 @@ let atariRGB = [
0xffff99, 0xffff99,
].map((hex) => RGB.fromHex(hex).fromNTSC()); ].map((hex) => RGB.fromHex(hex).fromNTSC());
//].map((hex) => RGB.fromHex(hex)); //].map((hex) => RGB.fromHex(hex));
*/
let atariRGB = [];
for (let i = 0; i < 256; i++) {
atariRGB[i] = RGB.fromGTIA(i);
}
/** /**
* Dither RGB input data with a target palette size. * Dither RGB input data with a target palette size.