atmos/os_lib/web_engine/
video_fit.rs1pub fn fit_contain(src_w: u32, src_h: u32, box_w: u32, box_h: u32) -> (u32, u32, u32, u32) {
6 if src_w == 0 || src_h == 0 || box_w == 0 || box_h == 0 {
7 return (0, 0, box_w, box_h);
8 }
9 let (w, h) = if (box_w as u64) * (src_h as u64) <= (box_h as u64) * (src_w as u64) {
11 let h = ((box_w as u64) * (src_h as u64) / (src_w as u64)) as u32;
13 (box_w, h.max(1))
14 } else {
15 let w = ((box_h as u64) * (src_w as u64) / (src_h as u64)) as u32;
16 (w.max(1), box_h)
17 };
18 ((box_w - w) / 2, (box_h - h) / 2, w, h)
19}