A cache function that I did using the path+rotation_amt as the key. Seems to work fine now, not sure whether it is the optimal way without memory leak haha.
Just found that this and the code in line 486 has to be together to draw the disc art. Not sure why we need to have 2 DrawImage function call?
Code snippet on line 486, found on function draw_ui(gr)
if (!pref.cdart_ontop || displayLyrics) {
if (rotatedCD && !displayPlaylist && !displayLibrary && pref.display_cdart) {
if (showExtraDrawTiming) drawCD = fb.CreateProfiler('cdart');
gr.DrawImage(rotatedCD, cdart_size.x, cdart_size.y, cdart_size.w, cdart_size.h, 0, 0, rotatedCD.width, rotatedCD.height, 0);
// Spin CD Image with Cache
function spinningCDImage() {
var temp_cdart;
rot_amt = (rot_amt + pref.spin_rotation_amt) % 360; // use this as key
key = cdartPath + '' + rot_amt;
if (pref.display_cdart) { // drawing cdArt rotated is slow, so first draw it rotated into the rotatedCD image, and then draw rotatedCD image unrotated in on_paint
if (cdart && cdart_size.w > 0) { // cdart must be square so just use cdart_size.w (width)
// check if rotated disc art exist in cache
if (spinning_cdart_cache.getImage(key)) { // if this art at this rotation was cached
rotatedCD2 = spinning_cdart_cache.getImage(key);
console.log('cache hit!');
}
else {
rotatedCD2 = gdi.CreateImage(cdart_size.w, cdart_size.w);
rotCDimg = rotatedCD2.GetGraphics();
rotCDimg.DrawImage(cdart, 0, 0, cdart_size.w, cdart_size.h, 0, 0, cdart.Width, cdart.Height, rot_amt , 255);
// store the rotated bitmap as cache
spinning_cdart_cache.encache(rotatedCD2, key);
console.log("encache...");
rotatedCD2 = spinning_cdart_cache.getImage(key);
rotatedCD2.ReleaseGraphics(rotCDimg);
}
}
RepaintWindow();
}
Another demo video with cache and showing the options. Notice how the timer stopped when I set the update interval in setInterval to 16ms. Not sure how to circumvene this.
https://youtu.be/jchpoe_I53s