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