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