Search in sources :

Example 6 with Directory

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);
}
Also used : JpegCommentDirectory(com.drew.metadata.jpeg.JpegCommentDirectory) Metadata(org.apache.tika.metadata.Metadata) Iterator(java.util.Iterator) ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) Directory(com.drew.metadata.Directory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) JpegCommentDirectory(com.drew.metadata.jpeg.JpegCommentDirectory) Test(org.junit.Test)

Example 7 with Directory

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;
}
Also used : HashMap(java.util.HashMap) Tag(com.drew.metadata.Tag) Directory(com.drew.metadata.Directory)

Example 8 with Directory

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());
        }
    }
}
Also used : StructImpl(lucee.runtime.type.StructImpl) Tag(com.drew.metadata.Tag) Directory(com.drew.metadata.Directory) Struct(lucee.runtime.type.Struct)

Example 9 with Directory

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;
        }
    }
}
Also used : PngDirectory(com.drew.metadata.png.PngDirectory) ParseException(net.pms.util.ParseException) Directory(com.drew.metadata.Directory) PngDirectory(com.drew.metadata.png.PngDirectory)

Example 10 with Directory

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;
                }
            }
        }
    }
}
Also used : PcxDirectory(com.drew.metadata.pcx.PcxDirectory) Directory(com.drew.metadata.Directory) PcxDirectory(com.drew.metadata.pcx.PcxDirectory)

Aggregations

Directory (com.drew.metadata.Directory)14 Tag (com.drew.metadata.Tag)4 ExifIFD0Directory (com.drew.metadata.exif.ExifIFD0Directory)4 ExifSubIFDDirectory (com.drew.metadata.exif.ExifSubIFDDirectory)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 JpegCommentDirectory (com.drew.metadata.jpeg.JpegCommentDirectory)2 ParseException (net.pms.util.ParseException)2 Metadata (org.apache.tika.metadata.Metadata)2 Test (org.junit.Test)2 ExifInterface (android.media.ExifInterface)1 ImageProcessingException (com.drew.imaging.ImageProcessingException)1 BmpHeaderDirectory (com.drew.metadata.bmp.BmpHeaderDirectory)1 ExifDirectoryBase (com.drew.metadata.exif.ExifDirectoryBase)1 ExifThumbnailDirectory (com.drew.metadata.exif.ExifThumbnailDirectory)1 GifControlDirectory (com.drew.metadata.gif.GifControlDirectory)1 GifHeaderDirectory (com.drew.metadata.gif.GifHeaderDirectory)1 IcoDirectory (com.drew.metadata.ico.IcoDirectory)1 JfifDirectory (com.drew.metadata.jfif.JfifDirectory)1 HuffmanTablesDirectory (com.drew.metadata.jpeg.HuffmanTablesDirectory)1 JpegDirectory (com.drew.metadata.jpeg.JpegDirectory)1