- Added method SrcImageView.set_crop_box_to_fit_dst_size().

- Fixed out-of-bounds error during resize with cropping.
- Refactored `ImageData`.
This commit is contained in:
Kirill Kuzminykh
2021-08-28 20:45:31 +03:00
parent c5d527704c
commit 4cb09ed0ac
3 changed files with 6 additions and 6 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ const fn p(r: u8, g: u8, b: u8, a: u8) -> u32 {
// Multiplies by alpha
fn get_src_image(width: NonZeroU32, height: NonZeroU32, pixel: u32) -> ImageData {
fn get_src_image(width: NonZeroU32, height: NonZeroU32, pixel: u32) -> ImageData<'static> {
let buf_size = (width.get() * height.get()) as usize;
let buffer = vec![pixel; buf_size];
ImageData::from_vec_u32(width, height, buffer, PixelType::U8x4).unwrap()
+2 -2
View File
@@ -13,7 +13,7 @@ const NEW_HEIGHT: u32 = 567;
const NEW_BIG_WIDTH: u32 = 4928;
const NEW_BIG_HEIGHT: u32 = 3279;
fn get_big_source_image() -> ImageData {
fn get_big_source_image() -> ImageData<'static> {
let img = utils::get_big_rgba_image();
let width = img.width();
let height = img.height();
@@ -26,7 +26,7 @@ fn get_big_source_image() -> ImageData {
.unwrap()
}
fn get_small_source_image() -> ImageData {
fn get_small_source_image() -> ImageData<'static> {
let img = utils::get_small_rgba_image();
let width = img.width();
let height = img.height();
+3 -3
View File
@@ -10,7 +10,7 @@ use fast_image_resize::{
};
fn get_source_image() -> ImageData<'static> {
let img = ImageReader::open("/home/cykooz/t.png")
let img = ImageReader::open("./data/nasa-4928x3279.png")
.unwrap()
.decode()
.unwrap();
@@ -173,12 +173,12 @@ fn resize_with_cropping() {
resizer.set_cpu_extensions(CpuExtensions::None);
}
let mut dst_image = ImageData::new(
NonZeroU32::new(256).unwrap(),
NonZeroU32::new(1024).unwrap(),
NonZeroU32::new(256).unwrap(),
src_image.pixel_type(),
);
let mut src_view = src_image.src_view();
src_view.set_crop_box_to_fit_dst_size(dst_image.width(), dst_image.height(), None);
resizer.resize(&src_view, &mut dst_image.dst_view());
save_result(&dst_image.src_view(), "cropping_lanczos3_avx2");
save_result(&dst_image.src_view(), "cropping_lanczos3");
}