varbpgw=newWorker('/static/bpgdec8a-ww.min.js');bpgw.onmessage=function(e){switch(e.data.type){case'log':console.log('Worker log:'+e.data.message);break;case'debug':console.log('Worker debug:'+e.data.data);debugger;break;case'res':varimg=e.data.image;varframes=e.data.frames;varloop_count=e.data.loop_count;varcnv=document.getElementById(e.data.meta);cnv.width=img.width;cnv.height=img.height;varctx=cnv.getContext('2d');(function(){functiond(){vara=img.n;++a>=frames.length&&(0==loop_count||img.q<loop_count ?(a=0,img.q++) :a=-1);0<=a&&(img.n=a,ctx.putImageData(frames[a].img,0,0),setTimeout(d,frames[a].duration))};ctx.putImageData(img,0,0);frames.length>1&&(img.n=0,img.q=0,setTimeout(d,frames[0].duration));}.bind(ctx,img,frames,loop_count))();console.log('Decode done');break;default:console.log('Unknown event:'+e.data);};};// arrayBuffer: BPG image// container: id of canvas (DOM) for renderingfunctiondecodeBpg(arrayBuffer,container){bpgw.postMessage({type:'image',img:arrayBuffer,meta:container});};