Add transpose and speedup rotation#994
Add transpose and speedup rotation#994wiredfool merged 8 commits intopython-pillow:masterfrom homm:add-transpose
Conversation
libImaging/Geometry.c
Outdated
There was a problem hiding this comment.
Rewording to native english. I think this is what you mean.
For large images rotation is an inefficient operation in terms of CPU cache.
One row in the source image affects each column in destination.
Rotating in chunks that fit in the cache can speed up rotation 8x on a modern CPU.
A chunk size of 128 requires only 65k of CPU cache and is large enough
that the overhead from the extra loops are not apparent.
|
Looks good to me.
Question: Merge order of this vs the other ones? After #977 ? |
|
Have added tests. Merge order doesn't matter. |
Tests/test_image_transpose.py
Outdated
There was a problem hiding this comment.
You really need change standard test image size :) #947
There was a problem hiding this comment.
Yes, it would be good, but it took quite a while to regenerate all the test images. (If we do decide to re-generate them, I tried to mention how they were generated in the commit messages.) We should at aim for any new non-hopper test images committed to meet the #947 requirements.
You could always open a different, non-square test image, or do a resize/crop before continuing.
|
Update tests with not square image and fix bugs in tests related to this! |
|
Great, non-square test images are definitely the way forward! Do you think you could add some error tests to cover these lines: And the other similar ones in the same file if you like. |
|
I think this is impossible, because those functions are used only from '_rotate', which creates temporary images with right mode and size. |
|
Sure, no problem. I'll let wiredfool have a look over it before merging. Thanks for all these improvements! |
Add transpose and cache aware rotation
This adds new
Imaging.TRANSPOSEmethod forImage.transpose()operation. Also this speeds upImage.ROTATE_90andImage.ROTATE_270.As you can see, this doesn't improve performance for relatively small images, because they whole fit in cache, but for large images this gives 8x speedup.
Tests pending.