Search in sources :

Example 1 with JpegDirectory

use of com.drew.metadata.jpeg.JpegDirectory in project UniversalMediaServer by UniversalMediaServer.

the class JPEGInfo method parseMetadata.

@Override
protected void parseMetadata(Metadata metadata) {
    if (metadata == null) {
        return;
    }
    super.parseMetadata(metadata);
    for (Directory directory : metadata.getDirectories()) {
        if (directory instanceof JpegDirectory) {
            parsedInfo.format = ImageFormat.JPEG;
            if (((JpegDirectory) directory).containsTag(JpegDirectory.TAG_IMAGE_WIDTH) && ((JpegDirectory) directory).containsTag(JpegDirectory.TAG_IMAGE_HEIGHT)) {
                parsedInfo.width = ((JpegDirectory) directory).getInteger(JpegDirectory.TAG_IMAGE_WIDTH);
                parsedInfo.height = ((JpegDirectory) directory).getInteger(JpegDirectory.TAG_IMAGE_HEIGHT);
            }
            if (((JpegDirectory) directory).containsTag(JpegDirectory.TAG_DATA_PRECISION)) {
                Integer i = ((JpegDirectory) directory).getInteger(JpegDirectory.TAG_DATA_PRECISION);
                if (i != null) {
                    parsedInfo.bitDepth = i;
                }
            }
            if (((JpegDirectory) directory).containsTag(JpegDirectory.TAG_NUMBER_OF_COMPONENTS)) {
                Integer i = ((JpegDirectory) directory).getInteger(JpegDirectory.TAG_NUMBER_OF_COMPONENTS);
                if (i != null) {
                    parsedInfo.numComponents = i;
                    /*
						 * This is "qualified" guessing based on the following assumption:
					     * Usually 1 = grey scaled, 3 = color YCbCr or YIQ, 4 = color CMYK
					     *
					     */
                    switch(parsedInfo.numComponents) {
                        case 1:
                            parsedInfo.colorSpaceType = ColorSpaceType.TYPE_GRAY;
                            break;
                        case 3:
                            parsedInfo.colorSpaceType = ColorSpaceType.TYPE_YCbCr;
                            break;
                        case 4:
                            parsedInfo.colorSpaceType = ColorSpaceType.TYPE_CMYK;
                            break;
                        default:
                    }
                    ((JPEGParseInfo) parsedInfo).components.clear();
                    for (int j = 0; j < parsedInfo.numComponents.intValue(); j++) {
                        ((JPEGParseInfo) parsedInfo).components.put(j, ((JpegDirectory) directory).getComponent(j));
                    }
                }
            }
            if (((JpegDirectory) directory).containsTag(JpegDirectory.TAG_COMPRESSION_TYPE)) {
                Integer i = ((JpegDirectory) directory).getInteger(JpegDirectory.TAG_COMPRESSION_TYPE);
                if (i != null) {
                    ((JPEGParseInfo) parsedInfo).compressionType = CompressionType.typeOf(i.intValue());
                }
            }
            ((JPEGParseInfo) parsedInfo).chromaSubsampling = JPEGSubsamplingNotation.calculateJPEGSubsampling((JpegDirectory) directory);
        } else if (directory instanceof JfifDirectory) {
            if (((JfifDirectory) directory).containsTag(JfifDirectory.TAG_VERSION)) {
                Integer i = ((JfifDirectory) directory).getInteger(JfifDirectory.TAG_VERSION);
                if (i != null) {
                    ((JPEGParseInfo) parsedInfo).jfifVersion = i;
                }
            }
        } else if (directory instanceof HuffmanTablesDirectory) {
            ((JPEGParseInfo) parsedInfo).isTypicalHuffman = Boolean.valueOf(((HuffmanTablesDirectory) directory).isTypical());
        }
    }
}
Also used : JpegDirectory(com.drew.metadata.jpeg.JpegDirectory) HuffmanTablesDirectory(com.drew.metadata.jpeg.HuffmanTablesDirectory) JfifDirectory(com.drew.metadata.jfif.JfifDirectory) Directory(com.drew.metadata.Directory) JfifDirectory(com.drew.metadata.jfif.JfifDirectory) HuffmanTablesDirectory(com.drew.metadata.jpeg.HuffmanTablesDirectory) JpegDirectory(com.drew.metadata.jpeg.JpegDirectory)

Aggregations

Directory (com.drew.metadata.Directory)1 JfifDirectory (com.drew.metadata.jfif.JfifDirectory)1 HuffmanTablesDirectory (com.drew.metadata.jpeg.HuffmanTablesDirectory)1 JpegDirectory (com.drew.metadata.jpeg.JpegDirectory)1