Skip to content

Commit 71ec2a2

Browse files
Update color choices
1 parent 390df50 commit 71ec2a2

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

public/app.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ let wasm = null;
1414
let loadedImage = null;
1515
let renderToken = 0;
1616

17+
function afficherOverlay(actif) {
18+
const overlay = document.getElementById("processing-overlay");
19+
if (overlay) overlay.hidden = !actif;
20+
}
21+
1722
async function chargerWasm() {
1823
const status = document.getElementById("wasm-status");
1924
const btnApply = document.getElementById("btn-apply");
@@ -433,7 +438,12 @@ function couleurTuile(pixels, larg, haut, sommets) {
433438
}
434439
}
435440

436-
if (compte === 0) return null;
441+
if (compte === 0) {
442+
const cx = Math.min(larg - 1, Math.max(0, Math.round((box.minX + box.maxX) / 2)));
443+
const cy = Math.min(haut - 1, Math.max(0, Math.round((box.minY + box.maxY) / 2)));
444+
const i = (cy * larg + cx) * 4;
445+
return [pixels[i], pixels[i + 1], pixels[i + 2]];
446+
}
437447
return [
438448
couleur_moyenne(rTot, compte),
439449
couleur_moyenne(gTot, compte),
@@ -489,12 +499,11 @@ function afficherSource(imgEl) {
489499
async function rendreSortie(imgEl) {
490500
const srcCanvas = document.getElementById("source-canvas");
491501
const outCanvas = document.getElementById("output-canvas");
492-
const overlay = document.getElementById("processing-overlay");
493502
const btnDl = document.getElementById("btn-download");
494503
const status = document.getElementById("wasm-status");
495504
const token = ++renderToken;
496505

497-
overlay.classList.add("actif");
506+
afficherOverlay(true);
498507
btnDl.disabled = true;
499508

500509
try {
@@ -525,7 +534,7 @@ async function rendreSortie(imgEl) {
525534
console.error("[pixel2polygon] Echec du rendu :", err);
526535
status.textContent = `Le rendu a echoue pour le mode ${state.method}.`;
527536
} finally {
528-
if (token === renderToken) overlay.classList.remove("actif");
537+
if (token === renderToken) afficherOverlay(false);
529538
}
530539
}
531540

@@ -553,7 +562,7 @@ function afficherZoneUpload() {
553562
document.getElementById("canvas-area").hidden = true;
554563
loadedImage = null;
555564
document.getElementById("btn-download").disabled = true;
556-
document.getElementById("processing-overlay").classList.remove("actif");
565+
afficherOverlay(false);
557566
}
558567

559568
function debounce(fn, delai) {
@@ -677,11 +686,26 @@ function basculerOnglet(nom) {
677686
}
678687

679688
async function init() {
680-
document.getElementById("btn-apply").disabled = true;
681-
lierControles();
682-
document.getElementById("tab-studio").addEventListener("click", () => basculerOnglet("studio"));
683-
document.getElementById("tab-source").addEventListener("click", () => basculerOnglet("source"));
684-
await chargerWasm();
689+
const btnApply = document.getElementById("btn-apply");
690+
if (btnApply) btnApply.disabled = true;
691+
692+
const tabStudio = document.getElementById("tab-studio");
693+
const tabSource = document.getElementById("tab-source");
694+
if (tabStudio) tabStudio.addEventListener("click", () => basculerOnglet("studio"));
695+
if (tabSource) tabSource.addEventListener("click", () => basculerOnglet("source"));
696+
basculerOnglet("studio");
697+
698+
try {
699+
lierControles();
700+
} catch (err) {
701+
console.error("[pixel2polygon] Echec de liaison des controles :", err);
702+
}
703+
704+
try {
705+
await chargerWasm();
706+
} catch (err) {
707+
console.error("[pixel2polygon] Echec d'initialisation WASM :", err);
708+
}
685709
}
686710

687711
init();

0 commit comments

Comments
 (0)