Search in sources :

Example 1 with Directory

use of com.drew.metadata.Directory 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)

Example 2 with Directory

use of com.drew.metadata.Directory in project UniversalMediaServer by UniversalMediaServer.

the class PSDInfo 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 PsdHeaderDirectory) {
            parsedInfo.format = ImageFormat.PSD;
            if (((PsdHeaderDirectory) directory).containsTag(PsdHeaderDirectory.TAG_IMAGE_WIDTH) && ((PsdHeaderDirectory) directory).containsTag(PsdHeaderDirectory.TAG_IMAGE_HEIGHT)) {
                parsedInfo.width = ((PsdHeaderDirectory) directory).getInteger(PsdHeaderDirectory.TAG_IMAGE_WIDTH);
                parsedInfo.height = ((PsdHeaderDirectory) directory).getInteger(PsdHeaderDirectory.TAG_IMAGE_HEIGHT);
            }
            if (((PsdHeaderDirectory) directory).containsTag(PsdHeaderDirectory.TAG_BITS_PER_CHANNEL)) {
                Integer i = ((PsdHeaderDirectory) directory).getInteger(PsdHeaderDirectory.TAG_BITS_PER_CHANNEL);
                if (i != null) {
                    parsedInfo.bitDepth = i;
                }
            }
            if (((PsdHeaderDirectory) directory).containsTag(PsdHeaderDirectory.TAG_COLOR_MODE)) {
                Integer i = ((PsdHeaderDirectory) directory).getInteger(PsdHeaderDirectory.TAG_COLOR_MODE);
                if (i != null) {
                    ((PSDParseInfo) parsedInfo).colorMode = ColorMode.typeOf(i.intValue());
                    /*
					     * Bitmap = 0; Grayscale = 1; Indexed = 2; RGB = 3; CMYK = 4; Multichannel = 7; Duotone = 8; Lab = 9.
						 */
                    switch(((PSDParseInfo) parsedInfo).colorMode) {
                        case GRAYSCALE:
                            parsedInfo.numComponents = 1;
                            parsedInfo.colorSpaceType = ColorSpaceType.TYPE_GRAY;
                            break;
                        case INDEXED:
                        case RGB:
                            parsedInfo.numComponents = 3;
                            parsedInfo.colorSpaceType = ColorSpaceType.TYPE_RGB;
                            break;
                        case CMYK:
                            parsedInfo.numComponents = 4;
                            parsedInfo.colorSpaceType = ColorSpaceType.TYPE_CMYK;
                            break;
                        case LAB:
                            parsedInfo.numComponents = 3;
                            parsedInfo.colorSpaceType = ColorSpaceType.TYPE_Lab;
                        default:
                    }
                }
            }
            if (((PsdHeaderDirectory) directory).containsTag(PsdHeaderDirectory.TAG_CHANNEL_COUNT)) {
                Integer i = ((PsdHeaderDirectory) directory).getInteger(PsdHeaderDirectory.TAG_CHANNEL_COUNT);
                if (i != null) {
                    ((PSDParseInfo) parsedInfo).channelCount = i;
                }
            }
        }
    }
}
Also used : PsdHeaderDirectory(com.drew.metadata.photoshop.PsdHeaderDirectory) Directory(com.drew.metadata.Directory) PsdHeaderDirectory(com.drew.metadata.photoshop.PsdHeaderDirectory) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with Directory

use of com.drew.metadata.Directory in project UniversalMediaServer by UniversalMediaServer.

the class ICOInfo method parseMetadata.

