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 
16 #include "libmythui/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 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 
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:90
BoundaryWanted
BoundaryWanted
Definition: mythimage.h:20
MythImage::m_fileName
QString m_fileName
Definition: mythimage.h:124
ReflectAxis
ReflectAxis
Definition: mythimage.h:18
MythImage::setIsOriented
void setIsOriented(bool oriented)
Definition: mythimage.h:94
MythImage::IsReflected
bool IsReflected() const
Definition: mythimage.h:54
ReflectAxis::Horizontal
@ Horizontal
BoundaryWanted::Yes
@ Yes
MythImage::GetCacheSize
uint GetCacheSize(void) const
Definition: mythimage.h:98
MythImageReader::m_fileName
QString m_fileName
Definition: mythimage.h:32
MythImage::setIsReflected
void setIsReflected(bool reflected)
Definition: mythimage.h:93
mythpainter.h
MythImage::SetChanged
virtual void SetChanged(bool change=true)
Definition: mythimage.h:50
uint
unsigned int uint
Definition: compat.h:81
MythImage::GetID
unsigned int GetID(void) const
Definition: mythimage.h:88
referencecounter.h
BoundaryWanted::No
@ No
MythImage::SetID
void SetID(unsigned int id)
Definition: mythimage.h:87
MythImage::SetParent
void SetParent(MythPainter *parent)
Definition: mythimage.h:45
MythImage::IsOriented
bool IsOriented() const
Definition: mythimage.h:55
MythImage::GetSize
int64_t GetSize(void)
Definition: mythimage.h:69
MythImage::s_ui
static MythUIHelper * s_ui
Definition: mythimage.h:128
MythPainter
Definition: mythpainter.h:34
MythImage
Definition: mythimage.h:36
MythImage::GetParent
MythPainter * GetParent(void)
Definition: mythimage.h:44
MythImage::IsChanged
bool IsChanged() const
Definition: mythimage.h:51
MythImageReader
Definition: mythimage.h:25
MythUIHelper
Definition: mythuihelper.h:23
ReflectAxis::Vertical
@ Vertical
ReferenceCounter::IncrRef
virtual int IncrRef(void)
Increments reference count.
Definition: referencecounter.cpp:101
build_compdb.filename
filename
Definition: build_compdb.py:21
FillDirection
FillDirection
Definition: mythimage.h:19
FillDirection::TopToBottom
@ TopToBottom
ReferenceCounter
General purpose reference counter.
Definition: referencecounter.h:26
Orientation
Encapsulates Exif orientation processing.
Definition: imagemetadata.h:62
MythImage::IsGradient
bool IsGradient() const
Definition: mythimage.h:53
FillDirection::LeftToRight
@ LeftToRight
MythImage::GetFileName
QString GetFileName(void) const
Definition: mythimage.h:91