You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2013/03/23 01:05:14 UTC

[04/13] ios commit: [CB-1285] added support for additional metadata provided by camera in iOS updates, tested and refined rational approximation algorith, added support for additional datatypes

[CB-1285] added support for additional metadata provided by camera in iOS updates, tested and refined rational approximation algorith, added support for additional datatypes


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

Branch: refs/heads/master
Commit: fbebe8f73ac9c467d529ac6bec073a7b2502a688
Parents: a5b8e24
Author: lorinbeer <lo...@adobe.com>
Authored: Wed Mar 20 21:37:31 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Wed Mar 20 21:37:31 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVJpegHeaderWriter.h |   11 ++-
 CordovaLib/Classes/CDVJpegHeaderWriter.m |  131 ++++++++++++++++++-------
 2 files changed, 103 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/fbebe8f7/CordovaLib/Classes/CDVJpegHeaderWriter.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.h b/CordovaLib/Classes/CDVJpegHeaderWriter.h
index b732c32..07f6b2c 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.h
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.h
@@ -37,10 +37,11 @@
                                        withPlaces: (NSNumber*) width;
 - (NSString*) formatNumberWithLeadingZeroes: (NSNumber*) numb 
                                  withPlaces: (NSNumber*) places;
+- (NSString*) decimalToUnsignedRational: (NSNumber*) numb
+                    withResultNumerator: (NSNumber**) numerator
+                  withResultDenominator: (NSNumber**) denominator;
 
-- (NSString*) decimalToUnsignedRational: (NSNumber*) numb;
-
-- (void) continuedFraction: (double) val 
+- (void) continuedFraction: (double) val
           withFractionList: (NSMutableArray*) fractionlist 
                withHorizon: (int) horizon;
 - (void) expandContinuedFraction: (NSArray*) fractionlist;
@@ -48,6 +49,10 @@
          withIntComponent: (int*) rightside 
          withFloatRemainder: (double*) leftside;
 
