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:
parent
1b22ee5e56
commit
3f847ba6dc
|
@ -959,18 +959,34 @@ static void FreeImageData(void *info, const void *data, size_t size) {
|
||||||
|
|
||||||
- (UIImage *)safeStaticImageFrame {
|
- (UIImage *)safeStaticImageFrame {
|
||||||
UIImage *image;
|
UIImage *image;
|
||||||
if (!_colorSpace) {
|
|
||||||
_colorSpace = [self sd_createColorSpaceWithDemuxer:_demux];
|
|
||||||
}
|
|
||||||
// Static WebP image
|
// Static WebP image
|
||||||
WebPIterator iter;
|
WebPIterator iter;
|
||||||
if (!WebPDemuxGetFrame(_demux, 1, &iter)) {
|
if (!WebPDemuxGetFrame(_demux, 1, &iter)) {
|
||||||
WebPDemuxReleaseIterator(&iter);
|
WebPDemuxReleaseIterator(&iter);
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
if (!_colorSpace) {
|
||||||
|
_colorSpace = [self sd_createColorSpaceWithDemuxer:_demux];
|
||||||
|
}
|
||||||
// Check whether we need to use thumbnail
|
// Check whether we need to use thumbnail
|
||||||
CGSize scaledSize = SDCalculateThumbnailSize(CGSizeMake(_canvasWidth, _canvasHeight), _preserveAspectRatio, _thumbnailSize);
|
CGImageRef imageRef;
|
||||||
CGImageRef imageRef = [self sd_createWebpImageWithData:iter.fragment colorSpace:_colorSpace scaledSize:scaledSize];
|
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) {
|
if (!imageRef) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue