image icon indicating copy to clipboard operation
image copied to clipboard

Implement Clone, Copy for SubImage

Open Shadlock0133 opened this issue 4 years ago • 1 comments

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.

Shadlock0133 avatar Sep 25 '21 19:09 Shadlock0133

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.

hgaiser avatar Oct 21 '21 11:10 hgaiser