You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/03/26 21:26:13 UTC
[1/2] ios commit: [CB-2790] added splice function to header writer:
accepts jpeg as NSData, and splices in exif data specified by a string
Updated Branches:
refs/heads/master 9a6a68948 -> 3e007c35f
[CB-2790] added splice function to header writer: accepts jpeg as NSData, and splices in exif data specified by a string
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/e078f628
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/e078f628
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/e078f628
Branch: refs/heads/master
Commit: e078f62853be7b45d9c39887e142b7fc1d2499aa
Parents: 9a6a689
Author: lorinbeer <lo...@adobe.com>
Authored: Mon Mar 25 16:42:26 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Mon Mar 25 16:42:26 2013 -0700
----------------------------------------------------------------------
CordovaLib/Classes/CDVJpegHeaderWriter.h | 2 +
CordovaLib/Classes/CDVJpegHeaderWriter.m | 47 +++++++++++++++++++++++++
2 files changed, 49 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/e078f628/CordovaLib/Classes/CDVJpegHeaderWriter.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.h b/CordovaLib/Classes/CDVJpegHeaderWriter.h
index 02fe91f..3b43ef0 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.h
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.h
@@ -24,6 +24,8 @@
NSDictionary * IFD0TagFormatDict;
}
+- (NSData*) spliceExifBlockIntoJpeg: (NSData*) jpegdata
+ withExifBlock: (NSString*) exifstr;
- (NSString*) createExifAPP1 : (NSDictionary*) datadict;
- (NSString*) formattedHexStringFromDecimalNumber: (NSNumber*) numb
withPlaces: (NSNumber*) width;
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/e078f628/CordovaLib/Classes/CDVJpegHeaderWriter.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.m b/CordovaLib/Classes/CDVJpegHeaderWriter.m
index 7b59d11..81172ee 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.m
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.m
@@ -95,6 +95,53 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
return self;
}
+- (NSData*) spliceExifBlockIntoJpeg: (NSData*) jpegdata withExifBlock: (NSString*) exifstr {
+
+ CDVJpegHeaderWriter * exifWriter = [[CDVJpegHeaderWriter alloc] init];
+
+ NSMutableData * exifdata = [NSMutableData dataWithCapacity: [exifstr length]/2];
+ int idx;
+ for (idx = 0; idx+1 < [exifstr length]; idx+=2) {
+ NSRange range = NSMakeRange(idx, 2);
+ NSString* hexStr = [exifstr substringWithRange:range];
+ NSScanner* scanner = [NSScanner scannerWithString:hexStr];
+ unsigned int intValue;
+ [scanner scanHexInt:&intValue];
+ [exifdata appendBytes:&intValue length:1];
+ }
+
+ NSMutableData * ddata = [NSMutableData dataWithCapacity: [jpegdata length]];
+ NSMakeRange(0,4);
+ int loc = 0;
+ bool done = false;
+ // read the jpeg data until we encounter the app1==0xFFE1 marker
+ while (loc+1 < [jpegdata length]) {
+ NSData * blag = [jpegdata subdataWithRange: NSMakeRange(loc,2)];
+ if( [[blag description] isEqualToString : @"<ffe1>"]) {
+ // read the APP1 block size bits
+ NSString * the = [exifWriter hexStringFromData:[jpegdata subdataWithRange: NSMakeRange(loc+2,2)]];
+ NSNumber * app1width = [exifWriter numericFromHexString:the];
+ //consume the original app1 block
+ [ddata appendData:exifdata];
+ // advance our loc marker past app1
+ loc += [app1width intValue] + 2;
+ done = true;
+ } else {
+ if(!done) {
+ [ddata appendData:blag];
+ loc += 2;
+ } else {
+ break;
+ }
+ }
+ }
+ // copy the remaining data
+ [ddata appendData:[jpegdata subdataWithRange: NSMakeRange(loc,[jpegdata length]-loc)]];
+ return ddata;
+}
+
+
+
/**
* Create the Exif data block as a hex string
* jpeg uses Application Markers (APP's) as markers for application data
[2/2] ios commit: [CB-2790] removed old splice code,
replaced with JpegHeaderWriter api calls
Posted by lo...@apache.org.
[CB-2790] removed old splice code, replaced with JpegHeaderWriter api calls
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/3e007c35
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/3e007c35
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/3e007c35
Branch: refs/heads/master
Commit: 3e007c35f59a00f436cd7000a72de8394758552b
Parents: e078f62
Author: lorinbeer <lo...@adobe.com>
Authored: Mon Mar 25 16:46:13 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Mon Mar 25 16:46:13 2013 -0700
----------------------------------------------------------------------
CordovaLib/Classes/CDVCamera.m | 43 ++--------------------------------
1 files changed, 3 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/3e007c35/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index ab1154e..c3e053e 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -300,48 +300,11 @@ static NSSet* org_apache_cordova_validArrowDirections;
} else {
data = UIImageJPEGRepresentation(scaledImage == nil ? image : scaledImage, cameraPicker.quality / 100.0f);
+ /* splice loc */
CDVJpegHeaderWriter * exifWriter = [[CDVJpegHeaderWriter alloc] init];
-
NSString * headerstring = [exifWriter createExifAPP1: [info objectForKey:@"UIImagePickerControllerMediaMetadata"]];
- NSMutableData * exifdata = [NSMutableData dataWithCapacity: [headerstring length]/2];
- int idx;
- for (idx = 0; idx+1 < [headerstring length]; idx+=2) {
- NSRange range = NSMakeRange(idx, 2);
- NSString* hexStr = [headerstring substringWithRange:range];
- NSScanner* scanner = [NSScanner scannerWithString:hexStr];
- unsigned int intValue;
- [scanner scanHexInt:&intValue];
- [exifdata appendBytes:&intValue length:1];
- }
-
- NSMutableData * ddata = [NSMutableData dataWithCapacity: [data length]];
- NSMakeRange(0,4);
- int loc = 0;
- bool done = false;
- // read the jpeg data until we encounter the app1==0xFFE1 marker
- while (loc+1 < [data length]) {
- NSData * blag = [data subdataWithRange: NSMakeRange(loc,2)];
- if( [[blag description] isEqualToString : @"<ffe1>"]) {
- // read the APP1 block size bits
- NSString * the = [exifWriter hexStringFromData:[data subdataWithRange: NSMakeRange(loc+2,2)]];
- NSNumber * app1width = [exifWriter numericFromHexString:the];
- //consume the original app1 block
- [ddata appendData:exifdata];
- // advance our loc marker past app1
- loc += [app1width intValue] + 2;
- done = true;
- } else {
- if(!done) {
- [ddata appendData:blag];
- loc += 2;
- } else {
- break;
- }
- }
- }
- // copy the remaining data
- [ddata appendData:[data subdataWithRange: NSMakeRange(loc,[data length]-loc)]];
- data = ddata;
+ data = [exifWriter spliceExifBlockIntoJpeg:data withExifBlock:headerstring];
+
}
if (cameraPicker.returnType == DestinationTypeFileUri) {