use of com.drew.metadata.exif.ExifIFD0Directory in project react-native-camera by lwansbrough.
the class MutableImage method fixOrientation.
public void fixOrientation() throws ImageMutationFailedException {
try {
Metadata metadata = originalImageMetaData();
ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
if (exifIFD0Directory == null) {
return;
} else if (exifIFD0Directory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
int exifOrientation = exifIFD0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
if (exifOrientation != 1) {
rotate(exifOrientation);
exifIFD0Directory.setInt(ExifIFD0Directory.TAG_ORIENTATION, 1);
}
}
} catch (ImageProcessingException | IOException | MetadataException e) {
throw new ImageMutationFailedException("failed to fix orientation", e);
}
}
use of com.drew.metadata.exif.ExifIFD0Directory in project tika by apache.
the class ImageMetadataExtractorTest method testExifHandlerParseDateError.
@Test
public void testExifHandlerParseDateError() throws MetadataException {
ExifIFD0Directory exif = mock(ExifIFD0Directory.class);
when(exif.containsTag(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL)).thenReturn(true);
when(exif.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL)).thenReturn(null);
Metadata metadata = new Metadata();
new ImageMetadataExtractor.ExifHandler().handle(exif, metadata);
assertEquals("Parsing should proceed without date", null, metadata.get(TikaCoreProperties.CREATED));
}
use of com.drew.metadata.exif.ExifIFD0Directory in project UniversalMediaServer by UniversalMediaServer.
the class ExifInfo method parseMetadata.
@SuppressFBWarnings("SF_SWITCH_NO_DEFAULT")
@Override
protected void parseMetadata(Metadata metadata) {
if (metadata == null) {
return;
}
((ExifParseInfo) parsedInfo).hasExifThumbnail = false;
for (Directory directory : metadata.getDirectories()) {
if (directory instanceof ExifIFD0Directory || directory instanceof ExifSubIFDDirectory) {
if (// Prefer Exif SubIFD Exif image width and height as they seem to be more accurate.
directory instanceof ExifSubIFDDirectory && ((ExifSubIFDDirectory) directory).containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH) && ((ExifSubIFDDirectory) directory).containsTag(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT)) {
parsedInfo.width = ((ExifSubIFDDirectory) directory).getInteger(ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH);
parsedInfo.height = ((ExifSubIFDDirectory) directory).getInteger(ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT);
} else if ((parsedInfo.width == null || parsedInfo.height == null || parsedInfo.width < 1 || parsedInfo.height < 1) && ((ExifDirectoryBase) directory).containsTag(ExifDirectoryBase.TAG_IMAGE_WIDTH) && ((ExifDirectoryBase) directory).containsTag(ExifDirectoryBase.TAG_IMAGE_HEIGHT)) {
parsedInfo.width = ((ExifDirectoryBase) directory).getInteger(ExifDirectoryBase.TAG_IMAGE_WIDTH);
parsedInfo.height = ((ExifDirectoryBase) directory).getInteger(ExifDirectoryBase.TAG_IMAGE_HEIGHT);
}
if (((ExifDirectoryBase) directory).containsTag(ExifDirectoryBase.TAG_ORIENTATION)) {
Integer i = ((ExifDirectoryBase) directory).getInteger(ExifDirectoryBase.TAG_ORIENTATION);
if (i != null) {
((ExifParseInfo) parsedInfo).exifOrientation = ExifOrientation.typeOf(i);
}
}
if (((ExifDirectoryBase) directory).containsTag(ExifDirectoryBase.TAG_COMPRESSION) && ((ExifParseInfo) parsedInfo).exifCompression == null) {
Integer i = ((ExifDirectoryBase) directory).getInteger(ExifDirectoryBase.TAG_COMPRESSION);
if (i != null) {
((ExifParseInfo) parsedInfo).exifCompression = ExifCompression.typeOf(i);
}
}
if (((ExifDirectoryBase) directory).containsTag(ExifDirectoryBase.TAG_BITS_PER_SAMPLE) && ((ExifParseInfo) parsedInfo).exifCompression == ExifCompression.UNCOMPRESSED) {
byte[] bytes = ((ExifDirectoryBase) directory).getByteArray(ExifDirectoryBase.TAG_BITS_PER_SAMPLE);
if (bytes != null && bytes.length > 0) {
Integer i;
try {
i = Integer.valueOf(ImagesUtil.getBitDepthFromArray(bytes));
} catch (InvalidStateException e) {
i = null;
LOGGER.trace("Unexpected bit depth array retrieved from Exif tag: {}", Arrays.toString(bytes));
}
if (i != null && i.intValue() > 0) {
parsedInfo.bitDepth = i;
}
}
}
if (((ExifDirectoryBase) directory).containsTag(ExifDirectoryBase.TAG_SAMPLES_PER_PIXEL) && parsedInfo.numComponents == null) {
Integer i = ((ExifDirectoryBase) directory).getInteger(ExifDirectoryBase.TAG_SAMPLES_PER_PIXEL);
if (i != null) {
parsedInfo.numComponents = i;
}
}
if (((ExifDirectoryBase) directory).containsTag(ExifDirectoryBase.TAG_PHOTOMETRIC_INTERPRETATION)) {
Integer i = ((ExifDirectoryBase) directory).getInteger(ExifDirectoryBase.TAG_PHOTOMETRIC_INTERPRETATION);
if (i != null) {
((ExifParseInfo) parsedInfo).photometricInterpretation = PhotometricInterpretation.typeOf(i);
if (((ExifParseInfo) parsedInfo).photometricInterpretation != null) {
switch(((ExifParseInfo) parsedInfo).photometricInterpretation) {
case RGB:
case RGB_PALETTE:
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
break;
case Y_CB_CR:
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_YCbCr;
break;
case CMYK:
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_CMYK;
break;
case CIE_LAB:
case ICC_LAB:
case ITU_LAB:
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_Lab;
break;
case PIXAR_LOG_LUV:
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_Luv;
break;
default:
}
}
}
}
if (((ExifDirectoryBase) directory).containsTag(ExifDirectoryBase.TAG_EXIF_VERSION)) {
byte[] bytes = ((ExifDirectoryBase) directory).getByteArray(ExifDirectoryBase.TAG_EXIF_VERSION);
if (bytes != null) {
((ExifParseInfo) parsedInfo).exifVersion = ImagesUtil.parseExifVersion(bytes);
}
}
if (directory instanceof ExifIFD0Directory && ((ExifDirectoryBase) directory).containsTag(ExifDirectoryBase.TAG_COLOR_SPACE)) {
Integer i = ((ExifDirectoryBase) directory).getInteger(ExifDirectoryBase.TAG_COLOR_SPACE);
if (i != null) {
((ExifParseInfo) parsedInfo).exifColorSpace = ExifColorSpace.typeOf(i.intValue());
}
}
} else if (directory instanceof ExifThumbnailDirectory && !((ExifParseInfo) parsedInfo).hasExifThumbnail.booleanValue()) {
if (((ExifThumbnailDirectory) directory).containsTag(ExifThumbnailDirectory.TAG_THUMBNAIL_LENGTH)) {
Integer i = ((ExifThumbnailDirectory) directory).getInteger(ExifThumbnailDirectory.TAG_THUMBNAIL_LENGTH);
((ExifParseInfo) parsedInfo).hasExifThumbnail = Boolean.valueOf(i != null && i.intValue() > 0);
}
}
}
}
use of com.drew.metadata.exif.ExifIFD0Directory in project react-native-camera by react-native-community.
the class MutableImage method fixOrientation.
public void fixOrientation() throws ImageMutationFailedException {
try {
Metadata metadata = originalImageMetaData();
ExifIFD0Directory exifIFD0Directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
if (exifIFD0Directory == null) {
return;
} else if (exifIFD0Directory.containsTag(ExifIFD0Directory.TAG_ORIENTATION)) {
int exifOrientation = exifIFD0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
if (exifOrientation != 1) {
rotate(exifOrientation);
exifIFD0Directory.setInt(ExifIFD0Directory.TAG_ORIENTATION, 1);
}
}
} catch (ImageProcessingException | IOException | MetadataException e) {
throw new ImageMutationFailedException("failed to fix orientation", e);
}
}
use of com.drew.metadata.exif.ExifIFD0Directory in project java-mapollage by trixon.
the class PhotoInfo method init.
public void init() throws ImageProcessingException, IOException {
try {
mMetadata = ImageMetadataReader.readMetadata(mFile);
mExifDirectory = mMetadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
mGpsDirectory = mMetadata.getFirstDirectoryOfType(GpsDirectory.class);
mGeoLocation = getGeoLocation();
try {
ExifIFD0Directory rotationDirectory = mMetadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
mOrientation = rotationDirectory.getInt(ExifSubIFDDirectory.TAG_ORIENTATION);
} catch (MetadataException | NullPointerException ex) {
mOrientation = 1;
}
} catch (IOException ex) {
throw new IOException(String.format("E000 %s", mFile.getAbsolutePath()));
}
}
Aggregations