diff --git a/web/site-sheet.js b/web/site-sheet.js index f5f3eeb..3cd956f 100644 --- a/web/site-sheet.js +++ b/web/site-sheet.js @@ -77,7 +77,8 @@ function mapaLinha(m,y,alfa,inicio,de){ m.tinta+=tinta; } // Uma imagem que o navegador abre, lida em faixas no tamanho real (1:1). -async function mapaDaImagem(img,larguraCm){ +// Melhor um ImageBitmap: decodificado uma vez, não a cada faixa. +async function mapaDaImagem(img,larguraCm,progresso){ const w=img.naturalWidth||img.width, h=img.naturalHeight||img.height; const m=novoMapa(w,h,larguraCm); const faixa=Math.max(1,Math.min(h,Math.floor(4e6/w))); @@ -90,6 +91,7 @@ async function mapaDaImagem(img,larguraCm){ ctx.drawImage(img,0,topo,w,n,0,0,w,n); const d=ctx.getImageData(0,0,w,n).data; for(let r=0;rsetTimeout(r)); // a página não congela } return m; diff --git a/web/site-upload.js b/web/site-upload.js index 69a03ff..472c9f3 100644 --- a/web/site-upload.js +++ b/web/site-upload.js @@ -92,9 +92,17 @@ function sel(fs){ }else if(md && RENDERIZA.test(x.f.name)){ carregarImagem(x.f).then(async img=>{ if(img){ - x.previewSrc=img.src; x.miniSrc=miniatura(img); x.fotoSrc=miniatura(img,480,720); + // Decoded once and kept: drawn from the , a large sheet is + // decoded again for each strip the check reads. + const fonte=await createImageBitmap(img).catch(()=>img); + x.previewSrc=img.src; x.miniSrc=miniatura(fonte); x.fotoSrc=miniatura(fonte,480,720); x.pct=80; pintaFolha(); - try{ x.an={...analisarMapa(await mapaDaImagem(img, md.larg)), fonteDpi:'arquivo'}; }catch(e){} + let mostrado=80; + try{ x.an={...analisarMapa(await mapaDaImagem(fonte, md.larg, p=>{ + const pct=80+Math.floor(p*19); + if(pct>mostrado){ mostrado=pct; x.pct=pct; pintaProgressoFolha(x); } + })), fonteDpi:'arquivo'}; }catch(e){} + if(fonte.close) fonte.close(); } x.pct=null; pintaFolha(); marcaResiduos(x); });