00001 #ifndef MYTHIMAGE_H_
00002 #define MYTHIMAGE_H_
00003
00004
00005
00006 #include <QImage>
00007 #include <QMutex>
00008 #include <QPixmap>
00009 #include <QImageReader>
00010
00011 #include "mythpainter.h"
00012
00013 enum ReflectAxis {ReflectHorizontal, ReflectVertical};
00014 enum FillDirection {FillLeftToRight, FillTopToBottom};
00015
00016 class QNetworkReply;
00017 class MythUIHelper;
00018
00019 class MUI_PUBLIC MythImageReader: public QImageReader
00020 {
00021 public:
00022 MythImageReader(const QString &fileName);
00023 ~MythImageReader();
00024
00025 private:
00026 QString m_fileName;
00027 QNetworkReply *m_networkReply;
00028 };
00029
00030 class MUI_PUBLIC MythImage : public QImage
00031 {
00032 public:
00033 MythImage(MythPainter *parent);
00034
00035 MythPainter* GetParent(void) { return m_Parent; }
00036 void SetParent(MythPainter *parent) { m_Parent = parent; }
00037 void UpRef(void);
00038 bool DownRef(void);
00039
00040 int RefCount(void);
00041
00042 virtual void SetChanged(bool change = true) { m_Changed = change; }
00043 bool IsChanged() const { return m_Changed; }
00044
00045 bool IsGradient() const { return m_isGradient; }
00046 bool IsReflected() const { return m_isReflected; }
00047
00048 void SetToYUV(void) { m_isYUV = true; }
00049 void ConvertToYUV(void);
00050
00051 void Assign(const QImage &img);
00052 void Assign(const QPixmap &pix);
00053
00054 bool Load(MythImageReader *reader);
00055 bool Load(const QString &filename, bool scale = true);
00056
00057 void Resize(const QSize &newSize, bool preserveAspect = false);
00058 void Reflect(ReflectAxis axis, int shear, int scale, int length,
00059 int spacing = 0);
00060 void ToGreyscale();
00061
00069 static MythImage *Gradient(MythPainter *painter,
00070 const QSize & size, const QColor &beg,
00071 const QColor &end, uint alpha,
00072 FillDirection direction = FillTopToBottom);
00073
00074 void SetID(unsigned int id) { m_imageId = id; }
00075 unsigned int GetID(void) const { return m_imageId; }
00076
00077 void SetFileName(QString fname) { m_FileName = fname; }
00078 QString GetFileName(void) const { return m_FileName; }
00079
00080 void setIsReflected(bool reflected) { m_isReflected = reflected; }
00081
00082 void SetIsInCache(bool bCached);
00083
00084 protected:
00085 virtual ~MythImage();
00086 static void MakeGradient(QImage &image, const QColor &begin,
00087 const QColor &end, int alpha,
00088 bool drawBoundary=true,
00089 FillDirection direction = FillTopToBottom);
00090
00091 bool m_Changed;
00092 MythPainter *m_Parent;
00093
00094 int m_RefCount;
00095 QMutex m_RefCountLock;
00096
00097 bool m_isGradient;
00098 QColor m_gradBegin;
00099 QColor m_gradEnd;
00100 int m_gradAlpha;
00101 FillDirection m_gradDirection;
00102
00103 bool m_isReflected;
00104 bool m_isYUV;
00105
00106 unsigned int m_imageId;
00107
00108 QString m_FileName;
00109
00110 static MythUIHelper *m_ui;
00111 bool m_cached;
00112 };
00113
00114 #endif
00115