-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for row pitch in ImageView and ImageViewMut
#66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for custom row pitches to ImageView and ImageViewMut, enabling encoded/decoded operations on cropped or non-contiguous sub-views. It refactors encoders and decoders to consume these views instead of raw buffers and updates tests to validate that contiguous vs. non‐contiguous workflows produce identical results.
- Introduce
row_pitchinImageView/ImageViewMutplusnew_with(),is_contiguous(),cropped(), and row iterators. - Refactor decoder/encoder APIs to use image views and new utilities (
for_each_chunk,for_each_f32_rgba_rows). - Update and add tests (
test_row_pitch) to verify contiguous and non-contiguous decode/encode yield the same output.
Reviewed Changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/util.rs | Switched read_dds_rect_as_u8 to the new read_surface_rect(image.view_mut(), rect) API |
| tests/encode.rs | Replaced manual buffer/stride logic with read_surface + .cropped(); added test_row_pitch |
| tests/decode.rs | Updated decode_rect tests to use ImageViewMut; added a decoding test_row_pitch |
| src/lib.rs | Added row_pitch field, constructors (new_with), is_contiguous, cropped, and row iterators |
| src/error.rs | Removed legacy pitch/buffer errors; added UnexpectedRectSize |
| src/resize.rs | Adjusted resizing to handle non‐contiguous views via row iterators |
| src/split.rs | Refactored split_surface_into_lines to use iterator-based ranges and cropping |
| src/encode/write_util.rs | New helpers: for_each_f32_rgba_rows and for_each_chunk |
| src/encode/* | Updated all encoder modules to accept ImageView, use chunk/row utilities |
| src/decode/* | Updated all decoder modules to accept ImageViewMut, use offset abstraction and row iterators |
Comments suppressed due to low confidence (2)
src/error.rs:127
- [nitpick] The message "Unexpected rectangle size" is vague—consider including the expected vs. actual sizes or clarifying that the image view size must match the rectangle size to aid debugging.
DecodingError::UnexpectedRectSize => {
src/split.rs:6
- [nitpick] Returning
Option<impl Iterator<...>>can obscure control flow and make callers less flexible. Consider returning aVec<Range<u32>>directly (orBox<dyn Iterator<...>>) to simplify the code and improve readability.
fn split_surface_into_lines(
|
Not even bad. I didn't expect copilot's reviews to be very good, but it actually found a bug my tests didn't catch. Sure, the fix wasn't 100% correct, but just pointing out the problem is good enough. As for the bug itself, I fixed it and changed the tests to cover the changed code paths. |
Resolves #56
This PR adds support for row pitch in image views, which makes cropping and en/decoding image rectangles possible. This is quite useful, but was a pain to implement, because the assumption
row_pitch == width * bytes_per_pixelas built into a lot of en/decoders. (It was such a pain that this PR is actually my third attempt at implementing this. But I'm quite happy that I did. The library is better for it.)I tested the new row pitch changes by en/decoding random images/data with a both contiguous and non-contiguous views. If everything is implemented correctly, they'll produce the same result. This is done for all possible combinations of format and color (currently 73*12).
The performance impact of this feature is negligible. It's maybe 1% on average. Truth be told, there was a lot of noise in my benchmark timings, so 1% is my best guesstimate. However, I can say with certainty that there are no dramatic slowdowns.
Changes:
row_pitch: usizefield toImageViewandImageViewMut. This makes it possible to useImageView*not just for whole (contiguous) images, but also for cropped sub-views of images.croppedandis_contiguousfunctions to the view types.decode_rectandDecoder::read_surface_rectAPIs to make use of row pitch support inImageViewMut. I also updatedDecodeErrorto remove 2 error variants that are no longer possibleand to add 1 new one.Recttype and replaced it with anOffsettype.