first commit
This commit is contained in:
commit
4d332ef662
27586 changed files with 3281783 additions and 0 deletions
|
|
@ -0,0 +1,102 @@
|
|||
package com.drew.imaging.jpeg;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.Tag;
|
||||
import com.drew.metadata.exif.ExifDirectory;
|
||||
import com.drew.metadata.exif.ExifReader;
|
||||
import com.drew.metadata.iptc.IptcReader;
|
||||
import com.drew.metadata.jpeg.JpegCommentReader;
|
||||
import com.drew.metadata.jpeg.JpegReader;
|
||||
import com.sun.image.codec.jpeg.JPEGDecodeParam;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class JpegMetadataReader {
|
||||
public static Metadata readMetadata(InputStream paramInputStream) throws JpegProcessingException {
|
||||
JpegSegmentReader jpegSegmentReader = new JpegSegmentReader(paramInputStream);
|
||||
return extractJpegSegmentReaderMetadata(jpegSegmentReader);
|
||||
}
|
||||
|
||||
public static Metadata readMetadata(File paramFile) throws JpegProcessingException {
|
||||
JpegSegmentReader jpegSegmentReader = new JpegSegmentReader(paramFile);
|
||||
return extractJpegSegmentReaderMetadata(jpegSegmentReader);
|
||||
}
|
||||
|
||||
private static Metadata extractJpegSegmentReaderMetadata(JpegSegmentReader paramJpegSegmentReader) {
|
||||
Metadata metadata = new Metadata();
|
||||
try {
|
||||
byte[] arrayOfByte = paramJpegSegmentReader.readSegment((byte)-31);
|
||||
new ExifReader(arrayOfByte).extract(metadata);
|
||||
} catch (JpegProcessingException e) {}
|
||||
try {
|
||||
byte[] arrayOfByte = paramJpegSegmentReader.readSegment((byte)-19);
|
||||
new IptcReader(arrayOfByte).extract(metadata);
|
||||
} catch (JpegProcessingException e) {}
|
||||
try {
|
||||
byte[] arrayOfByte = paramJpegSegmentReader.readSegment((byte)-64);
|
||||
new JpegReader(arrayOfByte).extract(metadata);
|
||||
} catch (JpegProcessingException e) {}
|
||||
try {
|
||||
byte[] arrayOfByte = paramJpegSegmentReader.readSegment((byte)-2);
|
||||
new JpegCommentReader(arrayOfByte).extract(metadata);
|
||||
} catch (JpegProcessingException e) {}
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public static Metadata readMetadata(JPEGDecodeParam paramJPEGDecodeParam) {
|
||||
Metadata metadata = new Metadata();
|
||||
byte[][] arrayOfByte1 = paramJPEGDecodeParam.getMarkerData(225);
|
||||
if (arrayOfByte1 != null && (arrayOfByte1[0]).length > 0)
|
||||
new ExifReader(arrayOfByte1[0]).extract(metadata);
|
||||
byte[][] arrayOfByte2 = paramJPEGDecodeParam.getMarkerData(237);
|
||||
if (arrayOfByte2 != null && (arrayOfByte2[0]).length > 0)
|
||||
new IptcReader(arrayOfByte2[0]).extract(metadata);
|
||||
byte[][] arrayOfByte3 = paramJPEGDecodeParam.getMarkerData(254);
|
||||
if (arrayOfByte3 != null && (arrayOfByte3[0]).length > 0)
|
||||
new JpegCommentReader(arrayOfByte3[0]).extract(metadata);
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public static void main(String[] paramArrayOfString) throws MetadataException, IOException {
|
||||
JpegMetadataReader jpegMetadataReader = new JpegMetadataReader();
|
||||
Metadata metadata = null;
|
||||
try {
|
||||
metadata = readMetadata(new File(paramArrayOfString[0]));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
System.exit(1);
|
||||
}
|
||||
Iterator iterator = metadata.getDirectoryIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Directory directory = (Directory)iterator.next();
|
||||
Iterator iterator1 = directory.getTagIterator();
|
||||
while (iterator1.hasNext()) {
|
||||
Tag tag = (Tag)iterator1.next();
|
||||
try {
|
||||
System.out.println("[" + directory.getName() + "] " + tag.getTagName() + " = " + tag.getDescription());
|
||||
} catch (MetadataException e) {
|
||||
System.err.println(e.getMessage());
|
||||
System.err.println(tag.getDirectoryName() + " " + tag.getTagName() + " (error)");
|
||||
}
|
||||
}
|
||||
if (directory.hasErrors()) {
|
||||
Iterator iterator2 = directory.getErrors();
|
||||
while (iterator2.hasNext())
|
||||
System.out.println("ERROR: " + iterator2.next());
|
||||
}
|
||||
}
|
||||
if (paramArrayOfString.length > 1 && paramArrayOfString[1].trim().equals("/thumb")) {
|
||||
ExifDirectory exifDirectory = (ExifDirectory)metadata.getDirectory(ExifDirectory.class);
|
||||
if (exifDirectory.containsThumbnail()) {
|
||||
System.out.println("Writing thumbnail...");
|
||||
exifDirectory.writeThumbnail(paramArrayOfString[0].trim() + ".thumb.jpg");
|
||||
} else {
|
||||
System.out.println("No thumbnail data exists in this image");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.drew.imaging.jpeg;
|
||||
|
||||
import com.drew.lang.CompoundException;
|
||||
|
||||
public class JpegProcessingException extends CompoundException {
|
||||
public JpegProcessingException(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public JpegProcessingException(String paramString, Throwable paramThrowable) {
|
||||
super(paramString, paramThrowable);
|
||||
}
|
||||
|
||||
public JpegProcessingException(Throwable paramThrowable) {
|
||||
super(paramThrowable);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
package com.drew.imaging.jpeg;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class JpegSegmentReader {
|
||||
private final File _file;
|
||||
|
||||
private final byte[] _data;
|
||||
|
||||
private InputStream _stream;
|
||||
|
||||
private HashMap _segmentDataMap;
|
||||
|
||||
private static final byte SEGMENT_SOS = -38;
|
||||
|
||||
private static final byte MARKER_EOI = -39;
|
||||
|
||||
public static final byte SEGMENT_APP0 = -32;
|
||||
|
||||
public static final byte SEGMENT_APP1 = -31;
|
||||
|
||||
public static final byte SEGMENT_APP2 = -30;
|
||||
|
||||
public static final byte SEGMENT_APP3 = -29;
|
||||
|
||||
public static final byte SEGMENT_APP4 = -28;
|
||||
|
||||
public static final byte SEGMENT_APP5 = -27;
|
||||
|
||||
public static final byte SEGMENT_APP6 = -26;
|
||||
|
||||
public static final byte SEGMENT_APP7 = -25;
|
||||
|
||||
public static final byte SEGMENT_APP8 = -24;
|
||||
|
||||
public static final byte SEGMENT_APP9 = -23;
|
||||
|
||||
public static final byte SEGMENT_APPA = -22;
|
||||
|
||||
public static final byte SEGMENT_APPB = -21;
|
||||
|
||||
public static final byte SEGMENT_APPC = -20;
|
||||
|
||||
public static final byte SEGMENT_APPD = -19;
|
||||
|
||||
public static final byte SEGMENT_APPE = -18;
|
||||
|
||||
public static final byte SEGMENT_APPF = -17;
|
||||
|
||||
public static final byte SEGMENT_SOI = -40;
|
||||
|
||||
public static final byte SEGMENT_DQT = -37;
|
||||
|
||||
public static final byte SEGMENT_DHT = -60;
|
||||
|
||||
public static final byte SEGMENT_SOF0 = -64;
|
||||
|
||||
public static final byte SEGMENT_COM = -2;
|
||||
|
||||
public JpegSegmentReader(File paramFile) throws JpegProcessingException {
|
||||
this._file = paramFile;
|
||||
this._data = null;
|
||||
readSegments();
|
||||
}
|
||||
|
||||
public JpegSegmentReader(byte[] paramArrayOfbyte) throws JpegProcessingException {
|
||||
this._file = null;
|
||||
this._data = paramArrayOfbyte;
|
||||
readSegments();
|
||||
}
|
||||
|
||||
public JpegSegmentReader(InputStream paramInputStream) throws JpegProcessingException {
|
||||
this._stream = paramInputStream;
|
||||
this._file = null;
|
||||
this._data = null;
|
||||
readSegments();
|
||||
}
|
||||
|
||||
public byte[] readSegment(byte paramByte) throws JpegProcessingException {
|
||||
return readSegment(paramByte, 0);
|
||||
}
|
||||
|
||||
public byte[] readSegment(byte paramByte, int paramInt) {
|
||||
Byte byte_ = new Byte(paramByte);
|
||||
if (this._segmentDataMap.containsKey(byte_)) {
|
||||
List list = (List)this._segmentDataMap.get(byte_);
|
||||
return (list.size() <= paramInt) ? null : (byte[])list.get(paramInt);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public final int getSegmentCount(byte paramByte) {
|
||||
List list = (List)this._segmentDataMap.get(new Byte(paramByte));
|
||||
return (list == null) ? 0 : list.size();
|
||||
}
|
||||
|
||||
private void readSegments() throws JpegProcessingException {
|
||||
this._segmentDataMap = new HashMap();
|
||||
BufferedInputStream bufferedInputStream = getJpegInputStream();
|
||||
try {
|
||||
int i = 0;
|
||||
if (!isValidJpegHeaderBytes(bufferedInputStream))
|
||||
throw new JpegProcessingException("not a jpeg file");
|
||||
i += true;
|
||||
while (true) {
|
||||
List list;
|
||||
byte b1 = (byte)(bufferedInputStream.read() & 0xFF);
|
||||
if ((b1 & 0xFF) != 255)
|
||||
throw new JpegProcessingException("expected jpeg segment start identifier 0xFF at offset " + i + ", not 0x" + Integer.toHexString(b1 & 0xFF));
|
||||
i++;
|
||||
byte b2 = (byte)(bufferedInputStream.read() & 0xFF);
|
||||
i++;
|
||||
byte[] arrayOfByte1 = new byte[2];
|
||||
bufferedInputStream.read(arrayOfByte1, 0, 2);
|
||||
i += 2;
|
||||
int j = arrayOfByte1[0] << 8 & 0xFF00 | arrayOfByte1[1] & 0xFF;
|
||||
j -= 2;
|
||||
if (j > bufferedInputStream.available())
|
||||
throw new JpegProcessingException("segment size would extend beyond file stream length");
|
||||
byte[] arrayOfByte2 = new byte[j];
|
||||
bufferedInputStream.read(arrayOfByte2, 0, j);
|
||||
i += j;
|
||||
if ((b2 & 0xFF) == 218)
|
||||
return;
|
||||
if ((b2 & 0xFF) == 217)
|
||||
return;
|
||||
Byte byte_ = new Byte(b2);
|
||||
if (this._segmentDataMap.containsKey(byte_)) {
|
||||
list = (List)this._segmentDataMap.get(byte_);
|
||||
} else {
|
||||
list = new ArrayList();
|
||||
this._segmentDataMap.put(byte_, list);
|
||||
}
|
||||
list.add(arrayOfByte2);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JpegProcessingException("IOException processing Jpeg file: " + e.getMessage(), e);
|
||||
} finally {
|
||||
try {
|
||||
if (bufferedInputStream != null)
|
||||
bufferedInputStream.close();
|
||||
} catch (IOException e) {
|
||||
throw new JpegProcessingException("IOException processing Jpeg file: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedInputStream getJpegInputStream() throws JpegProcessingException {
|
||||
ByteArrayInputStream byteArrayInputStream;
|
||||
if (this._stream != null)
|
||||
return (this._stream instanceof BufferedInputStream) ? (BufferedInputStream)this._stream : new BufferedInputStream(this._stream);
|
||||
if (this._data == null) {
|
||||
try {
|
||||
FileInputStream fileInputStream = new FileInputStream(this._file);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new JpegProcessingException("Jpeg file does not exist", e);
|
||||
}
|
||||
} else {
|
||||
byteArrayInputStream = new ByteArrayInputStream(this._data);
|
||||
}
|
||||
return new BufferedInputStream(byteArrayInputStream);
|
||||
}
|
||||
|
||||
private boolean isValidJpegHeaderBytes(InputStream paramInputStream) throws IOException {
|
||||
byte[] arrayOfByte = new byte[2];
|
||||
paramInputStream.read(arrayOfByte, 0, 2);
|
||||
return ((arrayOfByte[0] & 0xFF) == 255 && (arrayOfByte[1] & 0xFF) == 216);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.drew.imaging.jpeg.test;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegMetadataReader;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.exif.ExifDirectory;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class JpegMetadataReaderTest extends TestCase {
|
||||
public JpegMetadataReaderTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testExtractMetadata() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/exif/test/withExif.jpg");
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(file);
|
||||
assertTrue(metadata.containsDirectory(ExifDirectory.class));
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
assertEquals("80", directory.getString(34855));
|
||||
}
|
||||
|
||||
public void testExtractMetadataUsingInputStream() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/exif/test/withExif.jpg");
|
||||
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(bufferedInputStream);
|
||||
assertTrue(metadata.containsDirectory(ExifDirectory.class));
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
assertEquals("80", directory.getString(34855));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
package com.drew.imaging.jpeg.test;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegProcessingException;
|
||||
import com.drew.imaging.jpeg.JpegSegmentReader;
|
||||
import com.drew.metadata.exif.ExifReader;
|
||||
import com.drew.metadata.iptc.IptcReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class JpegSegmentReaderTest extends TestCase {
|
||||
public JpegSegmentReaderTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testIsJpegWithJpegFile() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/exif/test/withExif.jpg");
|
||||
try {
|
||||
new JpegSegmentReader(file);
|
||||
} catch (JpegProcessingException e) {
|
||||
fail("Error creating JpegSegmentReader");
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsJpegWithNonJpegFile() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/test/AllTests.java");
|
||||
try {
|
||||
new JpegSegmentReader(file);
|
||||
fail("shouldn't be able to construct JpegSegmentReader with non-jpeg file");
|
||||
} catch (JpegProcessingException e) {}
|
||||
}
|
||||
|
||||
public void testReadApp1Segment() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/exif/test/withExif.jpg");
|
||||
JpegSegmentReader jpegSegmentReader = new JpegSegmentReader(file);
|
||||
byte[] arrayOfByte = jpegSegmentReader.readSegment((byte)-31);
|
||||
assertTrue("exif data too short", (arrayOfByte.length > 4));
|
||||
assertEquals("Exif", new String(arrayOfByte, 0, 4));
|
||||
}
|
||||
|
||||
public void testReadDQTSegment() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/exif/test/withExif.jpg");
|
||||
JpegSegmentReader jpegSegmentReader = new JpegSegmentReader(file);
|
||||
byte[] arrayOfByte = jpegSegmentReader.readSegment((byte)-37);
|
||||
assertTrue("shouldn't have zero length quantizationTableData", (arrayOfByte.length > 0));
|
||||
assertTrue("quantizationTableData shouldn't start with 'Exif'", !"Exif".equals(new String(arrayOfByte, 0, 4)));
|
||||
}
|
||||
|
||||
public void testReadJpegByteArray() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/exif/test/withExif.jpg");
|
||||
byte[] arrayOfByte = new byte[(int)file.length()];
|
||||
new FileInputStream(file).read(arrayOfByte);
|
||||
new JpegSegmentReader(arrayOfByte).readSegment((byte)-31);
|
||||
}
|
||||
|
||||
public void testCreateWithInputStream() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/exif/test/withExif.jpg");
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
JpegSegmentReader jpegSegmentReader = null;
|
||||
try {
|
||||
jpegSegmentReader = new JpegSegmentReader(fileInputStream);
|
||||
} catch (JpegProcessingException e) {
|
||||
fail("Error constructing JpegSegmentReader using InputStream");
|
||||
}
|
||||
byte[] arrayOfByte = jpegSegmentReader.readSegment((byte)-31);
|
||||
assertEquals("Exif", new String(arrayOfByte, 0, 4));
|
||||
}
|
||||
|
||||
public void testReadSecondSegmentInstanace() throws Exception {
|
||||
File file = new File("src/com/drew/imaging/jpeg/test/withExifAndIptc.jpg");
|
||||
JpegSegmentReader jpegSegmentReader = new JpegSegmentReader(file);
|
||||
byte[] arrayOfByte1 = jpegSegmentReader.readSegment((byte)-31, 0);
|
||||
byte[] arrayOfByte2 = jpegSegmentReader.readSegment((byte)-31, 1);
|
||||
assertEquals("Exif", new String(arrayOfByte1, 0, 4));
|
||||
assertEquals("http", new String(arrayOfByte2, 0, 4));
|
||||
}
|
||||
|
||||
public void testReadNonExistantSegmentInstance() throws Exception {
|
||||
File file = new File("src/com/drew/imaging/jpeg/test/withExifAndIptc.jpg");
|
||||
JpegSegmentReader jpegSegmentReader = new JpegSegmentReader(file);
|
||||
assertNull("third exif segment shouldn't exist", jpegSegmentReader.readSegment((byte)-31, 3));
|
||||
}
|
||||
|
||||
public void testGetSegmentCount() throws Exception {
|
||||
File file = new File("src/com/drew/imaging/jpeg/test/withExifAndIptc.jpg");
|
||||
JpegSegmentReader jpegSegmentReader = new JpegSegmentReader(file);
|
||||
assertEquals(2, jpegSegmentReader.getSegmentCount((byte)-31));
|
||||
assertEquals(1, jpegSegmentReader.getSegmentCount((byte)-30));
|
||||
assertEquals(0, jpegSegmentReader.getSegmentCount((byte)-29));
|
||||
}
|
||||
|
||||
public void testCreateWithFileAndReadMultipleSegments() throws Exception {
|
||||
File file = new File("src/com/drew/imaging/jpeg/test/withExifAndIptc.jpg");
|
||||
JpegSegmentReader jpegSegmentReader = new JpegSegmentReader(file);
|
||||
validateMultipleSegmentRead(jpegSegmentReader);
|
||||
}
|
||||
|
||||
public void testCreateWithInputStreamAndReadMultipleSegments() throws Exception {
|
||||
File file = new File("src/com/drew/imaging/jpeg/test/withExifAndIptc.jpg");
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
JpegSegmentReader jpegSegmentReader = new JpegSegmentReader(fileInputStream);
|
||||
validateMultipleSegmentRead(jpegSegmentReader);
|
||||
}
|
||||
|
||||
private void validateMultipleSegmentRead(JpegSegmentReader paramJpegSegmentReader) throws JpegProcessingException {
|
||||
byte[] arrayOfByte1 = paramJpegSegmentReader.readSegment((byte)-19);
|
||||
byte[] arrayOfByte2 = paramJpegSegmentReader.readSegment((byte)-31);
|
||||
assertTrue("exif data too short", (arrayOfByte2.length > 4));
|
||||
new ExifReader(arrayOfByte2).extract();
|
||||
new IptcReader(arrayOfByte1).extract();
|
||||
assertEquals("Exif", new String(arrayOfByte2, 0, 4));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package com.drew.lang;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class CompoundException extends Exception {
|
||||
private final Throwable _innnerException;
|
||||
|
||||
public CompoundException(String paramString) {
|
||||
this(paramString, null);
|
||||
}
|
||||
|
||||
public CompoundException(Throwable paramThrowable) {
|
||||
this(null, paramThrowable);
|
||||
}
|
||||
|
||||
public CompoundException(String paramString, Throwable paramThrowable) {
|
||||
super(paramString);
|
||||
this._innnerException = paramThrowable;
|
||||
}
|
||||
|
||||
public Throwable getInnerException() {
|
||||
return this._innnerException;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(super.toString());
|
||||
if (this._innnerException != null) {
|
||||
stringBuffer.append("\n");
|
||||
stringBuffer.append("--- inner exception ---");
|
||||
stringBuffer.append("\n");
|
||||
stringBuffer.append(this._innnerException.toString());
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
public void printStackTrace(PrintStream paramPrintStream) {
|
||||
super.printStackTrace(paramPrintStream);
|
||||
if (this._innnerException != null) {
|
||||
paramPrintStream.println("--- inner exception ---");
|
||||
this._innnerException.printStackTrace(paramPrintStream);
|
||||
}
|
||||
}
|
||||
|
||||
public void printStackTrace(PrintWriter paramPrintWriter) {
|
||||
super.printStackTrace(paramPrintWriter);
|
||||
if (this._innnerException != null) {
|
||||
paramPrintWriter.println("--- inner exception ---");
|
||||
this._innnerException.printStackTrace(paramPrintWriter);
|
||||
}
|
||||
}
|
||||
|
||||
public void printStackTrace() {
|
||||
super.printStackTrace();
|
||||
if (this._innnerException != null) {
|
||||
System.err.println("--- inner exception ---");
|
||||
this._innnerException.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.drew.lang;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class NullOutputStream extends OutputStream {
|
||||
public void write(int paramInt) throws IOException {}
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package com.drew.lang;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Rational extends Number implements Serializable {
|
||||
private final int numerator;
|
||||
|
||||
private final int denominator;
|
||||
|
||||
private int maxSimplificationCalculations = 1000;
|
||||
|
||||
public Rational(int paramInt1, int paramInt2) {
|
||||
this.numerator = paramInt1;
|
||||
this.denominator = paramInt2;
|
||||
}
|
||||
|
||||
public double doubleValue() {
|
||||
return (double)this.numerator / (double)this.denominator;
|
||||
}
|
||||
|
||||
public float floatValue() {
|
||||
return (float)this.numerator / (float)this.denominator;
|
||||
}
|
||||
|
||||
public final byte byteValue() {
|
||||
return (byte)(int)doubleValue();
|
||||
}
|
||||
|
||||
public final int intValue() {
|
||||
return (int)doubleValue();
|
||||
}
|
||||
|
||||
public final long longValue() {
|
||||
return (long)doubleValue();
|
||||
}
|
||||
|
||||
public final short shortValue() {
|
||||
return (short)(int)doubleValue();
|
||||
}
|
||||
|
||||
public final int getDenominator() {
|
||||
return this.denominator;
|
||||
}
|
||||
|
||||
public final int getNumerator() {
|
||||
return this.numerator;
|
||||
}
|
||||
|
||||
public Rational getReciprocal() {
|
||||
return new Rational(this.denominator, this.numerator);
|
||||
}
|
||||
|
||||
public boolean isInteger() {
|
||||
return (this.denominator == 1 || (this.denominator != 0 && this.numerator % this.denominator == 0) || (this.denominator == 0 && this.numerator == 0));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.numerator + "/" + this.denominator;
|
||||
}
|
||||
|
||||
public String toSimpleString(boolean paramBoolean) {
|
||||
if (this.denominator == 0 && this.numerator != 0)
|
||||
return toString();
|
||||
if (isInteger())
|
||||
return Integer.toString(intValue());
|
||||
if (this.numerator != 1 && this.denominator % this.numerator == 0) {
|
||||
int i = this.denominator / this.numerator;
|
||||
return new Rational(1, i).toSimpleString(paramBoolean);
|
||||
}
|
||||
Rational rational = getSimplifiedInstance();
|
||||
if (paramBoolean) {
|
||||
String str = Double.toString(rational.doubleValue());
|
||||
if (str.length() < 5)
|
||||
return str;
|
||||
}
|
||||
return rational.toString();
|
||||
}
|
||||
|
||||
private boolean tooComplexForSimplification() {
|
||||
double d = (double)(Math.min(this.denominator, this.numerator) - 1) / 5.0D + 2.0D;
|
||||
return (d > (double)this.maxSimplificationCalculations);
|
||||
}
|
||||
|
||||
public boolean equals(Object paramObject) {
|
||||
if (!(paramObject instanceof Rational))
|
||||
return false;
|
||||
Rational rational = (Rational)paramObject;
|
||||
return (doubleValue() == rational.doubleValue());
|
||||
}
|
||||
|
||||
public Rational getSimplifiedInstance() {
|
||||
if (tooComplexForSimplification())
|
||||
return this;
|
||||
for (int i = 2; i <= Math.min(this.denominator, this.numerator); i++) {
|
||||
if ((i % 2 != 0 || i <= 2) && (i % 5 != 0 || i <= 5) && this.denominator % i == 0 && this.numerator % i == 0)
|
||||
return new Rational(this.numerator / i, this.denominator / i);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.drew.lang.test;
|
||||
|
||||
import com.drew.lang.CompoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class CompoundExceptionTest extends TestCase {
|
||||
public CompoundExceptionTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testUnnestedGetMessage() throws Exception {
|
||||
try {
|
||||
throw new CompoundException("message");
|
||||
} catch (CompoundException e) {
|
||||
assertEquals("message", e.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void testNestedGetMessage() throws Exception {
|
||||
try {
|
||||
try {
|
||||
throw new IOException("io");
|
||||
} catch (IOException e) {
|
||||
throw new CompoundException("compound", e);
|
||||
}
|
||||
} catch (CompoundException e) {
|
||||
assertEquals("compound", e.getMessage());
|
||||
assertEquals("io", e.getInnerException().getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void testNoInnerException() throws Exception {
|
||||
try {
|
||||
throw new CompoundException("message", null);
|
||||
} catch (CompoundException e) {
|
||||
try {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace(System.err);
|
||||
e.printStackTrace(new PrintWriter(System.err));
|
||||
} catch (Exception exception) {
|
||||
fail("Exception during printStackTrace for CompoundException with no inner exception");
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.drew.lang.test;
|
||||
|
||||
import com.drew.lang.NullOutputStream;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class NullOutputStreamTest extends TestCase {
|
||||
public NullOutputStreamTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testCreateNullOutputStream() throws Exception {
|
||||
NullOutputStream nullOutputStream = new NullOutputStream();
|
||||
nullOutputStream.write(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.drew.lang.test;
|
||||
|
||||
import com.drew.lang.Rational;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class RationalTest extends TestCase {
|
||||
public RationalTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testCreateRational() throws Exception {
|
||||
Rational rational = new Rational(1, 3);
|
||||
assertEquals(1, rational.getNumerator());
|
||||
assertEquals(3, rational.getDenominator());
|
||||
assertEquals(new Double(0.3333333333333333D), new Double(rational.doubleValue()));
|
||||
}
|
||||
|
||||
public void testToString() throws Exception {
|
||||
Rational rational = new Rational(1, 3);
|
||||
assertEquals("1/3", rational.toString());
|
||||
}
|
||||
|
||||
public void testToSimpleString() throws Exception {
|
||||
Rational rational1 = new Rational(1, 3);
|
||||
Rational rational2 = new Rational(2, 6);
|
||||
assertEquals("1/3", rational1.toSimpleString(true));
|
||||
assertEquals("1/3", rational2.toSimpleString(true));
|
||||
assertEquals(rational1, rational2);
|
||||
Rational rational3 = new Rational(10, 15);
|
||||
assertEquals("2/3", rational3.toSimpleString(true));
|
||||
Rational rational4 = new Rational(10, 5);
|
||||
assertTrue(rational4.isInteger());
|
||||
assertEquals("2", rational4.toSimpleString(true));
|
||||
assertEquals("2", rational4.toSimpleString(false));
|
||||
Rational rational5 = new Rational(4, 10);
|
||||
assertEquals("0.4", rational5.toSimpleString(true));
|
||||
assertEquals("2/5", rational5.toSimpleString(false));
|
||||
Rational rational6 = new Rational(3, 8);
|
||||
assertEquals("3/8", rational6.toSimpleString(true));
|
||||
Rational rational7 = new Rational(0, 8);
|
||||
assertTrue(rational7.isInteger());
|
||||
assertEquals("0", rational7.toSimpleString(true));
|
||||
assertEquals("0", rational7.toSimpleString(false));
|
||||
rational7 = new Rational(0, 0);
|
||||
assertTrue(rational7.isInteger());
|
||||
assertEquals("0", rational7.toSimpleString(true));
|
||||
assertEquals("0", rational7.toSimpleString(false));
|
||||
}
|
||||
|
||||
public void testGetReciprocal() throws Exception {
|
||||
Rational rational1 = new Rational(1, 3);
|
||||
Rational rational2 = rational1.getReciprocal();
|
||||
assertEquals("new rational should be reciprocal", new Rational(3, 1), rational2);
|
||||
assertEquals("origianl reciprocal should remain unchanged", new Rational(1, 3), rational1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.drew.metadata;
|
||||
|
||||
public class DefaultTagDescriptor extends TagDescriptor {
|
||||
public DefaultTagDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getTagName(int paramInt) {
|
||||
String str;
|
||||
for (str = Integer.toHexString(paramInt).toUpperCase(); str.length() < 4; str = "0" + str);
|
||||
return "Unknown tag 0x" + str;
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) {
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,383 @@
|
|||
package com.drew.metadata;
|
||||
|
||||
import com.drew.lang.Rational;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Array;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Directory implements Serializable {
|
||||
protected final HashMap _tagMap = new HashMap();
|
||||
|
||||
protected TagDescriptor _descriptor;
|
||||
|
||||
protected final List _definedTagList = new ArrayList();
|
||||
|
||||
private List _errorList;
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
protected abstract HashMap getTagNameMap();
|
||||
|
||||
public boolean containsTag(int paramInt) {
|
||||
return this._tagMap.containsKey(new Integer(paramInt));
|
||||
}
|
||||
|
||||
public Iterator getTagIterator() {
|
||||
return this._definedTagList.iterator();
|
||||
}
|
||||
|
||||
public int getTagCount() {
|
||||
return this._definedTagList.size();
|
||||
}
|
||||
|
||||
public void setDescriptor(TagDescriptor paramTagDescriptor) {
|
||||
if (paramTagDescriptor == null)
|
||||
throw new NullPointerException("cannot set a null descriptor");
|
||||
this._descriptor = paramTagDescriptor;
|
||||
}
|
||||
|
||||
public void addError(String paramString) {
|
||||
if (this._errorList == null)
|
||||
this._errorList = new ArrayList();
|
||||
this._errorList.add(paramString);
|
||||
}
|
||||
|
||||
public boolean hasErrors() {
|
||||
return (this._errorList != null && this._errorList.size() > 0);
|
||||
}
|
||||
|
||||
public Iterator getErrors() {
|
||||
return this._errorList.iterator();
|
||||
}
|
||||
|
||||
public int getErrorCount() {
|
||||
return this._errorList.size();
|
||||
}
|
||||
|
||||
public void setInt(int paramInt1, int paramInt2) {
|
||||
setObject(paramInt1, new Integer(paramInt2));
|
||||
}
|
||||
|
||||
public void setDouble(int paramInt, double paramDouble) {
|
||||
setObject(paramInt, new Double(paramDouble));
|
||||
}
|
||||
|
||||
public void setFloat(int paramInt, float paramFloat) {
|
||||
setObject(paramInt, new Float(paramFloat));
|
||||
}
|
||||
|
||||
public void setString(int paramInt, String paramString) {
|
||||
setObject(paramInt, paramString);
|
||||
}
|
||||
|
||||
public void setBoolean(int paramInt, boolean paramBoolean) {
|
||||
setObject(paramInt, new Boolean(paramBoolean));
|
||||
}
|
||||
|
||||
public void setLong(int paramInt, long paramLong) {
|
||||
setObject(paramInt, new Long(paramLong));
|
||||
}
|
||||
|
||||
public void setDate(int paramInt, Date paramDate) {
|
||||
setObject(paramInt, paramDate);
|
||||
}
|
||||
|
||||
public void setRational(int paramInt, Rational paramRational) {
|
||||
setObject(paramInt, paramRational);
|
||||
}
|
||||
|
||||
public void setRationalArray(int paramInt, Rational[] paramArrayOfRational) {
|
||||
setObjectArray(paramInt, paramArrayOfRational);
|
||||
}
|
||||
|
||||
public void setIntArray(int paramInt, int[] paramArrayOfint) {
|
||||
setObjectArray(paramInt, paramArrayOfint);
|
||||
}
|
||||
|
||||
public void setByteArray(int paramInt, byte[] paramArrayOfbyte) {
|
||||
setObjectArray(paramInt, paramArrayOfbyte);
|
||||
}
|
||||
|
||||
public void setStringArray(int paramInt, String[] paramArrayOfString) {
|
||||
setObjectArray(paramInt, paramArrayOfString);
|
||||
}
|
||||
|
||||
public void setObject(int paramInt, Object paramObject) {
|
||||
if (paramObject == null)
|
||||
throw new NullPointerException("cannot set a null object");
|
||||
Integer integer = new Integer(paramInt);
|
||||
if (!this._tagMap.containsKey(integer))
|
||||
this._definedTagList.add(new Tag(paramInt, this));
|
||||
this._tagMap.put(integer, paramObject);
|
||||
}
|
||||
|
||||
public void setObjectArray(int paramInt, Object paramObject) {
|
||||
setObject(paramInt, paramObject);
|
||||
}
|
||||
|
||||
public int getInt(int paramInt) throws MetadataException {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
throw new MetadataException("Tag " + getTagName(paramInt) + " has not been set -- check using containsTag() first");
|
||||
if (object instanceof String)
|
||||
try {
|
||||
return Integer.parseInt((String)object);
|
||||
} catch (NumberFormatException e) {
|
||||
String str = (String)object;
|
||||
int i = 0;
|
||||
for (int j = str.length() - 1; j >= 0; j--)
|
||||
i += str.charAt(j) << j * 8;
|
||||
return i;
|
||||
}
|
||||
if (object instanceof Number)
|
||||
return ((Number)object).intValue();
|
||||
throw new MetadataException("Requested tag cannot be cast to int");
|
||||
}
|
||||
|
||||
public String[] getStringArray(int paramInt) throws MetadataException {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
throw new MetadataException("Tag " + getTagName(paramInt) + " has not been set -- check using containsTag() first");
|
||||
if (object instanceof String[])
|
||||
return (String[])object;
|
||||
if (object instanceof String)
|
||||
return new String[] { (String)object };
|
||||
if (object instanceof int[]) {
|
||||
int[] arrayOfInt = (int[])object;
|
||||
String[] arrayOfString = new String[arrayOfInt.length];
|
||||
for (int i = 0; i < arrayOfString.length; i++)
|
||||
arrayOfString[i] = Integer.toString(arrayOfInt[i]);
|
||||
return arrayOfString;
|
||||
}
|
||||
if (object instanceof byte[]) {
|
||||
byte[] arrayOfByte = (byte[])object;
|
||||
String[] arrayOfString = new String[arrayOfByte.length];
|
||||
for (int i = 0; i < arrayOfString.length; i++)
|
||||
arrayOfString[i] = Byte.toString(arrayOfByte[i]);
|
||||
return arrayOfString;
|
||||
}
|
||||
if (object instanceof Rational[]) {
|
||||
Rational[] arrayOfRational = (Rational[])object;
|
||||
String[] arrayOfString = new String[arrayOfRational.length];
|
||||
for (int i = 0; i < arrayOfString.length; i++)
|
||||
arrayOfString[i] = arrayOfRational[i].toSimpleString(false);
|
||||
return arrayOfString;
|
||||
}
|
||||
throw new MetadataException("Requested tag cannot be cast to String array (" + object.getClass().toString() + ")");
|
||||
}
|
||||
|
||||
public int[] getIntArray(int paramInt) throws MetadataException {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
throw new MetadataException("Tag " + getTagName(paramInt) + " has not been set -- check using containsTag() first");
|
||||
if (object instanceof Rational[]) {
|
||||
Rational[] arrayOfRational = (Rational[])object;
|
||||
int[] arrayOfInt = new int[arrayOfRational.length];
|
||||
for (int i = 0; i < arrayOfInt.length; i++)
|
||||
arrayOfInt[i] = arrayOfRational[i].intValue();
|
||||
return arrayOfInt;
|
||||
}
|
||||
if (object instanceof int[])
|
||||
return (int[])object;
|
||||
if (object instanceof byte[]) {
|
||||
byte[] arrayOfByte = (byte[])object;
|
||||
int[] arrayOfInt = new int[arrayOfByte.length];
|
||||
for (int i = 0; i < arrayOfByte.length; i++) {
|
||||
byte b = arrayOfByte[i];
|
||||
arrayOfInt[i] = b;
|
||||
}
|
||||
return arrayOfInt;
|
||||
}
|
||||
if (object instanceof String) {
|
||||
String str = (String)object;
|
||||
int[] arrayOfInt = new int[str.length()];
|
||||
for (int i = 0; i < str.length(); i++)
|
||||
arrayOfInt[i] = str.charAt(i);
|
||||
return arrayOfInt;
|
||||
}
|
||||
throw new MetadataException("Requested tag cannot be cast to int array (" + object.getClass().toString() + ")");
|
||||
}
|
||||
|
||||
public byte[] getByteArray(int paramInt) throws MetadataException {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
throw new MetadataException("Tag " + getTagName(paramInt) + " has not been set -- check using containsTag() first");
|
||||
if (object instanceof Rational[]) {
|
||||
Rational[] arrayOfRational = (Rational[])object;
|
||||
byte[] arrayOfByte = new byte[arrayOfRational.length];
|
||||
for (int i = 0; i < arrayOfByte.length; i++)
|
||||
arrayOfByte[i] = arrayOfRational[i].byteValue();
|
||||
return arrayOfByte;
|
||||
}
|
||||
if (object instanceof byte[])
|
||||
return (byte[])object;
|
||||
if (object instanceof int[]) {
|
||||
int[] arrayOfInt = (int[])object;
|
||||
byte[] arrayOfByte = new byte[arrayOfInt.length];
|
||||
for (int i = 0; i < arrayOfInt.length; i++)
|
||||
arrayOfByte[i] = (byte)arrayOfInt[i];
|
||||
return arrayOfByte;
|
||||
}
|
||||
if (object instanceof String) {
|
||||
String str = (String)object;
|
||||
byte[] arrayOfByte = new byte[str.length()];
|
||||
for (int i = 0; i < str.length(); i++)
|
||||
arrayOfByte[i] = (byte)str.charAt(i);
|
||||
return arrayOfByte;
|
||||
}
|
||||
throw new MetadataException("Requested tag cannot be cast to byte array (" + object.getClass().toString() + ")");
|
||||
}
|
||||
|
||||
public double getDouble(int paramInt) throws MetadataException {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
throw new MetadataException("Tag " + getTagName(paramInt) + " has not been set -- check using containsTag() first");
|
||||
if (object instanceof String)
|
||||
try {
|
||||
return Double.parseDouble((String)object);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new MetadataException("unable to parse string " + object + " as a double", e);
|
||||
}
|
||||
if (object instanceof Number)
|
||||
return ((Number)object).doubleValue();
|
||||
throw new MetadataException("Requested tag cannot be cast to double");
|
||||
}
|
||||
|
||||
public float getFloat(int paramInt) throws MetadataException {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
throw new MetadataException("Tag " + getTagName(paramInt) + " has not been set -- check using containsTag() first");
|
||||
if (object instanceof String)
|
||||
try {
|
||||
return Float.parseFloat((String)object);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new MetadataException("unable to parse string " + object + " as a float", e);
|
||||
}
|
||||
if (object instanceof Number)
|
||||
return ((Number)object).floatValue();
|
||||
throw new MetadataException("Requested tag cannot be cast to float");
|
||||
}
|
||||
|
||||
public long getLong(int paramInt) throws MetadataException {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
throw new MetadataException("Tag " + getTagName(paramInt) + " has not been set -- check using containsTag() first");
|
||||
if (object instanceof String)
|
||||
try {
|
||||
return Long.parseLong((String)object);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new MetadataException("unable to parse string " + object + " as a long", e);
|
||||
}
|
||||
if (object instanceof Number)
|
||||
return ((Number)object).longValue();
|
||||
throw new MetadataException("Requested tag cannot be cast to long");
|
||||
}
|
||||
|
||||
public boolean getBoolean(int paramInt) throws MetadataException {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
throw new MetadataException("Tag " + getTagName(paramInt) + " has not been set -- check using containsTag() first");
|
||||
if (object instanceof Boolean)
|
||||
return ((Boolean)object).booleanValue();
|
||||
if (object instanceof String)
|
||||
try {
|
||||
return Boolean.getBoolean((String)object);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new MetadataException("unable to parse string " + object + " as a boolean", e);
|
||||
}
|
||||
if (object instanceof Number)
|
||||
return (((Number)object).doubleValue() != 0.0D);
|
||||
throw new MetadataException("Requested tag cannot be cast to boolean");
|
||||
}
|
||||
|
||||
public Date getDate(int paramInt) throws MetadataException {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
throw new MetadataException("Tag " + getTagName(paramInt) + " has not been set -- check using containsTag() first");
|
||||
if (object instanceof Date)
|
||||
return (Date)object;
|
||||
if (object instanceof String) {
|
||||
String[] arrayOfString = { "yyyy:MM:dd HH:mm:ss", "yyyy:MM:dd HH:mm", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm" };
|
||||
String str = (String)object;
|
||||
int i = 0;
|
||||
while (i < arrayOfString.length) {
|
||||
try {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(arrayOfString[i]);
|
||||
return simpleDateFormat.parse(str);
|
||||
} catch (ParseException e) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new MetadataException("Requested tag cannot be cast to java.util.Date");
|
||||
}
|
||||
|
||||
public Rational getRational(int paramInt) throws MetadataException {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
throw new MetadataException("Tag " + getTagName(paramInt) + " has not been set -- check using containsTag() first");
|
||||
if (object instanceof Rational)
|
||||
return (Rational)object;
|
||||
throw new MetadataException("Requested tag cannot be cast to Rational");
|
||||
}
|
||||
|
||||
public Rational[] getRationalArray(int paramInt) throws MetadataException {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
throw new MetadataException("Tag " + getTagName(paramInt) + " has not been set -- check using containsTag() first");
|
||||
if (object instanceof Rational[])
|
||||
return (Rational[])object;
|
||||
throw new MetadataException("Requested tag cannot be cast to Rational array (" + object.getClass().toString() + ")");
|
||||
}
|
||||
|
||||
public String getString(int paramInt) {
|
||||
Object object = getObject(paramInt);
|
||||
if (object == null)
|
||||
return null;
|
||||
if (object instanceof Rational)
|
||||
return ((Rational)object).toSimpleString(true);
|
||||
if (object.getClass().isArray()) {
|
||||
int i = Array.getLength(object);
|
||||
boolean bool = object.getClass().toString().startsWith("class [L");
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (j != 0)
|
||||
stringBuffer.append(' ');
|
||||
if (bool) {
|
||||
stringBuffer.append(Array.get(object, j).toString());
|
||||
} else {
|
||||
stringBuffer.append(Array.getInt(object, j));
|
||||
}
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
public Object getObject(int paramInt) {
|
||||
return this._tagMap.get(new Integer(paramInt));
|
||||
}
|
||||
|
||||
public String getTagName(int paramInt) {
|
||||
Integer integer = new Integer(paramInt);
|
||||
HashMap hashMap = getTagNameMap();
|
||||
if (!hashMap.containsKey(integer)) {
|
||||
String str;
|
||||
for (str = Integer.toHexString(paramInt); str.length() < 4; str = "0" + str);
|
||||
return "Unknown tag (0x" + str + ")";
|
||||
}
|
||||
return (String)hashMap.get(integer);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
if (this._descriptor == null)
|
||||
throw new MetadataException("a descriptor must be set using setDescriptor(...) before descriptions can be provided");
|
||||
return this._descriptor.getDescription(paramInt);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.drew.metadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
public final class Metadata implements Serializable {
|
||||
private final HashMap directoryMap = new HashMap();
|
||||
|
||||
private final ArrayList directoryList = new ArrayList();
|
||||
|
||||
public Iterator getDirectoryIterator() {
|
||||
return this.directoryList.iterator();
|
||||
}
|
||||
|
||||
public int getDirectoryCount() {
|
||||
return this.directoryList.size();
|
||||
}
|
||||
|
||||
public Directory getDirectory(Class paramClass) {
|
||||
Object object;
|
||||
if (!Directory.class.isAssignableFrom(paramClass))
|
||||
throw new RuntimeException("Class type passed to getDirectory must be an implementation of com.drew.metadata.Directory");
|
||||
if (this.directoryMap.containsKey(paramClass))
|
||||
return (Directory)this.directoryMap.get(paramClass);
|
||||
try {
|
||||
object = paramClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot instantiate provided Directory type: " + paramClass.toString());
|
||||
}
|
||||
this.directoryMap.put(paramClass, object);
|
||||
this.directoryList.add(object);
|
||||
return (Directory)object;
|
||||
}
|
||||
|
||||
public boolean containsDirectory(Class paramClass) {
|
||||
return this.directoryMap.containsKey(paramClass);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.drew.metadata;
|
||||
|
||||
import com.drew.lang.CompoundException;
|
||||
|
||||
public class MetadataException extends CompoundException {
|
||||
public MetadataException(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public MetadataException(Throwable paramThrowable) {
|
||||
super(paramThrowable);
|
||||
}
|
||||
|
||||
public MetadataException(String paramString, Throwable paramThrowable) {
|
||||
super(paramString, paramThrowable);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package com.drew.metadata;
|
||||
|
||||
public interface MetadataReader {
|
||||
Metadata extract();
|
||||
|
||||
Metadata extract(Metadata paramMetadata);
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
package com.drew.metadata;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegMetadataReader;
|
||||
import com.drew.imaging.jpeg.JpegProcessingException;
|
||||
import com.drew.imaging.jpeg.JpegSegmentReader;
|
||||
import com.drew.metadata.exif.ExifReader;
|
||||
import com.drew.metadata.iptc.IptcReader;
|
||||
import com.sun.image.codec.jpeg.JPEGCodec;
|
||||
import com.sun.image.codec.jpeg.JPEGDecodeParam;
|
||||
import com.sun.image.codec.jpeg.JPEGImageDecoder;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class SampleUsage {
|
||||
public SampleUsage(String paramString) {
|
||||
File file = new File(paramString);
|
||||
try {
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(file);
|
||||
printImageTags(1, metadata);
|
||||
} catch (JpegProcessingException e) {
|
||||
System.err.println("error 1a");
|
||||
}
|
||||
try {
|
||||
Metadata metadata = new Metadata();
|
||||
new ExifReader(file).extract(metadata);
|
||||
new IptcReader(file).extract(metadata);
|
||||
printImageTags(2, metadata);
|
||||
} catch (JpegProcessingException e) {
|
||||
System.err.println("error 2a");
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("error 2b");
|
||||
}
|
||||
try {
|
||||
JpegSegmentReader jpegSegmentReader = new JpegSegmentReader(file);
|
||||
byte[] arrayOfByte1 = jpegSegmentReader.readSegment((byte)-31);
|
||||
byte[] arrayOfByte2 = jpegSegmentReader.readSegment((byte)-19);
|
||||
Metadata metadata = new Metadata();
|
||||
new ExifReader(arrayOfByte1).extract(metadata);
|
||||
new IptcReader(arrayOfByte2).extract(metadata);
|
||||
printImageTags(3, metadata);
|
||||
} catch (JpegProcessingException e) {
|
||||
System.err.println("error 3a");
|
||||
}
|
||||
try {
|
||||
JPEGImageDecoder jPEGImageDecoder = JPEGCodec.createJPEGDecoder(new FileInputStream(file));
|
||||
BufferedImage bufferedImage = jPEGImageDecoder.decodeAsBufferedImage();
|
||||
JPEGDecodeParam jPEGDecodeParam = jPEGImageDecoder.getJPEGDecodeParam();
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(jPEGDecodeParam);
|
||||
printImageTags(4, metadata);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("error 4a");
|
||||
} catch (IOException e) {
|
||||
System.err.println("error 4b");
|
||||
}
|
||||
}
|
||||
|
||||
private void printImageTags(int paramInt, Metadata paramMetadata) {
|
||||
System.out.println();
|
||||
System.out.println("*** APPROACH " + paramInt + " ***");
|
||||
System.out.println();
|
||||
Iterator iterator = paramMetadata.getDirectoryIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Directory directory = (Directory)iterator.next();
|
||||
Iterator iterator1 = directory.getTagIterator();
|
||||
while (iterator1.hasNext()) {
|
||||
Tag tag = (Tag)iterator1.next();
|
||||
System.out.println(tag);
|
||||
}
|
||||
if (directory.hasErrors()) {
|
||||
Iterator iterator2 = directory.getErrors();
|
||||
while (iterator2.hasNext())
|
||||
System.out.println("ERROR: " + iterator2.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] paramArrayOfString) {
|
||||
new SampleUsage("src/com/drew/metadata/test/withIptcExifGps.jpg");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.drew.metadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Tag implements Serializable {
|
||||
private final int _tagType;
|
||||
|
||||
private final Directory _directory;
|
||||
|
||||
public Tag(int paramInt, Directory paramDirectory) {
|
||||
this._tagType = paramInt;
|
||||
this._directory = paramDirectory;
|
||||
}
|
||||
|
||||
public int getTagType() {
|
||||
return this._tagType;
|
||||
}
|
||||
|
||||
public String getTagTypeHex() {
|
||||
String str;
|
||||
for (str = Integer.toHexString(this._tagType); str.length() < 4; str = "0" + str);
|
||||
return "0x" + str;
|
||||
}
|
||||
|
||||
public String getDescription() throws MetadataException {
|
||||
return this._directory.getDescription(this._tagType);
|
||||
}
|
||||
|
||||
public String getTagName() {
|
||||
return this._directory.getTagName(this._tagType);
|
||||
}
|
||||
|
||||
public String getDirectoryName() {
|
||||
return this._directory.getName();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String str;
|
||||
try {
|
||||
str = getDescription();
|
||||
} catch (MetadataException e) {
|
||||
str = this._directory.getString(getTagType()) + " (unable to formulate description)";
|
||||
}
|
||||
return "[" + this._directory.getName() + "] " + getTagName() + " - " + str;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.drew.metadata;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class TagDescriptor implements Serializable {
|
||||
protected final Directory _directory;
|
||||
|
||||
public TagDescriptor(Directory paramDirectory) {
|
||||
this._directory = paramDirectory;
|
||||
}
|
||||
|
||||
public abstract String getDescription(int paramInt) throws MetadataException;
|
||||
}
|
||||
|
|
@ -0,0 +1,427 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class CanonMakernoteDescriptor extends TagDescriptor {
|
||||
public CanonMakernoteDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 49409:
|
||||
return getMacroModeDescription();
|
||||
case 49410:
|
||||
return getSelfTimerDelayDescription();
|
||||
case 49412:
|
||||
return getFlashModeDescription();
|
||||
case 49413:
|
||||
return getContinuousDriveModeDescription();
|
||||
case 49415:
|
||||
return getFocusMode1Description();
|
||||
case 49418:
|
||||
return getImageSizeDescription();
|
||||
case 49419:
|
||||
return getEasyShootingModeDescription();
|
||||
case 49421:
|
||||
return getContrastDescription();
|
||||
case 49422:
|
||||
return getSaturationDescription();
|
||||
case 49423:
|
||||
return getSharpnessDescription();
|
||||
case 49424:
|
||||
return getIsoDescription();
|
||||
case 49425:
|
||||
return getMeteringModeDescription();
|
||||
case 49427:
|
||||
return getAfPointSelectedDescription();
|
||||
case 49428:
|
||||
return getExposureModeDescription();
|
||||
case 49431:
|
||||
return getLongFocalLengthDescription();
|
||||
case 49432:
|
||||
return getShortFocalLengthDescription();
|
||||
case 49433:
|
||||
return getFocalUnitsPerMillimetreDescription();
|
||||
case 49437:
|
||||
return getFlashDetailsDescription();
|
||||
case 49440:
|
||||
return getFocusMode2Description();
|
||||
case 49671:
|
||||
return getWhiteBalanceDescription();
|
||||
case 49678:
|
||||
return getAfPointUsedDescription();
|
||||
case 49679:
|
||||
return getFlashBiasDescription();
|
||||
}
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
|
||||
private String getFlashBiasDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49679))
|
||||
return null;
|
||||
int i = this._directory.getInt(49679);
|
||||
switch (i) {
|
||||
case 65472:
|
||||
return "-2 EV";
|
||||
case 65484:
|
||||
return "-1.67 EV";
|
||||
case 65488:
|
||||
return "-1.50 EV";
|
||||
case 65492:
|
||||
return "-1.33 EV";
|
||||
case 65504:
|
||||
return "-1 EV";
|
||||
case 65516:
|
||||
return "-0.67 EV";
|
||||
case 65520:
|
||||
return "-0.50 EV";
|
||||
case 65524:
|
||||
return "-0.33 EV";
|
||||
case 0:
|
||||
return "0 EV";
|
||||
case 12:
|
||||
return "0.33 EV";
|
||||
case 16:
|
||||
return "0.50 EV";
|
||||
case 20:
|
||||
return "0.67 EV";
|
||||
case 32:
|
||||
return "1 EV";
|
||||
case 44:
|
||||
return "1.33 EV";
|
||||
case 48:
|
||||
return "1.50 EV";
|
||||
case 52:
|
||||
return "1.67 EV";
|
||||
case 64:
|
||||
return "2 EV";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getAfPointUsedDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49678))
|
||||
return null;
|
||||
int i = this._directory.getInt(49678);
|
||||
return ((i & 0x7) == 0) ? "Right" : (((i & 0x7) == 1) ? "Centre" : (((i & 0x7) == 2) ? "Left" : ("Unknown (" + i + ")")));
|
||||
}
|
||||
|
||||
private String getWhiteBalanceDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49671))
|
||||
return null;
|
||||
int i = this._directory.getInt(49671);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Auto";
|
||||
case 1:
|
||||
return "Sunny";
|
||||
case 2:
|
||||
return "Cloudy";
|
||||
case 3:
|
||||
return "Tungsten";
|
||||
case 4:
|
||||
return "Flourescent";
|
||||
case 5:
|
||||
return "Flash";
|
||||
case 6:
|
||||
return "Custom";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getFocusMode2Description() throws MetadataException {
|
||||
if (!this._directory.containsTag(49440))
|
||||
return null;
|
||||
int i = this._directory.getInt(49440);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Single";
|
||||
case 1:
|
||||
return "Continuous";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getFlashDetailsDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49437))
|
||||
return null;
|
||||
int i = this._directory.getInt(49437);
|
||||
return ((i << 14 & 0x1) > 0) ? "External E-TTL" : (((i << 13 & 0x1) > 0) ? "Internal flash" : (((i << 11 & 0x1) > 0) ? "FP sync used" : (((i << 4 & 0x1) > 0) ? "FP sync enabled" : ("Unknown (" + i + ")"))));
|
||||
}
|
||||
|
||||
private String getFocalUnitsPerMillimetreDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49433))
|
||||
return "";
|
||||
int i = this._directory.getInt(49433);
|
||||
return (i != 0) ? Integer.toString(i) : "";
|
||||
}
|
||||
|
||||
private String getShortFocalLengthDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49432))
|
||||
return null;
|
||||
int i = this._directory.getInt(49432);
|
||||
String str = getFocalUnitsPerMillimetreDescription();
|
||||
return Integer.toString(i) + " " + str;
|
||||
}
|
||||
|
||||
private String getLongFocalLengthDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49431))
|
||||
return null;
|
||||
int i = this._directory.getInt(49431);
|
||||
String str = getFocalUnitsPerMillimetreDescription();
|
||||
return Integer.toString(i) + " " + str;
|
||||
}
|
||||
|
||||
private String getExposureModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49428))
|
||||
return null;
|
||||
int i = this._directory.getInt(49428);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Easy shooting";
|
||||
case 1:
|
||||
return "Program";
|
||||
case 2:
|
||||
return "Tv-priority";
|
||||
case 3:
|
||||
return "Av-priority";
|
||||
case 4:
|
||||
return "Manual";
|
||||
case 5:
|
||||
return "A-DEP";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getAfPointSelectedDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49427))
|
||||
return null;
|
||||
int i = this._directory.getInt(49427);
|
||||
switch (i) {
|
||||
case 12288:
|
||||
return "None (MF)";
|
||||
case 12289:
|
||||
return "Auto selected";
|
||||
case 12290:
|
||||
return "Right";
|
||||
case 12291:
|
||||
return "Centre";
|
||||
case 12292:
|
||||
return "Left";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getMeteringModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49425))
|
||||
return null;
|
||||
int i = this._directory.getInt(49425);
|
||||
switch (i) {
|
||||
case 3:
|
||||
return "Evaluative";
|
||||
case 4:
|
||||
return "Partial";
|
||||
case 5:
|
||||
return "Centre weighted";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getIsoDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49424))
|
||||
return null;
|
||||
int i = this._directory.getInt(49424);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Not specified (see ISOSpeedRatings tag)";
|
||||
case 15:
|
||||
return "Auto";
|
||||
case 16:
|
||||
return "50";
|
||||
case 17:
|
||||
return "100";
|
||||
case 18:
|
||||
return "200";
|
||||
case 19:
|
||||
return "400";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getSharpnessDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49423))
|
||||
return null;
|
||||
int i = this._directory.getInt(49423);
|
||||
switch (i) {
|
||||
case 65535:
|
||||
return "Low";
|
||||
case 0:
|
||||
return "Normal";
|
||||
case 1:
|
||||
return "High";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getSaturationDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49422))
|
||||
return null;
|
||||
int i = this._directory.getInt(49422);
|
||||
switch (i) {
|
||||
case 65535:
|
||||
return "Low";
|
||||
case 0:
|
||||
return "Normal";
|
||||
case 1:
|
||||
return "High";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getContrastDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49421))
|
||||
return null;
|
||||
int i = this._directory.getInt(49421);
|
||||
switch (i) {
|
||||
case 65535:
|
||||
return "Low";
|
||||
case 0:
|
||||
return "Normal";
|
||||
case 1:
|
||||
return "High";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getEasyShootingModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49419))
|
||||
return null;
|
||||
int i = this._directory.getInt(49419);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Full auto";
|
||||
case 1:
|
||||
return "Manual";
|
||||
case 2:
|
||||
return "Landscape";
|
||||
case 3:
|
||||
return "Fast shutter";
|
||||
case 4:
|
||||
return "Slow shutter";
|
||||
case 5:
|
||||
return "Night";
|
||||
case 6:
|
||||
return "B&W";
|
||||
case 7:
|
||||
return "Sepia";
|
||||
case 8:
|
||||
return "Portrait";
|
||||
case 9:
|
||||
return "Sports";
|
||||
case 10:
|
||||
return "Macro / Closeup";
|
||||
case 11:
|
||||
return "Pan focus";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getImageSizeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49418))
|
||||
return null;
|
||||
int i = this._directory.getInt(49418);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Large";
|
||||
case 1:
|
||||
return "Medium";
|
||||
case 2:
|
||||
return "Small";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getFocusMode1Description() throws MetadataException {
|
||||
if (!this._directory.containsTag(49415))
|
||||
return null;
|
||||
int i = this._directory.getInt(49415);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "One-shot";
|
||||
case 1:
|
||||
return "AI Servo";
|
||||
case 2:
|
||||
return "AI Focus";
|
||||
case 3:
|
||||
return "MF";
|
||||
case 4:
|
||||
return "Single";
|
||||
case 5:
|
||||
return "Continuous";
|
||||
case 6:
|
||||
return "MF";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getContinuousDriveModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49413))
|
||||
return null;
|
||||
int i = this._directory.getInt(49413);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return (this._directory.getInt(49410) == 0) ? "Single shot" : "Single shot with self-timer";
|
||||
case 1:
|
||||
return "Continuous";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getFlashModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49412))
|
||||
return null;
|
||||
int i = this._directory.getInt(49412);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "No flash fired";
|
||||
case 1:
|
||||
return "Auto";
|
||||
case 2:
|
||||
return "On";
|
||||
case 3:
|
||||
return "Red-eye reduction";
|
||||
case 4:
|
||||
return "Slow-synchro";
|
||||
case 5:
|
||||
return "Auto and red-eye reduction";
|
||||
case 6:
|
||||
return "On and red-eye reduction";
|
||||
case 16:
|
||||
return "Extenal flash";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getSelfTimerDelayDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49410))
|
||||
return null;
|
||||
int i = this._directory.getInt(49410);
|
||||
return (i == 0) ? "Self timer not used" : (Double.toString((double)i * 0.1D) + " sec");
|
||||
}
|
||||
|
||||
private String getMacroModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(49409))
|
||||
return null;
|
||||
int i = this._directory.getInt(49409);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "Macro";
|
||||
case 2:
|
||||
return "Normal";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CanonMakernoteDirectory extends Directory {
|
||||
public static final int TAG_CANON_CAMERA_STATE_1 = 1;
|
||||
|
||||
public static final int TAG_CANON_CAMERA_STATE_2 = 4;
|
||||
|
||||
public static final int TAG_CANON_IMAGE_TYPE = 6;
|
||||
|
||||
public static final int TAG_CANON_FIRMWARE_VERSION = 7;
|
||||
|
||||
public static final int TAG_CANON_IMAGE_NUMBER = 8;
|
||||
|
||||
public static final int TAG_CANON_OWNER_NAME = 9;
|
||||
|
||||
public static final int TAG_CANON_SERIAL_NUMBER = 12;
|
||||
|
||||
public static final int TAG_CANON_UNKNOWN_1 = 13;
|
||||
|
||||
public static final int TAG_CANON_CUSTOM_FUNCTIONS = 15;
|
||||
|
||||
public static final int TAG_CANON_STATE1_MACRO_MODE = 49409;
|
||||
|
||||
public static final int TAG_CANON_STATE1_SELF_TIMER_DELAY = 49410;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_1 = 49411;
|
||||
|
||||
public static final int TAG_CANON_STATE1_FLASH_MODE = 49412;
|
||||
|
||||
public static final int TAG_CANON_STATE1_CONTINUOUS_DRIVE_MODE = 49413;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_2 = 49414;
|
||||
|
||||
public static final int TAG_CANON_STATE1_FOCUS_MODE_1 = 49415;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_3 = 49416;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_4 = 49417;
|
||||
|
||||
public static final int TAG_CANON_STATE1_IMAGE_SIZE = 49418;
|
||||
|
||||
public static final int TAG_CANON_STATE1_EASY_SHOOTING_MODE = 49419;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_5 = 49420;
|
||||
|
||||
public static final int TAG_CANON_STATE1_CONTRAST = 49421;
|
||||
|
||||
public static final int TAG_CANON_STATE1_SATURATION = 49422;
|
||||
|
||||
public static final int TAG_CANON_STATE1_SHARPNESS = 49423;
|
||||
|
||||
public static final int TAG_CANON_STATE1_ISO = 49424;
|
||||
|
||||
public static final int TAG_CANON_STATE1_METERING_MODE = 49425;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_6 = 49426;
|
||||
|
||||
public static final int TAG_CANON_STATE1_AF_POINT_SELECTED = 49427;
|
||||
|
||||
public static final int TAG_CANON_STATE1_EXPOSURE_MODE = 49428;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_7 = 49429;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_8 = 49430;
|
||||
|
||||
public static final int TAG_CANON_STATE1_LONG_FOCAL_LENGTH = 49431;
|
||||
|
||||
public static final int TAG_CANON_STATE1_SHORT_FOCAL_LENGTH = 49432;
|
||||
|
||||
public static final int TAG_CANON_STATE1_FOCAL_UNITS_PER_MM = 49433;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_9 = 49434;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_10 = 49435;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_11 = 49436;
|
||||
|
||||
public static final int TAG_CANON_STATE1_FLASH_DETAILS = 49437;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_12 = 49438;
|
||||
|
||||
public static final int TAG_CANON_STATE1_UNKNOWN_13 = 49439;
|
||||
|
||||
public static final int TAG_CANON_STATE1_FOCUS_MODE_2 = 49440;
|
||||
|
||||
public static final int TAG_CANON_STATE2_WHITE_BALANCE = 49671;
|
||||
|
||||
public static final int TAG_CANON_STATE2_SEQUENCE_NUMBER = 49673;
|
||||
|
||||
public static final int TAG_CANON_STATE2_AF_POINT_USED = 49678;
|
||||
|
||||
public static final int TAG_CANON_STATE2_FLASH_BIAS = 49679;
|
||||
|
||||
public static final int TAG_CANON_STATE2_SUBJECT_DISTANCE = 49683;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public CanonMakernoteDirectory() {
|
||||
setDescriptor(new CanonMakernoteDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Canon Makernote";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
public void setIntArray(int paramInt, int[] paramArrayOfint) {
|
||||
if (paramInt == 1) {
|
||||
int i = 49408;
|
||||
for (int j = 1; j < paramArrayOfint.length; j++)
|
||||
setInt(i + j, paramArrayOfint[j]);
|
||||
} else if (paramInt == 4) {
|
||||
int i = 49664;
|
||||
for (int j = 1; j < paramArrayOfint.length; j++)
|
||||
setInt(i + j, paramArrayOfint[j]);
|
||||
} else {
|
||||
super.setIntArray(paramInt, paramArrayOfint);
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(7), "Firmware Version");
|
||||
tagNameMap.put(new Integer(8), "Image Number");
|
||||
tagNameMap.put(new Integer(6), "Image Type");
|
||||
tagNameMap.put(new Integer(9), "Owner Name");
|
||||
tagNameMap.put(new Integer(13), "Makernote Unknown 1");
|
||||
tagNameMap.put(new Integer(15), "Custom Functions");
|
||||
tagNameMap.put(new Integer(12), "Camera Serial Number");
|
||||
tagNameMap.put(new Integer(49427), "AF Point Selected");
|
||||
tagNameMap.put(new Integer(49413), "Continuous Drive Mode");
|
||||
tagNameMap.put(new Integer(49421), "Contrast");
|
||||
tagNameMap.put(new Integer(49419), "Easy Shooting Mode");
|
||||
tagNameMap.put(new Integer(49428), "Exposure Mode");
|
||||
tagNameMap.put(new Integer(49437), "Flash Details");
|
||||
tagNameMap.put(new Integer(49412), "Flash Mode");
|
||||
tagNameMap.put(new Integer(49433), "Focal Units per mm");
|
||||
tagNameMap.put(new Integer(49415), "Focus Mode");
|
||||
tagNameMap.put(new Integer(49440), "Focus Mode");
|
||||
tagNameMap.put(new Integer(49418), "Image Size");
|
||||
tagNameMap.put(new Integer(49424), "Iso");
|
||||
tagNameMap.put(new Integer(49431), "Long Focal Length");
|
||||
tagNameMap.put(new Integer(49409), "Macro Mode");
|
||||
tagNameMap.put(new Integer(49425), "Metering Mode");
|
||||
tagNameMap.put(new Integer(49422), "Saturation");
|
||||
tagNameMap.put(new Integer(49410), "Self Timer Delay");
|
||||
tagNameMap.put(new Integer(49423), "Sharpness");
|
||||
tagNameMap.put(new Integer(49432), "Short Focal Length");
|
||||
tagNameMap.put(new Integer(49671), "White Balance");
|
||||
tagNameMap.put(new Integer(49673), "Sequence Number");
|
||||
tagNameMap.put(new Integer(49678), "AF Point Used");
|
||||
tagNameMap.put(new Integer(49679), "Flash Bias");
|
||||
tagNameMap.put(new Integer(49683), "Subject Distance");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,248 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class CasioMakernoteDescriptor extends TagDescriptor {
|
||||
public CasioMakernoteDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 1:
|
||||
return getRecordingModeDescription();
|
||||
case 2:
|
||||
return getQualityDescription();
|
||||
case 3:
|
||||
return getFocusingModeDescription();
|
||||
case 4:
|
||||
return getFlashModeDescription();
|
||||
case 5:
|
||||
return getFlashIntensityDescription();
|
||||
case 6:
|
||||
return getObjectDistanceDescription();
|
||||
case 7:
|
||||
return getWhiteBalanceDescription();
|
||||
case 10:
|
||||
return getDigitalZoomDescription();
|
||||
case 11:
|
||||
return getSharpnessDescription();
|
||||
case 12:
|
||||
return getContrastDescription();
|
||||
case 13:
|
||||
return getSaturationDescription();
|
||||
case 20:
|
||||
return getCcdSensitivityDescription();
|
||||
}
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
|
||||
private String getCcdSensitivityDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(20))
|
||||
return null;
|
||||
int i = this._directory.getInt(20);
|
||||
switch (i) {
|
||||
case 64:
|
||||
return "Normal";
|
||||
case 125:
|
||||
return "+1.0";
|
||||
case 250:
|
||||
return "+2.0";
|
||||
case 244:
|
||||
return "+3.0";
|
||||
case 80:
|
||||
return "Normal";
|
||||
case 100:
|
||||
return "High";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getSaturationDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(13))
|
||||
return null;
|
||||
int i = this._directory.getInt(13);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Normal";
|
||||
case 1:
|
||||
return "Low";
|
||||
case 2:
|
||||
return "High";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getContrastDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(12))
|
||||
return null;
|
||||
int i = this._directory.getInt(12);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Normal";
|
||||
case 1:
|
||||
return "Low";
|
||||
case 2:
|
||||
return "High";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getSharpnessDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(11))
|
||||
return null;
|
||||
int i = this._directory.getInt(11);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Normal";
|
||||
case 1:
|
||||
return "Soft";
|
||||
case 2:
|
||||
return "Hard";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getDigitalZoomDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(10))
|
||||
return null;
|
||||
int i = this._directory.getInt(10);
|
||||
switch (i) {
|
||||
case 65536:
|
||||
return "No digital zoom";
|
||||
case 65537:
|
||||
return "2x digital zoom";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getWhiteBalanceDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(7))
|
||||
return null;
|
||||
int i = this._directory.getInt(7);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "Auto";
|
||||
case 2:
|
||||
return "Tungsten";
|
||||
case 3:
|
||||
return "Daylight";
|
||||
case 4:
|
||||
return "Flourescent";
|
||||
case 5:
|
||||
return "Shade";
|
||||
case 129:
|
||||
return "Manual";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getObjectDistanceDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(6))
|
||||
return null;
|
||||
int i = this._directory.getInt(6);
|
||||
return i + "mm";
|
||||
}
|
||||
|
||||
private String getFlashIntensityDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(5))
|
||||
return null;
|
||||
int i = this._directory.getInt(5);
|
||||
switch (i) {
|
||||
case 11:
|
||||
return "Weak";
|
||||
case 13:
|
||||
return "Normal";
|
||||
case 15:
|
||||
return "Strong";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getFlashModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4))
|
||||
return null;
|
||||
int i = this._directory.getInt(4);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "Auto";
|
||||
case 2:
|
||||
return "On";
|
||||
case 3:
|
||||
return "Off";
|
||||
case 4:
|
||||
return "Red eye reduction";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getFocusingModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(3))
|
||||
return null;
|
||||
int i = this._directory.getInt(3);
|
||||
switch (i) {
|
||||
case 2:
|
||||
return "Macro";
|
||||
case 3:
|
||||
return "Auto focus";
|
||||
case 4:
|
||||
return "Manual focus";
|
||||
case 5:
|
||||
return "Infinity";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getQualityDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(2))
|
||||
return null;
|
||||
int i = this._directory.getInt(2);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "Economy";
|
||||
case 2:
|
||||
return "Normal";
|
||||
case 3:
|
||||
return "Fine";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getFocussingModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(3))
|
||||
return null;
|
||||
int i = this._directory.getInt(3);
|
||||
switch (i) {
|
||||
case 2:
|
||||
return "Macro";
|
||||
case 3:
|
||||
return "Auto focus";
|
||||
case 4:
|
||||
return "Manual focus";
|
||||
case 5:
|
||||
return "Infinity";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getRecordingModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(1))
|
||||
return null;
|
||||
int i = this._directory.getInt(1);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "Single shutter";
|
||||
case 2:
|
||||
return "Panorama";
|
||||
case 3:
|
||||
return "Night scene";
|
||||
case 4:
|
||||
return "Portrait";
|
||||
case 5:
|
||||
return "Landscape";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CasioMakernoteDirectory extends Directory {
|
||||
public static final int TAG_CASIO_RECORDING_MODE = 1;
|
||||
|
||||
public static final int TAG_CASIO_QUALITY = 2;
|
||||
|
||||
public static final int TAG_CASIO_FOCUSING_MODE = 3;
|
||||
|
||||
public static final int TAG_CASIO_FLASH_MODE = 4;
|
||||
|
||||
public static final int TAG_CASIO_FLASH_INTENSITY = 5;
|
||||
|
||||
public static final int TAG_CASIO_OBJECT_DISTANCE = 6;
|
||||
|
||||
public static final int TAG_CASIO_WHITE_BALANCE = 7;
|
||||
|
||||
public static final int TAG_CASIO_UNKNOWN_1 = 8;
|
||||
|
||||
public static final int TAG_CASIO_UNKNOWN_2 = 9;
|
||||
|
||||
public static final int TAG_CASIO_DIGITAL_ZOOM = 10;
|
||||
|
||||
public static final int TAG_CASIO_SHARPNESS = 11;
|
||||
|
||||
public static final int TAG_CASIO_CONTRAST = 12;
|
||||
|
||||
public static final int TAG_CASIO_SATURATION = 13;
|
||||
|
||||
public static final int TAG_CASIO_UNKNOWN_3 = 14;
|
||||
|
||||
public static final int TAG_CASIO_UNKNOWN_4 = 15;
|
||||
|
||||
public static final int TAG_CASIO_UNKNOWN_5 = 16;
|
||||
|
||||
public static final int TAG_CASIO_UNKNOWN_6 = 17;
|
||||
|
||||
public static final int TAG_CASIO_UNKNOWN_7 = 18;
|
||||
|
||||
public static final int TAG_CASIO_UNKNOWN_8 = 19;
|
||||
|
||||
public static final int TAG_CASIO_CCD_SENSITIVITY = 20;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public CasioMakernoteDirectory() {
|
||||
setDescriptor(new CasioMakernoteDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Casio Makernote";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(20), "CCD Sensitivity");
|
||||
tagNameMap.put(new Integer(12), "Contrast");
|
||||
tagNameMap.put(new Integer(10), "Digital Zoom");
|
||||
tagNameMap.put(new Integer(5), "Flash Intensity");
|
||||
tagNameMap.put(new Integer(4), "Flash Mode");
|
||||
tagNameMap.put(new Integer(3), "Focussing Mode");
|
||||
tagNameMap.put(new Integer(6), "Object Distance");
|
||||
tagNameMap.put(new Integer(2), "Quality");
|
||||
tagNameMap.put(new Integer(1), "Recording Mode");
|
||||
tagNameMap.put(new Integer(13), "Saturation");
|
||||
tagNameMap.put(new Integer(11), "Sharpness");
|
||||
tagNameMap.put(new Integer(8), "Makernote Unknown 1");
|
||||
tagNameMap.put(new Integer(9), "Makernote Unknown 2");
|
||||
tagNameMap.put(new Integer(14), "Makernote Unknown 3");
|
||||
tagNameMap.put(new Integer(15), "Makernote Unknown 4");
|
||||
tagNameMap.put(new Integer(16), "Makernote Unknown 5");
|
||||
tagNameMap.put(new Integer(17), "Makernote Unknown 6");
|
||||
tagNameMap.put(new Integer(18), "Makernote Unknown 7");
|
||||
tagNameMap.put(new Integer(19), "Makernote Unknown 8");
|
||||
tagNameMap.put(new Integer(7), "White Balance");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.MetadataException;
|
||||
|
||||
public class DataFormat {
|
||||
public static final DataFormat BYTE = new DataFormat("BYTE", 1);
|
||||
|
||||
public static final DataFormat STRING = new DataFormat("STRING", 2);
|
||||
|
||||
public static final DataFormat USHORT = new DataFormat("USHORT", 3);
|
||||
|
||||
public static final DataFormat ULONG = new DataFormat("ULONG", 4);
|
||||
|
||||
public static final DataFormat URATIONAL = new DataFormat("URATIONAL", 5);
|
||||
|
||||
public static final DataFormat SBYTE = new DataFormat("SBYTE", 6);
|
||||
|
||||
public static final DataFormat UNDEFINED = new DataFormat("UNDEFINED", 7);
|
||||
|
||||
public static final DataFormat SSHORT = new DataFormat("SSHORT", 8);
|
||||
|
||||
public static final DataFormat SLONG = new DataFormat("SLONG", 9);
|
||||
|
||||
public static final DataFormat SRATIONAL = new DataFormat("SRATIONAL", 10);
|
||||
|
||||
public static final DataFormat SINGLE = new DataFormat("SINGLE", 11);
|
||||
|
||||
public static final DataFormat DOUBLE = new DataFormat("DOUBLE", 12);
|
||||
|
||||
private final String myName;
|
||||
|
||||
private final int value;
|
||||
|
||||
public static DataFormat fromValue(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 1:
|
||||
return BYTE;
|
||||
case 2:
|
||||
return STRING;
|
||||
case 3:
|
||||
return USHORT;
|
||||
case 4:
|
||||
return ULONG;
|
||||
case 5:
|
||||
return URATIONAL;
|
||||
case 6:
|
||||
return SBYTE;
|
||||
case 7:
|
||||
return UNDEFINED;
|
||||
case 8:
|
||||
return SSHORT;
|
||||
case 9:
|
||||
return SLONG;
|
||||
case 10:
|
||||
return SRATIONAL;
|
||||
case 11:
|
||||
return SINGLE;
|
||||
case 12:
|
||||
return DOUBLE;
|
||||
}
|
||||
throw new MetadataException("value '" + paramInt + "' does not represent a known data format.");
|
||||
}
|
||||
|
||||
private DataFormat(String paramString, int paramInt) {
|
||||
this.myName = paramString;
|
||||
this.value = paramInt;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.myName;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,570 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.lang.Rational;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class ExifDescriptor extends TagDescriptor {
|
||||
private boolean _allowDecimalRepresentationOfRationals = true;
|
||||
|
||||
public ExifDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 274:
|
||||
return getOrientationDescription();
|
||||
case 296:
|
||||
return getResolutionDescription();
|
||||
case 531:
|
||||
return getYCbCrPositioningDescription();
|
||||
case 33434:
|
||||
return getExposureTimeDescription();
|
||||
case 37377:
|
||||
return getShutterSpeedDescription();
|
||||
case 33437:
|
||||
return getFNumberDescription();
|
||||
case 282:
|
||||
return getXResolutionDescription();
|
||||
case 283:
|
||||
return getYResolutionDescription();
|
||||
case 513:
|
||||
return getThumbnailOffsetDescription();
|
||||
case 514:
|
||||
return getThumbnailLengthDescription();
|
||||
case 37122:
|
||||
return getCompressionLevelDescription();
|
||||
case 37382:
|
||||
return getSubjectDistanceDescription();
|
||||
case 37383:
|
||||
return getMeteringModeDescription();
|
||||
case 37384:
|
||||
return getWhiteBalanceDescription();
|
||||
case 37385:
|
||||
return getFlashDescription();
|
||||
case 37386:
|
||||
return getFocalLengthDescription();
|
||||
case 40961:
|
||||
return getColorSpaceDescription();
|
||||
case 40962:
|
||||
return getExifImageWidthDescription();
|
||||
case 40963:
|
||||
return getExifImageHeightDescription();
|
||||
case 41488:
|
||||
return getFocalPlaneResolutionUnitDescription();
|
||||
case 41486:
|
||||
return getFocalPlaneXResolutionDescription();
|
||||
case 41487:
|
||||
return getFocalPlaneYResolutionDescription();
|
||||
case 256:
|
||||
return getThumbnailImageWidthDescription();
|
||||
case 257:
|
||||
return getThumbnailImageHeightDescription();
|
||||
case 258:
|
||||
return getBitsPerSampleDescription();
|
||||
case 259:
|
||||
return getCompressionDescription();
|
||||
case 262:
|
||||
return getPhotometricInterpretationDescription();
|
||||
case 278:
|
||||
return getRowsPerStripDescription();
|
||||
case 279:
|
||||
return getStripByteCountsDescription();
|
||||
case 277:
|
||||
return getSamplesPerPixelDescription();
|
||||
case 284:
|
||||
return getPlanarConfigurationDescription();
|
||||
case 530:
|
||||
return getYCbCrSubsamplingDescription();
|
||||
case 34850:
|
||||
return getExposureProgramDescription();
|
||||
case 37378:
|
||||
return getApertureValueDescription();
|
||||
case 37381:
|
||||
return getMaxApertureValueDescription();
|
||||
case 41495:
|
||||
return getSensingMethodDescription();
|
||||
case 37380:
|
||||
return getExposureBiasDescription();
|
||||
case 41728:
|
||||
return getFileSourceDescription();
|
||||
case 41729:
|
||||
return getSceneTypeDescription();
|
||||
case 37121:
|
||||
return getComponentConfigurationDescription();
|
||||
case 36864:
|
||||
return getExifVersionDescription();
|
||||
case 40960:
|
||||
return getFlashPixVersionDescription();
|
||||
case 532:
|
||||
return getReferenceBlackWhiteDescription();
|
||||
case 34855:
|
||||
return getIsoEquivalentDescription();
|
||||
case 61441:
|
||||
return getThumbnailDescription();
|
||||
}
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
|
||||
private String getThumbnailDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(61441))
|
||||
return null;
|
||||
int[] arrayOfInt = this._directory.getIntArray(61441);
|
||||
return "[" + arrayOfInt.length + " bytes of thumbnail data]";
|
||||
}
|
||||
|
||||
private String getIsoEquivalentDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(34855))
|
||||
return null;
|
||||
int i = this._directory.getInt(34855);
|
||||
if (i < 50)
|
||||
i *= 200;
|
||||
return Integer.toString(i);
|
||||
}
|
||||
|
||||
private String getReferenceBlackWhiteDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(532))
|
||||
return null;
|
||||
int[] arrayOfInt = this._directory.getIntArray(532);
|
||||
int i = arrayOfInt[0];
|
||||
int j = arrayOfInt[1];
|
||||
int k = arrayOfInt[2];
|
||||
int m = arrayOfInt[3];
|
||||
int n = arrayOfInt[4];
|
||||
int i1 = arrayOfInt[5];
|
||||
return "[" + i + "," + k + "," + n + "] " + "[" + j + "," + m + "," + i1 + "]";
|
||||
}
|
||||
|
||||
private String getExifVersionDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(36864))
|
||||
return null;
|
||||
int[] arrayOfInt = this._directory.getIntArray(36864);
|
||||
return convertBytesToVersionString(arrayOfInt);
|
||||
}
|
||||
|
||||
private String getFlashPixVersionDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(40960))
|
||||
return null;
|
||||
int[] arrayOfInt = this._directory.getIntArray(40960);
|
||||
return convertBytesToVersionString(arrayOfInt);
|
||||
}
|
||||
|
||||
private String getSceneTypeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(41729))
|
||||
return null;
|
||||
int i = this._directory.getInt(41729);
|
||||
return (i == 1) ? "Directly photographed image" : ("Unknown (" + i + ")");
|
||||
}
|
||||
|
||||
private String getFileSourceDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(41728))
|
||||
return null;
|
||||
int i = this._directory.getInt(41728);
|
||||
return (i == 3) ? "Digital Still Camera (DSC)" : ("Unknown (" + i + ")");
|
||||
}
|
||||
|
||||
private String getExposureBiasDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(37380))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(37380);
|
||||
return rational.toSimpleString(true);
|
||||
}
|
||||
|
||||
private String getMaxApertureValueDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(37381))
|
||||
return null;
|
||||
double d1 = this._directory.getDouble(37381);
|
||||
double d2 = Math.sqrt(2.0D);
|
||||
double d3 = Math.pow(d2, d1);
|
||||
DecimalFormat decimalFormat = new DecimalFormat("0.#");
|
||||
return "F" + decimalFormat.format(d3);
|
||||
}
|
||||
|
||||
private String getApertureValueDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(37378))
|
||||
return null;
|
||||
double d1 = this._directory.getDouble(37378);
|
||||
double d2 = Math.sqrt(2.0D);
|
||||
double d3 = Math.pow(d2, d1);
|
||||
DecimalFormat decimalFormat = new DecimalFormat("0.#");
|
||||
return "F" + decimalFormat.format(d3);
|
||||
}
|
||||
|
||||
private String getExposureProgramDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(34850))
|
||||
return null;
|
||||
switch (this._directory.getInt(34850)) {
|
||||
case 1:
|
||||
return "Manual control";
|
||||
case 2:
|
||||
return "Program normal";
|
||||
case 3:
|
||||
return "Aperture priority";
|
||||
case 4:
|
||||
return "Shutter priority";
|
||||
case 5:
|
||||
return "Program creative (slow program)";
|
||||
case 6:
|
||||
return "Program action (high-speed program)";
|
||||
case 7:
|
||||
return "Portrait mode";
|
||||
case 8:
|
||||
return "Landscape mode";
|
||||
}
|
||||
return "Unknown program (" + this._directory.getInt(34850) + ")";
|
||||
}
|
||||
|
||||
private String getYCbCrSubsamplingDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(530))
|
||||
return null;
|
||||
int[] arrayOfInt = this._directory.getIntArray(530);
|
||||
return (arrayOfInt[0] == 2 && arrayOfInt[1] == 1) ? "YCbCr4:2:2" : ((arrayOfInt[0] == 2 && arrayOfInt[1] == 2) ? "YCbCr4:2:0" : "(Unknown)");
|
||||
}
|
||||
|
||||
private String getPlanarConfigurationDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(284))
|
||||
return null;
|
||||
switch (this._directory.getInt(284)) {
|
||||
case 1:
|
||||
return "Chunky (contiguous for each subsampling pixel)";
|
||||
case 2:
|
||||
return "Separate (Y-plane/Cb-plane/Cr-plane format)";
|
||||
}
|
||||
return "Unknown configuration";
|
||||
}
|
||||
|
||||
private String getSamplesPerPixelDescription() {
|
||||
return !this._directory.containsTag(277) ? null : (this._directory.getString(277) + " samples/pixel");
|
||||
}
|
||||
|
||||
private String getRowsPerStripDescription() {
|
||||
return !this._directory.containsTag(278) ? null : (this._directory.getString(278) + " rows/strip");
|
||||
}
|
||||
|
||||
private String getStripByteCountsDescription() {
|
||||
return !this._directory.containsTag(279) ? null : (this._directory.getString(279) + " bytes");
|
||||
}
|
||||
|
||||
private String getPhotometricInterpretationDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(262))
|
||||
return null;
|
||||
switch (this._directory.getInt(262)) {
|
||||
case 1:
|
||||
return "Monochrome";
|
||||
case 2:
|
||||
return "RGB";
|
||||
case 6:
|
||||
return "YCbCr";
|
||||
}
|
||||
return "Unknown colour space";
|
||||
}
|
||||
|
||||
private String getCompressionDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(259))
|
||||
return null;
|
||||
switch (this._directory.getInt(259)) {
|
||||
case 1:
|
||||
return "No compression";
|
||||
case 6:
|
||||
return "JPEG compression";
|
||||
}
|
||||
return "Unknown compression";
|
||||
}
|
||||
|
||||
private String getBitsPerSampleDescription() {
|
||||
return !this._directory.containsTag(258) ? null : (this._directory.getString(258) + " bits/component/pixel");
|
||||
}
|
||||
|
||||
private String getThumbnailImageWidthDescription() {
|
||||
return !this._directory.containsTag(256) ? null : (this._directory.getString(256) + " pixels");
|
||||
}
|
||||
|
||||
private String getThumbnailImageHeightDescription() {
|
||||
return !this._directory.containsTag(257) ? null : (this._directory.getString(257) + " pixels");
|
||||
}
|
||||
|
||||
private String getFocalPlaneXResolutionDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(41486))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(41486);
|
||||
return rational.getReciprocal().toSimpleString(this._allowDecimalRepresentationOfRationals) + " " + getFocalPlaneResolutionUnitDescription().toLowerCase();
|
||||
}
|
||||
|
||||
private String getFocalPlaneYResolutionDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(259))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(41487);
|
||||
return rational.getReciprocal().toSimpleString(this._allowDecimalRepresentationOfRationals) + " " + getFocalPlaneResolutionUnitDescription().toLowerCase();
|
||||
}
|
||||
|
||||
private String getFocalPlaneResolutionUnitDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(41488))
|
||||
return null;
|
||||
switch (this._directory.getInt(41488)) {
|
||||
case 1:
|
||||
return "(No unit)";
|
||||
case 2:
|
||||
return "Inches";
|
||||
case 3:
|
||||
return "cm";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getExifImageWidthDescription() throws MetadataException {
|
||||
return !this._directory.containsTag(40962) ? null : (this._directory.getInt(40962) + " pixels");
|
||||
}
|
||||
|
||||
private String getExifImageHeightDescription() throws MetadataException {
|
||||
return !this._directory.containsTag(40963) ? null : (this._directory.getInt(40963) + " pixels");
|
||||
}
|
||||
|
||||
private String getColorSpaceDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(40961))
|
||||
return null;
|
||||
int i = this._directory.getInt(40961);
|
||||
return (i == 1) ? "sRGB" : ((i == 65535) ? "Undefined" : "Unknown");
|
||||
}
|
||||
|
||||
private String getFocalLengthDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(37386))
|
||||
return null;
|
||||
DecimalFormat decimalFormat = new DecimalFormat("0.0##");
|
||||
Rational rational = this._directory.getRational(37386);
|
||||
return decimalFormat.format(rational.doubleValue()) + " mm";
|
||||
}
|
||||
|
||||
private String getFlashDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(37385))
|
||||
return null;
|
||||
switch (this._directory.getInt(37385)) {
|
||||
case 0:
|
||||
return "No flash fired";
|
||||
case 1:
|
||||
return "Flash fired";
|
||||
case 5:
|
||||
return "Flash fired but strobe return light not detected";
|
||||
case 7:
|
||||
return "flash fired and strobe return light detected";
|
||||
}
|
||||
return "Unknown (" + this._directory.getInt(37385) + ")";
|
||||
}
|
||||
|
||||
private String getWhiteBalanceDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(37384))
|
||||
return null;
|
||||
switch (this._directory.getInt(37384)) {
|
||||
case 0:
|
||||
return "Unknown";
|
||||
case 1:
|
||||
return "Daylight";
|
||||
case 2:
|
||||
return "Flourescent";
|
||||
case 3:
|
||||
return "Tungsten";
|
||||
case 10:
|
||||
return "Flash";
|
||||
case 17:
|
||||
return "Standard light";
|
||||
case 18:
|
||||
return "Standard light (B)";
|
||||
case 19:
|
||||
return "Standard light (C)";
|
||||
case 20:
|
||||
return "D55";
|
||||
case 21:
|
||||
return "D65";
|
||||
case 22:
|
||||
return "D75";
|
||||
case 255:
|
||||
return "(Other)";
|
||||
}
|
||||
return "Unknown (" + this._directory.getInt(37384) + ")";
|
||||
}
|
||||
|
||||
private String getMeteringModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(37383))
|
||||
return null;
|
||||
int i = this._directory.getInt(37383);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Unknown";
|
||||
case 1:
|
||||
return "Average";
|
||||
case 2:
|
||||
return "Center weighted average";
|
||||
case 3:
|
||||
return "Spot";
|
||||
case 4:
|
||||
return "Multi-spot";
|
||||
case 5:
|
||||
return "Multi-segment";
|
||||
case 6:
|
||||
return "Partial";
|
||||
case 255:
|
||||
return "(Other)";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getSubjectDistanceDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(37382))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(37382);
|
||||
DecimalFormat decimalFormat = new DecimalFormat("0.0##");
|
||||
return decimalFormat.format(rational.doubleValue()) + " metres";
|
||||
}
|
||||
|
||||
private String getCompressionLevelDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(37122))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(37122);
|
||||
String str = rational.toSimpleString(this._allowDecimalRepresentationOfRationals);
|
||||
return (rational.isInteger() && rational.intValue() == 1) ? (str + " bit/pixel") : (str + " bits/pixel");
|
||||
}
|
||||
|
||||
private String getThumbnailLengthDescription() {
|
||||
return !this._directory.containsTag(514) ? null : (this._directory.getString(514) + " bytes");
|
||||
}
|
||||
|
||||
private String getThumbnailOffsetDescription() {
|
||||
return !this._directory.containsTag(513) ? null : (this._directory.getString(513) + " bytes");
|
||||
}
|
||||
|
||||
private String getYResolutionDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(283))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(283);
|
||||
return rational.toSimpleString(this._allowDecimalRepresentationOfRationals) + " dots per " + getResolutionDescription().toLowerCase();
|
||||
}
|
||||
|
||||
private String getXResolutionDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(282))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(282);
|
||||
return rational.toSimpleString(this._allowDecimalRepresentationOfRationals) + " dots per " + getResolutionDescription().toLowerCase();
|
||||
}
|
||||
|
||||
private String getExposureTimeDescription() {
|
||||
return !this._directory.containsTag(33434) ? null : (this._directory.getString(33434) + " sec");
|
||||
}
|
||||
|
||||
private String getShutterSpeedDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(37377))
|
||||
return null;
|
||||
int i = this._directory.getInt(37377);
|
||||
int j = (int)Math.pow(2.0D, (double)i);
|
||||
return "1/" + j + " sec";
|
||||
}
|
||||
|
||||
private String getFNumberDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(33437))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(33437);
|
||||
DecimalFormat decimalFormat = new DecimalFormat("0.#");
|
||||
return "F" + decimalFormat.format(rational.doubleValue());
|
||||
}
|
||||
|
||||
private String getYCbCrPositioningDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(531))
|
||||
return null;
|
||||
int i = this._directory.getInt(531);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "Center of pixel array";
|
||||
case 2:
|
||||
return "Datum point";
|
||||
}
|
||||
return String.valueOf(i);
|
||||
}
|
||||
|
||||
private String getOrientationDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(274))
|
||||
return null;
|
||||
int i = this._directory.getInt(274);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "top, left side";
|
||||
case 2:
|
||||
return "top, right side";
|
||||
case 3:
|
||||
return "bottom, right side";
|
||||
case 4:
|
||||
return "bottom, left side";
|
||||
case 5:
|
||||
return "left side, top";
|
||||
case 6:
|
||||
return "right side, top";
|
||||
case 7:
|
||||
return "right side, bottom";
|
||||
case 8:
|
||||
return "left side, bottom";
|
||||
}
|
||||
return String.valueOf(i);
|
||||
}
|
||||
|
||||
private String getResolutionDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(296))
|
||||
return "";
|
||||
int i = this._directory.getInt(296);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "(No unit)";
|
||||
case 2:
|
||||
return "Inch";
|
||||
case 3:
|
||||
return "cm";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getSensingMethodDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(41495))
|
||||
return null;
|
||||
int i = this._directory.getInt(41495);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "(Not defined)";
|
||||
case 2:
|
||||
return "One-chip color area sensor";
|
||||
case 3:
|
||||
return "Two-chip color area sensor";
|
||||
case 4:
|
||||
return "Three-chip color area sensor";
|
||||
case 5:
|
||||
return "Color sequential area sensor";
|
||||
case 7:
|
||||
return "Trilinear sensor";
|
||||
case 8:
|
||||
return "Color sequential linear sensor";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getComponentConfigurationDescription() throws MetadataException {
|
||||
int[] arrayOfInt = this._directory.getIntArray(37121);
|
||||
String[] arrayOfString = { "", "Y", "Cb", "Cr", "R", "G", "B" };
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int i = 0; i < Math.min(4, arrayOfInt.length); i++) {
|
||||
int j = arrayOfInt[i];
|
||||
if (j > 0 && j < arrayOfString.length)
|
||||
stringBuffer.append(arrayOfString[j]);
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
public static String convertBytesToVersionString(int[] paramArrayOfint) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int i = 0; i < 4 && i < paramArrayOfint.length; i++) {
|
||||
if (i == 2)
|
||||
stringBuffer.append('.');
|
||||
String str = String.valueOf((char)paramArrayOfint[i]);
|
||||
if (i != 0 || !"0".equals(str))
|
||||
stringBuffer.append(str);
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,361 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ExifDirectory extends Directory {
|
||||
public static final int TAG_SUB_IFDS = 330;
|
||||
|
||||
public static final int TAG_GPS_INFO = 34853;
|
||||
|
||||
public static final int TAG_APERTURE = 37378;
|
||||
|
||||
public static final int TAG_BITS_PER_SAMPLE = 258;
|
||||
|
||||
public static final int TAG_COMPRESSION = 259;
|
||||
|
||||
public static final int TAG_PHOTOMETRIC_INTERPRETATION = 262;
|
||||
|
||||
public static final int TAG_STRIP_OFFSETS = 273;
|
||||
|
||||
public static final int TAG_SAMPLES_PER_PIXEL = 277;
|
||||
|
||||
public static final int TAG_ROWS_PER_STRIP = 278;
|
||||
|
||||
public static final int TAG_STRIP_BYTE_COUNTS = 279;
|
||||
|
||||
public static final int TAG_PLANAR_CONFIGURATION = 284;
|
||||
|
||||
public static final int TAG_YCBCR_SUBSAMPLING = 530;
|
||||
|
||||
public static final int TAG_IMAGE_DESCRIPTION = 270;
|
||||
|
||||
public static final int TAG_SOFTWARE = 305;
|
||||
|
||||
public static final int TAG_DATETIME = 306;
|
||||
|
||||
public static final int TAG_WHITE_POINT = 318;
|
||||
|
||||
public static final int TAG_PRIMARY_CHROMATICITIES = 319;
|
||||
|
||||
public static final int TAG_YCBCR_COEFFICIENTS = 529;
|
||||
|
||||
public static final int TAG_REFERENCE_BLACK_WHITE = 532;
|
||||
|
||||
public static final int TAG_COPYRIGHT = 33432;
|
||||
|
||||
public static final int TAG_NEW_SUBFILE_TYPE = 254;
|
||||
|
||||
public static final int TAG_SUBFILE_TYPE = 255;
|
||||
|
||||
public static final int TAG_TRANSFER_FUNCTION = 301;
|
||||
|
||||
public static final int TAG_ARTIST = 315;
|
||||
|
||||
public static final int TAG_PREDICTOR = 317;
|
||||
|
||||
public static final int TAG_TILE_WIDTH = 322;
|
||||
|
||||
public static final int TAG_TILE_LENGTH = 323;
|
||||
|
||||
public static final int TAG_TILE_OFFSETS = 324;
|
||||
|
||||
public static final int TAG_TILE_BYTE_COUNTS = 325;
|
||||
|
||||
public static final int TAG_JPEG_TABLES = 347;
|
||||
|
||||
public static final int TAG_CFA_REPEAT_PATTERN_DIM = 33421;
|
||||
|
||||
public static final int TAG_CFA_PATTERN_2 = 33422;
|
||||
|
||||
public static final int TAG_BATTERY_LEVEL = 33423;
|
||||
|
||||
public static final int TAG_IPTC_NAA = 33723;
|
||||
|
||||
public static final int TAG_INTER_COLOR_PROFILE = 34675;
|
||||
|
||||
public static final int TAG_SPECTRAL_SENSITIVITY = 34852;
|
||||
|
||||
public static final int TAG_OECF = 34856;
|
||||
|
||||
public static final int TAG_INTERLACE = 34857;
|
||||
|
||||
public static final int TAG_TIME_ZONE_OFFSET = 34858;
|
||||
|
||||
public static final int TAG_SELF_TIMER_MODE = 34859;
|
||||
|
||||
public static final int TAG_FLASH_ENERGY = 37387;
|
||||
|
||||
public static final int TAG_SPATIAL_FREQ_RESPONSE = 37388;
|
||||
|
||||
public static final int TAG_NOISE = 37389;
|
||||
|
||||
public static final int TAG_IMAGE_NUMBER = 37393;
|
||||
|
||||
public static final int TAG_SECURITY_CLASSIFICATION = 37394;
|
||||
|
||||
public static final int TAG_IMAGE_HISTORY = 37395;
|
||||
|
||||
public static final int TAG_SUBJECT_LOCATION = 37396;
|
||||
|
||||
public static final int TAG_EXPOSURE_INDEX_2 = 37397;
|
||||
|
||||
public static final int TAG_TIFF_EP_STANDARD_ID = 37398;
|
||||
|
||||
public static final int TAG_FLASH_ENERGY_2 = 41483;
|
||||
|
||||
public static final int TAG_SPATIAL_FREQ_RESPONSE_2 = 41484;
|
||||
|
||||
public static final int TAG_SUBJECT_LOCATION_2 = 41492;
|
||||
|
||||
public static final int TAG_MAKE = 271;
|
||||
|
||||
public static final int TAG_MODEL = 272;
|
||||
|
||||
public static final int TAG_ORIENTATION = 274;
|
||||
|
||||
public static final int TAG_X_RESOLUTION = 282;
|
||||
|
||||
public static final int TAG_Y_RESOLUTION = 283;
|
||||
|
||||
public static final int TAG_RESOLUTION_UNIT = 296;
|
||||
|
||||
public static final int TAG_THUMBNAIL_OFFSET = 513;
|
||||
|
||||
public static final int TAG_THUMBNAIL_LENGTH = 514;
|
||||
|
||||
public static final int TAG_YCBCR_POSITIONING = 531;
|
||||
|
||||
public static final int TAG_EXPOSURE_TIME = 33434;
|
||||
|
||||
public static final int TAG_FNUMBER = 33437;
|
||||
|
||||
public static final int TAG_EXPOSURE_PROGRAM = 34850;
|
||||
|
||||
public static final int TAG_ISO_EQUIVALENT = 34855;
|
||||
|
||||
public static final int TAG_EXIF_VERSION = 36864;
|
||||
|
||||
public static final int TAG_DATETIME_ORIGINAL = 36867;
|
||||
|
||||
public static final int TAG_DATETIME_DIGITIZED = 36868;
|
||||
|
||||
public static final int TAG_COMPONENTS_CONFIGURATION = 37121;
|
||||
|
||||
public static final int TAG_COMPRESSION_LEVEL = 37122;
|
||||
|
||||
public static final int TAG_SHUTTER_SPEED = 37377;
|
||||
|
||||
public static final int TAG_BRIGHTNESS_VALUE = 37379;
|
||||
|
||||
public static final int TAG_EXPOSURE_BIAS = 37380;
|
||||
|
||||
public static final int TAG_MAX_APERTURE = 37381;
|
||||
|
||||
public static final int TAG_SUBJECT_DISTANCE = 37382;
|
||||
|
||||
public static final int TAG_METERING_MODE = 37383;
|
||||
|
||||
public static final int TAG_LIGHT_SOURCE = 37384;
|
||||
|
||||
public static final int TAG_WHITE_BALANCE = 37384;
|
||||
|
||||
public static final int TAG_FLASH = 37385;
|
||||
|
||||
public static final int TAG_FOCAL_LENGTH = 37386;
|
||||
|
||||
public static final int TAG_USER_COMMENT = 37510;
|
||||
|
||||
public static final int TAG_SUBSECOND_TIME = 37520;
|
||||
|
||||
public static final int TAG_SUBSECOND_TIME_ORIGINAL = 37521;
|
||||
|
||||
public static final int TAG_SUBSECOND_TIME_DIGITIZED = 37522;
|
||||
|
||||
public static final int TAG_FLASHPIX_VERSION = 40960;
|
||||
|
||||
public static final int TAG_COLOR_SPACE = 40961;
|
||||
|
||||
public static final int TAG_EXIF_IMAGE_WIDTH = 40962;
|
||||
|
||||
public static final int TAG_EXIF_IMAGE_HEIGHT = 40963;
|
||||
|
||||
public static final int TAG_RELATED_SOUND_FILE = 40964;
|
||||
|
||||
public static final int TAG_FOCAL_PLANE_X_RES = 41486;
|
||||
|
||||
public static final int TAG_FOCAL_PLANE_Y_RES = 41487;
|
||||
|
||||
public static final int TAG_FOCAL_PLANE_UNIT = 41488;
|
||||
|
||||
public static final int TAG_EXPOSURE_INDEX = 41493;
|
||||
|
||||
public static final int TAG_SENSING_METHOD = 41495;
|
||||
|
||||
public static final int TAG_FILE_SOURCE = 41728;
|
||||
|
||||
public static final int TAG_SCENE_TYPE = 41729;
|
||||
|
||||
public static final int TAG_CFA_PATTERN = 41730;
|
||||
|
||||
public static final int TAG_THUMBNAIL_IMAGE_WIDTH = 256;
|
||||
|
||||
public static final int TAG_THUMBNAIL_IMAGE_HEIGHT = 257;
|
||||
|
||||
public static final int TAG_THUMBNAIL_DATA = 61441;
|
||||
|
||||
public static final int TAG_FILL_ORDER = 266;
|
||||
|
||||
public static final int TAG_DOCUMENT_NAME = 269;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public ExifDirectory() {
|
||||
setDescriptor(new ExifDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Exif";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
public byte[] getThumbnailData() throws MetadataException {
|
||||
return !containsThumbnail() ? null : getByteArray(61441);
|
||||
}
|
||||
|
||||
public void writeThumbnail(String paramString) throws MetadataException, IOException {
|
||||
byte[] arrayOfByte = getThumbnailData();
|
||||
if (arrayOfByte == null)
|
||||
throw new MetadataException("No thumbnail data exists.");
|
||||
FileOutputStream fileOutputStream = null;
|
||||
try {
|
||||
fileOutputStream = new FileOutputStream(paramString);
|
||||
fileOutputStream.write(arrayOfByte);
|
||||
} finally {
|
||||
if (fileOutputStream != null)
|
||||
fileOutputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsThumbnail() {
|
||||
return containsTag(61441);
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(266), "Fill Order");
|
||||
tagNameMap.put(new Integer(269), "Document Name");
|
||||
tagNameMap.put(new Integer(4096), "Related Image File Format");
|
||||
tagNameMap.put(new Integer(4097), "Related Image Width");
|
||||
tagNameMap.put(new Integer(4098), "Related Image Length");
|
||||
tagNameMap.put(new Integer(342), "Transfer Range");
|
||||
tagNameMap.put(new Integer(512), "JPEG Proc");
|
||||
tagNameMap.put(new Integer(34665), "Exif Offset");
|
||||
tagNameMap.put(new Integer(37122), "Compressed Bits Per Pixel");
|
||||
tagNameMap.put(new Integer(37500), "Maker Note");
|
||||
tagNameMap.put(new Integer(40965), "Interoperability Offset");
|
||||
tagNameMap.put(new Integer(254), "New Subfile Type");
|
||||
tagNameMap.put(new Integer(255), "Subfile Type");
|
||||
tagNameMap.put(new Integer(256), "Thumbnail Image Width");
|
||||
tagNameMap.put(new Integer(257), "Thumbnail Image Height");
|
||||
tagNameMap.put(new Integer(258), "Bits Per Sample");
|
||||
tagNameMap.put(new Integer(259), "Compression");
|
||||
tagNameMap.put(new Integer(262), "Photometric Interpretation");
|
||||
tagNameMap.put(new Integer(270), "Image Description");
|
||||
tagNameMap.put(new Integer(271), "Make");
|
||||
tagNameMap.put(new Integer(272), "Model");
|
||||
tagNameMap.put(new Integer(273), "Strip Offsets");
|
||||
tagNameMap.put(new Integer(274), "Orientation");
|
||||
tagNameMap.put(new Integer(277), "Samples Per Pixel");
|
||||
tagNameMap.put(new Integer(278), "Rows Per Strip");
|
||||
tagNameMap.put(new Integer(279), "Strip Byte Counts");
|
||||
tagNameMap.put(new Integer(282), "X Resolution");
|
||||
tagNameMap.put(new Integer(283), "Y Resolution");
|
||||
tagNameMap.put(new Integer(284), "Planar Configuration");
|
||||
tagNameMap.put(new Integer(296), "Resolution Unit");
|
||||
tagNameMap.put(new Integer(301), "Transfer Function");
|
||||
tagNameMap.put(new Integer(305), "Software");
|
||||
tagNameMap.put(new Integer(306), "Date/Time");
|
||||
tagNameMap.put(new Integer(315), "Artist");
|
||||
tagNameMap.put(new Integer(317), "Predictor");
|
||||
tagNameMap.put(new Integer(318), "White Point");
|
||||
tagNameMap.put(new Integer(319), "Primary Chromaticities");
|
||||
tagNameMap.put(new Integer(322), "Tile Width");
|
||||
tagNameMap.put(new Integer(323), "Tile Length");
|
||||
tagNameMap.put(new Integer(324), "Tile Offsets");
|
||||
tagNameMap.put(new Integer(325), "Tile Byte Counts");
|
||||
tagNameMap.put(new Integer(330), "Sub IFDs");
|
||||
tagNameMap.put(new Integer(347), "JPEG Tables");
|
||||
tagNameMap.put(new Integer(513), "Thumbnail Offset");
|
||||
tagNameMap.put(new Integer(514), "Thumbnail Length");
|
||||
tagNameMap.put(new Integer(61441), "Thumbnail Data");
|
||||
tagNameMap.put(new Integer(529), "YCbCr Coefficients");
|
||||
tagNameMap.put(new Integer(530), "YCbCr Sub-Sampling");
|
||||
tagNameMap.put(new Integer(531), "YCbCr Positioning");
|
||||
tagNameMap.put(new Integer(532), "Reference Black/White");
|
||||
tagNameMap.put(new Integer(33421), "CFA Repeat Pattern Dim");
|
||||
tagNameMap.put(new Integer(33422), "CFA Pattern");
|
||||
tagNameMap.put(new Integer(33423), "Battery Level");
|
||||
tagNameMap.put(new Integer(33432), "Copyright");
|
||||
tagNameMap.put(new Integer(33434), "Exposure Time");
|
||||
tagNameMap.put(new Integer(33437), "F-Number");
|
||||
tagNameMap.put(new Integer(33723), "IPTC/NAA");
|
||||
tagNameMap.put(new Integer(34675), "Inter Color Profile");
|
||||
tagNameMap.put(new Integer(34850), "Exposure Program");
|
||||
tagNameMap.put(new Integer(34852), "Spectral Sensitivity");
|
||||
tagNameMap.put(new Integer(34853), "GPS Info");
|
||||
tagNameMap.put(new Integer(34855), "ISO Speed Ratings");
|
||||
tagNameMap.put(new Integer(34856), "OECF");
|
||||
tagNameMap.put(new Integer(34857), "Interlace");
|
||||
tagNameMap.put(new Integer(34858), "Time Zone Offset");
|
||||
tagNameMap.put(new Integer(34859), "Self Timer Mode");
|
||||
tagNameMap.put(new Integer(36864), "Exif Version");
|
||||
tagNameMap.put(new Integer(36867), "Date/Time Original");
|
||||
tagNameMap.put(new Integer(36868), "Date/Time Digitized");
|
||||
tagNameMap.put(new Integer(37121), "Components Configuration");
|
||||
tagNameMap.put(new Integer(37377), "Shutter Speed Value");
|
||||
tagNameMap.put(new Integer(37378), "Aperture Value");
|
||||
tagNameMap.put(new Integer(37379), "Brightness Value");
|
||||
tagNameMap.put(new Integer(37380), "Exposure Bias Value");
|
||||
tagNameMap.put(new Integer(37381), "Max Aperture Value");
|
||||
tagNameMap.put(new Integer(37382), "Subject Distance");
|
||||
tagNameMap.put(new Integer(37383), "Metering Mode");
|
||||
tagNameMap.put(new Integer(37384), "Light Source");
|
||||
tagNameMap.put(new Integer(37385), "Flash");
|
||||
tagNameMap.put(new Integer(37386), "Focal Length");
|
||||
tagNameMap.put(new Integer(37387), "Flash Energy");
|
||||
tagNameMap.put(new Integer(37388), "Spatial Frequency Response");
|
||||
tagNameMap.put(new Integer(37389), "Noise");
|
||||
tagNameMap.put(new Integer(37393), "Image Number");
|
||||
tagNameMap.put(new Integer(37394), "Security Classification");
|
||||
tagNameMap.put(new Integer(37395), "Image History");
|
||||
tagNameMap.put(new Integer(37396), "Subject Location");
|
||||
tagNameMap.put(new Integer(41493), "Exposure Index");
|
||||
tagNameMap.put(new Integer(37398), "TIFF/EP Standard ID");
|
||||
tagNameMap.put(new Integer(37510), "User Comment");
|
||||
tagNameMap.put(new Integer(37520), "Sub-Sec Time");
|
||||
tagNameMap.put(new Integer(37521), "Sub-Sec Time Original");
|
||||
tagNameMap.put(new Integer(37522), "Sub-Sec Time Digitized");
|
||||
tagNameMap.put(new Integer(40960), "FlashPix Version");
|
||||
tagNameMap.put(new Integer(40961), "Color Space");
|
||||
tagNameMap.put(new Integer(40962), "Exif Image Width");
|
||||
tagNameMap.put(new Integer(40963), "Exif Image Height");
|
||||
tagNameMap.put(new Integer(40964), "Related Sound File");
|
||||
tagNameMap.put(new Integer(41483), "Flash Energy");
|
||||
tagNameMap.put(new Integer(41484), "Spatial Frequency Response");
|
||||
tagNameMap.put(new Integer(41486), "Focal Plane X Resolution");
|
||||
tagNameMap.put(new Integer(41487), "Focal Plane Y Resolution");
|
||||
tagNameMap.put(new Integer(41488), "Focal Plane Resolution Unit");
|
||||
tagNameMap.put(new Integer(41492), "Subject Location");
|
||||
tagNameMap.put(new Integer(37397), "Exposure Index");
|
||||
tagNameMap.put(new Integer(41495), "Sensing Method");
|
||||
tagNameMap.put(new Integer(41728), "File Source");
|
||||
tagNameMap.put(new Integer(41729), "Scene Type");
|
||||
tagNameMap.put(new Integer(41730), "CFA Pattern");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class ExifInteropDescriptor extends TagDescriptor {
|
||||
public ExifInteropDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 1:
|
||||
return getInteropIndexDescription();
|
||||
case 2:
|
||||
return getInteropVersionDescription();
|
||||
}
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
|
||||
private String getInteropVersionDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(2))
|
||||
return null;
|
||||
int[] arrayOfInt = this._directory.getIntArray(2);
|
||||
return ExifDescriptor.convertBytesToVersionString(arrayOfInt);
|
||||
}
|
||||
|
||||
private String getInteropIndexDescription() {
|
||||
if (!this._directory.containsTag(1))
|
||||
return null;
|
||||
String str = this._directory.getString(1).trim();
|
||||
return "R98".equalsIgnoreCase(str) ? "Recommended Exif Interoperability Rules (ExifR98)" : ("Unknown (" + str + ")");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ExifInteropDirectory extends Directory {
|
||||
public static final int TAG_INTEROP_INDEX = 1;
|
||||
|
||||
public static final int TAG_INTEROP_VERSION = 2;
|
||||
|
||||
public static final int TAG_RELATED_IMAGE_FILE_FORMAT = 4096;
|
||||
|
||||
public static final int TAG_RELATED_IMAGE_WIDTH = 4097;
|
||||
|
||||
public static final int TAG_RELATED_IMAGE_LENGTH = 4098;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public ExifInteropDirectory() {
|
||||
setDescriptor(new ExifInteropDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Interoperability";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(1), "Interoperability Index");
|
||||
tagNameMap.put(new Integer(2), "Interoperability Version");
|
||||
tagNameMap.put(new Integer(4096), "Related Image File Format");
|
||||
tagNameMap.put(new Integer(4097), "Related Image Width");
|
||||
tagNameMap.put(new Integer(4098), "Related Image Length");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.MetadataException;
|
||||
|
||||
public class ExifProcessingException extends MetadataException {
|
||||
public ExifProcessingException(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public ExifProcessingException(String paramString, Throwable paramThrowable) {
|
||||
super(paramString, paramThrowable);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,351 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegProcessingException;
|
||||
import com.drew.imaging.jpeg.JpegSegmentReader;
|
||||
import com.drew.lang.Rational;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.MetadataReader;
|
||||
import java.io.File;
|
||||
|
||||
public class ExifReader implements MetadataReader {
|
||||
private final byte[] _data;
|
||||
|
||||
private boolean _isMotorollaByteOrder;
|
||||
|
||||
private Metadata _metadata;
|
||||
|
||||
static final int[] BYTES_PER_FORMAT = new int[] {
|
||||
0, 1, 1, 2, 4, 8, 1, 1, 2, 4,
|
||||
8, 4, 8 };
|
||||
|
||||
private static final int MAX_FORMAT_CODE = 12;
|
||||
|
||||
private static final int FMT_BYTE = 1;
|
||||
|
||||
private static final int FMT_STRING = 2;
|
||||
|
||||
private static final int FMT_USHORT = 3;
|
||||
|
||||
private static final int FMT_ULONG = 4;
|
||||
|
||||
private static final int FMT_URATIONAL = 5;
|
||||
|
||||
private static final int FMT_SBYTE = 6;
|
||||
|
||||
private static final int FMT_UNDEFINED = 7;
|
||||
|
||||
private static final int FMT_SSHORT = 8;
|
||||
|
||||
private static final int FMT_SLONG = 9;
|
||||
|
||||
private static final int FMT_SRATIONAL = 10;
|
||||
|
||||
private static final int FMT_SINGLE = 11;
|
||||
|
||||
private static final int FMT_DOUBLE = 12;
|
||||
|
||||
public static final int TAG_EXIF_OFFSET = 34665;
|
||||
|
||||
public static final int TAG_INTEROP_OFFSET = 40965;
|
||||
|
||||
public static final int TAG_GPS_INFO_OFFSET = 34853;
|
||||
|
||||
public static final int TAG_MAKER_NOTE = 37500;
|
||||
|
||||
public static int TIFF_HEADER_START_OFFSET = 6;
|
||||
|
||||
public ExifReader(File paramFile) throws JpegProcessingException {
|
||||
this(new JpegSegmentReader(paramFile).readSegment((byte)-31));
|
||||
}
|
||||
|
||||
public ExifReader(byte[] paramArrayOfbyte) {
|
||||
this._data = paramArrayOfbyte;
|
||||
}
|
||||
|
||||
public Metadata extract() {
|
||||
return extract(new Metadata());
|
||||
}
|
||||
|
||||
public Metadata extract(Metadata paramMetadata) {
|
||||
this._metadata = paramMetadata;
|
||||
if (this._data == null)
|
||||
return this._metadata;
|
||||
Directory directory = this._metadata.getDirectory(ExifDirectory.class);
|
||||
if (this._data.length <= 14) {
|
||||
directory.addError("Exif data segment must contain at least 14 bytes");
|
||||
return this._metadata;
|
||||
}
|
||||
if (!"Exif\000\000".equals(new String(this._data, 0, 6))) {
|
||||
directory.addError("Exif data segment doesn't begin with 'Exif'");
|
||||
return this._metadata;
|
||||
}
|
||||
String str = new String(this._data, 6, 2);
|
||||
if (!setByteOrder(str)) {
|
||||
directory.addError("Unclear distinction between Motorola/Intel byte ordering");
|
||||
return this._metadata;
|
||||
}
|
||||
if (get16Bits(8) != 42) {
|
||||
directory.addError("Invalid Exif start - should have 0x2A at offset 8 in Exif header");
|
||||
return this._metadata;
|
||||
}
|
||||
int i = get32Bits(10) + TIFF_HEADER_START_OFFSET;
|
||||
if (i >= this._data.length - 1) {
|
||||
directory.addError("First exif directory offset is beyond end of Exif data segment");
|
||||
i = 14;
|
||||
}
|
||||
processDirectory(directory, i);
|
||||
extractThumbnail(directory);
|
||||
return this._metadata;
|
||||
}
|
||||
|
||||
private void extractThumbnail(Directory paramDirectory) {
|
||||
if (!(paramDirectory instanceof ExifDirectory))
|
||||
return;
|
||||
if (!paramDirectory.containsTag(514) || !paramDirectory.containsTag(513))
|
||||
return;
|
||||
try {
|
||||
int i = paramDirectory.getInt(513);
|
||||
int j = paramDirectory.getInt(514);
|
||||
byte[] arrayOfByte = new byte[j];
|
||||
for (int k = 0; k < arrayOfByte.length; k++)
|
||||
arrayOfByte[k] = this._data[TIFF_HEADER_START_OFFSET + i + k];
|
||||
paramDirectory.setByteArray(61441, arrayOfByte);
|
||||
} catch (Throwable e) {
|
||||
paramDirectory.addError("Unable to extract thumbnail: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setByteOrder(String paramString) {
|
||||
if ("MM".equals(paramString)) {
|
||||
this._isMotorollaByteOrder = true;
|
||||
} else if ("II".equals(paramString)) {
|
||||
this._isMotorollaByteOrder = false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void processDirectory(Directory paramDirectory, int paramInt) {
|
||||
if (paramInt >= this._data.length || paramInt < 0) {
|
||||
paramDirectory.addError("Ignored directory marked to start outside data segement");
|
||||
return;
|
||||
}
|
||||
int i = get16Bits(paramInt);
|
||||
if (!isDirectoryLengthValid(paramInt)) {
|
||||
paramDirectory.addError("Illegally sized directory");
|
||||
return;
|
||||
}
|
||||
System.out.println("dirTagCount = " + i);
|
||||
int j;
|
||||
for (j = 0; j < i; j++) {
|
||||
int k = calculateDirectoryEntryOffset(paramInt, j);
|
||||
int m = get16Bits(k);
|
||||
int n = get16Bits(k + 2);
|
||||
if (n < 0 || n > 12) {
|
||||
paramDirectory.addError("Invalid format code: " + n);
|
||||
} else {
|
||||
int i1 = get32Bits(k + 4);
|
||||
int i2 = i1 * BYTES_PER_FORMAT[n];
|
||||
int i3 = calculateTagValueOffset(i2, k);
|
||||
if (i3 < 0) {
|
||||
paramDirectory.addError("Illegal pointer offset value in EXIF");
|
||||
} else {
|
||||
int i4 = TIFF_HEADER_START_OFFSET + get32Bits(i3);
|
||||
switch (m) {
|
||||
case 34665:
|
||||
processDirectory(this._metadata.getDirectory(ExifDirectory.class), i4);
|
||||
break;
|
||||
case 40965:
|
||||
processDirectory(this._metadata.getDirectory(ExifInteropDirectory.class), i4);
|
||||
break;
|
||||
case 34853:
|
||||
processDirectory(this._metadata.getDirectory(GpsDirectory.class), i4);
|
||||
break;
|
||||
case 37500:
|
||||
processMakerNote(i3);
|
||||
break;
|
||||
default:
|
||||
processTag(paramDirectory, m, i3, i1, n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
j = get32Bits(paramInt + 2 + 12 * i);
|
||||
if (j != 0) {
|
||||
j += TIFF_HEADER_START_OFFSET;
|
||||
if (j >= this._data.length)
|
||||
return;
|
||||
processDirectory(paramDirectory, j);
|
||||
}
|
||||
}
|
||||
|
||||
private void processMakerNote(int paramInt) {
|
||||
Directory directory = this._metadata.getDirectory(ExifDirectory.class);
|
||||
if (directory == null)
|
||||
return;
|
||||
String str = directory.getString(271);
|
||||
if ("OLYMP".equals(new String(this._data, paramInt, 5))) {
|
||||
processDirectory(this._metadata.getDirectory(OlympusMakernoteDirectory.class), paramInt + 8);
|
||||
} else if (str != null && str.trim().toUpperCase().startsWith("NIKON")) {
|
||||
if ("Nikon".equals(new String(this._data, paramInt, 5))) {
|
||||
if (this._data[paramInt + 6] == 1) {
|
||||
processDirectory(this._metadata.getDirectory(NikonType1MakernoteDirectory.class), paramInt + 8);
|
||||
} else if (this._data[paramInt + 6] == 2) {
|
||||
int i = TIFF_HEADER_START_OFFSET;
|
||||
TIFF_HEADER_START_OFFSET = paramInt + 10;
|
||||
processDirectory(this._metadata.getDirectory(NikonType3MakernoteDirectory.class), paramInt + 18);
|
||||
TIFF_HEADER_START_OFFSET = i;
|
||||
} else {
|
||||
directory.addError("Unsupported makernote data ignored.");
|
||||
}
|
||||
} else {
|
||||
processDirectory(this._metadata.getDirectory(NikonType2MakernoteDirectory.class), paramInt);
|
||||
}
|
||||
} else if ("Canon".equalsIgnoreCase(str)) {
|
||||
processDirectory(this._metadata.getDirectory(CanonMakernoteDirectory.class), paramInt);
|
||||
} else if ("Casio".equalsIgnoreCase(str)) {
|
||||
processDirectory(this._metadata.getDirectory(CasioMakernoteDirectory.class), paramInt);
|
||||
} else if ("FUJIFILM".equals(new String(this._data, paramInt, 8)) || "Fujifilm".equalsIgnoreCase(str)) {
|
||||
boolean bool = this._isMotorollaByteOrder;
|
||||
this._isMotorollaByteOrder = false;
|
||||
int i = paramInt + get32Bits(paramInt + 8);
|
||||
processDirectory(this._metadata.getDirectory(FujiFilmMakernoteDirectory.class), i);
|
||||
this._isMotorollaByteOrder = bool;
|
||||
} else {
|
||||
directory.addError("Unsupported makernote data ignored.");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDirectoryLengthValid(int paramInt) {
|
||||
int i = get16Bits(paramInt);
|
||||
int j = 2 + 12 * i + 4;
|
||||
return !(j + paramInt + TIFF_HEADER_START_OFFSET >= this._data.length);
|
||||
}
|
||||
|
||||
private void processTag(Directory paramDirectory, int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
|
||||
String str;
|
||||
Rational[] arrayOfRational;
|
||||
int[] arrayOfInt;
|
||||
int i;
|
||||
switch (paramInt4) {
|
||||
case 2:
|
||||
case 7:
|
||||
if (paramInt1 == 37510) {
|
||||
str = readCommentString(paramInt2, paramInt3, paramInt4);
|
||||
} else {
|
||||
str = readString(paramInt2, paramInt3);
|
||||
}
|
||||
paramDirectory.setString(paramInt1, str);
|
||||
break;
|
||||
case 5:
|
||||
case 10:
|
||||
if (paramInt3 == 1) {
|
||||
Rational rational = new Rational(get32Bits(paramInt2), get32Bits(paramInt2 + 4));
|
||||
paramDirectory.setRational(paramInt1, rational);
|
||||
break;
|
||||
}
|
||||
arrayOfRational = new Rational[paramInt3];
|
||||
for (i = 0; i < paramInt3; i++)
|
||||
arrayOfRational[i] = new Rational(get32Bits(paramInt2 + 8 * i), get32Bits(paramInt2 + 4 + 8 * i));
|
||||
paramDirectory.setRationalArray(paramInt1, arrayOfRational);
|
||||
break;
|
||||
case 1:
|
||||
case 6:
|
||||
if (paramInt3 == 1) {
|
||||
byte b = this._data[paramInt2];
|
||||
paramDirectory.setInt(paramInt1, b);
|
||||
break;
|
||||
}
|
||||
arrayOfInt = new int[paramInt3];
|
||||
for (i = 0; i < paramInt3; i++)
|
||||
arrayOfInt[i] = this._data[paramInt2 + i];
|
||||
paramDirectory.setIntArray(paramInt1, arrayOfInt);
|
||||
break;
|
||||
case 11:
|
||||
case 12:
|
||||
if (paramInt3 == 1) {
|
||||
byte b = this._data[paramInt2];
|
||||
paramDirectory.setInt(paramInt1, b);
|
||||
break;
|
||||
}
|
||||
arrayOfInt = new int[paramInt3];
|
||||
for (i = 0; i < paramInt3; i++)
|
||||
arrayOfInt[i] = this._data[paramInt2 + i];
|
||||
paramDirectory.setIntArray(paramInt1, arrayOfInt);
|
||||
break;
|
||||
case 3:
|
||||
case 8:
|
||||
if (paramInt3 == 1) {
|
||||
int j = get16Bits(paramInt2);
|
||||
paramDirectory.setInt(paramInt1, j);
|
||||
break;
|
||||
}
|
||||
arrayOfInt = new int[paramInt3];
|
||||
for (i = 0; i < paramInt3; i++)
|
||||
arrayOfInt[i] = get16Bits(paramInt2 + i * 2);
|
||||
paramDirectory.setIntArray(paramInt1, arrayOfInt);
|
||||
break;
|
||||
case 4:
|
||||
case 9:
|
||||
if (paramInt3 == 1) {
|
||||
int j = get32Bits(paramInt2);
|
||||
paramDirectory.setInt(paramInt1, j);
|
||||
break;
|
||||
}
|
||||
arrayOfInt = new int[paramInt3];
|
||||
for (i = 0; i < paramInt3; i++)
|
||||
arrayOfInt[i] = get32Bits(paramInt2 + i * 4);
|
||||
paramDirectory.setIntArray(paramInt1, arrayOfInt);
|
||||
break;
|
||||
default:
|
||||
paramDirectory.addError("unknown format code " + paramInt4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private int calculateTagValueOffset(int paramInt1, int paramInt2) {
|
||||
if (paramInt1 > 4) {
|
||||
int i = get32Bits(paramInt2 + 8);
|
||||
return (i + paramInt1 > this._data.length) ? -1 : (TIFF_HEADER_START_OFFSET + i);
|
||||
}
|
||||
return paramInt2 + 8;
|
||||
}
|
||||
|
||||
private String readString(int paramInt1, int paramInt2) {
|
||||
int i;
|
||||
for (i = 0; paramInt1 + i < this._data.length && this._data[paramInt1 + i] != 0 && i < paramInt2; i++);
|
||||
return new String(this._data, paramInt1, i);
|
||||
}
|
||||
|
||||
private String readCommentString(int paramInt1, int paramInt2, int paramInt3) {
|
||||
int i = paramInt2 * BYTES_PER_FORMAT[paramInt3];
|
||||
for (int j = i - 1; j >= 0 && this._data[paramInt1 + j] == 32; j--)
|
||||
this._data[paramInt1 + j] = 0;
|
||||
if ("ASCII".equals(new String(this._data, paramInt1, 5)))
|
||||
for (int k = 5; k < 10; k++) {
|
||||
byte b = this._data[paramInt1 + k];
|
||||
if (b != 0 && b != 32)
|
||||
return readString(paramInt1 + k, 1999);
|
||||
}
|
||||
return readString(paramInt1, 1999);
|
||||
}
|
||||
|
||||
private int calculateDirectoryEntryOffset(int paramInt1, int paramInt2) {
|
||||
return paramInt1 + 2 + 12 * paramInt2;
|
||||
}
|
||||
|
||||
private int get16Bits(int paramInt) {
|
||||
if (paramInt < 0 || paramInt >= this._data.length)
|
||||
throw new ArrayIndexOutOfBoundsException("attempt to read data outside of exif segment (index " + paramInt + " where max index is " + (this._data.length - 1) + ")");
|
||||
return this._isMotorollaByteOrder ? (this._data[paramInt] << 8 & 0xFF00 | this._data[paramInt + 1] & 0xFF) : (this._data[paramInt + 1] << 8 & 0xFF00 | this._data[paramInt] & 0xFF);
|
||||
}
|
||||
|
||||
private int get32Bits(int paramInt) {
|
||||
if (paramInt < 0 || paramInt >= this._data.length)
|
||||
throw new ArrayIndexOutOfBoundsException("attempt to read data outside of exif segment (index " + paramInt + " where max index is " + (this._data.length - 1) + ")");
|
||||
return this._isMotorollaByteOrder ? (this._data[paramInt] << 24 & 0xFF000000 | this._data[paramInt + 1] << 16 & 0xFF0000 | this._data[paramInt + 2] << 8 & 0xFF00 | this._data[paramInt + 3] & 0xFF) : (this._data[paramInt + 3] << 24 & 0xFF000000 | this._data[paramInt + 2] << 16 & 0xFF0000 | this._data[paramInt + 1] << 8 & 0xFF00 | this._data[paramInt] & 0xFF);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class FujiFilmMakernoteDirectory extends Directory {
|
||||
public static final int TAG_FUJIFILM_MAKERNOTE_VERSION = 0;
|
||||
|
||||
public static final int TAG_FUJIFILM_QUALITY = 4096;
|
||||
|
||||
public static final int TAG_FUJIFILM_SHARPNESS = 4097;
|
||||
|
||||
public static final int TAG_FUJIFILM_WHITE_BALANCE = 4098;
|
||||
|
||||
public static final int TAG_FUJIFILM_COLOR = 4099;
|
||||
|
||||
public static final int TAG_FUJIFILM_TONE = 4100;
|
||||
|
||||
public static final int TAG_FUJIFILM_FLASH_MODE = 4112;
|
||||
|
||||
public static final int TAG_FUJIFILM_FLASH_STRENGTH = 4113;
|
||||
|
||||
public static final int TAG_FUJIFILM_MACRO = 4128;
|
||||
|
||||
public static final int TAG_FUJIFILM_FOCUS_MODE = 4129;
|
||||
|
||||
public static final int TAG_FUJIFILM_SLOW_SYNCHRO = 4144;
|
||||
|
||||
public static final int TAG_FUJIFILM_PICTURE_MODE = 4145;
|
||||
|
||||
public static final int TAG_FUJIFILM_UNKNOWN_1 = 4146;
|
||||
|
||||
public static final int TAG_FUJIFILM_CONTINUOUS_TAKING_OR_AUTO_BRACKETTING = 4352;
|
||||
|
||||
public static final int TAG_FUJIFILM_UNKNOWN_2 = 4608;
|
||||
|
||||
public static final int TAG_FUJIFILM_BLUR_WARNING = 4864;
|
||||
|
||||
public static final int TAG_FUJIFILM_FOCUS_WARNING = 4865;
|
||||
|
||||
public static final int TAG_FUJIFILM_AE_WARNING = 4866;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public FujiFilmMakernoteDirectory() {
|
||||
setDescriptor(new FujifilmMakernoteDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "FujiFilm Makernote";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(4866), "AE Warning");
|
||||
tagNameMap.put(new Integer(4864), "Blur Warning");
|
||||
tagNameMap.put(new Integer(4099), "Color");
|
||||
tagNameMap.put(new Integer(4352), "Continuous Taking Or Auto Bracketting");
|
||||
tagNameMap.put(new Integer(4112), "Flash Mode");
|
||||
tagNameMap.put(new Integer(4113), "Flash Strength");
|
||||
tagNameMap.put(new Integer(4129), "Focus Mode");
|
||||
tagNameMap.put(new Integer(4865), "Focus Warning");
|
||||
tagNameMap.put(new Integer(4128), "Macro");
|
||||
tagNameMap.put(new Integer(0), "Makernote Version");
|
||||
tagNameMap.put(new Integer(4145), "Picture Mode");
|
||||
tagNameMap.put(new Integer(4096), "Quality");
|
||||
tagNameMap.put(new Integer(4097), "Sharpness");
|
||||
tagNameMap.put(new Integer(4144), "Slow Synchro");
|
||||
tagNameMap.put(new Integer(4100), "Tone");
|
||||
tagNameMap.put(new Integer(4146), "Makernote Unknown 1");
|
||||
tagNameMap.put(new Integer(4608), "Makernote Unknown 2");
|
||||
tagNameMap.put(new Integer(4098), "White Balance");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,260 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.lang.Rational;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class FujifilmMakernoteDescriptor extends TagDescriptor {
|
||||
public FujifilmMakernoteDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 4097:
|
||||
return getSharpnessDescription();
|
||||
case 4098:
|
||||
return getWhiteBalanceDescription();
|
||||
case 4099:
|
||||
return getColorDescription();
|
||||
case 4100:
|
||||
return getToneDescription();
|
||||
case 4112:
|
||||
return getFlashModeDescription();
|
||||
case 4113:
|
||||
return getFlashStrengthDescription();
|
||||
case 4128:
|
||||
return getMacroDescription();
|
||||
case 4129:
|
||||
return getFocusModeDescription();
|
||||
case 4144:
|
||||
return getSlowSyncDescription();
|
||||
case 4145:
|
||||
return getPictureModeDescription();
|
||||
case 4352:
|
||||
return getContinuousTakingOrAutoBrackettingDescription();
|
||||
case 4864:
|
||||
return getBlurWarningDescription();
|
||||
case 4865:
|
||||
return getFocusWarningDescription();
|
||||
case 4866:
|
||||
return getAutoExposureWarningDescription();
|
||||
}
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
|
||||
private String getAutoExposureWarningDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4866))
|
||||
return null;
|
||||
int i = this._directory.getInt(4866);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "AE good";
|
||||
case 1:
|
||||
return "Over exposed (>1/1000s @ F11)";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getFocusWarningDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4865))
|
||||
return null;
|
||||
int i = this._directory.getInt(4865);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Auto focus good";
|
||||
case 1:
|
||||
return "Out of focus";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getBlurWarningDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4864))
|
||||
return null;
|
||||
int i = this._directory.getInt(4864);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "No blur warning";
|
||||
case 1:
|
||||
return "Blur warning";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getContinuousTakingOrAutoBrackettingDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4352))
|
||||
return null;
|
||||
int i = this._directory.getInt(4352);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Off";
|
||||
case 1:
|
||||
return "On";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getPictureModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4145))
|
||||
return null;
|
||||
int i = this._directory.getInt(4145);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Auto";
|
||||
case 1:
|
||||
return "Portrait scene";
|
||||
case 2:
|
||||
return "Landscape scene";
|
||||
case 4:
|
||||
return "Sports scene";
|
||||
case 5:
|
||||
return "Night scene";
|
||||
case 6:
|
||||
return "Program AE";
|
||||
case 256:
|
||||
return "Aperture priority AE";
|
||||
case 512:
|
||||
return "Shutter priority AE";
|
||||
case 768:
|
||||
return "Manual exposure";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getSlowSyncDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4144))
|
||||
return null;
|
||||
int i = this._directory.getInt(4144);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Off";
|
||||
case 1:
|
||||
return "On";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getFocusModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4129))
|
||||
return null;
|
||||
int i = this._directory.getInt(4129);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Auto focus";
|
||||
case 1:
|
||||
return "Manual focus";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getMacroDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4128))
|
||||
return null;
|
||||
int i = this._directory.getInt(4128);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Off";
|
||||
case 1:
|
||||
return "On";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getFlashStrengthDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4113))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(4113);
|
||||
return rational.toSimpleString(false) + " eV (Apex)";
|
||||
}
|
||||
|
||||
private String getFlashModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4112))
|
||||
return null;
|
||||
int i = this._directory.getInt(4112);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Auto";
|
||||
case 1:
|
||||
return "On";
|
||||
case 2:
|
||||
return "Off";
|
||||
case 3:
|
||||
return "Red-eye reduction";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getToneDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4100))
|
||||
return null;
|
||||
int i = this._directory.getInt(4100);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Normal (STD)";
|
||||
case 256:
|
||||
return "High (HARD)";
|
||||
case 512:
|
||||
return "Low (ORG)";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getColorDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4099))
|
||||
return null;
|
||||
int i = this._directory.getInt(4099);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Normal (STD)";
|
||||
case 256:
|
||||
return "High";
|
||||
case 512:
|
||||
return "Low (ORG)";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getWhiteBalanceDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4098))
|
||||
return null;
|
||||
int i = this._directory.getInt(4098);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Auto";
|
||||
case 256:
|
||||
return "Daylight";
|
||||
case 512:
|
||||
return "Cloudy";
|
||||
case 768:
|
||||
return "DaylightColor-fluorescence";
|
||||
case 769:
|
||||
return "DaywhiteColor-fluorescence";
|
||||
case 770:
|
||||
return "White-fluorescence";
|
||||
case 1024:
|
||||
return "Incandenscense";
|
||||
case 3840:
|
||||
return "Custom white balance";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getSharpnessDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4097))
|
||||
return null;
|
||||
int i = this._directory.getInt(4097);
|
||||
switch (i) {
|
||||
case 1:
|
||||
case 2:
|
||||
return "Soft";
|
||||
case 3:
|
||||
return "Normal";
|
||||
case 4:
|
||||
case 5:
|
||||
return "Hard";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.lang.Rational;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class GpsDescriptor extends TagDescriptor {
|
||||
public GpsDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 6:
|
||||
return getGpsAltitudeDescription();
|
||||
case 5:
|
||||
return getGpsAltitudeRefDescription();
|
||||
case 9:
|
||||
return getGpsStatusDescription();
|
||||
case 10:
|
||||
return getGpsMeasureModeDescription();
|
||||
case 12:
|
||||
return getGpsSpeedRefDescription();
|
||||
case 14:
|
||||
case 16:
|
||||
case 23:
|
||||
return getGpsDirectionReferenceDescription(paramInt);
|
||||
case 15:
|
||||
case 17:
|
||||
case 24:
|
||||
return getGpsDirectionDescription(paramInt);
|
||||
case 25:
|
||||
return getGpsDestinationReferenceDescription();
|
||||
case 7:
|
||||
return getGpsTimeStampDescription();
|
||||
case 4:
|
||||
return getGpsLongitudeDescription();
|
||||
case 2:
|
||||
return getGpsLatitudeDescription();
|
||||
}
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
|
||||
private String getGpsLatitudeDescription() throws MetadataException {
|
||||
return !this._directory.containsTag(2) ? null : getHoursMinutesSecondsDescription(2);
|
||||
}
|
||||
|
||||
private String getGpsLongitudeDescription() throws MetadataException {
|
||||
return !this._directory.containsTag(4) ? null : getHoursMinutesSecondsDescription(4);
|
||||
}
|
||||
|
||||
private String getHoursMinutesSecondsDescription(int paramInt) throws MetadataException {
|
||||
Rational[] arrayOfRational = this._directory.getRationalArray(paramInt);
|
||||
int i = arrayOfRational[0].intValue();
|
||||
float f1 = arrayOfRational[1].floatValue();
|
||||
float f2 = arrayOfRational[2].floatValue();
|
||||
f2 += f1 % 1.0F * 60.0F;
|
||||
return String.valueOf(i) + "\"" + String.valueOf((int)f1) + "'" + String.valueOf(f2);
|
||||
}
|
||||
|
||||
private String getGpsTimeStampDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(7))
|
||||
return null;
|
||||
int[] arrayOfInt = this._directory.getIntArray(7);
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(arrayOfInt[0]);
|
||||
stringBuffer.append(":");
|
||||
stringBuffer.append(arrayOfInt[1]);
|
||||
stringBuffer.append(":");
|
||||
stringBuffer.append(arrayOfInt[2]);
|
||||
stringBuffer.append(" UTC");
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
private String getGpsDestinationReferenceDescription() {
|
||||
if (!this._directory.containsTag(25))
|
||||
return null;
|
||||
String str = this._directory.getString(25).trim();
|
||||
return "K".equalsIgnoreCase(str) ? "kilometers" : ("M".equalsIgnoreCase(str) ? "miles" : ("N".equalsIgnoreCase(str) ? "knots" : ("Unknown (" + str + ")")));
|
||||
}
|
||||
|
||||
private String getGpsDirectionDescription(int paramInt) {
|
||||
if (!this._directory.containsTag(paramInt))
|
||||
return null;
|
||||
String str = this._directory.getString(paramInt).trim();
|
||||
return str + " degrees";
|
||||
}
|
||||
|
||||
private String getGpsDirectionReferenceDescription(int paramInt) {
|
||||
if (!this._directory.containsTag(paramInt))
|
||||
return null;
|
||||
String str = this._directory.getString(paramInt).trim();
|
||||
return "T".equalsIgnoreCase(str) ? "True direction" : ("M".equalsIgnoreCase(str) ? "Magnetic direction" : ("Unknown (" + str + ")"));
|
||||
}
|
||||
|
||||
private String getGpsSpeedRefDescription() {
|
||||
if (!this._directory.containsTag(12))
|
||||
return null;
|
||||
String str = this._directory.getString(12).trim();
|
||||
return "K".equalsIgnoreCase(str) ? "kph" : ("M".equalsIgnoreCase(str) ? "mph" : ("N".equalsIgnoreCase(str) ? "knots" : ("Unknown (" + str + ")")));
|
||||
}
|
||||
|
||||
private String getGpsMeasureModeDescription() {
|
||||
if (!this._directory.containsTag(10))
|
||||
return null;
|
||||
String str = this._directory.getString(10).trim();
|
||||
return "2".equalsIgnoreCase(str) ? "2-dimensional measurement" : ("3".equalsIgnoreCase(str) ? "3-dimensional measurement" : ("Unknown (" + str + ")"));
|
||||
}
|
||||
|
||||
private String getGpsStatusDescription() {
|
||||
if (!this._directory.containsTag(9))
|
||||
return null;
|
||||
String str = this._directory.getString(9).trim();
|
||||
return "A".equalsIgnoreCase(str) ? "Measurement in progess" : ("V".equalsIgnoreCase(str) ? "Measurement Interoperability" : ("Unknown (" + str + ")"));
|
||||
}
|
||||
|
||||
private String getGpsAltitudeRefDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(5))
|
||||
return null;
|
||||
int i = this._directory.getInt(5);
|
||||
return (i == 0) ? "Sea level" : ("Unknown (" + i + ")");
|
||||
}
|
||||
|
||||
private String getGpsAltitudeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(6))
|
||||
return null;
|
||||
String str = this._directory.getRational(6).toSimpleString(true);
|
||||
return str + " metres";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GpsDirectory extends Directory {
|
||||
public static final int TAG_GPS_VERSION_ID = 0;
|
||||
|
||||
public static final int TAG_GPS_LATITUDE_REF = 1;
|
||||
|
||||
public static final int TAG_GPS_LATITUDE = 2;
|
||||
|
||||
public static final int TAG_GPS_LONGITUDE_REF = 3;
|
||||
|
||||
public static final int TAG_GPS_LONGITUDE = 4;
|
||||
|
||||
public static final int TAG_GPS_ALTITUDE_REF = 5;
|
||||
|
||||
public static final int TAG_GPS_ALTITUDE = 6;
|
||||
|
||||
public static final int TAG_GPS_TIME_STAMP = 7;
|
||||
|
||||
public static final int TAG_GPS_SATELLITES = 8;
|
||||
|
||||
public static final int TAG_GPS_STATUS = 9;
|
||||
|
||||
public static final int TAG_GPS_MEASURE_MODE = 10;
|
||||
|
||||
public static final int TAG_GPS_DOP = 11;
|
||||
|
||||
public static final int TAG_GPS_SPEED_REF = 12;
|
||||
|
||||
public static final int TAG_GPS_SPEED = 13;
|
||||
|
||||
public static final int TAG_GPS_TRACK_REF = 14;
|
||||
|
||||
public static final int TAG_GPS_TRACK = 15;
|
||||
|
||||
public static final int TAG_GPS_IMG_DIRECTION_REF = 16;
|
||||
|
||||
public static final int TAG_GPS_IMG_DIRECTION = 17;
|
||||
|
||||
public static final int TAG_GPS_MAP_DATUM = 18;
|
||||
|
||||
public static final int TAG_GPS_DEST_LATITUDE_REF = 19;
|
||||
|
||||
public static final int TAG_GPS_DEST_LATITUDE = 20;
|
||||
|
||||
public static final int TAG_GPS_DEST_LONGITUDE_REF = 21;
|
||||
|
||||
public static final int TAG_GPS_DEST_LONGITUDE = 22;
|
||||
|
||||
public static final int TAG_GPS_DEST_BEARING_REF = 23;
|
||||
|
||||
public static final int TAG_GPS_DEST_BEARING = 24;
|
||||
|
||||
public static final int TAG_GPS_DEST_DISTANCE_REF = 25;
|
||||
|
||||
public static final int TAG_GPS_DEST_DISTANCE = 26;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public GpsDirectory() {
|
||||
setDescriptor(new GpsDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "GPS";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(0), "GPS Version ID");
|
||||
tagNameMap.put(new Integer(1), "GPS Latitude Ref");
|
||||
tagNameMap.put(new Integer(2), "GPS Latitude");
|
||||
tagNameMap.put(new Integer(3), "GPS Longitude Ref");
|
||||
tagNameMap.put(new Integer(4), "GPS Longitude");
|
||||
tagNameMap.put(new Integer(5), "GPS Altitude Ref");
|
||||
tagNameMap.put(new Integer(6), "GPS Altitude");
|
||||
tagNameMap.put(new Integer(7), "GPS Time-Stamp");
|
||||
tagNameMap.put(new Integer(8), "GPS Satellites");
|
||||
tagNameMap.put(new Integer(9), "GPS Status");
|
||||
tagNameMap.put(new Integer(10), "GPS Measure Mode");
|
||||
tagNameMap.put(new Integer(11), "GPS DOP");
|
||||
tagNameMap.put(new Integer(12), "GPS Speed Ref");
|
||||
tagNameMap.put(new Integer(13), "GPS Speed");
|
||||
tagNameMap.put(new Integer(14), "GPS Track Ref");
|
||||
tagNameMap.put(new Integer(15), "GPS Track");
|
||||
tagNameMap.put(new Integer(16), "GPS Img Direction Ref");
|
||||
tagNameMap.put(new Integer(16), "GPS Img Direction");
|
||||
tagNameMap.put(new Integer(18), "GPS Map Datum");
|
||||
tagNameMap.put(new Integer(19), "GPS Dest Latitude Ref");
|
||||
tagNameMap.put(new Integer(20), "GPS Dest Latitude");
|
||||
tagNameMap.put(new Integer(21), "GPS Dest Longitude Ref");
|
||||
tagNameMap.put(new Integer(22), "GPS Dest Longitude");
|
||||
tagNameMap.put(new Integer(23), "GPS Dest Bearing Ref");
|
||||
tagNameMap.put(new Integer(24), "GPS Dest Bearing");
|
||||
tagNameMap.put(new Integer(25), "GPS Dest Distance Ref");
|
||||
tagNameMap.put(new Integer(26), "GPS Dest Distance");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,154 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.lang.Rational;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class NikonType1MakernoteDescriptor extends TagDescriptor {
|
||||
public NikonType1MakernoteDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 3:
|
||||
return getQualityDescription();
|
||||
case 4:
|
||||
return getColorModeDescription();
|
||||
case 5:
|
||||
return getImageAdjustmentDescription();
|
||||
case 6:
|
||||
return getCcdSensitivityDescription();
|
||||
case 7:
|
||||
return getWhiteBalanceDescription();
|
||||
case 8:
|
||||
return getFocusDescription();
|
||||
case 10:
|
||||
return getDigitalZoomDescription();
|
||||
case 11:
|
||||
return getConverterDescription();
|
||||
}
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
|
||||
private String getConverterDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(11))
|
||||
return null;
|
||||
int i = this._directory.getInt(11);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "None";
|
||||
case 1:
|
||||
return "Fisheye converter";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getDigitalZoomDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(10))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(10);
|
||||
return (rational.getNumerator() == 0) ? "No digital zoom" : (rational.toSimpleString(true) + "x digital zoom");
|
||||
}
|
||||
|
||||
private String getFocusDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(8))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(8);
|
||||
return (rational.getNumerator() == 1 && rational.getDenominator() == 0) ? "Infinite" : rational.toSimpleString(true);
|
||||
}
|
||||
|
||||
private String getWhiteBalanceDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(7))
|
||||
return null;
|
||||
int i = this._directory.getInt(7);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Auto";
|
||||
case 1:
|
||||
return "Preset";
|
||||
case 2:
|
||||
return "Daylight";
|
||||
case 3:
|
||||
return "Incandescense";
|
||||
case 4:
|
||||
return "Flourescence";
|
||||
case 5:
|
||||
return "Cloudy";
|
||||
case 6:
|
||||
return "SpeedLight";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getCcdSensitivityDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(6))
|
||||
return null;
|
||||
int i = this._directory.getInt(6);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "ISO80";
|
||||
case 2:
|
||||
return "ISO160";
|
||||
case 4:
|
||||
return "ISO320";
|
||||
case 5:
|
||||
return "ISO100";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getImageAdjustmentDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(5))
|
||||
return null;
|
||||
int i = this._directory.getInt(5);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Normal";
|
||||
case 1:
|
||||
return "Bright +";
|
||||
case 2:
|
||||
return "Bright -";
|
||||
case 3:
|
||||
return "Contrast +";
|
||||
case 4:
|
||||
return "Contrast -";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getColorModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(4))
|
||||
return null;
|
||||
int i = this._directory.getInt(4);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "Color";
|
||||
case 2:
|
||||
return "Monochrome";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getQualityDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(3))
|
||||
return null;
|
||||
int i = this._directory.getInt(3);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "VGA Basic";
|
||||
case 2:
|
||||
return "VGA Normal";
|
||||
case 3:
|
||||
return "VGA Fine";
|
||||
case 4:
|
||||
return "SXGA Basic";
|
||||
case 5:
|
||||
return "SXGA Normal";
|
||||
case 6:
|
||||
return "SXGA Fine";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class NikonType1MakernoteDirectory extends Directory {
|
||||
public static final int TAG_NIKON_TYPE1_UNKNOWN_1 = 2;
|
||||
|
||||
public static final int TAG_NIKON_TYPE1_QUALITY = 3;
|
||||
|
||||
public static final int TAG_NIKON_TYPE1_COLOR_MODE = 4;
|
||||
|
||||
public static final int TAG_NIKON_TYPE1_IMAGE_ADJUSTMENT = 5;
|
||||
|
||||
public static final int TAG_NIKON_TYPE1_CCD_SENSITIVITY = 6;
|
||||
|
||||
public static final int TAG_NIKON_TYPE1_WHITE_BALANCE = 7;
|
||||
|
||||
public static final int TAG_NIKON_TYPE1_FOCUS = 8;
|
||||
|
||||
public static final int TAG_NIKON_TYPE1_UNKNOWN_2 = 9;
|
||||
|
||||
public static final int TAG_NIKON_TYPE1_DIGITAL_ZOOM = 10;
|
||||
|
||||
public static final int TAG_NIKON_TYPE1_CONVERTER = 11;
|
||||
|
||||
public static final int TAG_NIKON_TYPE1_UNKNOWN_3 = 3840;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public NikonType1MakernoteDirectory() {
|
||||
setDescriptor(new NikonType1MakernoteDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Nikon Makernote";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(6), "CCD Sensitivity");
|
||||
tagNameMap.put(new Integer(4), "Color Mode");
|
||||
tagNameMap.put(new Integer(10), "Digital Zoom");
|
||||
tagNameMap.put(new Integer(11), "Fisheye Converter");
|
||||
tagNameMap.put(new Integer(8), "Focus");
|
||||
tagNameMap.put(new Integer(5), "Image Adjustment");
|
||||
tagNameMap.put(new Integer(3), "Quality");
|
||||
tagNameMap.put(new Integer(2), "Makernote Unknown 1");
|
||||
tagNameMap.put(new Integer(9), "Makernote Unknown 2");
|
||||
tagNameMap.put(new Integer(3840), "Makernote Unknown 3");
|
||||
tagNameMap.put(new Integer(7), "White Balance");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.lang.Rational;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class NikonType2MakernoteDescriptor extends TagDescriptor {
|
||||
public NikonType2MakernoteDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 2:
|
||||
return getIsoSettingDescription();
|
||||
case 134:
|
||||
return getDigitalZoomDescription();
|
||||
case 136:
|
||||
return getAutoFocusPositionDescription();
|
||||
}
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
|
||||
private String getAutoFocusPositionDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(136))
|
||||
return null;
|
||||
int[] arrayOfInt = this._directory.getIntArray(136);
|
||||
if (arrayOfInt.length != 4 || arrayOfInt[0] != 0 || arrayOfInt[2] != 0 || arrayOfInt[3] != 0)
|
||||
return "Unknown (" + this._directory.getString(136) + ")";
|
||||
switch (arrayOfInt[1]) {
|
||||
case 0:
|
||||
return "Centre";
|
||||
case 1:
|
||||
return "Top";
|
||||
case 2:
|
||||
return "Bottom";
|
||||
case 3:
|
||||
return "Left";
|
||||
case 4:
|
||||
return "Right";
|
||||
}
|
||||
return "Unknown (" + arrayOfInt[1] + ")";
|
||||
}
|
||||
|
||||
private String getDigitalZoomDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(134))
|
||||
return null;
|
||||
Rational rational = this._directory.getRational(134);
|
||||
return (rational.intValue() == 1) ? "No digital zoom" : (rational.toSimpleString(true) + "x digital zoom");
|
||||
}
|
||||
|
||||
private String getIsoSettingDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(2))
|
||||
return null;
|
||||
int[] arrayOfInt = this._directory.getIntArray(2);
|
||||
return (arrayOfInt[0] != 0 || arrayOfInt[1] == 0) ? ("Unknown (" + this._directory.getString(2) + ")") : ("ISO " + arrayOfInt[1]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class NikonType2MakernoteDirectory extends Directory {
|
||||
public static final int TAG_NIKON_TYPE2_UNKNOWN_1 = 1;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_ISO_SETTING = 2;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_COLOR_MODE = 3;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_QUALITY = 4;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_WHITE_BALANCE = 5;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_IMAGE_SHARPENING = 6;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_FOCUS_MODE = 7;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_FLASH_SETTING = 8;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_UNKNOWN_2 = 10;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_ISO_SELECTION = 15;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_IMAGE_ADJUSTMENT = 128;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_ADAPTER = 130;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_MANUAL_FOCUS_DISTANCE = 133;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_DIGITAL_ZOOM = 134;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_AF_FOCUS_POSITION = 136;
|
||||
|
||||
public static final int TAG_NIKON_TYPE2_DATA_DUMP = 16;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public NikonType2MakernoteDirectory() {
|
||||
setDescriptor(new NikonType2MakernoteDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Nikon Makernote";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(130), "Adapter");
|
||||
tagNameMap.put(new Integer(136), "AF Focus Position");
|
||||
tagNameMap.put(new Integer(3), "Color Mode");
|
||||
tagNameMap.put(new Integer(16), "Data Dump");
|
||||
tagNameMap.put(new Integer(134), "Digital Zoom");
|
||||
tagNameMap.put(new Integer(8), "Flash Setting");
|
||||
tagNameMap.put(new Integer(7), "Focus Mode");
|
||||
tagNameMap.put(new Integer(128), "Image Adjustment");
|
||||
tagNameMap.put(new Integer(6), "Image Sharpening");
|
||||
tagNameMap.put(new Integer(15), "ISO Selection");
|
||||
tagNameMap.put(new Integer(2), "ISO Setting");
|
||||
tagNameMap.put(new Integer(133), "Focus Distance");
|
||||
tagNameMap.put(new Integer(4), "Quality");
|
||||
tagNameMap.put(new Integer(1), "Makernote Unknown 1");
|
||||
tagNameMap.put(new Integer(10), "Makernote Unknown 2");
|
||||
tagNameMap.put(new Integer(5), "White Balance");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.lang.Rational;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class NikonType3MakernoteDescriptor extends TagDescriptor {
|
||||
public NikonType3MakernoteDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 132:
|
||||
return getLensDescription();
|
||||
case 146:
|
||||
return getHueAdjustmentDescription();
|
||||
case 141:
|
||||
return getColorModeDescription();
|
||||
}
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
|
||||
public String getLensDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(132))
|
||||
return null;
|
||||
Rational[] arrayOfRational = this._directory.getRationalArray(132);
|
||||
if (arrayOfRational.length != 4)
|
||||
return this._directory.getString(132);
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(arrayOfRational[0].intValue());
|
||||
stringBuffer.append('-');
|
||||
stringBuffer.append(arrayOfRational[1].intValue());
|
||||
stringBuffer.append("mm f/");
|
||||
stringBuffer.append(arrayOfRational[2].floatValue());
|
||||
stringBuffer.append('-');
|
||||
stringBuffer.append(arrayOfRational[3].floatValue());
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
public String getHueAdjustmentDescription() {
|
||||
return !this._directory.containsTag(146) ? null : (this._directory.getString(146) + " degrees");
|
||||
}
|
||||
|
||||
public String getColorModeDescription() {
|
||||
if (!this._directory.containsTag(141))
|
||||
return null;
|
||||
String str = this._directory.getString(141);
|
||||
return str.startsWith("MODE1") ? "Mode I (sRGB)" : str;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class NikonType3MakernoteDirectory extends Directory {
|
||||
public static final int TAG_NIKON_TYPE3_FIRMWARE_VERSION = 1;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_ISO_1 = 2;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_FILE_FORMAT = 4;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_CAMERA_WHITE_BALANCE = 5;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_CAMERA_SHARPENING = 6;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_AF_TYPE = 7;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_17 = 8;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_18 = 9;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_CAMERA_WHITE_BALANCE_FINE = 11;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_CAMERA_WHITE_BALANCE_RB_COEFF = 12;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_1 = 13;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_2 = 14;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_3 = 17;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_19 = 18;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_ISO_2 = 19;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_CAMERA_TONE_COMPENSATION = 129;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_4 = 131;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_LENS = 132;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_5 = 135;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_6 = 136;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_7 = 137;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_8 = 139;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_20 = 138;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_9 = 140;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_CAMERA_COLOR_MODE = 141;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_10 = 144;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_11 = 145;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_CAMERA_HUE_ADJUSTMENT = 146;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_NOISE_REDUCTION = 149;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_12 = 151;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_13 = 152;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_14 = 153;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_15 = 154;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_CAPTURE_EDITOR_DATA = 3585;
|
||||
|
||||
public static final int TAG_NIKON_TYPE3_UNKNOWN_16 = 3600;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public NikonType3MakernoteDirectory() {
|
||||
setDescriptor(new NikonType3MakernoteDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Nikon Makernote";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(1), "Firmware Version");
|
||||
tagNameMap.put(new Integer(2), "ISO");
|
||||
tagNameMap.put(new Integer(4), "File Format");
|
||||
tagNameMap.put(new Integer(5), "White Balance");
|
||||
tagNameMap.put(new Integer(6), "Sharpening");
|
||||
tagNameMap.put(new Integer(7), "AF Type");
|
||||
tagNameMap.put(new Integer(11), "White Balance Fine");
|
||||
tagNameMap.put(new Integer(12), "White Balance RB Coefficients");
|
||||
tagNameMap.put(new Integer(19), "ISO");
|
||||
tagNameMap.put(new Integer(129), "Tone Compensation");
|
||||
tagNameMap.put(new Integer(132), "Lens");
|
||||
tagNameMap.put(new Integer(141), "Colour Mode");
|
||||
tagNameMap.put(new Integer(146), "Camera Hue Adjustment");
|
||||
tagNameMap.put(new Integer(149), "Noise Reduction");
|
||||
tagNameMap.put(new Integer(3585), "Capture Editor Data");
|
||||
tagNameMap.put(new Integer(13), "Unknown 01");
|
||||
tagNameMap.put(new Integer(14), "Unknown 02");
|
||||
tagNameMap.put(new Integer(17), "Unknown 03");
|
||||
tagNameMap.put(new Integer(131), "Unknown 04");
|
||||
tagNameMap.put(new Integer(135), "Unknown 05");
|
||||
tagNameMap.put(new Integer(136), "Unknown 06");
|
||||
tagNameMap.put(new Integer(137), "Unknown 07");
|
||||
tagNameMap.put(new Integer(139), "Unknown 08");
|
||||
tagNameMap.put(new Integer(140), "Unknown 09");
|
||||
tagNameMap.put(new Integer(144), "Unknown 10");
|
||||
tagNameMap.put(new Integer(145), "Unknown 11");
|
||||
tagNameMap.put(new Integer(151), "Unknown 12");
|
||||
tagNameMap.put(new Integer(152), "Unknown 13");
|
||||
tagNameMap.put(new Integer(153), "Unknown 14");
|
||||
tagNameMap.put(new Integer(154), "Unknown 15");
|
||||
tagNameMap.put(new Integer(3600), "Unknown 16");
|
||||
tagNameMap.put(new Integer(8), "Unknown 17");
|
||||
tagNameMap.put(new Integer(9), "Unknown 18");
|
||||
tagNameMap.put(new Integer(18), "Unknown 19");
|
||||
tagNameMap.put(new Integer(138), "Unknown 20");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class OlympusMakernoteDescriptor extends TagDescriptor {
|
||||
public OlympusMakernoteDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 512:
|
||||
return getSpecialModeDescription();
|
||||
case 513:
|
||||
return getJpegQualityDescription();
|
||||
case 514:
|
||||
return getMacroModeDescription();
|
||||
case 516:
|
||||
return getDigiZoomRatioDescription();
|
||||
}
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
|
||||
private String getDigiZoomRatioDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(516))
|
||||
return null;
|
||||
int i = this._directory.getInt(516);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Normal";
|
||||
case 2:
|
||||
return "Digital 2x Zoom";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getMacroModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(514))
|
||||
return null;
|
||||
int i = this._directory.getInt(514);
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "Normal (no macro)";
|
||||
case 1:
|
||||
return "Macro";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getJpegQualityDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(513))
|
||||
return null;
|
||||
int i = this._directory.getInt(513);
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "SQ";
|
||||
case 2:
|
||||
return "HQ";
|
||||
case 3:
|
||||
return "SHQ";
|
||||
}
|
||||
return "Unknown (" + i + ")";
|
||||
}
|
||||
|
||||
private String getSpecialModeDescription() throws MetadataException {
|
||||
if (!this._directory.containsTag(512))
|
||||
return null;
|
||||
int[] arrayOfInt = this._directory.getIntArray(512);
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
switch (arrayOfInt[0]) {
|
||||
case 0:
|
||||
stringBuffer.append("Normal picture taking mode");
|
||||
break;
|
||||
case 1:
|
||||
stringBuffer.append("Unknown picture taking mode");
|
||||
break;
|
||||
case 2:
|
||||
stringBuffer.append("Fast picture taking mode");
|
||||
break;
|
||||
case 3:
|
||||
stringBuffer.append("Panorama picture taking mode");
|
||||
break;
|
||||
default:
|
||||
stringBuffer.append("Unknown picture taking mode");
|
||||
break;
|
||||
}
|
||||
stringBuffer.append(" - ");
|
||||
switch (arrayOfInt[1]) {
|
||||
case 0:
|
||||
stringBuffer.append("Unknown sequence number");
|
||||
break;
|
||||
case 1:
|
||||
stringBuffer.append("1st in a sequnce");
|
||||
break;
|
||||
case 2:
|
||||
stringBuffer.append("2nd in a sequence");
|
||||
break;
|
||||
case 3:
|
||||
stringBuffer.append("3rd in a sequence");
|
||||
break;
|
||||
default:
|
||||
stringBuffer.append(arrayOfInt[1]);
|
||||
stringBuffer.append("th in a sequence");
|
||||
break;
|
||||
}
|
||||
switch (arrayOfInt[2]) {
|
||||
case 1:
|
||||
stringBuffer.append("Left to right panorama direction");
|
||||
break;
|
||||
case 2:
|
||||
stringBuffer.append("Right to left panorama direction");
|
||||
break;
|
||||
case 3:
|
||||
stringBuffer.append("Bottom to top panorama direction");
|
||||
break;
|
||||
case 4:
|
||||
stringBuffer.append("Top to bottom panorama direction");
|
||||
break;
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.drew.metadata.exif;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class OlympusMakernoteDirectory extends Directory {
|
||||
public static final int TAG_OLYMPUS_SPECIAL_MODE = 512;
|
||||
|
||||
public static final int TAG_OLYMPUS_JPEG_QUALITY = 513;
|
||||
|
||||
public static final int TAG_OLYMPUS_MACRO_MODE = 514;
|
||||
|
||||
public static final int TAG_OLYMPUS_UNKNOWN_1 = 515;
|
||||
|
||||
public static final int TAG_OLYMPUS_DIGI_ZOOM_RATIO = 516;
|
||||
|
||||
public static final int TAG_OLYMPUS_UNKNOWN_2 = 517;
|
||||
|
||||
public static final int TAG_OLYMPUS_UNKNOWN_3 = 518;
|
||||
|
||||
public static final int TAG_OLYMPUS_FIRMWARE_VERSION = 519;
|
||||
|
||||
public static final int TAG_OLYMPUS_PICT_INFO = 520;
|
||||
|
||||
public static final int TAG_OLYMPUS_CAMERA_ID = 521;
|
||||
|
||||
public static final int TAG_OLYMPUS_DATA_DUMP = 3840;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public OlympusMakernoteDirectory() {
|
||||
setDescriptor(new OlympusMakernoteDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Olympus Makernote";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(512), "Special Mode");
|
||||
tagNameMap.put(new Integer(513), "Jpeg Quality");
|
||||
tagNameMap.put(new Integer(514), "Macro");
|
||||
tagNameMap.put(new Integer(515), "Makernote Unknown 1");
|
||||
tagNameMap.put(new Integer(516), "DigiZoom Ratio");
|
||||
tagNameMap.put(new Integer(517), "Makernote Unknown 2");
|
||||
tagNameMap.put(new Integer(518), "Makernote Unknown 3");
|
||||
tagNameMap.put(new Integer(519), "Firmware Version");
|
||||
tagNameMap.put(new Integer(520), "Pict Info");
|
||||
tagNameMap.put(new Integer(521), "Camera Id");
|
||||
tagNameMap.put(new Integer(3840), "Data Dump");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.drew.metadata.exif.test;
|
||||
|
||||
import com.drew.lang.Rational;
|
||||
import com.drew.metadata.exif.ExifDescriptor;
|
||||
import com.drew.metadata.exif.ExifDirectory;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ExifDescriptorTest extends TestCase {
|
||||
public ExifDescriptorTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testXResolution() throws Exception {
|
||||
ExifDirectory exifDirectory = new ExifDirectory();
|
||||
exifDirectory.setRational(282, new Rational(72, 1));
|
||||
exifDirectory.setInt(296, 2);
|
||||
ExifDescriptor exifDescriptor = new ExifDescriptor(exifDirectory);
|
||||
assertEquals("72 dots per inch", exifDescriptor.getDescription(282));
|
||||
}
|
||||
|
||||
public void testYResolution() throws Exception {
|
||||
ExifDirectory exifDirectory = new ExifDirectory();
|
||||
exifDirectory.setRational(283, new Rational(50, 1));
|
||||
exifDirectory.setInt(296, 3);
|
||||
ExifDescriptor exifDescriptor = new ExifDescriptor(exifDirectory);
|
||||
assertEquals("50 dots per cm", exifDescriptor.getDescription(283));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.drew.metadata.exif.test;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegMetadataReader;
|
||||
import com.drew.imaging.jpeg.JpegProcessingException;
|
||||
import com.drew.imaging.jpeg.JpegSegmentReader;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.exif.ExifDirectory;
|
||||
import java.io.File;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ExifDirectoryTest extends TestCase {
|
||||
public ExifDirectoryTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testGetDirectoryName() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
assertEquals("Exif", directory.getName());
|
||||
}
|
||||
|
||||
public void testGetThumbnailData() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/exif/test/withExif.jpg");
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(file);
|
||||
ExifDirectory exifDirectory = (ExifDirectory)metadata.getDirectory(ExifDirectory.class);
|
||||
assertTrue(exifDirectory.containsTag(61441));
|
||||
byte[] arrayOfByte = exifDirectory.getThumbnailData();
|
||||
try {
|
||||
new JpegSegmentReader(arrayOfByte);
|
||||
} catch (JpegProcessingException e) {
|
||||
fail("Unable to construct JpegSegmentReader from thumbnail data");
|
||||
}
|
||||
}
|
||||
|
||||
public void testWriteThumbnail() throws Exception {
|
||||
File file1 = new File("src/com/drew/metadata/exif/test/manuallyAddedThumbnail.jpg");
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(file1);
|
||||
ExifDirectory exifDirectory = (ExifDirectory)metadata.getDirectory(ExifDirectory.class);
|
||||
assertTrue(exifDirectory.containsTag(61441));
|
||||
File file2 = File.createTempFile("thumbnail", ".jpg");
|
||||
try {
|
||||
exifDirectory.writeThumbnail(file2.getAbsolutePath());
|
||||
assertTrue(new File(file2.getAbsolutePath()).exists());
|
||||
} finally {
|
||||
file2.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public void testContainsThumbnail() {
|
||||
ExifDirectory exifDirectory = new ExifDirectory();
|
||||
assertTrue(!exifDirectory.containsThumbnail());
|
||||
exifDirectory.setObject(61441, "foo");
|
||||
assertTrue(exifDirectory.containsThumbnail());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package com.drew.metadata.exif.test;
|
||||
|
||||
import com.drew.lang.Rational;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.exif.ExifDirectory;
|
||||
import com.drew.metadata.exif.ExifReader;
|
||||
import java.io.File;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ExifReaderTest extends TestCase {
|
||||
public ExifReaderTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testLoadFujiFilmJpeg() throws Exception {
|
||||
String str = "src/com/drew/metadata/exif/test/withExif.jpg";
|
||||
Metadata metadata = new ExifReader(new File(str)).extract();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
assertEquals("80", directory.getDescription(34855));
|
||||
}
|
||||
|
||||
public void testLoadJpegWithoutExifData() throws Exception {
|
||||
String str = "src/com/drew/metadata/exif/test/noExif.jpg";
|
||||
Metadata metadata = new ExifReader(new File(str)).extract();
|
||||
assertTrue(!metadata.containsDirectory(ExifDirectory.class));
|
||||
}
|
||||
|
||||
public void testLoadJpegWithBadExifData() throws Exception {
|
||||
String str = "src/com/drew/metadata/exif/test/badExif.jpg";
|
||||
Metadata metadata = new ExifReader(new File(str)).extract();
|
||||
assertEquals(0, metadata.getDirectory(ExifDirectory.class).getTagCount());
|
||||
}
|
||||
|
||||
public void testCrashRegressionTest() throws Exception {
|
||||
String str = "src/com/drew/metadata/exif/test/crash01.jpg";
|
||||
Metadata metadata = new ExifReader(new File(str)).extract();
|
||||
assertTrue((metadata.getDirectory(ExifDirectory.class).getTagCount() > 0));
|
||||
}
|
||||
|
||||
public void testUserComment() throws Exception {
|
||||
String str = "src/com/drew/metadata/exif/test/manuallyAddedThumbnail.jpg";
|
||||
Metadata metadata = new ExifReader(new File(str)).extract();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
assertEquals("Here we add a EXIF comment", directory.getString(37510));
|
||||
}
|
||||
|
||||
public void testThumbnailOffset() throws Exception {
|
||||
String str = "src/com/drew/metadata/exif/test/manuallyAddedThumbnail.jpg";
|
||||
Metadata metadata = new ExifReader(new File(str)).extract();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
assertEquals(192, directory.getInt(513));
|
||||
}
|
||||
|
||||
public void testThumbnailLength() throws Exception {
|
||||
String str = "src/com/drew/metadata/exif/test/manuallyAddedThumbnail.jpg";
|
||||
Metadata metadata = new ExifReader(new File(str)).extract();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
assertEquals(2970, directory.getInt(514));
|
||||
}
|
||||
|
||||
public void testDateTime() throws Exception {
|
||||
String str = "src/com/drew/metadata/exif/test/manuallyAddedThumbnail.jpg";
|
||||
Metadata metadata = new ExifReader(new File(str)).extract();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
assertEquals("2002:11:27 18:00:35", directory.getString(306));
|
||||
}
|
||||
|
||||
public void testXResolution() throws Exception {
|
||||
String str = "src/com/drew/metadata/exif/test/manuallyAddedThumbnail.jpg";
|
||||
Metadata metadata = new ExifReader(new File(str)).extract();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
Rational rational = directory.getRational(282);
|
||||
assertEquals(72, rational.getNumerator());
|
||||
assertEquals(1, rational.getDenominator());
|
||||
}
|
||||
|
||||
public void testYResolution() throws Exception {
|
||||
String str = "src/com/drew/metadata/exif/test/manuallyAddedThumbnail.jpg";
|
||||
Metadata metadata = new ExifReader(new File(str)).extract();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
Rational rational = directory.getRational(283);
|
||||
assertEquals(72, rational.getNumerator());
|
||||
assertEquals(1, rational.getDenominator());
|
||||
}
|
||||
|
||||
public void testCompression() throws Exception {
|
||||
String str = "src/com/drew/metadata/exif/test/manuallyAddedThumbnail.jpg";
|
||||
Metadata metadata = new ExifReader(new File(str)).extract();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
assertEquals(6, directory.getInt(259));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package com.drew.metadata.exif.test;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegMetadataReader;
|
||||
import com.drew.lang.Rational;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.exif.ExifDirectory;
|
||||
import com.drew.metadata.exif.NikonType1MakernoteDirectory;
|
||||
import java.io.File;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class NikonType1MakernoteTest extends TestCase {
|
||||
private NikonType1MakernoteDirectory _nikonDirectory;
|
||||
|
||||
private ExifDirectory _exifDirectory;
|
||||
|
||||
public NikonType1MakernoteTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/exif/test/nikonMakernoteType1.jpg");
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(file);
|
||||
this._nikonDirectory = (NikonType1MakernoteDirectory)metadata.getDirectory(NikonType1MakernoteDirectory.class);
|
||||
this._exifDirectory = (ExifDirectory)metadata.getDirectory(ExifDirectory.class);
|
||||
}
|
||||
|
||||
public void testNikonMakernote_MatchesKnownValues() throws Exception {
|
||||
assertTrue((this._nikonDirectory.getTagCount() > 0));
|
||||
assertEquals(8.0D, this._nikonDirectory.getDouble(2), 1.0E-4D);
|
||||
assertEquals(12, this._nikonDirectory.getInt(3));
|
||||
assertEquals(1, this._nikonDirectory.getInt(4));
|
||||
assertEquals(3, this._nikonDirectory.getInt(5));
|
||||
assertEquals(0, this._nikonDirectory.getInt(6));
|
||||
assertEquals(0, this._nikonDirectory.getInt(7));
|
||||
assertEquals(0, this._nikonDirectory.getInt(8));
|
||||
assertEquals("", this._nikonDirectory.getString(9));
|
||||
assertEquals(0.0D, this._nikonDirectory.getDouble(10), 1.0E-4D);
|
||||
assertEquals(0, this._nikonDirectory.getInt(11));
|
||||
int[] arrayOfInt1 = this._nikonDirectory.getIntArray(3840);
|
||||
int[] arrayOfInt2 = {
|
||||
0, 0, 16777216, 0, -1609193200, 0, 34833, 6931, 16178, 4372,
|
||||
4372, -972290529, -921882880, 15112, 0, 0, 1151495, 252903424, 17, 0,
|
||||
0, 844038208, 55184128, 218129428, 1476410198, 370540566, -250604010, 16711749, 204629079, 1729 };
|
||||
assertEquals(arrayOfInt2.length, arrayOfInt1.length);
|
||||
for (int i = 0; i < arrayOfInt2.length; i++)
|
||||
assertEquals(arrayOfInt2[i], arrayOfInt1[i]);
|
||||
}
|
||||
|
||||
public void testExifDirectory_MatchesKnownValues() throws Exception {
|
||||
assertEquals(" ", this._exifDirectory.getString(270));
|
||||
assertEquals("NIKON", this._exifDirectory.getString(271));
|
||||
assertEquals("E950", this._exifDirectory.getString(272));
|
||||
assertEquals(1, this._exifDirectory.getInt(274));
|
||||
assertEquals(300.0D, this._exifDirectory.getDouble(282), 0.001D);
|
||||
assertEquals(300.0D, this._exifDirectory.getDouble(283), 0.001D);
|
||||
assertEquals(2, this._exifDirectory.getInt(296));
|
||||
assertEquals("v981-79", this._exifDirectory.getString(305));
|
||||
assertEquals("2001:04:06 11:51:40", this._exifDirectory.getString(306));
|
||||
assertEquals(2, this._exifDirectory.getInt(531));
|
||||
assertEquals(new Rational(1, 77), this._exifDirectory.getRational(33434));
|
||||
assertEquals(5.5D, this._exifDirectory.getDouble(33437), 0.001D);
|
||||
assertEquals(2, this._exifDirectory.getInt(34850));
|
||||
assertEquals(80, this._exifDirectory.getInt(34855));
|
||||
assertEquals("0210", this._exifDirectory.getString(36864));
|
||||
assertEquals("2001:04:06 11:51:40", this._exifDirectory.getString(36868));
|
||||
assertEquals("2001:04:06 11:51:40", this._exifDirectory.getString(36867));
|
||||
assertEquals(197121, this._exifDirectory.getInt(37121));
|
||||
assertEquals(4, this._exifDirectory.getInt(37122));
|
||||
assertEquals(0, this._exifDirectory.getInt(37380));
|
||||
assertEquals(2.6D, this._exifDirectory.getDouble(37381), 0.001D);
|
||||
assertEquals(5, this._exifDirectory.getInt(37383));
|
||||
assertEquals(0, this._exifDirectory.getInt(37384));
|
||||
assertEquals(0, this._exifDirectory.getInt(37385));
|
||||
assertEquals(12.8D, this._exifDirectory.getDouble(37386), 0.001D);
|
||||
assertEquals("", this._exifDirectory.getString(37510));
|
||||
assertEquals("0100", this._exifDirectory.getString(40960));
|
||||
assertEquals(1, this._exifDirectory.getInt(40961));
|
||||
assertEquals(1600, this._exifDirectory.getInt(40962));
|
||||
assertEquals(1200, this._exifDirectory.getInt(40963));
|
||||
assertEquals(3, this._exifDirectory.getInt(41728));
|
||||
assertEquals(1, this._exifDirectory.getInt(41729));
|
||||
assertEquals(6, this._exifDirectory.getInt(259));
|
||||
assertEquals(2036, this._exifDirectory.getInt(513));
|
||||
assertEquals(4662, this._exifDirectory.getInt(514));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package com.drew.metadata.exif.test;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegMetadataReader;
|
||||
import com.drew.lang.Rational;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.exif.ExifDirectory;
|
||||
import com.drew.metadata.exif.NikonType2MakernoteDirectory;
|
||||
import java.io.File;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class NikonType2MakernoteTest extends TestCase {
|
||||
private NikonType2MakernoteDirectory _nikonDirectory;
|
||||
|
||||
private ExifDirectory _exifDirectory;
|
||||
|
||||
public NikonType2MakernoteTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/exif/test/nikonMakernoteType2.jpg");
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(file);
|
||||
this._nikonDirectory = (NikonType2MakernoteDirectory)metadata.getDirectory(NikonType2MakernoteDirectory.class);
|
||||
this._exifDirectory = (ExifDirectory)metadata.getDirectory(ExifDirectory.class);
|
||||
}
|
||||
|
||||
public void testNikonMakernote_MatchesKnownValues() throws Exception {
|
||||
assertEquals("", this._nikonDirectory.getString(1));
|
||||
assertEquals("0 0", this._nikonDirectory.getString(2));
|
||||
assertEquals("COLOR", this._nikonDirectory.getString(3));
|
||||
assertEquals("NORMAL ", this._nikonDirectory.getString(4));
|
||||
assertEquals("AUTO ", this._nikonDirectory.getString(5));
|
||||
assertEquals("AUTO ", this._nikonDirectory.getString(6));
|
||||
assertEquals("AF-C ", this._nikonDirectory.getString(7));
|
||||
assertEquals("NORMAL ", this._nikonDirectory.getString(8));
|
||||
assertEquals(new Rational(4416, 500), this._nikonDirectory.getRational(10));
|
||||
assertEquals("AUTO ", this._nikonDirectory.getString(15));
|
||||
assertEquals(1300, this._nikonDirectory.getInt(17));
|
||||
assertEquals("AUTO ", this._nikonDirectory.getString(128));
|
||||
assertEquals("OFF ", this._nikonDirectory.getString(130));
|
||||
assertEquals(0, this._nikonDirectory.getInt(133));
|
||||
assertEquals(1, this._nikonDirectory.getInt(134));
|
||||
assertEquals(" ", this._nikonDirectory.getString(143));
|
||||
assertEquals(0, this._nikonDirectory.getInt(148));
|
||||
assertEquals("FPNR", this._nikonDirectory.getString(149));
|
||||
assertEquals("PrintIM", this._nikonDirectory.getString(3584));
|
||||
assertEquals(1394, this._nikonDirectory.getInt(3600));
|
||||
}
|
||||
|
||||
public void testExifDirectory_MatchesKnownValues() throws Exception {
|
||||
assertEquals(" ", this._exifDirectory.getString(270));
|
||||
assertEquals("NIKON", this._exifDirectory.getString(271));
|
||||
assertEquals("E995", this._exifDirectory.getString(272));
|
||||
assertEquals(72.0D, this._exifDirectory.getDouble(282), 0.001D);
|
||||
assertEquals(72.0D, this._exifDirectory.getDouble(283), 0.001D);
|
||||
assertEquals(2, this._exifDirectory.getInt(296));
|
||||
assertEquals("E995v1.6", this._exifDirectory.getString(305));
|
||||
assertEquals("2002:08:29 17:31:40", this._exifDirectory.getString(306));
|
||||
assertEquals(1, this._exifDirectory.getInt(531));
|
||||
assertEquals(new Rational(2439024, 100000000), this._exifDirectory.getRational(33434));
|
||||
assertEquals(2.6D, this._exifDirectory.getDouble(33437), 0.001D);
|
||||
assertEquals(2, this._exifDirectory.getInt(34850));
|
||||
assertEquals(100, this._exifDirectory.getInt(34855));
|
||||
assertEquals("0210", this._exifDirectory.getString(36864));
|
||||
assertEquals("2002:08:29 17:31:40", this._exifDirectory.getString(36868));
|
||||
assertEquals("2002:08:29 17:31:40", this._exifDirectory.getString(36867));
|
||||
assertEquals(197121, this._exifDirectory.getInt(37121));
|
||||
assertEquals(0, this._exifDirectory.getInt(37380));
|
||||
assertEquals("0", this._exifDirectory.getString(37381));
|
||||
assertEquals(5, this._exifDirectory.getInt(37383));
|
||||
assertEquals(0, this._exifDirectory.getInt(37384));
|
||||
assertEquals(1, this._exifDirectory.getInt(37385));
|
||||
assertEquals(8.2D, this._exifDirectory.getDouble(37386), 0.001D);
|
||||
assertEquals("", this._exifDirectory.getString(37510));
|
||||
assertEquals("0100", this._exifDirectory.getString(40960));
|
||||
assertEquals(1, this._exifDirectory.getInt(40961));
|
||||
assertEquals(2048, this._exifDirectory.getInt(40962));
|
||||
assertEquals(1536, this._exifDirectory.getInt(40963));
|
||||
assertEquals(3, this._exifDirectory.getInt(41728));
|
||||
assertEquals(1, this._exifDirectory.getInt(41729));
|
||||
assertEquals(6, this._exifDirectory.getInt(259));
|
||||
assertEquals(1494, this._exifDirectory.getInt(513));
|
||||
assertEquals(6077, this._exifDirectory.getInt(514));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.drew.metadata.exif.test;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegMetadataReader;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.exif.NikonType3MakernoteDescriptor;
|
||||
import com.drew.metadata.exif.NikonType3MakernoteDirectory;
|
||||
import java.io.File;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class NikonType3MakernoteTest extends TestCase {
|
||||
private NikonType3MakernoteDirectory _nikonDirectory;
|
||||
|
||||
private NikonType3MakernoteDescriptor _descriptor;
|
||||
|
||||
public NikonType3MakernoteTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/exif/test/nikonMakernoteType3.jpg");
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(file);
|
||||
this._nikonDirectory = (NikonType3MakernoteDirectory)metadata.getDirectory(NikonType3MakernoteDirectory.class);
|
||||
this._descriptor = new NikonType3MakernoteDescriptor(this._nikonDirectory);
|
||||
}
|
||||
|
||||
public void testNikonMakernote_MatchesKnownValues() throws Exception {
|
||||
assertEquals("0200", this._nikonDirectory.getString(1));
|
||||
assertEquals("0 320", this._nikonDirectory.getString(2));
|
||||
assertEquals("0 320", this._nikonDirectory.getString(19));
|
||||
assertEquals("FLASH ", this._nikonDirectory.getString(5));
|
||||
assertEquals("AUTO ", this._nikonDirectory.getString(6));
|
||||
assertEquals("AF-C ", this._nikonDirectory.getString(7));
|
||||
assertEquals("NORMAL ", this._nikonDirectory.getString(8));
|
||||
assertEquals("0", this._nikonDirectory.getString(11));
|
||||
assertEquals("914", this._nikonDirectory.getString(17));
|
||||
assertEquals("AUTO ", this._nikonDirectory.getString(129));
|
||||
assertEquals("6", this._nikonDirectory.getString(131));
|
||||
assertEquals("240/10 850/10 35/10 45/10", this._nikonDirectory.getString(132));
|
||||
assertEquals("0", this._nikonDirectory.getString(135));
|
||||
assertEquals("1", this._nikonDirectory.getString(137));
|
||||
assertEquals("0", this._nikonDirectory.getString(138));
|
||||
assertEquals("MODE1 ", this._nikonDirectory.getString(141));
|
||||
assertEquals("NATURAL ", this._nikonDirectory.getString(144));
|
||||
assertEquals("0", this._nikonDirectory.getString(146));
|
||||
assertEquals("OFF ", this._nikonDirectory.getString(149));
|
||||
assertEquals("78/10 78/10", this._nikonDirectory.getString(154));
|
||||
}
|
||||
|
||||
public void testGetLensDescription() throws MetadataException {
|
||||
assertEquals("24-85mm f/3.5-4.5", this._descriptor.getDescription(132));
|
||||
assertEquals("24-85mm f/3.5-4.5", this._descriptor.getLensDescription());
|
||||
}
|
||||
|
||||
public void testGetHueAdjustmentDescription() throws MetadataException {
|
||||
assertEquals("0 degrees", this._descriptor.getDescription(146));
|
||||
assertEquals("0 degrees", this._descriptor.getHueAdjustmentDescription());
|
||||
}
|
||||
|
||||
public void testGetColorModeDescription() throws Exception {
|
||||
assertEquals("Mode I (sRGB)", this._descriptor.getDescription(141));
|
||||
assertEquals("Mode I (sRGB)", this._descriptor.getColorModeDescription());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.drew.metadata.iptc;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class IptcDescriptor extends TagDescriptor {
|
||||
public IptcDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) {
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package com.drew.metadata.iptc;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class IptcDirectory extends Directory {
|
||||
public static final int TAG_RECORD_VERSION = 512;
|
||||
|
||||
public static final int TAG_CAPTION = 632;
|
||||
|
||||
public static final int TAG_WRITER = 634;
|
||||
|
||||
public static final int TAG_HEADLINE = 617;
|
||||
|
||||
public static final int TAG_SPECIAL_INSTRUCTIONS = 552;
|
||||
|
||||
public static final int TAG_BY_LINE = 592;
|
||||
|
||||
public static final int TAG_BY_LINE_TITLE = 597;
|
||||
|
||||
public static final int TAG_CREDIT = 622;
|
||||
|
||||
public static final int TAG_SOURCE = 627;
|
||||
|
||||
public static final int TAG_OBJECT_NAME = 517;
|
||||
|
||||
public static final int TAG_DATE_CREATED = 567;
|
||||
|
||||
public static final int TAG_CITY = 602;
|
||||
|
||||
public static final int TAG_PROVINCE_OR_STATE = 607;
|
||||
|
||||
public static final int TAG_COUNTRY_OR_PRIMARY_LOCATION = 613;
|
||||
|
||||
public static final int TAG_ORIGINAL_TRANSMISSION_REFERENCE = 615;
|
||||
|
||||
public static final int TAG_CATEGORY = 527;
|
||||
|
||||
public static final int TAG_SUPPLEMENTAL_CATEGORIES = 532;
|
||||
|
||||
public static final int TAG_URGENCY = 522;
|
||||
|
||||
public static final int TAG_KEYWORDS = 537;
|
||||
|
||||
public static final int TAG_COPYRIGHT_NOTICE = 628;
|
||||
|
||||
public static final int TAG_RELEASE_DATE = 542;
|
||||
|
||||
public static final int TAG_RELEASE_TIME = 547;
|
||||
|
||||
public static final int TAG_TIME_CREATED = 572;
|
||||
|
||||
public static final int TAG_ORIGINATING_PROGRAM = 577;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public IptcDirectory() {
|
||||
setDescriptor(new IptcDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Iptc";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(512), "Directory Version");
|
||||
tagNameMap.put(new Integer(632), "Caption/Abstract");
|
||||
tagNameMap.put(new Integer(634), "Writer/Editor");
|
||||
tagNameMap.put(new Integer(617), "Headline");
|
||||
tagNameMap.put(new Integer(552), "Special Instructions");
|
||||
tagNameMap.put(new Integer(592), "By-line");
|
||||
tagNameMap.put(new Integer(597), "By-line Title");
|
||||
tagNameMap.put(new Integer(622), "Credit");
|
||||
tagNameMap.put(new Integer(627), "Source");
|
||||
tagNameMap.put(new Integer(517), "Object Name");
|
||||
tagNameMap.put(new Integer(567), "Date Created");
|
||||
tagNameMap.put(new Integer(602), "City");
|
||||
tagNameMap.put(new Integer(607), "Province/State");
|
||||
tagNameMap.put(new Integer(613), "Country/Primary Location");
|
||||
tagNameMap.put(new Integer(615), "Original Transmission Reference");
|
||||
tagNameMap.put(new Integer(527), "Category");
|
||||
tagNameMap.put(new Integer(532), "Supplemental Category(s)");
|
||||
tagNameMap.put(new Integer(522), "Urgency");
|
||||
tagNameMap.put(new Integer(537), "Keywords");
|
||||
tagNameMap.put(new Integer(628), "Copyright Notice");
|
||||
tagNameMap.put(new Integer(542), "Release Date");
|
||||
tagNameMap.put(new Integer(547), "Release Time");
|
||||
tagNameMap.put(new Integer(572), "Time Created");
|
||||
tagNameMap.put(new Integer(577), "Originating Program");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package com.drew.metadata.iptc;
|
||||
|
||||
import com.drew.metadata.MetadataException;
|
||||
|
||||
public class IptcProcessingException extends MetadataException {
|
||||
public IptcProcessingException(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public IptcProcessingException(String paramString, Throwable paramThrowable) {
|
||||
super(paramString, paramThrowable);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
package com.drew.metadata.iptc;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegProcessingException;
|
||||
import com.drew.imaging.jpeg.JpegSegmentReader;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.MetadataReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
public class IptcReader implements MetadataReader {
|
||||
private final byte[] _data;
|
||||
|
||||
public IptcReader(File paramFile) throws JpegProcessingException, FileNotFoundException {
|
||||
this(new JpegSegmentReader(paramFile).readSegment((byte)-19));
|
||||
}
|
||||
|
||||
public IptcReader(byte[] paramArrayOfbyte) {
|
||||
this._data = paramArrayOfbyte;
|
||||
}
|
||||
|
||||
public Metadata extract() {
|
||||
return extract(new Metadata());
|
||||
}
|
||||
|
||||
public Metadata extract(Metadata paramMetadata) {
|
||||
if (this._data == null)
|
||||
return paramMetadata;
|
||||
Directory directory = paramMetadata.getDirectory(IptcDirectory.class);
|
||||
int i = 0;
|
||||
try {
|
||||
while (i < this._data.length - 1 && get32Bits(i) != 7170)
|
||||
i++;
|
||||
} catch (MetadataException e) {
|
||||
directory.addError("Couldn't find start of Iptc data (invalid segment)");
|
||||
return paramMetadata;
|
||||
}
|
||||
while (i < this._data.length && this._data[i] == 28 && i + 5 < this._data.length) {
|
||||
byte b1;
|
||||
byte b2;
|
||||
int j;
|
||||
i++;
|
||||
try {
|
||||
b1 = this._data[i++];
|
||||
b2 = this._data[i++];
|
||||
j = get32Bits(i);
|
||||
} catch (MetadataException e) {
|
||||
directory.addError("Iptc data segment ended mid-way through tag descriptor");
|
||||
return paramMetadata;
|
||||
}
|
||||
i += 2;
|
||||
if (i + j > this._data.length) {
|
||||
directory.addError("data for tag extends beyond end of iptc segment");
|
||||
break;
|
||||
}
|
||||
processTag(directory, b1, b2, i, j);
|
||||
i += j;
|
||||
}
|
||||
return paramMetadata;
|
||||
}
|
||||
|
||||
private int get32Bits(int paramInt) throws MetadataException {
|
||||
if (paramInt >= this._data.length)
|
||||
throw new MetadataException("Attempt to read bytes from outside Iptc data buffer");
|
||||
return (this._data[paramInt] & 0xFF) << 8 | this._data[paramInt + 1] & 0xFF;
|
||||
}
|
||||
|
||||
private void processTag(Directory paramDirectory, int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
|
||||
short s;
|
||||
String str;
|
||||
int i = paramInt2 | paramInt1 << 8;
|
||||
switch (i) {
|
||||
case 512:
|
||||
s = (short)(this._data[paramInt3] << 8 | this._data[paramInt3 + 1]);
|
||||
paramDirectory.setInt(i, s);
|
||||
return;
|
||||
case 522:
|
||||
paramDirectory.setInt(i, this._data[paramInt3]);
|
||||
return;
|
||||
case 542:
|
||||
case 567:
|
||||
if (paramInt4 >= 8) {
|
||||
String str1 = new String(this._data, paramInt3, paramInt4);
|
||||
try {
|
||||
int j = Integer.parseInt(str1.substring(0, 4));
|
||||
int k = Integer.parseInt(str1.substring(4, 6)) - 1;
|
||||
int m = Integer.parseInt(str1.substring(6, 8));
|
||||
Date date = new GregorianCalendar(j, k, m).getTime();
|
||||
paramDirectory.setDate(i, date);
|
||||
return;
|
||||
} catch (NumberFormatException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (paramInt4 < 1) {
|
||||
str = "";
|
||||
} else {
|
||||
str = new String(this._data, paramInt3, paramInt4);
|
||||
}
|
||||
if (paramDirectory.containsTag(i)) {
|
||||
Object object;
|
||||
String[] arrayOfString;
|
||||
try {
|
||||
object = paramDirectory.getStringArray(i);
|
||||
} catch (MetadataException e) {
|
||||
object = null;
|
||||
}
|
||||
if (object == null) {
|
||||
arrayOfString = new String[1];
|
||||
} else {
|
||||
arrayOfString = new String[object.length + 1];
|
||||
for (int j = 0; j < object.length; j++)
|
||||
arrayOfString[j] = object[j];
|
||||
}
|
||||
arrayOfString[arrayOfString.length - 1] = str;
|
||||
paramDirectory.setStringArray(i, arrayOfString);
|
||||
} else {
|
||||
paramDirectory.setString(i, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package com.drew.metadata.iptc.test;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.iptc.IptcDirectory;
|
||||
import com.drew.metadata.iptc.IptcReader;
|
||||
import java.io.File;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class IptcReaderTest extends TestCase {
|
||||
public IptcReaderTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testDescription_City() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/iptc/test/withIptc.jpg");
|
||||
IptcReader iptcReader = new IptcReader(file);
|
||||
Metadata metadata = iptcReader.extract();
|
||||
assertTrue(metadata.containsDirectory(IptcDirectory.class));
|
||||
Directory directory = metadata.getDirectory(IptcDirectory.class);
|
||||
assertEquals("City", directory.getDescription(602));
|
||||
}
|
||||
|
||||
public void testDescription_Caption() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/iptc/test/withIptc.jpg");
|
||||
IptcReader iptcReader = new IptcReader(file);
|
||||
Metadata metadata = iptcReader.extract();
|
||||
assertTrue(metadata.containsDirectory(IptcDirectory.class));
|
||||
Directory directory = metadata.getDirectory(IptcDirectory.class);
|
||||
assertEquals("Caption", directory.getDescription(632));
|
||||
}
|
||||
|
||||
public void testDescription_Category() throws Exception {
|
||||
File file = new File("src/com/drew/metadata/iptc/test/withIptc.jpg");
|
||||
IptcReader iptcReader = new IptcReader(file);
|
||||
Metadata metadata = iptcReader.extract();
|
||||
assertTrue(metadata.containsDirectory(IptcDirectory.class));
|
||||
Directory directory = metadata.getDirectory(IptcDirectory.class);
|
||||
assertEquals("Supl. Category2 Supl. Category1 Cat", directory.getDescription(527));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package com.drew.metadata.jpeg;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class JpegCommentDescriptor extends TagDescriptor {
|
||||
public JpegCommentDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) {
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.drew.metadata.jpeg;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class JpegCommentDirectory extends Directory {
|
||||
public static final int TAG_JPEG_COMMENT = 0;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public JpegCommentDirectory() {
|
||||
setDescriptor(new JpegCommentDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "JpegComment";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(0), "Jpeg Comment");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.drew.metadata.jpeg;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegProcessingException;
|
||||
import com.drew.imaging.jpeg.JpegSegmentReader;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.MetadataReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public class JpegCommentReader implements MetadataReader {
|
||||
private final byte[] _data;
|
||||
|
||||
public JpegCommentReader(File paramFile) throws JpegProcessingException, FileNotFoundException {
|
||||
this(new JpegSegmentReader(paramFile).readSegment((byte)-2));
|
||||
}
|
||||
|
||||
public JpegCommentReader(byte[] paramArrayOfbyte) {
|
||||
this._data = paramArrayOfbyte;
|
||||
}
|
||||
|
||||
public Metadata extract() {
|
||||
return extract(new Metadata());
|
||||
}
|
||||
|
||||
public Metadata extract(Metadata paramMetadata) {
|
||||
if (this._data == null)
|
||||
return paramMetadata;
|
||||
JpegCommentDirectory jpegCommentDirectory = (JpegCommentDirectory)paramMetadata.getDirectory(JpegCommentDirectory.class);
|
||||
jpegCommentDirectory.setString(0, new String(this._data));
|
||||
return paramMetadata;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.drew.metadata.jpeg;
|
||||
|
||||
import com.drew.metadata.MetadataException;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class JpegComponent implements Serializable {
|
||||
private final int _componentId;
|
||||
|
||||
private final int _samplingFactorByte;
|
||||
|
||||
private final int _quantizationTableNumber;
|
||||
|
||||
public JpegComponent(int paramInt1, int paramInt2, int paramInt3) {
|
||||
this._componentId = paramInt1;
|
||||
this._samplingFactorByte = paramInt2;
|
||||
this._quantizationTableNumber = paramInt3;
|
||||
}
|
||||
|
||||
public int getComponentId() {
|
||||
return this._componentId;
|
||||
}
|
||||
|
||||
public String getComponentName() throws MetadataException {
|
||||
switch (this._componentId) {
|
||||
case 1:
|
||||
return "Y";
|
||||
case 2:
|
||||
return "Cb";
|
||||
case 3:
|
||||
return "Cr";
|
||||
case 4:
|
||||
return "I";
|
||||
case 5:
|
||||
return "Q";
|
||||
}
|
||||
throw new MetadataException("Unsupported component id: " + this._componentId);
|
||||
}
|
||||
|
||||
public int getQuantizationTableNumber() {
|
||||
return this._quantizationTableNumber;
|
||||
}
|
||||
|
||||
public int getHorizontalSamplingFactor() {
|
||||
return this._samplingFactorByte & 0xF;
|
||||
}
|
||||
|
||||
public int getVerticalSamplingFactor() {
|
||||
return this._samplingFactorByte >> 4 & 0xF;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package com.drew.metadata.jpeg;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.TagDescriptor;
|
||||
|
||||
public class JpegDescriptor extends TagDescriptor {
|
||||
public JpegDescriptor(Directory paramDirectory) {
|
||||
super(paramDirectory);
|
||||
}
|
||||
|
||||
public String getDescription(int paramInt) throws MetadataException {
|
||||
switch (paramInt) {
|
||||
case 6:
|
||||
return getComponentDataDescription(0);
|
||||
case 7:
|
||||
return getComponentDataDescription(1);
|
||||
case 8:
|
||||
return getComponentDataDescription(2);
|
||||
case 9:
|
||||
return getComponentDataDescription(3);
|
||||
case 0:
|
||||
return getDataPrecisionDescription();
|
||||
case 1:
|
||||
return getImageHeightDescription();
|
||||
case 3:
|
||||
return getImageWidthDescription();
|
||||
}
|
||||
return this._directory.getString(paramInt);
|
||||
}
|
||||
|
||||
public String getImageWidthDescription() {
|
||||
return this._directory.getString(3) + " pixels";
|
||||
}
|
||||
|
||||
public String getImageHeightDescription() {
|
||||
return this._directory.getString(1) + " pixels";
|
||||
}
|
||||
|
||||
public String getDataPrecisionDescription() {
|
||||
return this._directory.getString(0) + " bits";
|
||||
}
|
||||
|
||||
public String getComponentDataDescription(int paramInt) throws MetadataException {
|
||||
JpegComponent jpegComponent = ((JpegDirectory)this._directory).getComponent(paramInt);
|
||||
if (jpegComponent == null)
|
||||
throw new MetadataException("No Jpeg component exists with number " + paramInt);
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
stringBuffer.append(jpegComponent.getComponentName());
|
||||
stringBuffer.append(" component: Quantization table ");
|
||||
stringBuffer.append(jpegComponent.getQuantizationTableNumber());
|
||||
stringBuffer.append(", Sampling factors ");
|
||||
stringBuffer.append(jpegComponent.getHorizontalSamplingFactor());
|
||||
stringBuffer.append(" horiz/");
|
||||
stringBuffer.append(jpegComponent.getVerticalSamplingFactor());
|
||||
stringBuffer.append(" vert");
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.drew.metadata.jpeg;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class JpegDirectory extends Directory {
|
||||
public static final int TAG_JPEG_DATA_PRECISION = 0;
|
||||
|
||||
public static final int TAG_JPEG_IMAGE_HEIGHT = 1;
|
||||
|
||||
public static final int TAG_JPEG_IMAGE_WIDTH = 3;
|
||||
|
||||
public static final int TAG_JPEG_NUMBER_OF_COMPONENTS = 5;
|
||||
|
||||
public static final int TAG_JPEG_COMPONENT_DATA_1 = 6;
|
||||
|
||||
public static final int TAG_JPEG_COMPONENT_DATA_2 = 7;
|
||||
|
||||
public static final int TAG_JPEG_COMPONENT_DATA_3 = 8;
|
||||
|
||||
public static final int TAG_JPEG_COMPONENT_DATA_4 = 9;
|
||||
|
||||
protected static final HashMap tagNameMap = new HashMap();
|
||||
|
||||
public JpegDirectory() {
|
||||
setDescriptor(new JpegDescriptor(this));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Jpeg";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return tagNameMap;
|
||||
}
|
||||
|
||||
public JpegComponent getComponent(int paramInt) {
|
||||
int i = 6 + paramInt;
|
||||
return (JpegComponent)getObject(i);
|
||||
}
|
||||
|
||||
public int getImageWidth() throws MetadataException {
|
||||
return getInt(3);
|
||||
}
|
||||
|
||||
public int getImageHeight() throws MetadataException {
|
||||
return getInt(1);
|
||||
}
|
||||
|
||||
public int getNumberOfComponents() throws MetadataException {
|
||||
return getInt(5);
|
||||
}
|
||||
|
||||
static {
|
||||
tagNameMap.put(new Integer(0), "Data Precision");
|
||||
tagNameMap.put(new Integer(3), "Image Width");
|
||||
tagNameMap.put(new Integer(1), "Image Height");
|
||||
tagNameMap.put(new Integer(5), "Number of Components");
|
||||
tagNameMap.put(new Integer(6), "Component 1");
|
||||
tagNameMap.put(new Integer(7), "Component 2");
|
||||
tagNameMap.put(new Integer(8), "Component 3");
|
||||
tagNameMap.put(new Integer(9), "Component 4");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package com.drew.metadata.jpeg;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegProcessingException;
|
||||
import com.drew.imaging.jpeg.JpegSegmentReader;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.MetadataReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public class JpegReader implements MetadataReader {
|
||||
private final byte[] _data;
|
||||
|
||||
public JpegReader(File paramFile) throws JpegProcessingException, FileNotFoundException {
|
||||
this(new JpegSegmentReader(paramFile).readSegment((byte)-64));
|
||||
}
|
||||
|
||||
public JpegReader(byte[] paramArrayOfbyte) {
|
||||
this._data = paramArrayOfbyte;
|
||||
}
|
||||
|
||||
public Metadata extract() {
|
||||
return extract(new Metadata());
|
||||
}
|
||||
|
||||
public Metadata extract(Metadata paramMetadata) {
|
||||
if (this._data == null)
|
||||
return paramMetadata;
|
||||
JpegDirectory jpegDirectory = (JpegDirectory)paramMetadata.getDirectory(JpegDirectory.class);
|
||||
try {
|
||||
int i = get16Bits(0);
|
||||
jpegDirectory.setInt(0, i);
|
||||
int j = get32Bits(1);
|
||||
jpegDirectory.setInt(1, j);
|
||||
int k = get32Bits(3);
|
||||
jpegDirectory.setInt(3, k);
|
||||
int m = get16Bits(5);
|
||||
jpegDirectory.setInt(5, m);
|
||||
int n = 6;
|
||||
for (int i1 = 0; i1 < m; i1++) {
|
||||
int i2 = get16Bits(n++);
|
||||
int i3 = get16Bits(n++);
|
||||
int i4 = get16Bits(n++);
|
||||
JpegComponent jpegComponent = new JpegComponent(i2, i3, i4);
|
||||
jpegDirectory.setObject(6 + i1, jpegComponent);
|
||||
}
|
||||
} catch (MetadataException e) {
|
||||
jpegDirectory.addError("MetadataException: " + e);
|
||||
}
|
||||
return paramMetadata;
|
||||
}
|
||||
|
||||
private int get32Bits(int paramInt) throws MetadataException {
|
||||
if (paramInt + 1 >= this._data.length)
|
||||
throw new MetadataException("Attempt to read bytes from outside Jpeg segment data buffer");
|
||||
return (this._data[paramInt] & 0xFF) << 8 | this._data[paramInt + 1] & 0xFF;
|
||||
}
|
||||
|
||||
private int get16Bits(int paramInt) throws MetadataException {
|
||||
if (paramInt >= this._data.length)
|
||||
throw new MetadataException("Attempt to read bytes from outside Jpeg segment data buffer");
|
||||
return this._data[paramInt] & 0xFF;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.drew.metadata.jpeg.test;
|
||||
|
||||
import com.drew.metadata.jpeg.JpegComponent;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class JpegComponentTest extends TestCase {
|
||||
public JpegComponentTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testGetComponentCharacter() throws Exception {
|
||||
JpegComponent jpegComponent = new JpegComponent(1, 2, 3);
|
||||
assertEquals("Y", jpegComponent.getComponentName());
|
||||
jpegComponent = new JpegComponent(2, 2, 3);
|
||||
assertEquals("Cb", jpegComponent.getComponentName());
|
||||
jpegComponent = new JpegComponent(3, 2, 3);
|
||||
assertEquals("Cr", jpegComponent.getComponentName());
|
||||
jpegComponent = new JpegComponent(4, 2, 3);
|
||||
assertEquals("I", jpegComponent.getComponentName());
|
||||
jpegComponent = new JpegComponent(5, 2, 3);
|
||||
assertEquals("Q", jpegComponent.getComponentName());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package com.drew.metadata.jpeg.test;
|
||||
|
||||
import com.drew.metadata.MetadataException;
|
||||
import com.drew.metadata.jpeg.JpegComponent;
|
||||
import com.drew.metadata.jpeg.JpegDescriptor;
|
||||
import com.drew.metadata.jpeg.JpegDirectory;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class JpegDescriptorTest extends TestCase {
|
||||
private JpegDirectory _directory;
|
||||
|
||||
private JpegDescriptor _descriptor;
|
||||
|
||||
public JpegDescriptorTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void setUp() throws Exception {
|
||||
this._directory = new JpegDirectory();
|
||||
this._descriptor = new JpegDescriptor(this._directory);
|
||||
}
|
||||
|
||||
public void testGetComponentDataDescription_InvalidComponentNumber() throws Exception {
|
||||
try {
|
||||
this._descriptor.getComponentDataDescription(1);
|
||||
fail("Excepted exception");
|
||||
} catch (MetadataException e) {}
|
||||
}
|
||||
|
||||
public void testGetImageWidthDescription() throws Exception {
|
||||
this._directory.setInt(3, 123);
|
||||
assertEquals("123 pixels", this._descriptor.getImageWidthDescription());
|
||||
assertEquals("123 pixels", this._directory.getDescription(3));
|
||||
}
|
||||
|
||||
public void testGetImageHeightDescription() throws Exception {
|
||||
this._directory.setInt(1, 123);
|
||||
assertEquals("123 pixels", this._descriptor.getImageHeightDescription());
|
||||
assertEquals("123 pixels", this._directory.getDescription(1));
|
||||
}
|
||||
|
||||
public void testGetDataPrecisionDescription() throws Exception {
|
||||
this._directory.setInt(0, 8);
|
||||
assertEquals("8 bits", this._descriptor.getDataPrecisionDescription());
|
||||
assertEquals("8 bits", this._directory.getDescription(0));
|
||||
}
|
||||
|
||||
public void testGetComponentDescription() throws MetadataException {
|
||||
JpegComponent jpegComponent = new JpegComponent(1, 34, 0);
|
||||
this._directory.setObject(6, jpegComponent);
|
||||
assertEquals("Y component: Quantization table 0, Sampling factors 2 horiz/2 vert", this._directory.getDescription(6));
|
||||
assertEquals("Y component: Quantization table 0, Sampling factors 2 horiz/2 vert", this._descriptor.getComponentDataDescription(0));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package com.drew.metadata.jpeg.test;
|
||||
|
||||
import com.drew.metadata.jpeg.JpegComponent;
|
||||
import com.drew.metadata.jpeg.JpegDirectory;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class JpegDirectoryTest extends TestCase {
|
||||
private JpegDirectory _directory;
|
||||
|
||||
public JpegDirectoryTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void setUp() {
|
||||
this._directory = new JpegDirectory();
|
||||
}
|
||||
|
||||
public void testSetAndGetValue() throws Exception {
|
||||
this._directory.setInt(123, 8);
|
||||
assertEquals(8, this._directory.getInt(123));
|
||||
}
|
||||
|
||||
public void testGetComponent_NotAdded() {
|
||||
assertNull(this._directory.getComponent(1));
|
||||
}
|
||||
|
||||
public void testGetImageWidth() throws Exception {
|
||||
this._directory.setInt(3, 123);
|
||||
assertEquals(123, this._directory.getImageWidth());
|
||||
}
|
||||
|
||||
public void testGetImageHeight() throws Exception {
|
||||
this._directory.setInt(1, 123);
|
||||
assertEquals(123, this._directory.getImageHeight());
|
||||
}
|
||||
|
||||
public void testGetNumberOfComponents() throws Exception {
|
||||
this._directory.setInt(5, 3);
|
||||
assertEquals(3, this._directory.getNumberOfComponents());
|
||||
assertEquals("3", this._directory.getDescription(5));
|
||||
}
|
||||
|
||||
public void testGetComponent() throws Exception {
|
||||
JpegComponent jpegComponent1 = new JpegComponent(1, 2, 3);
|
||||
JpegComponent jpegComponent2 = new JpegComponent(1, 2, 3);
|
||||
JpegComponent jpegComponent3 = new JpegComponent(1, 2, 3);
|
||||
JpegComponent jpegComponent4 = new JpegComponent(1, 2, 3);
|
||||
this._directory.setObject(6, jpegComponent1);
|
||||
this._directory.setObject(7, jpegComponent2);
|
||||
this._directory.setObject(8, jpegComponent3);
|
||||
this._directory.setObject(9, jpegComponent4);
|
||||
assertSame(jpegComponent1, this._directory.getComponent(0));
|
||||
assertSame(jpegComponent2, this._directory.getComponent(1));
|
||||
assertSame(jpegComponent3, this._directory.getComponent(2));
|
||||
assertSame(jpegComponent4, this._directory.getComponent(3));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
package com.drew.metadata.jpeg.test;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegProcessingException;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.jpeg.JpegComponent;
|
||||
import com.drew.metadata.jpeg.JpegDirectory;
|
||||
import com.drew.metadata.jpeg.JpegReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class JpegReaderTest extends TestCase {
|
||||
private JpegDirectory _directory;
|
||||
|
||||
public JpegReaderTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void setUp() throws JpegProcessingException, FileNotFoundException {
|
||||
File file = new File("src/com/drew/metadata/jpeg/test/simple.jpg");
|
||||
JpegReader jpegReader = new JpegReader(file);
|
||||
Metadata metadata = jpegReader.extract();
|
||||
assertTrue(metadata.containsDirectory(JpegDirectory.class));
|
||||
this._directory = (JpegDirectory)metadata.getDirectory(JpegDirectory.class);
|
||||
}
|
||||
|
||||
public void testExtract_Width() throws Exception {
|
||||
assertEquals(800, this._directory.getInt(3));
|
||||
}
|
||||
|
||||
public void testExtract_Height() throws Exception {
|
||||
assertEquals(600, this._directory.getInt(1));
|
||||
}
|
||||
|
||||
public void testExtract_DataPrecision() throws Exception {
|
||||
assertEquals(8, this._directory.getInt(0));
|
||||
}
|
||||
|
||||
public void testExtract_NumberOfComponents() throws Exception {
|
||||
assertEquals(3, this._directory.getInt(5));
|
||||
}
|
||||
|
||||
public void testComponentData1() throws Exception {
|
||||
JpegComponent jpegComponent = (JpegComponent)this._directory.getObject(6);
|
||||
assertEquals("Y", jpegComponent.getComponentName());
|
||||
assertEquals(1, jpegComponent.getComponentId());
|
||||
assertEquals(0, jpegComponent.getQuantizationTableNumber());
|
||||
assertEquals(2, jpegComponent.getHorizontalSamplingFactor());
|
||||
assertEquals(2, jpegComponent.getVerticalSamplingFactor());
|
||||
}
|
||||
|
||||
public void testComponentData2() throws Exception {
|
||||
JpegComponent jpegComponent = (JpegComponent)this._directory.getObject(7);
|
||||
assertEquals("Cb", jpegComponent.getComponentName());
|
||||
assertEquals(2, jpegComponent.getComponentId());
|
||||
assertEquals(1, jpegComponent.getQuantizationTableNumber());
|
||||
assertEquals(1, jpegComponent.getHorizontalSamplingFactor());
|
||||
assertEquals(1, jpegComponent.getVerticalSamplingFactor());
|
||||
assertEquals("Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert", this._directory.getDescription(7));
|
||||
}
|
||||
|
||||
public void testComponentData3() throws Exception {
|
||||
JpegComponent jpegComponent = (JpegComponent)this._directory.getObject(8);
|
||||
assertEquals("Cr", jpegComponent.getComponentName());
|
||||
assertEquals(3, jpegComponent.getComponentId());
|
||||
assertEquals(1, jpegComponent.getQuantizationTableNumber());
|
||||
assertEquals(1, jpegComponent.getHorizontalSamplingFactor());
|
||||
assertEquals(1, jpegComponent.getVerticalSamplingFactor());
|
||||
assertEquals("Cr component: Quantization table 1, Sampling factors 1 horiz/1 vert", this._directory.getDescription(8));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.drew.metadata.test;
|
||||
|
||||
import com.drew.imaging.jpeg.test.JpegMetadataReaderTest;
|
||||
import com.drew.imaging.jpeg.test.JpegSegmentReaderTest;
|
||||
import com.drew.lang.test.CompoundExceptionTest;
|
||||
import com.drew.lang.test.NullOutputStreamTest;
|
||||
import com.drew.lang.test.RationalTest;
|
||||
import com.drew.metadata.exif.test.ExifDescriptorTest;
|
||||
import com.drew.metadata.exif.test.ExifDirectoryTest;
|
||||
import com.drew.metadata.exif.test.ExifReaderTest;
|
||||
import com.drew.metadata.exif.test.NikonType1MakernoteTest;
|
||||
import com.drew.metadata.exif.test.NikonType2MakernoteTest;
|
||||
import com.drew.metadata.exif.test.NikonType3MakernoteTest;
|
||||
import com.drew.metadata.iptc.test.IptcReaderTest;
|
||||
import com.drew.metadata.jpeg.test.JpegComponentTest;
|
||||
import com.drew.metadata.jpeg.test.JpegDescriptorTest;
|
||||
import com.drew.metadata.jpeg.test.JpegDirectoryTest;
|
||||
import com.drew.metadata.jpeg.test.JpegReaderTest;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
public class AllTests extends TestSuite {
|
||||
public static Test suite() {
|
||||
TestSuite testSuite = new TestSuite();
|
||||
testSuite.addTestSuite(DirectoryTest.class);
|
||||
testSuite.addTestSuite(ExifDirectoryTest.class);
|
||||
testSuite.addTestSuite(ExifReaderTest.class);
|
||||
testSuite.addTestSuite(ExifDescriptorTest.class);
|
||||
testSuite.addTestSuite(IptcReaderTest.class);
|
||||
testSuite.addTestSuite(MetadataTest.class);
|
||||
testSuite.addTestSuite(JpegReaderTest.class);
|
||||
testSuite.addTestSuite(JpegDirectoryTest.class);
|
||||
testSuite.addTestSuite(JpegComponentTest.class);
|
||||
testSuite.addTestSuite(JpegDescriptorTest.class);
|
||||
testSuite.addTestSuite(NikonType1MakernoteTest.class);
|
||||
testSuite.addTestSuite(NikonType2MakernoteTest.class);
|
||||
testSuite.addTestSuite(NikonType3MakernoteTest.class);
|
||||
testSuite.addTestSuite(CompoundExceptionTest.class);
|
||||
testSuite.addTestSuite(NullOutputStreamTest.class);
|
||||
testSuite.addTestSuite(RationalTest.class);
|
||||
testSuite.addTestSuite(JpegMetadataReaderTest.class);
|
||||
testSuite.addTestSuite(JpegSegmentReaderTest.class);
|
||||
return (Test)testSuite;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
package com.drew.metadata.test;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.Metadata;
|
||||
import java.util.GregorianCalendar;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class DirectoryTest extends TestCase {
|
||||
public DirectoryTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testSetAndGetInt() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory = metadata.getDirectory(MockDirectory.class);
|
||||
int i = 321;
|
||||
int j = 123;
|
||||
directory.setInt(j, i);
|
||||
assertEquals(i, directory.getInt(j));
|
||||
assertEquals(Integer.toString(i), directory.getString(j));
|
||||
}
|
||||
|
||||
public void testSetAndGetIntArray() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory = metadata.getDirectory(MockDirectory.class);
|
||||
int[] arrayOfInt1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
int i = 123;
|
||||
directory.setIntArray(i, arrayOfInt1);
|
||||
int[] arrayOfInt2 = directory.getIntArray(i);
|
||||
assertEquals(arrayOfInt1.length, arrayOfInt2.length);
|
||||
for (int j = 0; j < arrayOfInt1.length; j++) {
|
||||
int m = arrayOfInt1[j];
|
||||
int n = arrayOfInt2[j];
|
||||
assertEquals(m, n);
|
||||
}
|
||||
assertEquals(arrayOfInt1, directory.getIntArray(i));
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (int k = 0; k < arrayOfInt1.length; k++) {
|
||||
int m = arrayOfInt1[k];
|
||||
if (k > 0)
|
||||
stringBuffer.append(' ');
|
||||
stringBuffer.append(m);
|
||||
}
|
||||
assertEquals(stringBuffer.toString(), directory.getString(i));
|
||||
}
|
||||
|
||||
public void testSetStringAndGetDate() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory = metadata.getDirectory(MockDirectory.class);
|
||||
String str1 = "2002:01:30 24:59:59";
|
||||
String str2 = "2002:01:30 24:59";
|
||||
String str3 = "2002-01-30 24:59:59";
|
||||
String str4 = "2002-01-30 24:59";
|
||||
directory.setString(1, str1);
|
||||
directory.setString(2, str2);
|
||||
directory.setString(3, str3);
|
||||
directory.setString(4, str4);
|
||||
assertEquals(str1, directory.getString(1));
|
||||
assertEquals(new GregorianCalendar(2002, 0, 30, 24, 59, 59).getTime(), directory.getDate(1));
|
||||
assertEquals(new GregorianCalendar(2002, 0, 30, 24, 59, 0).getTime(), directory.getDate(2));
|
||||
assertEquals(new GregorianCalendar(2002, 0, 30, 24, 59, 59).getTime(), directory.getDate(3));
|
||||
assertEquals(new GregorianCalendar(2002, 0, 30, 24, 59, 0).getTime(), directory.getDate(4));
|
||||
}
|
||||
|
||||
public void testSetIntArrayGetByteArray() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory = metadata.getDirectory(MockDirectory.class);
|
||||
int[] arrayOfInt = { 1, 2, 3, 4, 5 };
|
||||
directory.setIntArray(1, arrayOfInt);
|
||||
assertEquals(arrayOfInt.length, (directory.getByteArray(1)).length);
|
||||
assertEquals(1, directory.getByteArray(1)[0]);
|
||||
}
|
||||
|
||||
public void testSetStringGetInt() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory = metadata.getDirectory(MockDirectory.class);
|
||||
byte[] arrayOfByte = { 1, 1 };
|
||||
directory.setString(1, new String(arrayOfByte));
|
||||
assertEquals(257, directory.getInt(1));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
package com.drew.metadata.test;
|
||||
|
||||
import com.drew.imaging.jpeg.JpegMetadataReader;
|
||||
import com.drew.lang.NullOutputStream;
|
||||
import com.drew.metadata.Directory;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.exif.ExifDirectory;
|
||||
import com.drew.metadata.exif.GpsDirectory;
|
||||
import com.drew.metadata.iptc.IptcDirectory;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Iterator;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class MetadataTest extends TestCase {
|
||||
public MetadataTest(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public void testSetAndGetSingleTag() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
directory.setInt(37378, 1);
|
||||
assertEquals(1, directory.getInt(37378));
|
||||
}
|
||||
|
||||
public void testSetSameTagMultpleTimes() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
directory.setInt(37378, 1);
|
||||
directory.setInt(37378, 2);
|
||||
assertEquals("setting the tag with a different value should override old value", 2, directory.getInt(37378));
|
||||
}
|
||||
|
||||
public void testGetDirectory() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
assertTrue(metadata.getDirectory(ExifDirectory.class) instanceof ExifDirectory);
|
||||
}
|
||||
|
||||
public void testSetAndGetMultipleTagsInSingleDirectory() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
directory.setString(37378, "Tag Value");
|
||||
directory.setString(33423, "Another tag");
|
||||
assertEquals("Tag Value", directory.getString(37378));
|
||||
assertEquals("Another tag", directory.getString(33423));
|
||||
}
|
||||
|
||||
public void testSetAndGetMultipleTagsInMultilpeDirectories() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory1 = metadata.getDirectory(ExifDirectory.class);
|
||||
Directory directory2 = metadata.getDirectory(GpsDirectory.class);
|
||||
directory1.setString(37378, "ExifAperture");
|
||||
directory1.setString(33423, "ExifBatteryLevel");
|
||||
directory2.setString(6, "GpsAltitude");
|
||||
directory2.setString(24, "GpsDestBearing");
|
||||
assertEquals("ExifAperture", directory1.getString(37378));
|
||||
assertEquals("ExifBatteryLevel", directory1.getString(33423));
|
||||
assertEquals("GpsAltitude", directory2.getString(6));
|
||||
assertEquals("GpsDestBearing", directory2.getString(24));
|
||||
}
|
||||
|
||||
public void testContainsTag() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
assertTrue(!directory.containsTag(37378));
|
||||
directory.setString(37378, "Tag Value");
|
||||
assertTrue(directory.containsTag(37378));
|
||||
}
|
||||
|
||||
public void testGetNonExistantTag() throws Exception {
|
||||
Metadata metadata = new Metadata();
|
||||
Directory directory = metadata.getDirectory(ExifDirectory.class);
|
||||
assertEquals(null, directory.getString(37378));
|
||||
}
|
||||
|
||||
public void testHasErrors() throws Exception {
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(new File("src/com/drew/metadata/exif/test/badExif.jpg"));
|
||||
assertTrue("exif error", metadata.getDirectory(ExifDirectory.class).hasErrors());
|
||||
metadata = JpegMetadataReader.readMetadata(new File("src/com/drew/metadata/exif/test/withExif.jpg"));
|
||||
assertTrue("no errors", !metadata.getDirectory(ExifDirectory.class).hasErrors());
|
||||
}
|
||||
|
||||
public void testGetErrors() throws Exception {
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(new File("src/com/drew/metadata/exif/test/badExif.jpg"));
|
||||
Iterator iterator = metadata.getDirectory(ExifDirectory.class).getErrors();
|
||||
assertTrue(iterator.hasNext());
|
||||
String str = (String)iterator.next();
|
||||
assertEquals("Exif data segment must contain at least 14 bytes", str);
|
||||
assertTrue(!iterator.hasNext());
|
||||
}
|
||||
|
||||
public void testGetErrorCount() throws Exception {
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(new File("src/com/drew/metadata/exif/test/badExif.jpg"));
|
||||
assertEquals(1, metadata.getDirectory(ExifDirectory.class).getErrorCount());
|
||||
}
|
||||
|
||||
public void testMetadataSerializable() throws Exception {
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(new File("src/com/drew/metadata/test/withIptcExifGps.jpg"));
|
||||
new ObjectOutputStream(new NullOutputStream()).writeObject(metadata);
|
||||
}
|
||||
|
||||
public void testSerializeAndRestore() throws Exception {
|
||||
Metadata metadata = JpegMetadataReader.readMetadata(new File("src/com/drew/metadata/test/withIptcExifGps.jpg"));
|
||||
File file = File.createTempFile("test", "ser");
|
||||
try {
|
||||
new ObjectOutputStream(new FileOutputStream(file)).writeObject(metadata);
|
||||
Metadata metadata1 = (Metadata)new ObjectInputStream(new FileInputStream(file)).readObject();
|
||||
assertTrue(metadata1.containsDirectory(ExifDirectory.class));
|
||||
assertTrue(metadata1.containsDirectory(IptcDirectory.class));
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.drew.metadata.test;
|
||||
|
||||
import com.drew.metadata.Directory;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MockDirectory extends Directory {
|
||||
private final HashMap _tagNameMap = new HashMap();
|
||||
|
||||
public String getName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
protected HashMap getTagNameMap() {
|
||||
return this._tagNameMap;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue