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 
19 enum class FillDirection {LeftToRight, TopToBottom};
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 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 
79  static MythImage *Gradient(MythPainter *painter,
80  QSize size, const QColor &begin,
81  const QColor &end, uint alpha,
83 
84  void SetID(unsigned int id) { m_imageId = id; }
85  unsigned int GetID(void) const { return m_imageId; }
86 
87  void SetFileName(QString fname) { m_fileName = std::move(fname); }
88  QString GetFileName(void) const { return m_fileName; }
89 
90  void setIsReflected(bool reflected) { m_isReflected = reflected; }
91  void setIsOriented(bool oriented) { m_isOriented = oriented; }
92 
93  void SetIsInCache(bool bCached);
94 
95  uint GetCacheSize(void) const
96  {
97 #if QT_VERSION < QT_VERSION_CHECK(5,10,0)
98  return (m_cached) ? byteCount() : 0;
99 #else
100  return (m_cached) ? sizeInBytes() : 0;
101 #endif
102  }
103 
104  protected:
105  ~MythImage() override;
106  static void MakeGradient(QImage &image, const QColor &begin,
107  const QColor &end, int alpha,
108  BoundaryWanted drawBoundary = BoundaryWanted::Yes,
110 
111  bool m_changed {false};
112  MythPainter *m_parent {nullptr};
113 
114  bool m_isGradient {false};
115  QColor m_gradBegin {0x00, 0x00, 0x00};
116  QColor m_gradEnd {0xFF, 0xFF, 0xFF};
117  int m_gradAlpha {255};
119 
120  bool m_isOriented {false};
121  bool m_isReflected {false};
122 
123  unsigned int m_imageId {0};
124 
125  QString m_fileName;
126 
127  bool m_cached {false};
128 
130 };
131 
132 #endif
133 
MUI_PUBLIC
#define MUI_PUBLIC
Definition: mythuiexp.h:9
ReferenceCounter::DecrRef
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
Definition: referencecounter.cpp:125
MythImage::SetFileName
void SetFileName(QString fname)
Definition: mythimage.h:87
BoundaryWanted
BoundaryWanted
Definition: mythimage.h:20
MythImage::m_fileName
QString m_fileName
Definition: mythimage.h:125
ReflectAxis
ReflectAxis
Definition: mythimage.h:18
MythImage::setIsOriented
void setIsOriented(bool oriented)
Definition: mythimage.h:91
MythImage::IsReflected
bool IsReflected() const
Definition: mythimage.h:54
ReflectAxis::Horizontal
@ Horizontal
MythImage::GetCacheSize
uint GetCacheSize(void) const
Definition: mythimage.h:95
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:637
MythImageReader::m_fileName
QString m_fileName
Definition: mythimage.h:32
MythImage::setIsReflected
void setIsReflected(bool reflected)
Definition: mythimage.h:90
mythpainter.h
MythImage::SetChanged
virtual void SetChanged(bool change=true)
Definition: mythimage.h:50
uint
unsigned int uint
Definition: compat.h:141
MythImage::GetID
unsigned int GetID(void) const
Definition: mythimage.h:85
referencecounter.h
BoundaryWanted::No
@ No
MythImage::SetID
void SetID(unsigned int id)
Definition: mythimage.h:84
MythImage::SetParent
void SetParent(MythPainter *parent)
Definition: mythimage.h:45
MythImage::IsOriented
bool IsOriented() const
Definition: mythimage.h:55
MythImage::s_ui
static MythUIHelper * s_ui
Definition: mythimage.h:129
MythPainter
Definition: mythpainter.h:33
MythImage
Definition: mythimage.h:37
MythImage::GetParent
MythPainter * GetParent(void)
Definition: mythimage.h:44
MythImage::IsChanged
bool IsChanged() const
Definition: mythimage.h:51
MythImageReader
Definition: mythimage.h:26
MythUIHelper
Definition: mythuihelper.h:25
ReflectAxis::Vertical
@ Vertical
ReferenceCounter::IncrRef
virtual int IncrRef(void)
Increments reference count.
Definition: referencecounter.cpp:101
FillDirection
FillDirection
Definition: mythimage.h:19
ReferenceCounter
General purpose reference counter.
Definition: referencecounter.h:27
Orientation
Encapsulates Exif orientation processing.
Definition: imagemetadata.h:63
MythImage::IsGradient
bool IsGradient() const
Definition: mythimage.h:53
FillDirection::LeftToRight
@ LeftToRight
MythImage::GetFileName
QString GetFileName(void) const
Definition: mythimage.h:88