Package com.drew.metadata

Examples of com.drew.metadata.Directory


        assertEquals("Parsing should proceed without date", null,
                metadata.get(TikaCoreProperties.CREATED));
    }
   
    public void testCopyUnknownFieldsHandler() throws MetadataException {
        Directory d = mock(Directory.class);
        Tag t1 = mock(Tag.class);
        when(t1.getTagName()).thenReturn("Image Description");
        when(t1.getDescription()).thenReturn("t1");
        Tag t2 = mock(Tag.class);
        when(t2.getTagName()).thenReturn(Metadata.KEYWORDS);
        when(t2.getDescription()).thenReturn("known");
        Tag t3 = mock(Tag.class);
        when(t3.getTagName()).thenReturn(TikaCoreProperties.DESCRIPTION.getName());
        when(t3.getDescription()).thenReturn("known");
        List<Tag> tags = Arrays.asList(t1, t2, t3);
        when(d.getTags()).thenReturn(tags);
        Metadata metadata = new Metadata();
        new ImageMetadataExtractor.CopyUnknownFieldsHandler().handle(d, metadata);
        assertEquals("t1", metadata.get("Image Description"));
        assertNull("keywords should be excluded from bulk copy because it is a defined field",
                metadata.get(Metadata.KEYWORDS));
View Full Code Here


     * @param directories Metadata Extractor {@link com.drew.metadata.Directory} instances.
     * @throws MetadataException This method does not handle exceptions from Metadata Extractor
     */   
    protected void handle(Iterator<Directory> directories) throws MetadataException {
        while (directories.hasNext()) {
            Directory directory = directories.next();
            for (int i = 0; i < handlers.length; i++) {
                if (handlers[i].supports(directory.getClass())) {
                    handlers[i].handle(directory, metadata);
                }
            }
        }
    }
View Full Code Here

     * @param directories Metadata Extractor {@link com.drew.metadata.Directory} instances.
     * @throws MetadataException This method does not handle exceptions from Metadata Extractor
     */   
    protected void handle(Iterator<Directory> directories) throws MetadataException {
        while (directories.hasNext()) {
            Directory directory = directories.next();
            for (int i = 0; i < handlers.length; i++) {
                if (handlers[i].supports(directory.getClass())) {
                    handlers[i].handle(directory, metadata);
                }
            }
        }
    }
View Full Code Here

    public void testHandleDirectories() throws MetadataException {
        Metadata metadata = mock(Metadata.class);
        ImageMetadataExtractor.DirectoryHandler handler1 = mock(ImageMetadataExtractor.DirectoryHandler.class);
        ImageMetadataExtractor e = new ImageMetadataExtractor(metadata, handler1);
       
        Directory directory = new JpegCommentDirectory();
        Iterator directories = mock(Iterator.class);
        when(directories.hasNext()).thenReturn(true, false);
        when(directories.next()).thenReturn(directory);
        when(handler1.supports(JpegCommentDirectory.class)).thenReturn(true);
       
View Full Code Here

                metadata.get(TikaCoreProperties.CREATED));
    }
   
    @Test
    public void testCopyUnknownFieldsHandler() throws MetadataException {
        Directory d = mock(Directory.class);
        Tag t1 = mock(Tag.class);
        when(t1.getTagName()).thenReturn("Image Description");
        when(t1.getDescription()).thenReturn("t1");
        Tag t2 = mock(Tag.class);
        when(t2.getTagName()).thenReturn(Metadata.KEYWORDS);
        when(t2.getDescription()).thenReturn("known");
        Tag t3 = mock(Tag.class);
        when(t3.getTagName()).thenReturn(TikaCoreProperties.DESCRIPTION.getName());
        when(t3.getDescription()).thenReturn("known");
        List<Tag> tags = Arrays.asList(t1, t2, t3);
        when(d.getTags()).thenReturn(tags);
        Metadata metadata = new Metadata();
        new ImageMetadataExtractor.CopyUnknownFieldsHandler().handle(d, metadata);
        assertEquals("t1", metadata.get("Image Description"));
        assertNull("keywords should be excluded from bulk copy because it is a defined field",
                metadata.get(Metadata.KEYWORDS));
View Full Code Here

     * @see <a href="http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto">http://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto</a>
     */
    public static Integer readOrientation(File filename) {
        try {
            final Metadata metadata = JpegMetadataReader.readMetadata(filename);
            final Directory dir = metadata.getDirectory(ExifIFD0Directory.class);
            return dir.getInt(ExifIFD0Directory.TAG_ORIENTATION);
        } catch (JpegProcessingException | MetadataException | IOException e) {
            Main.error(e);
        }
        return null;
    }
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

     * If successful, fills in the LatLon and EastNorth attributes of passed in image
     */
    private static void extractExif(ImageEntry e) {

        Metadata metadata;
        Directory dirExif;
        GpsDirectory dirGps;

        try {
            metadata = JpegMetadataReader.readMetadata(e.getFile());
            dirExif = metadata.getDirectory(ExifIFD0Directory.class);
            dirGps = metadata.getDirectory(GpsDirectory.class);
        } catch (CompoundException | IOException p) {
            e.setExifCoor(null);
            e.setPos(null);
            return;
        }

        try {
            if (dirExif != null) {
                int orientation = dirExif.getInt(ExifIFD0Directory.TAG_ORIENTATION);
                e.setExifOrientation(orientation);
            }
        } catch (MetadataException ex) {
            Main.debug(ex.getMessage());
        }
View Full Code Here

     * @param directories Metadata Extractor {@link com.drew.metadata.Directory} instances.
     * @throws MetadataException This method does not handle exceptions from Metadata Extractor
     */   
    protected void handle(Iterator<Directory> directories) throws MetadataException {
        while (directories.hasNext()) {
            Directory directory = directories.next();
            for (DirectoryHandler handler : handlers) {
                if (handler.supports(directory.getClass())) {
                    handler.handle(directory, metadata);
                }
            }
        }
    }
View Full Code Here

    } else {

      ImageMetadata imgmeta = new ImageMetadata();

      // Extract IPTC information
      Directory iptc = meta.getDirectory(IptcDirectory.class);
      if (iptc.containsTag(IptcDirectory.TAG_HEADLINE))
        imgmeta.setCaption(iptc.getString(IptcDirectory.TAG_HEADLINE));
      if (iptc.containsTag(IptcDirectory.TAG_CAPTION))
        imgmeta.setLegend(iptc.getString(IptcDirectory.TAG_CAPTION));
      if (iptc.containsTag(IptcDirectory.TAG_BY_LINE))
        imgmeta.setPhotographer(iptc.getString(IptcDirectory.TAG_BY_LINE));
      if (iptc.containsTag(IptcDirectory.TAG_COPYRIGHT_NOTICE))
        imgmeta.setCopyright(iptc.getString(IptcDirectory.TAG_COPYRIGHT_NOTICE));
      if (iptc.containsTag(IptcDirectory.TAG_CITY))
        imgmeta.setLocation(iptc.getString(IptcDirectory.TAG_CITY));
      if (iptc.containsTag(IptcDirectory.TAG_KEYWORDS)) {
        StringTokenizer st = new StringTokenizer(iptc.getString(IptcDirectory.TAG_KEYWORDS), ",;");
        while (st.hasMoreTokens()) {
          imgmeta.addKeyword(st.nextToken());
        }
      }

      // Extract EXIF information
      Directory exif = meta.getDirectory(ExifDirectory.class);
      if (exif.containsTag(ExifDirectory.TAG_DATETIME)) {
        try {
          imgmeta.setDateTaken(exif.getDate(ExifDirectory.TAG_DATETIME));
        } catch (MetadataException e) {
        }
      }
      if (exif.containsTag(ExifDirectory.TAG_ISO_EQUIVALENT)) {
        try {
          imgmeta.setFilmspeed(exif.getInt(ExifDirectory.TAG_ISO_EQUIVALENT));
        } catch (MetadataException e) {
        }
      }
      if (exif.containsTag(ExifDirectory.TAG_FNUMBER)) {
        try {
          imgmeta.setFNumber(exif.getFloat(ExifDirectory.TAG_FNUMBER));
        } catch (MetadataException e) {
        }
      }
      if (exif.containsTag(ExifDirectory.TAG_FOCAL_LENGTH)) {
        try {
          imgmeta.setFocalWidth(exif.getInt(ExifDirectory.TAG_FOCAL_LENGTH));
        } catch (MetadataException e) {
        }
      }
      if (exif.containsTag(ExifDirectory.TAG_EXPOSURE_TIME)) {
        try {
          imgmeta.setExposureTime(exif.getFloat(ExifDirectory.TAG_EXPOSURE_TIME));
        } catch (MetadataException e) {
        }
      }
      if (StringUtils.isBlank(imgmeta.getCopyright()) && exif.containsTag(ExifDirectory.TAG_COPYRIGHT))
        imgmeta.setCopyright(exif.getString(ExifDirectory.TAG_COPYRIGHT));

      // Extract GPS information
      try {
        Directory gps = meta.getDirectory(GpsDirectory.class);
        if (gps.containsTag(GpsDirectory.TAG_GPS_LATITUDE)) {
          Rational[] lat = gps.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);
          String latRef = gps.getString(GpsDirectory.TAG_GPS_LATITUDE_REF);
          double latitude = parseHMS(lat);
          if (latitude != 0) {
            if (StringUtils.isNotBlank(latRef) && "S".equalsIgnoreCase(latRef) && latitude > 0)
              latitude *= -1;
          }
          imgmeta.setGpsLat(latitude);
        }
        if (gps.containsTag(GpsDirectory.TAG_GPS_LONGITUDE)) {
          Rational[] lng = gps.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);
          String lngRef = gps.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF);
          double longitude = parseHMS(lng);
          if (longitude != 0) {
            if (StringUtils.isNotBlank(lngRef) && "W".equalsIgnoreCase(lngRef) && longitude > 0)
              longitude *= -1;
          }
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.