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

Changing logic to select frameCacheSizeOptimal. #172

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions FLAnimatedImage/FLAnimatedImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,12 @@ - (instancetype)initWithAnimatedGIFData:(NSData *)data optimalFrameCacheSize:(NS
if (optimalFrameCacheSize == 0) {
// Calculate the optimal frame cache size: try choosing a larger buffer window depending on the predicted image size.
// It's only dependent on the image size & number of frames and never changes.
CGFloat animatedImageDataSize = CGImageGetBytesPerRow(self.posterImage.CGImage) * self.size.height * (self.frameCount - skippedFrameCount) / MEGABYTE;
CGFloat animatedImageDataSizePerFrame = CGImageGetBytesPerRow(self.posterImage.CGImage) * self.size.height / MEGABYTE;
CGFloat animatedImageDataSize = animatedImageDataSizePerFrame * (self.frameCount - skippedFrameCount);
if (animatedImageDataSize <= FLAnimatedImageDataSizeCategoryAll) {
_frameCacheSizeOptimal = self.frameCount;
} else if (animatedImageDataSize <= FLAnimatedImageDataSizeCategoryDefault) {
} else if (animatedImageDataSize <= FLAnimatedImageDataSizeCategoryDefault ||
animatedImageDataSizePerFrame * FLAnimatedImageFrameCacheSizeDefault <= FLAnimatedImageDataSizeCategoryAll) {
// This value doesn't depend on device memory much because if we're not keeping all frames in memory we will always be decoding 1 frame up ahead per 1 frame that gets played and at this point we might as well just keep a small buffer just large enough to keep from running out of frames.
_frameCacheSizeOptimal = FLAnimatedImageFrameCacheSizeDefault;
} else {
Expand Down