From 4a483d7724ddee8c81da0a1c75597a1fb3ed2939 Mon Sep 17 00:00:00 2001 From: Andras Kovi Date: Sat, 4 Jan 2014 17:45:59 +0100 Subject: [PATCH] Use AFImageDownloader pod --- FRP.xcodeproj/project.pbxproj | 6 --- FRP/NSData+AFDecompression.h | 20 -------- FRP/NSData+AFDecompression.m | 96 ----------------------------------- Podfile | 3 +- Podfile.lock | 6 +++ 5 files changed, 8 insertions(+), 123 deletions(-) delete mode 100644 FRP/NSData+AFDecompression.h delete mode 100644 FRP/NSData+AFDecompression.m diff --git a/FRP.xcodeproj/project.pbxproj b/FRP.xcodeproj/project.pbxproj index 83bc496..cb13609 100644 --- a/FRP.xcodeproj/project.pbxproj +++ b/FRP.xcodeproj/project.pbxproj @@ -36,7 +36,6 @@ 5EBE2B16180B07D0007B6BF3 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EBE2AFA180B07D0007B6BF3 /* CoreData.framework */; }; 5EBE2B1E180B07D0007B6BF3 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 5EBE2B1C180B07D0007B6BF3 /* InfoPlist.strings */; }; 5EBE2B2B180B0AF1007B6BF3 /* FRPGalleryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EBE2B2A180B0AF1007B6BF3 /* FRPGalleryViewController.m */; }; - 734185B618776A1500508616 /* NSData+AFDecompression.m in Sources */ = {isa = PBXBuildFile; fileRef = 734185B518776A1500508616 /* NSData+AFDecompression.m */; }; F5C87C1873574C63889236C3 /* libPods-FRPTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E5F89E0211BE405E85BE5C5A /* libPods-FRPTests.a */; }; /* End PBXBuildFile section */ @@ -98,8 +97,6 @@ 5EBE2B1D180B07D0007B6BF3 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 5EBE2B29180B0AF1007B6BF3 /* FRPGalleryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FRPGalleryViewController.h; sourceTree = ""; }; 5EBE2B2A180B0AF1007B6BF3 /* FRPGalleryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FRPGalleryViewController.m; sourceTree = ""; }; - 734185B418776A1500508616 /* NSData+AFDecompression.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+AFDecompression.h"; sourceTree = ""; }; - 734185B518776A1500508616 /* NSData+AFDecompression.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+AFDecompression.m"; sourceTree = ""; }; 772BE9E4C5824F1C8E5CDC45 /* libPods-FRP.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FRP.a"; sourceTree = BUILT_PRODUCTS_DIR; }; C5AC1B577BDC442AA756B515 /* Pods-FRPTests.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FRPTests.xcconfig"; path = "Pods/Pods-FRPTests.xcconfig"; sourceTree = ""; }; CF6C5FA73F5F4703A3C7C4C0 /* Pods-FRP.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FRP.xcconfig"; path = "Pods/Pods-FRP.xcconfig"; sourceTree = ""; }; @@ -259,8 +256,6 @@ 5EBE2AFC180B07D0007B6BF3 /* FRP */ = { isa = PBXGroup; children = ( - 734185B418776A1500508616 /* NSData+AFDecompression.h */, - 734185B518776A1500508616 /* NSData+AFDecompression.m */, 5EBE2B05180B07D0007B6BF3 /* FRPAppDelegate.h */, 5EBE2B06180B07D0007B6BF3 /* FRPAppDelegate.m */, 5EBC59A4180B2AA200B683A7 /* FRPPhotoImporter.h */, @@ -478,7 +473,6 @@ 5E59511A180E21E0002F44FA /* FRPPhotoDetailViewController.m in Sources */, 5E595117180E0C33002F44FA /* FRPPhotoViewController.m in Sources */, 5EBC59A6180B2AA200B683A7 /* FRPPhotoImporter.m in Sources */, - 734185B618776A1500508616 /* NSData+AFDecompression.m in Sources */, 5EBE2B2B180B0AF1007B6BF3 /* FRPGalleryViewController.m in Sources */, 5E730B141815FE97003FCB43 /* FRPFullSizePhotoViewModel.m in Sources */, 5EAD1F5818173A3200C67860 /* FRPPhotoViewModel.m in Sources */, diff --git a/FRP/NSData+AFDecompression.h b/FRP/NSData+AFDecompression.h deleted file mode 100644 index 01dbb57..0000000 --- a/FRP/NSData+AFDecompression.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// NSData+AFDecompression.h -// Performance Problems Example -// -// Created by Ash Furrow on 2012-12-28. -// Copyright (c) 2012 Ash Furrow. All rights reserved. -// - -#import -#import -#import "ReactiveCocoa/ReactiveCocoa.h" - -typedef void (^AFJPEGWasDecompressedCallback)(UIImage *decompressedImage); - -@interface NSData (AFDecompression) - -// The callback block is executed on the main thread. --(void)af_decompressedImageFromJPEGDataWithCallback:(AFJPEGWasDecompressedCallback)callback; - -@end diff --git a/FRP/NSData+AFDecompression.m b/FRP/NSData+AFDecompression.m deleted file mode 100644 index b199134..0000000 --- a/FRP/NSData+AFDecompression.m +++ /dev/null @@ -1,96 +0,0 @@ -// -// NSData+AFDecompression.m -// Performance Problems Example -// -// Created by Ash Furrow on 2012-12-28. -// Copyright (c) 2012 Ash Furrow. All rights reserved. -// - -#import "NSData+AFDecompression.h" - -// Rounds numbers up to the specified multiple -NSInteger roundUp(NSInteger numToRound, NSInteger multiple) -{ - if(multiple == 0) - { - return numToRound; - } - - NSInteger remainder = numToRound % multiple; - if (remainder == 0) - { - return numToRound; - } - - return numToRound + multiple - remainder; -} - -@implementation NSData (AFDecompression) - --(void)af_decompressedImageFromJPEGDataWithCallback:(AFJPEGWasDecompressedCallback)callback -{ - uint8_t character = '\0'; - if (self.length > 0) { - [self getBytes:&character length:1]; - } - - if (character != 0xFF) - { - // This is not a valid JPEG. - callback(nil); - - return; - } - - // Creates a data provider, referencing ourself as the data. - CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((__bridge CFDataRef)self); - - // Use the data provider to get a CGImage and release the data provider. - CGImageRef image = CGImageCreateWithJPEGDataProvider(dataProvider, NULL, NO, kCGRenderingIntentDefault); - CGDataProviderRelease(dataProvider); - - // Create a bitmap context of a suitable size to draw to, forcing decode - size_t width = CGImageGetWidth(image); - size_t height = CGImageGetHeight(image); - size_t bytesPerRow = roundUp(width * 4, 16); - size_t byteCount = roundUp(height * bytesPerRow, 16); - - if (width == 0 || height == 0) - { - CGImageRelease(image); - - dispatch_async(dispatch_get_main_queue(), ^{ - callback(nil); - }); - - return; - } - - // Create the colour space and an image buffer - void *imageBuffer = malloc(byteCount); - CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB(); - - // Create the image context and release the colour space. - CGContextRef imageContext = CGBitmapContextCreate(imageBuffer, width, height, 8, bytesPerRow, colourSpace, kCGImageAlphaNone | kCGImageAlphaNoneSkipLast); - CGColorSpaceRelease(colourSpace); - - // Draw the image to the context and release it. - CGContextDrawImage(imageContext, CGRectMake(0, 0, width, height), image); - CGImageRelease(image); - - // Now get an image ref from the context. - CGImageRef outputImage = CGBitmapContextCreateImage(imageContext); - - // Clean up memory allocated by the colour space and image buffer. - CGContextRelease(imageContext); - free(imageBuffer); - - dispatch_async(dispatch_get_main_queue(), ^{ - UIImage *image = [UIImage imageWithCGImage:outputImage]; - callback(image); - // Release the output image after the callback has been completed. - CGImageRelease(outputImage); - }); -} - -@end diff --git a/Podfile b/Podfile index d071bfb..f078f26 100644 --- a/Podfile +++ b/Podfile @@ -7,7 +7,7 @@ pod 'ReactiveViewModel', '0.1.1' pod 'libextobjc', '0.3' pod '500px-iOS-api', '1.0.5' pod 'SVProgressHUD', '1.0' - +pod 'AFImageDownloader', '1.0.0' end target "FRPTests" do @@ -19,5 +19,6 @@ pod '500px-iOS-api', '1.0.5' pod 'Specta', '~> 0.2.1' pod 'Expecta', '~> 0.2' pod 'OCMock', '~> 2.2.2' +pod 'AFImageDownloader', '1.0.0' end diff --git a/Podfile.lock b/Podfile.lock index 1408c23..95e83df 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,6 +1,9 @@ PODS: - 500px-iOS-api (1.0.5) + - AFImageDownloader (1.0.0): + - Kiwi (~> 1.1.1) - Expecta (0.2.3) + - Kiwi (1.1.1) - libextobjc (0.3): - libextobjc/EXTADT - libextobjc/EXTAnnotation @@ -100,6 +103,7 @@ PODS: DEPENDENCIES: - 500px-iOS-api (= 1.0.5) + - AFImageDownloader (= 1.0.0) - Expecta (~> 0.2) - libextobjc (= 0.3) - OCMock (~> 2.2.2) @@ -110,7 +114,9 @@ DEPENDENCIES: SPEC CHECKSUMS: 500px-iOS-api: b67f7b641d79737eb26478d4e07cc1610314521c + AFImageDownloader: 4c385edcac3cea688c21b99d824ba6e73c190141 Expecta: dbc4a27fabb853bdd2e907e33f11ee43a9a47d0c + Kiwi: ab0fa8d13b97dca05915e31df9b2d888d74ab717 libextobjc: 820a79dbbbc498611e04fffd07d2d52a5588e7ac libffi: 64ef39353e747bb2b25e1026afd96a157bf9231c OCMock: ffba68873fd32cfd35d885bddad23bfa816da4a3