X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdrew%2Fjpeg%2FExifReader.java;h=0084b87b169a6b0913f386e677c34e15aaeb757f;hb=1ee49ae3c8ef3aa2e63eadd458531e5f8bd4f92c;hp=1637a9dbc633639d4126c2e892f58ce9f7e03498;hpb=da0b1f449260a0b4a94318006382a9039726ef3e;p=GpsPrune.git diff --git a/tim/prune/drew/jpeg/ExifReader.java b/tim/prune/drew/jpeg/ExifReader.java index 1637a9d..0084b87 100644 --- a/tim/prune/drew/jpeg/ExifReader.java +++ b/tim/prune/drew/jpeg/ExifReader.java @@ -25,31 +25,27 @@ public class ExifReader /** Thumbnail length */ private int _thumbnailLength = -1; - /** - * The number of bytes used per format descriptor. - */ + /** The number of bytes used per format descriptor */ private static final int[] BYTES_PER_FORMAT = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8}; - /** - * The number of formats known. - */ + /** The number of formats known */ private static final int MAX_FORMAT_CODE = 12; // Format types // Note: Cannot use the DataFormat enumeration in the case statement that uses these tags. // Is there a better way? - private static final int FMT_BYTE = 1; + //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_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_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; + //private static final int FMT_SINGLE = 11; + //private static final int FMT_DOUBLE = 12; public static final int TAG_EXIF_OFFSET = 0x8769; public static final int TAG_INTEROP_OFFSET = 0xA005; @@ -82,10 +78,12 @@ public class ExifReader private static final int TAG_THUMBNAIL_OFFSET = 0x0201; /** Thumbnail length */ private static final int TAG_THUMBNAIL_LENGTH = 0x0202; + /** Orientation of image */ + private static final int TAG_ORIENTATION = 0x0112; /** - * Creates an ExifReader for a Jpeg file. + * Creates an ExifReader for a Jpeg file * @param inFile File object to attempt to read from * @throws JpegException on failure */ @@ -144,7 +142,7 @@ public class ExifReader firstDirectoryOffset = 14; } - HashMap processedDirectoryOffsets = new HashMap(); + HashMap processedDirectoryOffsets = new HashMap(); // 0th IFD (we merge with Exif IFD) processDirectory(metadata, false, processedDirectoryOffsets, firstDirectoryOffset, TIFF_HEADER_START_OFFSET); @@ -179,15 +177,15 @@ public class ExifReader * 2 bytes: format code * 4 bytes: component count */ - private void processDirectory(JpegData inMetadata, boolean inIsGPS, HashMap inDirectoryOffsets, + private void processDirectory(JpegData inMetadata, boolean inIsGPS, HashMap inDirectoryOffsets, int inDirOffset, int inTiffHeaderOffset) { // check for directories we've already visited to avoid stack overflows when recursive/cyclic directory structures exist - if (inDirectoryOffsets.containsKey(new Integer(inDirOffset))) + if (inDirectoryOffsets.containsKey(Integer.valueOf(inDirOffset))) return; // remember that we've visited this directory so that we don't visit it again later - inDirectoryOffsets.put(new Integer(inDirOffset), "processed"); + inDirectoryOffsets.put(Integer.valueOf(inDirOffset), "processed"); if (inDirOffset >= _data.length || inDirOffset < 0) { @@ -387,6 +385,11 @@ public class ExifReader _thumbnailLength = get16Bits(inTagValueOffset); extractThumbnail(inMetadata); } + else if (inTagType == TAG_ORIENTATION) { + if (inMetadata.getOrientationCode() < 1) { + inMetadata.setOrientationCode(get16Bits(inTagValueOffset)); + } + } } /** @@ -415,7 +418,7 @@ public class ExifReader if (inByteCount > 4) { // If it's bigger than 4 bytes, the dir entry contains an offset. - // dirEntryOffset must be passed, as some makernote implementations (e.g. FujiFilm) incorrectly use an + // dirEntryOffset must be passed, as some makers (e.g. FujiFilm) incorrectly use an // offset relative to the start of the makernote itself, not the TIFF segment. final int offsetVal = get32Bits(inDirEntryOffset + 8); if (offsetVal + inByteCount > _data.length) @@ -510,7 +513,8 @@ public class ExifReader private int get16Bits(int offset) { if (offset<0 || offset+2>_data.length) - throw new ArrayIndexOutOfBoundsException("attempt to read data outside of exif segment (index " + offset + " where max index is " + (_data.length - 1) + ")"); + throw new ArrayIndexOutOfBoundsException("attempt to read data outside of exif segment (index " + + offset + " where max index is " + (_data.length - 1) + ")"); if (_isMotorolaByteOrder) { // Motorola - MSB first