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:11 UTC

[01/13] ios commit: [CB-1285] initial commit of exif header writer source, with appropriate license, migrated from incubator repo

Updated Branches:
  refs/heads/master 268e85284 -> b586157fa


[CB-1285] initial commit of exif header writer source, with appropriate license, migrated from incubator repo


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

Branch: refs/heads/master
Commit: 7ea1e2d96d73149bde9592b5f24a25d6b9949869
Parents: 8e4a7ae
Author: doggerelverse <lo...@adobe.com>
Authored: Thu Mar 14 21:29:17 2013 -0700
Committer: doggerelverse <lo...@adobe.com>
Committed: Thu Mar 14 21:29:17 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVExif.h             |   83 ++++
 CordovaLib/Classes/CDVJpegHeaderWriter.h |   63 +++
 CordovaLib/Classes/CDVJpegHeaderWriter.m |  510 +++++++++++++++++++++++++
 3 files changed, 656 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7ea1e2d9/CordovaLib/Classes/CDVExif.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVExif.h b/CordovaLib/Classes/CDVExif.h
new file mode 100644
index 0000000..38e8ef5
--- /dev/null
+++ b/CordovaLib/Classes/CDVExif.h
@@ -0,0 +1,83 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+//
+//  ExifData.h
+//  CordovaLib
+//
+//  Created by Lorin Beer on 2012-10-04.
+//
+//
+
+#ifndef CordovaLib_ExifData_h
+#define CordovaLib_ExifData_h
+
+typedef enum exifDataTypes {
+    EDT_UBYTE = 1,      // 8 bit unsigned integer
+    EDT_ASCII_STRING,   // 8 bits containing 7 bit ASCII code, null terminated
+    EDT_USHORT,         // 16 bit unsigned integer
+    EDT_ULONG,          // 32 bit unsigned integer
+    EDT_URATIONAL,      // 2 longs, first is numerator and second is denominator
+    EDT_SBYTE,
+    EDT_UNDEFINED,      // 8 bits
+    EDT_SSHORT,
+    EDT_SLONG,          // 32bit signed integer (2's complement)
+    EDT_SRATIONAL,      // 2 SLONGS, first long is numerator, second is denominator
+    EDT_SINGLEFLOAT,
+    EDT_DOUBLEFLOAT
+} ExifDataTypes;
+
+typedef enum formatFields {
+    FF_CODE = 0,
+    FF_TYPE,
+    FF_COUNT
+} FormatFields;
+
+static const int DataTypeToWidth[] = {1,1,2,4,8,1,1,2,4,8,4,8};
+
+void repfracExpandPartialQuotients(int * arr, int n) {
+    int i = 0;
+    int nx = 0;
+    int numerator = 0;
+    int denominator = 0;
+    
+    denominator = arr[n-1];
+    numerator = arr[n-++i] * arr[n-++i];
+    for (;n-i>=0;i++) {
+        
+    }
+}
+
+void repfracExp(int i, int * arr, int s, int * numerator, int * denominator) {
+    int temp;
+    if (i == s-1) {
+        *numerator = 1;
+        *denominator = arr[i];
+    } else if (i != 0) {
+        temp = *denominator;
+        *denominator = arr[i] * (*denominator) + *numerator;
+        *numerator = temp;
+        repfracExp(i-1,arr,s,*numerator,*denominator);
+    } else {
+        return;
+    }
+    return;
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7ea1e2d9/CordovaLib/Classes/CDVJpegHeaderWriter.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.h b/CordovaLib/Classes/CDVJpegHeaderWriter.h
new file mode 100644
index 0000000..1b8bf48
--- /dev/null
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.h
@@ -0,0 +1,63 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+//
+//  CDVImageHeaderWriter.h
+//  CordovaLib
+//
+//  Created by Lorin Beer on 2012-10-02.
+//
+//
+
+#import <Foundation/Foundation.h>
+
+@interface CDVJpegHeaderWriter : NSObject {
+    NSDictionary * SubIFDTagFormatDict;
+    NSDictionary * IFD0TagFormatDict;
+}
+
+- (void) readExifMetaData : (NSData*) imgdata;
+- (void) insertExifMetaData : (NSData*) imgdata: (NSDictionary*) exifdata;
+- (void) locateExifMetaData : (NSData*) imgdata;
+/**
+ * creates an IFD field
+ * Bytes 0-1 Tag code
+ * Bytes 2-3 Data type
+ * Bytes 4-7 Count, number of elements of the given data type
+ * Bytes 8-11 Value/Offset
+ */
+
+- (NSString*) createExifAPP1 : (NSDictionary*) datadict;
+
+- (void) createExifDataString : (NSDictionary*) datadict;
+
+- (NSString*) createDataElement : (NSString*) element
+              withElementData: (NSString*) data
+              withExternalDataBlock: (NSDictionary*) memblock;
+
+- (NSString*) decimalToUnsignedRational: (NSNumber *) numb
+         outputNumerator: (NSNumber *) num
+         outputDenominator: (NSNumber*) deno;
+
+
+- (NSString*) hexStringFromData : (NSData*) data;
+
+- (NSNumber*) numericFromHexString : (NSString *) hexstring;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7ea1e2d9/CordovaLib/Classes/CDVJpegHeaderWriter.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.m b/CordovaLib/Classes/CDVJpegHeaderWriter.m
new file mode 100644
index 0000000..f176d07
--- /dev/null
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.m
@@ -0,0 +1,510 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+//
+//  CDVImageHeaderWriter.m
+//  CordovaLib
+//
+//  Created by Lorin Beer on 2012-10-02.
+//
+//
+
+#import "CDVJpegHeaderWriter.h"
+#include "CDVExif.h"
+
+#define IntWrap(x) [NSNumber numberWithInt:x]
+
+// tag info shorthand, tagno: tag number, typecode: data type:, components: number of components
+#define TAGINF(tagno, typecode, components) [NSArray arrayWithObjects: tagno, typecode, components, nil]
+
+
+const uint mJpegId = 0xffd8; // JPEG format marker
+const uint mExifMarker = 0xffe1; // APP1 jpeg header marker
+const uint mExif = 0x45786966; // ASCII 'Exif', first characters of valid exif header after size
+const uint mMotorallaByteAlign = 0x4d4d; // 'MM', motorola byte align, msb first or 'sane'
+const uint mIntelByteAlgin = 0x4949; // 'II', Intel byte align, lsb first or 'batshit crazy reverso world'
+const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a(MM) or 0x2a00(II), tiff version number
+
+
+@implementation CDVJpegHeaderWriter
+
+- (id) init {    
+    // 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(@"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",
+                       
+                        // 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
+                        TAGINF(@"0128", [NSNumber numberWithInt:EDT_USHORT], @1), @"ResolutionUnit",
+                        TAGINF(@"013e", [NSNumber numberWithInt:EDT_URATIONAL], @2), @"WhitePoint",
+                        TAGINF(@"013f", [NSNumber numberWithInt:EDT_URATIONAL], @6), @"PrimaryChromaticities",
+                        TAGINF(@"0211", [NSNumber numberWithInt:EDT_URATIONAL], @3), @"YCbCrCoefficients",
+                        TAGINF(@"0213", [NSNumber numberWithInt:EDT_USHORT], @1), @"YCbCrPositioning",
+                        TAGINF(@"0214", [NSNumber numberWithInt:EDT_URATIONAL], @6), @"ReferenceBlackWhite",
+                        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",
+                        nil];
+
+    // 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(@"9201", [NSNumber numberWithInt:EDT_SRATIONAL], @1), @"ShutterSpeedValue",
+        //              @"WhiteBalance", [[NSDictionary alloc] initWithObjectsAndKeys: @"code", @"a403", nil],
+                      nil];
+    return self;
+}
+
+/**
+ * Create the Exif data block as a hex string
+ *   jpeg uses Application Markers (APP's) as markers for application data
+ *   APP1 is the application marker reserved for exif data
+ *
+ *   (NSDictionary*) datadict - with subdictionaries marked '{TIFF}' and '{EXIF}' as returned by imagePickerController with a valid
+ *                              didFinishPickingMediaWithInfo data dict, under key @"UIImagePickerControllerMediaMetadata"
+ *
+ *   the following constructs a hex string to Exif specifications, and is therefore brittle
+ *   altering the order of arguments to the string constructors, modifying field sizes or formats,
+  *  and any other minor change will likely prevent the exif data from being read
+ */
+- (NSString*) createExifAPP1 : (NSDictionary*) datadict {
+    NSMutableString * app1; // holds finalized product
+    NSString * exifIFD; // exif information file directory
+    NSString * subExifIFD; // subexif information file directory
+    
+    // FFE1 is the hex APP1 marker code, and will allow client apps to read the data
+    NSString * app1marker = @"ffe1";
+    // SSSS size, to be determined
+    // EXIF ascii characters followed by 2bytes of zeros
+    NSString * exifmarker = @"457869660000";
+    // Tiff header: 4d4d is motorolla byte align (big endian), 002a is hex for 42
+    NSString * tiffheader = @"4d4d002a";
+    //first IFD offset from the Tiff header to IFD0. Since we are writing it, we know it's address 0x08
+    NSString * ifd0offset = @"00000008";
+    
+    //data labeled as TIFF in UIImagePickerControllerMediaMetaData is part of the EXIF IFD0 portion of APP1
+    exifIFD = [self createExifIFDFromDict: [datadict objectForKey:@"{TIFF}"] withFormatDict: IFD0TagFormatDict isIFD0:YES];
+
+    //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];
+  /*  app1 = [[NSString alloc] initWithFormat:@"%@%04x%@%@%@%@",
+                app1marker,
+                ([exif length]/2)+16,
+                exifmarker,
+                tiffheader,
+                ifd0offset,
+                exif];
+    
+    NSLog(@"%@",app1);*/
+    
+    /*
+     * constructing app1 segment:
+     * 2 byte marker: ffe1
+     * 2 byte size  : app1 size
+     * 6 byte exif marker : ascii string 'exif' followed by two bytes of zeroes
+     */
+    /*
+    app1 = [[[NSMutableString alloc] initWithFormat: @"%@%04x%@%@%@%@%@",
+            app1marker,
+            16+[exifIFD length]/2+[subExifIFD length]/2,
+            exifmarker,
+            tiffheader,
+            ifd0offset,
+            exifIFD,
+            subExifIFD];
+*/
+    NSLog(@"%@ \n %d",subExifIFD,[subExifIFD length]);
+    
+
+    app1 = [[NSMutableString alloc] initWithFormat: @"%@%04x%@%@%@%@",
+            app1marker,
+            16+[exifIFD length]/2 /*+[subExifIFD length]/2*/,
+            exifmarker,
+            tiffheader,
+            ifd0offset,
+            exifIFD];
+    
+    NSLog(@"%@",app1);
+    
+    return app1;
+}
+
+/**
+ * returns hex string representing a valid exif information file directory constructed from the datadict and formatdict
+ * datadict exif data entries encode into ifd
+ * formatdict specifies format of data entries and allowed entries in this ifd
+ */
+- (NSString*) createExifIFDFromDict : (NSDictionary*) datadict withFormatDict : (NSDictionary*) formatdict isIFD0 : (BOOL) ifd0flag {
+    NSArray * datakeys = [datadict allKeys];
+    NSArray * knownkeys = [formatdict  allKeys]; // only keys in knowkeys are considered for entry in this IFD
+    NSMutableArray * ifdblock = [[NSMutableArray alloc] initWithCapacity: [datadict count]];
+    NSMutableArray * ifddatablock = [[NSMutableArray alloc] initWithCapacity: [datadict count]];
+    ifd0flag = NO;
+    
+    NSLog(@"%@",[datadict description]);
+
+    
+    for (int i = 0; i < [datakeys count]; i++) {
+        NSString * key = [datakeys objectAtIndex:i];
+        if ([knownkeys indexOfObject: key] != NSNotFound) {
+            // create new IFD entry
+            NSString * entry = [self  createIFDElement: key
+                                      withFormatDict: formatdict
+                                      withElementData: [datadict objectForKey:key]];
+            
+            NSString * data = [self createIFDElementDataWithFormat: [formatdict objectForKey:key]
+                                                   withData: [datadict objectForKey:key]];
+            NSLog(@"%@ %@",entry, data);
+            if (entry) {
+                [ifdblock addObject:entry];
+                if(!data) {
+                    [ifdblock addObject:@""];
+                } else {
+                    [ifddatablock addObject:data];
+                }
+            }
+        }
+    }
+    //[ifdblock addObject: [[NSString alloc] initWithFormat:@"8769%@%@", @"0004",@"00000001"]];
+    NSMutableString * exifstr = [[NSMutableString alloc] initWithCapacity: [ifdblock count] * 24];
+    NSMutableString * dbstr = [[NSMutableString alloc] initWithCapacity: 100];
+    
+    // calculate the starting address of the idf data block based on number 
+    int addr=0;
+    if (ifd0flag) {
+        // +1 for tag 0x8769, exifsubifd offset
+        addr = 14+(12*([ifddatablock count]+1));
+    } else {
+        addr = 14+12*[ifddatablock count];
+    }
+    
+    for (int i = 0; i < [ifdblock count]; i++) {
+
+        NSString * entry = [ifdblock objectAtIndex:i];
+        NSString * data = [ifddatablock objectAtIndex:i];
+        
+        NSLog(@"entry: %@ entry:%@", entry, data);
+        NSLog(@"%d",addr);
+        // check if the data fits into 4 bytes
+        if( [data length] <= 8) {
+            // concatenate the entry and the (4byte) data entry into the final IFD entry and append to exif ifd string
+            NSLog(@"%@   %@", entry, data);
+            [exifstr appendFormat : @"%@%@", entry, data];
+        } else {
+            [exifstr appendFormat : @"%@%08x", entry, addr];
+            [dbstr appendFormat: @"%@", data]; 
+            addr+= [data length] / 2;
+        }
+    }
+    
+    // calculate IFD0 terminal offset tags, currently ExifSubIFD
+    int entrycount = [ifdblock count];
+    if (ifd0flag) {
+        NSNumber * offset = [NSNumber numberWithInt:[exifstr length] / 2 + [dbstr length] / 2 ];
+        
+        [self appendExifOffsetTagTo: exifstr
+                        withOffset : offset];
+        entrycount++;
+    } 
+    return [[NSString alloc] initWithFormat: @"%04x%@%@%@",
+            entrycount,
+            exifstr,
+            @"00000000",
+            dbstr];
+}
+
+
+/**
+ * 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
+    NSLog(@"%@", [data description]);
+    if (fielddata) {
+        // format string @"%@%@%@%@", tag number, data format, components, value
+        NSNumber * dataformat = [fielddata objectAtIndex:1];
+        NSNumber * components = [fielddata 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
+                                                [self formatWithLeadingZeroes: @4 :dataformat], // the data type code
+                                                [components intValue]]; // number of components
+    }
+    return NULL;
+}
+
+/**
+ * appends exif IFD0 tag 8769 "ExifOffset" to the string provided
+ * (NSMutableString*) str - string you wish to append the 8769 tag to: APP1 or IFD0 hex data string 
+ *  //  TAGINF(@"8769", [NSNumber numberWithInt:EDT_ULONG], @1), @"ExifOffset",
+ */
+- (void) appendExifOffsetTagTo: (NSMutableString*) str withOffset : (NSNumber*) offset {
+    NSArray * format = TAGINF(@"8769", [NSNumber numberWithInt:EDT_ULONG], @1);
+    
+    NSString * entry = [self  createIFDElement: @"ExifOffset"
+                                withFormatDict: IFD0TagFormatDict
+                               withElementData: [offset stringValue]];
+    
+    NSString * data = [self createIFDElementDataWithFormat: format
+                                                  withData: [offset stringValue]];
+    [str appendFormat:@"%@%@", entry, data];
+}
+
+/*
+
+- (void) createTagDataHelper: (NSString *) tagname withTagCode: (NSInteger) tagcode {
+    NSMutableString * datastr = [NSMutableString alloc];
+    [datastr appendFormat: @"%@, tagcode", tagname];
+}
+*/
+
+
+
+/**
+ * formatIFHElementData
+ * formats the Information File Directory Data to exif format
+ * @return formatted data string
+ */
+- (NSString*) createIFDElementDataWithFormat: (NSArray*) dataformat withData: (NSString*) data {
+    NSMutableString * datastr = nil;
+    NSNumber * numerator = nil;
+    NSNumber * denominator = nil;
+    NSNumber * formatcode = [dataformat objectAtIndex:1];
+    
+    switch ([formatcode intValue]) {
+        case EDT_UBYTE:
+            break;
+        case EDT_ASCII_STRING:
+            datastr = [[NSMutableString alloc] init];
+            for (int i = 0; i < [data length]; i++) {
+                [datastr appendFormat:@"%02x",[data characterAtIndex:i]];
+            }
+            if ([datastr length] < 8) {
+                NSString * format = [NSString stringWithFormat:@"%%0%dd", 8 - [datastr length]];
+                [datastr appendFormat:format,0];
+            }
+            return datastr;
+        case EDT_USHORT:
+            return [[NSString alloc] initWithFormat : @"%@%@",
+                    [self formattedHexStringFromDecimalNumber: [NSNumber numberWithInt: [data intValue]] withPlaces: @4],
+                    @"00000000"];
+        case EDT_ULONG:
+            numerator = [NSNumber numberWithUnsignedLong:[data intValue]];
+            return [NSString stringWithFormat : @"%@",
+                    [self formattedHexStringFromDecimalNumber: numerator withPlaces: @8]];
+        case EDT_URATIONAL:
+            return [self decimalToUnsignedRational: [NSNumber numberWithDouble:[data doubleValue]]
+                            outputNumerator: numerator
+                          outputDenominator: denominator];
+        case EDT_SBYTE:
+            break;
+        case EDT_UNDEFINED:
+            break;     // 8 bits
+        case EDT_SSHORT:
+            break;
+        case EDT_SLONG:
+            break;          // 32bit signed integer (2's complement)
+        case EDT_SRATIONAL:
+            break;     // 2 SLONGS, first long is numerator, second is denominator
+        case EDT_SINGLEFLOAT:
+            break;
+        case EDT_DOUBLEFLOAT:
+            break;
+    }
+    return datastr;
+}
+
+
+//======================================================================================================================
+
+//======================================================================================================================
+
+/**
+ * creates a formatted little endian hex string from a number and width specifier
+ */
+- (NSString*) formattedHexStringFromDecimalNumber: (NSNumber*) numb withPlaces: (NSNumber*) width {
+    NSMutableString * str = [[NSMutableString alloc] initWithCapacity:[width intValue]];
+    NSString * formatstr = [[NSString alloc] initWithFormat: @"%%%@%dx", @"0", [width intValue]];
+    [str appendFormat:formatstr, [numb intValue]];
+    return str;
+}
+
+- (NSString*) formatWithLeadingZeroes: (NSNumber *) places: (NSNumber *) numb {
+    
+    NSNumberFormatter * formatter = [[NSNumberFormatter alloc] init];
+   // NSString * formatstr = [@"" stringByPaddingToLength:places withsString: @"0" ];
+    NSString *formatstr = [@"" stringByPaddingToLength:[places unsignedIntegerValue] withString:@"0" startingAtIndex:0];
+    [formatter setPositiveFormat:formatstr];
+    
+    return [formatter stringFromNumber:numb];
+}
+
+// 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];
+}
+
+// approximate a decimal with an unsigned rational by method of continued fraction
+- (NSString*) decimalToUnsignedRational: (NSNumber *) numb outputNumerator: (NSNumber *) num outputDenominator: (NSNumber*) deno {
+    num = [NSNumber numberWithUnsignedLong: 1];
+    deno = [NSNumber numberWithUnsignedLong: 1];
+
+    //calculate initial values
+    int term = [numb intValue];
+    double error = [numb doubleValue] - term;
+
+    NSMutableArray * fractionlist = [[NSMutableArray alloc] initWithCapacity:8];
+    [self continuedFraction: [numb doubleValue] withFractionList:fractionlist];
+    [self expandContinuedFraction: fractionlist];
+    return [self formatFractionList: fractionlist];
+}
+
+
+- (void) continuedFraction: (double) val withFractionList:(NSMutableArray*) fractionlist {
+    int whole;
+    double remainder;
+    // 1. split term
+    [self splitDouble: val withIntComponent: &whole withFloatRemainder: &remainder];
+    [fractionlist addObject: [NSNumber numberWithInt:whole]];
+    
+    // 2. calculate reciprocal of remainder
+    if (!remainder) return; // early exit, exact fraction found, avoids recip/0
+    double recip = 1 / remainder;
+
+    // 3. exit condition
+    if ([fractionlist count] > 8) {
+        return;
+    }
+    
+    // 4. recurse
+    [self continuedFraction:recip withFractionList: fractionlist];
+    
+}
+
+
+-(void) simplifyPartialQuotients: (NSArray*) arr {
+    int denominator = [[arr lastObject] intValue];
+    int numerator = 1;
+    for (int i = [arr count]; i > 0; i--) {
+       // [self op1: [arr objectAtIndex:i] withNumerator:]
+    }
+    
+}
+
+-(void) expandContinuedFraction: (NSArray*) fractionlist {
+    int i = 0;
+    int den = 0;
+    int num = 0;
+
+    //begin at the end of the list
+    i = [fractionlist count] - 1;
+    num = 1;
+    den = [fractionlist objectAtIndex:i];
+    
+    while (i > 0) {
+        int t = [fractionlist objectAtIndex: i-1];
+        num = t * den + num;
+        if (i==1) {
+            break;
+        } else {
+            t = num;
+            num = den;
+            den = t;
+        }
+        i--;
+    }
+    
+    NSLog(@"%d %d",den,num);
+}
+
+- (void) op1: (int) n withNumerator: (NSNumber*) num withDenominator: (NSNumber*) denom {
+    num = [NSNumber numberWithInt:[denom intValue]*n+[num intValue]];
+}
+
+
+- (NSString*) formatFractionList: (NSArray *) fractionlist {
+    NSMutableString * str = [[NSMutableString alloc] initWithCapacity:16];
+    
+    if ([fractionlist count] == 1){
+        [str appendFormat: @"%08x00000001", [[fractionlist objectAtIndex:0] intValue]];
+    }
+    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
+    *leftside = val - *rightside;
+//    int digits = [[NSString stringWithFormat:@"%f", de] length] - 2;
+//    *leftside =  de * pow(10,digits);;
+}
+
+
+//
+- (NSString*) hexStringFromData : (NSData*) data {
+    //overflow detection
+    const unsigned char *dataBuffer = [data bytes];
+    return [[NSString alloc] initWithFormat: @"%02x%02x",
+                                        (unsigned char)dataBuffer[0],
+                                        (unsigned char)dataBuffer[1]];
+}
+
+// convert a hex string to a number
+- (NSNumber*) numericFromHexString : (NSString *) hexstring {
+    NSScanner * scan = NULL;
+    unsigned int numbuf= 0;
+    
+    scan = [NSScanner scannerWithString:hexstring];
+    [scan scanHexInt:&numbuf];
+    return [NSNumber numberWithInt:numbuf];
+}
+
+@end


