From 1d3908410bdf8f87cba7501c4b022bc901ebd535 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 24 Mar 2023 01:18:49 -0700 Subject: [PATCH] using the 'pal' colors is closer? why???? --- dither-image.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/dither-image.js b/dither-image.js index ebe7faf..1bf07af 100644 --- a/dither-image.js +++ b/dither-image.js @@ -68,6 +68,39 @@ class RGB { 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) { return new RGB( callback(this.r), @@ -166,6 +199,7 @@ class RGB { } } +/* // snarfed from https://lospec.com/palette-list/atari-8-bit-family-gtia // which was calculated with Retrospecs App's Atari 800 emulator let atariRGB = [ @@ -427,6 +461,14 @@ let atariRGB = [ 0xffff99, ].map((hex) => RGB.fromHex(hex).fromNTSC()); //].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.