You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/02/12 04:14:33 UTC

[10/13] ios commit: [CB-2213] Skipped image scaling when possible.

[CB-2213] Skipped image scaling when possible.

Image scaling/conversion is skippable when we're returning a native URI (eg. assets-library://).


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/c71f9e6b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/c71f9e6b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/c71f9e6b

Branch: refs/heads/master
Commit: c71f9e6b49ab92e46e5ebd4995698521ebabb594
Parents: 5b09c79
Author: Max Woghiren <ma...@gmail.com>
Authored: Wed Jan 23 16:54:38 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Mon Feb 11 21:06:24 2013 -0500

----------------------------------------------------------------------
 CordovaLib/Classes/CDVCamera.m |  100 ++++++++++++++++++-----------------
 1 files changed, 51 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c71f9e6b/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index 4cf5c82..22aca98 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -232,66 +232,68 @@ static NSSet* org_apache_cordova_validArrowDirections;
     NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
     // IMAGE TYPE
     if ([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
-        // get the image
-        UIImage* image = nil;
-        if (cameraPicker.allowsEditing && [info objectForKey:UIImagePickerControllerEditedImage]) {
-            image = [info objectForKey:UIImagePickerControllerEditedImage];
+        if (cameraPicker.returnType == DestinationTypeNativeUri) {
+            NSString* nativeUri = [(NSURL*)[info objectForKey:UIImagePickerControllerReferenceURL] absoluteString];
+            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nativeUri];
         } else {
-            image = [info objectForKey:UIImagePickerControllerOriginalImage];
-        }
+            // get the image
+            UIImage* image = nil;
+            if (cameraPicker.allowsEditing && [info objectForKey:UIImagePickerControllerEditedImage]) {
+                image = [info objectForKey:UIImagePickerControllerEditedImage];
+            } else {
+                image = [info objectForKey:UIImagePickerControllerOriginalImage];
+            }
 
-        if (cameraPicker.saveToPhotoAlbum) {
-            UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
-        }
+            if (cameraPicker.saveToPhotoAlbum) {
+                UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
+            }
 
-        if (cameraPicker.correctOrientation) {
-            image = [self imageCorrectedForCaptureOrientation:image];
-        }
+            if (cameraPicker.correctOrientation) {
+                image = [self imageCorrectedForCaptureOrientation:image];
+            }
 
-        UIImage* scaledImage = nil;
+            UIImage* scaledImage = nil;
 
-        if ((cameraPicker.targetSize.width > 0) && (cameraPicker.targetSize.height > 0)) {
-            // if cropToSize, resize image and crop to target size, otherwise resize to fit target without cropping
-            if (cameraPicker.cropToSize) {
-                scaledImage = [self imageByScalingAndCroppingForSize:image toSize:cameraPicker.targetSize];
-            } else {
-                scaledImage = [self imageByScalingNotCroppingForSize:image toSize:cameraPicker.targetSize];
+            if ((cameraPicker.targetSize.width > 0) && (cameraPicker.targetSize.height > 0)) {
+                // if cropToSize, resize image and crop to target size, otherwise resize to fit target without cropping
+                if (cameraPicker.cropToSize) {
+                    scaledImage = [self imageByScalingAndCroppingForSize:image toSize:cameraPicker.targetSize];
+                } else {
+                    scaledImage = [self imageByScalingNotCroppingForSize:image toSize:cameraPicker.targetSize];
+                }
             }
-        }
 
-        NSData* data = nil;
+            NSData* data = nil;
 
-        if (cameraPicker.encodingType == EncodingTypePNG) {
-            data = UIImagePNGRepresentation(scaledImage == nil ? image : scaledImage);
-        } else {
-            data = UIImageJPEGRepresentation(scaledImage == nil ? image : scaledImage, cameraPicker.quality / 100.0f);
-        }
+            if (cameraPicker.encodingType == EncodingTypePNG) {
+                data = UIImagePNGRepresentation(scaledImage == nil ? image : scaledImage);
+            } else {
+                data = UIImageJPEGRepresentation(scaledImage == nil ? image : scaledImage, cameraPicker.quality / 100.0f);
+            }
 
-        if (cameraPicker.returnType == DestinationTypeFileUri) {
-            // write to temp directory and return URI
-            // get the temp directory path
-            NSString* docsPath = [NSTemporaryDirectory ()stringByStandardizingPath];
-            NSError* err = nil;
-            NSFileManager* fileMgr = [[NSFileManager alloc] init]; // recommended by apple (vs [NSFileManager defaultManager]) to be threadsafe
-            // generate unique file name
-            NSString* filePath;
-
-            int i = 1;
-            do {
-                filePath = [NSString stringWithFormat:@"%@/%@%03d.%@", docsPath, CDV_PHOTO_PREFIX, i++, cameraPicker.encodingType == EncodingTypePNG ? @"png":@"jpg"];
-            } while ([fileMgr fileExistsAtPath:filePath]);
-
-            // save file
-            if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
-                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
+            if (cameraPicker.returnType == DestinationTypeFileUri) {
+                // write to temp directory and return URI
+                // get the temp directory path
+                NSString* docsPath = [NSTemporaryDirectory ()stringByStandardizingPath];
+                NSError* err = nil;
+                NSFileManager* fileMgr = [[NSFileManager alloc] init]; // recommended by apple (vs [NSFileManager defaultManager]) to be threadsafe
+                // generate unique file name
+                NSString* filePath;
+
+                int i = 1;
+                do {
+                    filePath = [NSString stringWithFormat:@"%@/%@%03d.%@", docsPath, CDV_PHOTO_PREFIX, i++, cameraPicker.encodingType == EncodingTypePNG ? @"png":@"jpg"];
+                } while ([fileMgr fileExistsAtPath:filePath]);
+
+                // save file
+                if (![data writeToFile:filePath options:NSAtomicWrite error:&err]) {
+                    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_IO_EXCEPTION messageAsString:[err localizedDescription]];
+                } else {
+                    result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[[NSURL fileURLWithPath:filePath] absoluteString]];
+                }
             } else {
-                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[[NSURL fileURLWithPath:filePath] absoluteString]];
+                result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[data base64EncodedString]];
             }
-        } else if (cameraPicker.returnType == DestinationTypeNativeUri) {
-            NSString* nativeUri = [(NSURL*)[info objectForKey:UIImagePickerControllerReferenceURL] absoluteString];
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nativeUri];
-        } else {
-            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:[data base64EncodedString]];
         }
     }
     // NOT IMAGE TYPE (MOVIE)