+- (NSString*) formatRationalWithNumerator: (NSNumber*) numerator
+                          withDenominator: (NSNumber*) denominator
+                               asSigned: (Boolean) signedFlag;
+
 /*
 - (void) readExifMetaData : (NSData*) imgdata;
 - (void) spliceImageData : (NSData*) imgdata withExifData: (NSDictionary*) exifdata;

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/fbebe8f7/CordovaLib/Classes/CDVJpegHeaderWriter.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.m b/CordovaLib/Classes/CDVJpegHeaderWriter.m
index 1a8fc2a..be35721 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.m
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.m
@@ -79,28 +79,34 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
 
     // supported tages for exif subIFD
     SubIFDTagFormatDict = [[NSDictionary alloc] initWithObjectsAndKeys:
-                        TAGINF(@"829a", [NSNumber numberWithInt:EDT_URATIONAL], @1), @"ExposureTime",
-                        TAGINF(@"829d", [NSNumber numberWithInt:EDT_URATIONAL], @1), @"FNumber",
-                        TAGINF(@"8822", [NSNumber numberWithInt:EDT_USHORT], @1), @"ExposureProgram",
-                        TAGINF(@"8827", [NSNumber numberWithInt:EDT_USHORT], @2), @"ISOSpeedRatings",
                           // TAGINF(@"9000", [NSNumber numberWithInt:], @), @"ExifVersion",
-                          TAGINF(@"9004",[NSNumber numberWithInt:EDT_ASCII_STRING],@20), @"DateTimeDigitized",
-                          TAGINF(@"9003",[NSNumber numberWithInt:EDT_ASCII_STRING],@20), @"DateTimeOriginal",
-                          TAGINF(@"9207", [NSNumber numberWithInt:EDT_USHORT], @1), @"MeteringMode",
-                          TAGINF(@"9209", [NSNumber numberWithInt:EDT_USHORT], @1), @"Flash",
-                          TAGINF(@"920a", [NSNumber numberWithInt:EDT_URATIONAL], @1), @"FocalLength",
-                          TAGINF(@"920a", [NSNumber numberWithInt:EDT_URATIONAL], @1), @"FocalLength",
-                //      TAGINF(@"9202",[NSNumber numberWithInt:EDT_URATIONAL],@1), @"ApertureValue",
-                //      TAGINF(@"9203",[NSNumber numberWithInt:EDT_SRATIONAL],@1), @"BrightnessValue",
-                         TAGINF(@"a001",[NSNumber numberWithInt:EDT_USHORT],@1), @"ColorSpace",
-                         TAGINF(@"8822", [NSNumber numberWithInt:EDT_USHORT], @1), @"ExposureProgram",
-        //              @"PixelXDimension", [[NSDictionary alloc] initWithObjectsAndKeys: @"code", @"a002", nil],
-        //              @"PixelYDimension", [[NSDictionary alloc] initWithObjectsAndKeys: @"code", @"a003", nil],
-        //              @"SceneType", [[NSDictionary alloc] initWithObjectsAndKeys: @"code", @"a301", nil],
-        //              @"SensingMethod", [[NSDictionary alloc] initWithObjectsAndKeys: @"code", @"a217", nil],
-        //              @"Sharpness", [[NSDictionary alloc] initWithObjectsAndKeys: @"code", @"a40A", nil],
+                           // TAGINF(@"9202",[NSNumber numberWithInt:EDT_URATIONAL],@1), @"ApertureValue",
+                           // TAGINF(@"9203",[NSNumber numberWithInt:EDT_SRATIONAL],@1), @"BrightnessValue",
+                           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(@"829a", [NSNumber numberWithInt:EDT_URATIONAL], @1), @"ExposureTime",
+                           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(@"920a", [NSNumber numberWithInt:EDT_URATIONAL], @1), @"FocalLength",
+
+                           //TAGINF(@"8827", [NSNumber numberWithInt:EDT_USHORT], @2), @"ISOSpeedRatings",
+
+                           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",
+                           // 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(@"9201", [NSNumber numberWithInt:EDT_SRATIONAL], @1), @"ShutterSpeedValue",
-        //              @"WhiteBalance", [[NSDictionary alloc] initWithObjectsAndKeys: @"code", @"a403", nil],
+                           // 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",
                       nil];
     return self;
 }
@@ -266,6 +272,8 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
     NSMutableString * datastr = nil;
     NSNumber * tmp = nil;
     NSNumber * formatcode = [dataformat objectAtIndex:1];
+    NSNumber * num = @0;
+    NSNumber * denom = @0;
     
     switch ([formatcode intValue]) {
         case EDT_UBYTE:
@@ -289,12 +297,16 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
             return [NSString stringWithFormat : @"%@",
                     [self formattedHexStringFromDecimalNumber: tmp withPlaces: @8]];
         case EDT_URATIONAL:
-            return [self decimalToUnsignedRational: [NSNumber numberWithDouble:[data doubleValue]]];
+            return [self decimalToUnsignedRational: [NSNumber numberWithDouble:[data doubleValue]]
+                               withResultNumerator: &num
+                             withResultDenominator: &denom];
         case EDT_SBYTE:
+            
             break;
         case EDT_UNDEFINED:
             break;     // 8 bits
         case EDT_SSHORT:
+            
             break;
         case EDT_SLONG:
             break;          // 32bit signed integer (2's complement)
@@ -329,23 +341,47 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
 }
 
 // approximate a decimal with a rational by method of continued fraction
-/*
-- (void) decimalToRational: (NSNumber *) numb: (NSNumber *) numerator: (NSNumber*) denominator {
-    numerator = [NSNumber numberWithLong: 1];
-    denominator = [NSNumber numberWithLong: 1];
+// can be collasped into decimalToUnsignedRational after testing
+- (void) decimalToRational: (NSNumber *) numb
+       withResultNumerator: (NSNumber**) numerator
+     withResultDenominator: (NSNumber**) denominator {
+    NSMutableArray * fractionlist = [[NSMutableArray alloc] initWithCapacity:8];
+    
+    [self continuedFraction: [numb doubleValue]
+           withFractionList: fractionlist
+                withHorizon: 8];
+    
+    // simplify complex fraction represented by partial fraction list
+    [self expandContinuedFraction: fractionlist
+              withResultNumerator: numerator
+            withResultDenominator: denominator];
+
 }
-*/
 
 // approximate a decimal with an unsigned rational by method of continued fraction
