image
image copied to clipboard
Improve performance of grayscale function and better clone standards
Hey! I was working with your library and found out that the grayscale function was too slow, specially, compared to the examples you use, for example:
DynamicImage::ImageLuma8(image.into_luma8());
After some investigation I found the issue inside the grayscale function, when using the code above there's a call to the dynamic map function which works much faster than the imageops::grayscale generic function.
I also changed a few unneeded conversions to just clone since the type is already the same (in this case for example ImageLumaA8 was being converted with imageops even though it's not needed)
After those changes the DynamicImage grayscale function is now faster than the example code above.
Pictures proving the new grayscale is faster:
Old performance:
New performance:
Edit: Forgot to remove comment from license agreement
I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to choose either at their option.
I'd feel better about this if we had some theory for why convert
is faster than imageops::grayscale
. Are we sure they're producing identical results?
The conceptual difference: imageops::grayscale
does an external loop over pixels, convert
is the interior iteration version of this loop. Due imageops
being generic it can't statically know the best iteration strategy for the layout, nor can it communicate the same bounds checks to the compiler. It's not very surprising to me.
@fintelia Just ran a few tests to check that the resulting images of grayscale are correct. They are! I'll add a few images of the result of the "new" function