1
0
Fork 0

clockbg 0.06: 25% speed improvement if Math.randInt exists (2v25 fw)

master
Gordon Williams 2024-10-25 09:38:00 +01:00
parent 4ff01d1db0
commit 242eda245b
3 changed files with 9 additions and 4 deletions

View File

@ -5,3 +5,4 @@
'Plasma' generative background 'Plasma' generative background
Add a 'view' option in settings menu to view the current background Add a 'view' option in settings menu to view the current background
0.05: Random square+plasma speed improvements (~2x faster) 0.05: Random square+plasma speed improvements (~2x faster)
0.06: 25% speed improvement if Math.randInt exists (2v25 fw)

View File

@ -1,6 +1,7 @@
let settings; let settings;
exports.reload = function() { exports.reload = function() {
//let t = Date.now();
settings = Object.assign({ settings = Object.assign({
style : "randomcolor", style : "randomcolor",
colors : ["#F00","#0F0","#00F"] colors : ["#F00","#0F0","#00F"]
@ -17,7 +18,8 @@ exports.reload = function() {
let bpp = (settings.colors.length>4)?4:2; let bpp = (settings.colors.length>4)?4:2;
let bg = Graphics.createArrayBuffer(11,11,bpp,{msb:true}); let bg = Graphics.createArrayBuffer(11,11,bpp,{msb:true});
let u32 = new Uint32Array(bg.buffer); // faster to do 1/4 of the ops of E.mapInPlace(bg.buffer, bg.buffer, ()=>Math.random()*256); let u32 = new Uint32Array(bg.buffer); // faster to do 1/4 of the ops of E.mapInPlace(bg.buffer, bg.buffer, ()=>Math.random()*256);
E.mapInPlace(u32, u32, function(r,n){"ram";return r()*n}.bind(null,Math.random,0x100000000)); // random pixels if (Math.randInt) E.mapInPlace(u32, u32, Math.randInt); // random pixels
else E.mapInPlace(u32, u32, function(r,n){"ram";return r()*n}.bind(null,Math.random,0x100000000)); // random pixels
bg.buffer[bg.buffer.length-1]=Math.random()*256; // 11x11 isn't a multiple of 4 bytes - we need to set the last one! bg.buffer[bg.buffer.length-1]=Math.random()*256; // 11x11 isn't a multiple of 4 bytes - we need to set the last one!
bg.palette = new Uint16Array(1<<bpp); bg.palette = new Uint16Array(1<<bpp);
bg.palette.set(settings.colors.map(c=>g.toColor(c))); bg.palette.set(settings.colors.map(c=>g.toColor(c)));
@ -28,7 +30,8 @@ exports.reload = function() {
settings.style = "image"; settings.style = "image";
let bg = Graphics.createArrayBuffer(16,16,4,{msb:true}); let bg = Graphics.createArrayBuffer(16,16,4,{msb:true});
let u32 = new Uint32Array(bg.buffer); // faster to do 1/4 of the ops of E.mapInPlace(bg.buffer, bg.buffer, ()=>Math.random()*256); let u32 = new Uint32Array(bg.buffer); // faster to do 1/4 of the ops of E.mapInPlace(bg.buffer, bg.buffer, ()=>Math.random()*256);
E.mapInPlace(u32, u32, function(r,n){"ram";return r()*n}.bind(null,Math.random,0x100000000)); // random pixels if (Math.randInt) E.mapInPlace(u32, u32, Math.randInt); // random pixels
else E.mapInPlace(u32, u32, function(r,n){"ram";return r()*n}.bind(null,Math.random,0x100000000)); // random pixels
bg.filter([ // a gaussian filter to smooth out bg.filter([ // a gaussian filter to smooth out
1, 4, 7, 4, 1, 1, 4, 7, 4, 1,
4,16,26,16, 4, 4,16,26,16, 4,
@ -42,6 +45,7 @@ exports.reload = function() {
settings.imgOpt = {scale:11}; settings.imgOpt = {scale:11};
delete settings.colors; delete settings.colors;
} }
//console.log("bg",Date.now()-t);
}; };
exports.reload(); exports.reload();

View File

@ -1,7 +1,7 @@
{ "id": "clockbg", { "id": "clockbg",
"name": "Clock Backgrounds", "name": "Clock Backgrounds",
"shortName":"Backgrounds", "shortName":"Backgrounds",
"version": "0.05", "version": "0.06",
"description": "Library that allows clocks to include a custom background (generated on demand or uploaded).", "description": "Library that allows clocks to include a custom background (generated on demand or uploaded).",
"icon": "app.png", "icon": "app.png",
"screenshots": [{"url":"screenshot.png"},{"url":"screenshot2.png"},{"url":"screenshot3.png"}], "screenshots": [{"url":"screenshot.png"},{"url":"screenshot2.png"},{"url":"screenshot3.png"}],