diff options
author | Wu-cheng Li <wuchengli@google.com> | 2010-01-31 22:34:33 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2010-02-04 16:26:16 +0800 |
commit | 574d52d26f44b600cdab3d3361eaa5f6dd9d7a4d (patch) | |
tree | 6641ca57e134cb2adec419041c701df211e43336 | |
parent | a39920ca4b96a456511fa32ba90c77f119a274c3 (diff) | |
download | jhead-574d52d26f44b600cdab3d3361eaa5f6dd9d7a4d.tar.gz |
Change focal length string to rational.
bug:2375989
-rw-r--r-- | exif.c | 14 | ||||
-rw-r--r-- | jhead.h | 7 | ||||
-rw-r--r-- | main.c | 11 |
3 files changed, 24 insertions, 8 deletions
@@ -717,7 +717,8 @@ static void ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, case TAG_FOCALLENGTH: // Nice digital cameras actually save the focal length as a function // of how farthey are zoomed in. - ImageInfo.FocalLength = (float)ConvertAnyFormat(ValuePtr, Format); + ImageInfo.FocalLength.num = Get32u(ValuePtr); + ImageInfo.FocalLength.denom = Get32u(4+(char *)ValuePtr); break; case TAG_SUBJECT_DISTANCE: @@ -1047,10 +1048,13 @@ void process_EXIF (unsigned char * ExifSection, unsigned int length) // that Jhad can do about it - its a camera problem. ImageInfo.CCDWidth = (float)(ExifImageWidth * FocalplaneUnits / FocalplaneXRes); - if (ImageInfo.FocalLength && ImageInfo.FocalLength35mmEquiv == 0){ + if (ImageInfo.FocalLength.num != 0 && ImageInfo.FocalLength.denom != 0 + && ImageInfo.FocalLength35mmEquiv == 0){ // Compute 35 mm equivalent focal length based on sensor geometry if we haven't // already got it explicitly from a tag. - ImageInfo.FocalLength35mmEquiv = (int)(ImageInfo.FocalLength/ImageInfo.CCDWidth*36 + 0.5); + ImageInfo.FocalLength35mmEquiv = (int)( + (double)ImageInfo.FocalLength.num / ImageInfo.FocalLength.denom + / ImageInfo.CCDWidth * 36 + 0.5); } } } @@ -1559,8 +1563,8 @@ void ShowImageInfo(int ShowFileInfo) } - if (ImageInfo.FocalLength){ - printf("Focal length : %4.1fmm",(double)ImageInfo.FocalLength); + if (ImageInfo.FocalLength.num != 0 && ImageInfo.FocalLength.denom != 0) { + printf("Focal length : %4.1fmm",(double)ImageInfo.FocalLength.num / ImageInfo.FocalLength.denom); if (ImageInfo.FocalLength35mmEquiv){ printf(" (35mm equivalent: %dmm)", ImageInfo.FocalLength35mmEquiv); } @@ -59,6 +59,11 @@ extern int DumpExifMap; #define MAX_DATE_COPIES 10 +typedef struct { + uint32_t num; + uint32_t denom; +} rat_t; + //-------------------------------------------------------------------------- // This structure stores Exif header image elements in a simple manner // Used to store camera data as extracted from the various ways that it can be @@ -75,7 +80,7 @@ typedef struct { int IsColor; int Process; int FlashUsed; - float FocalLength; + rat_t FocalLength; float ExposureTime; float ApertureFNumber; float Distance; @@ -517,6 +517,13 @@ static int addKeyValueDouble(char** buf, int bufLen, const char* key, double val return addKeyValueString(buf, bufLen, key, valueStr); } +// Returns new buffer length. Rational value will be appended as "numerator/denominator". +static int addKeyValueRational(char** buf, int bufLen, const char* key, rat_t value) { + char valueStr[25]; + snprintf(valueStr, sizeof(valueStr), "%u/%u", value.num, value.denom); + return addKeyValueString(buf, bufLen, key, valueStr); +} + static jstring getAttributes(JNIEnv *env, jobject jobj, jstring jfilename) { #ifdef SUPERDEBUG @@ -571,8 +578,8 @@ static jstring getAttributes(JNIEnv *env, jobject jobj, jstring jfilename) bufLen = addKeyValueInt(&buf, bufLen, "Flash", ImageInfo.FlashUsed); if (bufLen == 0) return NULL; - if (ImageInfo.FocalLength){ - bufLen = addKeyValueInt(&buf, bufLen, "FocalLength", ImageInfo.FocalLength); + if (ImageInfo.FocalLength.num != 0 && ImageInfo.FocalLength.denom != 0) { + bufLen = addKeyValueRational(&buf, bufLen, "FocalLength", ImageInfo.FocalLength); if (bufLen == 0) return NULL; } |