MythTV  master
imagemetadata.h
Go to the documentation of this file.
1 
9 #ifndef IMAGEMETADATA_H
10 #define IMAGEMETADATA_H
11 
12 #include <QCoreApplication> // for tr()
13 #include <QStringBuilder>
14 #include <QStringList>
15 #include <QDateTime>
16 
17 #include "mythmetaexp.h"
18 
19 
20 // Exif 2.3 standard tag names, see http://www.exiv2.org/tags.html
21 #define EXIF_TAG_ORIENTATION "Exif.Image.Orientation"
22 #define EXIF_TAG_DATETIME "Exif.Image.DateTime"
23 #define EXIF_TAG_DATE_FORMAT "yyyy:MM:dd hh:mm:ss"
24 #define EXIF_TAG_IMAGEDESCRIPTION "Exif.Image.ImageDescription"
25 #define EXIF_TAG_USERCOMMENT "Exif.Photo.UserComment"
26 #define EXIF_PRINT_IMAGE_MATCHING 0xc4a5
27 
28 // ffmpeg video tags
29 #define FFMPEG_TAG_ORIENTATION "rotate"
30 #define FFMPEG_TAG_DATETIME "creation_time"
31 #define FFMPEG_TAG_DATE_FORMAT "yyyy-MM-dd hh:mm:ss"
32 
33 // Pseudo keys for passing Myth data as metadata tags.
34 #define EXIF_MYTH_HOST "Myth.host"
35 #define EXIF_MYTH_PATH "Myth.path"
36 #define EXIF_MYTH_NAME "Myth.name"
37 #define EXIF_MYTH_SIZE "Myth.size"
38 #define EXIF_MYTH_ORIENT "Myth.orient"
39 
40 
44  kRotateCW = 1,
45  kRotateCCW = 2,
48 };
49 
50 
59 {
60  Q_DECLARE_TR_FUNCTIONS(Orientation)
61 public:
62  explicit Orientation(int composite)
63  : m_current(composite / 10), m_file(composite % 10) {}
64  Orientation(int current, int file) : m_current(current), m_file(file) {}
65 
67  int Composite() { return m_current * 10 + m_file; }
68  int Transform(int);
69  int GetCurrent(bool compensate);
70  QString Description();
71 
72  static int FromRotation(const QString &degrees);
73 
74 private:
75  static QString AsText(int orientation);
76 
77  int Apply(int);
78 
79  typedef QHash<int, QHash<int, int> > Matrix;
80 
82  static const bool krunningQt541;
84  static const Matrix kQt541_orientation;
85  static Matrix InitOrientationMatrix();
86 
88  int m_current;
90  int m_file;
91 };
92 
93 
96 {
97  Q_DECLARE_TR_FUNCTIONS(ImageMetaData);
98 public:
99  static ImageMetaData* FromPicture(const QString &filePath);
100  static ImageMetaData* FromVideo(const QString &filePath);
101 
102  virtual ~ImageMetaData() = default;
103 
105  static const QString kSeparator;
106 
108  static QString ToString(const QString &name, const QString &label, const QString &value)
109  { return name % kSeparator % label % kSeparator % value; }
110 
112  static QStringList FromString(const QString &str)
113  { return str.split(kSeparator); }
114 
115  typedef QMap<QString, QStringList> TagMap;
116  static TagMap ToMap(const QStringList &tags);
117 
118  virtual bool IsValid() = 0;
119  virtual QStringList GetAllTags() = 0;
120  virtual int GetOrientation(bool *exists = nullptr) = 0;
121  virtual QDateTime GetOriginalDateTime(bool *exists = nullptr) = 0;
122  virtual QString GetComment(bool *exists = nullptr) = 0;
123 
124 protected:
125  explicit ImageMetaData(const QString &filePath) : m_filePath(filePath) {}
126 
128  QString m_filePath;
129 };
130 
131 
132 #endif // IMAGEMETADATA_H
133 
int m_file
The orientation of the raw file image, as specified by the camera.
Definition: imagemetadata.h:90
int Composite()
Encode original & current orientation to a single Db field.
Definition: imagemetadata.h:67
Abstract class for image metadata.
Definition: imagemetadata.h:95
Encapsulates Exif orientation processing.
Definition: imagemetadata.h:58
static QStringList FromString(const QString &str)
Decodes metadata name, label, value from a string.
Orientation(int composite)
Definition: imagemetadata.h:62
Reset to Exif value.
Definition: imagemetadata.h:43
static const bool krunningQt541
True when using Qt 5.4.1 with its deviant orientation behaviour.
Definition: imagemetadata.h:82
ImageFileTransform
Image transformations.
Definition: imagemetadata.h:42
static const QString kSeparator
Unique separator to delimit fields within a string.
#define META_PUBLIC
Definition: mythmetaexp.h:9
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
static QString ToString(const QString &name, const QString &label, const QString &value)
Encodes metadata into a string as <tag name><tag label><tag value>
Reflect about horizontal axis.
Definition: imagemetadata.h:47
static void Transform(SIMI *Simi, F_PT xo, F_PT yo, F_PT *x, F_PT *y)
Definition: ifs.c:338
const char * name
Definition: ParseText.cpp:328
QHash< int, QHash< int, int > > Matrix
Definition: imagemetadata.h:79
Rotate anti-clockwise.
Definition: imagemetadata.h:45
int m_current
The orientation to use: the file orientation with user transformations applied.
Definition: imagemetadata.h:88
Reflect about vertical axis.
Definition: imagemetadata.h:46
Orientation(int current, int file)
Definition: imagemetadata.h:64
QString m_filePath
Image filepath.
Rotate clockwise.
Definition: imagemetadata.h:44
static const Matrix kQt541_orientation
Orientation conversions for proper display on Qt 5.4.1.
Definition: imagemetadata.h:84
ImageMetaData(const QString &filePath)
QMap< QString, QStringList > TagMap