use of com.drew.metadata.Directory in project tika by apache.
the class ImageMetadataExtractorTest method testHandleDirectories.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testHandleDirectories() throws MetadataException {
Metadata metadata = mock(Metadata.class);
ImageMetadataExtractor.DirectoryHandler handler1 = mock(ImageMetadataExtractor.DirectoryHandler.class);
ImageMetadataExtractor e = new ImageMetadataExtractor(metadata, handler1);
Directory directory = new JpegCommentDirectory();
Iterator directories = mock(Iterator.class);
when(directories.hasNext()).thenReturn(true, false);
when(directories.next()).thenReturn(directory);
when(handler1.supports(JpegCommentDirectory.class)).thenReturn(true);
e.handle(directories);
verify(handler1).supports(JpegCommentDirectory.class);
verify(handler1).handle(directory, metadata);
}
use of com.drew.metadata.Directory in project nifi by apache.
the class ExtractImageMetadata method getTags.
private Map<String, String> getTags(Integer max, Metadata metadata) {
Map<String, String> results = new HashMap<>();
int i = 0;
for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) {
results.put(directory.getName() + "." + tag.getTagName(), tag.getDescription());
if (max != null) {
i++;
if (i >= max) {
return results;
}
}
}
}
return results;
}
use of com.drew.metadata.Directory in project Lucee by lucee.
the class ImageMetaDrew method fill.
private static void fill(Struct info, Metadata metadata) {
Iterator<Directory> directories = metadata.getDirectories().iterator();
while (directories.hasNext()) {
Directory directory = directories.next();
Struct sct = new StructImpl();
info.setEL(KeyImpl.init(directory.getName()), sct);
Iterator<Tag> tags = directory.getTags().iterator();
while (tags.hasNext()) {
Tag tag = tags.next();
sct.setEL(KeyImpl.init(tag.getTagName()), tag.getDescription());
}
}
}
use of com.drew.metadata.Directory in project UniversalMediaServer by UniversalMediaServer.
the class PNGInfo method parseMetadata.
@Override
protected void parseMetadata(Metadata metadata) throws ParseException {
if (metadata == null) {
return;
}
for (Directory directory : metadata.getDirectories()) {
if (directory instanceof PngDirectory && PngChunkType.IHDR.equals(((PngDirectory) directory).getPngChunkType())) {
parsedInfo.format = ImageFormat.PNG;
if (((PngDirectory) directory).containsTag(PngDirectory.TAG_IMAGE_WIDTH) && ((PngDirectory) directory).containsTag(PngDirectory.TAG_IMAGE_HEIGHT)) {
parsedInfo.width = ((PngDirectory) directory).getInteger(PngDirectory.TAG_IMAGE_WIDTH);
parsedInfo.height = ((PngDirectory) directory).getInteger(PngDirectory.TAG_IMAGE_HEIGHT);
}
if (((PngDirectory) directory).containsTag(PngDirectory.TAG_BITS_PER_SAMPLE)) {
parsedInfo.bitDepth = ((PngDirectory) directory).getInteger(PngDirectory.TAG_BITS_PER_SAMPLE);
}
if (((PngDirectory) directory).containsTag(PngDirectory.TAG_INTERLACE_METHOD)) {
Integer i = ((PngDirectory) directory).getInteger(PngDirectory.TAG_INTERLACE_METHOD);
if (i != null) {
((PNGParseInfo) parsedInfo).interlaceMethod = InterlaceMethod.typeOf(i);
}
}
if (((PngDirectory) directory).containsTag(PngDirectory.TAG_COLOR_TYPE)) {
Integer i = ((PngDirectory) directory).getInteger(PngDirectory.TAG_COLOR_TYPE);
if (i != null) {
((PNGParseInfo) parsedInfo).colorType = PngColorType.fromNumericValue(i);
switch(((PNGParseInfo) parsedInfo).colorType) {
case // Grayscale without alpha
Greyscale:
parsedInfo.numComponents = 1;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_GRAY;
break;
case // RGB without alpha
TrueColor:
parsedInfo.numComponents = 3;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
break;
case // Palette index
IndexedColor:
parsedInfo.numComponents = 3;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
break;
case // Grayscale with alpha
GreyscaleWithAlpha:
parsedInfo.numComponents = 2;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_GRAY;
break;
case // RGB with alpha
TrueColorWithAlpha:
parsedInfo.numComponents = 4;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
break;
default:
}
}
}
}
if (directory instanceof PngDirectory && PngChunkType.tRNS.equals(((PngDirectory) directory).getPngChunkType())) {
((PNGParseInfo) parsedInfo).hasTransparencyChunk = true;
if (((PNGParseInfo) parsedInfo).colorType == null || ((PNGParseInfo) parsedInfo).numComponents == null) {
throw new ParseException("PNG parsing failed with ancillary chunk tRNS appearing before critical chunk IHDR");
}
if (((PNGParseInfo) parsedInfo).colorType == PngColorType.GreyscaleWithAlpha || ((PNGParseInfo) parsedInfo).colorType == PngColorType.TrueColorWithAlpha) {
throw new ParseException(String.format("PNG parsing failed with illegal combination of %s color type and tRNS transparancy chunk", ((PNGParseInfo) parsedInfo).colorType));
}
parsedInfo.numComponents++;
}
if (directory instanceof PngDirectory && PngChunkType.sBIT.equals(((PngDirectory) directory).getPngChunkType())) {
((PNGParseInfo) parsedInfo).isModifiedBitDepth = true;
}
}
}
use of com.drew.metadata.Directory in project UniversalMediaServer by UniversalMediaServer.
the class PCXInfo method parseMetadata.
@Override
protected void parseMetadata(Metadata metadata) {
if (metadata == null) {
return;
}
for (Directory directory : metadata.getDirectories()) {
if (directory instanceof PcxDirectory) {
parsedInfo.format = ImageFormat.PCX;
if (((PcxDirectory) directory).containsTag(PcxDirectory.TAG_XMIN) && ((PcxDirectory) directory).containsTag(PcxDirectory.TAG_XMAX) && ((PcxDirectory) directory).containsTag(PcxDirectory.TAG_YMIN) && ((PcxDirectory) directory).containsTag(PcxDirectory.TAG_YMAX)) {
Integer min = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_XMIN);
Integer max = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_XMAX);
if (min != null && max != null) {
parsedInfo.width = max.intValue() - min.intValue() + 1;
}
min = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_YMIN);
max = ((PcxDirectory) directory).getInteger(PcxDirectory.TAG_YMAX);
if (min != null && max != null) {
parsedInfo.height = max.intValue() - min.intValue() + 1;
}
}
}
}
}
Aggregations