Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Clamp extract_crop box coordinates to image bounds on both sides

Amrithesh Kakkoth Ente37bd1696a1df
diff --git a/mobile/apps/photos/rust/src/ml/pet/preprocess.rs b/mobile/apps/photos/rust/src/ml/pet/preprocess.rs
index 97d3ad76d1..d42a0eb3d3 100644
--- a/mobile/apps/photos/rust/src/ml/pet/preprocess.rs
+++ b/mobile/apps/photos/rust/src/ml/pet/preprocess.rs
@@ -89,10 +89,10 @@ pub fn extract_crop(
let img_w = decoded.dimensions.width;
let img_h = decoded.dimensions.height;
- let x1 = (box_xyxy[0] * img_w as f32).round().max(0.0) as u32;
- let y1 = (box_xyxy[1] * img_h as f32).round().max(0.0) as u32;
- let x2 = (box_xyxy[2] * img_w as f32).round().min(img_w as f32) as u32;
- let y2 = (box_xyxy[3] * img_h as f32).round().min(img_h as f32) as u32;
+ let x1 = (box_xyxy[0] * img_w as f32).round().clamp(0.0, img_w as f32) as u32;
+ let y1 = (box_xyxy[1] * img_h as f32).round().clamp(0.0, img_h as f32) as u32;
+ let x2 = (box_xyxy[2] * img_w as f32).round().clamp(0.0, img_w as f32) as u32;
+ let y2 = (box_xyxy[3] * img_h as f32).round().clamp(0.0, img_h as f32) as u32;
let crop_w = x2.saturating_sub(x1);
let crop_h = y2.saturating_sub(y1);