Home | History | Annotate | Download | only in media_galleries
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_UTILITY_MEDIA_GALLERIES_IMAGE_METADATA_EXTRACTOR_H_
      6 #define CHROME_UTILITY_MEDIA_GALLERIES_IMAGE_METADATA_EXTRACTOR_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/callback_forward.h"
     12 
     13 namespace media {
     14 class DataSource;
     15 }
     16 
     17 namespace net {
     18 class DrainableIOBuffer;
     19 }
     20 
     21 namespace metadata {
     22 
     23 // Extracts a basic set of image metadata tags. Users must initialize the
     24 // library before use. Each class instance is 'one-time-use', and cannot be used
     25 // to extract metadata from multiple images.
     26 class ImageMetadataExtractor {
     27  public:
     28   typedef base::Callback<void(bool)> DoneCallback;
     29 
     30   // One of these two is required before use of this class.
     31   static bool InitializeLibrary();
     32   static bool InitializeLibraryForTesting();
     33 
     34   ImageMetadataExtractor();
     35   ~ImageMetadataExtractor();
     36 
     37   // |callback| called with whether or not the extraction succeeded. Should
     38   // only be called once.
     39   void Extract(media::DataSource* source, const DoneCallback& callback);
     40 
     41   // All below methods require Extract to have already succeeded.
     42   // Returns -1 if file does not define a width or height.
     43   int width() const;
     44   int height() const;
     45 
     46   // In degrees.
     47   int rotation() const;
     48 
     49   // In pixels per inch.
     50   double x_resolution() const;
     51   double y_resolution() const;
     52 
     53   // In the same string form as the original file.
     54   const std::string& date() const;
     55 
     56   const std::string& camera_make() const;
     57   const std::string& camera_model() const;
     58   double exposure_time_sec() const;
     59   bool flash_fired() const;
     60   double f_number() const;
     61   double focal_length_mm() const;
     62   int iso_equivalent() const;
     63 
     64  private:
     65   // Second half of the Extract method.
     66   void FinishExtraction(const DoneCallback& callback,
     67                         net::DrainableIOBuffer* buffer);
     68 
     69   bool extracted_;
     70 
     71   int width_;
     72   int height_;
     73 
     74   int rotation_;
     75 
     76   double x_resolution_;
     77   double y_resolution_;
     78 
     79   std::string date_;
     80 
     81   std::string camera_make_;
     82   std::string camera_model_;
     83   double exposure_time_sec_;
     84   bool flash_fired_;
     85   double f_number_;
     86   double focal_length_mm_;
     87   int iso_equivalent_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(ImageMetadataExtractor);
     90 };
     91 
     92 }  // namespace metadata
     93 
     94 #endif  // CHROME_UTILITY_MEDIA_GALLERIES_IMAGE_METADATA_EXTRACTOR_H_
     95