Fix the issue that progressive image which show first poster image, the decode image size is wrong. Should always create CGContext for animated image

This commit is contained in:
DreamPiggy 2020-01-18 19:42:35 +08:00
parent 1b22ee5e56
commit 3f847ba6dc
1 changed files with 21 additions and 5 deletions

View File

@ -959,18 +959,34 @@ static void FreeImageData(void *info, const void *data, size_t size) {
- (UIImage *)safeStaticImageFrame {
UIImage *image;
if (!_colorSpace) {
_colorSpace = [self sd_createColorSpaceWithDemuxer:_demux];
}
// Static WebP image
WebPIterator iter;
if (!WebPDemuxGetFrame(_demux, 1, &iter)) {
WebPDemuxReleaseIterator(&iter);
return nil;
}
if (!_colorSpace) {
_colorSpace = [self sd_createColorSpaceWithDemuxer:_demux];
}
// Check whether we need to use thumbnail
CGSize scaledSize = SDCalculateThumbnailSize(CGSizeMake(_canvasWidth, _canvasHeight), _preserveAspectRatio, _thumbnailSize);
CGImageRef imageRef = [self sd_createWebpImageWithData:iter.fragment colorSpace:_colorSpace scaledSize:scaledSize];
CGImageRef imageRef;
if (_hasAnimation) {
// If have animation, we still need to allocate a CGContext, because the poster frame may be smaller than canvas
if (!_canvas) {
CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Host;
bitmapInfo |= _hasAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst;
CGContextRef canvas = CGBitmapContextCreate(NULL, _canvasWidth, _canvasHeight, 8, 0, [SDImageCoderHelper colorSpaceGetDeviceRGB], bitmapInfo);
if (!canvas) {
return nil;
}
_canvas = canvas;
}
CGSize scaledSize = SDCalculateThumbnailSize(CGSizeMake(_canvasWidth, _canvasHeight), _preserveAspectRatio, _thumbnailSize);
imageRef = [self sd_drawnWebpImageWithCanvas:_canvas iterator:iter colorSpace:_colorSpace scaledSize:scaledSize];
} else {
CGSize scaledSize = SDCalculateThumbnailSize(CGSizeMake(iter.width, iter.height), _preserveAspectRatio, _thumbnailSize);
imageRef = [self sd_createWebpImageWithData:iter.fragment colorSpace:_colorSpace scaledSize:scaledSize];
}
if (!imageRef) {
return nil;
}