mirror of
https://github.com/zhigang1992/PINRemoteImage.git
synced 2026-04-24 04:15:32 +08:00
More explicit TargetConditional intentions
First we check to see if we are on the iOS or tvOS. If not, then we defer back to OS X. TARGET_OS_IPHONE is a variant of TARGET_OS_MAC, which makes this whole thing really stupid.
This commit is contained in:
@@ -1 +1 @@
|
||||
github "pinterest/PINCache" "2.2.1"
|
||||
github "pinterest/PINCache" "2.2.2"
|
||||
|
||||
@@ -6,15 +6,16 @@
|
||||
//
|
||||
//
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@import Foundation;
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
@import UIKit;
|
||||
#elif TARGET_OS_MAC
|
||||
@import Cocoa;
|
||||
#endif
|
||||
|
||||
#import "PINRemoteImageMacros.h"
|
||||
|
||||
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
|
||||
#if !(TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
@interface NSImage (PINiOSMapping)
|
||||
|
||||
@property(nonatomic, readonly, nullable) CGImageRef CGImage;
|
||||
@@ -34,7 +35,7 @@ NSData * __nullable PINImagePNGRepresentation(PINImage * __nonnull image);
|
||||
+ (nullable PINImage *)pin_decodedImageWithData:(nonnull NSData *)data;
|
||||
+ (nullable PINImage *)pin_decodedImageWithData:(nonnull NSData *)data skipDecodeIfPossible:(BOOL)skipDecodeIfPossible;
|
||||
+ (nullable PINImage *)pin_decodedImageWithCGImageRef:(nonnull CGImageRef)imageRef;
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
+ (nullable PINImage *)pin_decodedImageWithCGImageRef:(nonnull CGImageRef)imageRef orientation:(UIImageOrientation) orientation;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
#import "NSData+ImageDetectors.h"
|
||||
|
||||
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
|
||||
#if !(TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
|
||||
@implementation NSImage (PINiOSMapping)
|
||||
|
||||
- (CGImageRef)CGImage
|
||||
@@ -46,9 +46,9 @@
|
||||
|
||||
NSData * __nullable PINImageJPEGRepresentation(PINImage * __nonnull image, CGFloat compressionQuality)
|
||||
{
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
return UIImageJPEGRepresentation(image, compressionQuality);
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
|
||||
NSDictionary *imageProperties = @{NSImageCompressionFactor : @(compressionQuality)};
|
||||
return [imageRep representationUsingType:NSJPEGFileType properties:imageProperties];
|
||||
@@ -56,9 +56,9 @@ NSData * __nullable PINImageJPEGRepresentation(PINImage * __nonnull image, CGFlo
|
||||
}
|
||||
|
||||
NSData * __nullable PINImagePNGRepresentation(PINImage * __nonnull image) {
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
return UIImagePNGRepresentation(image);
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
|
||||
NSDictionary *imageProperties = @{NSImageCompressionFactor : @1};
|
||||
return [imageRep representationUsingType:NSPNGFileType properties:imageProperties];
|
||||
@@ -95,14 +95,14 @@ NSData * __nullable PINImagePNGRepresentation(PINImage * __nonnull image) {
|
||||
if (imageSourceRef) {
|
||||
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(imageSourceRef, 0, (CFDictionaryRef)@{(NSString *)kCGImageSourceShouldCache : (NSNumber *)kCFBooleanFalse});
|
||||
if (imageRef) {
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
UIImageOrientation orientation = pin_UIImageOrienationFromImageSource(imageSourceRef);
|
||||
if (skipDecodeIfPossible) {
|
||||
decodedImage = [PINImage imageWithCGImage:imageRef scale:1.0 orientation:orientation];
|
||||
} else {
|
||||
decodedImage = [self pin_decodedImageWithCGImageRef:imageRef orientation:orientation];
|
||||
}
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
if (skipDecodeIfPossible) {
|
||||
CGSize imageSize = CGSizeMake(CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
|
||||
decodedImage = [[NSImage alloc] initWithCGImage:imageRef size:imageSize];
|
||||
@@ -121,7 +121,7 @@ NSData * __nullable PINImagePNGRepresentation(PINImage * __nonnull image) {
|
||||
|
||||
+ (PINImage *)pin_decodedImageWithCGImageRef:(CGImageRef)imageRef
|
||||
{
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
return [self pin_decodedImageWithCGImageRef:imageRef orientation:UIImageOrientationUp];
|
||||
}
|
||||
|
||||
@@ -154,18 +154,18 @@ NSData * __nullable PINImagePNGRepresentation(PINImage * __nonnull image) {
|
||||
|
||||
CGImageRef newImage = CGBitmapContextCreateImage(ctx);
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
decodedImage = [UIImage imageWithCGImage:newImage scale:1.0 orientation:orientation];
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
decodedImage = [[NSImage alloc] initWithCGImage:newImage size:imageSize];
|
||||
#endif
|
||||
CGImageRelease(newImage);
|
||||
CGContextRelease(ctx);
|
||||
|
||||
} else {
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
decodedImage = [UIImage imageWithCGImage:imageRef scale:1.0 orientation:orientation];
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
decodedImage = [[NSImage alloc] initWithCGImage:imageRef size:imageSize];
|
||||
#endif
|
||||
}
|
||||
@@ -173,7 +173,7 @@ NSData * __nullable PINImagePNGRepresentation(PINImage * __nonnull image) {
|
||||
return decodedImage;
|
||||
}
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
UIImageOrientation pin_UIImageOrienationFromImageSource(CGImageSourceRef imageSourceRef) {
|
||||
UIImageOrientation orientation = UIImageOrientationUp;
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
|
||||
#ifdef PIN_WEBP
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
@import UIKit;
|
||||
#elif TARGET_OS_MAC
|
||||
@import Cocoa;
|
||||
#endif
|
||||
|
||||
#import "PINRemoteImageMacros.h"
|
||||
|
||||
@@ -65,9 +65,9 @@ static void releaseData(void *info, const void *data, size_t size)
|
||||
renderingIntent);
|
||||
|
||||
PINImage *image = nil;
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
image = [UIImage imageWithCGImage:imageRef];
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
image = [[self alloc] initWithCGImage:imageRef size:CGSizeZero];
|
||||
#endif
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
//
|
||||
//
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
@import UIKit;
|
||||
#elif TARGET_OS_MAC
|
||||
@import Cocoa;
|
||||
#endif
|
||||
|
||||
#import "PINRemoteImageManager.h"
|
||||
|
||||
@@ -92,9 +92,9 @@
|
||||
|
||||
- (void)pin_setPlaceholderWithImage:(PINImage *)image
|
||||
{
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
[self setImage:image forState:UIControlStateNormal];
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
[self setImage:image];
|
||||
#endif
|
||||
}
|
||||
@@ -102,10 +102,10 @@
|
||||
- (void)pin_updateUIWithImage:(PINImage *)image animatedImage:(FLAnimatedImage *)animatedImage
|
||||
{
|
||||
if (image) {
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
[self setImage:image forState:UIControlStateNormal];
|
||||
[self setNeedsLayout];
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
[self setImage:image];
|
||||
[self setNeedsLayout:YES];
|
||||
#endif
|
||||
@@ -114,10 +114,10 @@
|
||||
|
||||
- (void)pin_clearImages
|
||||
{
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
[self setImage:nil forState:UIControlStateNormal];
|
||||
[self setNeedsLayout];
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
[self setImage:nil];
|
||||
[self setNeedsLayout:YES];
|
||||
#endif
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
//
|
||||
//
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
@import UIKit;
|
||||
#elif TARGET_OS_MAC
|
||||
@import Cocoa;
|
||||
#endif
|
||||
|
||||
#import "PINRemoteImageManager.h"
|
||||
|
||||
@@ -100,9 +100,9 @@
|
||||
if (image) {
|
||||
self.image = image;
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
[self setNeedsLayout];
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
[self setNeedsLayout:YES];
|
||||
#endif
|
||||
}
|
||||
@@ -112,9 +112,9 @@
|
||||
{
|
||||
self.image = nil;
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
[self setNeedsLayout];
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
[self setNeedsLayout:YES];
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
//
|
||||
//
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@import Foundation;
|
||||
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
@import UIKit;
|
||||
#elif TARGET_OS_MAC
|
||||
@import Cocoa;
|
||||
#endif
|
||||
|
||||
#import "PINRemoteImageMacros.h"
|
||||
|
||||
@@ -326,9 +326,9 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
CGFloat imageScale = inputImage.scale;
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
// TODO: What scale factor should be used here?
|
||||
CGFloat imageScale = [[NSScreen mainScreen] backingScaleFactor];
|
||||
#endif
|
||||
@@ -343,15 +343,15 @@
|
||||
}
|
||||
|
||||
CGContextRef ctx;
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
UIGraphicsBeginImageContextWithOptions(inputSize, YES, imageScale);
|
||||
ctx = UIGraphicsGetCurrentContext();
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
ctx = CGBitmapContextCreate(0, inputSize.width, inputSize.height, 8, 0, [NSColorSpace genericRGBColorSpace].CGColorSpace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
|
||||
#endif
|
||||
|
||||
if (ctx) {
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
CGContextScaleCTM(ctx, 1.0, -1.0);
|
||||
CGContextTranslateCTM(ctx, 0, -inputSize.height);
|
||||
#endif
|
||||
@@ -431,9 +431,9 @@
|
||||
|
||||
// Cleanup
|
||||
free(outputBuffer->data);
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
outputImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
CGImageRef outputImageRef = CGBitmapContextCreateImage(ctx);
|
||||
outputImage = [[NSImage alloc] initWithCGImage:outputImageRef size:inputSize];
|
||||
CFRelease(outputImageRef);
|
||||
@@ -453,7 +453,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
UIGraphicsEndImageContext();
|
||||
#endif
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
//
|
||||
//
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
@import UIKit;
|
||||
#elif TARGET_OS_MAC
|
||||
@import Cocoa;
|
||||
#endif
|
||||
|
||||
#import "PINRemoteImageManager.h"
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
#define FLAnimatedImage NSObject
|
||||
#endif
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
#define PINImage UIImage
|
||||
#define PINImageView UIImageView
|
||||
#define PINButton UIButton
|
||||
#else
|
||||
#elif TARGET_OS_MAC
|
||||
#define PINImage NSImage
|
||||
#define PINImageView NSImageView
|
||||
#define PINButton NSButton
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
//
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@import Foundation;
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
@import UIKit;
|
||||
#elif TARGET_OS_MAC
|
||||
@import Cocoa;
|
||||
#endif
|
||||
|
||||
#import "PINRemoteImageManagerResult.h"
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
//
|
||||
//
|
||||
|
||||
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@import Foundation;
|
||||
|
||||
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR || TARGET_OS_TV)
|
||||
@import UIKit;
|
||||
#elif TARGET_OS_MAC
|
||||
@import Cocoa;
|
||||
#endif
|
||||
|
||||
#import "PINRemoteImageMacros.h"
|
||||
|
||||
Reference in New Issue
Block a user