cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lorinb...@apache.org
Subject [1/3] ios commit: [CB-2896] fixed error in exif subifd offset calculation for tag 8769
Date Wed, 03 Apr 2013 16:25:05 GMT
Updated Branches:
  refs/heads/master 850c4bd62 -> 997359f0a


[CB-2896] fixed error in exif subifd offset calculation for tag 8769


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

Branch: refs/heads/master
Commit: deb60d86af34a2124a00092916e6395b4594c9ab
Parents: c08e414
Author: lorinbeer <lorin@adobe.com>
Authored: Tue Apr 2 17:33:11 2013 -0700
Committer: lorinbeer <lorin@adobe.com>
Committed: Tue Apr 2 17:33:11 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVJpegHeaderWriter.m |   65 +++++++++++++------------
 1 files changed, 34 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/deb60d86/CordovaLib/Classes/CDVJpegHeaderWriter.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.m b/CordovaLib/Classes/CDVJpegHeaderWriter.m
index 0c15d74..6118c30 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.m
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.m
@@ -38,14 +38,14 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits
are 0x002a
     // supported tags for exif IFD
     IFD0TagFormatDict = [[NSDictionary alloc] initWithObjectsAndKeys:
                   //      TAGINF(@"010e", [NSNumber numberWithInt:EDT_ASCII_STRING], @0),
@"ImageDescription",
-                        TAGINF(@"0132", [NSNumber numberWithInt:EDT_ASCII_STRING], @20),
@"DateTime",
-                        TAGINF(@"010f", [NSNumber numberWithInt:EDT_ASCII_STRING], @0), @"Make",
-                        TAGINF(@"0110", [NSNumber numberWithInt:EDT_ASCII_STRING], @0), @"Model",
-                        TAGINF(@"0131", [NSNumber numberWithInt:EDT_ASCII_STRING], @0), @"Software",
+    //                    TAGINF(@"0132", [NSNumber numberWithInt:EDT_ASCII_STRING], @20),
@"DateTime",
+    //                    TAGINF(@"010f", [NSNumber numberWithInt:EDT_ASCII_STRING], @0),
@"Make",
+    //                    TAGINF(@"0110", [NSNumber numberWithInt:EDT_ASCII_STRING], @0),
@"Model",
+    //                    TAGINF(@"0131", [NSNumber numberWithInt:EDT_ASCII_STRING], @0),
@"Software",
                         TAGINF(@"011a", [NSNumber numberWithInt:EDT_URATIONAL], @1), @"XResolution",
                         TAGINF(@"011b", [NSNumber numberWithInt:EDT_URATIONAL], @1), @"YResolution",
                         // currently supplied outside of Exif data block by UIImagePickerControllerMediaMetadata,
this is set manually in CDVCamera.m
-                        TAGINF(@"0112", [NSNumber numberWithInt:EDT_USHORT], @1), @"Orientation",
+    /*                    TAGINF(@"0112", [NSNumber numberWithInt:EDT_USHORT], @1), @"Orientation",
                        
                         // rest of the tags are supported by exif spec, but are not specified
by UIImagePickerControllerMediaMedadata
                         // should camera hardware supply these values in future versions,
or if they can be derived, ImageHeaderWriter will include them gracefully
@@ -58,7 +58,7 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are
0x002a
                         TAGINF(@"8298", [NSNumber numberWithInt:EDT_URATIONAL], @0), @"Copyright",
                          
                         // offset to exif subifd, we determine this dynamically based on
the size of the main exif IFD
-                        TAGINF(@"8769", [NSNumber numberWithInt:EDT_ULONG], @1), @"ExifOffset",
+                        TAGINF(@"8769", [NSNumber numberWithInt:EDT_ULONG], @1), @"ExifOffset",*/
                         nil];
 
 
@@ -70,26 +70,26 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits
are 0x002a
                            TAGINF(@"a001",[NSNumber numberWithInt:EDT_USHORT],@1), @"ColorSpace",
                            //TAGINF(@"9004",[NSNumber numberWithInt:EDT_ASCII_STRING],@20),
@"DateTimeDigitized",
                            //TAGINF(@"9003",[NSNumber numberWithInt:EDT_ASCII_STRING],@20),
@"DateTimeOriginal",
-                           TAGINF(@"a402", [NSNumber numberWithInt:EDT_USHORT], @1), @"ExposureMode",
-                           TAGINF(@"8822", [NSNumber numberWithInt:EDT_USHORT], @1), @"ExposureProgram",
+             //              TAGINF(@"a402", [NSNumber numberWithInt:EDT_USHORT], @1), @"ExposureMode",
+             //              TAGINF(@"8822", [NSNumber numberWithInt:EDT_USHORT], @1), @"ExposureProgram",
                            //                     TAGINF(@"829a", [NSNumber numberWithInt:EDT_URATIONAL],