@Override
protected void parseMetadata(Metadata metadata) {
    if (metadata == null) {
        return;
    }
    for (Directory directory : metadata.getDirectories()) {
        if (directory instanceof IcoDirectory) {
            parsedInfo.format = ImageFormat.ICO;
            if (((IcoDirectory) directory).containsTag(IcoDirectory.TAG_IMAGE_WIDTH) && ((IcoDirectory) directory).containsTag(IcoDirectory.TAG_IMAGE_HEIGHT)) {
                parsedInfo.width = ((IcoDirectory) directory).getInteger(IcoDirectory.TAG_IMAGE_WIDTH);
                parsedInfo.height = ((IcoDirectory) directory).getInteger(IcoDirectory.TAG_IMAGE_HEIGHT);
            }
        }
    }
}
Also used : IcoDirectory(com.drew.metadata.ico.IcoDirectory) Directory(com.drew.metadata.Directory) IcoDirectory(com.drew.metadata.ico.IcoDirectory)

Example 4 with Directory

use of com.drew.metadata.Directory 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:
                    }
                }
            }
        }
    }
}
Also used : BmpHeaderDirectory(com.drew.metadata.bmp.BmpHeaderDirectory) BmpHeaderDirectory(com.drew.metadata.bmp.BmpHeaderDirectory) Directory(com.drew.metadata.Directory) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 5 with Directory

use of com.drew.metadata.Directory in project drill by apache.

the class GenericMetadataReader method read.

