Skip to content

Commit

Permalink
Merge pull request SDWebImage#3499 from acton393/useSDGraphicsImageRe…
Browse files Browse the repository at this point in the history
…nderer

refactor:use SDGraphicsImageRenderer
  • Loading branch information
dreampiggy authored Feb 21, 2023
2 parents 554e05a + 53cd568 commit 50aade0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
29 changes: 15 additions & 14 deletions SDWebImage/Core/SDImageIOCoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "UIImage+Metadata.h"
#import "SDImageGraphics.h"
#import "SDImageIOAnimatedCoderInternal.h"
#import "SDGraphicsImageRenderer.h"

#import <ImageIO/ImageIO.h>
#import <CoreServices/CoreServices.h>
Expand Down Expand Up @@ -95,22 +96,22 @@ + (UIImage *)createBitmapPDFWithData:(nonnull NSData *)data pageNumber:(NSUInteg
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(xScale, yScale);
CGAffineTransform transform = CGPDFPageGetDrawingTransform(page, box, drawRect, 0, preserveAspectRatio);

SDGraphicsBeginImageContextWithOptions(targetRect.size, NO, 0);
CGContextRef context = SDGraphicsGetCurrentContext();

SDGraphicsImageRendererFormat *format = [[SDGraphicsImageRendererFormat alloc] init];
format.opaque = NO;
SDGraphicsImageRenderer *renderer = [[SDGraphicsImageRenderer alloc] initWithSize:targetRect.size format:format];
image = [renderer imageWithActions:^(CGContextRef _Nonnull context) {

#if SD_UIKIT || SD_WATCH
// Core Graphics coordinate system use the bottom-left, UIKit use the flipped one
CGContextTranslateCTM(context, 0, targetRect.size.height);
CGContextScaleCTM(context, 1, -1);
// Core Graphics coordinate system use the bottom-left, UIKit use the flipped one
CGContextTranslateCTM(context, 0, targetRect.size.height);
CGContextScaleCTM(context, 1, -1);
#endif

CGContextConcatCTM(context, scaleTransform);
CGContextConcatCTM(context, transform);

CGContextDrawPDFPage(context, page);

image = SDGraphicsGetImageFromCurrentImageContext();
SDGraphicsEndImageContext();

CGContextConcatCTM(context, scaleTransform);
CGContextConcatCTM(context, transform);

CGContextDrawPDFPage(context, page);
}];

CGPDFDocumentRelease(document);

Expand Down
11 changes: 7 additions & 4 deletions SDWebImage/Core/UIImage+Transform.m
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,13 @@ - (nullable UIImage *)sd_blurredImageWithRadius:(CGFloat)blurRadius {
if (CGImageGetBitsPerPixel(imageRef) != 32 ||
CGImageGetBitsPerComponent(imageRef) != 8 ||
!((CGImageGetBitmapInfo(imageRef) & kCGBitmapAlphaInfoMask))) {
SDGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
[self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
imageRef = SDGraphicsGetImageFromCurrentImageContext().CGImage;
SDGraphicsEndImageContext();
SDGraphicsImageRendererFormat *format = [[SDGraphicsImageRendererFormat alloc] init];
format.scale = self.scale;
format.opaque = NO;
SDGraphicsImageRenderer *renderer = [[SDGraphicsImageRenderer alloc] initWithSize:self.size format:format];
imageRef = [renderer imageWithActions:^(CGContextRef _Nonnull context) {
[self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
}].CGImage;
}

vImage_Buffer effect = {}, scratch = {};
Expand Down

0 comments on commit 50aade0

Please sign in to comment.