Skip to content

Commit

Permalink
apply clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarriba committed Feb 15, 2024
1 parent e442e11 commit 17288b0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions benches/color_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ fn gray_iter(image: &Image<f32, 3>) -> Image<u8, 1> {
let r = image.data[[y, x, 0]];
let g = image.data[[y, x, 1]];
let b = image.data[[y, x, 2]];
let gray_pixel = (76. * r as f32 + 150. * g as f32 + 29. * b as f32) / 255.;
let gray_pixel = (76. * r + 150. * g + 29. * b) / 255.;
gray_image.data[[y, x, 0]] = gray_pixel as u8;
}
}
gray_image
}

fn gray_vec(image: &Image<f32, 3>) -> Image<u8, 1> {
// convert to f32
let mut image_f32 = image.data.mapv(|x| x as f32);
let mut image_f32 = image.data.mapv(|x| x);

// get channels
let mut binding = image_f32.view_mut();
Expand All @@ -43,7 +42,7 @@ fn gray_vec(image: &Image<f32, 3>) -> Image<u8, 1> {
}

#[cfg(feature = "candle")]
fn gray_candle(image: Image) -> Image {
fn gray_candle(image: Image<f32, 3>) -> Image<u8, 3> {
let image_data = image.data.as_slice().unwrap();
let shape = (image.image_size().height, image.image_size().width, 3);

Expand Down Expand Up @@ -79,7 +78,7 @@ fn gray_candle(image: Image) -> Image {
}
};

Image::from_shape_vec([shape.0, shape.1, shape.2], data)
Image::new(image.image_size(), data).unwrap()
}

fn gray_image_crate(image: &Image<u8, 3>) -> Image<u8, 1> {
Expand Down
1 change: 0 additions & 1 deletion examples/binarize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use kornia_rs::io::functions as F;
use rerun;

fn main() -> Result<(), Box<dyn std::error::Error>> {
// read the image
Expand Down
1 change: 0 additions & 1 deletion examples/imgproc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use kornia_rs::io::functions as F;
use rerun;

fn main() -> Result<(), Box<dyn std::error::Error>> {
// read the image
Expand Down
1 change: 0 additions & 1 deletion examples/rerun_viz.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use kornia_rs::io::functions as F;
use rerun;

fn main() -> Result<(), Box<dyn std::error::Error>> {
// read the image
Expand Down
5 changes: 4 additions & 1 deletion src/io/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use super::jpeg::{ImageDecoder, ImageEncoder};
pub fn read_image_jpeg(file_path: &Path) -> Result<Image<u8, 3>> {
// verify the file exists and is a JPEG
if !file_path.exists() {
return Err(anyhow::anyhow!("File does not exist: {}", file_path.to_str().unwrap()).into());
return Err(anyhow::anyhow!(
"File does not exist: {}",
file_path.to_str().unwrap()
));
}

let file_path = match file_path.extension() {
Expand Down
2 changes: 1 addition & 1 deletion src/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ mod tests {
width: 4,
height: 5,
},
vec![0f32; 4 * 5 * 1],
vec![0f32; 4 * 5],
)
.unwrap();
let image_resized = super::resize(
Expand Down

0 comments on commit 17288b0

Please sign in to comment.