]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: image.i | |
3 | // Purpose: SWIG interface file for wxImage, wxImageHandler, etc. | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 28-Apr-1999 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | ||
14 | %module image | |
15 | ||
16 | %{ | |
17 | #include "helpers.h" | |
18 | #include "pyistream.h" | |
19 | #include <wx/image.h> | |
20 | %} | |
21 | ||
22 | //---------------------------------------------------------------------- | |
23 | ||
24 | %include typemaps.i | |
25 | %include my_typemaps.i | |
26 | ||
27 | // Import some definitions of other classes, etc. | |
28 | %import _defs.i | |
29 | %import misc.i | |
30 | %import gdi.i | |
31 | %import streams.i | |
32 | ||
33 | //--------------------------------------------------------------------------- | |
34 | ||
35 | class wxImageHandler : public wxObject { | |
36 | public: | |
37 | // wxImageHandler(); Abstract Base Class | |
38 | wxString GetName(); | |
39 | wxString GetExtension(); | |
40 | long GetType(); | |
41 | wxString GetMimeType(); | |
42 | ||
43 | //bool LoadFile(wxImage* image, wxInputStream& stream); | |
44 | //bool SaveFile(wxImage* image, wxOutputStream& stream); | |
45 | //virtual int GetImageCount( wxInputStream& stream ); | |
46 | //bool CanRead( wxInputStream& stream ); | |
47 | ||
48 | bool CanRead( const wxString& name ); | |
49 | ||
50 | void SetName(const wxString& name); | |
51 | void SetExtension(const wxString& extension); | |
52 | void SetType(long type); | |
53 | void SetMimeType(const wxString& mimetype); | |
54 | }; | |
55 | ||
56 | //--------------------------------------------------------------------------- | |
57 | ||
58 | class wxPNGHandler : public wxImageHandler { | |
59 | public: | |
60 | wxPNGHandler(); | |
61 | }; | |
62 | ||
63 | ||
64 | class wxJPEGHandler : public wxImageHandler { | |
65 | public: | |
66 | wxJPEGHandler(); | |
67 | }; | |
68 | ||
69 | ||
70 | class wxBMPHandler : public wxImageHandler { | |
71 | public: | |
72 | wxBMPHandler(); | |
73 | }; | |
74 | ||
75 | class wxICOHandler : public wxBMPHandler { | |
76 | public: | |
77 | wxICOHandler(); | |
78 | }; | |
79 | ||
80 | class wxCURHandler : public wxICOHandler { | |
81 | public: | |
82 | wxCURHandler(); | |
83 | }; | |
84 | ||
85 | class wxANIHandler : public wxCURHandler { | |
86 | public: | |
87 | wxANIHandler(); | |
88 | }; | |
89 | ||
90 | class wxGIFHandler : public wxImageHandler { | |
91 | public: | |
92 | wxGIFHandler(); | |
93 | }; | |
94 | ||
95 | class wxPNMHandler : public wxImageHandler { | |
96 | public: | |
97 | wxPNMHandler(); | |
98 | }; | |
99 | ||
100 | class wxPCXHandler : public wxImageHandler { | |
101 | public: | |
102 | wxPCXHandler(); | |
103 | }; | |
104 | ||
105 | class wxTIFFHandler : public wxImageHandler { | |
106 | public: | |
107 | wxTIFFHandler(); | |
108 | }; | |
109 | ||
110 | ||
111 | ||
112 | //--------------------------------------------------------------------------- | |
113 | ||
114 | class wxImage : public wxObject { | |
115 | public: | |
116 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); | |
117 | ~wxImage(); | |
118 | ||
119 | void Create( int width, int height ); | |
120 | void Destroy(); | |
121 | ||
122 | wxImage Scale( int width, int height ); | |
123 | wxImage& Rescale(int width, int height); | |
124 | ||
125 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
126 | unsigned char GetRed( int x, int y ); | |
127 | unsigned char GetGreen( int x, int y ); | |
128 | unsigned char GetBlue( int x, int y ); | |
129 | ||
130 | // find first colour that is not used in the image and has higher | |
131 | // RGB values than <startR,startG,startB> | |
132 | bool FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT, | |
133 | byte startR = 0, byte startG = 0, byte startB = 0 ) const; | |
134 | ||
135 | // Set image's mask to the area of 'mask' that has <mr,mg,mb> colour | |
136 | bool SetMaskFromImage(const wxImage & mask, | |
137 | byte mr, byte mg, byte mb); | |
138 | ||
139 | // void DoFloodFill (wxCoord x, wxCoord y, | |
140 | // const wxBrush & fillBrush, | |
141 | // const wxColour& testColour, | |
142 | // int style = wxFLOOD_SURFACE, | |
143 | // int LogicalFunction = wxCOPY /* currently unused */ ) ; | |
144 | ||
145 | static bool CanRead( const wxString& name ); | |
146 | static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY ); | |
147 | ||
148 | bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); | |
149 | %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ); | |
150 | ||
151 | bool SaveFile( const wxString& name, int type ); | |
152 | %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype ); | |
153 | ||
154 | %name(CanReadStream) static bool CanRead( wxInputStream& stream ); | |
155 | %name(LoadStream) bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 ); | |
156 | %name(LoadMimeStream) bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 ); | |
157 | ||
158 | bool Ok(); | |
159 | int GetWidth(); | |
160 | int GetHeight(); | |
161 | ||
162 | wxImage GetSubImage(const wxRect& rect); | |
163 | wxImage Copy(); | |
164 | void Paste( const wxImage &image, int x, int y ); | |
165 | ||
166 | //unsigned char *GetData(); | |
167 | //void SetData( unsigned char *data ); | |
168 | ||
169 | %addmethods { | |
170 | PyObject* GetData() { | |
171 | unsigned char* data = self->GetData(); | |
172 | int len = self->GetWidth() * self->GetHeight() * 3; | |
173 | return PyString_FromStringAndSize((char*)data, len); | |
174 | } | |
175 | ||
176 | void SetData(PyObject* data) { | |
177 | unsigned char* dataPtr; | |
178 | ||
179 | if (! PyString_Check(data)) { | |
180 | PyErr_SetString(PyExc_TypeError, "Expected string object"); | |
181 | return /* NULL */ ; | |
182 | } | |
183 | ||
184 | size_t len = self->GetWidth() * self->GetHeight() * 3; | |
185 | dataPtr = (unsigned char*) malloc(len); | |
186 | memcpy(dataPtr, PyString_AsString(data), len); | |
187 | self->SetData(dataPtr); | |
188 | } | |
189 | } | |
190 | ||
191 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); | |
192 | unsigned char GetMaskRed(); | |
193 | unsigned char GetMaskGreen(); | |
194 | unsigned char GetMaskBlue(); | |
195 | void SetMask( bool mask = TRUE ); | |
196 | bool HasMask(); | |
197 | ||
198 | wxImage Rotate(double angle, const wxPoint & centre_of_rotation, | |
199 | bool interpolating = TRUE, wxPoint * offset_after_rotation = NULL) const ; | |
200 | wxImage Rotate90( bool clockwise = TRUE ) ; | |
201 | wxImage Mirror( bool horizontally = TRUE ) ; | |
202 | ||
203 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
204 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
205 | ||
206 | // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black) | |
207 | wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const; | |
208 | ||
209 | void SetOption(const wxString& name, const wxString& value); | |
210 | %name(SetOptionInt)void SetOption(const wxString& name, int value); | |
211 | wxString GetOption(const wxString& name) const; | |
212 | int GetOptionInt(const wxString& name) const; | |
213 | bool HasOption(const wxString& name) const; | |
214 | ||
215 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ); | |
216 | // TODO: unsigned long ComputeHistogram( wxHashTable &h ); | |
217 | ||
218 | static void AddHandler( wxImageHandler *handler ); | |
219 | static void InsertHandler( wxImageHandler *handler ); | |
220 | static bool RemoveHandler( const wxString& name ); | |
221 | ||
222 | ||
223 | %addmethods { | |
224 | wxBitmap ConvertToBitmap() { | |
225 | wxBitmap bitmap(*self); | |
226 | return bitmap; | |
227 | } | |
228 | ||
229 | wxBitmap ConvertToMonoBitmap( unsigned char red, | |
230 | unsigned char green, | |
231 | unsigned char blue ) { | |
232 | wxImage mono = self->ConvertToMono( red, green, blue ); | |
233 | wxBitmap bitmap( mono, 1 ); | |
234 | return bitmap; | |
235 | } | |
236 | } | |
237 | }; | |
238 | ||
239 | ||
240 | // Alternate constructors | |
241 | %new wxImage* wxEmptyImage(int width=0, int height=0); | |
242 | %new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1); | |
243 | %new wxImage* wxImageFromBitmap(const wxBitmap &bitmap); | |
244 | %new wxImage* wxImageFromData(int width, int height, unsigned char* data); | |
245 | %new wxImage* wxImageFromStream(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1); | |
246 | %new wxImage* wxImageFromStreamMime(wxInputStream& stream, const wxString& mimetype, int index = -1 ); | |
247 | ||
248 | %{ | |
249 | wxImage* wxEmptyImage(int width=0, int height=0) { | |
250 | if (width == 0 && height == 0) | |
251 | return new wxImage; | |
252 | else | |
253 | return new wxImage(width, height); | |
254 | } | |
255 | ||
256 | ||
257 | wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) { | |
258 | return new wxImage(name, mimetype, index); | |
259 | } | |
260 | ||
261 | ||
262 | wxImage* wxImageFromBitmap(const wxBitmap &bitmap) { | |
263 | return new wxImage(bitmap.ConvertToImage()); | |
264 | } | |
265 | ||
266 | ||
267 | wxImage* wxImageFromData(int width, int height, unsigned char* data) { | |
268 | // Copy the source data so the wxImage can clean it up later | |
269 | unsigned char* copy = (unsigned char*)malloc(width*height*3); | |
270 | if (copy == NULL) { | |
271 | PyErr_NoMemory(); | |
272 | return NULL; | |
273 | } | |
274 | memcpy(copy, data, width*height*3); | |
275 | return new wxImage(width, height, copy, FALSE); | |
276 | } | |
277 | ||
278 | ||
279 | wxImage* wxImageFromStream(wxInputStream& stream, | |
280 | long type = wxBITMAP_TYPE_ANY, int index = -1) { | |
281 | return new wxImage(stream, type, index); | |
282 | } | |
283 | ||
284 | ||
285 | wxImage* wxImageFromStreamMime(wxInputStream& stream, | |
286 | const wxString& mimetype, int index = -1 ) { | |
287 | return new wxImage(stream, mimetype, index); | |
288 | } | |
289 | %} | |
290 | ||
291 | ||
292 | ||
293 | void wxInitAllImageHandlers(); | |
294 | ||
295 | ||
296 | %readonly | |
297 | %{ | |
298 | #if 0 | |
299 | %} | |
300 | ||
301 | extern wxImage wxNullImage; | |
302 | ||
303 | %readwrite | |
304 | %{ | |
305 | #endif | |
306 | %} | |
307 | ||
308 | ||
309 | ||
310 | //--------------------------------------------------------------------------- | |
311 | // This one is here to avoid circular imports | |
312 | ||
313 | %new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1); | |
314 | ||
315 | %{ | |
316 | wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) { | |
317 | return new wxBitmap(img, depth); | |
318 | } | |
319 | ||
320 | %} | |
321 | ||
322 | ||
323 | //--------------------------------------------------------------------------- |