MythTV master
mythimage.h
Go to the documentation of this file.
1#ifndef MYTHIMAGE_H_
2#define MYTHIMAGE_H_
3
4// Base class, inherited by painter-specific classes.
5
6// C++ headers
7#include <utility>
8
9// QT headers
10#include <QImage>
11#include <QImageReader>
12#include <QMutex>
13#include <QPixmap>
14
17
18enum class ReflectAxis : std::uint8_t {Horizontal, Vertical};
19enum class FillDirection : std::uint8_t {LeftToRight, TopToBottom};
20enum class BoundaryWanted : std::uint8_t {No, Yes};
21
22class QNetworkReply;
23class MythUIHelper;
24
25class MUI_PUBLIC MythImageReader: public QImageReader
26{
27 public:
28 explicit MythImageReader(QString fileName);
30
31 private:
32 QString m_fileName;
33 QNetworkReply *m_networkReply {nullptr};
34};
35
36class MUI_PUBLIC MythImage : public QImage, public ReferenceCounter
37{
38 public:
39 static QImage ApplyExifOrientation(QImage &image, int orientation);
40
42 explicit MythImage(MythPainter *parent, const char *name = "MythImage");
43
44 MythPainter* GetParent(void) { return m_parent; }
45 void SetParent(MythPainter *parent) { m_parent = parent; }
46
47 int IncrRef(void) override; // ReferenceCounter
48 int DecrRef(void) override; // ReferenceCounter
49
50 virtual void SetChanged(bool change = true) { m_changed = change; }
51 bool IsChanged() const { return m_changed; }
52
53 bool IsGradient() const { return m_isGradient; }
54 bool IsReflected() const { return m_isReflected; }
55 bool IsOriented() const { return m_isOriented; }
56
57 void Assign(const QImage &img);
58 void Assign(const QPixmap &pix);
59
60 bool Load(MythImageReader *reader);
61 bool Load(const QString &filename);
62
63 void Orientation(int orientation);
64 void Resize(QSize newSize, bool preserveAspect = false);
65 void Reflect(ReflectAxis axis, int shear, int scale, int length,
66 int spacing = 0);
67 void ToGreyscale();
68
69 int64_t GetSize(void)
70 { return static_cast<int64_t>(bytesPerLine()) * height(); }
71
82 static MythImage *Gradient(MythPainter *painter,
83 QSize size, const QColor &begin,
84 const QColor &end, uint alpha,
86
87 void SetID(unsigned int id) { m_imageId = id; }
88 unsigned int GetID(void) const { return m_imageId; }
89
90 void SetFileName(QString fname) { m_fileName = std::move(fname); }
91 QString GetFileName(void) const { return m_fileName; }
92
93 void setIsReflected(bool reflected) { m_isReflected = reflected; }
94 void setIsOriented(bool oriented) { m_isOriented = oriented; }
95
96 void SetIsInCache(bool bCached);
97
98 uint GetCacheSize(void) const
99 {
100 return (m_cached) ? sizeInBytes() : 0;
101 }
102
103 protected:
104 ~MythImage() override;
105 static void MakeGradient(QImage &image, const QColor &begin,
106 const QColor &end, int alpha,
107 BoundaryWanted drawBoundary = BoundaryWanted::Yes,
109
110 bool m_changed {false};
111 MythPainter *m_parent {nullptr};
112
113 bool m_isGradient {false};
114 QColor m_gradBegin {0x00, 0x00, 0x00};
115 QColor m_gradEnd {0xFF, 0xFF, 0xFF};
116 int m_gradAlpha {255};
118
119 bool m_isOriented {false};
120 bool m_isReflected {false};
121
122 unsigned int m_imageId {0};
123
124 QString m_fileName;
125
126 bool m_cached {false};
127
129};
130
131#endif
132
QString m_fileName
Definition: mythimage.h:32
uint GetCacheSize(void) const
Definition: mythimage.h:98
bool IsChanged() const
Definition: mythimage.h:51
QString m_fileName
Definition: mythimage.h:124
virtual void SetChanged(bool change=true)
Definition: mythimage.h:50
void setIsOriented(bool oriented)
Definition: mythimage.h:94
unsigned int GetID(void) const
Definition: mythimage.h:88
void SetFileName(QString fname)
Definition: mythimage.h:90
bool IsReflected() const
Definition: mythimage.h:54
static MythUIHelper * s_ui
Definition: mythimage.h:128
bool IsOriented() const
Definition: mythimage.h:55
MythPainter * GetParent(void)
Definition: mythimage.h:44
int64_t GetSize(void)
Definition: mythimage.h:69
bool IsGradient() const
Definition: mythimage.h:53
void SetID(unsigned int id)
Definition: mythimage.h:87
void setIsReflected(bool reflected)
Definition: mythimage.h:93
QString GetFileName(void) const
Definition: mythimage.h:91
void SetParent(MythPainter *parent)
Definition: mythimage.h:45
Encapsulates Exif orientation processing.
Definition: imagemetadata.h:63
General purpose reference counter.
unsigned int uint
Definition: freesurround.h:24
ReflectAxis
Definition: mythimage.h:18
BoundaryWanted
Definition: mythimage.h:20
FillDirection
Definition: mythimage.h:19
#define MUI_PUBLIC
Definition: mythuiexp.h:9