]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
Update for bitmap, image on scaling, transparancy,
[wxWidgets.git] / include / wx / image.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: image.h
3 // Purpose: wxImage class
4 // Author: Robert Roebling
5 // RCS-ID: $Id$
6 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_IMAGE_H_
11 #define _WX_IMAGE_H_
12
13 #ifdef __GNUG__
14 #pragma interface "image.h"
15 #endif
16
17 #include "wx/setup.h"
18 #include "wx/object.h"
19 #include "wx/string.h"
20 #include "wx/gdicmn.h"
21
22 //-----------------------------------------------------------------------------
23 // classes
24 //-----------------------------------------------------------------------------
25
26 class WXDLLEXPORT wxImageHandler;
27 class WXDLLEXPORT wxPNGHandler;
28 class WXDLLEXPORT wxBMPHandler;
29 class WXDLLEXPORT wxImage;
30
31 class WXDLLEXPORT wxBitmap;
32
33 //-----------------------------------------------------------------------------
34 // wxImageHandler
35 //-----------------------------------------------------------------------------
36
37 class WXDLLEXPORT wxImageHandler: public wxObject
38 {
39 DECLARE_DYNAMIC_CLASS(wxImageHandler)
40
41 public:
42 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
43
44 virtual bool LoadFile( wxImage *image, const wxString& name );
45 virtual bool SaveFile( wxImage *image, const wxString& name );
46
47 inline void SetName(const wxString& name) { m_name = name; }
48 inline void SetExtension(const wxString& ext) { m_extension = ext; }
49 inline void SetType(long type) { m_type = type; }
50 inline wxString GetName() const { return m_name; }
51 inline wxString GetExtension() const { return m_extension; }
52 inline long GetType() const { return m_type; }
53
54 protected:
55 wxString m_name;
56 wxString m_extension;
57 long m_type;
58
59 };
60
61 //-----------------------------------------------------------------------------
62 // wxPNGHandler
63 //-----------------------------------------------------------------------------
64
65 class WXDLLEXPORT wxPNGHandler: public wxImageHandler
66 {
67 DECLARE_DYNAMIC_CLASS(wxPNGHandler)
68
69 public:
70
71 inline wxPNGHandler()
72 {
73 m_name = "PNG file";
74 m_extension = "png";
75 m_type = wxBITMAP_TYPE_PNG;
76 };
77
78 virtual bool LoadFile( wxImage *image, const wxString& name );
79 virtual bool SaveFile( wxImage *image, const wxString& name );
80 };
81
82 //-----------------------------------------------------------------------------
83 // wxBMPHandler
84 //-----------------------------------------------------------------------------
85
86 class WXDLLEXPORT wxBMPHandler: public wxImageHandler
87 {
88 DECLARE_DYNAMIC_CLASS(wxBMPHandler)
89
90 public:
91
92 inline wxBMPHandler()
93 {
94 m_name = "BMP file";
95 m_extension = "bmp";
96 m_type = wxBITMAP_TYPE_BMP;
97 };
98
99 virtual bool LoadFile( wxImage *image, const wxString& name );
100 };
101
102 //-----------------------------------------------------------------------------
103 // wxImage
104 //-----------------------------------------------------------------------------
105
106 class WXDLLEXPORT wxImage: public wxObject
107 {
108 DECLARE_DYNAMIC_CLASS(wxImage)
109
110 friend class WXDLLEXPORT wxImageHandler;
111
112 public:
113
114 wxImage();
115 wxImage( int width, int height );
116 wxImage( const wxString& name, long type = wxBITMAP_TYPE_PNG );
117
118 wxImage( const wxImage& image );
119 wxImage( const wxImage* image );
120
121 // these functions get implemented in /src/(platform)/bitmap.cpp
122 wxImage( const wxBitmap &bitmap );
123 wxBitmap ConvertToBitmap() const;
124
125 void Create( int width, int height );
126 void Destroy();
127
128 wxImage Scale( int width, int height );
129
130 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG );
131 virtual bool SaveFile( const wxString& name, int type );
132
133 bool Ok() const;
134 int GetWidth() const;
135 int GetHeight() const;
136
137 char unsigned *GetData() const;
138 void SetData( char unsigned *data );
139
140 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
141 unsigned char GetMaskRed() const;
142 unsigned char GetMaskGreen() const;
143 unsigned char GetMaskBlue() const;
144 void SetMask( bool mask = TRUE );
145 bool HasMask() const;
146
147 inline wxImage& operator = (const wxImage& image)
148 { if (*this == image) return (*this); Ref(image); return *this; }
149 inline bool operator == (const wxImage& image)
150 { return m_refData == image.m_refData; }
151 inline bool operator != (const wxImage& image)
152 { return m_refData != image.m_refData; }
153
154 static inline wxList& GetHandlers() { return sm_handlers; }
155 static void AddHandler( wxImageHandler *handler );
156 static void InsertHandler( wxImageHandler *handler );
157 static bool RemoveHandler( const wxString& name );
158 static wxImageHandler *FindHandler( const wxString& name );
159 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
160 static wxImageHandler *FindHandler( long imageType );
161
162 static void CleanUpHandlers();
163 static void InitStandardHandlers();
164
165 protected:
166
167 static wxList sm_handlers;
168
169 };
170
171 #endif
172 // _WX_IMAGE_H_