From 1dc78a9b5b8bb809e59f8a24e630d812609be373 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Mon, 7 Aug 2017 18:39:30 -0230 Subject: [PATCH] Pre-calculate phosphor colours, and remove redundant shift parameter. This leads to nice speedups in the TIASurface::render() method. --- src/emucore/TIASurface.cxx | 21 ++++++++++----------- src/emucore/TIASurface.hxx | 7 +++++-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/emucore/TIASurface.cxx b/src/emucore/TIASurface.cxx index 5c84874f0..2483e6a1b 100644 --- a/src/emucore/TIASurface.cxx +++ b/src/emucore/TIASurface.cxx @@ -55,6 +55,11 @@ TIASurface::TIASurface(OSystem& system) myBaseTiaSurface = myFB.allocateSurface(kTIAW*2, kTIAH); memset(myRGBFramebuffer, 0, AtariNTSC::outWidth(kTIAW) * kTIAH); + + // Precalculate the average colors for the 'phosphor' effect + for(Int16 c = 255; c >= 0; c--) + for(Int16 p = 255; p >= 0; p--) + myPhosphorPalette[c][p] = getPhosphor(c, p); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -139,7 +144,7 @@ uInt32 TIASurface::pixel(uInt32 idx, uInt8 shift) const uInt32 p = myRGBFramebuffer[idx]; // Mix current calculated frame with previous displayed frame - const uInt32 retVal = getRGBPhosphor(myPalette[c], p, shift); + const uInt32 retVal = getRGBPhosphor(myPalette[c], p); // Store back into displayed frame buffer (for next frame) myRGBFramebuffer[idx] = retVal; @@ -237,7 +242,7 @@ void TIASurface::enablePhosphor(bool enable, int blend) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -inline uInt32 TIASurface::getRGBPhosphor(uInt32 c, uInt32 p, uInt8 shift) const +inline uInt32 TIASurface::getRGBPhosphor(uInt32 c, uInt32 p) const { #define TO_RGB(color, red, green, blue) \ red = color >> 16; green = color >> 8; blue = color; @@ -248,15 +253,9 @@ inline uInt32 TIASurface::getRGBPhosphor(uInt32 c, uInt32 p, uInt8 shift) const TO_RGB(p, rp, gp, bp); // Mix current calculated frame with previous displayed frame - uInt8 rn = getPhosphor(rc, rp); - uInt8 gn = getPhosphor(gc, gp); - uInt8 bn = getPhosphor(bc, bp); - - if(shift) - { - // Convert RGB to grayscale - rn = gn = bn = uInt8(0.2126*rn + 0.7152*gn + 0.0722*bn); - } + uInt8 rn = myPhosphorPalette[rc][rp]; + uInt8 gn = myPhosphorPalette[gc][gp]; + uInt8 bn = myPhosphorPalette[bc][bp]; return (rn << 16) | (gn << 8) | bn; } diff --git a/src/emucore/TIASurface.hxx b/src/emucore/TIASurface.hxx index 549c1dfcc..8f2182fe9 100644 --- a/src/emucore/TIASurface.hxx +++ b/src/emucore/TIASurface.hxx @@ -119,7 +119,7 @@ class TIASurface @return Averaged value of the two colors */ - inline uInt8 getPhosphor(uInt8 c1, uInt8 c2) const { + inline uInt8 getPhosphor(const uInt8 c1, uInt8 c2) const { // Use maximum of current and decayed previous values c2 = uInt8(c2 * myPhosphorPercent); if(c1 > c2) return c1; // raise (assumed immediate) @@ -134,7 +134,7 @@ class TIASurface @return Averaged value of the two RGB colors */ - uInt32 getRGBPhosphor(uInt32 c, uInt32 cp, uInt8 shift = 0) const; + uInt32 getRGBPhosphor(uInt32 c, uInt32 cp) const; /** Enable/disable/query NTSC filtering effects. @@ -184,6 +184,9 @@ class TIASurface // Amount to blend when using phosphor effect float myPhosphorPercent; + + // Precalculated averaged phosphor colors + uInt8 myPhosphorPalette[256][256]; ///////////////////////////////////////////////////////////// // Use scanlines in TIA rendering mode