Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Article version

  • Loading branch information...
commit d3577ae2e30bbf7c77920aeefe69f049418a3c75 1 parent 8e430a2
Oliver Drobnik authored
50 CocoaneticsBench.xcodeproj/project.pbxproj
@@ -18,6 +18,13 @@
18 18 A70C0CA21435A79C00CC3C72 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CA01435A79C00CC3C72 /* MainWindow.xib */; };
19 19 A70C0CA51435A79C00CC3C72 /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A70C0CA41435A79C00CC3C72 /* RootViewController.m */; };
20 20 A70C0CA81435A79C00CC3C72 /* RootViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CA61435A79C00CC3C72 /* RootViewController.xib */; };
  21 + A70C0CBE1435AD6600CC3C72 /* ImageBenchmark.m in Sources */ = {isa = PBXBuildFile; fileRef = A70C0CBD1435AD6600CC3C72 /* ImageBenchmark.m */; };
  22 + A70C0CC81435CD2500CC3C72 /* Flower_2048x1536.png in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CC31435CD2500CC3C72 /* Flower_2048x1536.png */; };
  23 + A70C0CC91435CD2500CC3C72 /* Flower_1024x768.png in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CC41435CD2500CC3C72 /* Flower_1024x768.png */; };
  24 + A70C0CCA1435CD2500CC3C72 /* Flower_128x96.png in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CC51435CD2500CC3C72 /* Flower_128x96.png */; };
  25 + A70C0CCB1435CD2500CC3C72 /* Flower_256x192.png in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CC61435CD2500CC3C72 /* Flower_256x192.png */; };
  26 + A70C0CCC1435CD2500CC3C72 /* Flower_512x384.png in Resources */ = {isa = PBXBuildFile; fileRef = A70C0CC71435CD2500CC3C72 /* Flower_512x384.png */; };
  27 + A70C0CCE1435DFAA00CC3C72 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A70C0CCD1435DFAA00CC3C72 /* ImageIO.framework */; };
