Merge pull request #3312 from JPlay/fix_animated_image_total_duration_calculate

fix: Eliminates accumulated floating point errors.
This commit is contained in:
DreamPiggy 2021-12-31 16:28:32 +08:00 committed by GitHub
commit 89313b997e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -57,12 +57,12 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
durations[i] = frames[i].duration * 1000;
}
NSUInteger const gcd = gcdArray(frameCount, durations);
__block NSUInteger totalDuration = 0;
__block NSTimeInterval totalDuration = 0;
NSMutableArray<UIImage *> *animatedImages = [NSMutableArray arrayWithCapacity:frameCount];
[frames enumerateObjectsUsingBlock:^(SDImageFrame * _Nonnull frame, NSUInteger idx, BOOL * _Nonnull stop) {
UIImage *image = frame.image;
NSUInteger duration = frame.duration * 1000;
totalDuration += duration;
totalDuration += frame.duration;
NSUInteger repeatCount;
if (gcd) {
repeatCount = duration / gcd;
@ -74,7 +74,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
}
}];
animatedImage = [UIImage animatedImageWithImages:animatedImages duration:totalDuration / 1000.f];
animatedImage = [UIImage animatedImageWithImages:animatedImages duration:totalDuration];
#else