]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
converted to 16 colors
[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 #include "wx/bitmap.h"
22
23 #if wxUSE_STREAMS
24 #include "wx/stream.h"
25 #endif
26
27 //-----------------------------------------------------------------------------
28 // classes
29 //-----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxImageHandler;
32 #if wxUSE_LIBPNG
33 class WXDLLEXPORT wxPNGHandler;
34 #endif
35 #if wxUSE_LIBJPEG
36 class WXDLLEXPORT wxJPEGHandler;
37 #endif
38 class WXDLLEXPORT wxBMPHandler;
39 class WXDLLEXPORT wxImage;
40
41 //-----------------------------------------------------------------------------
42 // wxImageHandler
43 //-----------------------------------------------------------------------------
44
45 class WXDLLEXPORT wxImageHandler: public wxObject
46 {
47 DECLARE_DYNAMIC_CLASS(wxImageHandler)
48
49 public:
50 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
51
52 #if wxUSE_STREAMS
53 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
54 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
55 #endif
56
57 inline void SetName(const wxString& name) { m_name = name; }
58 inline void SetExtension(const wxString& ext) { m_extension = ext; }
59 inline void SetType(long type) { m_type = type; }
60 inline void SetMimeType(const wxString& type) { m_mime = type; }
61 inline wxString GetName() const { return m_name; }
62 inline wxString GetExtension() const { return m_extension; }
63 inline long GetType() const { return m_type; }
64 inline wxString GetMimeType() const { return m_mime; }
65
66 protected:
67 wxString m_name;
68 wxString m_extension;
69 wxString m_mime;
70 long m_type;
71
72 };
73
74 //-----------------------------------------------------------------------------
75 // wxPNGHandler
76 //-----------------------------------------------------------------------------
77
78 #if wxUSE_LIBPNG
79 class WXDLLEXPORT wxPNGHandler: public wxImageHandler
80 {
81 DECLARE_DYNAMIC_CLASS(wxPNGHandler)
82
83 public:
84
85 inline wxPNGHandler()
86 {
87 m_name = "PNG file";
88 m_extension = "png";
89 m_type = wxBITMAP_TYPE_PNG;
90 m_mime = "image/png";
91 };
92
93 #if wxUSE_STREAMS
94 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
95 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
96 #endif
97 };
98 #endif
99
100 //-----------------------------------------------------------------------------
101 // wxJPEGHandler
102 //-----------------------------------------------------------------------------
103
104 #if wxUSE_LIBJPEG
105 class WXDLLEXPORT wxJPEGHandler: public wxImageHandler
106 {
107 DECLARE_DYNAMIC_CLASS(wxJPEGHandler)
108
109 public:
110
111 inline wxJPEGHandler()
112 {
113 m_name = "JPEG file";
114 m_extension = "jpg";
115 m_type = wxBITMAP_TYPE_JPEG;
116 m_mime = "image/jpeg";
117 };
118
119 #if wxUSE_STREAMS
120 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
121 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
122 #endif
123 };
124 #endif
125
126 //-----------------------------------------------------------------------------
127 // wxBMPHandler
128 //-----------------------------------------------------------------------------
129
130 class WXDLLEXPORT wxBMPHandler: public wxImageHandler
131 {
132 DECLARE_DYNAMIC_CLASS(wxBMPHandler)
133
134 public:
135
136 inline wxBMPHandler()
137 {
138 m_name = "BMP file";
139 m_extension = "bmp";
140 m_type = wxBITMAP_TYPE_BMP;
141 m_mime = "image/bmp";
142 };
143
144 #if wxUSE_STREAMS
145 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
146 #endif
147 };
148
149 //-----------------------------------------------------------------------------
150 // wxGIFHandler
151 //-----------------------------------------------------------------------------
152
153 class WXDLLEXPORT wxGIFHandler : public wxImageHandler
154 {
155 DECLARE_DYNAMIC_CLASS(wxGIFHandler)
156
157 public:
158
159 inline wxGIFHandler()
160 {
161 m_name = "GIF file";
162 m_extension = "gif";
163 m_type = wxBITMAP_TYPE_GIF;
164 m_mime = "image/gif";
165 };
166
167 #if wxUSE_STREAMS
168 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
169 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
170 #endif
171 };
172
173 //-----------------------------------------------------------------------------
174 // wxImage
175 //-----------------------------------------------------------------------------
176
177 class WXDLLEXPORT wxImage: public wxObject
178 {
179 DECLARE_DYNAMIC_CLASS(wxImage)
180
181 friend class WXDLLEXPORT wxImageHandler;
182
183 public:
184
185 wxImage();
186 wxImage( int width, int height );
187 wxImage( const wxString& name, long type = wxBITMAP_TYPE_PNG );
188 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
189 wxImage( const wxString& name, const wxString& mimetype );
190 wxImage( wxInputStream& stream, const wxString& mimetype );
191
192 wxImage( const wxImage& image );
193 wxImage( const wxImage* image );
194
195 // these functions get implemented in /src/(platform)/bitmap.cpp
196 wxImage( const wxBitmap &bitmap );
197 operator wxBitmap() const { return ConvertToBitmap(); }
198 wxBitmap ConvertToBitmap() const;
199
200 void Create( int width, int height );
201 void Destroy();
202
203 // return the new image with size width*height
204 wxImage Scale( int width, int height ) const;
205
206 // rescales the image in place
207 void Rescale( int width, int height ) { *this = Scale(width, height); }
208
209 // these routines are slow but safe
210 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
211 unsigned char GetRed( int x, int y );
212 unsigned char GetGreen( int x, int y );
213 unsigned char GetBlue( int x, int y );
214
215 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG );
216 virtual bool LoadFile( const wxString& name, const wxString& mimetype );
217
218 #if wxUSE_STREAMS
219 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
220 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
221 #endif
222
223 virtual bool SaveFile( const wxString& name, int type );
224 virtual bool SaveFile( const wxString& name, const wxString& mimetype );
225
226 #if wxUSE_STREAMS
227 virtual bool SaveFile( wxOutputStream& stream, int type );
228 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
229 #endif
230
231 bool Ok() const;
232 int GetWidth() const;
233 int GetHeight() const;
234
235 char unsigned *GetData() const;
236 void SetData( char unsigned *data );
237
238 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
239 unsigned char GetMaskRed() const;
240 unsigned char GetMaskGreen() const;
241 unsigned char GetMaskBlue() const;
242 void SetMask( bool mask = TRUE );
243 bool HasMask() const;
244
245 wxImage& operator = (const wxImage& image)
246 {
247 if ( (*this) != image )
248 Ref(image);
249 return *this;
250 }
251
252 bool operator == (const wxImage& image)
253 { return m_refData == image.m_refData; }
254 bool operator != (const wxImage& image)
255 { return m_refData != image.m_refData; }
256
257 static wxList& GetHandlers() { return sm_handlers; }
258 static void AddHandler( wxImageHandler *handler );
259 static void InsertHandler( wxImageHandler *handler );
260 static bool RemoveHandler( const wxString& name );
261 static wxImageHandler *FindHandler( const wxString& name );
262 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
263 static wxImageHandler *FindHandler( long imageType );
264 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
265
266 static void CleanUpHandlers();
267 static void InitStandardHandlers();
268
269 protected:
270
271 static wxList sm_handlers;
272
273 };
274
275 #endif
276 // _WX_IMAGE_H_
277