diff options
author | Jeff Sharkey <jsharkey@android.com> | 2013-08-21 11:27:36 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2013-08-21 11:30:43 -0700 |
commit | 31b17e69a87e4caa50f9c6b1a47c84ef75f79d83 (patch) | |
tree | 564537abc7996bdddc3cf4e6c8094d387f859a15 | |
parent | b788750e0d55f0986e5ee0aadc91ec340b9f1b63 (diff) | |
download | jhead-31b17e69a87e4caa50f9c6b1a47c84ef75f79d83.tar.gz |
Support extracting of thumbnail offsets.android-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1android-cts-4.4_r4android-cts-4.4_r1android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.4_r0.7android-4.4.2_r2.0.1android-4.4.2_r2android-4.4.2_r1.0.1android-4.4.2_r1android-4.4.1_r1.0.1android-4.4.1_r1kitkat-releasekitkat-mr1.1-releasekitkat-mr1-releasekitkat-cts-releasekitkat-cts-devidea133
AssetFileDescriptors work by defining a region of an underlying
FileDescriptor across process boundaries, so they require the offset
and length of the EXIF thumbnail region.
Bug: 10412208
Change-Id: I7520fdbbddd7afb1c454bd523ec32eb3602a998f
-rw-r--r-- | jhead.h | 1 | ||||
-rwxr-xr-x | jpgfile.c | 4 | ||||
-rw-r--r-- | main.c | 30 |
3 files changed, 35 insertions, 0 deletions
@@ -52,6 +52,7 @@ typedef unsigned char uchar; typedef struct { uchar * Data; int Type; + unsigned Offset; unsigned Size; }Section_t; @@ -156,6 +156,7 @@ int ReadJpegSections (FILE * infile, ReadMode_t ReadMode) Sections[SectionsRead].Type = marker; + Sections[SectionsRead].Offset = ftell(infile); // Read the length of the section. lh = fgetc(infile); @@ -221,6 +222,7 @@ int ReadJpegSections (FILE * infile, ReadMode_t ReadMode) CheckSectionsAllocated(); Sections[SectionsRead].Data = Data; + Sections[SectionsRead].Offset = cp; Sections[SectionsRead].Size = size; Sections[SectionsRead].Type = PSEUDO_IMAGE_MARKER; SectionsRead ++; @@ -351,6 +353,7 @@ int ReadJpegSectionsFromBuffer (unsigned char* buffer, unsigned int buffer_size, } Sections[SectionsRead].Type = marker; + Sections[SectionsRead].Offset = pos; // Read the length of the section. lh = buffer[pos++]; @@ -410,6 +413,7 @@ int ReadJpegSectionsFromBuffer (unsigned char* buffer, unsigned int buffer_size, CheckSectionsAllocated(); Sections[SectionsRead].Data = Data; + Sections[SectionsRead].Offset = pos; Sections[SectionsRead].Size = size; Sections[SectionsRead].Type = PSEUDO_IMAGE_MARKER; SectionsRead ++; @@ -475,6 +475,35 @@ noThumbnail: return NULL; } +static jlongArray getThumbnailRange(JNIEnv *env, jobject jobj, jstring jfilename) { + jlongArray resultArray = NULL; + const char* filename = (*env)->GetStringUTFChars(env, jfilename, NULL); + if (filename) { + loadExifInfo(filename, FALSE); + Section_t* ExifSection = FindSection(M_EXIF); + if (ExifSection == NULL || ImageInfo.ThumbnailSize == 0) { + goto done; + } + + jlong result[2]; + result[0] = ExifSection->Offset + ImageInfo.ThumbnailOffset + 8; + result[1] = ImageInfo.ThumbnailSize; + + resultArray = (*env)->NewLongArray(env, 2); + if (resultArray == NULL) { + goto done; + } + + (*env)->SetLongArrayRegion(env, resultArray, 0, 2, result); + } +done: + if (filename) { + (*env)->ReleaseStringUTFChars(env, jfilename, filename); + } + DiscardData(); + return resultArray; +} + static int attributeCount; // keep track of how many attributes we've added // returns new buffer length @@ -728,6 +757,7 @@ static JNINativeMethod methods[] = { {"appendThumbnailNative", "(Ljava/lang/String;Ljava/lang/String;)Z", (void*)appendThumbnail }, {"commitChangesNative", "(Ljava/lang/String;)V", (void*)commitChanges }, {"getThumbnailNative", "(Ljava/lang/String;)[B", (void*)getThumbnail }, + {"getThumbnailRangeNative", "(Ljava/lang/String;)[J", (void*)getThumbnailRange }, }; /* |