Permalink
Browse files

Merge pull request #1 from markpmiles/master

Added heading metadata handling
  • Loading branch information...
gpambrozio committed Jul 4, 2011
2 parents 956e05f + 1dc636c commit dd973eb94997ff09bd8772b12bf7cc99916a33e5
Showing with 43 additions and 7 deletions.
  1. +2 −0 GusUtils/NSMutableDictionary+ImageMetadata.h
  2. +41 −7 GusUtils/NSMutableDictionary+ImageMetadata.m
@@ -45,7 +45,9 @@
- (void)setKeywords:(NSString*)keywords;
- (void)setImageOrientarion:(UIImageOrientation)orientation;
- (void)setDigitalZoom:(CGFloat)zoom;
+- (void)setHeading:(CLHeading*)heading;
@property (nonatomic, assign) CLLocation *location;
+@property (nonatomic, assign) CLLocationDirection trueHeading;
@end
@@ -20,6 +20,8 @@ @implementation FIX_CATEGORY_BUG_ImageMetadataCategory @end
@implementation NSMutableDictionary (ImageMetadataCategory)
+@dynamic trueHeading;
+
- (id)initWithImageSampleBuffer:(CMSampleBufferRef) imageDataSampleBuffer {
// Dictionary of metadata is here
@@ -106,19 +108,41 @@ - (void)setLocation:(CLLocation *)location {
lngRef = @"E";
}
- NSDictionary* locDict = [[NSDictionary alloc] initWithObjectsAndKeys:
- location.timestamp, (NSString*)kCGImagePropertyGPSTimeStamp,
- latRef, (NSString*)kCGImagePropertyGPSLatitudeRef,
- [NSNumber numberWithFloat:exifLatitude], (NSString*)kCGImagePropertyGPSLatitude,
- lngRef, (NSString*)kCGImagePropertyGPSLongitudeRef,
- [NSNumber numberWithFloat:exifLongitude], (NSString*)kCGImagePropertyGPSLongitude,
- nil];
+ NSMutableDictionary *locDict = [[NSMutableDictionary alloc] init];
+ if ([self objectForKey:(NSString*)kCGImagePropertyGPSDictionary]) {
+ [locDict addEntriesFromDictionary:[self objectForKey:(NSString*)kCGImagePropertyGPSDictionary]];
+ }
+ [locDict setObject:location.timestamp forKey:(NSString*)kCGImagePropertyGPSTimeStamp];
+ [locDict setObject:latRef forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
+ [locDict setObject:[NSNumber numberWithFloat:exifLatitude] forKey:(NSString*)kCGImagePropertyGPSLatitude];
+ [locDict setObject:lngRef forKey:(NSString*)kCGImagePropertyGPSLongitudeRef];
+ [locDict setObject:[NSNumber numberWithFloat:exifLongitude] forKey:(NSString*)kCGImagePropertyGPSLongitude];
+ [locDict setObject:[NSNumber numberWithFloat:location.horizontalAccuracy] forKey:(NSString*)kCGImagePropertyGPSDOP];
+ [locDict setObject:[NSNumber numberWithFloat:location.altitude] forKey:(NSString*)kCGImagePropertyGPSAltitude];
[self setObject:locDict forKey:(NSString*)kCGImagePropertyGPSDictionary];
[locDict release];
}
}
+// Set heading while preserving location metadata, if it exists.
+- (void)setHeading:(CLHeading *)locatioHeading {
+
+ if (locatioHeading) {
+
+ CLLocationDirection trueDirection = locatioHeading.trueHeading;
+ NSMutableDictionary *locDict = [[NSMutableDictionary alloc] init];
+ if ([self objectForKey:(NSString*)kCGImagePropertyGPSDictionary]) {
+ [locDict addEntriesFromDictionary:[self objectForKey:(NSString*)kCGImagePropertyGPSDictionary]];
+ }
+ [locDict setObject:@"T" forKey:(NSString*)kCGImagePropertyGPSImgDirectionRef];
+ [locDict setObject:[NSNumber numberWithFloat:trueDirection] forKey:(NSString*)kCGImagePropertyGPSImgDirection];
+
+ [self setObject:locDict forKey:(NSString*)kCGImagePropertyGPSDictionary];
+ [locDict release];
+ }
+}
+
- (CLLocation*)location {
NSDictionary *locDict = [self objectForKey:(NSString*)kCGImagePropertyGPSDictionary];
if (locDict) {
@@ -140,6 +164,16 @@ - (CLLocation*)location {
return nil;
}
+- (CLLocationDirection)trueHeading {
+ NSDictionary *locDict = [self objectForKey:(NSString*)kCGImagePropertyGPSDictionary];
+ CLLocationDirection heading = 0;
+ if (locDict) {
+ heading = [[locDict objectForKey:(NSString*)kCGImagePropertyGPSImgDirection] doubleValue];
+ }
+
+ return heading;
+}
+
- (NSMutableDictionary *)dictionaryForKey:(CFStringRef)key {
NSDictionary *dict = [self objectForKey:(NSString*)key];
NSMutableDictionary *mutableDict;

0 comments on commit dd973eb

Please sign in to comment.