[07/13] ios commit: [CB-1285] readded public helper functions supporting splice into existing jpeg nsdata operation

Posted by sh...@apache.org.
[CB-1285] readded public helper functions supporting splice into existing jpeg nsdata operation


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

Branch: refs/heads/master
Commit: 9e648940473c36d39bff6bba02c9a41896560033
Parents: 8a605b3
Author: lorinbeer <lo...@adobe.com>
Authored: Fri Mar 22 12:24:01 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Fri Mar 22 12:24:01 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVJpegHeaderWriter.h |   14 ++---------
 CordovaLib/Classes/CDVJpegHeaderWriter.m |   28 +++++++++++++++++-------
 2 files changed, 23 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/9e648940/CordovaLib/Classes/CDVJpegHeaderWriter.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.h b/CordovaLib/Classes/CDVJpegHeaderWriter.h
index 07f6b2c..9382af7 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.h
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.h
@@ -17,14 +17,6 @@
  under the License.
  */
 
-//
-//  CDVImageHeaderWriter.h
-//  CordovaLib
-//
-//  Created by Lorin Beer on 2012-10-02.
-//
-//
-
 #import <Foundation/Foundation.h>
 
 @interface CDVJpegHeaderWriter : NSObject {
@@ -32,7 +24,7 @@
     NSDictionary * IFD0TagFormatDict;
 }
 
-
+- (NSString*) createExifAPP1 : (NSDictionary*) datadict;
 - (NSString*) formattedHexStringFromDecimalNumber: (NSNumber*) numb 
                                        withPlaces: (NSNumber*) width;
 - (NSString*) formatNumberWithLeadingZeroes: (NSNumber*) numb 
@@ -40,7 +32,6 @@
 - (NSString*) decimalToUnsignedRational: (NSNumber*) numb
                     withResultNumerator: (NSNumber**) numerator
                   withResultDenominator: (NSNumber**) denominator;
-
 - (void) continuedFraction: (double) val
           withFractionList: (NSMutableArray*) fractionlist 
                withHorizon: (int) horizon;
@@ -48,10 +39,11 @@
 - (void) splitDouble: (double) val 
          withIntComponent: (int*) rightside 
          withFloatRemainder: (double*) leftside;
-
 - (NSString*) formatRationalWithNumerator: (NSNumber*) numerator
                           withDenominator: (NSNumber*) denominator
                                asSigned: (Boolean) signedFlag;
+- (NSString*) hexStringFromData : (NSData*) data;
+- (NSNumber*) numericFromHexString : (NSString *) hexstring;
 
 /*
 - (void) readExifMetaData : (NSData*) imgdata;

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/9e648940/CordovaLib/Classes/CDVJpegHeaderWriter.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.m b/CordovaLib/Classes/CDVJpegHeaderWriter.m
index be35721..c6bba1e 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.m
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.m
@@ -17,14 +17,6 @@
  under the License.
  */
 
-//
-//  CDVImageHeaderWriter.m
-//  CordovaLib
-//
-//  Created by Lorin Beer on 2012-10-02.
-//
-//
-
 /**
  * creates an IFD field
  * Bytes 0-1 Tag code
@@ -468,4 +460,24 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
     *leftside = val - *rightside;
 }
 
+
+//
+- (NSString*) hexStringFromData : (NSData*) data {
+    //overflow detection
+    const unsigned char *dataBuffer = [data bytes];
+    return [[NSString alloc] initWithFormat: @"%02x%02x",
+            (unsigned char)dataBuffer[0],
+            (unsigned char)dataBuffer[1]];
+}
+
+// convert a hex string to a number
+- (NSNumber*) numericFromHexString : (NSString *) hexstring {
+    NSScanner * scan = NULL;
+    unsigned int numbuf= 0;
+    
+    scan = [NSScanner scannerWithString:hexstring];
+    [scan scanHexInt:&numbuf];
+    return [NSNumber numberWithInt:numbuf];
+}
+
 @end


[05/13] ios commit: [CB-1285] added unit tests for CDVJpegHeaderWriter, tests rational approximation and utility functions involved in the creation of the APP1 data block in a JPEG header. For test of APP1 data block integrity, best method is to read res

Posted by sh...@apache.org.
[CB-1285] added unit tests for CDVJpegHeaderWriter, tests rational approximation and utility functions involved in the creation of the APP1 data block in a JPEG header. For test of APP1 data block integrity, best method is to read resulting image


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

Branch: refs/heads/master
Commit: c960151767abfe000e007278d59a70512861fb01
Parents: fbebe8f
Author: lorinbeer <lo...@adobe.com>
Authored: Wed Mar 20 21:41:42 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Wed Mar 20 21:41:42 2013 -0700

----------------------------------------------------------------------
 CordovaLibTests/ExifTests.h |   27 +++++++
 CordovaLibTests/ExifTests.m |  155 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 182 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c9601517/CordovaLibTests/ExifTests.h
----------------------------------------------------------------------
diff --git a/CordovaLibTests/ExifTests.h b/CordovaLibTests/ExifTests.h
new file mode 100644
index 0000000..b46241b
--- /dev/null
+++ b/CordovaLibTests/ExifTests.h
@@ -0,0 +1,27 @@
+//
+//  ExifTestTests.h
+//  ExifTestTests
+//
+//  Created by Lorin Beer on 2013-03-18.
+//
+//
+
+#import <SenTestingKit/SenTestingKit.h>
+
+#import "../ExifTest/CDVJpegHeaderWriter.h"
+
+#define ARC4RANDOM_MAX 0x100000000
+
+@interface ExifTestTests : SenTestCase {
+    CDVJpegHeaderWriter * testHeaderWriter;
+    NSNumber * testErrorThreshhold;
+}
+
+- (void) testContinuedFractionWithUInt;
+- (void) testContinuedFractionWithUFloat;
+- (void) testContinuedFractionsWorstCase;
+- (void) testFormatHexFromDecimal;
+- (void) testFormatNumberWithLeadingZeroes;
+- (void) testUnsignedRationalToString;
+- (void) testSignedRationalToString;
+@end
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c9601517/CordovaLibTests/ExifTests.m
----------------------------------------------------------------------
diff --git a/CordovaLibTests/ExifTests.m b/CordovaLibTests/ExifTests.m
new file mode 100644
index 0000000..960ac95
--- /dev/null
+++ b/CordovaLibTests/ExifTests.m
@@ -0,0 +1,155 @@
+//
+//  ExifTestTests.m
+//  ExifTestTests
+//
+//  Created by Lorin Beer on 2013-03-18.
+//
+//
+
+#import <SenTestingKit/SenTestingKit.h>
+
+#import "ExifTestTests.h"
+#import "../ExifTest/CDVJpegHeaderWriter.m"
+
+
+@implementation ExifTestTests
+
+- (void)setUp
+{
+    [super setUp];
+    testHeaderWriter = [[CDVJpegHeaderWriter alloc] init];
+    testErrorThreshhold = [NSNumber numberWithDouble: 0.000001];
+    NSLog(@"%x", ~10+1);
+    
+    
+}
+
+- (void)tearDown
+{
+    // Tear-down code here.
+    
+    [super tearDown];
+}
+
+//==================================================================================================
+// rational approximation of decimal by continued fraction tests
+//==================================================================================================
+
+// tests continued fraction with random int
+- (void)testContinuedFractionWithUInt {
+    NSLog(@"Continued Fraction Test with random int value, numerator should be generated value, denominator should be 1");
+    NSNumber * numerator = @0;
+    NSNumber * denominator = @0;
+    NSNumber * testValue = [NSNumber numberWithInt: abs(arc4random())];
+    [testHeaderWriter decimalToUnsignedRational: testValue
+                  withResultNumerator: &numerator
+                withResultDenominator: &denominator];
+    STAssertEquals([numerator intValue],
+                   [testValue intValue],
+                   @"Numerator did not match");
+    STAssertEquals([denominator intValue],
+                   1,
+                   @"denominator was not one");
+}
+
+// tests continued fraction with random float
+- (void)testContinuedFractionWithUFloat {
+    NSLog(@"Continued Fraction Test with random double value, resulting fraction should be within acceptable error threshhold");
+    NSNumber * threshhold = @0.1;
+    NSNumber * numerator = @0;
+    NSNumber * denominator = @0;
+    NSLog(@"%f",((double)arc4random() / ARC4RANDOM_MAX) * 100.0f);
+    NSNumber * testValue = [NSNumber numberWithDouble:
+                                ((double)arc4random() / ARC4RANDOM_MAX) * 100.0f];
+
+    [testHeaderWriter decimalToUnsignedRational: testValue
+                            withResultNumerator: &numerator
+                          withResultDenominator: &denominator];
+    NSLog(@"%lf, %lf",[testValue doubleValue], [numerator doubleValue]/[denominator doubleValue]);
+
+    STAssertEqualsWithAccuracy([testValue doubleValue],
+                               [numerator doubleValue]/[denominator doubleValue],
+                               [threshhold doubleValue],
+                               @"rational approximation did not meet acceptable error threshhold");
+    
+}
+
+// tests continued fraction in sqrt(2) worst case
+- (void)testContinuedFractionsWorstCase {
+    NSLog(@"Continued Fraction Test with provable worst case ~sqrt(2), resulting fraction should be within acceptable error threshhold");
+    NSNumber * threshhold = @0.1;
+    NSNumber * numerator = @0;
+    NSNumber * denominator = @0;
+    NSNumber * testValue = [NSNumber numberWithDouble: sqrt(2)];
+    [testHeaderWriter decimalToUnsignedRational: testValue
+                            withResultNumerator: &numerator
+                          withResultDenominator: &denominator];
+    STAssertEqualsWithAccuracy([testValue doubleValue],
+                               [numerator doubleValue]/[denominator doubleValue],
+                               [threshhold doubleValue],
+                               @"rational approximation did not meet acceptable error threshhold");
+}
+
+// tests format hex from a decimal
+- (void) testFormatHexFromDecimal {
+    NSNumber * testValue = @1;
+    NSNumber * testPlaces = @8;
+    NSString * result = nil;
+    result = [testHeaderWriter formattedHexStringFromDecimalNumber: testValue
+                                                        withPlaces: testPlaces];
+    // assert not nil
+    STAssertNotNil(result, @"nil renturned from formattedHexStringFromDecimalNumber");
+    // assert correct number of places
+    STAssertEquals([result length], [testPlaces unsignedIntegerValue],
+                   @"returned string to wrong number of places. Should be = %i Was = %i",
+                   [testPlaces intValue],
+                   [result length]);
+    // assert correct hex representation
+    STAssertTrueNoThrow([result isEqualToString:@"00000001"], @"result should be equal to @00000001");
+
+}
+
+// tests format number string with leading zeroes
+- (void) testFormatNumberWithLeadingZeroes {
+    NSString * result = nil;
+    NSNumber * testValue = @8769; // Exif SubIFD Offset Tag
+    NSNumber * testPlaces = @6;
+    result = [testHeaderWriter formatNumberWithLeadingZeroes: testValue
+                                                  withPlaces: testPlaces];
+    STAssertNotNil(result, @"nil renturned from formattedHexStringFromDecimalNumber");
+    STAssertEquals([result length],
+                   [testPlaces unsignedIntegerValue],
+                   @"returned string to wrong number of places. Should be = %i Was = %i",
+                   [testPlaces intValue],
+                   [result length]);
+    // assert correct hex representation
+    STAssertTrueNoThrow([result isEqualToString:@"008769"], @"result was = %@ should be = @008769", result);
+}
+
+- (void) testUnsignedRationalToString {
+    NSString * result = nil;
+    NSNumber * numerator = @1;
+    NSNumber * denominator = @10;
+    result = [testHeaderWriter formatRationalWithNumerator: numerator
+                                           withDenominator: denominator
+                                                  asSigned: FALSE];
+    NSLog(result);
+    STAssertNotNil(result, @"nil returned from testUnsignedRationalToString");
+    STAssertTrueNoThrow([result length]==16, @"returned string with wrong length. Exif rationals are 8 bytes, string has %ld bytes",[result length]/2);
+    STAssertTrueNoThrow([result isEqualToString:@"000000010000000a"], @"result was = %@ should be = @0000000100000010", result);
+}
+
+- (void) testSignedRationalToString {
+    NSString * result = nil;
+    NSNumber * numerator = @-1;
+    NSNumber * denominator = @-10;
+    result = [testHeaderWriter formatRationalWithNumerator: numerator
+                                           withDenominator: denominator
+                                                  asSigned: TRUE];
+    NSLog(result);
+    STAssertNotNil(result, @"nil returned from testSignedRationalToString");
+    STAssertTrueNoThrow([result length]==16, @"returned string with wrong length. Exif rationals are 8 bytes, string has %ld bytes",[result length]/2);
+    STAssertTrueNoThrow([result isEqualToString:@"fffffffffffffff6"], @"result was = %@ should be = @000000FF000000F6", result);
+}
+
+@end


[12/13] ios commit: [commenting] removed xcode auto header block

Posted by sh...@apache.org.
[commenting] removed xcode auto header block


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

Branch: refs/heads/master
Commit: 24e73736072e41c0d731839c9098397eb96766a6
Parents: 42341ff
Author: lorinbeer <lo...@adobe.com>
Authored: Fri Mar 22 16:47:43 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Fri Mar 22 16:47:43 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVJpegHeaderWriter.m |   17 -----------------
 1 files changed, 0 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/24e73736/CordovaLib/Classes/CDVJpegHeaderWriter.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.m b/CordovaLib/Classes/CDVJpegHeaderWriter.m
index 6c645fc..7b59d11 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.m
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.m
@@ -17,23 +17,6 @@
  under the License.
  */
 
-//
-//  CDVImageHeaderWriter.m
-//  CordovaLib
-//
-//  Created by Lorin Beer on 2012-10-02.
-//
-//
-
-/**
- * creates an IFD field
- * Bytes 0-1 Tag code
- * Bytes 2-3 Data type
- * Bytes 4-7 Count, number of elements of the given data type
- * Bytes 8-11 Value/Offset
- */
-
-
 #import "CDVJpegHeaderWriter.h"
 #include "CDVExif.h"
 


[10/13] ios commit: [CB-1285] uncrustify and added project files to pbxproj

Posted by sh...@apache.org.
[CB-1285] uncrustify and added project files to pbxproj


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

Branch: refs/heads/master
Commit: f1d58e8a2e283eb19d4809b5772c2aaa3bc382ab
Parents: 7ab7246
Author: lorinbeer <lo...@adobe.com>
Authored: Fri Mar 22 16:01:04 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Fri Mar 22 16:01:04 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVJpegHeaderWriter.m        |    1 +
 CordovaLib/CordovaLib.xcodeproj/project.pbxproj |   12 ++++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/f1d58e8a/CordovaLib/Classes/CDVJpegHeaderWriter.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.m b/CordovaLib/Classes/CDVJpegHeaderWriter.m
index 5273262..6c645fc 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.m
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.m
@@ -51,6 +51,7 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
 @implementation CDVJpegHeaderWriter
 
 - (id) init {    
+    self = [super init];
     // supported tags for exif IFD
     IFD0TagFormatDict = [[NSDictionary alloc] initWithObjectsAndKeys:
                   //      TAGINF(@"010e", [NSNumber numberWithInt:EDT_ASCII_STRING], @0), @"ImageDescription",

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/f1d58e8a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
index 5054f7e..e14f1f6 100644
--- a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
+++ b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
@@ -44,6 +44,9 @@
 		30F5EBAB14CA26E700987760 /* CDVCommandDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 30F5EBA914CA26E700987760 /* CDVCommandDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		3E76876D156A90EE00EB6FA3 /* CDVLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E76876B156A90EE00EB6FA3 /* CDVLogger.m */; };
 		3E76876F156A90EE00EB6FA3 /* CDVLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E76876C156A90EE00EB6FA3 /* CDVLogger.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		68B7516E16FD18190076A8B4 /* CDVJpegHeaderWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 68B7516B16FD18190076A8B4 /* CDVJpegHeaderWriter.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		68B7516F16FD18190076A8B4 /* CDVJpegHeaderWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 68B7516C16FD18190076A8B4 /* CDVJpegHeaderWriter.m */; };
+		68B7517016FD19F80076A8B4 /* CDVExif.h in Headers */ = {isa = PBXBuildFile; fileRef = 68B7516A16FD18190076A8B4 /* CDVExif.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		8852C43A14B65FD800F0E735 /* CDVViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 8852C43614B65FD800F0E735 /* CDVViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		8852C43C14B65FD800F0E735 /* CDVViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8852C43714B65FD800F0E735 /* CDVViewController.m */; };
 		8887FD661090FBE7009987E8 /* CDVCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = 8887FD261090FBE7009987E8 /* CDVCamera.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -141,6 +144,9 @@
 		686357DC14100B1600DF4CF2 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; };
 		68A32D7114102E1C006B237C /* libCordova.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCordova.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		68A32D7414103017006B237C /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
+		68B7516A16FD18190076A8B4 /* CDVExif.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVExif.h; path = Classes/CDVExif.h; sourceTree = "<group>"; };
+		68B7516B16FD18190076A8B4 /* CDVJpegHeaderWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVJpegHeaderWriter.h; path = Classes/CDVJpegHeaderWriter.h; sourceTree = "<group>"; };
+		68B7516C16FD18190076A8B4 /* CDVJpegHeaderWriter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVJpegHeaderWriter.m; path = Classes/CDVJpegHeaderWriter.m; sourceTree = "<group>"; };
 		8220B5C316D5427E00EC3921 /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; };
 		8852C43614B65FD800F0E735 /* CDVViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVViewController.h; path = Classes/CDVViewController.h; sourceTree = "<group>"; };
 		8852C43714B65FD800F0E735 /* CDVViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVViewController.m; path = Classes/CDVViewController.m; sourceTree = "<group>"; };
@@ -294,6 +300,9 @@
 				8887FD271090FBE7009987E8 /* CDVCamera.m */,
 				1F584B991385A28900ED25E8 /* CDVCapture.h */,
 				1F584B9A1385A28900ED25E8 /* CDVCapture.m */,
