use of com.drew.metadata.bmp.BmpHeaderDirectory in project UniversalMediaServer by UniversalMediaServer.
the class BMPInfo method parseMetadata.
@SuppressFBWarnings("SF_SWITCH_NO_DEFAULT")
@Override
protected void parseMetadata(Metadata metadata) {
if (metadata == null) {
return;
}
for (Directory directory : metadata.getDirectories()) {
if (directory instanceof BmpHeaderDirectory) {
parsedInfo.format = ImageFormat.BMP;
if (((BmpHeaderDirectory) directory).containsTag(BmpHeaderDirectory.TAG_IMAGE_WIDTH) && ((BmpHeaderDirectory) directory).containsTag(BmpHeaderDirectory.TAG_IMAGE_HEIGHT)) {
parsedInfo.width = ((BmpHeaderDirectory) directory).getInteger(BmpHeaderDirectory.TAG_IMAGE_WIDTH);
parsedInfo.height = ((BmpHeaderDirectory) directory).getInteger(BmpHeaderDirectory.TAG_IMAGE_HEIGHT);
}
}
if (((BmpHeaderDirectory) directory).containsTag(BmpHeaderDirectory.TAG_BITS_PER_PIXEL) && ((BmpHeaderDirectory) directory).containsTag(BmpHeaderDirectory.TAG_COMPRESSION) && ((BmpHeaderDirectory) directory).containsTag(BmpHeaderDirectory.TAG_HEADER_SIZE)) {
Integer compression = ((BmpHeaderDirectory) directory).getInteger(BmpHeaderDirectory.TAG_COMPRESSION);
Integer headerSize = ((BmpHeaderDirectory) directory).getInteger(BmpHeaderDirectory.TAG_HEADER_SIZE);
Integer bitsPerPixel = ((BmpHeaderDirectory) directory).getInteger(BmpHeaderDirectory.TAG_BITS_PER_PIXEL);
if (compression != null && headerSize != null && bitsPerPixel != null) {
CompressionType compressionType = CompressionType.typeOf(compression.intValue(), headerSize.intValue());
((BMPParseInfo) parsedInfo).compressionType = compressionType;
if (parsedInfo.bitDepth != null) {
switch(compressionType) {
case BIT_FIELDS:
case HUFFMAN_1D:
case NONE:
case PNG:
case RLE24:
case RLE4:
case RLE8:
// "qualified guessing"
switch(bitsPerPixel.intValue()) {
case 1:
parsedInfo.numComponents = 1;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_GRAY;
parsedInfo.bitDepth = 1;
break;
case 2:
case 4:
case 8:
parsedInfo.numComponents = 3;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
parsedInfo.bitDepth = 8;
break;
case 16:
// assuming 5:6:5 - could also be 5:5:5:1
parsedInfo.numComponents = 3;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
parsedInfo.bitDepth = 5;
break;
case 24:
parsedInfo.numComponents = 3;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
parsedInfo.bitDepth = 8;
break;
case 32:
parsedInfo.numComponents = 4;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
parsedInfo.bitDepth = 8;
break;
default:
}
break;
case JPEG:
parsedInfo.numComponents = 3;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
parsedInfo.bitDepth = bitsPerPixel.intValue() / 3;
break;
case RGBA_BIT_FIELDS:
parsedInfo.numComponents = 4;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
parsedInfo.bitDepth = bitsPerPixel.intValue() / 4;
break;
case CMYK_NONE:
case CMYK_RLE4:
case CMYK_RLE8:
parsedInfo.numComponents = 4;
parsedInfo.colorSpaceType = ColorSpaceType.TYPE_CMYK;
parsedInfo.bitDepth = bitsPerPixel.intValue() / 4;
break;
case UNKNOWN:
default:
}
}
}
}
}
}
Aggregations