Skip to content
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

Skipping frames for Animated WebP #61

Open
DanielZanchi opened this issue Dec 24, 2021 · 0 comments
Open

Skipping frames for Animated WebP #61

DanielZanchi opened this issue Dec 24, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@DanielZanchi
Copy link

DanielZanchi commented Dec 24, 2021

It would be good to have an option to skip frames for animated webP.
If I have a thumbnail trying to render an animated wepb image with 120 frames it could be good to render only 30 frames, to preserve speed and memory.
Maybe not the first 30 frames but skipping frames in a loop: the animation will not be very smooth obviously.

A simple, not nice looking solution to skip half of the frames:
SDImageWebPCoder.m
line 264
Adding a skipper in the loop and duplicating the duration

    int skipper = 0;
    do {
        skipper++;
        if ((skipper %2) == 0) {
            continue;
        }
            
        @autoreleasepool {
            CGImageRef imageRef = [self sd_drawnWebpImageWithCanvas:canvas iterator:iter colorSpace:colorSpace scaledSize:scaledSize];
            if (!imageRef) {
                continue;
            }

#if SD_UIKIT || SD_WATCH
            UIImage *image = [[UIImage alloc] initWithCGImage:imageRef scale:scale orientation:UIImageOrientationUp];
#else
            UIImage *image = [[UIImage alloc] initWithCGImage:imageRef scale:scale orientation:kCGImagePropertyOrientationUp];
#endif
            CGImageRelease(imageRef);
            
            NSTimeInterval duration = [self sd_frameDurationWithIterator:iter];
            SDImageFrame *frame = [SDImageFrame frameWithImage:image duration:(duration*2)];
            [frames addObject:frame];
        }
        
    } while (WebPDemuxNextFrame(&iter));
@kinarobin kinarobin added the enhancement New feature or request label Dec 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants