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