Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Return zero if the size of the input is equal to the output #9

Closed
rsuu opened this issue Jul 13, 2022 · 1 comment
Closed

[BUG] Return zero if the size of the input is equal to the output #9

rsuu opened this issue Jul 13, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@rsuu
Copy link

rsuu commented Jul 13, 2022

Code here

use std::io::BufWriter;
use std::num::NonZeroU32;

use image::codecs::png::PngEncoder;
use image::io::Reader as ImageReader;
use image::{ColorType, ImageEncoder};

use fast_image_resize as fir;

fn main() {
    not_work(); // output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    work(); // output: [255, 196, 181, 255, 196, 181, 255, 198, 181, 255]
}

fn work() {
    let img = ImageReader::open("/dev/shm/0/1.png")
        .unwrap()
        .decode()
        .unwrap();
    let width = NonZeroU32::new(img.width()).unwrap();
    let height = NonZeroU32::new(img.height()).unwrap();

    let src_image = fir::Image::from_vec_u8(
        width,
        height,
        img.to_rgb8().into_raw(),
        fir::PixelType::U8x3,
    )
    .unwrap();

    let fix_width = NonZeroU32::new(img.width() * 2).unwrap();
    let fix_height = NonZeroU32::new(img.height() * 2).unwrap();
    let dst_width = fix_width; // fix here
    let dst_height = fix_height;

    let mut dst_image = fir::Image::new(dst_width, dst_height, src_image.pixel_type());
    let mut dst_view = dst_image.view_mut();
    let mut resizer = fir::Resizer::new(fir::ResizeAlg::Convolution(fir::FilterType::Box));

    resizer.resize(&src_image.view(), &mut dst_view).unwrap();

    eprintln!("{:?}", &dst_image.buffer()[0..10]);
}

fn not_work() {
    let img = ImageReader::open("/dev/shm/0/1.png")
        .unwrap()
        .decode()
        .unwrap();
    let width = NonZeroU32::new(img.width()).unwrap();
    let height = NonZeroU32::new(img.height()).unwrap();

    let src_image = fir::Image::from_vec_u8(
        width,
        height,
        img.to_rgb8().into_raw(),
        fir::PixelType::U8x3,
    )
    .unwrap();
    let dst_width = width; // bug here
    let dst_height = height;

    let mut dst_image = fir::Image::new(dst_width, dst_height, src_image.pixel_type());
    let mut dst_view = dst_image.view_mut();
    let mut resizer = fir::Resizer::new(fir::ResizeAlg::Convolution(fir::FilterType::Box));

    resizer.resize(&src_image.view(), &mut dst_view).unwrap();

    eprintln!("{:?}", &dst_image.buffer()[0..10]);
}
@Cykooz Cykooz added the bug Something isn't working label Jul 14, 2022
@Cykooz Cykooz self-assigned this Jul 14, 2022
Cykooz added a commit that referenced this issue Jul 14, 2022
@Cykooz
Copy link
Owner

Cykooz commented Jul 14, 2022

Thank you.
Has fixed in release 0.9.7

@Cykooz Cykooz closed this as completed Jul 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants