From 911328c1b4c149c5a4bf7adef675c1abe3ba162c Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 23 Jun 2022 19:37:13 +0800 Subject: [PATCH] Fix the case when previous pipeline use thumbnail transformer use together, second pipeline use the full size loading --- SDWebImage/Core/SDWebImageManager.m | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/SDWebImage/Core/SDWebImageManager.m b/SDWebImage/Core/SDWebImageManager.m index 3c0fa69e..04e4e1c5 100644 --- a/SDWebImage/Core/SDWebImageManager.m +++ b/SDWebImage/Core/SDWebImageManager.m @@ -575,9 +575,16 @@ static id _defaultImageLoader; @autoreleasepool { // transformed/thumbnailed cache key NSString *key = [self cacheKeyForURL:url context:context]; - UIImage *transformedImage = [transformer transformedImageWithImage:originalImage forKey:key]; + // Case that transformer one thumbnail, which this time need full pixel image + UIImage *fullSizeImage = originalImage; + if (shouldDecodeFullImage) { + SDWebImageMutableContext *tempContext = [context mutableCopy]; + tempContext[SDWebImageContextImageThumbnailPixelSize] = nil; + fullSizeImage = SDImageCacheDecodeImageData(originalData, key, options, tempContext) ?: originalImage; + } + UIImage *transformedImage = [transformer transformedImageWithImage:fullSizeImage forKey:key]; if (transformedImage && finished) { - BOOL imageWasTransformed = ![transformedImage isEqual:originalImage]; + BOOL imageWasTransformed = ![transformedImage isEqual:fullSizeImage]; NSData *cacheData; // pass nil if the image was transformed, so we can recalculate the data from the image if (cacheSerializer && (storeCacheType == SDImageCacheTypeDisk || storeCacheType == SDImageCacheTypeAll)) { @@ -589,7 +596,7 @@ static id _defaultImageLoader; [self callStoreTransformCacheProcessForOperation:operation url:url options:options context:context image:transformedImage data:cacheData cacheType:cacheType transformed:imageWasTransformed finished:finished completed:completedBlock]; } else { // Continue store transform cache process - [self callStoreTransformCacheProcessForOperation:operation url:url options:options context:context image:originalImage data:originalData cacheType:cacheType transformed:NO finished:finished completed:completedBlock]; + [self callStoreTransformCacheProcessForOperation:operation url:url options:options context:context image:fullSizeImage data:originalData cacheType:cacheType transformed:NO finished:finished completed:completedBlock]; } } }); @@ -601,9 +608,9 @@ static id _defaultImageLoader; // disable thumbnail decoding SDWebImageMutableContext *tempContext = [context mutableCopy]; tempContext[SDWebImageContextImageThumbnailPixelSize] = nil; - UIImage *originalImage = SDImageCacheDecodeImageData(originalData, key, options, tempContext); + UIImage *fullSizeImage = SDImageCacheDecodeImageData(originalData, key, options, tempContext) ?: originalImage; // Continue store transform cache process - [self callStoreTransformCacheProcessForOperation:operation url:url options:options context:context image:originalImage data:originalData cacheType:cacheType transformed:NO finished:finished completed:completedBlock]; + [self callStoreTransformCacheProcessForOperation:operation url:url options:options context:context image:fullSizeImage data:originalData cacheType:cacheType transformed:NO finished:finished completed:completedBlock]; } }); } else {