From ffb226fe73ead78c1f1e64bc743c702943d15b2a Mon Sep 17 00:00:00 2001 From: imeepos Date: Mon, 18 Aug 2025 14:20:26 +0800 Subject: [PATCH] Add TVAI parameter validation and fix filter name - Add comprehensive TVAI parameter validation in OutputSettings: * Validate scale, width, height ranges * Clamp enhancement parameters (-100 to 100) * Validate blend factor (0.0 to 1.0) * Validate device, VRAM, and instances settings * Set default TVAI model and parameters - Fix filter name in parameter analysis example: * tvai_stab -> tvai_stb (correct filter name) Files modified: - cargos/tvai-v2/src/template.rs (TVAI validation and defaults) - cargos/tvai/examples/parameter_usage_analysis.rs (filter name fix) --- cargos/tvai-v2/src/template.rs | 93 +++++++++++++++++++ .../tvai/examples/parameter_usage_analysis.rs | 2 +- 2 files changed, 94 insertions(+), 1 deletion(-) diff --git a/cargos/tvai-v2/src/template.rs b/cargos/tvai-v2/src/template.rs index 0c3db4a..6f5a585 100644 --- a/cargos/tvai-v2/src/template.rs +++ b/cargos/tvai-v2/src/template.rs @@ -862,6 +862,78 @@ impl OutputSettings { self.hide_banner = Some(true); } + // Validate TVAI parameters + if let Some(tvai_scale) = self.tvai_scale { + if tvai_scale < 0 || tvai_scale > 10 { + self.tvai_scale = Some(tvai_scale.clamp(0, 10)); + } + } + + if let Some(tvai_width) = self.tvai_width { + if tvai_width <= 0 || tvai_width > 16384 { + return Err(TvaiError::ValidationError(format!("Invalid TVAI width: {}", tvai_width))); + } + } + + if let Some(tvai_height) = self.tvai_height { + if tvai_height <= 0 || tvai_height > 16384 { + return Err(TvaiError::ValidationError(format!("Invalid TVAI height: {}", tvai_height))); + } + } + + // Validate TVAI enhancement parameters (-100 to 100 range) + if let Some(preblur) = self.tvai_preblur { + self.tvai_preblur = Some(preblur.clamp(-100, 100)); + } + if let Some(noise) = self.tvai_noise { + self.tvai_noise = Some(noise.clamp(-100, 100)); + } + if let Some(details) = self.tvai_details { + self.tvai_details = Some(details.clamp(-100, 100)); + } + if let Some(halo) = self.tvai_halo { + self.tvai_halo = Some(halo.clamp(-100, 100)); + } + if let Some(blur) = self.tvai_blur { + self.tvai_blur = Some(blur.clamp(-100, 100)); + } + if let Some(compression) = self.tvai_compression { + self.tvai_compression = Some(compression.clamp(-100, 100)); + } + + // Validate TVAI blend factor (0.0 to 1.0) + if let Some(blend) = self.tvai_blend { + if blend < 0.0 || blend > 1.0 { + self.tvai_blend = Some(blend.clamp(0.0, 1.0)); + } + } + + // Validate TVAI device (-2 to reasonable GPU count) + if let Some(device) = self.tvai_device { + if device < -2 || device > 15 { + self.tvai_device = Some(device.clamp(-2, 15)); + } + } + + // Validate TVAI VRAM setting (0 or 1) + if let Some(vram) = self.tvai_vram { + if vram < 0 || vram > 1 { + self.tvai_vram = Some(vram.clamp(0, 1)); + } + } + + // Validate TVAI instances (1 to reasonable count) + if let Some(instances) = self.tvai_instances { + if instances < 1 || instances > 8 { + self.tvai_instances = Some(instances.clamp(1, 8)); + } + } + + // Set default TVAI values if None + if self.tvai_model.is_none() { + self.tvai_model = Some("prob-4".to_string()); + } + Ok(()) } @@ -958,6 +1030,27 @@ impl Default for OutputSettings { copy_metadata: Some(true), no_audio: Some(false), hide_banner: Some(true), + + // Filter and metadata defaults + filter_complex: None, + metadata: None, + + // TVAI enhancement defaults + tvai_model: Some("prob-4".to_string()), + tvai_scale: Some(0), // Auto scale + tvai_width: None, + tvai_height: None, + tvai_preblur: Some(0), + tvai_noise: Some(0), + tvai_details: Some(0), + tvai_halo: Some(0), + tvai_blur: Some(0), + tvai_compression: Some(0), + tvai_estimate: Some(8), + tvai_blend: Some(0.2), + tvai_device: Some(-2), // Auto device + tvai_vram: Some(1), // High VRAM usage + tvai_instances: Some(1), } } } diff --git a/cargos/tvai/examples/parameter_usage_analysis.rs b/cargos/tvai/examples/parameter_usage_analysis.rs index 2961922..e5cc6d8 100644 --- a/cargos/tvai/examples/parameter_usage_analysis.rs +++ b/cargos/tvai/examples/parameter_usage_analysis.rs @@ -139,7 +139,7 @@ fn main() -> std::result::Result<(), Box> { if cmd.contains("tvai_up") { println!("✅ Enhancement filter applied (uses: model, scale, compress, detail, sharpen, denoise, dehalo, deblur)"); } - if cmd.contains("tvai_stab") { + if cmd.contains("tvai_stb") { println!("✅ Stabilization filter applied (uses: method, smooth)"); } if cmd.contains("tvai_fi") {