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 
15 #include "referencecounter.h"
16 #include "mythpainter.h"
17 
20 enum class BoundaryWanted {No, Yes};
21 
22 class QNetworkReply;
23 class MythUIHelper;
24 
25 class MUI_PUBLIC MythImageReader: public QImageReader
26 {
27  public:
28  explicit MythImageReader(QString fileName);
29  ~MythImageReader();
30 
31  private:
32  QString m_fileName;
33  QNetworkReply *m_networkReply {nullptr};
34 };
35 
36 class 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 SetToYUV(void) { m_isYUV = true; }
58  void ConvertToYUV(void);
59 
60  void Assign(const QImage &img);
61  void Assign(const QPixmap &pix);
62 
63  bool Load(MythImageReader *reader);
64  bool Load(const QString &filename);
65 
66  void Orientation(int orientation);
67  void Resize(const QSize &newSize, bool preserveAspect = false);
68  void Reflect(ReflectAxis axis, int shear, int scale, int length,
69  int spacing = 0);
70  void ToGreyscale();
71 
82  static MythImage *Gradient(MythPainter *painter,
83  const 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 #if QT_VERSION < QT_VERSION_CHECK(5,10,0)
101  return (m_cached) ? byteCount() : 0;
102 #else
103  return (m_cached) ? sizeInBytes() : 0;
104 #endif
105  }
106 
107  protected:
108  ~MythImage() override;
109  static void MakeGradient(QImage &image, const QColor &begin,
110  const QColor &end, int alpha,
111  BoundaryWanted drawBoundary = BoundaryWanted::Yes,
113 
114  bool m_Changed {false};
115  MythPainter *m_Parent {nullptr};
116 
117  bool m_isGradient {false};
118  QColor m_gradBegin {"#000000"};
119  QColor m_gradEnd {"#FFFFFF"};
120  int m_gradAlpha {255};
122 
123  bool m_isOriented {false};
124  bool m_isReflected {false};
125  bool m_isYUV {false};
126 
127  unsigned int m_imageId {0};
128 
129  QString m_FileName;
130 
131  bool m_cached {false};
132 
134 };
135 
136 #endif
137 
unsigned int GetID(void) const
Definition: mythimage.h:88
Encapsulates Exif orientation processing.
Definition: imagemetadata.h:62
virtual void SetChanged(bool change=true)
Definition: mythimage.h:50
General purpose reference counter.
static MythUIHelper * s_ui
Definition: mythimage.h:133
void setIsOriented(bool oriented)
Definition: mythimage.h:94
ReflectAxis
Definition: mythimage.h:18
MythPainter * GetParent(void)
Definition: mythimage.h:44
bool IsReflected() const
Definition: mythimage.h:54
virtual int IncrRef(void)
Increments reference count.
BoundaryWanted
Definition: mythimage.h:20
uint GetCacheSize(void) const
Definition: mythimage.h:98
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
bool IsOriented() const
Definition: mythimage.h:55
unsigned int uint
Definition: compat.h:140
QString m_fileName
Definition: mythimage.h:32
void SetFileName(QString fname)
Definition: mythimage.h:90
#define MUI_PUBLIC
Definition: mythuiexp.h:9
bool IsGradient() const
Definition: mythimage.h:53
bool IsChanged() const
Definition: mythimage.h:51
QString GetFileName(void) const
Definition: mythimage.h:91
void SetID(unsigned int id)
Definition: mythimage.h:87
void SetParent(MythPainter *parent)
Definition: mythimage.h:45
void setIsReflected(bool reflected)
Definition: mythimage.h:93
QString m_FileName
Definition: mythimage.h:129
void SetToYUV(void)
Definition: mythimage.h:57
FillDirection
Definition: mythimage.h:19