-
Notifications
You must be signed in to change notification settings - Fork 618
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
Implement a rows()
iterator on SubImage
and GenericImageView
to unlock better performance
#2300
Comments
What would be the return type of this function? |
rows()
iterator on GenericImageView
rows()
iterator on SubImage
Ah, you are correct! With GenericImageView we have no guarantee that pixels in a row are laid out in memory contiguously. We can however guarantee this about the |
The I've gone in circles about this part of the API. First I think that it would be nice to constrain the layout of GenericImage. Then I realize that you can just use ImageBuffer directly if you want that, so I think about deprecating GenericImage. But that would break a lot of downstream code, so might as well just leave it around? |
I don't think I think we need a type or a trait for a rectangular sub-image of an existing image, so that we could implement |
How often is image pixel data non-contiguous, and is it worth catering to the potential non-contiguous image use-cases at the cost of heavier genericness? Additionally, do crop and region drawing functions even need a Perhaps we should simply remove/deprecate all the generic traits since they have dubious usefulness and could be misleading to users. |
From perf perspective having a match on an enum per row is not too bad, as long as the innermost loop can be iterating over a slice (loop per pixel type). |
rows()
iterator on SubImage
rows()
iterator on SubImage
and GenericImageView
to unlock better performance
Another bottleneck was pointed out in a trivial 180 rotation function that's currently implemented like this: Lines 90 to 95 in 25fbd3f
We would like to write it like this instead to reduce the amount of bounds checks: for (src_row, dest_row) in image.rows().zip(destination.rows_mut().rev()) {
for (src_pixel, dst_pixel) in (src_row, dest_row.rev()) {
*dst_pixel = src_pixel;
}
} But that is not possible now because there is no |
Also there is a need for exposing rows as slices rather than a simple iterator. It is not necessary for a 180 degree rotation function, but for more complex image processing that's going to access each pixel lots of times, like blur, it's absolutely crucial. |
Right now the
ImageBuffer
type has arows()
function to iterate over the rows of the image, butGenericImageView
SubImage
does not.Working with rows rather than individual pixels is often much faster, because it lets you leverage SIMD to process multiple pixels at once. For example, #2295 would be trivial to fix given this API.
The text was updated successfully, but these errors were encountered: