Merge "Revert "ExifInterface: switch from using jhead to java implementation"" into nyc-dev
am: b21622d477
* commit 'b21622d4773c64b9815818e71f8011ca17e79974':
Revert "ExifInterface: switch from using jhead to java implementation"
This commit is contained in:
@@ -20207,8 +20207,6 @@ package android.media {
|
||||
|
||||
public class ExifInterface {
|
||||
ctor public ExifInterface(java.lang.String) throws java.io.IOException;
|
||||
ctor public ExifInterface(java.io.FileDescriptor) throws java.io.IOException;
|
||||
ctor public ExifInterface(java.io.InputStream) throws java.io.IOException;
|
||||
method public double getAltitude(double);
|
||||
method public java.lang.String getAttribute(java.lang.String);
|
||||
method public double getAttributeDouble(java.lang.String, double);
|
||||
@@ -20230,10 +20228,6 @@ package android.media {
|
||||
field public static final java.lang.String TAG_APERTURE = "FNumber";
|
||||
field public static final java.lang.String TAG_DATETIME = "DateTime";
|
||||
field public static final java.lang.String TAG_DATETIME_DIGITIZED = "DateTimeDigitized";
|
||||
field public static final java.lang.String TAG_DIGITAL_ZOOM_RATIO = "DigitalZoomRatio";
|
||||
field public static final java.lang.String TAG_EXPOSURE_BIAS_VALUE = "ExposureBiasValue";
|
||||
field public static final java.lang.String TAG_EXPOSURE_MODE = "ExposureMode";
|
||||
field public static final java.lang.String TAG_EXPOSURE_PROGRAM = "ExposureProgram";
|
||||
field public static final java.lang.String TAG_EXPOSURE_TIME = "ExposureTime";
|
||||
field public static final java.lang.String TAG_FLASH = "Flash";
|
||||
field public static final java.lang.String TAG_FOCAL_LENGTH = "FocalLength";
|
||||
@@ -20249,12 +20243,9 @@ package android.media {
|
||||
field public static final java.lang.String TAG_IMAGE_LENGTH = "ImageLength";
|
||||
field public static final java.lang.String TAG_IMAGE_WIDTH = "ImageWidth";
|
||||
field public static final java.lang.String TAG_ISO = "ISOSpeedRatings";
|
||||
field public static final java.lang.String TAG_LIGHT_SOURCE = "LightSource";
|
||||
field public static final java.lang.String TAG_MAKE = "Make";
|
||||
field public static final java.lang.String TAG_METERING_MODE = "MeteringMode";
|
||||
field public static final java.lang.String TAG_MODEL = "Model";
|
||||
field public static final java.lang.String TAG_ORIENTATION = "Orientation";
|
||||
field public static final java.lang.String TAG_SUBJECT_DISTANCE = "SubjectDistance";
|
||||
field public static final java.lang.String TAG_SUBSEC_TIME = "SubSecTime";
|
||||
field public static final java.lang.String TAG_SUBSEC_TIME_DIG = "SubSecTimeDigitized";
|
||||
field public static final java.lang.String TAG_SUBSEC_TIME_ORIG = "SubSecTimeOriginal";
|
||||
|
||||
@@ -21715,8 +21715,6 @@ package android.media {
|
||||
|
||||
public class ExifInterface {
|
||||
ctor public ExifInterface(java.lang.String) throws java.io.IOException;
|
||||
ctor public ExifInterface(java.io.FileDescriptor) throws java.io.IOException;
|
||||
ctor public ExifInterface(java.io.InputStream) throws java.io.IOException;
|
||||
method public double getAltitude(double);
|
||||
method public java.lang.String getAttribute(java.lang.String);
|
||||
method public double getAttributeDouble(java.lang.String, double);
|
||||
@@ -21738,10 +21736,6 @@ package android.media {
|
||||
field public static final java.lang.String TAG_APERTURE = "FNumber";
|
||||
field public static final java.lang.String TAG_DATETIME = "DateTime";
|
||||
field public static final java.lang.String TAG_DATETIME_DIGITIZED = "DateTimeDigitized";
|
||||
field public static final java.lang.String TAG_DIGITAL_ZOOM_RATIO = "DigitalZoomRatio";
|
||||
field public static final java.lang.String TAG_EXPOSURE_BIAS_VALUE = "ExposureBiasValue";
|
||||
field public static final java.lang.String TAG_EXPOSURE_MODE = "ExposureMode";
|
||||
field public static final java.lang.String TAG_EXPOSURE_PROGRAM = "ExposureProgram";
|
||||
field public static final java.lang.String TAG_EXPOSURE_TIME = "ExposureTime";
|
||||
field public static final java.lang.String TAG_FLASH = "Flash";
|
||||
field public static final java.lang.String TAG_FOCAL_LENGTH = "FocalLength";
|
||||
@@ -21757,12 +21751,9 @@ package android.media {
|
||||
field public static final java.lang.String TAG_IMAGE_LENGTH = "ImageLength";
|
||||
field public static final java.lang.String TAG_IMAGE_WIDTH = "ImageWidth";
|
||||
field public static final java.lang.String TAG_ISO = "ISOSpeedRatings";
|
||||
field public static final java.lang.String TAG_LIGHT_SOURCE = "LightSource";
|
||||
field public static final java.lang.String TAG_MAKE = "Make";
|
||||
field public static final java.lang.String TAG_METERING_MODE = "MeteringMode";
|
||||
field public static final java.lang.String TAG_MODEL = "Model";
|
||||
field public static final java.lang.String TAG_ORIENTATION = "Orientation";
|
||||
field public static final java.lang.String TAG_SUBJECT_DISTANCE = "SubjectDistance";
|
||||
field public static final java.lang.String TAG_SUBSEC_TIME = "SubSecTime";
|
||||
field public static final java.lang.String TAG_SUBSEC_TIME_DIG = "SubSecTimeDigitized";
|
||||
field public static final java.lang.String TAG_SUBSEC_TIME_ORIG = "SubSecTimeOriginal";
|
||||
|
||||
@@ -20216,8 +20216,6 @@ package android.media {
|
||||
|
||||
public class ExifInterface {
|
||||
ctor public ExifInterface(java.lang.String) throws java.io.IOException;
|
||||
ctor public ExifInterface(java.io.FileDescriptor) throws java.io.IOException;
|
||||
ctor public ExifInterface(java.io.InputStream) throws java.io.IOException;
|
||||
method public double getAltitude(double);
|
||||
method public java.lang.String getAttribute(java.lang.String);
|
||||
method public double getAttributeDouble(java.lang.String, double);
|
||||
@@ -20239,10 +20237,6 @@ package android.media {
|
||||
field public static final java.lang.String TAG_APERTURE = "FNumber";
|
||||
field public static final java.lang.String TAG_DATETIME = "DateTime";
|
||||
field public static final java.lang.String TAG_DATETIME_DIGITIZED = "DateTimeDigitized";
|
||||
field public static final java.lang.String TAG_DIGITAL_ZOOM_RATIO = "DigitalZoomRatio";
|
||||
field public static final java.lang.String TAG_EXPOSURE_BIAS_VALUE = "ExposureBiasValue";
|
||||
field public static final java.lang.String TAG_EXPOSURE_MODE = "ExposureMode";
|
||||
field public static final java.lang.String TAG_EXPOSURE_PROGRAM = "ExposureProgram";
|
||||
field public static final java.lang.String TAG_EXPOSURE_TIME = "ExposureTime";
|
||||
field public static final java.lang.String TAG_FLASH = "Flash";
|
||||
field public static final java.lang.String TAG_FOCAL_LENGTH = "FocalLength";
|
||||
@@ -20258,12 +20252,9 @@ package android.media {
|
||||
field public static final java.lang.String TAG_IMAGE_LENGTH = "ImageLength";
|
||||
field public static final java.lang.String TAG_IMAGE_WIDTH = "ImageWidth";
|
||||
field public static final java.lang.String TAG_ISO = "ISOSpeedRatings";
|
||||
field public static final java.lang.String TAG_LIGHT_SOURCE = "LightSource";
|
||||
field public static final java.lang.String TAG_MAKE = "Make";
|
||||
field public static final java.lang.String TAG_METERING_MODE = "MeteringMode";
|
||||
field public static final java.lang.String TAG_MODEL = "Model";
|
||||
field public static final java.lang.String TAG_ORIENTATION = "Orientation";
|
||||
field public static final java.lang.String TAG_SUBJECT_DISTANCE = "SubjectDistance";
|
||||
field public static final java.lang.String TAG_SUBSEC_TIME = "SubSecTime";
|
||||
field public static final java.lang.String TAG_SUBSEC_TIME_DIG = "SubSecTimeDigitized";
|
||||
field public static final java.lang.String TAG_SUBSEC_TIME_ORIG = "SubSecTimeOriginal";
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -43,10 +43,14 @@ LOCAL_SHARED_LIBRARIES := \
|
||||
libcamera_client \
|
||||
libmtp \
|
||||
libusbhost \
|
||||
libjhead \
|
||||
libexif \
|
||||
libpiex \
|
||||
libstagefright_amrnb_common
|
||||
|
||||
LOCAL_REQUIRED_MODULES := \
|
||||
libjhead_jni
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := \
|
||||
libstagefright_amrnbenc
|
||||
|
||||
|
||||
@@ -83,18 +83,19 @@ static void ExifInterface_initRaw(JNIEnv *env) {
|
||||
}
|
||||
|
||||
static jobject ExifInterface_getRawMetadata(
|
||||
JNIEnv* env, jclass /* clazz */, jobject jfileDescriptor) {
|
||||
int fd = jniGetFDFromFileDescriptor(env, jfileDescriptor);
|
||||
if (fd < 0) {
|
||||
ALOGI("Invalid file descriptor");
|
||||
JNIEnv* env, jclass /* clazz */, jstring jfilename) {
|
||||
const char* filenameChars = env->GetStringUTFChars(jfilename, NULL);
|
||||
if (filenameChars == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
String8 filename(filenameChars);
|
||||
env->ReleaseStringUTFChars(jfilename, filenameChars);
|
||||
|
||||
piex::PreviewImageData image_data;
|
||||
std::unique_ptr<FileStream> stream(new FileStream(fd));
|
||||
std::unique_ptr<FileStream> stream(new FileStream(filename));
|
||||
|
||||
if (!GetExifFromRawImage(stream.get(), String8("[file descriptor]"), image_data)) {
|
||||
ALOGI("Raw image not detected");
|
||||
if (!GetExifFromRawImage(stream.get(), filename, image_data)) {
|
||||
ALOGI("Raw image not detected: %s", filename.string());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -262,7 +263,7 @@ static jobject ExifInterface_getRawMetadata(
|
||||
|
||||
static JNINativeMethod gMethods[] = {
|
||||
{ "initRawNative", "()V", (void *)ExifInterface_initRaw },
|
||||
{ "getRawAttributesNative", "(Ljava/io/FileDescriptor;)Ljava/util/HashMap;",
|
||||
{ "getRawAttributesNative", "(Ljava/lang/String;)Ljava/util/HashMap;",
|
||||
(void*)ExifInterface_getRawMetadata },
|
||||
};
|
||||
|
||||
|
||||
@@ -28,19 +28,6 @@
|
||||
|
||||
namespace android {
|
||||
|
||||
FileStream::FileStream(const int fd)
|
||||
: mPosition(0),
|
||||
mSize(0) {
|
||||
mFile = fdopen(fd, "r");
|
||||
if (mFile == NULL) {
|
||||
return;
|
||||
}
|
||||
// Get the size.
|
||||
fseek(mFile, 0l, SEEK_END);
|
||||
mSize = ftell(mFile);
|
||||
fseek(mFile, 0l, SEEK_SET);
|
||||
}
|
||||
|
||||
FileStream::FileStream(const String8 filename)
|
||||
: mPosition(0),
|
||||
mSize(0) {
|
||||
|
||||
@@ -35,7 +35,6 @@ private:
|
||||
size_t mSize;
|
||||
|
||||
public:
|
||||
FileStream(const int fd);
|
||||
FileStream(const String8 filename);
|
||||
~FileStream();
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 103 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 8.4 KiB |
Binary file not shown.
@@ -1,108 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2016 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
<array name="exifbyteorderii_jpg">
|
||||
<item>true</item>
|
||||
<item>512</item>
|
||||
<item>288</item>
|
||||
<item>false</item>
|
||||
<item>0.0</item>
|
||||
<item>0.0</item>
|
||||
<item>0.0</item>
|
||||
<item>SAMSUNG</item>
|
||||
<item>SM-N900S</item>
|
||||
<item>2.200</item>
|
||||
<item>2016:01:29 18:32:27</item>
|
||||
<item>0.033</item>
|
||||
<item>0</item>
|
||||
<item>413/100</item>
|
||||
<item />
|
||||
<item />
|
||||
<item />
|
||||
<item />
|
||||
<item />
|
||||
<item />
|
||||
<item />
|
||||
<item />
|
||||
<item />
|
||||
<item>480</item>
|
||||
<item>640</item>
|
||||
<item>50</item>
|
||||
<item>6</item>
|
||||
<item>0</item>
|
||||
</array>
|
||||
<array name="exifbyteordermm_jpg">
|
||||
<item>false</item>
|
||||
<item>0</item>
|
||||
<item>0</item>
|
||||
<item>true</item>
|
||||
<item>0.0</item>
|
||||
<item>0.0</item>
|
||||
<item>0.0</item>
|
||||
<item>LGE</item>
|
||||
<item>Nexus 5</item>
|
||||
<item>2.400</item>
|
||||
<item>2016:01:29 15:44:58</item>
|
||||
<item>0.017</item>
|
||||
<item>0</item>
|
||||
<item>3970/1000</item>
|
||||
<item>0/1000</item>
|
||||
<item>0</item>
|
||||
<item>1970:01:01</item>
|
||||
<item>0/1,0/1,0/10000</item>
|
||||
<item>N</item>
|
||||
<item>0/1,0/1,0/10000</item>
|
||||
<item>E</item>
|
||||
<item>GPS</item>
|
||||
<item>00:00:00</item>
|
||||
<item>176</item>
|
||||
<item>144</item>
|
||||
<item>146</item>
|
||||
<item>0</item>
|
||||
<item>0</item>
|
||||
</array>
|
||||
<array name="lg_g4_iso_800_dng">
|
||||
<item>false</item>
|
||||
<item>0</item>
|
||||
<item>0</item>
|
||||
<item>true</item>
|
||||
<item>53.834507</item>
|
||||
<item>10.69585</item>
|
||||
<item>0.0</item>
|
||||
<item>LGE</item>
|
||||
<item>LG-H815</item>
|
||||
<item>1.800</item>
|
||||
<item>2015:11:12 16:46:18</item>
|
||||
<item>0.0040</item>
|
||||
<item>0.0</item>
|
||||
<item>442/100</item>
|
||||
<item>0/1</item>
|
||||
<item>0</item>
|
||||
<item>1970:01:17</item>
|
||||
<item>53/1,50/1,423/100</item>
|
||||
<item>N</item>
|
||||
<item>10/1,41/1,4506/100</item>
|
||||
<item>E</item>
|
||||
<item />
|
||||
<item>18:08:10</item>
|
||||
<item>337</item>
|
||||
<item>600</item>
|
||||
<item>800</item>
|
||||
<item>1</item>
|
||||
<item />
|
||||
</array>
|
||||
</resources>
|
||||
@@ -50,7 +50,6 @@ public class MediaFrameworkUnitTestRunner extends InstrumentationTestRunner {
|
||||
addMediaScannerUnitTests(suite);
|
||||
addCameraUnitTests(suite);
|
||||
addImageReaderTests(suite);
|
||||
addExifInterfaceTests(suite);
|
||||
return suite;
|
||||
}
|
||||
|
||||
@@ -110,8 +109,4 @@ public class MediaFrameworkUnitTestRunner extends InstrumentationTestRunner {
|
||||
private void addMediaScannerUnitTests(TestSuite suite) {
|
||||
suite.addTestSuite(MediaInserterTest.class);
|
||||
}
|
||||
|
||||
private void addExifInterfaceTests(TestSuite suite) {
|
||||
suite.addTestSuite(ExifInterfaceTest.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,418 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.mediaframeworktest.unit;
|
||||
|
||||
import com.android.mediaframeworktest.R;
|
||||
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.media.ExifInterface;
|
||||
import android.os.Environment;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.util.Log;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.system.OsConstants;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import libcore.io.IoUtils;
|
||||
import libcore.io.Streams;
|
||||
|
||||
public class ExifInterfaceTest extends AndroidTestCase {
|
||||
private static final String TAG = ExifInterface.class.getSimpleName();
|
||||
private static final boolean VERBOSE = false; // lots of logging
|
||||
|
||||
private static final double DIFFERENCE_TOLERANCE = .005;
|
||||
private static final int BUFFER_SIZE = 32768;
|
||||
|
||||
// List of files.
|
||||
private static final String EXIF_BYTE_ORDER_II_JPEG = "ExifByteOrderII.jpg";
|
||||
private static final String EXIF_BYTE_ORDER_MM_JPEG = "ExifByteOrderMM.jpg";
|
||||
private static final String LG_G4_ISO_800_DNG = "lg_g4_iso_800.dng";
|
||||
private static final int[] IMAGE_RESOURCES = new int[] {
|
||||
R.raw.image_exif_byte_order_ii, R.raw.image_exif_byte_order_mm, R.raw.lg_g4_iso_800 };
|
||||
private static final String[] IMAGE_FILENAMES = new String[] {
|
||||
EXIF_BYTE_ORDER_II_JPEG, EXIF_BYTE_ORDER_MM_JPEG, LG_G4_ISO_800_DNG };
|
||||
|
||||
private static final String[] EXIF_TAGS = {
|
||||
ExifInterface.TAG_MAKE,
|
||||
ExifInterface.TAG_MODEL,
|
||||
ExifInterface.TAG_APERTURE,
|
||||
ExifInterface.TAG_DATETIME,
|
||||
ExifInterface.TAG_EXPOSURE_TIME,
|
||||
ExifInterface.TAG_FLASH,
|
||||
ExifInterface.TAG_FOCAL_LENGTH,
|
||||
ExifInterface.TAG_GPS_ALTITUDE,
|
||||
ExifInterface.TAG_GPS_ALTITUDE_REF,
|
||||
ExifInterface.TAG_GPS_DATESTAMP,
|
||||
ExifInterface.TAG_GPS_LATITUDE,
|
||||
ExifInterface.TAG_GPS_LATITUDE_REF,
|
||||
ExifInterface.TAG_GPS_LONGITUDE,
|
||||
ExifInterface.TAG_GPS_LONGITUDE_REF,
|
||||
ExifInterface.TAG_GPS_PROCESSING_METHOD,
|
||||
ExifInterface.TAG_GPS_TIMESTAMP,
|
||||
ExifInterface.TAG_IMAGE_LENGTH,
|
||||
ExifInterface.TAG_IMAGE_WIDTH,
|
||||
ExifInterface.TAG_ISO,
|
||||
ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.TAG_WHITE_BALANCE
|
||||
};
|
||||
|
||||
private static class ExpectedValue {
|
||||
// Thumbnail information.
|
||||
public final boolean hasThumbnail;
|
||||
public final int thumbnailWidth;
|
||||
public final int thumbnailHeight;
|
||||
|
||||
// GPS information.
|
||||
public final boolean hasLatLong;
|
||||
public final float latitude;
|
||||
public final float longitude;
|
||||
public final float altitude;
|
||||
|
||||
// Values.
|
||||
public final String make;
|
||||
public final String model;
|
||||
public final float aperture;
|
||||
public final String datetime;
|
||||
public final float exposureTime;
|
||||
public final float flash;
|
||||
public final String focalLength;
|
||||
public final String gpsAltitude;
|
||||
public final String gpsAltitudeRef;
|
||||
public final String gpsDatestamp;
|
||||
public final String gpsLatitude;
|
||||
public final String gpsLatitudeRef;
|
||||
public final String gpsLongitude;
|
||||
public final String gpsLongitudeRef;
|
||||
public final String gpsProcessingMethod;
|
||||
public final String gpsTimestamp;
|
||||
public final String imageLength;
|
||||
public final String imageWidth;
|
||||
public final String iso;
|
||||
public final String whiteBalance;
|
||||
public final String orientation;
|
||||
|
||||
private static String getString(TypedArray typedArray, int index) {
|
||||
String stringValue = typedArray.getString(index);
|
||||
if (stringValue == null || stringValue.equals("")) {
|
||||
return null;
|
||||
}
|
||||
return stringValue.trim();
|
||||
}
|
||||
|
||||
public ExpectedValue(TypedArray typedArray) {
|
||||
// Reads thumbnail information.
|
||||
hasThumbnail = typedArray.getBoolean(0, false);
|
||||
thumbnailWidth = typedArray.getInt(1, 0);
|
||||
thumbnailHeight = typedArray.getInt(2, 0);
|
||||
|
||||
// Reads GPS information.
|
||||
hasLatLong = typedArray.getBoolean(3, false);
|
||||
latitude = typedArray.getFloat(4, 0f);
|
||||
longitude = typedArray.getFloat(5, 0f);
|
||||
altitude = typedArray.getFloat(6, 0f);
|
||||
|
||||
// Read values.
|
||||
make = getString(typedArray, 7);
|
||||
model = getString(typedArray, 8);
|
||||
aperture = typedArray.getFloat(9, 0f);
|
||||
datetime = getString(typedArray, 10);
|
||||
exposureTime = typedArray.getFloat(11, 0f);
|
||||
flash = typedArray.getFloat(12, 0f);
|
||||
focalLength = getString(typedArray, 13);
|
||||
gpsAltitude = getString(typedArray, 14);
|
||||
gpsAltitudeRef = getString(typedArray, 15);
|
||||
gpsDatestamp = getString(typedArray, 16);
|
||||
gpsLatitude = getString(typedArray, 17);
|
||||
gpsLatitudeRef = getString(typedArray, 18);
|
||||
gpsLongitude = getString(typedArray, 19);
|
||||
gpsLongitudeRef = getString(typedArray, 20);
|
||||
gpsProcessingMethod = getString(typedArray, 21);
|
||||
gpsTimestamp = getString(typedArray, 22);
|
||||
imageLength = getString(typedArray, 23);
|
||||
imageWidth = getString(typedArray, 24);
|
||||
iso = getString(typedArray, 25);
|
||||
orientation = getString(typedArray, 26);
|
||||
whiteBalance = getString(typedArray, 27);
|
||||
|
||||
typedArray.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
|
||||
for (int i = 0; i < IMAGE_RESOURCES.length; ++i) {
|
||||
String outputPath = new File(Environment.getExternalStorageDirectory(),
|
||||
IMAGE_FILENAMES[i]).getAbsolutePath();
|
||||
try (InputStream inputStream = getContext().getResources().openRawResource(
|
||||
IMAGE_RESOURCES[i])) {
|
||||
try (FileOutputStream outputStream = new FileOutputStream(outputPath)) {
|
||||
Streams.copy(inputStream, outputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
for (int i = 0; i < IMAGE_RESOURCES.length; ++i) {
|
||||
String imageFilePath = new File(Environment.getExternalStorageDirectory(),
|
||||
IMAGE_FILENAMES[i]).getAbsolutePath();
|
||||
File imageFile = new File(imageFilePath);
|
||||
if (imageFile.exists()) {
|
||||
imageFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private void printExifTagsAndValues(String fileName, ExifInterface exifInterface) {
|
||||
// Prints thumbnail information.
|
||||
if (exifInterface.hasThumbnail()) {
|
||||
byte[] thumbnailBytes = exifInterface.getThumbnail();
|
||||
if (thumbnailBytes != null) {
|
||||
Log.v(TAG, fileName + " Thumbnail size = " + thumbnailBytes.length);
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(
|
||||
thumbnailBytes, 0, thumbnailBytes.length);
|
||||
if (bitmap == null) {
|
||||
Log.e(TAG, fileName + " Corrupted thumbnail!");
|
||||
} else {
|
||||
Log.v(TAG, fileName + " Thumbnail size: " + bitmap.getWidth() + ", "
|
||||
+ bitmap.getHeight());
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, fileName + " Corrupted image (no thumbnail)");
|
||||
}
|
||||
} else {
|
||||
if (exifInterface.getThumbnail() != null) {
|
||||
Log.e(TAG, fileName + " Corrupted image (a thumbnail exists)");
|
||||
} else {
|
||||
Log.v(TAG, fileName + " No thumbnail");
|
||||
}
|
||||
}
|
||||
|
||||
// Prints GPS information.
|
||||
Log.v(TAG, fileName + " Altitude = " + exifInterface.getAltitude(.0));
|
||||
|
||||
float[] latLong = new float[2];
|
||||
if (exifInterface.getLatLong(latLong)) {
|
||||
Log.v(TAG, fileName + " Latitude = " + latLong[0]);
|
||||
Log.v(TAG, fileName + " Longitude = " + latLong[1]);
|
||||
} else {
|
||||
Log.v(TAG, fileName + "No latlong data");
|
||||
}
|
||||
|
||||
// Prints values.
|
||||
for (String tagKey : EXIF_TAGS) {
|
||||
String tagValue = exifInterface.getAttribute(tagKey);
|
||||
Log.v(TAG, fileName + "Key{" + tagKey + "} = '" + tagValue + "'");
|
||||
}
|
||||
}
|
||||
|
||||
private void compareFloatTag(ExifInterface exifInterface, String tag, float expectedValue) {
|
||||
String stringValue = exifInterface.getAttribute(tag);
|
||||
float floatValue = 0f;
|
||||
|
||||
if (stringValue != null) {
|
||||
floatValue = Float.parseFloat(stringValue);
|
||||
}
|
||||
|
||||
assertEquals(expectedValue, floatValue, DIFFERENCE_TOLERANCE);
|
||||
}
|
||||
|
||||
private void compareStringTag(ExifInterface exifInterface, String tag, String expectedValue) {
|
||||
String stringValue = exifInterface.getAttribute(tag);
|
||||
if (stringValue != null) {
|
||||
stringValue = stringValue.trim();
|
||||
}
|
||||
|
||||
assertEquals(expectedValue, stringValue);
|
||||
}
|
||||
|
||||
private void compareWithExpectedValue(ExifInterface exifInterface,
|
||||
ExpectedValue expectedValue) {
|
||||
// Checks a thumbnail image.
|
||||
assertEquals(expectedValue.hasThumbnail, exifInterface.hasThumbnail());
|
||||
if (expectedValue.hasThumbnail) {
|
||||
byte[] thumbnailBytes = exifInterface.getThumbnail();
|
||||
assertNotNull(thumbnailBytes);
|
||||
Bitmap thumbnailBitmap =
|
||||
BitmapFactory.decodeByteArray(thumbnailBytes, 0, thumbnailBytes.length);
|
||||
assertNotNull(thumbnailBitmap);
|
||||
assertEquals(expectedValue.thumbnailWidth, thumbnailBitmap.getWidth());
|
||||
assertEquals(expectedValue.thumbnailHeight, thumbnailBitmap.getHeight());
|
||||
} else {
|
||||
assertNull(exifInterface.getThumbnail());
|
||||
}
|
||||
|
||||
// Checks GPS information.
|
||||
float[] latLong = new float[2];
|
||||
assertEquals(expectedValue.hasLatLong, exifInterface.getLatLong(latLong));
|
||||
if (expectedValue.hasLatLong) {
|
||||
assertEquals(expectedValue.latitude, latLong[0], DIFFERENCE_TOLERANCE);
|
||||
assertEquals(expectedValue.longitude, latLong[1], DIFFERENCE_TOLERANCE);
|
||||
}
|
||||
assertEquals(expectedValue.altitude, exifInterface.getAltitude(.0), DIFFERENCE_TOLERANCE);
|
||||
|
||||
// Checks values.
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_MAKE, expectedValue.make);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_MODEL, expectedValue.model);
|
||||
compareFloatTag(exifInterface, ExifInterface.TAG_APERTURE, expectedValue.aperture);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_DATETIME, expectedValue.datetime);
|
||||
compareFloatTag(exifInterface, ExifInterface.TAG_EXPOSURE_TIME, expectedValue.exposureTime);
|
||||
compareFloatTag(exifInterface, ExifInterface.TAG_FLASH, expectedValue.flash);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_FOCAL_LENGTH, expectedValue.focalLength);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_GPS_ALTITUDE, expectedValue.gpsAltitude);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_GPS_ALTITUDE_REF,
|
||||
expectedValue.gpsAltitudeRef);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_GPS_DATESTAMP,
|
||||
expectedValue.gpsDatestamp);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_GPS_LATITUDE, expectedValue.gpsLatitude);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_GPS_LATITUDE_REF,
|
||||
expectedValue.gpsLatitudeRef);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_GPS_LONGITUDE,
|
||||
expectedValue.gpsLongitude);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_GPS_LONGITUDE_REF,
|
||||
expectedValue.gpsLongitudeRef);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_GPS_PROCESSING_METHOD,
|
||||
expectedValue.gpsProcessingMethod);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_GPS_TIMESTAMP,
|
||||
expectedValue.gpsTimestamp);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_IMAGE_LENGTH, expectedValue.imageLength);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_IMAGE_WIDTH, expectedValue.imageWidth);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_ISO, expectedValue.iso);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_ORIENTATION, expectedValue.orientation);
|
||||
compareStringTag(exifInterface, ExifInterface.TAG_WHITE_BALANCE,
|
||||
expectedValue.whiteBalance);
|
||||
}
|
||||
|
||||
private void testExifInterfaceForJpeg(String fileName, int typedArrayResourceId)
|
||||
throws IOException {
|
||||
ExpectedValue expectedValue = new ExpectedValue(
|
||||
getContext().getResources().obtainTypedArray(typedArrayResourceId));
|
||||
File imageFile = new File(Environment.getExternalStorageDirectory(), fileName);
|
||||
|
||||
// Created via path.
|
||||
ExifInterface exifInterface = new ExifInterface(imageFile.getAbsolutePath());
|
||||
if (VERBOSE) {
|
||||
printExifTagsAndValues(fileName, exifInterface);
|
||||
}
|
||||
compareWithExpectedValue(exifInterface, expectedValue);
|
||||
|
||||
// Created via InputStream.
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
in = new FileInputStream(imageFile.getAbsolutePath());
|
||||
exifInterface = new ExifInterface(in);
|
||||
if (VERBOSE) {
|
||||
printExifTagsAndValues(fileName, exifInterface);
|
||||
}
|
||||
compareWithExpectedValue(exifInterface, expectedValue);
|
||||
} finally {
|
||||
IoUtils.closeQuietly(in);
|
||||
}
|
||||
|
||||
// Created via FileDescriptor.
|
||||
try {
|
||||
FileDescriptor fd = Os.open(imageFile.getAbsolutePath(), OsConstants.O_RDONLY, 0600);
|
||||
exifInterface = new ExifInterface(fd);
|
||||
if (VERBOSE) {
|
||||
printExifTagsAndValues(fileName, exifInterface);
|
||||
}
|
||||
compareWithExpectedValue(exifInterface, expectedValue);
|
||||
} catch (ErrnoException e) {
|
||||
e.rethrowAsIOException();
|
||||
}
|
||||
|
||||
// Test for saving attributes.
|
||||
try {
|
||||
FileDescriptor fd = Os.open(imageFile.getAbsolutePath(), OsConstants.O_RDWR, 0600);
|
||||
exifInterface = new ExifInterface(fd);
|
||||
exifInterface.saveAttributes();
|
||||
exifInterface = new ExifInterface(fd);
|
||||
if (VERBOSE) {
|
||||
printExifTagsAndValues(fileName, exifInterface);
|
||||
}
|
||||
compareWithExpectedValue(exifInterface, expectedValue);
|
||||
} catch (ErrnoException e) {
|
||||
e.rethrowAsIOException();
|
||||
}
|
||||
|
||||
// Test for modifying one attribute.
|
||||
exifInterface = new ExifInterface(imageFile.getAbsolutePath());
|
||||
exifInterface.setAttribute(ExifInterface.TAG_MAKE, "abc");
|
||||
exifInterface.saveAttributes();
|
||||
exifInterface = new ExifInterface(imageFile.getAbsolutePath());
|
||||
if (VERBOSE) {
|
||||
printExifTagsAndValues(fileName, exifInterface);
|
||||
}
|
||||
assertEquals("abc", exifInterface.getAttribute(ExifInterface.TAG_MAKE));
|
||||
}
|
||||
|
||||
private void testExifInterfaceForRaw(String fileName, int typedArrayResourceId)
|
||||
throws IOException {
|
||||
ExpectedValue expectedValue = new ExpectedValue(
|
||||
getContext().getResources().obtainTypedArray(typedArrayResourceId));
|
||||
File imageFile = new File(Environment.getExternalStorageDirectory(), fileName);
|
||||
|
||||
// Created via path.
|
||||
ExifInterface exifInterface = new ExifInterface(imageFile.getAbsolutePath());
|
||||
if (VERBOSE) {
|
||||
printExifTagsAndValues(fileName, exifInterface);
|
||||
}
|
||||
compareWithExpectedValue(exifInterface, expectedValue);
|
||||
|
||||
// Created via FileDescriptor.
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
in = new FileInputStream(imageFile);
|
||||
exifInterface = new ExifInterface(in.getFD());
|
||||
if (VERBOSE) {
|
||||
printExifTagsAndValues(fileName, exifInterface);
|
||||
}
|
||||
compareWithExpectedValue(exifInterface, expectedValue);
|
||||
} finally {
|
||||
IoUtils.closeQuietly(in);
|
||||
}
|
||||
}
|
||||
|
||||
public void testReadExifDataFromExifByteOrderIIJpeg() throws Throwable {
|
||||
testExifInterfaceForJpeg(EXIF_BYTE_ORDER_II_JPEG, R.array.exifbyteorderii_jpg);
|
||||
}
|
||||
|
||||
public void testReadExifDataFromExifByteOrderMMJpeg() throws Throwable {
|
||||
testExifInterfaceForJpeg(EXIF_BYTE_ORDER_MM_JPEG, R.array.exifbyteordermm_jpg);
|
||||
}
|
||||
|
||||
public void testReadExifDataFromLgG4Iso800Dng() throws Throwable {
|
||||
testExifInterfaceForRaw(LG_G4_ISO_800_DNG, R.array.lg_g4_iso_800_dng);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user