Search in sources :

Example 1 with GifHeaderDirectory

use of com.drew.metadata.gif.GifHeaderDirectory in project UniversalMediaServer by UniversalMediaServer.

the class GIFInfo method parseMetadata.

@Override
protected void parseMetadata(Metadata metadata) throws ParseException {
    if (metadata == null) {
        return;
    }
    for (Directory directory : metadata.getDirectories()) {
        if (directory instanceof GifHeaderDirectory) {
            parsedInfo.format = ImageFormat.GIF;
            parsedInfo.numComponents = 3;
            if (((GifHeaderDirectory) directory).containsTag(GifHeaderDirectory.TAG_IMAGE_WIDTH) && ((GifHeaderDirectory) directory).containsTag(GifHeaderDirectory.TAG_IMAGE_HEIGHT)) {
                parsedInfo.width = ((GifHeaderDirectory) directory).getInteger(GifHeaderDirectory.TAG_IMAGE_WIDTH);
                parsedInfo.height = ((GifHeaderDirectory) directory).getInteger(GifHeaderDirectory.TAG_IMAGE_HEIGHT);
            }
            if (((GifHeaderDirectory) directory).containsTag(GifHeaderDirectory.TAG_BITS_PER_PIXEL)) {
                parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
                Integer i = ((GifHeaderDirectory) directory).getInteger(GifHeaderDirectory.TAG_BITS_PER_PIXEL);
                if (i != null) {
                    parsedInfo.bitDepth = i.intValue();
                }
            }
            if (((GifHeaderDirectory) directory).containsTag(GifHeaderDirectory.TAG_GIF_FORMAT_VERSION)) {
                String s = ((GifHeaderDirectory) directory).getString(GifHeaderDirectory.TAG_GIF_FORMAT_VERSION, "US-ASCII");
                if (s != null) {
                    ((GIFParseInfo) parsedInfo).formatVersion = s;
                }
            }
        } else if (directory instanceof GifControlDirectory) {
            boolean hasTransparency = ((GifControlDirectory) directory).isTransparent();
            ((GIFParseInfo) parsedInfo).hasTransparency = hasTransparency;
            if (hasTransparency) {
                if (parsedInfo.numComponents == null) {
                    throw new ParseException("Invalid GIF image - Graphic Control Extension block encountered before the Header block");
                }
                parsedInfo.numComponents = 4;
            }
        }
    }
}
Also used : GifControlDirectory(com.drew.metadata.gif.GifControlDirectory) ParseException(net.pms.util.ParseException) GifHeaderDirectory(com.drew.metadata.gif.GifHeaderDirectory) Directory(com.drew.metadata.Directory) GifControlDirectory(com.drew.metadata.gif.GifControlDirectory) GifHeaderDirectory(com.drew.metadata.gif.GifHeaderDirectory)

Aggregations

Directory (com.drew.metadata.Directory)1 GifControlDirectory (com.drew.metadata.gif.GifControlDirectory)1 GifHeaderDirectory (com.drew.metadata.gif.GifHeaderDirectory)1 ParseException (net.pms.util.ParseException)1