diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 0097543..e1c5264 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -33,147 +33,75 @@ fn scan_dir(path: String) -> Result, String> { } use image::GenericImageView; - use image::Pixel; - - #[derive(serde::Serialize)] - struct ZcaResult { - x: f64, - y: f64, - zone: String, - } - - #[tauri::command] - fn get_zca_suggestion(path: String) -> Result { - let img = image::open(&path).map_err(|e| e.to_string())?; - let (width, height) = img.dimensions(); - - - let bottom_start_y = (height as f64 * 0.8) as u32; - let zone_height = height - bottom_start_y; - let zone_width = width / 3; - - - let zones = [ - ("Left", 0, bottom_start_y), - ("Center", zone_width, bottom_start_y), - ("Right", zone_width * 2, bottom_start_y), - ]; - - let mut min_std_dev = f64::MAX; - let mut best_zone = "Center"; - let mut best_pos = (0.5, 0.9); // Default center - - for (name, start_x, start_y) in zones.iter() { - let mut luma_values = Vec::with_capacity((zone_width * zone_height) as usize); - - - for y in *start_y..height { - for x in *start_x..(*start_x + zone_width) { - if x >= width { continue; } - let pixel = img.get_pixel(x, y); - let rgb = pixel.to_rgb(); - let luma = 0.299 * rgb[0] as f64 + 0.587 * rgb[1] as f64 + 0.114 * rgb[2] as f64; - luma_values.push(luma); - } - } - - let count = luma_values.len() as f64; - if count == 0.0 { continue; } - - let mean = luma_values.iter().sum::() / count; - let variance = luma_values.iter().map(|v| (v - mean).powi(2)).sum::() / count; - let std_dev = variance.sqrt(); - - if std_dev < min_std_dev { - min_std_dev = std_dev; - best_zone = name; - let center_x_px = *start_x as f64 + (zone_width as f64 / 2.0); - - let center_y_px = *start_y as f64 + (zone_height as f64 / 2.0); - + // Position closer to bottom (75% of the zone height instead of 50%) + // Zone starts at 80%. Height is 20%. 0.8 + 0.2 * 0.75 = 0.95 + let center_y_px = *start_y as f64 + (zone_height as f64 * 0.75); best_pos = (center_x_px / width as f64, center_y_px / height as f64); - } - } - - Ok(ZcaResult { - x: best_pos.0, - y: best_pos.1, - zone: best_zone.to_string(), - }) - } - #[cfg_attr(mobile, tauri::mobile_entry_point)] - pub fn run() { - tauri::Builder::default() - .plugin(tauri_plugin_dialog::init()) - .invoke_handler(tauri::generate_handler![scan_dir, get_zca_suggestion]) - .run(tauri::generate_context!()) - .expect("error while running tauri application"); - } diff --git a/src/components/HeroView.vue b/src/components/HeroView.vue index dde55fc..d6e9223 100644 --- a/src/components/HeroView.vue +++ b/src/components/HeroView.vue @@ -6,11 +6,12 @@ const store = useGalleryStore();