image
image copied to clipboard
DynamicImage:from SubImage<&DynamicImage>::to_image creates Rgba8 instead of L16
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
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?
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
Ahh I see. Thanks for the hint.