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,
51  kFlipVertical = 4
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() const { return m_current * 10 + m_file; }
72  int Transform(int transform);
73  int GetCurrent(bool compensate);
74  QString Description() const;
75 
76  static int FromRotation(const QString &degrees);
77 
78 private:
79  static QString AsText(int orientation);
80 
81  int Apply(int transform) const;
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 {
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 = QMultiMap<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 
Orientation::Orientation
Orientation(int current, int file)
Definition: imagemetadata.h:68
Orientation::Matrix
QHash< int, QHash< int, int > > Matrix
Definition: imagemetadata.h:83
ImageMetaData::~ImageMetaData
virtual ~ImageMetaData()=default
Orientation::m_current
int m_current
The orientation to use: the file orientation with user transformations applied.
Definition: imagemetadata.h:92
Transform
static void Transform(SIMI *Simi, F_PT xo, F_PT yo, F_PT *x, F_PT *y)
Definition: ifs.cpp:333
ImageMetaData
Abstract class for image metadata.
Definition: imagemetadata.h:100
ImageMetaData::Q_DECLARE_TR_FUNCTIONS
Q_DECLARE_TR_FUNCTIONS(ImageMetaData)
ImageMetaData::IsValid
virtual bool IsValid()=0
build_compdb.file
file
Definition: build_compdb.py:55
mythmetaexp.h
Orientation::Orientation
Orientation(int composite)
Definition: imagemetadata.h:66
Orientation::m_file
int m_file
The orientation of the raw file image, as specified by the camera.
Definition: imagemetadata.h:94
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
ImageMetaData::GetOrientation
virtual int GetOrientation(bool *exists=nullptr)=0
ImageMetaData::ToString
static QString ToString(const QString &name, const QString &label, const QString &value)
Encodes metadata into a string as <tag name><tag label><tag value>
Definition: imagemetadata.h:112
ImageMetaData::m_filePath
QString m_filePath
Image filepath.
Definition: imagemetadata.h:133
ImageFileTransform
ImageFileTransform
Image transformations.
Definition: imagemetadata.h:46
Orientation::Composite
int Composite() const
Encode original & current orientation to a single Db field.
Definition: imagemetadata.h:71
ImageMetaData::FromString
static QStringList FromString(const QString &str)
Decodes metadata name, label, value from a string.
Definition: imagemetadata.h:116
ImageMetaData::GetOriginalDateTime
virtual QDateTime GetOriginalDateTime(bool *exists=nullptr)=0
ImageMetaData::TagMap
QMultiMap< QString, QStringList > TagMap
Definition: imagemetadata.h:119
ImageMetaData::GetAllTags
virtual QStringList GetAllTags()=0
ImageMetaData::ImageMetaData
ImageMetaData(QString filePath)
Definition: imagemetadata.h:129
kFlipVertical
@ kFlipVertical
Reflect about horizontal axis.
Definition: imagemetadata.h:51
Orientation::kQt541_orientation
static const Matrix kQt541_orientation
Orientation conversions for proper display on Qt 5.4.1.
Definition: imagemetadata.h:88
kRotateCW
@ kRotateCW
Rotate clockwise.
Definition: imagemetadata.h:48
ImageMetaData::kSeparator
static const QString kSeparator
Unique separator to delimit fields within a string.
Definition: imagemetadata.h:109
ImageMetaData::GetComment
virtual QString GetComment(bool *exists=nullptr)=0
kFlipHorizontal
@ kFlipHorizontal
Reflect about vertical axis.
Definition: imagemetadata.h:50
META_PUBLIC
#define META_PUBLIC
Definition: mythmetaexp.h:9
Orientation::krunningQt541
static const bool krunningQt541
True when using Qt 5.4.1 with its deviant orientation behaviour.
Definition: imagemetadata.h:86
kResetToExif
@ kResetToExif
Reset to Exif value.
Definition: imagemetadata.h:47
Orientation
Encapsulates Exif orientation processing.
Definition: imagemetadata.h:63
kRotateCCW
@ kRotateCCW
Rotate anti-clockwise.
Definition: imagemetadata.h:49