Package com.drew.metadata

Examples of com.drew.metadata.Directory


    {
        if (_data == null) {
            return metadata;
        }

        Directory directory = metadata.getDirectory(IptcDirectory.class);

        // find start of data
        int offset = 0;
        try {
            while (offset < _data.length - 1 && get32Bits(offset) != 0x1c02) {
                offset++;
            }
        } catch (MetadataException e) {
            directory.addError("Couldn't find start of Iptc data (invalid segment)");
            return metadata;
        }

        // for each tag
        while (offset < _data.length) {
            // identifies start of a tag
            if (_data[offset] != 0x1c) {
                break;
            }
            // we need at least five bytes left to read a tag
            if ((offset + 5) >= _data.length) {
                break;
            }

            offset++;

            int directoryType;
            int tagType;
            int tagByteCount;
            try {
                directoryType = _data[offset++];
                tagType = _data[offset++];
                tagByteCount = get32Bits(offset);
            } catch (MetadataException e) {
                directory.addError("Iptc data segment ended mid-way through tag descriptor");
                return metadata;
            }
            offset += 2;
            if ((offset + tagByteCount) > _data.length) {
                directory.addError("data for tag extends beyond end of iptc segment");
                break;
            }

            processTag(directory, directoryType, tagType, offset, tagByteCount);
            offset += tagByteCount;
View Full Code Here


    {
        File iptcFile = new File("src/com/drew/metadata/iptc/test/withIptc.jpg");
        MetadataReader reader = new IptcReader(iptcFile);
        Metadata metadata = reader.extract();
        assertTrue(metadata.containsDirectory(IptcDirectory.class));
        Directory directory = metadata.getDirectory(IptcDirectory.class);
        assertEquals("City", directory.getDescription(IptcDirectory.TAG_CITY));
    }
View Full Code Here

    {
        File iptcFile = new File("src/com/drew/metadata/iptc/test/withIptc.jpg");
        MetadataReader reader = new IptcReader(iptcFile);
        Metadata metadata = reader.extract();
        assertTrue(metadata.containsDirectory(IptcDirectory.class));
        Directory directory = metadata.getDirectory(IptcDirectory.class);
        assertEquals("Caption", directory.getDescription(IptcDirectory.TAG_CAPTION));
    }
View Full Code Here

    {
        File iptcFile = new File("src/com/drew/metadata/iptc/test/withIptc.jpg");
        MetadataReader reader = new IptcReader(iptcFile);
        Metadata metadata = reader.extract();
        assertTrue(metadata.containsDirectory(IptcDirectory.class));
        Directory directory = metadata.getDirectory(IptcDirectory.class);
        assertEquals("Supl. Category2 Supl. Category1 Cat", directory.getDescription(IptcDirectory.TAG_CATEGORY));
    }
View Full Code Here

        StringBuffer exifBuf = new StringBuffer();

        // iterate through metadata directories
        Iterator directories = metadata.getDirectoryIterator();
        while (directories.hasNext()) {
            Directory directory = (Directory)directories.next();
            // iterate through tags
            Iterator tags = directory.getTagIterator();
            while (tags.hasNext()) {
                Tag tag = (Tag)tags.next();
                exifBuf.append(tag.getTagName().toString());
                exifBuf.append("=");
               
View Full Code Here

    }

    private void processMakerNote(int subdirOffset, @NotNull Set<Integer> processedDirectoryOffsets, int tiffHeaderOffset, @NotNull final Metadata metadata, @NotNull BufferReader reader) throws BufferBoundsException
    {
        // Determine the camera model and makernote format
        Directory ifd0Directory = metadata.getDirectory(ExifIFD0Directory.class);

        if (ifd0Directory==null)
            return;

        String cameraModel = ifd0Directory.getString(ExifIFD0Directory.TAG_MAKE);

        //final String firstTwoChars = reader.getString(subdirOffset, 2);
        final String firstThreeChars = reader.getString(subdirOffset, 3);
        final String firstFourChars = reader.getString(subdirOffset, 4);
        final String firstFiveChars = reader.getString(subdirOffset, 5);
        final String firstSixChars = reader.getString(subdirOffset, 6);
        final String firstSevenChars = reader.getString(subdirOffset, 7);
        final String firstEightChars = reader.getString(subdirOffset, 8);
        final String firstTwelveChars = reader.getString(subdirOffset, 12);

        if ("OLYMP".equals(firstFiveChars) || "EPSON".equals(firstFiveChars) || "AGFA".equals(firstFourChars)) {
            // Olympus Makernote
            // Epson and Agfa use Olympus maker note standard: http://www.ozhiker.com/electronics/pjmt/jpeg_info/
            processDirectory(metadata.getOrCreateDirectory(OlympusMakernoteDirectory.class), processedDirectoryOffsets, subdirOffset + 8, tiffHeaderOffset, metadata, reader);
        } else if (cameraModel != null && cameraModel.trim().toUpperCase().startsWith("NIKON")) {
            if ("Nikon".equals(firstFiveChars)) {
                /* There are two scenarios here:
                 * Type 1:                  **
                 * :0000: 4E 69 6B 6F 6E 00 01 00-05 00 02 00 02 00 06 00 Nikon...........
                 * :0010: 00 00 EC 02 00 00 03 00-03 00 01 00 00 00 06 00 ................
                 * Type 3:                  **
                 * :0000: 4E 69 6B 6F 6E 00 02 00-00 00 4D 4D 00 2A 00 00 Nikon....MM.*...
                 * :0010: 00 08 00 1E 00 01 00 07-00 00 00 04 30 32 30 30 ............0200
                 */
                switch (reader.getUInt8(subdirOffset + 6)) {
                    case 1:
                        processDirectory(metadata.getOrCreateDirectory(NikonType1MakernoteDirectory.class), processedDirectoryOffsets, subdirOffset + 8, tiffHeaderOffset, metadata, reader);
                        break;
                    case 2:
                        processDirectory(metadata.getOrCreateDirectory(NikonType2MakernoteDirectory.class), processedDirectoryOffsets, subdirOffset + 18, subdirOffset + 10, metadata, reader);
                        break;
                    default:
                        ifd0Directory.addError("Unsupported Nikon makernote data ignored.");
                        break;
                }
            } else {
                // The IFD begins with the first MakerNote byte (no ASCII name).  This occurs with CoolPix 775, E990 and D1 models.
                processDirectory(metadata.getOrCreateDirectory(NikonType2MakernoteDirectory.class), processedDirectoryOffsets, subdirOffset, tiffHeaderOffset, metadata, reader);
View Full Code Here

*/
public class AdobeJpegReader implements MetadataReader
{
    public void extract(@NotNull final BufferReader reader, @NotNull Metadata metadata)
    {
        final Directory directory = metadata.getOrCreateDirectory(AdobeJpegDirectory.class);

        if (reader.getLength() != 12) {
            directory.addError(String.format("Adobe JPEG data is expected to be 12 bytes long, not %d.", reader.getLength()));
            return;
        }

        try {
            reader.setMotorolaByteOrder(false);

            if (!reader.getString(0, 5).equals("Adobe")) {
                directory.addError("Invalid Adobe JPEG data header.");
                return;
            }

            directory.setInt(AdobeJpegDirectory.TAG_DCT_ENCODE_VERSION, reader.getUInt16(5));
            directory.setInt(AdobeJpegDirectory.TAG_APP14_FLAGS0, reader.getUInt16(7));
            directory.setInt(AdobeJpegDirectory.TAG_APP14_FLAGS1, reader.getUInt16(9));
            directory.setInt(AdobeJpegDirectory.TAG_COLOR_TRANSFORM, reader.getInt8(11));
        } catch (BufferBoundsException ex) {
            directory.addError("Exif data segment ended prematurely");
        }
    }
View Full Code Here

            tree.startContent();

            // iterate through metadata directories
            Iterator<Directory> directories = metadata.getDirectories().iterator();
            while (directories.hasNext()) {
                Directory directory = directories.next();
                String dir = directory.getName();
                Iterator<Tag> tags = directory.getTags().iterator();
                while (tags.hasNext()) {
                    Tag tag = tags.next();

                    tree.addStartElement(c_tag);
                    tree.addAttribute(_dir, dir);
View Full Code Here

      dis.reset();
      MetadataReader reader = new MetadataReader(dis);
      Metadata metadata = reader.extract();
      Iterator directories = metadata.getDirectoryIterator();
      while (directories.hasNext()) {
        Directory directory = (Directory)directories.next();
        Iterator tags = directory.getTagIterator();
        while (tags.hasNext()) {
          Tag tag = (Tag)tags.next();
          header.addEXIFInformation(tag.getTagName(), tag.getDescription());
        }
      }
View Full Code Here

  }

  private static void fill(Struct info,Metadata metadata) throws MetadataException {
    Iterator<Directory> directories = metadata.getDirectoryIterator();
    while (directories.hasNext()) {
        Directory directory = directories.next();
        Struct sct=new StructImpl();
        info.setEL(KeyImpl.init(directory.getName()), sct);
       
        Iterator<Tag> tags = directory.getTagIterator();
        while (tags.hasNext()) {
            Tag tag = tags.next();
            sct.setEL(KeyImpl.init(tag.getTagName()), tag.getDescription());
        }
    }
View Full Code Here

TOP

Related Classes of com.drew.metadata.Directory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.