PistonDevelopers / resize

Simple resampling library in pure Rust
http://docs.piston.rs/resize/resize/
MIT License
125 stars 18 forks source link

Edges of image are upscaled incorrectly with Point mode #30

Open xmakro opened 3 years ago

xmakro commented 3 years ago

A 2x2 grayscale image:

[1, 0,
 0, 2]

Is incorrectly upscaled to the following 4x4 image:

[1, 0, 0, 0, 
 0, 2, 2, 2, 
 0, 2, 2, 2, 
 0, 2, 2, 2]

This can be reproduced with:

fn main() {
    let mut resizer = resize::new(2, 2, 4, 4, resize::Pixel::Gray8, resize::Type::Point).unwrap();
    let src = vec![1u8, 0u8, 0u8, 2u8];
    let mut dst = vec![0u8; 4 * 4];
    resizer.resize(&src, &mut dst).unwrap();
    println!("{:?}", dst);
    // prints: [1, 0, 0, 0, 0, 2, 2, 2, 0, 2, 2, 2, 0, 2, 2, 2]
}

I only observe this behavior for the edges of the image, the center part of the image is upscaled correctly.

swfsql commented 1 year ago

I observed that on a 3x3 image, the center is also scaled incorrectly. But the distortion increases at the edge.