summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-08-21 11:27:36 -0700
committerJeff Sharkey <jsharkey@android.com>2013-08-21 11:30:43 -0700
commit31b17e69a87e4caa50f9c6b1a47c84ef75f79d83 (patch)
tree564537abc7996bdddc3cf4e6c8094d387f859a15
parentb788750e0d55f0986e5ee0aadc91ec340b9f1b63 (diff)
downloadjhead-31b17e69a87e4caa50f9c6b1a47c84ef75f79d83.tar.gz
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.h1
-rwxr-xr-xjpgfile.c4
-rw-r--r--main.c30
3 files changed, 35 insertions, 0 deletions
diff --git a/jhead.h b/jhead.h
index 596bfea..a3825e8 100644
--- a/jhead.h
+++ b/jhead.h
@@ -52,6 +52,7 @@ typedef unsigned char uchar;
typedef struct {
uchar * Data;
int Type;
+ unsigned Offset;
unsigned Size;
}Section_t;
diff --git a/jpgfile.c b/jpgfile.c
index 1ef9e99..214c888 100755
--- a/jpgfile.c
+++ b/jpgfile.c
@@ -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 ++;
diff --git a/main.c b/main.c
index b8f1445..ace5bdd 100644
--- a/main.c
+++ b/main.c
@@ -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 },
};
/*