+				68B7516A16FD18190076A8B4 /* CDVExif.h */,
+				68B7516B16FD18190076A8B4 /* CDVJpegHeaderWriter.h */,
+				68B7516C16FD18190076A8B4 /* CDVJpegHeaderWriter.m */,
 				1F3C04CC12BC247D004F9E10 /* CDVContact.h */,
 				1F3C04CD12BC247D004F9E10 /* CDVContact.m */,
 				8887FD2A1090FBE7009987E8 /* CDVContacts.h */,
@@ -366,6 +375,8 @@
 			isa = PBXHeadersBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				68B7517016FD19F80076A8B4 /* CDVExif.h in Headers */,
+				68B7516E16FD18190076A8B4 /* CDVJpegHeaderWriter.h in Headers */,
 				8887FD661090FBE7009987E8 /* CDVCamera.h in Headers */,
 				8887FD681090FBE7009987E8 /* NSDictionary+Extensions.h in Headers */,
 				8887FD6A1090FBE7009987E8 /* CDVContacts.h in Headers */,
@@ -504,6 +515,7 @@
 				30F3930C169F839700B22307 /* CDVJSON.m in Sources */,
 				EB96673C16A8970A00D86CDF /* CDVUserAgentUtil.m in Sources */,
 				EBFF4DBC16D3FE2E008F452B /* CDVWebViewDelegate.m in Sources */,
+				68B7516F16FD18190076A8B4 /* CDVJpegHeaderWriter.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};


[11/13] ios commit: [CB-1285] fixed unsued var warning, and incomplete implementation warning

Posted by sh...@apache.org.
[CB-1285] fixed unsued var warning, and incomplete implementation warning


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

Branch: refs/heads/master
Commit: 42341ff4dd33feb8c267ad200ffcca79241b1571
Parents: f1d58e8
Author: lorinbeer <lo...@adobe.com>
Authored: Fri Mar 22 16:17:21 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Fri Mar 22 16:17:21 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVCamera.m           |    2 --
 CordovaLib/Classes/CDVJpegHeaderWriter.h |    2 +-
 2 files changed, 1 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/42341ff4/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index 9bf326a..ab1154e 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -314,7 +314,6 @@ static NSSet* org_apache_cordova_validArrowDirections;
                     [exifdata appendBytes:&intValue length:1];
                 }
                
-                NSMutableData * buffer = [NSMutableData dataWithLength: 4];
                 NSMutableData * ddata = [NSMutableData dataWithCapacity: [data length]];
                 NSMakeRange(0,4);
                 int loc = 0;
@@ -327,7 +326,6 @@ static NSSet* org_apache_cordova_validArrowDirections;
                         NSString * the = [exifWriter hexStringFromData:[data subdataWithRange: NSMakeRange(loc+2,2)]];
                         NSNumber * app1width = [exifWriter numericFromHexString:the];
                         //consume the original app1 block
-                        NSData * blag = [data subdataWithRange: NSMakeRange(loc,[app1width intValue])];
                         [ddata appendData:exifdata];
                         // advance our loc marker past app1
                         loc += [app1width intValue] + 2;

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/42341ff4/CordovaLib/Classes/CDVJpegHeaderWriter.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.h b/CordovaLib/Classes/CDVJpegHeaderWriter.h
index 9382af7..02fe91f 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.h
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.h
@@ -35,7 +35,7 @@
 - (void) continuedFraction: (double) val
           withFractionList: (NSMutableArray*) fractionlist 
                withHorizon: (int) horizon;
-- (void) expandContinuedFraction: (NSArray*) fractionlist;
+//- (void) expandContinuedFraction: (NSArray*) fractionlist;
 - (void) splitDouble: (double) val 
          withIntComponent: (int*) rightside 
          withFloatRemainder: (double*) leftside;


[13/13] ios commit: Merge branch 'refs/heads/CB-1285'

Posted by sh...@apache.org.
Merge branch 'refs/heads/CB-1285'


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

Branch: refs/heads/master
Commit: b586157fae2c3f38859a7bebecdaac4675aa27c2
Parents: 268e852 24e7373
Author: Shazron Abdullah <sh...@apache.org>
Authored: Fri Mar 22 16:55:30 2013 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Fri Mar 22 16:55:30 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVCamera.m                  |   71 +++-
 CordovaLib/Classes/CDVExif.h                    |   43 ++
 CordovaLib/Classes/CDVJpegHeaderWriter.h        |   60 +++
 CordovaLib/Classes/CDVJpegHeaderWriter.m        |  472 ++++++++++++++++++
 CordovaLib/CordovaLib.xcodeproj/project.pbxproj |   12 +
 CordovaLibTests/ExifTests.h                     |   27 +
 CordovaLibTests/ExifTests.m                     |  155 ++++++
 7 files changed, 826 insertions(+), 14 deletions(-)
----------------------------------------------------------------------



[03/13] ios commit: Merge remote-tracking branch 'upstream/master' into CB-1285

Posted by sh...@apache.org.
Merge remote-tracking branch 'upstream/master' into CB-1285


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

Branch: refs/heads/master
Commit: a5b8e248433ea7305f9ae5155d648fc98094bcf1
Parents: 7923974 8d28567
Author: lorinbeer <lo...@adobe.com>
Authored: Wed Mar 20 21:29:08 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Wed Mar 20 21:29:08 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVAvailability.h               |    6 +-
 CordovaLib/Classes/CDVCamera.h                     |    4 +-
 CordovaLib/Classes/CDVCamera.m                     |   27 +-
 CordovaLib/Classes/CDVCapture.m                    |   10 +-
 CordovaLib/Classes/CDVCommandDelegateImpl.m        |    2 +-
 CordovaLib/Classes/CDVCommandQueue.m               |    4 +-
 CordovaLib/Classes/CDVConfigParser.m               |    2 +-
 CordovaLib/Classes/CDVConnection.m                 |    2 +-
 CordovaLib/Classes/CDVContact.m                    |   28 +-
 CordovaLib/Classes/CDVContacts.h                   |   14 +-
 CordovaLib/Classes/CDVContacts.m                   |  490 +++++++-------
 CordovaLib/Classes/CDVFile.h                       |    1 +
 CordovaLib/Classes/CDVFile.m                       |  347 +++++------
 CordovaLib/Classes/CDVFileTransfer.h               |    8 +-
 CordovaLib/Classes/CDVFileTransfer.m               |   42 +-
 CordovaLib/Classes/CDVGlobalization.m              |   62 +-
 CordovaLib/Classes/CDVInAppBrowser.h               |    1 +
 CordovaLib/Classes/CDVInAppBrowser.m               |   38 +-
 CordovaLib/Classes/CDVInvokedUrlCommand.h          |    6 +-
 CordovaLib/Classes/CDVLocalStorage.h               |    4 +-
 CordovaLib/Classes/CDVLocalStorage.m               |   36 +-
 CordovaLib/Classes/CDVLocation.h                   |    8 +-
 CordovaLib/Classes/CDVLocation.m                   |   24 +-
 CordovaLib/Classes/CDVNotification.h               |    1 +
 CordovaLib/Classes/CDVNotification.m               |   84 ++-
 CordovaLib/Classes/CDVPluginResult.h               |    3 +
 CordovaLib/Classes/CDVPluginResult.m               |   12 +-
 CordovaLib/Classes/CDVReachability.m               |   28 +-
 CordovaLib/Classes/CDVSound.m                      |    6 +-
 CordovaLib/Classes/CDVSplashScreen.m               |   13 +-
 CordovaLib/Classes/CDVURLProtocol.m                |   12 +-
 CordovaLib/Classes/CDVUserAgentUtil.m              |    2 +-
 CordovaLib/Classes/CDVViewController.h             |    1 +
 CordovaLib/Classes/CDVViewController.m             |   24 +-
 CordovaLib/Classes/CDVWebViewDelegate.m            |    2 +-
 CordovaLib/Classes/NSData+Base64.m                 |   19 +-
 CordovaLib/Classes/NSDictionary+Extensions.m       |    2 +-
 CordovaLib/cordova.ios.js                          |  414 ++++++++++---
 CordovaLibTests/CDVFakeFileManager.h               |    2 +-
 CordovaLibTests/CDVFileTransferTests.m             |   12 +-
 CordovaLibTests/CDVLocalStorageTests.m             |   24 +-
 CordovaLibTests/CDVUserAgentTest.m                 |    4 +-
 CordovaLibTests/CDVWebViewTest.m                   |    4 +-
 .../project/__TESTING__/Classes/AppDelegate.m      |    4 +-
 hooks/pre-commit                                   |    5 +
 45 files changed, 1046 insertions(+), 798 deletions(-)
----------------------------------------------------------------------



[08/13] ios commit: [CB-1285] added exif binary string splice operation to camera jpeg case, removed auto header

Posted by sh...@apache.org.
[CB-1285] added exif binary string splice operation to camera jpeg case, removed auto header


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

Branch: refs/heads/master
Commit: ac0cb7c610098a7f56f6c33fc88ddf2eb65d8d1d
Parents: 9e64894
Author: lorinbeer <lo...@adobe.com>
Authored: Fri Mar 22 12:26:50 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Fri Mar 22 12:26:50 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVCamera.m |   68 +++++++++++++++++++++++++++-------
 CordovaLib/Classes/CDVExif.h   |    9 +----
 2 files changed, 55 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/ac0cb7c6/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index 1f05333..bba339d 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -18,6 +18,7 @@
  */
 
 #import "CDVCamera.h"
+#import "CDVJpegHeaderWriter.h"
 #import "NSArray+Comparisons.h"
 #import "NSData+Base64.h"
 #import "NSDictionary+Extensions.h"
@@ -84,6 +85,12 @@ static NSSet* org_apache_cordova_validArrowDirections;
         return;
     }
 
+    NSNumber* cameraDirection = [arguments objectAtIndex:11];
+    UIImagePickerControllerCameraDevice cameraDevice = UIImagePickerControllerCameraDeviceRear; // default
+    if (cameraDirection != nil) {
+        cameraDevice = (UIImagePickerControllerSourceType)[cameraDirection intValue];
+    }
+
     bool allowEdit = [[arguments objectAtIndex:7] boolValue];
     NSNumber* targetWidth = [arguments objectAtIndex:3];
     NSNumber* targetHeight = [arguments objectAtIndex:4];
@@ -107,6 +114,7 @@ static NSSet* org_apache_cordova_validArrowDirections;
 
     cameraPicker.delegate = self;
     cameraPicker.sourceType = sourceType;
+    cameraPicker.cameraDevice = cameraDevice;
     cameraPicker.allowsEditing = allowEdit; // THIS IS ALL IT TAKES FOR CROPPING - jm
     cameraPicker.callbackId = callbackId;
     cameraPicker.targetSize = targetSize;
@@ -124,26 +132,18 @@ static NSSet* org_apache_cordova_validArrowDirections;
     cameraPicker.returnType = ([arguments objectAtIndex:1]) ? [[arguments objectAtIndex:1] intValue] : DestinationTypeFileUri;
 
     if (sourceType == UIImagePickerControllerSourceTypeCamera) {
-        // We only allow taking pictures (no video) in this API.
+        // we only allow taking pictures (no video) in this api
         cameraPicker.mediaTypes = [NSArray arrayWithObjects:(NSString*)kUTTypeImage, nil];
-
-        // We can only set the camera device if we're actually using the camera.
-        NSNumber* cameraDirection = [arguments objectAtIndex:11];
-        UIImagePickerControllerCameraDevice cameraDevice = UIImagePickerControllerCameraDeviceRear; // default
-        if (cameraDirection != nil) {
-            cameraDevice = (UIImagePickerControllerSourceType)[cameraDirection intValue];
-        }
-        cameraPicker.cameraDevice = cameraDevice;
     } else if (mediaType == MediaTypeAll) {
         cameraPicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
     } else {
-        NSArray* mediaArray = [NSArray arrayWithObjects:(NSString*)(mediaType == MediaTypeVideo ? kUTTypeMovie : kUTTypeImage), nil];
+        NSArray* mediaArray = [NSArray arrayWithObjects:(NSString*)(mediaType == MediaTypeVideo ? kUTTypeMovie:kUTTypeImage), nil];
         cameraPicker.mediaTypes = mediaArray;
     }
 
     if ([self popoverSupported] && (sourceType != UIImagePickerControllerSourceTypeCamera)) {
         if (cameraPicker.popoverController == nil) {
-            cameraPicker.popoverController = [[NSClassFromString(@"UIPopoverController")alloc] initWithContentViewController:cameraPicker];
+            cameraPicker.popoverController = [[NSClassFromString (@"UIPopoverController")alloc] initWithContentViewController:cameraPicker];
         }
         NSDictionary* options = [command.arguments objectAtIndex:10 withDefault:nil];
         [self displayPopover:options];
@@ -299,12 +299,52 @@ static NSSet* org_apache_cordova_validArrowDirections;
                 data = UIImagePNGRepresentation(scaledImage == nil ? image : scaledImage);
             } else {
                 data = UIImageJPEGRepresentation(scaledImage == nil ? image : scaledImage, cameraPicker.quality / 100.0f);
+                
+                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 * buffer = [NSMutableData dataWithLength: 4];
+                NSMutableData * ddata = [NSMutableData dataWithCapacity: [data length]];
+                NSMakeRange(0,4);
+                int loc = 0;
+                //         CDVImageHeaderWriter * me = [[CDVImageHeaderWriter alloc] init];
+                
+                // 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 next
+                        NSString * the = [exifWriter hexStringFromData:[data subdataWithRange: NSMakeRange(loc+2,2)]];
+                        NSNumber * app1width = [exifWriter numericFromHexString:the];
+                        
+                        NSData * blag = [data subdataWithRange: NSMakeRange(loc,[app1width intValue])];
+                        [ddata appendData:exifdata];
+                        // advance our loc marker past app1
+                        loc += [app1width intValue] + 2;
+                        
+                    } else {
+                        [ddata appendData:blag];
+                        loc += 2;
+                    }
+                }
+                data = ddata;
             }
 
             if (cameraPicker.returnType == DestinationTypeFileUri) {
                 // write to temp directory and return URI
                 // get the temp directory path
-                NSString* docsPath = [NSTemporaryDirectory()stringByStandardizingPath];
+                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
@@ -429,7 +469,7 @@ static NSSet* org_apache_cordova_validArrowDirections;
             rotation_radians = 0.0;
             break;
 
-        case UIImageOrientationDown:
+        case UIImageOrientationDown :
             rotation_radians = M_PI; // don't be scared of radians, if you're reading this, you're good at math
             break;
 
@@ -528,7 +568,7 @@ static NSSet* org_apache_cordova_validArrowDirections;
     // first parameter an image
     [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
     [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"upload\"; filename=\"%@\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]];
-    [postBody appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding : NSUTF8StringEncoding]];
+    [postBody appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
     [postBody appendData:imageData];
 
     //	// second parameter information

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/ac0cb7c6/CordovaLib/Classes/CDVExif.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVExif.h b/CordovaLib/Classes/CDVExif.h
index 27240c8..3e8adbd 100644
--- a/CordovaLib/Classes/CDVExif.h
+++ b/CordovaLib/Classes/CDVExif.h
@@ -17,14 +17,6 @@
  under the License.
  */
 
-//
-//  ExifData.h
-//  Declares exif format codes and static data
-//
-//  Created by Lorin Beer on 2012-10-04.
-//
-//
-
 #ifndef CordovaLib_ExifData_h
 #define CordovaLib_ExifData_h
 
@@ -47,4 +39,5 @@ typedef enum exifDataTypes {
 // maps integer code for exif data types to width in bytes
 static const int DataTypeToWidth[] = {1,1,2,4,8,1,1,2,4,8,4,8};
 
+static const int RECURSE_HORIZON = 8;
 #endif


[06/13] ios commit: Merge remote-tracking branch 'upstream/master' into CB-1285

Posted by sh...@apache.org.
Merge remote-tracking branch 'upstream/master' into CB-1285

merging upstream changes into local branch


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

Branch: refs/heads/master
Commit: 8a605b313d0841d37622db968a87119f3f09fce5
Parents: c960151 9ce85c2
Author: lorinbeer <lo...@adobe.com>
Authored: Fri Mar 22 11:30:42 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Fri Mar 22 11:30:42 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVAvailability.h     |    5 +-
 CordovaLib/VERSION                       |    2 +-
 CordovaLib/cordova.ios.js                |  137 ++++++++++++++++++++++---
 CordovaLibTests/CordovaLibApp/config.xml |    1 +
 bin/templates/project/www/index.html     |    2 +-
 5 files changed, 130 insertions(+), 17 deletions(-)
----------------------------------------------------------------------



[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

Posted by sh...@apache.org.
[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


[09/13] ios commit: [CB-1285] replaced debugging copy (per byte) with block copy in data splice, removed logging

Posted by sh...@apache.org.
[CB-1285] replaced debugging copy (per byte) with block copy in data splice, removed logging


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

Branch: refs/heads/master
Commit: 7ab7246556ad5c40c1eb886404d21093e7d2599a
Parents: ac0cb7c
Author: lorinbeer <lo...@adobe.com>
Authored: Fri Mar 22 15:38:17 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Fri Mar 22 15:38:17 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVCamera.m           |   19 ++++++++++++-------
 CordovaLib/Classes/CDVJpegHeaderWriter.m |   19 ++++++++++++-------
 2 files changed, 24 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7ab72465/CordovaLib/Classes/CDVCamera.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCamera.m b/CordovaLib/Classes/CDVCamera.m
index bba339d..9bf326a 100644
--- a/CordovaLib/Classes/CDVCamera.m
+++ b/CordovaLib/Classes/CDVCamera.m
@@ -318,26 +318,31 @@ static NSSet* org_apache_cordova_validArrowDirections;
                 NSMutableData * ddata = [NSMutableData dataWithCapacity: [data length]];
                 NSMakeRange(0,4);
                 int loc = 0;
-                //         CDVImageHeaderWriter * me = [[CDVImageHeaderWriter alloc] init];
-                
+                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 next
+                        // 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
                         NSData * blag = [data subdataWithRange: NSMakeRange(loc,[app1width intValue])];
                         [ddata appendData:exifdata];
                         // advance our loc marker past app1
                         loc += [app1width intValue] + 2;
-                        
+                        done = true;
                     } else {
-                        [ddata appendData:blag];
-                        loc += 2;
+                        if(!done) {
+                            [ddata appendData:blag];
+                            loc += 2;
+                        } else {
+                            break;
+                        }
                     }
                 }
+                // copy the remaining data
+                [ddata appendData:[data subdataWithRange: NSMakeRange(loc,[data length]-loc)]];
                 data = ddata;
             }
 

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/7ab72465/CordovaLib/Classes/CDVJpegHeaderWriter.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.m b/CordovaLib/Classes/CDVJpegHeaderWriter.m
index c6bba1e..5273262 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.m
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.m
@@ -17,6 +17,14 @@
  under the License.
  */
 
+//
+//  CDVImageHeaderWriter.m
+//  CordovaLib
+//
+//  Created by Lorin Beer on 2012-10-02.
+//
+//
+
 /**
  * creates an IFD field
  * Bytes 0-1 Tag code
@@ -137,13 +145,14 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
     subExifIFD = [self createExifIFDFromDict: [datadict objectForKey:@"{Exif}"] withFormatDict: SubIFDTagFormatDict isIFD0:NO];
 
     // construct the complete app1 data block
-    app1 = [[NSMutableString alloc] initWithFormat: @"%@%04x%@%@%@%@",
+    app1 = [[NSMutableString alloc] initWithFormat: @"%@%04x%@%@%@%@%@",
             app1marker,
-            16+[exifIFD length]/2,
+            16+[exifIFD length]/2+[subExifIFD length]/2/*16+[exifIFD length]/2*/,
             exifmarker,
             tiffheader,
             ifd0offset,
-            exifIFD];
+            exifIFD,
+            subExifIFD];
      
     return app1;
 }
@@ -225,7 +234,6 @@ 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
-    NSLog(@"%@", [data description]);
     if (fielddata) {
         // format string @"%@%@%@%@", tag number, data format, components, value
         NSNumber * dataformat = [fielddata objectAtIndex:1];
@@ -366,7 +374,6 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
               withResultNumerator: numerator
             withResultDenominator: denominator];
     
-    NSLog(@"%@ %d %d %@", @"Hi Int values", [*numerator intValue], [*denominator intValue],[fractionlist description]);
     return [self formatFractionList: fractionlist];
 }
 
@@ -401,7 +408,6 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
     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;
@@ -444,7 +450,6 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
 - (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];


[02/13] ios commit: [CB-1285] removed dead code in implementation, fixed xcode warnings, commented

Posted by sh...@apache.org.
[CB-1285] removed dead code in implementation, fixed xcode warnings, commented


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

Branch: refs/heads/master
Commit: 79239741f2af34d5377d78bd1d4e509814d8450d
Parents: 7ea1e2d
Author: doggerelverse <lo...@adobe.com>
Authored: Thu Mar 14 23:05:57 2013 -0700
Committer: doggerelverse <lo...@adobe.com>
Committed: Thu Mar 14 23:05:57 2013 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVExif.h             |   39 +-----
 CordovaLib/Classes/CDVJpegHeaderWriter.h |   38 +++---
 CordovaLib/Classes/CDVJpegHeaderWriter.m |  196 ++++++------------------
 3 files changed, 71 insertions(+), 202 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/79239741/CordovaLib/Classes/CDVExif.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVExif.h b/CordovaLib/Classes/CDVExif.h
index 38e8ef5..27240c8 100644
--- a/CordovaLib/Classes/CDVExif.h
+++ b/CordovaLib/Classes/CDVExif.h
@@ -19,7 +19,7 @@
 
 //
 //  ExifData.h
-//  CordovaLib
+//  Declares exif format codes and static data
 //
 //  Created by Lorin Beer on 2012-10-04.
 //
@@ -28,6 +28,7 @@
 #ifndef CordovaLib_ExifData_h
 #define CordovaLib_ExifData_h
 
+// exif data types
 typedef enum exifDataTypes {
     EDT_UBYTE = 1,      // 8 bit unsigned integer
     EDT_ASCII_STRING,   // 8 bits containing 7 bit ASCII code, null terminated
@@ -43,41 +44,7 @@ typedef enum exifDataTypes {
     EDT_DOUBLEFLOAT
 } ExifDataTypes;
 
-typedef enum formatFields {
-    FF_CODE = 0,
-    FF_TYPE,
-    FF_COUNT
-} FormatFields;
-
+// maps integer code for exif data types to width in bytes
 static const int DataTypeToWidth[] = {1,1,2,4,8,1,1,2,4,8,4,8};
 
-void repfracExpandPartialQuotients(int * arr, int n) {
-    int i = 0;
-    int nx = 0;
-    int numerator = 0;
-    int denominator = 0;
-    
-    denominator = arr[n-1];
-    numerator = arr[n-++i] * arr[n-++i];
-    for (;n-i>=0;i++) {
-        
-    }
-}
-
-void repfracExp(int i, int * arr, int s, int * numerator, int * denominator) {
-    int temp;
-    if (i == s-1) {
-        *numerator = 1;
-        *denominator = arr[i];
-    } else if (i != 0) {
-        temp = *denominator;
-        *denominator = arr[i] * (*denominator) + *numerator;
-        *numerator = temp;
-        repfracExp(i-1,arr,s,*numerator,*denominator);
-    } else {
-        return;
-    }
-    return;
-}
-
 #endif

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/79239741/CordovaLib/Classes/CDVJpegHeaderWriter.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.h b/CordovaLib/Classes/CDVJpegHeaderWriter.h
index 1b8bf48..b732c32 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.h
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.h
@@ -32,32 +32,32 @@
     NSDictionary * IFD0TagFormatDict;
 }
 
+
+- (NSString*) formattedHexStringFromDecimalNumber: (NSNumber*) numb 
+                                       withPlaces: (NSNumber*) width;
+- (NSString*) formatNumberWithLeadingZeroes: (NSNumber*) numb 
+                                 withPlaces: (NSNumber*) places;
+
+- (NSString*) decimalToUnsignedRational: (NSNumber*) numb;
+
+- (void) continuedFraction: (double) val 
+          withFractionList: (NSMutableArray*) fractionlist 
+               withHorizon: (int) horizon;
+- (void) expandContinuedFraction: (NSArray*) fractionlist;
+- (void) splitDouble: (double) val 
+         withIntComponent: (int*) rightside 
+         withFloatRemainder: (double*) leftside;
+
+/*
 - (void) readExifMetaData : (NSData*) imgdata;
-- (void) insertExifMetaData : (NSData*) imgdata: (NSDictionary*) exifdata;
+- (void) spliceImageData : (NSData*) imgdata withExifData: (NSDictionary*) exifdata;
 - (void) locateExifMetaData : (NSData*) imgdata;
-/**
- * creates an IFD field
- * Bytes 0-1 Tag code
- * Bytes 2-3 Data type
- * Bytes 4-7 Count, number of elements of the given data type
- * Bytes 8-11 Value/Offset
- */
-
 - (NSString*) createExifAPP1 : (NSDictionary*) datadict;
-
 - (void) createExifDataString : (NSDictionary*) datadict;
-
 - (NSString*) createDataElement : (NSString*) element
               withElementData: (NSString*) data
               withExternalDataBlock: (NSDictionary*) memblock;
-
-- (NSString*) decimalToUnsignedRational: (NSNumber *) numb
-         outputNumerator: (NSNumber *) num
-         outputDenominator: (NSNumber*) deno;
-
-
 - (NSString*) hexStringFromData : (NSData*) data;
-
 - (NSNumber*) numericFromHexString : (NSString *) hexstring;
-
+*/
 @end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/79239741/CordovaLib/Classes/CDVJpegHeaderWriter.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJpegHeaderWriter.m b/CordovaLib/Classes/CDVJpegHeaderWriter.m
index f176d07..1a8fc2a 100644
--- a/CordovaLib/Classes/CDVJpegHeaderWriter.m
+++ b/CordovaLib/Classes/CDVJpegHeaderWriter.m
@@ -25,15 +25,21 @@
 //
 //
 
+/**
+ * creates an IFD field
+ * Bytes 0-1 Tag code
+ * Bytes 2-3 Data type
+ * Bytes 4-7 Count, number of elements of the given data type
+ * Bytes 8-11 Value/Offset
+ */
+
+
 #import "CDVJpegHeaderWriter.h"
 #include "CDVExif.h"
 
-#define IntWrap(x) [NSNumber numberWithInt:x]
-
 // tag info shorthand, tagno: tag number, typecode: data type:, components: number of components
 #define TAGINF(tagno, typecode, components) [NSArray arrayWithObjects: tagno, typecode, components, nil]
 
-
 const uint mJpegId = 0xffd8; // JPEG format marker
 const uint mExifMarker = 0xffe1; // APP1 jpeg header marker
 const uint mExif = 0x45786966; // ASCII 'Exif', first characters of valid exif header after size
@@ -109,7 +115,7 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
  *
  *   the following constructs a hex string to Exif specifications, and is therefore brittle
  *   altering the order of arguments to the string constructors, modifying field sizes or formats,
-  *  and any other minor change will likely prevent the exif data from being read
+ *   and any other minor change will likely prevent the exif data from being read
  */
 - (NSString*) createExifAPP1 : (NSDictionary*) datadict {
     NSMutableString * app1; // holds finalized product
@@ -131,74 +137,39 @@ 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];
-  /*  app1 = [[NSString alloc] initWithFormat:@"%@%04x%@%@%@%@",
-                app1marker,
-                ([exif length]/2)+16,
-                exifmarker,
-                tiffheader,
-                ifd0offset,
-                exif];
-    
-    NSLog(@"%@",app1);*/
-    
-    /*
-     * constructing app1 segment:
-     * 2 byte marker: ffe1
-     * 2 byte size  : app1 size
-     * 6 byte exif marker : ascii string 'exif' followed by two bytes of zeroes
-     */
-    /*
-    app1 = [[[NSMutableString alloc] initWithFormat: @"%@%04x%@%@%@%@%@",
-            app1marker,
-            16+[exifIFD length]/2+[subExifIFD length]/2,
-            exifmarker,
-            tiffheader,
-            ifd0offset,
-            exifIFD,
-            subExifIFD];
-*/
-    NSLog(@"%@ \n %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,
             exifmarker,
             tiffheader,
             ifd0offset,
             exifIFD];
-    
-    NSLog(@"%@",app1);
-    
+     
     return app1;
 }
 
