Skip to content

Commit

Permalink
small optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarriba committed Feb 1, 2024
1 parent da0f11c commit d7d22c2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ fn bilinear_interpolation(image: &Array3<u8>, u: f32, v: f32, c: usize) -> f32 {
let (height, width, _) = image.dim();
let iu = u.trunc() as usize;
let iv = v.trunc() as usize;

let frac_u = u.fract();
let frac_v = v.fract();
let val00 = image[[iv, iu, c]] as f32;
Expand All @@ -41,9 +42,12 @@ fn bilinear_interpolation(image: &Array3<u8>, u: f32, v: f32, c: usize) -> f32 {
val00
};

val00 * (1. - frac_u) * (1. - frac_v)
+ val01 * frac_u * (1. - frac_v)
+ val10 * (1. - frac_u) * frac_v
let frac_uu = 1. - frac_u;
let frac_vv = 1. - frac_v;

val00 * frac_uu * frac_vv
+ val01 * frac_u * frac_vv
+ val10 * frac_uu * frac_v
+ val11 * frac_u * frac_v
}

Expand Down Expand Up @@ -126,6 +130,7 @@ pub fn resize(image: &Image, new_size: ImageSize, optional_args: ResizeOptions)
InterpolationMode::NearestNeighbor => {
nearest_neighbor_interpolation(&image.data, u, v, k)
}
_ => panic!("Interpolation mode not implemented"),

Check warning on line 133 in src/resize.rs

View workflow job for this annotation

GitHub Actions / Test Suite - x86_64-unknown-linux-gnu

unreachable pattern

Check warning on line 133 in src/resize.rs

View workflow job for this annotation

GitHub Actions / Test Suite - aarch64-unknown-linux-gnu

unreachable pattern

Check warning on line 133 in src/resize.rs

View workflow job for this annotation

GitHub Actions / Check

unreachable pattern

Check warning on line 133 in src/resize.rs

View workflow job for this annotation

GitHub Actions / Clippy Output

unreachable pattern

warning: unreachable pattern --> src/resize.rs:133:17 | 133 | _ => panic!("Interpolation mode not implemented"), | ^ | = note: `#[warn(unreachable_patterns)]` on by default
});

// write the pixel values to the output image
Expand Down

0 comments on commit d7d22c2

Please sign in to comment.