//
// This code is based on the code in TIFFMetadataReader but it's been
// simplified and does much less error-checking because we just wrote
// the TIFF file ourselves so we know it's valid.
//
final OrderableRandomAccessFile file =
new OrderableRandomAccessFile( fileName, "rw" );
try {
if ( file.readShort() == TIFF_LITTLE_ENDIAN )
file.order( ByteOrder.LITTLE_ENDIAN );
file.seek( TIFF_HEADER_SIZE - TIFF_INT_SIZE );
int ifdOffset = file.readInt();
while ( ifdOffset > 0 ) {
file.seek( ifdOffset );
final int entryCount = file.readUnsignedShort();
for ( int entry = 0; entry < entryCount; ++entry ) {
final int entryOffset =
TIFFMetadataReader.calcIFDEntryOffset( ifdOffset, entry );
file.seek( entryOffset );
final int tagID = file.readUnsignedShort();
if ( tagID == TIFF_PHOTOSHOP_IMAGE_RESOURCES ) {
file.seek( file.getFilePointer() - TIFF_SHORT_SIZE );
file.writeShort( TIFF_EXIF_IFD_POINTER );
file.writeShort( TIFF_FIELD_TYPE_ULONG );
file.writeInt( 1 );
final int subdirOffset = file.readInt();
fixEXIFDirectory( file, subdirOffset, 0 );
return;
}
}
ifdOffset = file.readInt();
}
}
finally {
file.close();
}
}