image icon indicating copy to clipboard operation
image copied to clipboard

DynamicImage:from SubImage<&DynamicImage>::to_image creates Rgba8 instead of L16

Open emirror-de opened this issue 1 year ago • 3 comments

I am using the code below to transform a grayscale image from SubImage<&DynamicImage> to DynamicImage. Is there something I am missing during this conversion?

Expected

I would expect the new dest image to be L16 as well.

Actual behaviour

dest image is of Rgba8.

Reproduction steps

// source = SubImage<&DynamicImage>
debug!("{}", source.inner().color()); // outputs: L16
let dest = DynamicImage::from(source.to_image());
debug!("{}", dest.color()); // outputs: Rgba8

emirror-de avatar Jul 01 '24 09:07 emirror-de

I am now using this workaround:

let tmp_img = source.to_image();
let mut dest = DynamicImage::new(tmp_img.width(), tmp_img.height(), img.inner().color());
dest.copy_from(&*source, 0, 0)?;

But this feels a bit complicated and suboptimal?

emirror-de avatar Jul 01 '24 09:07 emirror-de

This is related to https://github.com/image-rs/image/issues/1952. The DynamicImage enum implements GenericImage<Rgba<u8>> even though it really shouldn't

fintelia avatar Jul 02 '24 05:07 fintelia

Ahh I see. Thanks for the hint.

emirror-de avatar Jul 03 '24 18:07 emirror-de