Tips on accelerating the YUV conversion...

10 views
Skip to first unread message

Brendan Robert

unread,
Jan 22, 2013, 12:57:23 PM1/22/13
to java...@googlegroups.com
At the cost of memory usage (this is really negligible though) you should consider using a multi-dimension array and pre-calculate the conversions of these math operations:
data[c] = (int) Math.min((data[c] & 0xff0000) * 1.30f, 0xff0000) & 0xff0000;
data[c+1] = (int) Math.min((data[c+1] & 0xff00) * 1.30f, 0xff00) & 0xff00;
data[c+2] = (int) Math.min((data[c+2] & 0xff) * 1.35f, 0xff);

That way you can use lookups for integer values rather than more expensive on-the-fly float operations. I saw a tremendous speedup in my Jace emulator when I implemented this. Here's my take on it, as well as the necessary YUV conversions, starting around line 196:


The Apple // display is of course very different than Atari. It only had a fixed palette of 16 colors so I was able to represent just those 16 colors. But you can see how I am able to convert each pixel to RGB more quickly on the fly using this lookup technique.

I am very impressed how you implemented other features! Great work!

-Brendan


Paulo Peccin

unread,
Jan 23, 2013, 5:06:56 PM1/23/13
to java...@googlegroups.com
Yes, it can be a good point for optimization! Thanks for the tip!

I did not invest much time in this yet, since its used only when you activate a special "CRT" mode to emulate the RGB triads. This code is not used during normal emulation.

But you're right. 
The 2600 has a 128 color palette, so I will need bigger arrays with pre-calculated values for PAL and NTSC, but not too big of a deal.

Regards,
Peccin

Reply all
Reply to author
Forward
0 new messages