cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lorinb...@apache.org
Subject [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
Date Tue, 26 Mar 2013 20:31:16 GMT
Updated Branches:
  refs/heads/2.6.x b586157fa -> fda308b3b


[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/99a1cc92
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/99a1cc92
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/99a1cc92

Branch: refs/heads/2.6.x
Commit: 99a1cc92d016607065ea44b0ace89f58f2239f99
Parents: b586157
Author: lorinbeer <lorin@adobe.com>
Authored: Mon Mar 25 16:42:26 2013 -0700
Committer: lorinbeer <lorin@adobe.com>
Committed: Tue Mar 26 13:30:36 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/99a1cc92/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/99a1cc92/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


Mime
View raw message