Optimization: modify RGB pixel data locally instead of calling functions.

This is allowed, since after analyzing the code, we see the pixel format
will always be ARGB8888 mode, so we can hard-code the logic to do the
conversion.

This leads to a measurable performance improvement, since we eliminate
3 function calls per RGB colour lookup.  And the calls themselves involved
IF statements and various other shifts that weren't needed.  Assuming
normal phosphor mode with 160x210 pixels, this saves 100,800 function calls
per frame!
This commit is contained in:
Stephen Anthony 2017-07-05 14:48:43 -02:30
parent ea59fdd3f2
commit 970804b9f3
1 changed files with 6 additions and 3 deletions

View File

@ -235,10 +235,13 @@ void TIASurface::enablePhosphor(bool enable, int blend)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline uInt32 TIASurface::getRGBPhosphor(uInt32 c, uInt32 p, uInt8 shift) const
{
#define TO_RGB(color, red, green, blue) \
red = color >> 16; green = color >> 8; blue = color;
uInt8 rc, gc, bc, rp, gp, bp;
myFB.getRGB(c, &rc, &gc, &bc);
myFB.getRGB(p, &rp, &gp, &bp);
TO_RGB(c, rc, gc, bc);
TO_RGB(p, rp, gp, bp);
// Mix current calculated frame with previous displayed frame
uInt8 rn = getPhosphor(rc, rp);
@ -251,7 +254,7 @@ inline uInt32 TIASurface::getRGBPhosphor(uInt32 c, uInt32 p, uInt8 shift) const
rn = gn = bn = uInt8(0.2126*rn + 0.7152*gn + 0.0722*bn);
}
return myFB.mapRGB(rn, gn, bn);
return (rn << 16) | (gn << 8) | bn;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -