]>
Commit | Line | Data |
---|---|---|
cf694132 | 1 | ///////////////////////////////////////////////////////////////////////////// |
d14a1e28 RD |
2 | // Name: _image.i |
3 | // Purpose: SWIG definitions for wxImage and such | |
cf694132 RD |
4 | // |
5 | // Author: Robin Dunn | |
6 | // | |
d14a1e28 | 7 | // Created: 25-Sept-2000 |
cf694132 | 8 | // RCS-ID: $Id$ |
d14a1e28 | 9 | // Copyright: (c) 2003 by Total Control Software |
cf694132 RD |
10 | // Licence: wxWindows license |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
d14a1e28 | 13 | // Not a %module |
cf694132 | 14 | |
d14a1e28 RD |
15 | |
16 | //--------------------------------------------------------------------------- | |
cf694132 RD |
17 | |
18 | %{ | |
d14a1e28 | 19 | #include "wx/wxPython/pyistream.h" |
cf694132 RD |
20 | %} |
21 | ||
9cbf6f6e | 22 | //--------------------------------------------------------------------------- |
d14a1e28 | 23 | %newgroup |
9cbf6f6e | 24 | |
cf694132 | 25 | |
9416aa89 | 26 | class wxImageHandler : public wxObject { |
cf694132 | 27 | public: |
1dec68aa | 28 | // wxImageHandler(); Abstract Base Class |
cf694132 RD |
29 | wxString GetName(); |
30 | wxString GetExtension(); | |
31 | long GetType(); | |
32 | wxString GetMimeType(); | |
33 | ||
34 | //bool LoadFile(wxImage* image, wxInputStream& stream); | |
35 | //bool SaveFile(wxImage* image, wxOutputStream& stream); | |
b5a5d647 RD |
36 | //virtual int GetImageCount( wxInputStream& stream ); |
37 | //bool CanRead( wxInputStream& stream ); | |
38 | ||
39 | bool CanRead( const wxString& name ); | |
cf694132 RD |
40 | |
41 | void SetName(const wxString& name); | |
42 | void SetExtension(const wxString& extension); | |
43 | void SetType(long type); | |
44 | void SetMimeType(const wxString& mimetype); | |
45 | }; | |
46 | ||
cf694132 | 47 | |
d14a1e28 | 48 | //--------------------------------------------------------------------------- |
cf694132 | 49 | |
d14a1e28 RD |
50 | class wxImageHistogram /* : public wxImageHistogramBase */ |
51 | { | |
06c0fba4 | 52 | public: |
d14a1e28 | 53 | wxImageHistogram(); |
cf694132 | 54 | |
dd9f7fea | 55 | DocStr(MakeKey, "Get the key in the histogram for the given RGB values"); |
d14a1e28 RD |
56 | static unsigned long MakeKey(unsigned char r, |
57 | unsigned char g, | |
58 | unsigned char b); | |
cf694132 | 59 | |
dd9f7fea RD |
60 | DocDeclAStr( |
61 | bool, FindFirstUnusedColour(unsigned char *OUTPUT, | |
62 | unsigned char *OUTPUT, | |
63 | unsigned char *OUTPUT, | |
64 | unsigned char startR = 1, | |
65 | unsigned char startG = 0, | |
66 | unsigned char startB = 0 ) const, | |
67 | "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)", | |
68 | "Find first colour that is not used in the image and has higher RGB values than\n" | |
69 | "startR, startG, startB. Returns a tuple consisting of a success flag and rgb\n" | |
70 | "values."); | |
9b3d3bc4 RD |
71 | }; |
72 | ||
73 | ||
cf694132 RD |
74 | //--------------------------------------------------------------------------- |
75 | ||
d14a1e28 | 76 | |
9416aa89 | 77 | class wxImage : public wxObject { |
cf694132 | 78 | public: |
b5a5d647 | 79 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); |
cf694132 RD |
80 | ~wxImage(); |
81 | ||
d14a1e28 RD |
82 | // Alternate constructors |
83 | %name(ImageFromMime) wxImage(const wxString& name, const wxString& mimetype, int index = -1); | |
84 | %name(ImageFromStream) wxImage(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1); | |
85 | %name(ImageFromStreamMime) wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1 ); | |
86 | %extend { | |
dd9f7fea | 87 | %name(EmptyImage) wxImage(int width=0, int height=0, bool clear = True) { |
d14a1e28 RD |
88 | if (width > 0 && height > 0) |
89 | return new wxImage(width, height, clear); | |
90 | else | |
91 | return new wxImage; | |
92 | } | |
dce2bd22 | 93 | |
d14a1e28 RD |
94 | %name(ImageFromBitmap) wxImage(const wxBitmap &bitmap) { |
95 | return new wxImage(bitmap.ConvertToImage()); | |
96 | } | |
97 | ||
98 | %name(ImageFromData) wxImage(int width, int height, unsigned char* data) { | |
99 | // Copy the source data so the wxImage can clean it up later | |
100 | unsigned char* copy = (unsigned char*)malloc(width*height*3); | |
101 | if (copy == NULL) { | |
102 | PyErr_NoMemory(); | |
103 | return NULL; | |
104 | } | |
105 | memcpy(copy, data, width*height*3); | |
dd9f7fea | 106 | return new wxImage(width, height, copy, False); |
d14a1e28 RD |
107 | } |
108 | } | |
109 | ||
cf694132 RD |
110 | void Create( int width, int height ); |
111 | void Destroy(); | |
6c0168c9 | 112 | |
cf694132 | 113 | wxImage Scale( int width, int height ); |
9cbf6f6e | 114 | wxImage ShrinkBy( int xFactor , int yFactor ) const ; |
f6bcfd97 | 115 | wxImage& Rescale(int width, int height); |
cf694132 RD |
116 | |
117 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
118 | unsigned char GetRed( int x, int y ); | |
119 | unsigned char GetGreen( int x, int y ); | |
120 | unsigned char GetBlue( int x, int y ); | |
121 | ||
9cbf6f6e RD |
122 | void SetAlpha(int x, int y, unsigned char alpha); |
123 | unsigned char GetAlpha(int x, int y); | |
124 | bool HasAlpha(); | |
125 | ||
126 | // find first colour that is not used in the image and has higher | |
68bc8549 | 127 | // RGB values than <startR,startG,startB> |
dd9f7fea RD |
128 | DocDeclAStr( |
129 | bool, FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT, | |
130 | byte startR = 0, byte startG = 0, byte startB = 0 ) const, | |
131 | "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)", | |
132 | "Find first colour that is not used in the image and has higher RGB values than\n" | |
133 | "startR, startG, startB. Returns a tuple consisting of a success flag and rgb\n" | |
134 | "values."); | |
135 | ||
68bc8549 RD |
136 | |
137 | // Set image's mask to the area of 'mask' that has <mr,mg,mb> colour | |
138 | bool SetMaskFromImage(const wxImage & mask, | |
139 | byte mr, byte mg, byte mb); | |
140 | ||
db0ff83e RD |
141 | // void DoFloodFill (wxCoord x, wxCoord y, |
142 | // const wxBrush & fillBrush, | |
143 | // const wxColour& testColour, | |
144 | // int style = wxFLOOD_SURFACE, | |
145 | // int LogicalFunction = wxCOPY /* currently unused */ ) ; | |
68bc8549 | 146 | |
96bfd053 | 147 | static bool CanRead( const wxString& name ); |
b5a5d647 RD |
148 | static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
149 | ||
150 | bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); | |
151 | %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ); | |
cf694132 RD |
152 | |
153 | bool SaveFile( const wxString& name, int type ); | |
154 | %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype ); | |
155 | ||
f74ff5ef RD |
156 | %name(CanReadStream) static bool CanRead( wxInputStream& stream ); |
157 | %name(LoadStream) bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 ); | |
158 | %name(LoadMimeStream) bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 ); | |
159 | ||
cf694132 RD |
160 | bool Ok(); |
161 | int GetWidth(); | |
162 | int GetHeight(); | |
163 | ||
ba938c3d RD |
164 | %extend { |
165 | wxSize GetSize() { | |
166 | wxSize size(self->GetWidth(), self->GetHeight()); | |
167 | return size; | |
168 | } | |
169 | } | |
170 | ||
9d8bd15f | 171 | wxImage GetSubImage(const wxRect& rect); |
f6bcfd97 BP |
172 | wxImage Copy(); |
173 | void Paste( const wxImage &image, int x, int y ); | |
9d8bd15f | 174 | |
1dc2f865 RD |
175 | //unsigned char *GetData(); |
176 | //void SetData( unsigned char *data ); | |
177 | ||
d14a1e28 | 178 | %extend { |
9cbf6f6e | 179 | PyObject* GetData() { |
d55d6b3f RD |
180 | unsigned char* data = self->GetData(); |
181 | int len = self->GetWidth() * self->GetHeight() * 3; | |
d14a1e28 RD |
182 | PyObject* rv; |
183 | wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len)); | |
184 | return rv; | |
d55d6b3f | 185 | } |
9cbf6f6e RD |
186 | void SetData(PyObject* data) { |
187 | unsigned char* dataPtr; | |
d55d6b3f | 188 | |
9cbf6f6e RD |
189 | if (! PyString_Check(data)) { |
190 | PyErr_SetString(PyExc_TypeError, "Expected string object"); | |
191 | return /* NULL */ ; | |
192 | } | |
193 | ||
194 | size_t len = self->GetWidth() * self->GetHeight() * 3; | |
195 | dataPtr = (unsigned char*) malloc(len); | |
d14a1e28 | 196 | wxPyBLOCK_THREADS( memcpy(dataPtr, PyString_AsString(data), len) ); |
9cbf6f6e RD |
197 | self->SetData(dataPtr); |
198 | // wxImage takes ownership of dataPtr... | |
199 | } | |
200 | ||
201 | ||
202 | ||
203 | PyObject* GetDataBuffer() { | |
1dc2f865 RD |
204 | unsigned char* data = self->GetData(); |
205 | int len = self->GetWidth() * self->GetHeight() * 3; | |
d14a1e28 RD |
206 | PyObject* rv; |
207 | wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) ); | |
208 | return rv; | |
1dc2f865 | 209 | } |
1e4a197e RD |
210 | void SetDataBuffer(PyObject* data) { |
211 | unsigned char* buffer; | |
212 | int size; | |
213 | ||
da32eb53 | 214 | bool blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
215 | if (!PyArg_Parse(data, "t#", &buffer, &size)) |
216 | goto done; | |
1e4a197e RD |
217 | |
218 | if (size != self->GetWidth() * self->GetHeight() * 3) { | |
219 | PyErr_SetString(PyExc_TypeError, "Incorrect buffer size"); | |
d14a1e28 | 220 | goto done; |
1e4a197e | 221 | } |
1e4a197e | 222 | self->SetData(buffer); |
d14a1e28 | 223 | done: |
da32eb53 | 224 | wxPyEndBlockThreads(blocked); |
1e4a197e RD |
225 | } |
226 | ||
9cbf6f6e RD |
227 | |
228 | ||
229 | PyObject* GetAlphaData() { | |
230 | unsigned char* data = self->GetAlpha(); | |
231 | if (! data) { | |
232 | RETURN_NONE(); | |
233 | } else { | |
234 | int len = self->GetWidth() * self->GetHeight(); | |
d14a1e28 RD |
235 | PyObject* rv; |
236 | wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len) ); | |
237 | return rv; | |
9cbf6f6e RD |
238 | } |
239 | } | |
240 | void SetAlphaData(PyObject* data) { | |
1dc2f865 RD |
241 | unsigned char* dataPtr; |
242 | ||
243 | if (! PyString_Check(data)) { | |
244 | PyErr_SetString(PyExc_TypeError, "Expected string object"); | |
245 | return /* NULL */ ; | |
246 | } | |
9d8bd15f | 247 | |
9cbf6f6e | 248 | size_t len = self->GetWidth() * self->GetHeight(); |
185d7c3e | 249 | dataPtr = (unsigned char*) malloc(len); |
d14a1e28 | 250 | wxPyBLOCK_THREADS( memcpy(dataPtr, PyString_AsString(data), len) ); |
9cbf6f6e | 251 | self->SetAlpha(dataPtr); |
3b5ccda1 | 252 | // wxImage takes ownership of dataPtr... |
1dc2f865 | 253 | } |
9cbf6f6e RD |
254 | |
255 | ||
256 | ||
257 | PyObject* GetAlphaBuffer() { | |
258 | unsigned char* data = self->GetAlpha(); | |
259 | int len = self->GetWidth() * self->GetHeight(); | |
d14a1e28 RD |
260 | PyObject* rv; |
261 | wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) ); | |
262 | return rv; | |
9cbf6f6e RD |
263 | } |
264 | void SetAlphaBuffer(PyObject* data) { | |
265 | unsigned char* buffer; | |
266 | int size; | |
267 | ||
da32eb53 | 268 | bool blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
269 | if (!PyArg_Parse(data, "t#", &buffer, &size)) |
270 | goto done; | |
9cbf6f6e RD |
271 | |
272 | if (size != self->GetWidth() * self->GetHeight()) { | |
273 | PyErr_SetString(PyExc_TypeError, "Incorrect buffer size"); | |
d14a1e28 | 274 | goto done; |
9cbf6f6e RD |
275 | } |
276 | self->SetAlpha(buffer); | |
d14a1e28 | 277 | done: |
da32eb53 | 278 | wxPyEndBlockThreads(blocked); |
9cbf6f6e | 279 | } |
1dc2f865 | 280 | } |
cf694132 RD |
281 | |
282 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); | |
283 | unsigned char GetMaskRed(); | |
284 | unsigned char GetMaskGreen(); | |
285 | unsigned char GetMaskBlue(); | |
dd9f7fea | 286 | void SetMask( bool mask = True ); |
cf694132 RD |
287 | bool HasMask(); |
288 | ||
f6bcfd97 | 289 | wxImage Rotate(double angle, const wxPoint & centre_of_rotation, |
dd9f7fea RD |
290 | bool interpolating = True, wxPoint * offset_after_rotation = NULL) const ; |
291 | wxImage Rotate90( bool clockwise = True ) ; | |
292 | wxImage Mirror( bool horizontally = True ) ; | |
f6bcfd97 BP |
293 | |
294 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
295 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
296 | ||
6c0168c9 RD |
297 | // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black) |
298 | wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const; | |
299 | ||
300 | void SetOption(const wxString& name, const wxString& value); | |
301 | %name(SetOptionInt)void SetOption(const wxString& name, int value); | |
302 | wxString GetOption(const wxString& name) const; | |
303 | int GetOptionInt(const wxString& name) const; | |
304 | bool HasOption(const wxString& name) const; | |
305 | ||
f6bcfd97 | 306 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ); |
9cbf6f6e | 307 | unsigned long ComputeHistogram( wxImageHistogram& h ); |
f6bcfd97 | 308 | |
96bfd053 RD |
309 | static void AddHandler( wxImageHandler *handler ); |
310 | static void InsertHandler( wxImageHandler *handler ); | |
311 | static bool RemoveHandler( const wxString& name ); | |
3ef86e32 | 312 | static wxString GetImageExtWildcard(); |
b96c7a38 RD |
313 | |
314 | ||
d14a1e28 | 315 | %extend { |
b96c7a38 RD |
316 | wxBitmap ConvertToBitmap() { |
317 | wxBitmap bitmap(*self); | |
318 | return bitmap; | |
319 | } | |
320 | ||
321 | wxBitmap ConvertToMonoBitmap( unsigned char red, | |
322 | unsigned char green, | |
323 | unsigned char blue ) { | |
324 | wxImage mono = self->ConvertToMono( red, green, blue ); | |
325 | wxBitmap bitmap( mono, 1 ); | |
326 | return bitmap; | |
327 | } | |
328 | } | |
1fded56b | 329 | |
d14a1e28 | 330 | %pythoncode { def __nonzero__(self): return self.Ok() } |
cf694132 RD |
331 | }; |
332 | ||
926bb76c | 333 | |
f74ff5ef | 334 | |
d14a1e28 | 335 | void wxInitAllImageHandlers(); |
cf694132 | 336 | |
f74ff5ef | 337 | |
d14a1e28 RD |
338 | // See also wxPy_ReinitStockObjects in helpers.cpp |
339 | %immutable; | |
340 | const wxImage wxNullImage; | |
341 | %mutable; | |
cf694132 | 342 | |
d14a1e28 | 343 | //--------------------------------------------------------------------------- |
f74ff5ef | 344 | |
b5a5d647 | 345 | |
d14a1e28 RD |
346 | MAKE_CONST_WXSTRING(IMAGE_OPTION_BMP_FORMAT); |
347 | MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_X); | |
348 | MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_Y); | |
349 | MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTION); | |
350 | MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONUNIT); | |
f74ff5ef | 351 | |
d14a1e28 RD |
352 | enum |
353 | { | |
354 | wxIMAGE_RESOLUTION_INCHES = 1, | |
355 | wxIMAGE_RESOLUTION_CM = 2 | |
356 | }; | |
f74ff5ef RD |
357 | |
358 | ||
d14a1e28 RD |
359 | enum |
360 | { | |
361 | wxBMP_24BPP = 24, // default, do not need to set | |
362 | //wxBMP_16BPP = 16, // wxQuantize can only do 236 colors? | |
363 | wxBMP_8BPP = 8, // 8bpp, quantized colors | |
364 | wxBMP_8BPP_GREY = 9, // 8bpp, rgb averaged to greys | |
365 | wxBMP_8BPP_GRAY = wxBMP_8BPP_GREY, | |
366 | wxBMP_8BPP_RED = 10, // 8bpp, red used as greyscale | |
367 | wxBMP_8BPP_PALETTE = 11, // 8bpp, use the wxImage's palette | |
368 | wxBMP_4BPP = 4, // 4bpp, quantized colors | |
369 | wxBMP_1BPP = 1, // 1bpp, quantized "colors" | |
370 | wxBMP_1BPP_BW = 2 // 1bpp, black & white from red | |
371 | }; | |
f74ff5ef RD |
372 | |
373 | ||
d14a1e28 RD |
374 | class wxBMPHandler : public wxImageHandler { |
375 | public: | |
376 | wxBMPHandler(); | |
377 | }; | |
cf694132 | 378 | |
d14a1e28 RD |
379 | class wxICOHandler : public wxBMPHandler { |
380 | public: | |
381 | wxICOHandler(); | |
382 | }; | |
f74ff5ef | 383 | |
d14a1e28 RD |
384 | class wxCURHandler : public wxICOHandler { |
385 | public: | |
386 | wxCURHandler(); | |
387 | }; | |
f74ff5ef | 388 | |
d14a1e28 RD |
389 | class wxANIHandler : public wxCURHandler { |
390 | public: | |
391 | wxANIHandler(); | |
392 | }; | |
06c0fba4 | 393 | |
0a651eb8 | 394 | |
d14a1e28 | 395 | //--------------------------------------------------------------------------- |
0a651eb8 | 396 | |
d14a1e28 RD |
397 | class wxPNGHandler : public wxImageHandler { |
398 | public: | |
399 | wxPNGHandler(); | |
400 | }; | |
0a651eb8 | 401 | |
0a651eb8 | 402 | |
d14a1e28 RD |
403 | class wxGIFHandler : public wxImageHandler { |
404 | public: | |
405 | wxGIFHandler(); | |
406 | }; | |
0a651eb8 RD |
407 | |
408 | ||
d14a1e28 RD |
409 | class wxPCXHandler : public wxImageHandler { |
410 | public: | |
411 | wxPCXHandler(); | |
412 | }; | |
926bb76c | 413 | |
926bb76c | 414 | |
d14a1e28 RD |
415 | class wxJPEGHandler : public wxImageHandler { |
416 | public: | |
417 | wxJPEGHandler(); | |
418 | }; | |
926bb76c | 419 | |
926bb76c | 420 | |
d14a1e28 RD |
421 | class wxPNMHandler : public wxImageHandler { |
422 | public: | |
423 | wxPNMHandler(); | |
424 | }; | |
425 | ||
426 | class wxXPMHandler : public wxImageHandler { | |
427 | public: | |
428 | wxXPMHandler(); | |
429 | }; | |
430 | ||
431 | class wxTIFFHandler : public wxImageHandler { | |
432 | public: | |
433 | wxTIFFHandler(); | |
434 | }; | |
435 | ||
436 | ||
437 | #if wxUSE_IFF | |
438 | class wxIFFHandler : public wxImageHandler { | |
439 | public: | |
440 | wxIFFHandler(); | |
441 | }; | |
442 | #endif | |
926bb76c | 443 | |
cf694132 | 444 | //--------------------------------------------------------------------------- |