Permalink
Browse files

Added benchmark for HW decompression

  • Loading branch information...
1 parent be5333b commit 3dd379905fcf6d4b7be4aa0f3a3dd5834221f949 @odrobnik committed Aug 30, 2012
@@ -12,6 +12,7 @@
A70C0C8E1435A79C00CC3C72 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A70C0C8D1435A79C00CC3C72 /* CoreGraphics.framework */; };
A70C0C901435A79C00CC3C72 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A70C0C8F1435A79C00CC3C72 /* CoreData.framework */; };
A70C0CCE1435DFAA00CC3C72 /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A70C0CCD1435DFAA00CC3C72 /* ImageIO.framework */; };
+ A79B4CB415EF9ECC0042520A /* CoreImage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A79B4CB315EF9ECC0042520A /* CoreImage.framework */; };
A7C71E29151363E700B64A37 /* CocoaneticsBench.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = A7C71E13151363E700B64A37 /* CocoaneticsBench.xcdatamodeld */; };
A7C71E2B151363E700B64A37 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = A7C71E17151363E700B64A37 /* MainWindow.xib */; };
A7C71E2C151363E700B64A37 /* RootViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = A7C71E19151363E700B64A37 /* RootViewController.xib */; };
@@ -40,6 +41,7 @@
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; };
A70C0CCD1435DFAA00CC3C72 /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; };
+ A79B4CB315EF9ECC0042520A /* CoreImage.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreImage.framework; path = System/Library/Frameworks/CoreImage.framework; sourceTree = SDKROOT; };
A7C71E10151363E700B64A37 /* CocoaneticsBench-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "CocoaneticsBench-Info.plist"; sourceTree = "<group>"; };
A7C71E11151363E700B64A37 /* CocoaneticsBench-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CocoaneticsBench-Prefix.pch"; sourceTree = "<group>"; };
A7C71E14151363E700B64A37 /* CocoaneticsBench.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = CocoaneticsBench.xcdatamodel; sourceTree = "<group>"; };
@@ -74,6 +76,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ A79B4CB415EF9ECC0042520A /* CoreImage.framework in Frameworks */,
A70C0CCE1435DFAA00CC3C72 /* ImageIO.framework in Frameworks */,
A70C0C8A1435A79C00CC3C72 /* UIKit.framework in Frameworks */,
A70C0C8C1435A79C00CC3C72 /* Foundation.framework in Frameworks */,
@@ -98,6 +101,7 @@
A70C0C7A1435A79C00CC3C72 = {
isa = PBXGroup;
children = (
+ A79B4CB315EF9ECC0042520A /* CoreImage.framework */,
A7C71E36151363EF00B64A37 /* Battery Log */,
A7C71E0F151363E700B64A37 /* Image Decompression */,
A70C0C881435A79C00CC3C72 /* Frameworks */,
@@ -479,6 +483,7 @@
A7C71E5B151364EE00B64A37 /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
@@ -10,51 +10,9 @@
#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;
-}
+
+// enable the following line to benchmark HW decompression
+//#define USE_CIIMAGE
@implementation ImageBenchmark
@@ -99,7 +57,7 @@ - (NSString *)description
}
else if ([_mode isEqualToString:@"PNG"])
{
- benchmarkModeString = [NSString stringWithFormat:@"PNG", _quality*100.0];
+ benchmarkModeString = [NSString stringWithFormat:@"PNG"];
}
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];
@@ -216,31 +174,35 @@ - (void)decompressImage:(UIImage *)image
{
UIGraphicsBeginImageContext(CGSizeMake(1, 1));
- [image drawAtPoint:CGPointZero];
+ //[image drawAtPoint:CGPointZero];
UIGraphicsEndImageContext();
}
- (void)drawImage:(UIImage *)image
{
- CGContextRef context = newBitmapContextSuitableForSize(image.size);
+ UIGraphicsBeginImageContext(image.size);
+
+ CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(context, NO);
CGContextSetInterpolationQuality(context, kCGInterpolationNone);
CGContextSetBlendMode(context, kCGBlendModeCopy);
CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage);
- CGContextRelease(context);
+ UIGraphicsEndImageContext();
}
- (UIImage *)sourceImage
{
-// if (!_mode)
-// {
-// return [UIImage imageNamed:_imageName];
-// }
-
NSURL *url = [NSURL fileURLWithPath:_internalOverrideSourcePath?_internalOverrideSourcePath:_path];
+
+
+#ifdef USE_CIIMAGE
+ CIImage *ciImage = [CIImage imageWithContentsOfURL:url];
+
+ UIImage *retImage = [UIImage imageWithCIImage:ciImage];
+#else
NSDictionary *dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:(id)kCGImageSourceShouldCache];
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)url, (CFDictionaryRef)nil);
@@ -249,30 +211,32 @@ - (UIImage *)sourceImage
UIImage *retImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
CFRelease(source);
-
+#endif
+
return retImage;
-// return [UIImage imageWithContentsOfFile:_internalOverrideSourcePath?_internalOverrideSourcePath:_path];
}
- (void)run
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSDate *before = [NSDate date];
+ CFAbsoluteTime before = CFAbsoluteTimeGetCurrent();
UIImage *image = [self sourceImage];
- NSDate *after = [NSDate date];
- _timeForInit = [after timeIntervalSinceDate:before];
-
+ CFAbsoluteTime after = CFAbsoluteTimeGetCurrent();
+ _timeForInit = after - before;
- before = [NSDate date];
+#ifndef USE_CIIMAGE
+ // for CIImage->UIImage the decompression already took place in init
+ before = CFAbsoluteTimeGetCurrent();
[self decompressImage:image];
- after = [NSDate date];
- _timeForDecompress = [after timeIntervalSinceDate:before];
+ after = CFAbsoluteTimeGetCurrent();
+ _timeForDecompress = after - before;
+#endif
- before = [NSDate date];
+ before = CFAbsoluteTimeGetCurrent();
[self drawImage:image];
- after = [NSDate date];
- _timeForDraw = [after timeIntervalSinceDate:before];
+ after = CFAbsoluteTimeGetCurrent();
+ _timeForDraw = after - before;
_didRun = YES;

0 comments on commit 3dd3799

Please sign in to comment.