feat(stage3): Multi-pass target measurement averaging with Argyll average (fixes #87) #99
@@ -420,6 +420,36 @@ pub async fn run_chartread(
|
|||||||
state.spawn(app, id, binary, args, cwd).await
|
state.spawn(app, id, binary, args, cwd).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct AverageConfig {
|
||||||
|
pub inputs: Vec<String>,
|
||||||
|
pub output: String,
|
||||||
|
pub cwd: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build_average_args(config: &AverageConfig) -> Vec<String> {
|
||||||
|
let mut args = vec!["-v".to_string()];
|
||||||
|
for input in &config.inputs {
|
||||||
|
args.push(input.clone());
|
||||||
|
}
|
||||||
|
args.push(config.output.clone());
|
||||||
|
args
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn run_average(
|
||||||
|
app: AppHandle,
|
||||||
|
state: State<'_, ProcessManager>,
|
||||||
|
config: AverageConfig,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
let binary = resolve_binary(app.clone(), "average".to_string()).await?;
|
||||||
|
let args = build_average_args(&config);
|
||||||
|
let id = format!("average_{}", config.output);
|
||||||
|
let cwd = Some(resolve_safe_cwd(&app, &config.cwd)?);
|
||||||
|
|
||||||
|
state.spawn(app, id, binary, args, cwd).await
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct ColprofConfig {
|
pub struct ColprofConfig {
|
||||||
pub algorithm: String,
|
pub algorithm: String,
|
||||||
@@ -726,6 +756,17 @@ mod tests {
|
|||||||
assert_eq!(args, vec!["-v", "-u", "-c", "1", "my_profile"]);
|
assert_eq!(args, vec!["-v", "-u", "-c", "1", "my_profile"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_build_average_args() {
|
||||||
|
let config = AverageConfig {
|
||||||
|
inputs: vec!["pass1.ti3".to_string(), "pass2.ti3".to_string()],
|
||||||
|
output: "avg.ti3".to_string(),
|
||||||
|
cwd: "/home/user".to_string(),
|
||||||
|
};
|
||||||
|
let args = build_average_args(&config);
|
||||||
|
assert_eq!(args, vec!["-v", "pass1.ti3", "pass2.ti3", "avg.ti3"]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_build_colprof_args() {
|
fn test_build_colprof_args() {
|
||||||
let config = ColprofConfig {
|
let config = ColprofConfig {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ pub fn run() {
|
|||||||
commands::read_file_base64,
|
commands::read_file_base64,
|
||||||
commands::read_tiff_preview_png,
|
commands::read_tiff_preview_png,
|
||||||
commands::run_chartread,
|
commands::run_chartread,
|
||||||
|
commands::run_average,
|
||||||
commands::run_colprof,
|
commands::run_colprof,
|
||||||
commands::run_profcheck,
|
commands::run_profcheck,
|
||||||
commands::get_printers,
|
commands::get_printers,
|
||||||
|
|||||||
+15
-1
@@ -291,6 +291,20 @@
|
|||||||
<!-- Swatch Grid -->
|
<!-- Swatch Grid -->
|
||||||
<div class="swatch-grid" id="swatchGrid"></div>
|
<div class="swatch-grid" id="swatchGrid"></div>
|
||||||
|
|
||||||
|
<!-- Multi-Pass Session & Averaging Controls -->
|
||||||
|
<div class="averaging-panel hidden" id="chartreadAveragingPanel" style="margin-top: 16px; padding: 14px; border: 1px solid var(--border-color, #333); border-radius: 8px; background: rgba(255, 255, 255, 0.03);">
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
|
||||||
|
<h3 style="margin: 0; font-size: 1rem;">Multi-Pass Target Averaging</h3>
|
||||||
|
<span id="passCounterBadge" class="status-badge badge-idle">Pass 1 Complete</span>
|
||||||
|
</div>
|
||||||
|
<p class="sub-label" style="margin-bottom: 12px;">You can measure additional printed copies to reduce measurement and printing noise before computing the profile.</p>
|
||||||
|
<div id="passesList" class="passes-list" style="display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px;"></div>
|
||||||
|
<div style="display: flex; gap: 8px;">
|
||||||
|
<button type="button" class="secondary" id="btnMeasureAnotherSheet">➕ Measure Another Sheet</button>
|
||||||
|
<button type="button" class="primary" id="btnFinishAndAverage">✓ Average Passes & Proceed →</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Process Log -->
|
<!-- Process Log -->
|
||||||
<details class="log-container hidden" id="chartreadLogContainer">
|
<details class="log-container hidden" id="chartreadLogContainer">
|
||||||
<summary>Process Output</summary>
|
<summary>Process Output</summary>
|
||||||
@@ -482,7 +496,7 @@
|
|||||||
|
|
||||||
<h5>Three.js</h5>
|
<h5>Three.js</h5>
|
||||||
<p>Copyright (c) 2010-2023 three.js authors</p>
|
<p>Copyright (c) 2010-2023 three.js authors</p>
|
||||||
<p class="license-legal-block">Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:<br/><br/>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.<br/><br/>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
|
<p class="license-legal-block">Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:<br/><br/>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.<br/><br/>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
|
||||||
|
|
||||||
<h5>Delaunator</h5>
|
<h5>Delaunator</h5>
|
||||||
<p>Copyright (c) 2017, Mapbox</p>
|
<p>Copyright (c) 2017, Mapbox</p>
|
||||||
|
|||||||
+95
-4
@@ -211,7 +211,7 @@ export function initChartread() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const unlistenExit = await listen("process:exit", (event) => {
|
const unlistenExit = await listen("process:exit", async (event) => {
|
||||||
if (event.payload.id !== currentProcessId) return;
|
if (event.payload.id !== currentProcessId) return;
|
||||||
unlistenStdout();
|
unlistenStdout();
|
||||||
unlistenStderr();
|
unlistenStderr();
|
||||||
@@ -220,11 +220,23 @@ export function initChartread() {
|
|||||||
|
|
||||||
if (event.payload.code === 0) {
|
if (event.payload.code === 0) {
|
||||||
setState(STATE.FINISHED);
|
setState(STATE.FINISHED);
|
||||||
setPrompt("✅ Measurement complete! .ti3 file has been saved.");
|
setPrompt("✅ Sheet measurement completed!");
|
||||||
logPre.textContent += "\n[SUCCESS] chartread completed. .ti3 file written.\n";
|
logPre.textContent += "\n[SUCCESS] chartread sheet measurement completed.\n";
|
||||||
|
|
||||||
|
// Track pass in session
|
||||||
|
currentPassIndex++;
|
||||||
|
recordedPasses.push({
|
||||||
|
index: currentPassIndex,
|
||||||
|
filename: `${basename}.ti3`,
|
||||||
|
time: new Date().toLocaleTimeString(),
|
||||||
|
});
|
||||||
|
|
||||||
|
renderPassesList();
|
||||||
|
if (averagingPanel) averagingPanel.classList.remove("hidden");
|
||||||
|
if (passCounterBadge) passCounterBadge.textContent = `${recordedPasses.length} Pass(es) Recorded`;
|
||||||
|
|
||||||
wizardState.setTarget(basename, cwd);
|
wizardState.setTarget(basename, cwd);
|
||||||
setStage3Result(basename, cwd);
|
setStage3Result(basename, cwd);
|
||||||
advanceToStage4();
|
|
||||||
} else {
|
} else {
|
||||||
setState(STATE.FINISHED);
|
setState(STATE.FINISHED);
|
||||||
setPrompt(`❌ chartread exited with code ${event.payload.code}.`);
|
setPrompt(`❌ chartread exited with code ${event.payload.code}.`);
|
||||||
@@ -241,6 +253,85 @@ export function initChartread() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Multi-pass measurement controls
|
||||||
|
const averagingPanel = document.getElementById("chartreadAveragingPanel");
|
||||||
|
const passesList = document.getElementById("passesList");
|
||||||
|
const passCounterBadge = document.getElementById("passCounterBadge");
|
||||||
|
const btnMeasureAnotherSheet = document.getElementById("btnMeasureAnotherSheet");
|
||||||
|
const btnFinishAndAverage = document.getElementById("btnFinishAndAverage");
|
||||||
|
let currentPassIndex = 0;
|
||||||
|
const recordedPasses = [];
|
||||||
|
|
||||||
|
function renderPassesList() {
|
||||||
|
if (!passesList) return;
|
||||||
|
passesList.innerHTML = "";
|
||||||
|
recordedPasses.forEach((pass, i) => {
|
||||||
|
const item = document.createElement("div");
|
||||||
|
item.style.cssText = "display:flex; justify-content:space-between; align-items:center; background:rgba(255,255,255,0.05); padding:6px 10px; border-radius:4px; font-size:0.85rem;";
|
||||||
|
item.innerHTML = `<span><strong>Sheet Pass #${i + 1}</strong> (${pass.filename})</span><span style="opacity:0.7;">✓ ${pass.time}</span>`;
|
||||||
|
passesList.appendChild(item);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (btnMeasureAnotherSheet) {
|
||||||
|
btnMeasureAnotherSheet.addEventListener("click", () => {
|
||||||
|
setState(STATE.IDLE);
|
||||||
|
setPrompt(`Ready to measure sheet pass #${recordedPasses.length + 1}. Press 'Start Measurement'.`);
|
||||||
|
if (btnStartRead) btnStartRead.click();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (btnFinishAndAverage) {
|
||||||
|
btnFinishAndAverage.addEventListener("click", async () => {
|
||||||
|
const basename = stage2Basename || wizardState.basename;
|
||||||
|
const cwd = stage2Cwd || wizardState.cwd;
|
||||||
|
|
||||||
|
if (recordedPasses.length <= 1) {
|
||||||
|
setPrompt("Single pass accepted. Proceeding to Stage 4...");
|
||||||
|
wizardState.setTarget(basename, cwd);
|
||||||
|
setStage3Result(basename, cwd);
|
||||||
|
advanceToStage4();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setPrompt("Averaging measurement passes with Argyll average utility...");
|
||||||
|
btnFinishAndAverage.disabled = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const averageConfig = {
|
||||||
|
inputs: recordedPasses.map(p => p.filename),
|
||||||
|
output: `${basename}.ti3`,
|
||||||
|
cwd: cwd,
|
||||||
|
};
|
||||||
|
|
||||||
|
const unlistenAvgExit = await listen("process:exit", (event) => {
|
||||||
|
if (event.payload.id !== `average_${basename}.ti3`) return;
|
||||||
|
unlistenAvgExit();
|
||||||
|
btnFinishAndAverage.disabled = false;
|
||||||
|
|
||||||
|
if (event.payload.code === 0) {
|
||||||
|
setPrompt(`✅ Successfully averaged ${recordedPasses.length} measurement passes into ${basename}.ti3!`);
|
||||||
|
wizardState.setTarget(basename, cwd);
|
||||||
|
setStage3Result(basename, cwd);
|
||||||
|
advanceToStage4();
|
||||||
|
} else {
|
||||||
|
setPrompt(`⚠️ Argyll average exited with code ${event.payload.code}. Proceeding with primary pass.`);
|
||||||
|
wizardState.setTarget(basename, cwd);
|
||||||
|
setStage3Result(basename, cwd);
|
||||||
|
advanceToStage4();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await invoke("run_average", { config: averageConfig });
|
||||||
|
} catch (e) {
|
||||||
|
console.error("run_average error:", e);
|
||||||
|
btnFinishAndAverage.disabled = false;
|
||||||
|
setStage3Result(basename, cwd);
|
||||||
|
advanceToStage4();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Calibrate / confirm button — sends space + newline
|
// Calibrate / confirm button — sends space + newline
|
||||||
if (btnCalibrate) {
|
if (btnCalibrate) {
|
||||||
btnCalibrate.addEventListener("click", async () => {
|
btnCalibrate.addEventListener("click", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user