@1), @"ExposureTime",
-                           //          TAGINF(@"829d", [NSNumber numberWithInt:EDT_URATIONAL],
@1), @"FNumber",
-                           TAGINF(@"9209", [NSNumber numberWithInt:EDT_USHORT], @1), @"Flash",
+                           //TAGINF(@"829d", [NSNumber numberWithInt:EDT_URATIONAL], @1),
@"FNumber",
+              //             TAGINF(@"9209", [NSNumber numberWithInt:EDT_USHORT], @1), @"Flash",
                            // FocalLengthIn35mmFilm
-                           TAGINF(@"a405", [NSNumber numberWithInt:EDT_USHORT], @1), @"FocalLenIn35mmFilm",
+               //            TAGINF(@"a405", [NSNumber numberWithInt:EDT_USHORT], @1), @"FocalLenIn35mmFilm",
                            //                         TAGINF(@"920a", [NSNumber numberWithInt:EDT_URATIONAL],
@1), @"FocalLength",
                            // TAGINF(@"8827", [NSNumber numberWithInt:EDT_USHORT], @2), @"ISOSpeedRatings",
-                           TAGINF(@"9207", [NSNumber numberWithInt:EDT_USHORT],@1), @"MeteringMode",
+                //           TAGINF(@"9207", [NSNumber numberWithInt:EDT_USHORT],@1), @"MeteringMode",
                            // specific to compressed data
-                           TAGINF(@"a002", [NSNumber numberWithInt:EDT_ULONG],@1), @"PixelXDimension",
-                           TAGINF(@"a003", [NSNumber numberWithInt:EDT_ULONG],@1), @"PixelYDimension",
+                 //          TAGINF(@"a002", [NSNumber numberWithInt:EDT_ULONG],@1), @"PixelXDimension",
+                 //          TAGINF(@"a003", [NSNumber numberWithInt:EDT_ULONG],@1), @"PixelYDimension",
                            // data type undefined, but this is a DSC camera, so value is
always 1, treat as ushort
-                           TAGINF(@"a301", [NSNumber numberWithInt:EDT_USHORT],@1), @"SceneType",
-                           TAGINF(@"a217",[NSNumber numberWithInt:EDT_USHORT],@1), @"SensingMethod",
+                  //         TAGINF(@"a301", [NSNumber numberWithInt:EDT_USHORT],@1), @"SceneType",
+                  //         TAGINF(@"a217",[NSNumber numberWithInt:EDT_USHORT],@1), @"SensingMethod",
                            // TAGINF(@"9201", [NSNumber numberWithInt:EDT_SRATIONAL], @1),
@"ShutterSpeedValue",
                            // specifies location of main subject in scene (x,y,wdith,height)
expressed before rotation processing
                            // TAGINF(@"9214", [NSNumber numberWithInt:EDT_USHORT], @4), @"SubjectArea",
-                           TAGINF(@"a403", [NSNumber numberWithInt:EDT_USHORT], @1), @"WhiteBalance",
+                   //        TAGINF(@"a403", [NSNumber numberWithInt:EDT_USHORT], @1), @"WhiteBalance",
                            nil];
     return self;
 }
@@ -173,11 +173,14 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits
are 0x002a
 
     //data labeled as EXIF in UIImagePickerControllerMediaMetaData is part of the EXIF Sub
