image
image copied to clipboard
Implement Clone, Copy for SubImage
I would like to be able to copy subimage of a reference (SubImage<&T>).
My specific use case for this functionality is storing copy-less subimages for deduplication. For example:
for _ in bounds {
let view = image.view(x, y, width, height);
if contains(seen_views, view) { continue; }
seen_views.push(view); // view is moved here
view.to_image().save(...); // which causes error here
}
This is more generally applicable to working with borrowing subimages. Currently you can achieve it using SubImage::new or GenericImageView::view, but require passing bounds around, which is slightly unergonomic.
For implementation, I think derives would suffice.
Hm yeah I agree, it makes sense for SubImage to be Clone and Copy :). I submitted a PR to fix this issue: https://github.com/image-rs/image/pull/1582.