Merge "ExifInterface: fix writing STRING and SRATIONAL formats" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f2a1076cd3
@@ -2025,6 +2025,12 @@ public class ExifInterface {
|
|||||||
int bytesWritten = 0;
|
int bytesWritten = 0;
|
||||||
int dataFormat = getDataFormatOfExifEntryValue(entryValue);
|
int dataFormat = getDataFormatOfExifEntryValue(entryValue);
|
||||||
|
|
||||||
|
if (dataFormat == IFD_FORMAT_STRING) {
|
||||||
|
byte[] asciiArray = (entryValue + '\0').getBytes(Charset.forName("US-ASCII"));
|
||||||
|
dataOutputStream.write(asciiArray);
|
||||||
|
return asciiArray.length;
|
||||||
|
}
|
||||||
|
|
||||||
// Values can be composed of several components. Each component is separated by char ','.
|
// Values can be composed of several components. Each component is separated by char ','.
|
||||||
String[] components = entryValue.split(",");
|
String[] components = entryValue.split(",");
|
||||||
for (String component : components) {
|
for (String component : components) {
|
||||||
@@ -2037,11 +2043,6 @@ public class ExifInterface {
|
|||||||
dataOutputStream.writeDouble(Double.parseDouble(component));
|
dataOutputStream.writeDouble(Double.parseDouble(component));
|
||||||
bytesWritten += 8;
|
bytesWritten += 8;
|
||||||
break;
|
break;
|
||||||
case IFD_FORMAT_STRING:
|
|
||||||
byte[] asciiArray = (component + '\0').getBytes(Charset.forName("US-ASCII"));
|
|
||||||
dataOutputStream.write(asciiArray);
|
|
||||||
bytesWritten += asciiArray.length;
|
|
||||||
break;
|
|
||||||
case IFD_FORMAT_SRATIONAL:
|
case IFD_FORMAT_SRATIONAL:
|
||||||
String[] rationalNumber = component.split("/");
|
String[] rationalNumber = component.split("/");
|
||||||
dataOutputStream.writeInt(Integer.parseInt(rationalNumber[0]));
|
dataOutputStream.writeInt(Integer.parseInt(rationalNumber[0]));
|
||||||
@@ -2060,11 +2061,31 @@ public class ExifInterface {
|
|||||||
// See TIFF 6.0 spec Types. page 15.
|
// See TIFF 6.0 spec Types. page 15.
|
||||||
// Take the first component if there are more than one component.
|
// Take the first component if there are more than one component.
|
||||||
if (entryValue.contains(",")) {
|
if (entryValue.contains(",")) {
|
||||||
entryValue = entryValue.split(",")[0];
|
String[] entryValues = entryValue.split(",");
|
||||||
|
int dataFormat = getDataFormatOfExifEntryValue(entryValues[0]);
|
||||||
|
if (dataFormat == IFD_FORMAT_STRING) {
|
||||||
|
return IFD_FORMAT_STRING;
|
||||||
|
}
|
||||||
|
for (int i = 1; i < entryValues.length; ++i) {
|
||||||
|
if (getDataFormatOfExifEntryValue(entryValues[i]) != dataFormat) {
|
||||||
|
return IFD_FORMAT_STRING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dataFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entryValue.contains("/")) {
|
if (entryValue.contains("/")) {
|
||||||
return IFD_FORMAT_SRATIONAL;
|
String[] rationalNumber = entryValue.split("/");
|
||||||
|
if (rationalNumber.length == 2) {
|
||||||
|
try {
|
||||||
|
Integer.parseInt(rationalNumber[0]);
|
||||||
|
Integer.parseInt(rationalNumber[1]);
|
||||||
|
return IFD_FORMAT_SRATIONAL;
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return IFD_FORMAT_STRING;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(entryValue);
|
Integer.parseInt(entryValue);
|
||||||
@@ -2084,6 +2105,9 @@ public class ExifInterface {
|
|||||||
// Determines the size of EXIF entry value.
|
// Determines the size of EXIF entry value.
|
||||||
private static int getSizeOfExifEntryValue(int dataFormat, String entryValue) {
|
private static int getSizeOfExifEntryValue(int dataFormat, String entryValue) {
|
||||||
// See TIFF 6.0 spec Types page 15.
|
// See TIFF 6.0 spec Types page 15.
|
||||||
|
if (dataFormat == IFD_FORMAT_STRING) {
|
||||||
|
return (entryValue + '\0').getBytes(Charset.forName("US-ASCII")).length;
|
||||||
|
}
|
||||||
int bytesEstimated = 0;
|
int bytesEstimated = 0;
|
||||||
String[] components = entryValue.split(",");
|
String[] components = entryValue.split(",");
|
||||||
for (String component : components) {
|
for (String component : components) {
|
||||||
@@ -2094,10 +2118,6 @@ public class ExifInterface {
|
|||||||
case IFD_FORMAT_DOUBLE:
|
case IFD_FORMAT_DOUBLE:
|
||||||
bytesEstimated += 8;
|
bytesEstimated += 8;
|
||||||
break;
|
break;
|
||||||
case IFD_FORMAT_STRING:
|
|
||||||
bytesEstimated
|
|
||||||
+= (component + '\0').getBytes(Charset.forName("US-ASCII")).length;
|
|
||||||
break;
|
|
||||||
case IFD_FORMAT_SRATIONAL:
|
case IFD_FORMAT_SRATIONAL:
|
||||||
bytesEstimated += 8;
|
bytesEstimated += 8;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user