-- (NSString*) decimalToUnsignedRational: (NSNumber *) numb {
+- (NSString*) decimalToUnsignedRational: (NSNumber *) numb
+                          withResultNumerator: (NSNumber**) numerator
+                        withResultDenominator: (NSNumber**) denominator {
     NSMutableArray * fractionlist = [[NSMutableArray alloc] initWithCapacity:8];
-    [self continuedFraction: [numb doubleValue] withFractionList:fractionlist withHorizon:8];
-    [self expandContinuedFraction: fractionlist];
+    
+    // generate partial fraction list
+    [self continuedFraction: [numb doubleValue]
+           withFractionList: fractionlist
+                withHorizon: 8];
+    
+    // simplify complex fraction represented by partial fraction list
+    [self expandContinuedFraction: fractionlist
+              withResultNumerator: numerator
+            withResultDenominator: denominator];
+    
+    NSLog(@"%@ %d %d %@", @"Hi Int values", [*numerator intValue], [*denominator intValue],[fractionlist description]);
     return [self formatFractionList: fractionlist];
 }
 
 // recursive implementation of decimal approximation by continued fraction
-- (void) continuedFraction: (double) val withFractionList: (NSMutableArray*) fractionlist withHorizon: (int) horizon {
+- (void) continuedFraction: (double) val
+          withFractionList: (NSMutableArray*) fractionlist
+               withHorizon: (int) horizon {
     int whole;
     double remainder;
     // 1. split term
@@ -367,18 +403,26 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
 }
 
 // expand continued fraction list, creating a single level rational approximation
--(void) expandContinuedFraction: (NSArray*) fractionlist {
+-(void) expandContinuedFraction: (NSArray*) fractionlist
+                  withResultNumerator: (NSNumber**) numerator
+                withResultDenominator: (NSNumber**) denominator {
     int i = 0;
     int den = 0;
     int num = 0;
-
+    NSLog(@"%@",[fractionlist description]);
+    if ([fractionlist count] == 1) {
+        *numerator = [NSNumber numberWithInt:[[fractionlist objectAtIndex:0] intValue]];
+        *denominator = @1;
+        return;
+    }
+    
     //begin at the end of the list
     i = [fractionlist count] - 1;
     num = 1;
-    den = [fractionlist objectAtIndex:i];
+    den = [[fractionlist objectAtIndex:i] intValue];
     
     while (i > 0) {
-        int t = [fractionlist objectAtIndex: i-1];
+        int t = [[fractionlist objectAtIndex: i-1] intValue];
         num = t * den + num;
         if (i==1) {
             break;
@@ -389,8 +433,9 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
         }
         i--;
     }
-    
-    NSLog(@"%d %d",den,num);
+    // set result parameters values
+    *numerator = [NSNumber numberWithInt: num];
+    *denominator = [NSNumber numberWithInt: den];
 }
 
 // formats expanded fraction list to string matching exif specification
@@ -403,6 +448,20 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
     return str;
 }
 
+// format rational as
+- (NSString*) formatRationalWithNumerator: (NSNumber*) numerator withDenominator: (NSNumber*) denominator asSigned: (Boolean) signedFlag {
+    NSMutableString * str = [[NSMutableString alloc] initWithCapacity:16];
+    if (signedFlag) {
+        NSLog(@"Formatting as SIGNED rational");
+        long num = [numerator longValue];
+        long den = [denominator longValue];
+        [str appendFormat: @"%08lx%08lx", num >= 0 ? num : ~ABS(num) + 1, num >= 0 ? den : ~ABS(den) + 1];
+    } else {
+        [str appendFormat: @"%08lx%08lx", [numerator unsignedLongValue], [denominator unsignedLongValue]];
+    }
+    return str;
+}
+
 // split a floating point number into two integer values representing the left and right side of the decimal
 - (void) splitDouble: (double) val withIntComponent: (int*) rightside withFloatRemainder: (double*) leftside {
     *rightside = val; // convert numb to int representation, which truncates the decimal portion