Skip to content

Commit

Permalink
remove: BinaryRawView
Browse files Browse the repository at this point in the history
  • Loading branch information
salam99823 committed Dec 8, 2024
1 parent 43b5bf2 commit a67842d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 103 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use image::GenericImageView;

pub use neigbors::Neighbors;
pub use pixel::Bit;
pub use view::{raw::BinaryRawView, BinaryView};
pub use view::BinaryView;

mod neigbors;
mod pixel;
Expand Down Expand Up @@ -41,7 +41,7 @@ impl BinaryImage {
}
}

impl GenericImageView for BinaryImage {
impl image::GenericImageView for BinaryImage {
type Pixel = pixel::Bit;
#[inline]
unsafe fn unsafe_get_pixel(&self, x: u32, y: u32) -> Self::Pixel {
Expand Down Expand Up @@ -84,7 +84,7 @@ impl image::GenericImage for BinaryImage {
}
}

impl<I: GenericImageView<Pixel = Bit>> From<&I> for BinaryImage {
impl<I: image::GenericImageView<Pixel = Bit>> From<&I> for BinaryImage {
fn from(view: &I) -> Self {
BinaryImage {
height: view.height(),
Expand Down
62 changes: 33 additions & 29 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,37 @@ static DATA: [u8; 16] = [
#[test]
fn test_neigbors() {
let binary_image = BinaryImage::from_raw(4, 4, &DATA);
let neigbors = Neighbors::get_neighbors(&binary_image, 1, 1);

assert_eq!(neigbors.bits(), 0b1010_0001);

let neigbors = Neighbors::get_neighbors(&binary_image, 2, 2);

assert_eq!(neigbors.bits(), 0b0101_1001);

let neigbors = Neighbors::get_neighbors(&binary_image, 0, 0);

assert_eq!(neigbors.bits(), 0b0000_1000);
assert_eq!(
Neighbors::get_neighbors(&binary_image, 1, 1).bits(),
0b1010_0001
);
assert_eq!(
Neighbors::get_neighbors(&binary_image, 2, 2).bits(),
0b0101_1001
);
assert_eq!(
Neighbors::get_neighbors(&binary_image, 0, 0).bits(),
0b0000_1000
);
}

#[test]
fn test_binary_image_creation() {
let binary_image = BinaryImage::from_raw(4, 4, &DATA);
let image = BinaryImage::from_raw(4, 4, &DATA);

assert_eq!(binary_image.width(), 4);
assert_eq!(binary_image.height(), 4);
assert!(*binary_image.get_pixel(0, 0));
assert!(*binary_image.get_pixel(2, 1));
assert!(*binary_image.get_pixel(1, 2));
assert!(*binary_image.get_pixel(3, 3));
assert_eq!(image.width(), 4);
assert_eq!(image.height(), 4);
assert!(*image.get_pixel(0, 0));
assert!(*image.get_pixel(2, 1));
assert!(*image.get_pixel(1, 2));
assert!(*image.get_pixel(3, 3));
}

#[test]
fn test_binary_view() {
let binary_image = BinaryImage::from_raw(4, 4, &DATA);
let view = BinaryView(&binary_image);
fn test_view() {
let image = BinaryImage::from_raw(4, 4, &DATA);
let view = BinaryView(&image);

assert_eq!(view.width(), 4);
assert_eq!(view.height(), 4);
Expand All @@ -50,13 +52,15 @@ fn test_binary_view() {
}

#[test]
fn test_binary_raw_view() {
let raw_view = BinaryRawView::new(4, 4, &DATA);

assert_eq!(raw_view.width(), 4);
assert_eq!(raw_view.height(), 4);
assert!(*raw_view.get_pixel(0, 0));
assert!(*raw_view.get_pixel(2, 1));
assert!(*raw_view.get_pixel(1, 2));
assert!(*raw_view.get_pixel(3, 3));
fn test_view_raw() {
let image: image::ImageBuffer<image::Luma<u8>, &[u8]> =
image::ImageBuffer::from_raw(4, 4, &DATA[..]).unwrap();
let view = BinaryView(&image);

assert_eq!(view.width(), 4);
assert_eq!(view.height(), 4);
assert!(*view.get_pixel(0, 0));
assert!(*view.get_pixel(2, 1));
assert!(*view.get_pixel(1, 2));
assert!(*view.get_pixel(3, 3));
}
4 changes: 1 addition & 3 deletions src/view/mod.rs → src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use num_traits::Zero;

use crate::pixel::Bit;

pub mod raw;

#[derive(Debug, Clone, DerefMut, Deref, From, Constructor)]
pub struct BinaryView<'a, I>(pub &'a I)
where
Expand All @@ -32,7 +30,7 @@ where
alpha
},
);
Bit::from(if alpha_exist { alphas } else { channels })
Bit(if alpha_exist { alphas } else { channels })
}
#[inline]
fn get_pixel(&self, x: u32, y: u32) -> Self::Pixel {
Expand Down
68 changes: 0 additions & 68 deletions src/view/raw.rs

This file was deleted.

0 comments on commit a67842d

Please sign in to comment.