[SCM] Multi-format 1D/2D barcode image processing library branch, upstream, updated. 24d4480bc48cf9eabf7b2bd2f528248b0e458809
rpechayr
rpechayr at 59b500cc-1b3d-0410-9834-0bbf25fbcc57
Wed Aug 4 01:31:46 UTC 2010
The following commit has been merged in the upstream branch:
commit 020338283683c5592ab5ab991c486e1fced540f4
Author: rpechayr <rpechayr at 59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Date: Sat May 29 11:31:41 2010 +0000
[iphone] Memory leak fixed. Widget does not crash anymore after a few seconds. No more memory warning either
git-svn-id: http://zxing.googlecode.com/svn/trunk@1396 59b500cc-1b3d-0410-9834-0bbf25fbcc57
diff --git a/iphone/ScanTest/Classes/RootViewController.m b/iphone/ScanTest/Classes/RootViewController.m
index a9ae9a2..cec4693 100644
--- a/iphone/ScanTest/Classes/RootViewController.m
+++ b/iphone/ScanTest/Classes/RootViewController.m
@@ -18,16 +18,20 @@
- (void)viewDidLoad {
[super viewDidLoad];
[self setTitle:@"ZXing"];
- scanController = [ZXingWidgetController alloc];
+
+ scanController = [[ZXingWidgetController alloc] initWithDelegate:self];
[scanController setOneDMode:NO];
[scanController setShowCancel:YES];
scanController = [scanController initWithDelegate:self];
NSBundle *mainBundle = [NSBundle mainBundle];
[scanController setSoundToPlay:[[NSURL fileURLWithPath:[mainBundle pathForResource:@"beep-beep" ofType:@"aiff"] isDirectory:NO] retain]];
+
}
- (IBAction)scanPressed:(id)sender {
- [self presentModalViewController:scanController animated:YES];
+ //UIImagePickerController *picker = [[UIImagePickerController alloc] init];
+ [self presentModalViewController:scanController
+ animated:YES];
// [self.navigationController pushViewController:scanController animated:true];
}
@@ -64,7 +68,7 @@
- (void)scanResult:(NSString *)result {
//[self.resultsView setText:result];
- [self dismissModalViewControllerAnimated:NO];
+ [self dismissModalViewControllerAnimated:YES];
self.resultsToDisplay = result;
}
@@ -78,7 +82,7 @@
}
- (void)cancelled {
- [self dismissModalViewControllerAnimated:true];
+ [self dismissModalViewControllerAnimated:YES];
}
#pragma mark -
diff --git a/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj b/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj
index 6081c74..2b04330 100755
--- a/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj
+++ b/iphone/ScanTest/ScanTest.xcodeproj/project.pbxproj
@@ -297,6 +297,7 @@
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
+ GCC_VERSION = 4.2;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "../ZXingWidget/Classes/**";
@@ -316,7 +317,7 @@
HEADER_SEARCH_PATHS = "../ZXingWidget/Classes/**";
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PREBINDING = NO;
- SDKROOT = iphoneos3.1.3;
+ SDKROOT = iphonesimulator3.1.3;
};
name = Release;
};
diff --git a/iphone/ZXingWidget/Classes/Decoder.h b/iphone/ZXingWidget/Classes/Decoder.h
index 4b28141..be2bf57 100644
--- a/iphone/ZXingWidget/Classes/Decoder.h
+++ b/iphone/ZXingWidget/Classes/Decoder.h
@@ -32,6 +32,7 @@
size_t subsetHeight;
size_t subsetBytesPerRow;
id<DecoderDelegate> delegate;
+ NSOperationQueue *operationQueue;
}
@property(nonatomic, retain) UIImage *image;
@@ -42,6 +43,7 @@
@property(assign) size_t subsetHeight;
@property(assign) size_t subsetBytesPerRow;
@property(nonatomic, assign) id<DecoderDelegate> delegate;
+ at property (nonatomic, retain) NSOperationQueue *operationQueue;
- (void) decodeImage:(UIImage *)image;
- (void) decodeImage:(UIImage *)image cropRect:(CGRect)cropRect;
diff --git a/iphone/ZXingWidget/Classes/Decoder.mm b/iphone/ZXingWidget/Classes/Decoder.mm
index d5ca9cf..edc6336 100644
--- a/iphone/ZXingWidget/Classes/Decoder.mm
+++ b/iphone/ZXingWidget/Classes/Decoder.mm
@@ -42,7 +42,17 @@ using namespace zxing;
@synthesize subsetHeight;
@synthesize subsetBytesPerRow;
@synthesize delegate;
+ at synthesize operationQueue;
+
+- (id)init {
+ if (self = [super init]) {
+ NSOperationQueue *opQueue = [[NSOperationQueue alloc] init];
+ self.operationQueue = opQueue;
+ [opQueue release];
+ }
+ return self;
+}
- (void)willDecodeImage {
if ([self.delegate respondsToSelector:@selector(decoder:willDecodeImage:usingSubset:)]) {
[self.delegate decoder:self willDecodeImage:self.image usingSubset:self.subsetImage];
@@ -56,6 +66,7 @@ using namespace zxing;
}
- (void)didDecodeImage:(TwoDDecoderResult *)result {
+
if ([self.delegate respondsToSelector:@selector(decoder:didDecodeImage:usingSubset:withResult:)]) {
[self.delegate decoder:self didDecodeImage:self.image usingSubset:self.subsetImage withResult:result];
}
@@ -64,6 +75,7 @@ using namespace zxing;
}
- (void)failedToDecodeImage:(NSString *)reason {
+
if ([self.delegate respondsToSelector:@selector(decoder:failedToDecodeImage:usingSubset:reason:)]) {
[self.delegate decoder:self failedToDecodeImage:self.image usingSubset:self.subsetImage reason:reason];
}
@@ -143,13 +155,13 @@ using namespace zxing;
}
- (void)decode:(id)arg {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSAutoreleasePool* mainpool = [[NSAutoreleasePool alloc] init];
{
NSSet *formatReaders = [FormatReader formatReaders];
Ref<LuminanceSource> source (new GrayBytesMonochromeBitmapSource(subsetData, subsetWidth, subsetHeight, subsetBytesPerRow));
-
Ref<Binarizer> binarizer (new GlobalHistogramBinarizer(source));
Ref<BinaryBitmap> grayImage (new BinaryBitmap(binarizer));
#ifdef DEBUG
@@ -163,10 +175,11 @@ using namespace zxing;
for (int i = 0; !decoderResult && i < 4; i++) {
#endif
for (FormatReader *reader in formatReaders) {
+ NSAutoreleasePool *secondarypool = [[NSAutoreleasePool alloc] init];
try {
#ifdef DEBUG
NSLog(@"decoding gray image");
- #endif
+ #endif
Ref<Result> result([reader decode:grayImage]);
#ifdef DEBUG
NSLog(@"gray image decoded");
@@ -198,6 +211,7 @@ using namespace zxing;
} catch (...) {
NSLog(@"Caught unknown exception!");
}
+ [secondarypool release];
}
#ifdef TRY_ROTATIONS
@@ -226,15 +240,12 @@ using namespace zxing;
waitUntilDone:NO];
}
}
- [pool drain];
+
+
#ifdef DEBUG
NSLog(@"finished decoding.");
#endif
-
- // if this is not the main thread, then we end it
- if (![NSThread isMainThread]) {
- [NSThread exit];
- }
+ [mainpool release];
}
- (void) decodeImage:(UIImage *)i {
@@ -249,17 +260,25 @@ using namespace zxing;
[self willDecodeImage];
[self performSelectorOnMainThread:@selector(progressDecodingImage:)
withObject:NSLocalizedString(@"Decoder MessageWhileDecoding", @"Decoding ...")
- waitUntilDone:NO];
-
- [NSThread detachNewThreadSelector:@selector(decode:)
+ waitUntilDone:NO];
+ NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(decode:) object:nil];
+ [operationQueue addOperation:op];
+ [op release];
+ //[self performSelectorInBackground:@selector(decode:) withObject:nil];
+
+
+ //[self performSelector:@selector(decode:) onThread:decodingThread withObject:nil waitUntilDone:NO];
+ /*[NSThread detachNewThreadSelector:@selector(decode:)
toTarget:self
- withObject:nil];
+ withObject:nil];*/
}
- (void) dealloc {
+
[image release];
[subsetImage release];
if (subsetData) free(subsetData);
+ [operationQueue release];
[super dealloc];
}
diff --git a/iphone/ZXingWidget/Classes/ZXingWidgetController.h b/iphone/ZXingWidget/Classes/ZXingWidgetController.h
index 5a0cb0c..daf29b9 100755
--- a/iphone/ZXingWidget/Classes/ZXingWidgetController.h
+++ b/iphone/ZXingWidget/Classes/ZXingWidgetController.h
@@ -23,15 +23,15 @@
@protocol ZXingDelegate;
@interface ZXingWidgetController : UIImagePickerController <DecoderDelegate, CancelDelegate> {
- ParsedResult *result;
- NSArray *actions;
- OverlayView *overlayView;
- SystemSoundID beepSound;
- BOOL showCancel;
- NSURL *soundToPlay;
- id<ZXingDelegate> delegate;
- BOOL wasCancelled;
- BOOL oneDMode;
+ ParsedResult *result;
+ NSArray *actions;
+ OverlayView *overlayView;
+ SystemSoundID beepSound;
+ BOOL showCancel;
+ NSURL *soundToPlay;
+ id<ZXingDelegate> delegate;
+ BOOL wasCancelled;
+ BOOL oneDMode;
}
@property (nonatomic, assign) id<ZXingDelegate> delegate;
@@ -48,4 +48,4 @@
@protocol ZXingDelegate
- (void)scanResult:(NSString *)result;
- (void)cancelled;
- at end
+ at end
\ No newline at end of file
diff --git a/iphone/ZXingWidget/Classes/ZXingWidgetController.m b/iphone/ZXingWidget/Classes/ZXingWidgetController.m
index 1c52454..173af15 100755
--- a/iphone/ZXingWidget/Classes/ZXingWidgetController.m
+++ b/iphone/ZXingWidget/Classes/ZXingWidgetController.m
@@ -33,192 +33,199 @@ CGImageRef UIGetScreenImage();
@synthesize result, actions, showCancel, delegate, soundToPlay, oneDMode;
- (id)initWithDelegate:(id<ZXingDelegate>)scanDelegate {
- if (self = [super init]) {
- [self setDelegate:scanDelegate];
- beepSound = -1;
- self.wantsFullScreenLayout = YES;
- self.sourceType = UIImagePickerControllerSourceTypeCamera;
- float zoomFactor = CAMERA_SCALAR;
- if ([self fixedFocus]) {
- zoomFactor *= 2.0;
- }
- self.cameraViewTransform = CGAffineTransformScale(
- self.cameraViewTransform, zoomFactor, zoomFactor);
- overlayView = [OverlayView alloc];
- [overlayView setOneDMode:oneDMode];
- overlayView = [overlayView initWithCancelEnabled:showCancel frame:[UIScreen mainScreen].bounds];
- [overlayView setDelegate:self];
- self.sourceType = UIImagePickerControllerSourceTypeCamera;
- self.showsCameraControls = NO;
- self.cameraOverlayView = overlayView;
- self.allowsEditing = NO; // [[NSUserDefaults standardUserDefaults] boolForKey:@"allowEditing"];
- }
-
- return self;
+ if (self = [super init]) {
+ [self setDelegate:scanDelegate];
+ beepSound = -1;
+ self.wantsFullScreenLayout = YES;
+ if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
+ self.sourceType = UIImagePickerControllerSourceTypeCamera;
+ float zoomFactor = CAMERA_SCALAR;
+ if ([self fixedFocus]) {
+ zoomFactor *= 2.0;
+ }
+ if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
+ self.cameraViewTransform = CGAffineTransformScale(
+ self.cameraViewTransform, zoomFactor, zoomFactor);
+ overlayView = [OverlayView alloc];
+ [overlayView setOneDMode:oneDMode];
+ overlayView = [overlayView initWithCancelEnabled:showCancel frame:[UIScreen mainScreen].bounds];
+ [overlayView setDelegate:self];
+ if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
+ {
+ self.showsCameraControls = NO;
+ self.cameraOverlayView = overlayView;
+ self.allowsEditing = NO; // [[NSUserDefaults standardUserDefaults] boolForKey:@"allowEditing"];
+ }
+ }
+
+ return self;
}
- (void)dealloc {
- if (beepSound != -1) {
- AudioServicesDisposeSystemSoundID(beepSound);
- }
- [overlayView dealloc];
- [super dealloc];
+ if (beepSound != -1) {
+ AudioServicesDisposeSystemSoundID(beepSound);
+ }
+ [overlayView dealloc];
+ [super dealloc];
}
- (void)cancelled {
- NSLog(@"cancelled called in ZXingWidgetController");
- wasCancelled = true;
- if (delegate != nil) {
- [delegate cancelled];
- }
+ NSLog(@"cancelled called in ZXingWidgetController");
+ wasCancelled = true;
+ if (delegate != nil) {
+ [delegate cancelled];
+ }
}
- (NSString *)getPlatform {
- size_t size;
- sysctlbyname("hw.machine", NULL, &size, NULL, 0);
- char *machine = malloc(size);
- sysctlbyname("hw.machine", machine, &size, NULL, 0);
- NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
- free(machine);
- return platform;
+ size_t size;
+ sysctlbyname("hw.machine", NULL, &size, NULL, 0);
+ char *machine = malloc(size);
+ sysctlbyname("hw.machine", machine, &size, NULL, 0);
+ NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
+ free(machine);
+ return platform;
}
- (BOOL)fixedFocus {
- NSString *platform = [self getPlatform];
- if ([platform isEqualToString:@"iPhone1,1"] ||
- [platform isEqualToString:@"iPhone1,2"]) return true;
- return false;
+ NSString *platform = [self getPlatform];
+ if ([platform isEqualToString:@"iPhone1,1"] ||
+ [platform isEqualToString:@"iPhone1,2"]) return true;
+ return false;
}
- (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if ([self soundToPlay] != nil) {
- OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)[self soundToPlay], &beepSound);
- if (error != kAudioServicesNoError) {
- NSLog(@"Problem loading nearSound.caf");
- }
- }
+ [super viewWillAppear:animated];
+ if ([self soundToPlay] != nil) {
+ OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)[self soundToPlay], &beepSound);
+ if (error != kAudioServicesNoError) {
+ NSLog(@"Problem loading nearSound.caf");
+ }
+ }
}
- (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- [overlayView setPoints:nil];
- wasCancelled = false;
- [NSTimer scheduledTimerWithTimeInterval: FIRST_TAKE_DELAY
- target: self
- selector: @selector(takePicture:)
- userInfo: nil
- repeats: NO];
+ [super viewDidAppear:animated];
+ [overlayView setPoints:nil];
+ wasCancelled = false;
+ [NSTimer scheduledTimerWithTimeInterval: FIRST_TAKE_DELAY
+ target: self
+ selector: @selector(takePicture:)
+ userInfo: nil
+ repeats: NO];
}
- (CGImageRef)CGImageRotated90:(CGImageRef)imgRef
{
- CGFloat angleInRadians = -90 * (M_PI / 180);
- CGFloat width = CGImageGetWidth(imgRef);
- CGFloat height = CGImageGetHeight(imgRef);
-
- CGRect imgRect = CGRectMake(0, 0, width, height);
- CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
- CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform);
-
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
- CGContextRef bmContext = CGBitmapContextCreate(NULL,
- rotatedRect.size.width,
- rotatedRect.size.height,
- 8,
- 0,
- colorSpace,
- kCGImageAlphaPremultipliedFirst);
- CGContextSetAllowsAntialiasing(bmContext, FALSE);
- CGContextSetInterpolationQuality(bmContext, kCGInterpolationNone);
- CGColorSpaceRelease(colorSpace);
-// CGContextTranslateCTM(bmContext,
-// +(rotatedRect.size.width/2),
-// +(rotatedRect.size.height/2));
- CGContextScaleCTM(bmContext, rotatedRect.size.width/rotatedRect.size.height, 1.0);
- CGContextTranslateCTM(bmContext, 0.0, rotatedRect.size.height);
- CGContextRotateCTM(bmContext, angleInRadians);
-// CGContextTranslateCTM(bmContext,
-// -(rotatedRect.size.width/2),
-// -(rotatedRect.size.height/2));
- CGContextDrawImage(bmContext, CGRectMake(0, 0,
- rotatedRect.size.width,
- rotatedRect.size.height),
- imgRef);
-
- CGImageRef rotatedImage = CGBitmapContextCreateImage(bmContext);
- CFRelease(bmContext);
- [(id)rotatedImage autorelease];
-
- return rotatedImage;
+ CGFloat angleInRadians = -90 * (M_PI / 180);
+ CGFloat width = CGImageGetWidth(imgRef);
+ CGFloat height = CGImageGetHeight(imgRef);
+
+ CGRect imgRect = CGRectMake(0, 0, width, height);
+ CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
+ CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform);
+
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ CGContextRef bmContext = CGBitmapContextCreate(NULL,
+ rotatedRect.size.width,
+ rotatedRect.size.height,
+ 8,
+ 0,
+ colorSpace,
+ kCGImageAlphaPremultipliedFirst);
+ CGContextSetAllowsAntialiasing(bmContext, FALSE);
+ CGContextSetInterpolationQuality(bmContext, kCGInterpolationNone);
+ CGColorSpaceRelease(colorSpace);
+ // CGContextTranslateCTM(bmContext,
+ // +(rotatedRect.size.width/2),
+ // +(rotatedRect.size.height/2));
+ CGContextScaleCTM(bmContext, rotatedRect.size.width/rotatedRect.size.height, 1.0);
+ CGContextTranslateCTM(bmContext, 0.0, rotatedRect.size.height);
+ CGContextRotateCTM(bmContext, angleInRadians);
+ // CGContextTranslateCTM(bmContext,
+ // -(rotatedRect.size.width/2),
+ // -(rotatedRect.size.height/2));
+ CGContextDrawImage(bmContext, CGRectMake(0, 0,
+ rotatedRect.size.width,
+ rotatedRect.size.height),
+ imgRef);
+
+ CGImageRef rotatedImage = CGBitmapContextCreateImage(bmContext);
+ CFRelease(bmContext);
+ [(id)rotatedImage autorelease];
+
+ return rotatedImage;
}
- (CGImageRef)CGImageRotated180:(CGImageRef)imgRef
{
- CGFloat angleInRadians = M_PI;
- CGFloat width = CGImageGetWidth(imgRef);
- CGFloat height = CGImageGetHeight(imgRef);
-
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
- CGContextRef bmContext = CGBitmapContextCreate(NULL,
- width,
- height,
- 8,
- 0,
- colorSpace,
- kCGImageAlphaPremultipliedFirst);
- CGContextSetAllowsAntialiasing(bmContext, FALSE);
- CGContextSetInterpolationQuality(bmContext, kCGInterpolationNone);
- CGColorSpaceRelease(colorSpace);
- CGContextTranslateCTM(bmContext,
- +(width/2),
- +(height/2));
- CGContextRotateCTM(bmContext, angleInRadians);
- CGContextTranslateCTM(bmContext,
- -(width/2),
- -(height/2));
- CGContextDrawImage(bmContext, CGRectMake(0, 0, width, height), imgRef);
-
- CGImageRef rotatedImage = CGBitmapContextCreateImage(bmContext);
- CFRelease(bmContext);
- [(id)rotatedImage autorelease];
-
- return rotatedImage;
+ CGFloat angleInRadians = M_PI;
+ CGFloat width = CGImageGetWidth(imgRef);
+ CGFloat height = CGImageGetHeight(imgRef);
+
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ CGContextRef bmContext = CGBitmapContextCreate(NULL,
+ width,
+ height,
+ 8,
+ 0,
+ colorSpace,
+ kCGImageAlphaPremultipliedFirst);
+ CGContextSetAllowsAntialiasing(bmContext, FALSE);
+ CGContextSetInterpolationQuality(bmContext, kCGInterpolationNone);
+ CGColorSpaceRelease(colorSpace);
+ CGContextTranslateCTM(bmContext,
+ +(width/2),
+ +(height/2));
+ CGContextRotateCTM(bmContext, angleInRadians);
+ CGContextTranslateCTM(bmContext,
+ -(width/2),
+ -(height/2));
+ CGContextDrawImage(bmContext, CGRectMake(0, 0, width, height), imgRef);
+
+ CGImageRef rotatedImage = CGBitmapContextCreateImage(bmContext);
+ CFRelease(bmContext);
+ [(id)rotatedImage autorelease];
+
+ return rotatedImage;
}
- (void)takePicture:(NSTimer*)theTimer {
- CGImageRef capture = UIGetScreenImage();
- CGRect cropRect = [overlayView cropRect];
- if (oneDMode) {
- // let's just give the decoder a vertical band right above the red line
- cropRect.origin.x = cropRect.origin.x + (cropRect.size.width / 2) - (ONE_D_BAND_HEIGHT + 1);
- cropRect.size.width = ONE_D_BAND_HEIGHT;
- // do a rotate
- CGImageRef croppedImg = CGImageCreateWithImageInRect(capture, cropRect);
- CGImageRelease(capture);
- capture = [self CGImageRotated90:croppedImg];
- capture = [self CGImageRotated180:capture];
-// UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage:capture], nil, nil, nil);
- CGImageRelease(croppedImg);
- cropRect.origin.x = 0.0;
- cropRect.origin.y = 0.0;
- cropRect.size.width = CGImageGetWidth(capture);
- cropRect.size.height = CGImageGetHeight(capture);
- }
-
- UIImage *scrn = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(capture, cropRect)];
- Decoder *d = [[Decoder alloc] init];
- d.delegate = self;
- cropRect.origin.x = 0.0;
- cropRect.origin.y = 0.0;
- [d decodeImage:scrn cropRect:cropRect];
+ CGImageRef capture = UIGetScreenImage();
+ CGRect cropRect = [overlayView cropRect];
+ if (oneDMode) {
+ // let's just give the decoder a vertical band right above the red line
+ cropRect.origin.x = cropRect.origin.x + (cropRect.size.width / 2) - (ONE_D_BAND_HEIGHT + 1);
+ cropRect.size.width = ONE_D_BAND_HEIGHT;
+ // do a rotate
+ CGImageRef croppedImg = CGImageCreateWithImageInRect(capture, cropRect);
+ capture = [self CGImageRotated90:croppedImg];
+ capture = [self CGImageRotated180:capture];
+ // UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage:capture], nil, nil, nil);
+ CGImageRelease(croppedImg);
+ cropRect.origin.x = 0.0;
+ cropRect.origin.y = 0.0;
+ cropRect.size.width = CGImageGetWidth(capture);
+ cropRect.size.height = CGImageGetHeight(capture);
+ }
+ CGImageRef newImage = CGImageCreateWithImageInRect(capture, cropRect);
+ CGImageRelease(capture);
+ //UIImage *scrn = [UIImage imageWithCGImage:newImage];
+ UIImage *scrn = [[UIImage alloc] initWithCGImage:newImage];
+ CGImageRelease(newImage);
+ Decoder *d = [[Decoder alloc] init];
+ d.delegate = self;
+ cropRect.origin.x = 0.0;
+ cropRect.origin.y = 0.0;
+ [d decodeImage:scrn cropRect:cropRect];
+ [scrn release];
}
// DecoderDelegate methods
- (void)decoder:(Decoder *)decoder willDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset{
#ifdef DEBUG
- NSLog(@"DecoderViewController MessageWhileDecodingWithDimensions: Decoding image (%.0fx%.0f) ...", image.size.width, image.size.height);
+ NSLog(@"DecoderViewController MessageWhileDecodingWithDimensions: Decoding image (%.0fx%.0f) ...", image.size.width, image.size.height);
#endif
}
@@ -229,48 +236,48 @@ CGImageRef UIGetScreenImage();
}
- (void)presentResultForString:(NSString *)resultString {
- self.result = [ResultParser parsedResultForString:resultString];
-
- if (beepSound != -1) {
- AudioServicesPlaySystemSound(beepSound);
- }
+ self.result = [ResultParser parsedResultForString:resultString];
+
+ if (beepSound != -1) {
+ AudioServicesPlaySystemSound(beepSound);
+ }
#ifdef DEBUG
- NSLog(@"result string = %@", resultString);
- NSLog(@"result has %d actions", actions ? 0 : actions.count);
+ NSLog(@"result string = %@", resultString);
+ NSLog(@"result has %d actions", actions ? 0 : actions.count);
#endif
- // [self updateToolbar];
+ // [self updateToolbar];
}
- (void)presentResultPoints:(NSArray *)resultPoints
forImage:(UIImage *)image
usingSubset:(UIImage *)subset {
- // simply add the points to the image view
- [overlayView setPoints:resultPoints];
+ // simply add the points to the image view
+ [overlayView setPoints:resultPoints];
}
- (void)decoder:(Decoder *)decoder didDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset withResult:(TwoDDecoderResult *)twoDResult {
- [self presentResultForString:[twoDResult text]];
- [self presentResultPoints:[twoDResult points] forImage:image usingSubset:subset];
- // now, in a selector, call the delegate to give this overlay time to show the points
- [self performSelector:@selector(alertDelegate:) withObject:[[twoDResult text] copy] afterDelay:1.0];
- decoder.delegate = nil;
- [decoder release];
+ [self presentResultForString:[twoDResult text]];
+ [self presentResultPoints:[twoDResult points] forImage:image usingSubset:subset];
+ // now, in a selector, call the delegate to give this overlay time to show the points
+ [self performSelector:@selector(alertDelegate:) withObject:[[twoDResult text] copy] afterDelay:1.0];
+ decoder.delegate = nil;
+ [decoder release];
}
-- (void)alertDelegate:(id)text {
- if (delegate != nil) {
- [delegate scanResult:text];
- }
+- (void)alertDelegate:(id)text {
+ if (delegate != nil) {
+ [delegate scanResult:text];
+ }
}
- (void)decoder:(Decoder *)decoder failedToDecodeImage:(UIImage *)image usingSubset:(UIImage *)subset reason:(NSString *)reason {
- decoder.delegate = nil;
- [decoder release];
- [overlayView setPoints:nil];
- if (!wasCancelled) {
- [self takePicture:nil];
- }
- //[self updateToolbar];
+ decoder.delegate = nil;
+ [decoder release];
+ [overlayView setPoints:nil];
+ if (!wasCancelled) {
+ [self takePicture:nil];
+ }
+ //[self updateToolbar];
}
@end
diff --git a/iphone/ZXingWidget/Classes/parsedResults/EmailParsedResult.m b/iphone/ZXingWidget/Classes/parsedResults/EmailParsedResult.m
index d333cba..7370d36 100644
--- a/iphone/ZXingWidget/Classes/parsedResults/EmailParsedResult.m
+++ b/iphone/ZXingWidget/Classes/parsedResults/EmailParsedResult.m
@@ -54,6 +54,7 @@
[parts addObject:[NSString stringWithFormat:NSLocalizedString(@"EmailParsedResult Display: Body", @"%@"), self.body]];
}
return [parts componentsJoinedByString:@"\n"];
+ [parts release];
}
+ (NSString *)typeName {
diff --git a/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj b/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj
index a0e5ebc..86cc47f 100644
--- a/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj
+++ b/iphone/ZXingWidget/ZXingWidget.xcodeproj/project.pbxproj
@@ -461,22 +461,6 @@
children = (
E53458B311987396000CB77F /* CoreSrc */,
08FB77AEFE84172EC02AAC07 /* Classes */,
- 1F027FB711A7BEBF006B06DE /* TwoDDecoderResult.h */,
- 1F027FB811A7BEBF006B06DE /* TwoDDecoderResult.m */,
- 1F027FB911A7BEBF006B06DE /* ZXingWidgetController.h */,
- 1F027FBA11A7BEBF006B06DE /* ZXingWidgetController.m */,
- 1F027F9F11A7BEAF006B06DE /* Decoder.h */,
- 1F027FA011A7BEAF006B06DE /* Decoder.mm */,
- 1F027FA111A7BEAF006B06DE /* DecoderDelegate.h */,
- 1F027FA211A7BEAF006B06DE /* FormatReader.h */,
- 1F027FA311A7BEAF006B06DE /* FormatReader.mm */,
- 1F027FA411A7BEAF006B06DE /* GrayBytesMonochromeBitmapSource.cpp */,
- 1F027FA511A7BEAF006B06DE /* GrayBytesMonochromeBitmapSource.h */,
- 1F027FA611A7BEAF006B06DE /* MultiFormatReader.mm */,
- 1F027FA711A7BEAF006B06DE /* NSString+HTML.h */,
- 1F027FA811A7BEAF006B06DE /* NSString+HTML.m */,
- 1F027FA911A7BEAF006B06DE /* OverlayView.h */,
- 1F027FAA11A7BEAF006B06DE /* OverlayView.m */,
32C88DFF0371C24200C91783 /* Other Sources */,
0867D69AFE84028FC02AAC07 /* Frameworks */,
E5345D2811999F53000CB77F /* Resources */,
@@ -499,6 +483,22 @@
08FB77AEFE84172EC02AAC07 /* Classes */ = {
isa = PBXGroup;
children = (
+ 1F027FB711A7BEBF006B06DE /* TwoDDecoderResult.h */,
+ 1F027FB811A7BEBF006B06DE /* TwoDDecoderResult.m */,
+ 1F027FB911A7BEBF006B06DE /* ZXingWidgetController.h */,
+ 1F027FBA11A7BEBF006B06DE /* ZXingWidgetController.m */,
+ 1F027F9F11A7BEAF006B06DE /* Decoder.h */,
+ 1F027FA011A7BEAF006B06DE /* Decoder.mm */,
+ 1F027FA111A7BEAF006B06DE /* DecoderDelegate.h */,
+ 1F027FA211A7BEAF006B06DE /* FormatReader.h */,
+ 1F027FA311A7BEAF006B06DE /* FormatReader.mm */,
+ 1F027FA411A7BEAF006B06DE /* GrayBytesMonochromeBitmapSource.cpp */,
+ 1F027FA511A7BEAF006B06DE /* GrayBytesMonochromeBitmapSource.h */,
+ 1F027FA611A7BEAF006B06DE /* MultiFormatReader.mm */,
+ 1F027FA711A7BEAF006B06DE /* NSString+HTML.h */,
+ 1F027FA811A7BEAF006B06DE /* NSString+HTML.m */,
+ 1F027FA911A7BEAF006B06DE /* OverlayView.h */,
+ 1F027FAA11A7BEAF006B06DE /* OverlayView.m */,
E5345A00119876A5000CB77F /* Actions */,
E53459EF119876A5000CB77F /* ParsedResults */,
E53459D4119876A5000CB77F /* ResultParsers */,
@@ -1144,7 +1144,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 3.1.3;
OTHER_LDFLAGS = "-ObjC";
PREBINDING = NO;
- SDKROOT = iphoneos3.1.3;
+ SDKROOT = iphoneos4.0;
};
name = Debug;
};
@@ -1158,7 +1158,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 3.1.3;
OTHER_LDFLAGS = "-ObjC";
PREBINDING = NO;
- SDKROOT = iphoneos3.1.3;
+ SDKROOT = iphoneos4.0;
};
name = Release;
};
--
Multi-format 1D/2D barcode image processing library
More information about the Pkg-google-commits
mailing list