IFD portion of APP1
     subExifIFD = [self createExifIFDFromDict: [datadict objectForKey:@"{Exif}"] withFormatDict:
SubIFDTagFormatDict isIFD0:NO];
-
+    NSLog(@"SUB EXIF IFD %@  WITH SIZE: %d",exifIFD,[exifIFD length]);
+    
+    NSLog(@"SUB EXIF IFD %@  WITH SIZE: %d",subExifIFD,[subExifIFD length]);
+    
     // construct the complete app1 data block
     app1 = [[NSMutableString alloc] initWithFormat: @"%@%04x%@%@%@%@%@",
             app1marker,
-            16+[exifIFD length]/2+[subExifIFD length]/2/*16+[exifIFD length]/2*/,
+            16 + ([exifIFD length]/2) + ([subExifIFD length]/2) /*16+[exifIFD length]/2*/,
             exifmarker,
             tiffheader,
             ifd0offset,
@@ -193,7 +196,7 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits
are 0x002a
     NSArray * knownkeys = [formatdict  allKeys]; // only keys in knowkeys are considered
for entry in this IFD
     NSMutableArray * ifdblock = [[NSMutableArray alloc] initWithCapacity: [datadict count]];
// all ifd entries
     NSMutableArray * ifddatablock = [[NSMutableArray alloc] initWithCapacity: [datadict count]];
// data block entries
-    ifd0flag = NO; // ifd0 requires a special flag and has offset to next ifd appended to
end
+ //   ifd0flag = NO; // ifd0 requires a special flag and has offset to next ifd appended
to end
     
     // iterate through known provided data keys
     for (int i = 0; i < [datakeys count]; i++) {
@@ -202,7 +205,7 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits
are 0x002a
         if ([knownkeys indexOfObject: key] != NSNotFound) {
             // create new IFD entry
             NSString * entry = [self  createIFDElement: key
-                                      withFormatDict: formatdict
+                                            withFormat: [formatdict objectForKey:key]
                                       withElementData: [datadict objectForKey:key]];
             // create the IFD entry's data block
             NSString * data = [self createIFDElementDataWithFormat: [formatdict objectForKey:key]
@@ -248,7 +251,8 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits
are 0x002a
     // calculate IFD0 terminal offset tags, currently ExifSubIFD
     int entrycount = [ifdblock count];
     if (ifd0flag) {
-        NSNumber * offset = [NSNumber numberWithInt:[exifstr length] / 2 + [dbstr length]
/ 2 ];
+        // 18 accounts for 8769's width + offset to next ifd, 6 accounts for start of header
+        NSNumber * offset = [NSNumber numberWithInt:[exifstr length] / 2 + [dbstr length]
/ 2 + 18+6];
         
         [self appendExifOffsetTagTo: exifstr
                         withOffset : offset];
@@ -262,18 +266,18 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits
are 0x002a
 }
 
 // Creates an exif formatted exif information file directory entry
-- (NSString*) createIFDElement: (NSString*) elementName withFormatDict : (NSDictionary*)
formatdict withElementData : (NSString*) data  {
-    NSArray * fielddata = [formatdict objectForKey: elementName];// format data of desired
field
-    if (fielddata) {
+- (NSString*) createIFDElement: (NSString*) elementName withFormat: (NSArray*) formtemplate
withElementData: (NSString*) data  {
+    //NSArray * fielddata = [formatdict objectForKey: elementName];// format data of desired
field
+    if (formtemplate) {
         // format string @"%@%@%@%@", tag number, data format, components, value
-        NSNumber * dataformat = [fielddata objectAtIndex:1];
-        NSNumber * components = [fielddata objectAtIndex:2];
+        NSNumber * dataformat = [formtemplate objectAtIndex:1];
+        NSNumber * components = [formtemplate objectAtIndex:2];
         if([components intValue] == 0) {
             components = [NSNumber numberWithInt: [data length] * DataTypeToWidth[[dataformat
intValue]-1]];            
         }
 
         return [[NSString alloc] initWithFormat: @"%@%@%08x",
-                                                [fielddata objectAtIndex:0], // the field
code
+                                                [formtemplate objectAtIndex:0], // the field
code
                                                 [self formatNumberWithLeadingZeroes: dataformat
withPlaces: @4], // the data type code
                                                 [components intValue]]; // number of components
     }
@@ -289,7 +293,7 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits
are 0x002a
     NSArray * format = TAGINF(@"8769", [NSNumber numberWithInt:EDT_ULONG], @1);
     
     NSString * entry = [self  createIFDElement: @"ExifOffset"
-                                withFormatDict: IFD0TagFormatDict
+                                withFormat: format
                                withElementData: [offset stringValue]];
     
     NSString * data = [self createIFDElementDataWithFormat: format
@@ -321,7 +325,7 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits
are 0x002a
         case EDT_USHORT:
             return [[NSString alloc] initWithFormat : @"%@%@",
                     [self formattedHexStringFromDecimalNumber: [NSNumber numberWithInt: [data
intValue]] withPlaces: @4],
-                    @"00000000"];
+                    @"0000"];
         case EDT_ULONG:
             tmp = [NSNumber numberWithUnsignedLong:[data intValue]];
             return [NSString stringWithFormat : @"%@",
@@ -336,7 +340,6 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits
are 0x002a
         case EDT_UNDEFINED:
             break;     // 8 bits
         case EDT_SSHORT:
-            
             break;
         case EDT_SLONG:
             break;          // 32bit signed integer (2's complement)


Mime
View raw message