21 28 /* End PBXBuildFile section */
22 29
23 30 /* Begin PBXFileReference section */
@@ -26,17 +33,25 @@
26 33 A70C0C8B1435A79C00CC3C72 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
27 34 A70C0C8D1435A79C00CC3C72 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
28 35 A70C0C8F1435A79C00CC3C72 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
29   - A70C0C931435A79C00CC3C72 /* CocoaneticsBench-Info.plist */ = {isa = PBXFileReference; path = "CocoaneticsBench-Info.plist"; sourceTree = "<group>"; };
  36 + A70C0C931435A79C00CC3C72 /* CocoaneticsBench-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CocoaneticsBench-Info.plist"; sourceTree = "<group>"; };
30 37 A70C0C951435A79C00CC3C72 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
31 38 A70C0C971435A79C00CC3C72 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32   - A70C0C991435A79C00CC3C72 /* CocoaneticsBench-Prefix.pch */ = {isa = PBXFileReference; path = "CocoaneticsBench-Prefix.pch"; sourceTree = "<group>"; };
33   - A70C0C9A1435A79C00CC3C72 /* CocoaneticsBenchAppDelegate.h */ = {isa = PBXFileReference; path = CocoaneticsBenchAppDelegate.h; sourceTree = "<group>"; };
  39 + A70C0C991435A79C00CC3C72 /* CocoaneticsBench-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CocoaneticsBench-Prefix.pch"; sourceTree = "<group>"; };
  40 + A70C0C9A1435A79C00CC3C72 /* CocoaneticsBenchAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CocoaneticsBenchAppDelegate.h; sourceTree = "<group>"; };
34 41 A70C0C9B1435A79C00CC3C72 /* CocoaneticsBenchAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CocoaneticsBenchAppDelegate.m; sourceTree = "<group>"; };
35 42 A70C0C9E1435A79C00CC3C72 /* CocoaneticsBench.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = CocoaneticsBench.xcdatamodel; sourceTree = "<group>"; };
36 43 A70C0CA11435A79C00CC3C72 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainWindow.xib; sourceTree = "<group>"; };
37   - A70C0CA31435A79C00CC3C72 /* RootViewController.h */ = {isa = PBXFileReference; path = RootViewController.h; sourceTree = "<group>"; };
  44 + A70C0CA31435A79C00CC3C72 /* RootViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RootViewController.h; sourceTree = "<group>"; };
38 45 A70C0CA41435A79C00CC3C72 /* RootViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RootViewController.m; sourceTree = "<group>"; };
39 46 A70C0CA71435A79C00CC3C72 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/RootViewController.xib; sourceTree = "<group>"; };
  47 + A70C0CBC1435AD6600CC3C72 /* ImageBenchmark.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageBenchmark.h; sourceTree = "<group>"; };
  48 + A70C0CBD1435AD6600CC3C72 /* ImageBenchmark.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageBenchmark.m; sourceTree = "<group>"; };
  49 + A70C0CC31435CD2500CC3C72 /* Flower_2048x1536.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Flower_2048x1536.png; sourceTree = "<group>"; };
  50 + A70C0CC41435CD2500CC3C72 /* Flower_1024x768.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Flower_1024x768.png; sourceTree = "<group>"; };
  51 + A70C0CC51435CD2500CC3C72 /* Flower_128x96.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Flower_128x96.png; sourceTree = "<group>"; };
  52 + A70C0CC61435CD2500CC3C72 /* Flower_256x192.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Flower_256x192.png; sourceTree = "<group>"; };
  53 + A70C0CC71435CD2500CC3C72 /* Flower_512x384.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Flower_512x384.png; sourceTree = "<group>"; };
  54 + A70C0CCD1435DFAA00CC3C72 /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; };
40 55 /* End PBXFileReference section */
41 56
42 57 /* Begin PBXFrameworksBuildPhase section */
@@ -44,6 +59,7 @@
44 59 isa = PBXFrameworksBuildPhase;
45 60 buildActionMask = 2147483647;
46 61 files = (
  62 + A70C0CCE1435DFAA00CC3C72 /* ImageIO.framework in Frameworks */,
47 63 A70C0C8A1435A79C00CC3C72 /* UIKit.framework in Frameworks */,
48 64 A70C0C8C1435A79C00CC3C72 /* Foundation.framework in Frameworks */,
49 65 A70C0C8E1435A79C00CC3C72 /* CoreGraphics.framework in Frameworks */,
@@ -57,6 +73,7 @@
57 73 A70C0C7A1435A79C00CC3C72 = {
58 74 isa = PBXGroup;
59 75 children = (
  76 + A70C0CCD1435DFAA00CC3C72 /* ImageIO.framework */,
60 77 A70C0C911435A79C00CC3C72 /* CocoaneticsBench */,
61 78 A70C0C881435A79C00CC3C72 /* Frameworks */,
62 79 A70C0C861435A79C00CC3C72 /* Products */,
@@ -93,6 +110,8 @@
93 110 A70C0CA61435A79C00CC3C72 /* RootViewController.xib */,
94 111 A70C0C9D1435A79C00CC3C72 /* CocoaneticsBench.xcdatamodeld */,
95 112 A70C0C921435A79C00CC3C72 /* Supporting Files */,
  113 + A70C0CBC1435AD6600CC3C72 /* ImageBenchmark.h */,
  114 + A70C0CBD1435AD6600CC3C72 /* ImageBenchmark.m */,
96 115 );
97 116 path = CocoaneticsBench;
98 117 sourceTree = "<group>";
@@ -100,6 +119,7 @@
100 119 A70C0C921435A79C00CC3C72 /* Supporting Files */ = {
101 120 isa = PBXGroup;
102 121 children = (
  122 + A70C0CAE1435AAFE00CC3C72 /* Images */,
103 123 A70C0C931435A79C00CC3C72 /* CocoaneticsBench-Info.plist */,
104 124 A70C0C941435A79C00CC3C72 /* InfoPlist.strings */,
105 125 A70C0C971435A79C00CC3C72 /* main.m */,
@@ -108,6 +128,18 @@
108 128 name = "Supporting Files";
109 129 sourceTree = "<group>";
110 130 };
  131 + A70C0CAE1435AAFE00CC3C72 /* Images */ = {
  132 + isa = PBXGroup;
  133 + children = (
  134 + A70C0CC31435CD2500CC3C72 /* Flower_2048x1536.png */,
  135 + A70C0CC41435CD2500CC3C72 /* Flower_1024x768.png */,
  136 + A70C0CC51435CD2500CC3C72 /* Flower_128x96.png */,
  137 + A70C0CC61435CD2500CC3C72 /* Flower_256x192.png */,
  138 + A70C0CC71435CD2500CC3C72 /* Flower_512x384.png */,
  139 + );
  140 + name = Images;
  141 + sourceTree = "<group>";
  142 + };
111 143 /* End PBXGroup section */
112 144
113 145 /* Begin PBXNativeTarget section */
@@ -134,6 +166,7 @@
134 166 A70C0C7C1435A79C00CC3C72 /* Project object */ = {
135 167 isa = PBXProject;
136 168 attributes = {
  169 + LastUpgradeCheck = 0420;
137 170 ORGANIZATIONNAME = Cocoanetics;
138 171 };
139 172 buildConfigurationList = A70C0C7F1435A79C00CC3C72 /* Build configuration list for PBXProject "CocoaneticsBench" */;
@@ -161,6 +194,11 @@
161 194 A70C0C961435A79C00CC3C72 /* InfoPlist.strings in Resources */,
162 195 A70C0CA21435A79C00CC3C72 /* MainWindow.xib in Resources */,
163 196 A70C0CA81435A79C00CC3C72 /* RootViewController.xib in Resources */,
  197 + A70C0CC81435CD2500CC3C72 /* Flower_2048x1536.png in Resources */,
  198 + A70C0CC91435CD2500CC3C72 /* Flower_1024x768.png in Resources */,
  199 + A70C0CCA1435CD2500CC3C72 /* Flower_128x96.png in Resources */,
  200 + A70C0CCB1435CD2500CC3C72 /* Flower_256x192.png in Resources */,
  201 + A70C0CCC1435CD2500CC3C72 /* Flower_512x384.png in Resources */,
164 202 );
165 203 runOnlyForDeploymentPostprocessing = 0;
166 204 };
@@ -175,6 +213,7 @@
175 213 A70C0C9C1435A79C00CC3C72 /* CocoaneticsBenchAppDelegate.m in Sources */,
176 214 A70C0C9F1435A79C00CC3C72 /* CocoaneticsBench.xcdatamodeld in Sources */,
177 215 A70C0CA51435A79C00CC3C72 /* RootViewController.m in Sources */,
  216 + A70C0CBE1435AD6600CC3C72 /* ImageBenchmark.m in Sources */,
178 217 );
179 218 runOnlyForDeploymentPostprocessing = 0;
180 219 };
@@ -257,6 +296,7 @@
257 296 GCC_PRECOMPILE_PREFIX_HEADER = YES;
258 297 GCC_PREFIX_HEADER = "CocoaneticsBench/CocoaneticsBench-Prefix.pch";
259 298 INFOPLIST_FILE = "CocoaneticsBench/CocoaneticsBench-Info.plist";
  299 + IPHONEOS_DEPLOYMENT_TARGET = 4.0;
