Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Article version

  • Loading branch information...
commit d3577ae2e30bbf7c77920aeefe69f049418a3c75 1 parent 8e430a2
@Cocoanetics authored
View
50 CocoaneticsBench.xcodeproj/project.pbxproj
@@ -18,6 +18,13 @@
A70C0CA21435A79C00CC3C72 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CA01435A79C00CC3C72 /* MainWindow.xib */; };
A70C0CA51435A79C00CC3C72 /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A70C0CA41435A79C00CC3C72 /* RootViewController.m */; };
A70C0CA81435A79C00CC3C72 /* RootViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CA61435A79C00CC3C72 /* RootViewController.xib */; };
+ A70C0CBE1435AD6600CC3C72 /* ImageBenchmark.m in Sources */ = {isa = PBXBuildFile; fileRef = A70C0CBD1435AD6600CC3C72 /* ImageBenchmark.m */; };
+ A70C0CC81435CD2500CC3C72 /* Flower_2048x1536.png in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CC31435CD2500CC3C72 /* Flower_2048x1536.png */; };
+ A70C0CC91435CD2500CC3C72 /* Flower_1024x768.png in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CC41435CD2500CC3C72 /* Flower_1024x768.png */; };
+ A70C0CCA1435CD2500CC3C72 /* Flower_128x96.png in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CC51435CD2500CC3C72 /* Flower_128x96.png */; };
+ A70C0CCB1435CD2500CC3C72 /* Flower_256x192.png in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CC61435CD2500CC3C72 /* Flower_256x192.png */; };
+ A70C0CCC1435CD2500CC3C72 /* Flower_512x384.png in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CC71435CD2500CC3C72 /* Flower_512x384.png */; };
+ A70C0CCE1435DFAA00CC3C72 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A70C0CCD1435DFAA00CC3C72 /* ImageIO.framework */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -26,17 +33,25 @@
A70C0C8B1435A79C00CC3C72 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
A70C0C8D1435A79C00CC3C72 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
A70C0C8F1435A79C00CC3C72 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
- A70C0C931435A79C00CC3C72 /* CocoaneticsBench-Info.plist */ = {isa = PBXFileReference; path = "CocoaneticsBench-Info.plist"; sourceTree = "<group>"; };
+ A70C0C931435A79C00CC3C72 /* CocoaneticsBench-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CocoaneticsBench-Info.plist"; sourceTree = "<group>"; };
A70C0C951435A79C00CC3C72 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
A70C0C971435A79C00CC3C72 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
- A70C0C991435A79C00CC3C72 /* CocoaneticsBench-Prefix.pch */ = {isa = PBXFileReference; path = "CocoaneticsBench-Prefix.pch"; sourceTree = "<group>"; };
- A70C0C9A1435A79C00CC3C72 /* CocoaneticsBenchAppDelegate.h */ = {isa = PBXFileReference; path = CocoaneticsBenchAppDelegate.h; sourceTree = "<group>"; };
+ A70C0C991435A79C00CC3C72 /* CocoaneticsBench-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CocoaneticsBench-Prefix.pch"; sourceTree = "<group>"; };
+ A70C0C9A1435A79C00CC3C72 /* CocoaneticsBenchAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CocoaneticsBenchAppDelegate.h; sourceTree = "<group>"; };
A70C0C9B1435A79C00CC3C72 /* CocoaneticsBenchAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CocoaneticsBenchAppDelegate.m; sourceTree = "<group>"; };
A70C0C9E1435A79C00CC3C72 /* CocoaneticsBench.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = CocoaneticsBench.xcdatamodel; sourceTree = "<group>"; };
A70C0CA11435A79C00CC3C72 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainWindow.xib; sourceTree = "<group>"; };
- A70C0CA31435A79C00CC3C72 /* RootViewController.h */ = {isa = PBXFileReference; path = RootViewController.h; sourceTree = "<group>"; };
+ A70C0CA31435A79C00CC3C72 /* RootViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RootViewController.h; sourceTree = "<group>"; };
A70C0CA41435A79C00CC3C72 /* RootViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RootViewController.m; sourceTree = "<group>"; };
A70C0CA71435A79C00CC3C72 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/RootViewController.xib; sourceTree = "<group>"; };
+ A70C0CBC1435AD6600CC3C72 /* ImageBenchmark.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageBenchmark.h; sourceTree = "<group>"; };
+ A70C0CBD1435AD6600CC3C72 /* ImageBenchmark.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageBenchmark.m; sourceTree = "<group>"; };
+ A70C0CC31435CD2500CC3C72 /* Flower_2048x1536.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Flower_2048x1536.png; sourceTree = "<group>"; };
+ A70C0CC41435CD2500CC3C72 /* Flower_1024x768.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Flower_1024x768.png; sourceTree = "<group>"; };
+ A70C0CC51435CD2500CC3C72 /* Flower_128x96.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Flower_128x96.png; sourceTree = "<group>"; };
+ A70C0CC61435CD2500CC3C72 /* Flower_256x192.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Flower_256x192.png; sourceTree = "<group>"; };
+ A70C0CC71435CD2500CC3C72 /* Flower_512x384.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Flower_512x384.png; sourceTree = "<group>"; };
+ A70C0CCD1435DFAA00CC3C72 /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -44,6 +59,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ A70C0CCE1435DFAA00CC3C72 /* ImageIO.framework in Frameworks */,
A70C0C8A1435A79C00CC3C72 /* UIKit.framework in Frameworks */,
A70C0C8C1435A79C00CC3C72 /* Foundation.framework in Frameworks */,
A70C0C8E1435A79C00CC3C72 /* CoreGraphics.framework in Frameworks */,
@@ -57,6 +73,7 @@
A70C0C7A1435A79C00CC3C72 = {
isa = PBXGroup;
children = (
+ A70C0CCD1435DFAA00CC3C72 /* ImageIO.framework */,
A70C0C911435A79C00CC3C72 /* CocoaneticsBench */,
A70C0C881435A79C00CC3C72 /* Frameworks */,
A70C0C861435A79C00CC3C72 /* Products */,
@@ -93,6 +110,8 @@
A70C0CA61435A79C00CC3C72 /* RootViewController.xib */,
A70C0C9D1435A79C00CC3C72 /* CocoaneticsBench.xcdatamodeld */,
A70C0C921435A79C00CC3C72 /* Supporting Files */,
+ A70C0CBC1435AD6600CC3C72 /* ImageBenchmark.h */,
+ A70C0CBD1435AD6600CC3C72 /* ImageBenchmark.m */,
);
path = CocoaneticsBench;
sourceTree = "<group>";
@@ -100,6 +119,7 @@
A70C0C921435A79C00CC3C72 /* Supporting Files */ = {
isa = PBXGroup;
children = (
+ A70C0CAE1435AAFE00CC3C72 /* Images */,
A70C0C931435A79C00CC3C72 /* CocoaneticsBench-Info.plist */,
A70C0C941435A79C00CC3C72 /* InfoPlist.strings */,
A70C0C971435A79C00CC3C72 /* main.m */,
@@ -108,6 +128,18 @@
name = "Supporting Files";
sourceTree = "<group>";
};
+ A70C0CAE1435AAFE00CC3C72 /* Images */ = {
+ isa = PBXGroup;
+ children = (
+ A70C0CC31435CD2500CC3C72 /* Flower_2048x1536.png */,
+ A70C0CC41435CD2500CC3C72 /* Flower_1024x768.png */,
+ A70C0CC51435CD2500CC3C72 /* Flower_128x96.png */,
+ A70C0CC61435CD2500CC3C72 /* Flower_256x192.png */,
+ A70C0CC71435CD2500CC3C72 /* Flower_512x384.png */,
+ );
+ name = Images;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -134,6 +166,7 @@
A70C0C7C1435A79C00CC3C72 /* Project object */ = {
isa = PBXProject;
attributes = {
+ LastUpgradeCheck = 0420;
ORGANIZATIONNAME = Cocoanetics;
};
buildConfigurationList = A70C0C7F1435A79C00CC3C72 /* Build configuration list for PBXProject "CocoaneticsBench" */;
@@ -161,6 +194,11 @@
A70C0C961435A79C00CC3C72 /* InfoPlist.strings in Resources */,
A70C0CA21435A79C00CC3C72 /* MainWindow.xib in Resources */,
A70C0CA81435A79C00CC3C72 /* RootViewController.xib in Resources */,
+ A70C0CC81435CD2500CC3C72 /* Flower_2048x1536.png in Resources */,
+ A70C0CC91435CD2500CC3C72 /* Flower_1024x768.png in Resources */,
+ A70C0CCA1435CD2500CC3C72 /* Flower_128x96.png in Resources */,
+ A70C0CCB1435CD2500CC3C72 /* Flower_256x192.png in Resources */,
+ A70C0CCC1435CD2500CC3C72 /* Flower_512x384.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -175,6 +213,7 @@
A70C0C9C1435A79C00CC3C72 /* CocoaneticsBenchAppDelegate.m in Sources */,
A70C0C9F1435A79C00CC3C72 /* CocoaneticsBench.xcdatamodeld in Sources */,
A70C0CA51435A79C00CC3C72 /* RootViewController.m in Sources */,
+ A70C0CBE1435AD6600CC3C72 /* ImageBenchmark.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -257,6 +296,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "CocoaneticsBench/CocoaneticsBench-Prefix.pch";
INFOPLIST_FILE = "CocoaneticsBench/CocoaneticsBench-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
@@ -268,6 +308,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "CocoaneticsBench/CocoaneticsBench-Prefix.pch";
INFOPLIST_FILE = "CocoaneticsBench/CocoaneticsBench-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
@@ -292,6 +333,7 @@
A70C0CAD1435A79C00CC3C72 /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
View
12 CocoaneticsBench/CocoaneticsBench.xcdatamodeld/CocoaneticsBench.xcdatamodel/contents
@@ -1,9 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<model name="Test1.xcdatamodel" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1" systemVersion="11A491" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
+<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="562" systemVersion="11C48" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="Event">
+ <attribute name="deviceModel" optional="YES" attributeType="String"/>
+ <attribute name="durationDecompress" optional="YES" attributeType="Double" defaultValueString="0.0"/>
+ <attribute name="durationInitImage" optional="YES" attributeType="Double" defaultValueString="0.0"/>
+ <attribute name="imageCompressionFactor" optional="YES" attributeType="Float" defaultValueString="0.0"/>
+ <attribute name="imageFileFormat" optional="YES" attributeType="String"/>
+ <attribute name="imageHeight" optional="YES" attributeType="Float" defaultValueString="0.0"/>
+ <attribute name="imageWidth" optional="YES" attributeType="Float" defaultValueString="0.0"/>
+ <attribute name="osVersion" optional="YES" attributeType="String"/>
<attribute name="timeStamp" optional="YES" attributeType="Date"/>
</entity>
<elements>
- <element name="Event" positionX="261" positionY="189" width="128" height="60"/>
+ <element name="Event" positionX="261" positionY="189" width="128" height="180"/>
</elements>
</model>
View
98 CocoaneticsBench/CocoaneticsBenchAppDelegate.m
@@ -9,6 +9,8 @@
#import "CocoaneticsBenchAppDelegate.h"
#import "RootViewController.h"
+#import "ImageBenchmark.h"
+
@implementation CocoaneticsBenchAppDelegate
@@ -20,6 +22,102 @@ @implementation CocoaneticsBenchAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
+ //ImageBenchmark *i ;
+
+ ImageBenchmark *i = [[[ImageBenchmark alloc] initWithCrushedPNGNamed:@"Flower_128x96"] autorelease];
+ [i prepareAsCrushedPNG];
+ [i run];
+ NSLog(@"%@", i);
+
+ [i prepareAsUncrushedPNG];
+ [i run];
+ NSLog(@"%@", i);
+
+
+ for (int j=10; j <= 100; j+=10)
+ {
+ [i prepareAsJPEGSourceWithQuality:j/100.0];
+ [i run];
+ NSLog(@"%@", i);
+ }
+
+
+ i = [[[ImageBenchmark alloc] initWithCrushedPNGNamed:@"Flower_256x192"] autorelease];
+ [i prepareAsCrushedPNG];
+
+ [i run];
+ NSLog(@"%@", i);
+
+ [i prepareAsUncrushedPNG];
+ [i run];
+ NSLog(@"%@", i);
+
+
+ for (int j=10; j <= 100; j+=10)
+ {
+ [i prepareAsJPEGSourceWithQuality:j/100.0];
+ [i run];
+ NSLog(@"%@", i);
+ }
+
+
+ i = [[[ImageBenchmark alloc] initWithCrushedPNGNamed:@"Flower_512x384"] autorelease];
+ [i prepareAsCrushedPNG];
+
+ [i run];
+ NSLog(@"%@", i);
+
+ [i prepareAsUncrushedPNG];
+ [i run];
+ NSLog(@"%@", i);
+
+
+ for (int j=10; j <= 100; j+=10)
+ {
+ [i prepareAsJPEGSourceWithQuality:j/100.0];
+ [i run];
+ NSLog(@"%@", i);
+ }
+
+ i = [[[ImageBenchmark alloc] initWithCrushedPNGNamed:@"Flower_1024x768"] autorelease];
+ [i prepareAsCrushedPNG];
+
+ [i run];
+ NSLog(@"%@", i);
+
+ [i prepareAsUncrushedPNG];
+ [i run];
+ NSLog(@"%@", i);
+
+
+ for (int j=10; j <= 100; j+=10)
+ {
+ [i prepareAsJPEGSourceWithQuality:j/100.0];
+ [i run];
+ NSLog(@"%@", i);
+ }
+
+
+
+ i = [[[ImageBenchmark alloc] initWithCrushedPNGNamed:@"Flower_2048x1536"] autorelease];
+ [i prepareAsCrushedPNG];
+
+ [i run];
+ NSLog(@"%@", i);
+
+ [i prepareAsUncrushedPNG];
+ [i run];
+ NSLog(@"%@", i);
+
+
+ for (int j=10; j <= 100; j+=10)
+ {
+ [i prepareAsJPEGSourceWithQuality:j/100.0];
+ [i run];
+ NSLog(@"%@", i);
+ }
+
+
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
self.window.rootViewController = self.navigationController;
View
BIN  CocoaneticsBench/Flower_1024x768.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  CocoaneticsBench/Flower_128x96.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  CocoaneticsBench/Flower_2048x1536.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  CocoaneticsBench/Flower_256x192.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  CocoaneticsBench/Flower_512x384.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
39 CocoaneticsBench/ImageBenchmark.h
@@ -0,0 +1,39 @@
+//
+// ImageBenchmark.h
+// CocoaneticsBench
+//
+// Created by Oliver Drobnik on 9/30/11.
+// Copyright 2011 Cocoanetics. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface ImageBenchmark : NSObject
+{
+ NSString *_imageName;
+ NSString *_path;
+ NSString *_internalOverrideSourcePath;
+
+ CGFloat _quality;
+ NSString *_mode;
+
+
+ NSTimeInterval _timeForInit;
+ NSTimeInterval _timeForDecompress;
+ NSTimeInterval _timeForDraw;
+
+ BOOL _didRun;
+}
+
+- (id)initWithCrushedPNGNamed:(NSString *)imageName;
+
+- (void)prepareAsCrushedPNG;
+- (void)prepareAsUncrushedPNG;
+- (void)prepareAsJPEGSourceWithQuality:(CGFloat)quality;
+
+
+- (void)run;
+
+@end
+
+CGContextRef newBitmapContextSuitableForSize(CGSize size);
View
283 CocoaneticsBench/ImageBenchmark.m
@@ -0,0 +1,283 @@
+//
+// ImageBenchmark.m
+// CocoaneticsBench
+//
+// Created by Oliver Drobnik on 9/30/11.
+// Copyright 2011 Cocoanetics. All rights reserved.
+//
+
+#import "ImageBenchmark.h"
+
+#import <ImageIO/ImageIO.h>
+
+CGContextRef newBitmapContextSuitableForSize(CGSize size)
+{
+ int pixelsWide = size.width;
+ int pixelsHigh = size.height;
+ CGContextRef context = NULL;
+ CGColorSpaceRef colorSpace;
+ // void * bitmapData;
+ // int bitmapByteCount;
+ int bitmapBytesPerRow;
+
+ bitmapBytesPerRow = (pixelsWide * 4); //4
+ // bitmapByteCount = (bitmapBytesPerRow * pixelsHigh);
+
+
+
+ /* bitmapData = malloc( bitmapByteCount );
+
+ memset(bitmapData, 0, bitmapByteCount); // set memory to black, alpha 0
+
+ if (bitmapData == NULL)
+ {
+ return NULL;
+ }
+ */
+ colorSpace = CGColorSpaceCreateDeviceRGB();
+
+
+ context = CGBitmapContextCreate ( NULL, //bitmapData, // let the device handle the memory
+ pixelsWide,
+ pixelsHigh,
+ 8, // bits per component
+ bitmapBytesPerRow,
+ colorSpace,
+ kCGImageAlphaPremultipliedFirst);
+ CGColorSpaceRelease( colorSpace );
+
+
+ if (context== NULL)
+ {
+ // free (bitmapData);
+ return NULL;
+ }
+
+ return context;
+}
+
+
+@implementation ImageBenchmark
+
+- (id)initWithCrushedPNGNamed:(NSString *)imageName
+{
+ self = [super init];
+ if (self)
+ {
+ _path = [[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"] copy];
+ _imageName = [imageName copy];
+ }
+
+ return self;
+}
+
+- (void)dealloc
+{
+ [_path release];
+ [_imageName release];
+ [_internalOverrideSourcePath release];
+
+ [super dealloc];
+}
+
+
+- (NSString *)description
+{
+ NSString *fileName = [_path lastPathComponent];
+
+ if (_didRun)
+ {
+ NSString *benchmarkModeString = nil;
+
+ if (!_mode)
+ {
+ benchmarkModeString = @"Crushed PNG";
+ }
+ else if ([_mode isEqualToString:@"JPG"])
+ {
+ benchmarkModeString = [NSString stringWithFormat:@"JPG %.0f%%", _quality*100.0];
+ }
+ else if ([_mode isEqualToString:@"PNG"])
+ {
+ benchmarkModeString = [NSString stringWithFormat:@"PNG", _quality*100.0];
+ }
+
+ return [NSString stringWithFormat:@"%@ (%@) init: %.0f ms decompress: %.0f ms draw: %.0f ms total %.0f ms", fileName, benchmarkModeString, _timeForInit*1000.0, _timeForDecompress*1000.0, _timeForDraw*1000.0, (_timeForInit + _timeForDecompress + _timeForDraw) * 1000.0];
+ }
+ else
+ {
+ return [NSString stringWithFormat:@"%@ not run", fileName];
+ }
+}
+
+- (void)prepareAsCrushedPNG
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSString *fileName = [[[_path lastPathComponent] stringByDeletingPathExtension] stringByAppendingPathExtension:@"crushed.png"];
+
+ NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
+ NSString *cacheImagePath = [cachesPath stringByAppendingPathComponent:fileName];
+
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+
+ if (![fileManager fileExistsAtPath:cacheImagePath])
+ {
+ [fileManager copyItemAtPath:_path toPath:cacheImagePath error:NULL];
+ }
+
+ [_internalOverrideSourcePath release];
+ _internalOverrideSourcePath = [cacheImagePath copy];
+
+ [_mode release];
+ _mode = nil;
+ _quality = 0;
+
+ [pool drain];
+
+}
+
+- (void)prepareAsUncrushedPNG
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSString *fileName = [[[_path lastPathComponent] stringByDeletingPathExtension] stringByAppendingPathExtension:@"uncrushed.png"];
+
+ NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
+ NSString *cacheImagePath = [cachesPath stringByAppendingPathComponent:fileName];
+
+
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+
+ if (![fileManager fileExistsAtPath:cacheImagePath])
+ {
+ UIImage *image = [UIImage imageWithContentsOfFile:_path];
+ UIGraphicsBeginImageContext(image.size);
+
+ [image drawAtPoint:CGPointZero];
+
+ UIImage *rawImage = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+
+ NSData *imageData = UIImagePNGRepresentation(rawImage);
+
+
+ [imageData writeToFile:cacheImagePath atomically:NO];
+ }
+
+ [_internalOverrideSourcePath release];
+ _internalOverrideSourcePath = [cacheImagePath copy];
+
+ [_mode release];
+ _mode = @"PNG";
+ _quality = 0;
+
+ [pool drain];
+}
+
+- (void)prepareAsJPEGSourceWithQuality:(CGFloat)quality
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSString *fileName = [[[_path lastPathComponent] stringByDeletingPathExtension] stringByAppendingPathExtension:[NSString stringWithFormat:@"%.0f.jpg", quality*100.0]];
+
+ NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
+ NSString *cacheImagePath = [cachesPath stringByAppendingPathComponent:fileName];
+
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+
+ if (![fileManager fileExistsAtPath:cacheImagePath])
+ {
+ UIImage *image = [UIImage imageWithContentsOfFile:_path];
+ UIGraphicsBeginImageContext(image.size);
+
+ [image drawAtPoint:CGPointZero];
+
+ UIImage *rawImage = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+
+ NSData *imageData = UIImageJPEGRepresentation(rawImage, quality);
+
+
+ [imageData writeToFile:cacheImagePath atomically:NO];
+ }
+
+ [_internalOverrideSourcePath release];
+ _internalOverrideSourcePath = [cacheImagePath copy];
+
+ [_mode release];
+ _mode = @"JPG";
+ _quality = quality;
+
+ [pool drain];
+}
+
+- (void)decompressImage:(UIImage *)image
+{
+ UIGraphicsBeginImageContext(CGSizeMake(1, 1));
+
+ [image drawAtPoint:CGPointZero];
+
+ UIGraphicsEndImageContext();
+}
+
+- (void)drawImage:(UIImage *)image
+{
+ CGContextRef context = newBitmapContextSuitableForSize(image.size);
+ CGContextSetShouldAntialias(context, NO);
+ CGContextSetInterpolationQuality(context, kCGInterpolationNone);
+ CGContextSetBlendMode(context, kCGBlendModeCopy);
+
+ CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
+
+ CGContextRelease(context);
+}
+
+- (UIImage *)sourceImage
+{
+// if (!_mode)
+// {
+// return [UIImage imageNamed:_imageName];
+// }
+
+ NSURL *url = [NSURL fileURLWithPath:_internalOverrideSourcePath?_internalOverrideSourcePath:_path];
+ NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:(id)kCGImageSourceShouldCache];
+
+ CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)url, (CFDictionaryRef)nil);
+ CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, 0, (CFDictionaryRef)dict);
+
+ UIImage *retImage = [UIImage imageWithCGImage:cgImage];
+ CGImageRelease(cgImage);
+ CFRelease(source);
+
+ return retImage;
+// return [UIImage imageWithContentsOfFile:_internalOverrideSourcePath?_internalOverrideSourcePath:_path];
+}
+
+- (void)run
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSDate *before = [NSDate date];
+ UIImage *image = [self sourceImage];
+ NSDate *after = [NSDate date];
+ _timeForInit = [after timeIntervalSinceDate:before];
+
+
+ before = [NSDate date];
+ [self decompressImage:image];
+ after = [NSDate date];
+ _timeForDecompress = [after timeIntervalSinceDate:before];
+
+ before = [NSDate date];
+ [self drawImage:image];
+ after = [NSDate date];
+ _timeForDraw = [after timeIntervalSinceDate:before];
+
+ _didRun = YES;
+
+ [pool drain];
+}
+
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.