Skip to content

Conversation

@197g
Copy link
Member

@197g 197g commented Dec 20, 2025

Similar to flipv_in_place this never needs to grow the underlying container. Our behavior of clipping the crop selection to the images dimensions ensures that the target dimensions are always smaller.

As discussed, besides the obvious performance advantages over other forms of cropping into a new allocation this would also be relevant to #2672 .

As a complementary method introduce ImageBuffer::shrink_to_fit.

Similar to `flipv_in_place` this never needs to grow the underlying
container. Our behavior of clipping the crop selection to the images
dimensions ensures that the target dimensions are always smaller.

self.width = selection.width;
self.height = selection.height;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we can't shrink the container here as this is generic over it. We could do it in DynamicImage on top of the original transform to avoid issues as rust-lang/rust#120091 even though additional conditions may be necessary for the behavior to be considered particular surprising (i.e. the linked issues is because an internal use of vec reserve/truncate leaves it with a lot of capacity, an analogy would thus be an operation that internally crops, but for instance ImageReader #2672 could truncate itself quite well).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's at least introduce the necessary method for this in the same patch.

The underlying vector can be accessed and shrunk to its own length by
itself so this also shrinks the length of the vector to fit the image.
@197g 197g merged commit 2418c3f into main Dec 21, 2025
32 checks passed
@197g 197g deleted the crop-in-place branch December 21, 2025 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants