throws BadImageFileException, IOException, UnknownImageTypeException
{
if (!USE_EMBEDDED_PREVIEW)
return super.getPreviewImage(imageInfo, maxWidth, maxHeight);
final ImageMetadataDirectory dir =
imageInfo.getMetadata().getDirectoryFor( MinoltaDirectory.class );
if ( dir == null ) {
//
// This should never be null, but just in case ...
//
return null;
}
//
// We can't just call createWritableRasterFrom() directly using the
// ImageInfo.getByteBuffer() because Minolta is being annoying by
// deliberately obfuscating the preview image: they change the first
// byte of the JPEG from FF to some other value (I've seen 02).
//
// We have to redo a lot of what createWritableRasterFrom() does here
// so we can get a hold of the buffer and change the fist byte back to
// FF. Because we have to modify it, it can't be a FileByteBuffer, so
// we have to copy it into an ArrayByteBuffer.
//
final ImageMetaValue offsetValue =
dir.getValue( MINOLTA_PREVIEW_IMAGE_START );
final ImageMetaValue lengthValue =
dir.getValue( MINOLTA_PREVIEW_IMAGE_LENGTH );
if ( offsetValue == null || lengthValue == null )
return null;
final int offset = offsetValue.getIntValue();
final int length = lengthValue.getIntValue();
if ( offset <= 0 || length <= 0 )