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