1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
use fast_image_resize::images::{TypedCroppedImageMut, TypedImage};
use fast_image_resize::pixels::U8;
use fast_image_resize::{ImageView, ImageViewMut};
use testing::non_zero_u32;
mod testing;
mod split_by_width {
use super::*;
use fast_image_resize::images::{TypedCroppedImage, TypedImageRef};
fn split<T: ImageView>(img: &T) {
for num_parts in 1..16 {
let res = img
.split_by_width(0, non_zero_u32(512), non_zero_u32(num_parts))
.unwrap();
assert_eq!(res.len() as u32, num_parts);
let sum_width = res.iter().map(|v| v.width()).sum::<u32>();
assert_eq!(sum_width, 512);
}
}
fn split_mut<T: ImageViewMut>(img: &mut T) {
for num_parts in 1..16 {
let res = img
.split_by_width_mut(0, non_zero_u32(512), non_zero_u32(num_parts))
.unwrap();
assert_eq!(res.len() as u32, num_parts);
let sum_width = res.iter().map(|v| v.width()).sum::<u32>();
assert_eq!(sum_width, 512);
}
}
#[test]
fn typed_image_ref() {
let width = 512;
let height = 384;
let buffer = vec![U8::new(0); (width * height) as usize];
let img = TypedImageRef::<U8>::new(width, height, &buffer).unwrap();
split(&img);
}
#[test]
fn typed_image() {
let mut img = TypedImage::<U8>::new(512, 384);
split(&img);
split_mut(&mut img);
}
#[test]
fn typed_cropped_image() {
let img = TypedImage::<U8>::new(512 + 20, 384 + 20);
let cropped_img = TypedCroppedImage::from_ref(&img, 10, 10, 512, 384).unwrap();
split(&cropped_img);
}
#[test]
fn typed_cropped_image_mut() {
let mut img = TypedImage::<U8>::new(512 + 20, 384 + 20);
let mut cropped_img = TypedCroppedImageMut::from_ref(&mut img, 10, 10, 512, 384).unwrap();
split(&cropped_img);
split_mut(&mut cropped_img);
}
}
mod split_by_height {
use super::*;
use fast_image_resize::images::{TypedCroppedImage, TypedImageRef};
fn split<T: ImageView>(img: &T) {
for num_parts in 1..16 {
let res = img
.split_by_height(0, non_zero_u32(512), non_zero_u32(num_parts))
.unwrap();
assert_eq!(res.len() as u32, num_parts);
let sum_height = res.iter().map(|v| v.height()).sum::<u32>();
assert_eq!(sum_height, 512);
}
}
fn split_mut<T: ImageViewMut>(img: &mut T) {
for num_parts in 1..16 {
let res = img
.split_by_height_mut(0, non_zero_u32(512), non_zero_u32(num_parts))
.unwrap();
assert_eq!(res.len() as u32, num_parts);
let sum_height = res.iter().map(|v| v.height()).sum::<u32>();
assert_eq!(sum_height, 512);
}
}
#[test]
fn typed_image_ref() {
let width = 384;
let height = 512;
let buffer = vec![U8::new(0); (width * height) as usize];
let img = TypedImageRef::<U8>::new(width, height, &buffer).unwrap();
split(&img);
}
#[test]
fn typed_image() {
let mut img: TypedImage<U8> = TypedImage::new(384, 512);
split(&img);
split_mut(&mut img);
}
#[test]
fn typed_cropped_image() {
let img = TypedImage::<U8>::new(384 + 20, 512 + 20);
let cropped_img = TypedCroppedImage::from_ref(&img, 10, 10, 384, 512).unwrap();
split(&cropped_img);
}
#[test]
fn typed_cropped_image_mut() {
let mut img: TypedImage<U8> = TypedImage::new(384 + 20, 512 + 20);
let mut cropped_img = TypedCroppedImageMut::from_ref(&mut img, 10, 10, 384, 512).unwrap();
split(&cropped_img);
split_mut(&mut cropped_img);
}
}
|