perf: a ready sheet is decoded once for its check, with the progress shown
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 3m23s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m8s

Drawn from the <img>, a large sheet was decoded again for each strip the
residue check reads. Decoded once into an ImageBitmap and reused for the
thumbnails, the check of a 57 x 50 cm sheet at 300 DPI drops from 4,7 s to
1,4 s, and the bar moves while it runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-22 18:06:03 -03:00
parent 88181b755d
commit 56e5462647
2 changed files with 13 additions and 3 deletions

View File

@@ -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;r<n;r++) mapaLinha(m,topo+r,d,r*w*4+3,4);
if(progresso) progresso((topo+n)/h);
await new Promise(r=>setTimeout(r)); // a página não congela
}
return m;

View File

@@ -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 <img>, 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);
});