260 300 PRODUCT_NAME = "$(TARGET_NAME)";
261 301 WRAPPER_EXTENSION = app;
262 302 };
@@ -268,6 +308,7 @@
268 308 GCC_PRECOMPILE_PREFIX_HEADER = YES;
269 309 GCC_PREFIX_HEADER = "CocoaneticsBench/CocoaneticsBench-Prefix.pch";
270 310 INFOPLIST_FILE = "CocoaneticsBench/CocoaneticsBench-Info.plist";
  311 + IPHONEOS_DEPLOYMENT_TARGET = 4.0;
271 312 PRODUCT_NAME = "$(TARGET_NAME)";
272 313 WRAPPER_EXTENSION = app;
273 314 };
@@ -292,6 +333,7 @@
292 333 A70C0CAD1435A79C00CC3C72 /* Release */,
293 334 );
294 335 defaultConfigurationIsVisible = 0;
  336 + defaultConfigurationName = Release;
295 337 };
296 338 /* End XCConfigurationList section */
297 339
12 CocoaneticsBench/CocoaneticsBench.xcdatamodeld/CocoaneticsBench.xcdatamodel/contents
... ... @@ -1,9 +1,17 @@
1 1 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2   -<model name="Test1.xcdatamodel" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1" systemVersion="11A491" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
  2 +<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="562" systemVersion="11C48" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
