You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// blend the current frame with the non-disposed frame, then update
// the non-disposed frame according to the disposal method.
fnblend_and_dispose_pixel(
dispose:DisposalMethod,
previous:&mutRgba<u8>,
current:&mutRgba<u8>,
){
let pixel_alpha = current.channels()[3];
if pixel_alpha == 0{
*current = *previous;
}
match dispose {
DisposalMethod::Any | DisposalMethod::Keep => {
// do not dispose
// (keep pixels from this frame)
// note: the `Any` disposal method is underspecified in the GIF
// spec, but most viewers treat it identically to `Keep`
*previous = *current;
}
DisposalMethod::Background => {
// restore to background color
// (background shows through transparent pixels in the next frame)
*previous = Rgba([0,0,0,0]);
}
DisposalMethod::Previous => {
// restore to previous
// (dispose frames leaving the last none disposal frame)
}
}
}
As you can see, it has non-trivial branches on every pixel, and no vectorization. Its performance could be considerably improved by branching once on the disposal method outside the loop, since the blending method is the same for every frame; and then calling the appropriate loop with no branches that operates on multiple elements at once, e.g. via slice::chunks_exact_mut.
However I have not checked how much time is spent with this function with a profiler. It might be that this function is Fast Enough ™️ (although I doubt that).
The text was updated successfully, but these errors were encountered:
This happens in
image
v0.24.7 as well as the latest git on commit 96b8ceeThe following function is currently called for every pixel in the image when decoding animated GIFs:
image/src/codecs/gif.rs
Lines 289 to 319 in 96b8cee
As you can see, it has non-trivial branches on every pixel, and no vectorization. Its performance could be considerably improved by branching once on the disposal method outside the loop, since the blending method is the same for every frame; and then calling the appropriate loop with no branches that operates on multiple elements at once, e.g. via
slice::chunks_exact_mut
.However I have not checked how much time is spent with this function with a profiler. It might be that this function is Fast Enough ™️ (although I doubt that).
The text was updated successfully, but these errors were encountered: