summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAngus Kong <shkong@google.com>2012-01-19 15:56:10 +0800
committerAngus Kong <shkong@google.com>2012-01-19 17:19:54 +0800
commit482486a3d21c4d4c933f3081ff14122292314bc7 (patch)
tree7ce8d7f6ae2cebff79b2be7747ee533a0d56bb2f
parentf485c62af532ad43c72268d7a5b3a399b1ef51cb (diff)
downloadjhead-482486a3d21c4d4c933f3081ff14122292314bc7.tar.gz
Use values from attributes for DateTime tag.
The library uses values from attributes for DateTime tag if found in the attribute set. This is to fix the bug when there is a DateTime tag from java side, jhead library will write multiple DateTime tags. bug:5766177 Change-Id: I98de235edabdd1de4fc7d111ca13f3b580c2e351
-rw-r--r--exif.c24
-rw-r--r--jhead.c3
-rw-r--r--jhead.h5
-rw-r--r--main.c7
4 files changed, 26 insertions, 13 deletions
diff --git a/exif.c b/exif.c
index 8d8c0c0..381d9dc 100644
--- a/exif.c
+++ b/exif.c
@@ -311,6 +311,11 @@ int TagNameToValue(const char* tagName)
return -1;
}
+int IsDateTimeTag(unsigned short tag)
+{
+ return ((tag == TAG_DATETIME)? TRUE: FALSE);
+}
+
//--------------------------------------------------------------------------
// Convert a 16 bit unsigned value to file's native byte order
//--------------------------------------------------------------------------
@@ -1200,7 +1205,7 @@ char* formatStr(int format) {
// Create minimal exif header - just date and thumbnail pointers,
// so that date and thumbnail may be filled later.
//--------------------------------------------------------------------------
-static void create_EXIF_internal(ExifElement_t* elements, int exifTagCount, int gpsTagCount, char* Buffer)
+static void create_EXIF_internal(ExifElement_t* elements, int exifTagCount, int gpsTagCount, int hasDateTimeTag, char* Buffer)
{
unsigned short NumEntries;
int DataWriteIndex;
@@ -1221,21 +1226,26 @@ static void create_EXIF_internal(ExifElement_t* elements, int exifTagCount, int
{
DirIndex = DataWriteIndex;
- NumEntries = 2 + exifTagCount; // the two extra are the datetime and the thumbnail
+ NumEntries = 1 + exifTagCount; // the extra is the thumbnail
if (gpsTagCount) {
++NumEntries; // allow for the GPS info tag
}
+ if (!hasDateTimeTag) {
+ // We have to write extra date time tag. The entry number should be
+ // adjusted.
+ ++NumEntries;
+ }
DataWriteIndex += 2 + NumEntries*12 + 4;
Put16u(Buffer+DirIndex, NumEntries); // Number of entries
DirIndex += 2;
// Entries go here...
- {
+ if (!hasDateTimeTag) {
// Date/time entry
char* dateTime = NULL;
char dateBuf[20];
- if (ImageInfo.numDateTimeTags){
+ if (ImageInfo.numDateTimeTags) {
// If we had a pre-existing exif header, use time from that.
dateTime = ImageInfo.DateTime;
} else {
@@ -1275,7 +1285,7 @@ static void create_EXIF_internal(ExifElement_t* elements, int exifTagCount, int
&DirIndex,
&DataWriteIndex);
}
-
+
if (gpsTagCount) {
// Link to gps dir entry
writeExifTagAndData(TAG_GPSINFO,
@@ -1412,7 +1422,7 @@ static void create_EXIF_internal(ExifElement_t* elements, int exifTagCount, int
}
}
-void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount)
+void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount, int hasDateTimeTag)
{
// It is hard to calculate exact necessary size for editing the exif
// header dynamically, so we are using the maximum size of EXIF, 64K
@@ -1420,7 +1430,7 @@ void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount)
char* Buffer = malloc(EXIF_MAX_SIZE);
if (Buffer != NULL) {
- create_EXIF_internal(elements, exifTagCount, gpsTagCount, Buffer);
+ create_EXIF_internal(elements, exifTagCount, gpsTagCount, hasDateTimeTag, Buffer);
free(Buffer);
} else {
ErrFatal("Could not allocate memory");
diff --git a/jhead.c b/jhead.c
index 8f3002e..7ecd84c 100644
--- a/jhead.c
+++ b/jhead.c
@@ -911,7 +911,7 @@ void ProcessFile(const char * FileName)
if (CreateExifSection){
// Make a new minimal exif section
- create_EXIF(NULL, 0, 0);
+ create_EXIF(NULL, 0, 0, 0);
Modified = TRUE;
}
@@ -1696,4 +1696,3 @@ int main (int argc, char **argv)
#endif
#endif // commented out -- security risk
-
diff --git a/jhead.h b/jhead.h
index 4347fe8..460747f 100644
--- a/jhead.h
+++ b/jhead.h
@@ -176,8 +176,9 @@ int Get16u(void * Short);
unsigned Get32u(void * Long);
int Get32s(void * Long);
void Put32u(void * Value, unsigned PutValue);
-void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount);
+void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount, int hasDateTimeTag);
int TagNameToValue(const char* tagName);
+int IsDateTimeTag(unsigned short tag);
//--------------------------------------------------------------------------
// Exif format descriptor stuff
@@ -277,5 +278,3 @@ extern char* formatStr(int format);
#define M_DHT 0xC4
#define M_DRI 0xDD
#define M_IPTC 0xED // IPTC marker
-
-
diff --git a/main.c b/main.c
index b67724f..b8f1445 100644
--- a/main.c
+++ b/main.c
@@ -230,6 +230,7 @@ static void saveAttributes(JNIEnv *env, jobject jobj, jstring jfilename, jstring
int i;
char tag[100];
+ int hasDateTimeTag = FALSE;
int gpsTagCount = 0;
int exifTagCount = 0;
@@ -263,6 +264,10 @@ static void saveAttributes(JNIEnv *env, jobject jobj, jstring jfilename, jstring
}
attrPtr = tagEnd + 1;
+ if (IsDateTimeTag(exifElementTable[i].Tag)) {
+ hasDateTimeTag = TRUE;
+ }
+
// next get the length of the attribute value
int valueLen = atoi(attrPtr);
attrPtr = strchr(attrPtr, ' ') + 1;
@@ -315,7 +320,7 @@ static void saveAttributes(JNIEnv *env, jobject jobj, jstring jfilename, jstring
}
}
- create_EXIF(exifElementTable, exifTagCount, gpsTagCount);
+ create_EXIF(exifElementTable, exifTagCount, gpsTagCount, hasDateTimeTag);
if (thumbnailData) {
copyThumbnailData(thumbnailData, thumbnailLength);