-/**
- * returns hex string representing a valid exif information file directory constructed from the datadict and formatdict
- * datadict exif data entries encode into ifd
- * formatdict specifies format of data entries and allowed entries in this ifd
- */
+// returns hex string representing a valid exif information file directory constructed from the datadict and formatdict
 - (NSString*) createExifIFDFromDict : (NSDictionary*) datadict withFormatDict : (NSDictionary*) formatdict isIFD0 : (BOOL) ifd0flag {
-    NSArray * datakeys = [datadict allKeys];
+    NSArray * datakeys = [datadict allKeys]; // all known data keys 
     NSArray * knownkeys = [formatdict  allKeys]; // only keys in knowkeys are considered for entry in this IFD
-    NSMutableArray * ifdblock = [[NSMutableArray alloc] initWithCapacity: [datadict count]];
-    NSMutableArray * ifddatablock = [[NSMutableArray alloc] initWithCapacity: [datadict count]];
-    ifd0flag = NO;
-    
-    NSLog(@"%@",[datadict description]);
-
+    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
     
+    // iterate through known provided data keys
     for (int i = 0; i < [datakeys count]; i++) {
         NSString * key = [datakeys objectAtIndex:i];
+        // don't muck about with unknown keys
         if ([knownkeys indexOfObject: key] != NSNotFound) {
             // create new IFD entry
             NSString * entry = [self  createIFDElement: key
                                       withFormatDict: formatdict
                                       withElementData: [datadict objectForKey:key]];
-            
+            // create the IFD entry's data block
             NSString * data = [self createIFDElementDataWithFormat: [formatdict objectForKey:key]
                                                    withData: [datadict objectForKey:key]];
-            NSLog(@"%@ %@",entry, data);
             if (entry) {
                 [ifdblock addObject:entry];
                 if(!data) {
@@ -209,30 +180,26 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
             }
         }
     }
-    //[ifdblock addObject: [[NSString alloc] initWithFormat:@"8769%@%@", @"0004",@"00000001"]];
+    
     NSMutableString * exifstr = [[NSMutableString alloc] initWithCapacity: [ifdblock count] * 24];
     NSMutableString * dbstr = [[NSMutableString alloc] initWithCapacity: 100];
     
-    // calculate the starting address of the idf data block based on number 
-    int addr=0;
+    int addr=0; // current offset/address in datablock
     if (ifd0flag) {
-        // +1 for tag 0x8769, exifsubifd offset
-        addr = 14+(12*([ifddatablock count]+1));
+        // calculate offset to datablock based on ifd file entry count
+        addr = 14+(12*([ifddatablock count]+1)); // +1 for tag 0x8769, exifsubifd offset
     } else {
+        // same calculation as above, but no exifsubifd offset
         addr = 14+12*[ifddatablock count];
     }
     
     for (int i = 0; i < [ifdblock count]; i++) {
-
         NSString * entry = [ifdblock objectAtIndex:i];
         NSString * data = [ifddatablock objectAtIndex:i];
         
-        NSLog(@"entry: %@ entry:%@", entry, data);
-        NSLog(@"%d",addr);
         // check if the data fits into 4 bytes
         if( [data length] <= 8) {
             // concatenate the entry and the (4byte) data entry into the final IFD entry and append to exif ifd string
-            NSLog(@"%@   %@", entry, data);
             [exifstr appendFormat : @"%@%@", entry, data];
         } else {
             [exifstr appendFormat : @"%@%08x", entry, addr];
@@ -253,14 +220,11 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
     return [[NSString alloc] initWithFormat: @"%04x%@%@%@",
             entrycount,
             exifstr,
-            @"00000000",
-            dbstr];
+            @"00000000", // offset to next IFD, 0 since there is none
+            dbstr]; // lastly, the datablock
 }
 
-
-/**
- * Creates an exif formatted exif information file directory entry
- */
+// 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
     NSLog(@"%@", [data description]);
@@ -274,7 +238,7 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
 
         return [[NSString alloc] initWithFormat: @"%@%@%08x",
                                                 [fielddata objectAtIndex:0], // the field code
-                                                [self formatWithLeadingZeroes: @4 :dataformat], // the data type code
+                                                [self formatNumberWithLeadingZeroes: dataformat withPlaces: @4], // the data type code
                                                 [components intValue]]; // number of components
     }
     return NULL;
@@ -297,25 +261,10 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
     [str appendFormat:@"%@%@", entry, data];
 }
 
-/*
-
-- (void) createTagDataHelper: (NSString *) tagname withTagCode: (NSInteger) tagcode {
-    NSMutableString * datastr = [NSMutableString alloc];
-    [datastr appendFormat: @"%@, tagcode", tagname];
-}
-*/
-
-
-
-/**
- * formatIFHElementData
- * formats the Information File Directory Data to exif format
- * @return formatted data string
- */
+// formats the Information File Directory Data to exif format
 - (NSString*) createIFDElementDataWithFormat: (NSArray*) dataformat withData: (NSString*) data {
     NSMutableString * datastr = nil;
-    NSNumber * numerator = nil;
-    NSNumber * denominator = nil;
+    NSNumber * tmp = nil;
     NSNumber * formatcode = [dataformat objectAtIndex:1];
     
     switch ([formatcode intValue]) {
@@ -336,13 +285,11 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
                     [self formattedHexStringFromDecimalNumber: [NSNumber numberWithInt: [data intValue]] withPlaces: @4],
                     @"00000000"];
         case EDT_ULONG:
-            numerator = [NSNumber numberWithUnsignedLong:[data intValue]];
+            tmp = [NSNumber numberWithUnsignedLong:[data intValue]];
             return [NSString stringWithFormat : @"%@",
-                    [self formattedHexStringFromDecimalNumber: numerator withPlaces: @8]];
+                    [self formattedHexStringFromDecimalNumber: tmp withPlaces: @8]];
         case EDT_URATIONAL:
-            return [self decimalToUnsignedRational: [NSNumber numberWithDouble:[data doubleValue]]
-                            outputNumerator: numerator
-                          outputDenominator: denominator];
+            return [self decimalToUnsignedRational: [NSNumber numberWithDouble:[data doubleValue]]];
         case EDT_SBYTE:
             break;
         case EDT_UNDEFINED:
@@ -361,14 +308,11 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
     return datastr;
 }
 
-
 //======================================================================================================================
-
+// Utility Methods
 //======================================================================================================================
 
-/**
- * creates a formatted little endian hex string from a number and width specifier
- */
+// creates a formatted little endian hex string from a number and width specifier
 - (NSString*) formattedHexStringFromDecimalNumber: (NSNumber*) numb withPlaces: (NSNumber*) width {
     NSMutableString * str = [[NSMutableString alloc] initWithCapacity:[width intValue]];
     NSString * formatstr = [[NSString alloc] initWithFormat: @"%%%@%dx", @"0", [width intValue]];
@@ -376,39 +320,32 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
     return str;
 }
 
-- (NSString*) formatWithLeadingZeroes: (NSNumber *) places: (NSNumber *) numb {
-    
+// format number as string with leading 0's
+- (NSString*) formatNumberWithLeadingZeroes: (NSNumber *) numb withPlaces: (NSNumber *) places { 
     NSNumberFormatter * formatter = [[NSNumberFormatter alloc] init];
-   // NSString * formatstr = [@"" stringByPaddingToLength:places withsString: @"0" ];
     NSString *formatstr = [@"" stringByPaddingToLength:[places unsignedIntegerValue] withString:@"0" startingAtIndex:0];
     [formatter setPositiveFormat:formatstr];
-    
     return [formatter stringFromNumber:numb];
 }
 
 // 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];
 }
+*/
 
 // approximate a decimal with an unsigned rational by method of continued fraction
-- (NSString*) decimalToUnsignedRational: (NSNumber *) numb outputNumerator: (NSNumber *) num outputDenominator: (NSNumber*) deno {
-    num = [NSNumber numberWithUnsignedLong: 1];
-    deno = [NSNumber numberWithUnsignedLong: 1];
-
-    //calculate initial values
-    int term = [numb intValue];
-    double error = [numb doubleValue] - term;
-
+- (NSString*) decimalToUnsignedRational: (NSNumber *) numb {
     NSMutableArray * fractionlist = [[NSMutableArray alloc] initWithCapacity:8];
-    [self continuedFraction: [numb doubleValue] withFractionList:fractionlist];
+    [self continuedFraction: [numb doubleValue] withFractionList:fractionlist withHorizon:8];
     [self expandContinuedFraction: fractionlist];
     return [self formatFractionList: fractionlist];
 }
 
-
-- (void) continuedFraction: (double) val withFractionList:(NSMutableArray*) fractionlist {
+// recursive implementation of decimal approximation by continued fraction
+- (void) continuedFraction: (double) val withFractionList: (NSMutableArray*) fractionlist withHorizon: (int) horizon {
     int whole;
     double remainder;
     // 1. split term
@@ -420,25 +357,16 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
     double recip = 1 / remainder;
 
     // 3. exit condition
-    if ([fractionlist count] > 8) {
+    if ([fractionlist count] > horizon) {
         return;
     }
     
     // 4. recurse
-    [self continuedFraction:recip withFractionList: fractionlist];
-    
-}
-
-
--(void) simplifyPartialQuotients: (NSArray*) arr {
-    int denominator = [[arr lastObject] intValue];
-    int numerator = 1;
-    for (int i = [arr count]; i > 0; i--) {
-       // [self op1: [arr objectAtIndex:i] withNumerator:]
-    }
+    [self continuedFraction:recip withFractionList: fractionlist withHorizon: horizon];
     
 }
 
+// expand continued fraction list, creating a single level rational approximation
 -(void) expandContinuedFraction: (NSArray*) fractionlist {
     int i = 0;
     int den = 0;
@@ -465,11 +393,7 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
     NSLog(@"%d %d",den,num);
 }
 
-- (void) op1: (int) n withNumerator: (NSNumber*) num withDenominator: (NSNumber*) denom {
-    num = [NSNumber numberWithInt:[denom intValue]*n+[num intValue]];
-}
-
-
+// formats expanded fraction list to string matching exif specification
 - (NSString*) formatFractionList: (NSArray *) fractionlist {
     NSMutableString * str = [[NSMutableString alloc] initWithCapacity:16];
     
@@ -483,28 +407,6 @@ const uint mTiffLength = 0x2a; // after byte align bits, next to bits are 0x002a
 - (void) splitDouble: (double) val withIntComponent: (int*) rightside withFloatRemainder: (double*) leftside {
     *rightside = val; // convert numb to int representation, which truncates the decimal portion
     *leftside = val - *rightside;
-//    int digits = [[NSString stringWithFormat:@"%f", de] length] - 2;
-//    *leftside =  de * pow(10,digits);;
-}
-
-
-//
-- (NSString*) hexStringFromData : (NSData*) data {
-    //overflow detection
-    const unsigned char *dataBuffer = [data bytes];
-    return [[NSString alloc] initWithFormat: @"%02x%02x",
-                                        (unsigned char)dataBuffer[0],
-                                        (unsigned char)dataBuffer[1]];
-}
-
-// convert a hex string to a number
-- (NSNumber*) numericFromHexString : (NSString *) hexstring {
-    NSScanner * scan = NULL;
-    unsigned int numbuf= 0;
-    
-    scan = [NSScanner scannerWithString:hexstring];
-    [scan scanHexInt:&numbuf];
-    return [NSNumber numberWithInt:numbuf];
 }
 
 @end