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;
}
}
}
}
Aggregations