3 3 <entity name="Event">
  4 + <attribute name="deviceModel" optional="YES" attributeType="String"/>
  5 + <attribute name="durationDecompress" optional="YES" attributeType="Double" defaultValueString="0.0"/>
  6 + <attribute name="durationInitImage" optional="YES" attributeType="Double" defaultValueString="0.0"/>
  7 + <attribute name="imageCompressionFactor" optional="YES" attributeType="Float" defaultValueString="0.0"/>
  8 + <attribute name="imageFileFormat" optional="YES" attributeType="String"/>
  9 + <attribute name="imageHeight" optional="YES" attributeType="Float" defaultValueString="0.0"/>
  10 + <attribute name="imageWidth" optional="YES" attributeType="Float" defaultValueString="0.0"/>
  11 + <attribute name="osVersion" optional="YES" attributeType="String"/>
4 12 <attribute name="timeStamp" optional="YES" attributeType="Date"/>
5 13 </entity>
6 14 <elements>
7   - <element name="Event" positionX="261" positionY="189" width="128" height="60"/>
  15 + <element name="Event" positionX="261" positionY="189" width="128" height="180"/>
8 16 </elements>
9 17 </model>
98 CocoaneticsBench/CocoaneticsBenchAppDelegate.m
@@ -9,6 +9,8 @@
9 9 #import "CocoaneticsBenchAppDelegate.h"
10 10
11 11 #import "RootViewController.h"
  12 +#import "ImageBenchmark.h"
  13 +
