Implement less abstracted nearest filtering.

Add some tests that try to compare image's Nearest with my
implementation.  According the PSNR they're very different, but to a
human the look the same.
This commit is contained in:
2020-02-22 09:36:23 -08:00
parent 77d69221d1
commit 7f64a4d2f6
2 changed files with 151 additions and 16 deletions

View File

@@ -2,12 +2,13 @@ use criterion::BenchmarkId;
use criterion::Throughput;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use image::imageops::FilterType;
use image::imageops;
use image::GenericImageView;
use photosync::library::load_image;
use photosync::library::resize;
use photosync::library::save_to_jpeg_bytes;
use photosync::library::FilterType;
pub fn criterion_benchmark(c: &mut Criterion) {
const TEST_IMAGE_PATH: &'static str = "testdata/image.jpg";
@@ -28,9 +29,10 @@ pub fn criterion_benchmark(c: &mut Criterion) {
{
let (w, h) = size;
for filter in [
FilterType::Builtin(imageops::Nearest),
FilterType::Builtin(imageops::CatmullRom),
FilterType::Builtin(imageops::Lanczos3),
FilterType::Nearest,
FilterType::CatmullRom,
FilterType::Lanczos3,
]
.iter()
{
@@ -62,7 +64,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
),
size,
|b, size| {
let small_img = resize(&img, *size, FilterType::Lanczos3);
let small_img = resize(&img, *size, FilterType::Builtin(imageops::Lanczos3));
b.iter(|| black_box(save_to_jpeg_bytes(&small_img)))
},
);
@@ -80,7 +82,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|b, size| {
b.iter(|| {
let img = load_image(TEST_IMAGE_PATH).expect("failed to load test image");
let small_img = resize(&img, *size, FilterType::Lanczos3);
let small_img = resize(&img, *size, FilterType::Builtin(imageops::Lanczos3));
black_box(save_to_jpeg_bytes(&small_img))
})
},