[imageio] Radically speed up PFM loading #17689
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The original code used a clever trick to allow format conversion (3float -> 4float) in-place (it went sequentially(!) from the end of the data buffer to the beginning thus ensuring that the data would not be overwritten). Unfortunately, this made the code OpenMP-incompatible. The use of two buffers (input data and output for darktable) made it possible to parallelize the format conversion loops.
Also, the code contained a separate loop for reordering image rows (bottom-top to top-bottom) using a temporary row buffer. In effect, this meant copying the entire array of image data twice more. For large images it took quite a significant amount of time.
We managed to get rid of these rows reordering by copying the rows to the correct address directly in the format conversion loop.
As a result, for example, a PFM file converted from a 45 megapixel Nikon Z7 camera image on a computer with an AMD Ryzen 7 5800HS CPU was loaded with the original code in 0.45 seconds, after changes in this PR in 0.09 seconds (fivefold speed up!).