12 14
13 15 @implementation CocoaneticsBenchAppDelegate
14 16
@@ -20,6 +22,102 @@ @implementation CocoaneticsBenchAppDelegate
20 22
21 23 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
22 24 {
  25 + //ImageBenchmark *i ;
  26 +
  27 + ImageBenchmark *i = [[[ImageBenchmark alloc] initWithCrushedPNGNamed:@"Flower_128x96"] autorelease];
  28 + [i prepareAsCrushedPNG];
  29 + [i run];
  30 + NSLog(@"%@", i);
  31 +
  32 + [i prepareAsUncrushedPNG];
  33 + [i run];
  34 + NSLog(@"%@", i);
  35 +
  36 +
  37 + for (int j=10; j <= 100; j+=10)
  38 + {
  39 + [i prepareAsJPEGSourceWithQuality:j/100.0];
  40 + [i run];
  41 + NSLog(@"%@", i);
  42 + }
  43 +
  44 +
  45 + i = [[[ImageBenchmark alloc] initWithCrushedPNGNamed:@"Flower_256x192"] autorelease];
  46 + [i prepareAsCrushedPNG];
  47 +
  48 + [i run];
  49 + NSLog(@"%@", i);
  50 +
  51 + [i prepareAsUncrushedPNG];
  52 + [i run];
  53 + NSLog(@"%@", i);
  54 +
  55 +
  56 + for (int j=10; j <= 100; j+=10)
  57 + {
  58 + [i prepareAsJPEGSourceWithQuality:j/100.0];
  59 + [i run];
  60 + NSLog(@"%@", i);
  61 + }
  62 +
  63 +
  64 + i = [[[ImageBenchmark alloc] initWithCrushedPNGNamed:@"Flower_512x384"] autorelease];
  65 + [i prepareAsCrushedPNG];
  66 +
  67 + [i run];
  68 + NSLog(@"%@", i);
  69 +
  70 + [i prepareAsUncrushedPNG];
  71 + [i run];
  72 + NSLog(@"%@", i);
  73 +
  74 +
  75 + for (int j=10; j <= 100; j+=10)
  76 + {
  77 + [i prepareAsJPEGSourceWithQuality:j/100.0];
  78 + [i run];
  79 + NSLog(@"%@", i);
  80 + }
  81 +
  82 + i = [[[ImageBenchmark alloc] initWithCrushedPNGNamed:@"Flower_1024x768"] autorelease];
  83 + [i prepareAsCrushedPNG];
  84 +
  85 + [i run];
  86 + NSLog(@"%@", i);
  87 +
  88 + [i prepareAsUncrushedPNG];
  89 + [i run];
  90 + NSLog(@"%@", i);
  91 +
  92 +
  93 + for (int j=10; j <= 100; j+=10)
  94 + {
  95 + [i prepareAsJPEGSourceWithQuality:j/100.0];
  96 + [i run];
  97 + NSLog(@"%@", i);
  98 + }
  99 +
  100 +
  101 +
  102 + i = [[[ImageBenchmark alloc] initWithCrushedPNGNamed:@"Flower_2048x1536"] autorelease];
  103 + [i prepareAsCrushedPNG];
  104 +
  105 + [i run];
  106 + NSLog(@"%@", i);
  107 +
  108 + [i prepareAsUncrushedPNG];
  109 + [i run];
  110 + NSLog(@"%@", i);
  111 +
  112 +
  113 + for (int j=10; j <= 100; j+=10)
  114 + {
  115 + [i prepareAsJPEGSourceWithQuality:j/100.0];
  116 + [i run];
  117 + NSLog(@"%@", i);
  118 + }
  119 +
  120 +
23 121 // Override point for customization after application launch.
24 122 // Add the navigation controller's view to the window and display.
25 123 self.window.rootViewController = self.navigationController;
BIN  CocoaneticsBench/Flower_1024x768.png
BIN  CocoaneticsBench/Flower_128x96.png
BIN  CocoaneticsBench/Flower_2048x1536.png
BIN  CocoaneticsBench/Flower_256x192.png
BIN  CocoaneticsBench/Flower_512x384.png
39 CocoaneticsBench/ImageBenchmark.h
... ... @@ -0,0 +1,39 @@
  1 +//
  2 +// ImageBenchmark.h
  3 +// CocoaneticsBench
  4 +//
  5 +// Created by Oliver Drobnik on 9/30/11.
  6 +// Copyright 2011 Cocoanetics. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +@interface ImageBenchmark : NSObject
  12 +{
  13 + NSString *_imageName;
  14 + NSString *_path;
  15 + NSString *_internalOverrideSourcePath;
  16 +
  17 + CGFloat _quality;
  18 + NSString *_mode;
  19 +
  20 +
  21 + NSTimeInterval _timeForInit;
  22 + NSTimeInterval _timeForDecompress;
  23 + NSTimeInterval _timeForDraw;
  24 +
  25 + BOOL _didRun;
  26 +}
  27 +
  28 +- (id)initWithCrushedPNGNamed:(NSString *)imageName;
  29 +
  30 +- (void)prepareAsCrushedPNG;
  31 +- (void)prepareAsUncrushedPNG;
  32 +- (void)prepareAsJPEGSourceWithQuality:(CGFloat)quality;
  33 +
  34 +
  35 +- (void)run;
  36 +
  37 +@end
  38 +
  39 +CGContextRef newBitmapContextSuitableForSize(CGSize size);
283 CocoaneticsBench/ImageBenchmark.m
... ... @@ -0,0 +1,283 @@
  1 +//
  2 +// ImageBenchmark.m
  3 +// CocoaneticsBench
  4 +//
  5 +// Created by Oliver Drobnik on 9/30/11.
  6 +// Copyright 2011 Cocoanetics. All rights reserved.
  7 +//
  8 +
  9 +#import "ImageBenchmark.h"
  10 +
  11 +#import <ImageIO/ImageIO.h>
  12 +
  13 +CGContextRef newBitmapContextSuitableForSize(CGSize size)
  14 +{
  15 + int pixelsWide = size.width;
  16 + int pixelsHigh = size.height;
  17 + CGContextRef context = NULL;
  18 + CGColorSpaceRef colorSpace;
  19 + // void * bitmapData;
  20 + // int bitmapByteCount;
  21 + int bitmapBytesPerRow;
  22 +
  23 + bitmapBytesPerRow = (pixelsWide * 4); //4
  24 + // bitmapByteCount = (bitmapBytesPerRow * pixelsHigh);
  25 +
  26 +
  27 +
  28 + /* bitmapData = malloc( bitmapByteCount );
  29 +
  30 + memset(bitmapData, 0, bitmapByteCount); // set memory to black, alpha 0
  31 +
  32 + if (bitmapData == NULL)
  33 + {
  34 + return NULL;
  35 + }
  36 + */
  37 + colorSpace = CGColorSpaceCreateDeviceRGB();
  38 +
  39 +
  40 + context = CGBitmapContextCreate ( NULL, //bitmapData, // let the device handle the memory
  41 + pixelsWide,
  42 + pixelsHigh,
  43 + 8, // bits per component
  44 + bitmapBytesPerRow,
  45 + colorSpace,
  46 + kCGImageAlphaPremultipliedFirst);
  47 + CGColorSpaceRelease( colorSpace );
  48 +
  49 +
  50 + if (context== NULL)
  51 + {
  52 + // free (bitmapData);
  53 + return NULL;
  54 + }
  55 +
  56 + return context;
  57 +}
  58 +
  59 +
  60 +@implementation ImageBenchmark
  61 +
  62 +- (id)initWithCrushedPNGNamed:(NSString *)imageName
  63 +{
  64 + self = [super init];
  65 + if (self)
  66 + {
  67 + _path = [[[NSBundle mainBundle] pathForResource:imageName ofType:@"png"] copy];
  68 + _imageName = [imageName copy];
  69 + }
  70 +
  71 + return self;
  72 +}
  73 +
  74 +- (void)dealloc
  75 +{
  76 + [_path release];
  77 + [_imageName release];
  78 + [_internalOverrideSourcePath release];
  79 +
  80 + [super dealloc];
  81 +}
  82 +
  83 +
  84 +- (NSString *)description
  85 +{
  86 + NSString *fileName = [_path lastPathComponent];
  87 +
  88 + if (_didRun)
  89 + {
  90 + NSString *benchmarkModeString = nil;
  91 +
  92 + if (!_mode)
  93 + {
  94 + benchmarkModeString = @"Crushed PNG";
  95 + }
  96 + else if ([_mode isEqualToString:@"JPG"])
  97 + {
  98 + benchmarkModeString = [NSString stringWithFormat:@"JPG %.0f%%", _quality*100.0];
  99 + }
  100 + else if ([_mode isEqualToString:@"PNG"])
  101 + {
  102 + benchmarkModeString = [NSString stringWithFormat:@"PNG", _quality*100.0];
  103 + }
  104 +
  105 + 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];
  106 + }
  107 + else
  108 + {
  109 + return [NSString stringWithFormat:@"%@ not run", fileName];
  110 + }
  111 +}
  112 +
  113 +- (void)prepareAsCrushedPNG
  114 +{
  115 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  116 +
  117 + NSString *fileName = [[[_path lastPathComponent] stringByDeletingPathExtension] stringByAppendingPathExtension:@"crushed.png"];
  118 +
  119 + NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
  120 + NSString *cacheImagePath = [cachesPath stringByAppendingPathComponent:fileName];
  121 +
  122 + NSFileManager *fileManager = [NSFileManager defaultManager];
  123 +
  124 + if (![fileManager fileExistsAtPath:cacheImagePath])
  125 + {
  126 + [fileManager copyItemAtPath:_path toPath:cacheImagePath error:NULL];
  127 + }
  128 +
  129 + [_internalOverrideSourcePath release];
  130 + _internalOverrideSourcePath = [cacheImagePath copy];
  131 +
  132 + [_mode release];
  133 + _mode = nil;
  134 + _quality = 0;
  135 +
  136 + [pool drain];
  137 +
  138 +}
  139 +
  140 +- (void)prepareAsUncrushedPNG
  141 +{
  142 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  143 +
  144 + NSString *fileName = [[[_path lastPathComponent] stringByDeletingPathExtension] stringByAppendingPathExtension:@"uncrushed.png"];
  145 +
  146 + NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
  147 + NSString *cacheImagePath = [cachesPath stringByAppendingPathComponent:fileName];
  148 +
  149 +
  150 + NSFileManager *fileManager = [NSFileManager defaultManager];
  151 +
  152 + if (![fileManager fileExistsAtPath:cacheImagePath])
  153 + {
  154 + UIImage *image = [UIImage imageWithContentsOfFile:_path];
  155 + UIGraphicsBeginImageContext(image.size);
  156 +
  157 + [image drawAtPoint:CGPointZero];
  158 +
  159 + UIImage *rawImage = UIGraphicsGetImageFromCurrentImageContext();
  160 + UIGraphicsEndImageContext();
  161 +
  162 + NSData *imageData = UIImagePNGRepresentation(rawImage);
  163 +
  164 +
  165 + [imageData writeToFile:cacheImagePath atomically:NO];
  166 + }
  167 +
  168 + [_internalOverrideSourcePath release];
  169 + _internalOverrideSourcePath = [cacheImagePath copy];
  170 +
  171 + [_mode release];
  172 + _mode = @"PNG";
  173 + _quality = 0;
  174 +
  175 + [pool drain];
  176 +}
  177 +
  178 +- (void)prepareAsJPEGSourceWithQuality:(CGFloat)quality
  179 +{
  180 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  181 +
  182 + NSString *fileName = [[[_path lastPathComponent] stringByDeletingPathExtension] stringByAppendingPathExtension:[NSString stringWithFormat:@"%.0f.jpg", quality*100.0]];
  183 +
  184 + NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
  185 + NSString *cacheImagePath = [cachesPath stringByAppendingPathComponent:fileName];
  186 +
  187 + NSFileManager *fileManager = [NSFileManager defaultManager];
  188 +
  189 + if (![fileManager fileExistsAtPath:cacheImagePath])
  190 + {
  191 + UIImage *image = [UIImage imageWithContentsOfFile:_path];
  192 + UIGraphicsBeginImageContext(image.size);
  193 +
  194 + [image drawAtPoint:CGPointZero];
  195 +
  196 + UIImage *rawImage = UIGraphicsGetImageFromCurrentImageContext();
  197 + UIGraphicsEndImageContext();
  198 +
  199 + NSData *imageData = UIImageJPEGRepresentation(rawImage, quality);
  200 +
  201 +
  202 + [imageData writeToFile:cacheImagePath atomically:NO];
  203 + }
  204 +
  205 + [_internalOverrideSourcePath release];
  206 + _internalOverrideSourcePath = [cacheImagePath copy];
  207 +
  208 + [_mode release];
  209 + _mode = @"JPG";
  210 + _quality = quality;
  211 +
  212 + [pool drain];
  213 +}
  214 +
  215 +- (void)decompressImage:(UIImage *)image
  216 +{
  217 + UIGraphicsBeginImageContext(CGSizeMake(1, 1));
  218 +
  219 + [image drawAtPoint:CGPointZero];
  220 +
  221 + UIGraphicsEndImageContext();
  222 +}
  223 +
  224 +- (void)drawImage:(UIImage *)image
  225 +{
  226 + CGContextRef context = newBitmapContextSuitableForSize(image.size);
  227 + CGContextSetShouldAntialias(context, NO);
  228 + CGContextSetInterpolationQuality(context, kCGInterpolationNone);
  229 + CGContextSetBlendMode(context, kCGBlendModeCopy);
  230 +
  231 + CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
  232 +
  233 + CGContextRelease(context);
  234 +}
  235 +
  236 +- (UIImage *)sourceImage
  237 +{
  238 +// if (!_mode)
  239 +// {
  240 +// return [UIImage imageNamed:_imageName];
  241 +// }
  242 +
  243 + NSURL *url = [NSURL fileURLWithPath:_internalOverrideSourcePath?_internalOverrideSourcePath:_path];
  244 + NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:(id)kCGImageSourceShouldCache];
  245 +
  246 + CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)url, (CFDictionaryRef)nil);
  247 + CGImageRef cgImage = CGImageSourceCreateImageAtIndex(source, 0, (CFDictionaryRef)dict);
  248 +
  249 + UIImage *retImage = [UIImage imageWithCGImage:cgImage];
  250 + CGImageRelease(cgImage);
  251 + CFRelease(source);
  252 +
  253 + return retImage;
  254 +// return [UIImage imageWithContentsOfFile:_internalOverrideSourcePath?_internalOverrideSourcePath:_path];
  255 +}
  256 +
  257 +- (void)run
  258 +{
  259 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  260 +
  261 + NSDate *before = [NSDate date];
  262 + UIImage *image = [self sourceImage];
  263 + NSDate *after = [NSDate date];
  264 + _timeForInit = [after timeIntervalSinceDate:before];
  265 +
  266 +
  267 + before = [NSDate date];
  268 + [self decompressImage:image];
  269 + after = [NSDate date];
  270 + _timeForDecompress = [after timeIntervalSinceDate:before];
  271 +
  272 + before = [NSDate date];
  273 + [self drawImage:image];
  274 + after = [NSDate date];
  275 + _timeForDraw = [after timeIntervalSinceDate:before];
  276 +
  277 + _didRun = YES;
  278 +
  279 + [pool drain];
  280 +}
  281 +
  282 +
  283 +@end

0 comments on commit d3577ae

Please sign in to comment.
Something went wrong with that request. Please try again.