public void read(@NotNull FileType fileType, @NotNull FileStatus fileStatus, @NotNull Metadata metadata) {
    GenericMetadataDirectory directory = new GenericMetadataDirectory();
    boolean skipEPSPreview = false;
    directory.setLong(GenericMetadataDirectory.TAG_FILE_SIZE, fileStatus.getLen());
    // Add local time zone offset to store the last modified time as local time
    // just like TO_TIMESTAMP(UNIX_TIMESTAMP()) returns local time
    directory.setDate(GenericMetadataDirectory.TAG_FILE_DATE_TIME, new Date(fileStatus.getModificationTime() + TimeZone.getDefault().getRawOffset()));
    directory.setString(GenericMetadataDirectory.TAG_FORMAT, fileType.name().toUpperCase());
    for (Directory dir : metadata.getDirectories()) {
        if (dir instanceof JpegDirectory) {
            final JpegDirectory jpegDir = (JpegDirectory) dir;
            directory.setPixelWidth(jpegDir, JpegDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(jpegDir, JpegDirectory.TAG_IMAGE_HEIGHT);
            directory.setBitPerPixel(jpegDir, JpegDirectory.TAG_DATA_PRECISION, JpegDirectory.TAG_NUMBER_OF_COMPONENTS);
            continue;
        }
        if (dir instanceof JfifDirectory) {
            final JfifDirectory jfifDir = (JfifDirectory) dir;
            try {
                final int unit = jfifDir.getResUnits();
                if (unit == 1 || unit == 2) {
                    directory.setDPIWidth(jfifDir, JfifDirectory.TAG_RESX, unit == 1 ? 1.0 : 2.54);
                    directory.setDPIHeight(jfifDir, JfifDirectory.TAG_RESY, unit == 1 ? 1.0 : 2.54);
                }
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            continue;
        }
        if (dir instanceof ExifIFD0Directory) {
            if (skipEPSPreview) {
                skipEPSPreview = false;
                continue;
            }
            final ExifIFD0Directory ifd0Dir = (ExifIFD0Directory) dir;
            directory.setPixelWidth(ifd0Dir, ExifIFD0Directory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(ifd0Dir, ExifIFD0Directory.TAG_IMAGE_HEIGHT);
            directory.setOrientation(ifd0Dir, ExifIFD0Directory.TAG_ORIENTATION);
            try {
                final int unit = ifd0Dir.getInt(ExifIFD0Directory.TAG_RESOLUTION_UNIT);
                if (unit == 2 || unit == 3) {
                    directory.setDPIWidth(ifd0Dir, ExifIFD0Directory.TAG_X_RESOLUTION, unit == 2 ? 1.0 : 2.54);
                    directory.setDPIHeight(ifd0Dir, ExifIFD0Directory.TAG_Y_RESOLUTION, unit == 2 ? 1.0 : 2.54);
                }
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            int[] bitPerSample = ifd0Dir.getIntArray(ExifIFD0Directory.TAG_BITS_PER_SAMPLE);
            if (bitPerSample != null) {
                int bitsPerPixel = 0;
                for (int n : bitPerSample) {
                    bitsPerPixel += n;
                }
                directory.setBitPerPixel(bitsPerPixel);
            }
            continue;
        }
        if (dir instanceof ExifSubIFDDirectory) {
            final ExifSubIFDDirectory subIFDDir = (ExifSubIFDDirectory) dir;
            directory.setPixelWidth(subIFDDir, ExifSubIFDDirectory.TAG_EXIF_IMAGE_WIDTH);
            directory.setPixelHeight(subIFDDir, ExifSubIFDDirectory.TAG_EXIF_IMAGE_HEIGHT);
            continue;
        }
        if (dir instanceof PsdHeaderDirectory) {
            final PsdHeaderDirectory psdDir = (PsdHeaderDirectory) dir;
            directory.setPixelWidth(psdDir, PsdHeaderDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(psdDir, PsdHeaderDirectory.TAG_IMAGE_HEIGHT);
            directory.setBitPerPixel(psdDir, PsdHeaderDirectory.TAG_BITS_PER_CHANNEL, PsdHeaderDirectory.TAG_CHANNEL_COUNT);
            directory.setColorMode(psdDir, PsdHeaderDirectory.TAG_COLOR_MODE);
            continue;
        }
        if (dir instanceof PngDirectory) {
            final PngDirectory pngDir = (PngDirectory) dir;
            if (pngDir.getPngChunkType() == PngChunkType.IHDR) {
                directory.setPixelWidth(pngDir, PngDirectory.TAG_IMAGE_WIDTH);
                directory.setPixelHeight(pngDir, PngDirectory.TAG_IMAGE_HEIGHT);
                try {
                    int numOfComponent = 1;
                    int colorType = pngDir.getInt(PngDirectory.TAG_COLOR_TYPE);
                    if (colorType == PngColorType.IndexedColor.getNumericValue()) {
                        directory.setColorMode("Indexed");
                    } else if (colorType == PngColorType.Greyscale.getNumericValue()) {
                        directory.setColorMode("Grayscale");
                    } else if (colorType == PngColorType.GreyscaleWithAlpha.getNumericValue()) {
                        numOfComponent = 2;
                        directory.setColorMode("Grayscale");
                        directory.setAlpha(true);
                    } else if (colorType == PngColorType.TrueColor.getNumericValue()) {
                        numOfComponent = 3;
                    } else if (colorType == PngColorType.TrueColorWithAlpha.getNumericValue()) {
                        numOfComponent = 4;
                        directory.setAlpha(true);
                    }
                    directory.setBitPerPixel(pngDir.getInt(PngDirectory.TAG_BITS_PER_SAMPLE) * numOfComponent);
                } catch (MetadataException e) {
                // Nothing needs to be done
                }
                continue;
            }
            if (pngDir.getPngChunkType() == PngChunkType.pHYs) {
                try {
                    final int unit = pngDir.getInt(PngDirectory.TAG_UNIT_SPECIFIER);
                    if (unit == 1) {
                        directory.setDPIWidth(pngDir, PngDirectory.TAG_PIXELS_PER_UNIT_X, 0.0254);
                        directory.setDPIHeight(pngDir, PngDirectory.TAG_PIXELS_PER_UNIT_Y, 0.0254);
                    }
                } catch (MetadataException e) {
                // Nothing needs to be done
                }
                continue;
            }
            if (pngDir.getPngChunkType() == PngChunkType.tRNS) {
                directory.setAlpha(true);
                continue;
            }
            continue;
        }
        if (dir instanceof BmpHeaderDirectory) {
            final BmpHeaderDirectory bmpDir = (BmpHeaderDirectory) dir;
            directory.setPixelWidth(bmpDir, BmpHeaderDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(bmpDir, BmpHeaderDirectory.TAG_IMAGE_HEIGHT);
            directory.setDPIWidth(bmpDir, BmpHeaderDirectory.TAG_X_PIXELS_PER_METER, 0.0254);
            directory.setDPIHeight(bmpDir, BmpHeaderDirectory.TAG_Y_PIXELS_PER_METER, 0.0254);
            try {
                final int bitsPerPixel = bmpDir.getInt(BmpHeaderDirectory.TAG_BITS_PER_PIXEL);
                if (bitsPerPixel <= 8) {
                    directory.setColorMode("Indexed");
                }
                directory.setBitPerPixel(bitsPerPixel);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            continue;
        }
        if (dir instanceof GifHeaderDirectory) {
            final GifHeaderDirectory gifDir = (GifHeaderDirectory) dir;
            directory.setPixelWidth(gifDir, GifHeaderDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(gifDir, GifHeaderDirectory.TAG_IMAGE_HEIGHT);
            directory.setColorMode("Indexed");
            directory.setBitPerPixel(gifDir, GifHeaderDirectory.TAG_BITS_PER_PIXEL);
            continue;
        }
        if (dir instanceof GifControlDirectory) {
            final GifControlDirectory gifControlDir = (GifControlDirectory) dir;
            directory.setAlpha(gifControlDir, GifControlDirectory.TAG_TRANSPARENT_COLOR_FLAG);
            continue;
        }
        if (dir instanceof IcoDirectory) {
            final IcoDirectory icoDir = (IcoDirectory) dir;
            directory.setPixelWidth(icoDir, IcoDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(icoDir, IcoDirectory.TAG_IMAGE_HEIGHT);
            try {
                if (icoDir.getInt(IcoDirectory.TAG_COLOUR_PALETTE_SIZE) != 0) {
                    directory.setColorMode("Indexed");
                }
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            directory.setBitPerPixel(icoDir, IcoDirectory.TAG_BITS_PER_PIXEL);
            directory.setAlpha(true);
            continue;
        }
        if (dir instanceof PcxDirectory) {
            final PcxDirectory pcxDir = (PcxDirectory) dir;
            try {
                directory.setPixelWidth(pcxDir.getInt(PcxDirectory.TAG_XMAX) - pcxDir.getInt(PcxDirectory.TAG_XMIN) + 1);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            try {
                directory.setPixelHeight(pcxDir.getInt(PcxDirectory.TAG_YMAX) - pcxDir.getInt(PcxDirectory.TAG_YMIN) + 1);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            directory.setDPIWidth(pcxDir, PcxDirectory.TAG_HORIZONTAL_DPI);
            directory.setDPIHeight(pcxDir, PcxDirectory.TAG_VERTICAL_DPI);
            directory.setBitPerPixel(pcxDir, PcxDirectory.TAG_BITS_PER_PIXEL, PcxDirectory.TAG_COLOR_PLANES);
            try {
                int colorPlanes = pcxDir.getInt(PcxDirectory.TAG_COLOR_PLANES);
                if (colorPlanes == 1) {
                    if (pcxDir.getInt(PcxDirectory.TAG_PALETTE_TYPE) == 2) {
                        directory.setColorMode("Grayscale");
                    } else {
                        directory.setColorMode("Indexed");
                    }
                }
                directory.setAlpha(colorPlanes == 4);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            continue;
        }
        if (dir instanceof WavDirectory) {
            final WavDirectory wavDir = (WavDirectory) dir;
            directory.setColorMode("N/A");
            directory.setDuration(wavDir, WavDirectory.TAG_DURATION);
            directory.setAudioCodec(wavDir, WavDirectory.TAG_FORMAT);
            directory.setAudioSampleSize(wavDir, WavDirectory.TAG_BITS_PER_SAMPLE);
            directory.setAudioSampleRate(wavDir, WavDirectory.TAG_SAMPLES_PER_SEC);
        }
        if (dir instanceof AviDirectory) {
            final AviDirectory aviDir = (AviDirectory) dir;
            directory.setPixelWidth(aviDir, AviDirectory.TAG_WIDTH);
            directory.setPixelHeight(aviDir, AviDirectory.TAG_HEIGHT);
            directory.setDuration(aviDir, AviDirectory.TAG_DURATION);
            directory.setVideoCodec(aviDir, AviDirectory.TAG_VIDEO_CODEC);
            directory.setFrameRate(aviDir, AviDirectory.TAG_FRAMES_PER_SECOND);
            directory.setAudioCodec(aviDir, AviDirectory.TAG_AUDIO_CODEC);
            directory.setAudioSampleRate(aviDir, AviDirectory.TAG_SAMPLES_PER_SECOND);
            continue;
        }
        if (dir instanceof WebpDirectory) {
            final WebpDirectory webpDir = (WebpDirectory) dir;
            directory.setPixelWidth(webpDir, WebpDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(webpDir, WebpDirectory.TAG_IMAGE_HEIGHT);
            directory.setAlpha(webpDir, WebpDirectory.TAG_HAS_ALPHA);
            continue;
        }
        if (dir instanceof QuickTimeVideoDirectory) {
            final QuickTimeVideoDirectory qtVideoDir = (QuickTimeVideoDirectory) dir;
            directory.setPixelWidth(qtVideoDir, QuickTimeVideoDirectory.TAG_WIDTH);
            directory.setPixelHeight(qtVideoDir, QuickTimeVideoDirectory.TAG_HEIGHT);
            directory.setDPIWidth(qtVideoDir, QuickTimeVideoDirectory.TAG_HORIZONTAL_RESOLUTION);
            directory.setDPIHeight(qtVideoDir, QuickTimeVideoDirectory.TAG_VERTICAL_RESOLUTION);
            try {
                int bitsPerPixel = qtVideoDir.getInt(QuickTimeVideoDirectory.TAG_DEPTH) % 32;
                directory.setBitPerPixel(bitsPerPixel);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            directory.setDuration(qtVideoDir, QuickTimeVideoDirectory.TAG_DURATION);
            directory.setVideoCodec(qtVideoDir, QuickTimeVideoDirectory.TAG_COMPRESSION_TYPE);
            directory.setFrameRate(qtVideoDir, QuickTimeVideoDirectory.TAG_FRAME_RATE);
            continue;
        }
        if (dir instanceof QuickTimeSoundDirectory) {
            final QuickTimeSoundDirectory qtSoundDir = (QuickTimeSoundDirectory) dir;
            directory.setAudioCodec(qtSoundDir, QuickTimeSoundDirectory.TAG_AUDIO_FORMAT);
            directory.setAudioSampleSize(qtSoundDir, QuickTimeSoundDirectory.TAG_AUDIO_SAMPLE_SIZE);
            directory.setAudioSampleRate(qtSoundDir, QuickTimeSoundDirectory.TAG_AUDIO_SAMPLE_RATE);
            continue;
        }
        if (dir instanceof QuickTimeDirectory) {
            final QuickTimeDirectory qtDir = (QuickTimeDirectory) dir;
            directory.setDuration(qtDir, QuickTimeDirectory.TAG_DURATION);
            continue;
        }
        if (dir instanceof Mp4VideoDirectory) {
            final Mp4VideoDirectory mp4VideoDir = (Mp4VideoDirectory) dir;
            directory.setPixelWidth(mp4VideoDir, Mp4VideoDirectory.TAG_WIDTH);
            directory.setPixelHeight(mp4VideoDir, Mp4VideoDirectory.TAG_HEIGHT);
            directory.setDPIWidth(mp4VideoDir, Mp4VideoDirectory.TAG_HORIZONTAL_RESOLUTION);
            directory.setDPIHeight(mp4VideoDir, Mp4VideoDirectory.TAG_VERTICAL_RESOLUTION);
            try {
                int bitsPerPixel = mp4VideoDir.getInt(Mp4VideoDirectory.TAG_DEPTH) % 32;
                directory.setBitPerPixel(bitsPerPixel);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            directory.setDuration(mp4VideoDir, Mp4VideoDirectory.TAG_DURATION);
            directory.setVideoCodec(mp4VideoDir, Mp4VideoDirectory.TAG_COMPRESSION_TYPE);
            directory.setFrameRate(mp4VideoDir, Mp4VideoDirectory.TAG_FRAME_RATE);
            continue;
        }
        if (dir instanceof Mp4SoundDirectory) {
            final Mp4SoundDirectory mp4SoundDir = (Mp4SoundDirectory) dir;
            directory.setAudioCodec(mp4SoundDir, Mp4SoundDirectory.TAG_AUDIO_FORMAT);
            directory.setAudioSampleSize(mp4SoundDir, Mp4SoundDirectory.TAG_AUDIO_SAMPLE_SIZE);
            directory.setAudioSampleRate(mp4SoundDir, Mp4SoundDirectory.TAG_AUDIO_SAMPLE_RATE);
            continue;
        }
        if (dir instanceof Mp4Directory) {
            final Mp4Directory mp4Dir = (Mp4Directory) dir;
            directory.setDuration(mp4Dir, Mp4Directory.TAG_DURATION);
            continue;
        }
        if (dir instanceof EpsDirectory) {
            final EpsDirectory epsDir = (EpsDirectory) dir;
            directory.setPixelWidth(epsDir, EpsDirectory.TAG_IMAGE_WIDTH);
            directory.setPixelHeight(epsDir, EpsDirectory.TAG_IMAGE_HEIGHT);
            try {
                int bitsPerPixel = 24;
                int colorType = epsDir.getInt(EpsDirectory.TAG_COLOR_TYPE);
                if (colorType == 1) {
                    String imageData = epsDir.getString(EpsDirectory.TAG_IMAGE_DATA);
                    if (imageData != null && imageData.split(" ")[2].equals("1")) {
                        bitsPerPixel = 1;
                        directory.setColorMode("Bitmap");
                    } else {
                        bitsPerPixel = 8;
                        directory.setColorMode("Grayscale");
                    }
                } else if (colorType == 2) {
                    directory.setColorMode("Lab");
                } else if (colorType == 4) {
                    bitsPerPixel = 32;
                    directory.setColorMode("CMYK");
                }
                directory.setBitPerPixel(bitsPerPixel);
                skipEPSPreview = epsDir.containsTag(EpsDirectory.TAG_TIFF_PREVIEW_SIZE);
            } catch (MetadataException e) {
            // Nothing needs to be done
            }
            continue;
        }
    }
    // Set default value if empty
    directory.setPixelWidth(0);
    directory.setPixelHeight(0);
    directory.setOrientation(0);
    directory.setDPIWidth(0.0);
    directory.setDPIHeight(0.0);
    directory.setColorMode("RGB");
    directory.setBitPerPixel(0);
    directory.setAlpha(false);
    directory.setDuration(0);
    directory.setVideoCodec("Unknown");
    directory.setFrameRate(0.0);
    directory.setAudioCodec("Unknown");
    directory.setAudioSampleSize(0);
    directory.setAudioSampleRate(0.0);
    metadata.addDirectory(directory);
}
Also used : GifControlDirectory(com.drew.metadata.gif.GifControlDirectory) PngDirectory(com.drew.metadata.png.PngDirectory) QuickTimeSoundDirectory(com.drew.metadata.mov.media.QuickTimeSoundDirectory) WebpDirectory(com.drew.metadata.webp.WebpDirectory) MetadataException(com.drew.metadata.MetadataException) ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) QuickTimeVideoDirectory(com.drew.metadata.mov.media.QuickTimeVideoDirectory) PcxDirectory(com.drew.metadata.pcx.PcxDirectory) GifHeaderDirectory(com.drew.metadata.gif.GifHeaderDirectory) PsdHeaderDirectory(com.drew.metadata.photoshop.PsdHeaderDirectory) EpsDirectory(com.drew.metadata.eps.EpsDirectory) AviDirectory(com.drew.metadata.avi.AviDirectory) GifControlDirectory(com.drew.metadata.gif.GifControlDirectory) Mp4Directory(com.drew.metadata.mp4.Mp4Directory) WebpDirectory(com.drew.metadata.webp.WebpDirectory) BmpHeaderDirectory(com.drew.metadata.bmp.BmpHeaderDirectory) ExifSubIFDDirectory(com.drew.metadata.exif.ExifSubIFDDirectory) Directory(com.drew.metadata.Directory) JfifDirectory(com.drew.metadata.jfif.JfifDirectory) QuickTimeDirectory(com.drew.metadata.mov.QuickTimeDirectory) IcoDirectory(com.drew.metadata.ico.IcoDirectory) JpegDirectory(com.drew.metadata.jpeg.JpegDirectory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) PngDirectory(com.drew.metadata.png.PngDirectory) Mp4VideoDirectory(com.drew.metadata.mp4.media.Mp4VideoDirectory) QuickTimeVideoDirectory(com.drew.metadata.mov.media.QuickTimeVideoDirectory) Mp4SoundDirectory(com.drew.metadata.mp4.media.Mp4SoundDirectory) PsdHeaderDirectory(com.drew.metadata.photoshop.PsdHeaderDirectory) PcxDirectory(com.drew.metadata.pcx.PcxDirectory) GifHeaderDirectory(com.drew.metadata.gif.GifHeaderDirectory) QuickTimeSoundDirectory(com.drew.metadata.mov.media.QuickTimeSoundDirectory) WavDirectory(com.drew.metadata.wav.WavDirectory) QuickTimeDirectory(com.drew.metadata.mov.QuickTimeDirectory) Mp4VideoDirectory(com.drew.metadata.mp4.media.Mp4VideoDirectory) Mp4SoundDirectory(com.drew.metadata.mp4.media.Mp4SoundDirectory) Mp4Directory(com.drew.metadata.mp4.Mp4Directory) Date(java.util.Date) AviDirectory(com.drew.metadata.avi.AviDirectory) WavDirectory(com.drew.metadata.wav.WavDirectory) JpegDirectory(com.drew.metadata.jpeg.JpegDirectory) ExifIFD0Directory(com.drew.metadata.exif.ExifIFD0Directory) BmpHeaderDirectory(com.drew.metadata.bmp.BmpHeaderDirectory) EpsDirectory(com.drew.metadata.eps.EpsDirectory) IcoDirectory(com.drew.metadata.ico.IcoDirectory) JfifDirectory(com.drew.metadata.jfif.JfifDirectory)

Aggregations

Directory (com.drew.metadata.Directory)17 ExifIFD0Directory (com.drew.metadata.exif.ExifIFD0Directory)7 ExifSubIFDDirectory (com.drew.metadata.exif.ExifSubIFDDirectory)6 Tag (com.drew.metadata.Tag)5 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 ImageProcessingException (com.drew.imaging.ImageProcessingException)2 BmpHeaderDirectory (com.drew.metadata.bmp.BmpHeaderDirectory)2 EpsDirectory (com.drew.metadata.eps.EpsDirectory)2 GifControlDirectory (com.drew.metadata.gif.GifControlDirectory)2 GifHeaderDirectory (com.drew.metadata.gif.GifHeaderDirectory)2 IcoDirectory (com.drew.metadata.ico.IcoDirectory)2 JfifDirectory (com.drew.metadata.jfif.JfifDirectory)2 JpegCommentDirectory (com.drew.metadata.jpeg.JpegCommentDirectory)2 JpegDirectory (com.drew.metadata.jpeg.JpegDirectory)2 PcxDirectory (com.drew.metadata.pcx.PcxDirectory)2 PsdHeaderDirectory (com.drew.metadata.photoshop.PsdHeaderDirectory)2 PngDirectory (com.drew.metadata.png.PngDirectory)2 WebpDirectory (com.drew.metadata.webp.WebpDirectory)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2