Skip to content

Commit e9e1ca8

Browse files
committed
Don't offset if cropping to same length
This could perhaps be generalized via a clamp, but whatever
1 parent ba9f638 commit e9e1ca8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cradle-cli/src/main_ed7.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,12 @@ fn crop(img: &RgbaImage) -> (image::SubImage<&RgbaImage>, (i32, i32)) {
233233
let u = (0..h). find(|&y| (0..w).any(|x| img.get_pixel(x, y).0[3] != 0))?;
234234
let d = (0..h).rfind(|&y| (0..w).any(|x| img.get_pixel(x, y).0[3] != 0))?;
235235

236-
let cx = w as i32 / 2 - (r+l) as i32 / 2;
237-
let cy = h as i32 / 2 - (d+u) as i32 / 2;
238-
239236
let ow = (r - l + 2).next_power_of_two().max(4); // I don't know why the +2
240237
let oh = (d - u + 2).next_power_of_two().max(4);
238+
239+
let cx = if ow == w { 0 } else { w as i32 / 2 - (r+l) as i32 / 2 };
240+
let cy = if oh == h { 0 } else { h as i32 / 2 - (d+u) as i32 / 2 };
241+
241242
let ox = (w as i32 / 2 - cx) as u32 - ow / 2;
242243
let oy = (h as i32 / 2 - cy) as u32 - oh / 2;
243244

0 commit comments

Comments
 (0)