]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: _image.i | |
3 | // Purpose: SWIG definitions for wxImage and such | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 25-Sept-2000 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | ||
18 | %{ | |
19 | #include "wx/wxPython/pyistream.h" | |
20 | %} | |
21 | ||
22 | //--------------------------------------------------------------------------- | |
23 | %newgroup | |
24 | ||
25 | ||
26 | class wxImageHandler : public wxObject { | |
27 | public: | |
28 | // wxImageHandler(); Abstract Base Class | |
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); | |
36 | //virtual int GetImageCount( wxInputStream& stream ); | |
37 | //bool CanRead( wxInputStream& stream ); | |
38 | ||
39 | bool CanRead( const wxString& name ); | |
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 | ||
47 | ||
48 | //--------------------------------------------------------------------------- | |
49 | ||
50 | class wxImageHistogram /* : public wxImageHistogramBase */ | |
51 | { | |
52 | public: | |
53 | wxImageHistogram(); | |
54 | ||
55 | DocStr(MakeKey, "Get the key in the histogram for the given RGB values", ""); | |
56 | static unsigned long MakeKey(unsigned char r, | |
57 | unsigned char g, | |
58 | unsigned char b); | |
59 | ||
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 | |
69 | values than startR, startG, startB. Returns a tuple consisting of a | |
70 | success flag and rgb values.", ""); | |
71 | ||
72 | %extend { | |
73 | DocStr(GetCount, | |
74 | "Returns the pixel count for the given key. Use `MakeKey` to create a | |
75 | key value from a RGB tripple.", ""); | |
76 | unsigned long GetCount(unsigned long key) { | |
77 | wxImageHistogramEntry e = (*self)[key]; | |
78 | return e.value; | |
79 | } | |
80 | ||
81 | DocStr(GetCountRGB, | |
82 | "Returns the pixel count for the given RGB values.", ""); | |
83 | unsigned long GetCountRGB(unsigned char r, | |
84 | unsigned char g, | |
85 | unsigned char b) { | |
86 | unsigned long key = wxImageHistogram::MakeKey(r, g, b); | |
87 | wxImageHistogramEntry e = (*self)[key]; | |
88 | return e.value; | |
89 | } | |
90 | ||
91 | DocStr(GetCountColour, | |
92 | "Returns the pixel count for the given `wx.Colour` value.", ""); | |
93 | unsigned long GetCountColour(const wxColour& colour) { | |
94 | unsigned long key = wxImageHistogram::MakeKey(colour.Red(), | |
95 | colour.Green(), | |
96 | colour.Blue()); | |
97 | wxImageHistogramEntry e = (*self)[key]; | |
98 | return e.value; | |
99 | } | |
100 | } | |
101 | ||
102 | }; | |
103 | ||
104 | ||
105 | //--------------------------------------------------------------------------- | |
106 | ||
107 | %{ | |
108 | typedef unsigned char* buffer; | |
109 | %} | |
110 | ||
111 | %typemap(in) (buffer data, int DATASIZE) | |
112 | { if (!PyArg_Parse($input, "t#", &$1, &$2)) SWIG_fail; } | |
113 | ||
114 | %typemap(in) (buffer alpha, int ALPHASIZE) | |
115 | { if (!PyArg_Parse($input, "t#", &$1, &$2)) SWIG_fail; } | |
116 | ||
117 | //--------------------------------------------------------------------------- | |
118 | ||
119 | ||
120 | class wxImage : public wxObject { | |
121 | public: | |
122 | DocCtorStr( | |
123 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ), | |
124 | "", ""); | |
125 | ||
126 | ~wxImage(); | |
127 | ||
128 | // Alternate constructors | |
129 | DocCtorStrName( | |
130 | wxImage(const wxString& name, const wxString& mimetype, int index = -1), | |
131 | "", "", | |
132 | ImageFromMime); | |
133 | ||
134 | DocCtorStrName( | |
135 | wxImage(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1), | |
136 | "", "", | |
137 | ImageFromStream); | |
138 | ||
139 | DocCtorStrName( | |
140 | wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1 ), | |
141 | "", "", | |
142 | ImageFromStreamMime); | |
143 | ||
144 | %extend { | |
145 | %RenameDocCtor( | |
146 | EmptyImage, | |
147 | "Construct an empty image of a given size, optionally setting all | |
148 | pixels to black.", "", | |
149 | wxImage(int width=0, int height=0, bool clear = true)) | |
150 | { | |
151 | if (width > 0 && height > 0) | |
152 | return new wxImage(width, height, clear); | |
153 | else | |
154 | return new wxImage; | |
155 | } | |
156 | ||
157 | ||
158 | MustHaveApp(wxImage(const wxBitmap &bitmap)); | |
159 | ||
160 | %RenameDocCtor( | |
161 | ImageFromBitmap, | |
162 | "Construct an Image from a `wx.Bitmap`.", "", | |
163 | wxImage(const wxBitmap &bitmap)) | |
164 | { | |
165 | return new wxImage(bitmap.ConvertToImage()); | |
166 | } | |
167 | ||
168 | %RenameDocCtor( | |
169 | ImageFromData, | |
170 | "Construct an Image from a buffer of RGB bytes. Accepts either a | |
171 | string or a buffer object holding the data and the length of the data | |
172 | must be width*height*3.", "", | |
173 | wxImage(int width, int height, buffer data, int DATASIZE)) | |
174 | { | |
175 | if (DATASIZE != width*height*3) { | |
176 | wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size."); | |
177 | return NULL; | |
178 | } | |
179 | ||
180 | // Copy the source data so the wxImage can clean it up later | |
181 | buffer copy = (buffer)malloc(DATASIZE); | |
182 | if (copy == NULL) { | |
183 | wxPyBLOCK_THREADS(PyErr_NoMemory()); | |
184 | return NULL; | |
185 | } | |
186 | memcpy(copy, data, DATASIZE); | |
187 | return new wxImage(width, height, copy, false); | |
188 | } | |
189 | ||
190 | ||
191 | %RenameDocCtor( | |
192 | ImageFromDataWithAlpha, | |
193 | "Construct an Image from a buffer of RGB bytes with an Alpha channel. | |
194 | Accepts either a string or a buffer object holding the data and the | |
195 | length of the data must be width*height*3.", "", | |
196 | wxImage(int width, int height, buffer data, int DATASIZE, buffer alpha, int ALPHASIZE)) | |
197 | { | |
198 | if (DATASIZE != width*height*3) { | |
199 | wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size."); | |
200 | return NULL; | |
201 | } | |
202 | if (ALPHASIZE != width*height) { | |
203 | wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size."); | |
204 | return NULL; | |
205 | } | |
206 | ||
207 | // Copy the source data so the wxImage can clean it up later | |
208 | buffer dcopy = (buffer)malloc(DATASIZE); | |
209 | if (dcopy == NULL) { | |
210 | wxPyBLOCK_THREADS(PyErr_NoMemory()); | |
211 | return NULL; | |
212 | } | |
213 | memcpy(dcopy, data, DATASIZE); | |
214 | ||
215 | buffer acopy = (buffer)malloc(ALPHASIZE); | |
216 | if (acopy == NULL) { | |
217 | wxPyBLOCK_THREADS(PyErr_NoMemory()); | |
218 | return NULL; | |
219 | } | |
220 | memcpy(acopy, alpha, ALPHASIZE); | |
221 | ||
222 | return new wxImage(width, height, dcopy, acopy, false); | |
223 | } | |
224 | } | |
225 | ||
226 | // TODO: wxImage( char** xpmData ); | |
227 | ||
228 | ||
229 | void Create( int width, int height ); | |
230 | void Destroy(); | |
231 | ||
232 | wxImage Scale( int width, int height ); | |
233 | wxImage ShrinkBy( int xFactor , int yFactor ) const ; | |
234 | wxImage& Rescale(int width, int height); | |
235 | ||
236 | // resizes the image in place | |
237 | wxImage& Resize( const wxSize& size, const wxPoint& pos, | |
238 | int r = -1, int g = -1, int b = -1 ); | |
239 | ||
240 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
241 | ||
242 | %Rename(SetRGBRect, | |
243 | void, SetRGB( const wxRect& rect, | |
244 | unsigned char r, unsigned char g, unsigned char b )); | |
245 | ||
246 | unsigned char GetRed( int x, int y ); | |
247 | unsigned char GetGreen( int x, int y ); | |
248 | unsigned char GetBlue( int x, int y ); | |
249 | ||
250 | void SetAlpha(int x, int y, unsigned char alpha); | |
251 | unsigned char GetAlpha(int x, int y); | |
252 | bool HasAlpha(); | |
253 | ||
254 | DocDeclStr( | |
255 | void , InitAlpha(), | |
256 | "Initializes the image alpha channel data. It is an error to call it if | |
257 | the image already has alpha data. If it doesn't, alpha data will be by | |
258 | default initialized to all pixels being fully opaque. But if the image | |
259 | has a a mask colour, all mask pixels will be completely transparent.", ""); | |
260 | ||
261 | ||
262 | // find first colour that is not used in the image and has higher | |
263 | // RGB values than <startR,startG,startB> | |
264 | DocDeclAStr( | |
265 | bool, FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT, | |
266 | byte startR = 0, byte startG = 0, byte startB = 0 ) const, | |
267 | "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)", | |
268 | "Find first colour that is not used in the image and has higher RGB | |
269 | values than startR, startG, startB. Returns a tuple consisting of a | |
270 | success flag and rgb values.", ""); | |
271 | ||
272 | ||
273 | DocDeclStr( | |
274 | bool , ConvertAlphaToMask(byte threshold = 128), | |
275 | "If the image has alpha channel, this method converts it to mask. All pixels | |
276 | with alpha value less than ``threshold`` are replaced with mask colour and the | |
277 | alpha channel is removed. Mask colour is chosen automatically using | |
278 | `FindFirstUnusedColour`. | |
279 | ||
280 | If the image image doesn't have alpha channel, ConvertAlphaToMask does | |
281 | nothing.", ""); | |
282 | ||
283 | ||
284 | DocDeclStr( | |
285 | bool , ConvertColourToAlpha( unsigned char r, unsigned char g, unsigned char b ), | |
286 | "This method converts an image where the original alpha information is | |
287 | only available as a shades of a colour (actually shades of grey) | |
288 | typically when you draw anti-aliased text into a bitmap. The DC | |
289 | drawing routines draw grey values on the black background although | |
290 | they actually mean to draw white with differnt alpha values. This | |
291 | method reverses it, assuming a black (!) background and white text. | |
292 | The method will then fill up the whole image with the colour given.", ""); | |
293 | ||
294 | ||
295 | ||
296 | // Set image's mask to the area of 'mask' that has <mr,mg,mb> colour | |
297 | bool SetMaskFromImage(const wxImage & mask, | |
298 | byte mr, byte mg, byte mb); | |
299 | ||
300 | // void DoFloodFill (wxCoord x, wxCoord y, | |
301 | // const wxBrush & fillBrush, | |
302 | // const wxColour& testColour, | |
303 | // int style = wxFLOOD_SURFACE, | |
304 | // int LogicalFunction = wxCOPY /* currently unused */ ) ; | |
305 | ||
306 | static bool CanRead( const wxString& name ); | |
307 | static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY ); | |
308 | ||
309 | bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); | |
310 | %Rename(LoadMimeFile, bool, LoadFile( const wxString& name, const wxString& mimetype, int index = -1 )); | |
311 | ||
312 | bool SaveFile( const wxString& name, int type ); | |
313 | %Rename(SaveMimeFile, bool, SaveFile( const wxString& name, const wxString& mimetype )); | |
314 | ||
315 | %Rename(CanReadStream, static bool, CanRead( wxInputStream& stream )); | |
316 | %Rename(LoadStream, bool, LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 )); | |
317 | %Rename(LoadMimeStream, bool, LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 )); | |
318 | ||
319 | bool Ok(); | |
320 | int GetWidth(); | |
321 | int GetHeight(); | |
322 | ||
323 | %extend { | |
324 | wxSize GetSize() { | |
325 | wxSize size(self->GetWidth(), self->GetHeight()); | |
326 | return size; | |
327 | } | |
328 | } | |
329 | ||
330 | wxImage GetSubImage(const wxRect& rect); | |
331 | ||
332 | // Paste the image or part of this image into an image of the given size at the pos | |
333 | // any newly exposed areas will be filled with the rgb colour | |
334 | // by default if r = g = b = -1 then fill with this image's mask colour or find and | |
335 | // set a suitable mask colour | |
336 | wxImage Size( const wxSize& size, const wxPoint& pos, | |
337 | int r = -1, int g = -1, int b = -1 ) const; | |
338 | ||
339 | wxImage Copy(); | |
340 | void Paste( const wxImage &image, int x, int y ); | |
341 | ||
342 | //unsigned char *GetData(); | |
343 | //void SetData( unsigned char *data ); | |
344 | ||
345 | %extend { | |
346 | DocStr(GetData, | |
347 | "Returns a string containing a copy of the RGB bytes of the image.", ""); | |
348 | PyObject* GetData() | |
349 | { | |
350 | buffer data = self->GetData(); | |
351 | int len = self->GetWidth() * self->GetHeight() * 3; | |
352 | PyObject* rv; | |
353 | wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len)); | |
354 | return rv; | |
355 | } | |
356 | DocStr(SetData, | |
357 | "Resets the Image's RGB data from a buffer of RGB bytes. Accepts | |
358 | either a string or a buffer object holding the data and the length of | |
359 | the data must be width*height*3.", ""); | |
360 | void SetData(buffer data, int DATASIZE) | |
361 | { | |
362 | if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) { | |
363 | wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size."); | |
364 | return; | |
365 | } | |
366 | buffer copy = (buffer)malloc(DATASIZE); | |
367 | if (copy == NULL) { | |
368 | wxPyBLOCK_THREADS(PyErr_NoMemory()); | |
369 | return; | |
370 | } | |
371 | memcpy(copy, data, DATASIZE); | |
372 | self->SetData(copy, false); | |
373 | // wxImage takes ownership of copy... | |
374 | } | |
375 | ||
376 | ||
377 | DocStr(GetDataBuffer, | |
378 | "Returns a writable Python buffer object that is pointing at the RGB | |
379 | image data buffer inside the wx.Image.", ""); | |
380 | PyObject* GetDataBuffer() | |
381 | { | |
382 | buffer data = self->GetData(); | |
383 | int len = self->GetWidth() * self->GetHeight() * 3; | |
384 | PyObject* rv; | |
385 | wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) ); | |
386 | return rv; | |
387 | } | |
388 | ||
389 | DocStr(SetDataBuffer, | |
390 | "Sets the internal image data pointer to point at a Python buffer | |
391 | object. This can save a copy of the data but you must ensure that the | |
392 | buffer object lives longer than the wx.Image does.", ""); | |
393 | void SetDataBuffer(buffer data, int DATASIZE) | |
394 | { | |
395 | if (DATASIZE != self->GetWidth() * self->GetHeight() * 3) { | |
396 | wxPyErr_SetString(PyExc_ValueError, "Invalid data buffer size."); | |
397 | return; | |
398 | } | |
399 | self->SetData(data, true); | |
400 | } | |
401 | ||
402 | ||
403 | ||
404 | DocStr(GetAlphaData, | |
405 | "Returns a string containing a copy of the alpha bytes of the image.", ""); | |
406 | PyObject* GetAlphaData() { | |
407 | buffer data = self->GetAlpha(); | |
408 | if (! data) { | |
409 | RETURN_NONE(); | |
410 | } else { | |
411 | int len = self->GetWidth() * self->GetHeight(); | |
412 | PyObject* rv; | |
413 | wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len) ); | |
414 | return rv; | |
415 | } | |
416 | } | |
417 | ||
418 | DocStr(SetAlphaData, | |
419 | "Resets the Image's alpha data from a buffer of bytes. Accepts either | |
420 | a string or a buffer object holding the data and the length of the | |
421 | data must be width*height.", ""); | |
422 | void SetAlphaData(buffer alpha, int ALPHASIZE) | |
423 | { | |
424 | if (ALPHASIZE != self->GetWidth() * self->GetHeight()) { | |
425 | wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size."); | |
426 | return; | |
427 | } | |
428 | buffer acopy = (buffer)malloc(ALPHASIZE); | |
429 | if (acopy == NULL) { | |
430 | wxPyBLOCK_THREADS(PyErr_NoMemory()); | |
431 | return; | |
432 | } | |
433 | memcpy(acopy, alpha, ALPHASIZE); | |
434 | self->SetAlpha(acopy, false); | |
435 | // wxImage takes ownership of acopy... | |
436 | } | |
437 | ||
438 | ||
439 | ||
440 | DocStr(GetDataBuffer, | |
441 | "Returns a writable Python buffer object that is pointing at the Alpha | |
442 | data buffer inside the wx.Image.", ""); | |
443 | PyObject* GetAlphaBuffer() | |
444 | { | |
445 | buffer data = self->GetAlpha(); | |
446 | int len = self->GetWidth() * self->GetHeight(); | |
447 | PyObject* rv; | |
448 | wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) ); | |
449 | return rv; | |
450 | } | |
451 | ||
452 | ||
453 | DocStr(SetDataBuffer, | |
454 | "Sets the internal image alpha pointer to point at a Python buffer | |
455 | object. This can save a copy of the data but you must ensure that the | |
456 | buffer object lives longer than the wx.Image does.", ""); | |
457 | void SetAlphaBuffer(buffer alpha, int ALPHASIZE) | |
458 | { | |
459 | if (ALPHASIZE != self->GetWidth() * self->GetHeight()) { | |
460 | wxPyErr_SetString(PyExc_ValueError, "Invalid alpha buffer size."); | |
461 | return; | |
462 | } | |
463 | self->SetAlpha(alpha, true); | |
464 | } | |
465 | } | |
466 | ||
467 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); | |
468 | ||
469 | DocDeclAStr( | |
470 | /*bool*/ void , GetOrFindMaskColour( unsigned char *OUTPUT, | |
471 | unsigned char *OUTPUT, | |
472 | unsigned char *OUTPUT ) const, | |
473 | "GetOrFindMaskColour() -> (r,g,b)", | |
474 | "Get the current mask colour or find a suitable colour.", ""); | |
475 | ||
476 | ||
477 | unsigned char GetMaskRed(); | |
478 | unsigned char GetMaskGreen(); | |
479 | unsigned char GetMaskBlue(); | |
480 | void SetMask( bool mask = true ); | |
481 | bool HasMask(); | |
482 | ||
483 | wxImage Rotate(double angle, const wxPoint & centre_of_rotation, | |
484 | bool interpolating = true, wxPoint * offset_after_rotation = NULL) const ; | |
485 | wxImage Rotate90( bool clockwise = true ) ; | |
486 | wxImage Mirror( bool horizontally = true ) ; | |
487 | ||
488 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
489 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
490 | ||
491 | // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black) | |
492 | wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const; | |
493 | ||
494 | void SetOption(const wxString& name, const wxString& value); | |
495 | %Rename(SetOptionInt, void, SetOption(const wxString& name, int value)); | |
496 | wxString GetOption(const wxString& name) const; | |
497 | int GetOptionInt(const wxString& name) const; | |
498 | bool HasOption(const wxString& name) const; | |
499 | ||
500 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ); | |
501 | unsigned long ComputeHistogram( wxImageHistogram& h ); | |
502 | ||
503 | static void AddHandler( wxImageHandler *handler ); | |
504 | static void InsertHandler( wxImageHandler *handler ); | |
505 | static bool RemoveHandler( const wxString& name ); | |
506 | static wxString GetImageExtWildcard(); | |
507 | ||
508 | ||
509 | MustHaveApp(ConvertToBitmap); | |
510 | MustHaveApp(ConvertToMonoBitmap); | |
511 | ||
512 | %extend { | |
513 | wxBitmap ConvertToBitmap(int depth=-1) { | |
514 | wxBitmap bitmap(*self, depth); | |
515 | return bitmap; | |
516 | } | |
517 | ||
518 | wxBitmap ConvertToMonoBitmap( unsigned char red, | |
519 | unsigned char green, | |
520 | unsigned char blue ) { | |
521 | wxImage mono = self->ConvertToMono( red, green, blue ); | |
522 | wxBitmap bitmap( mono, 1 ); | |
523 | return bitmap; | |
524 | } | |
525 | } | |
526 | ||
527 | %pythoncode { def __nonzero__(self): return self.Ok() } | |
528 | }; | |
529 | ||
530 | ||
531 | ||
532 | ///void wxInitAllImageHandlers(); | |
533 | ||
534 | %pythoncode { | |
535 | def InitAllImageHandlers(): | |
536 | """ | |
537 | The former functionality of InitAllImageHanders is now done internal to | |
538 | the _core_ extension module and so this function has become a simple NOP. | |
539 | """ | |
540 | pass | |
541 | } | |
542 | ||
543 | ||
544 | ||
545 | // See also wxPy_ReinitStockObjects in helpers.cpp | |
546 | %immutable; | |
547 | const wxImage wxNullImage; | |
548 | %mutable; | |
549 | ||
550 | //--------------------------------------------------------------------------- | |
551 | ||
552 | MAKE_CONST_WXSTRING(IMAGE_OPTION_FILENAME); | |
553 | MAKE_CONST_WXSTRING(IMAGE_OPTION_BMP_FORMAT); | |
554 | MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_X); | |
555 | MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_Y); | |
556 | MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTION); | |
557 | MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONX); | |
558 | MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONY); | |
559 | MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONUNIT); | |
560 | MAKE_CONST_WXSTRING(IMAGE_OPTION_QUALITY); | |
561 | ||
562 | enum | |
563 | { | |
564 | wxIMAGE_RESOLUTION_INCHES = 1, | |
565 | wxIMAGE_RESOLUTION_CM = 2 | |
566 | }; | |
567 | ||
568 | ||
569 | MAKE_CONST_WXSTRING(IMAGE_OPTION_BITSPERSAMPLE); | |
570 | MAKE_CONST_WXSTRING(IMAGE_OPTION_SAMPLESPERPIXEL); | |
571 | MAKE_CONST_WXSTRING(IMAGE_OPTION_COMPRESSION); | |
572 | MAKE_CONST_WXSTRING(IMAGE_OPTION_IMAGEDESCRIPTOR); | |
573 | ||
574 | MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_FORMAT); | |
575 | MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_BITDEPTH); | |
576 | ||
577 | enum | |
578 | { | |
579 | wxPNG_TYPE_COLOUR = 0, | |
580 | wxPNG_TYPE_GREY = 2, | |
581 | wxPNG_TYPE_GREY_RED = 3 | |
582 | }; | |
583 | ||
584 | enum | |
585 | { | |
586 | wxBMP_24BPP = 24, // default, do not need to set | |
587 | //wxBMP_16BPP = 16, // wxQuantize can only do 236 colors? | |
588 | wxBMP_8BPP = 8, // 8bpp, quantized colors | |
589 | wxBMP_8BPP_GREY = 9, // 8bpp, rgb averaged to greys | |
590 | wxBMP_8BPP_GRAY = wxBMP_8BPP_GREY, | |
591 | wxBMP_8BPP_RED = 10, // 8bpp, red used as greyscale | |
592 | wxBMP_8BPP_PALETTE = 11, // 8bpp, use the wxImage's palette | |
593 | wxBMP_4BPP = 4, // 4bpp, quantized colors | |
594 | wxBMP_1BPP = 1, // 1bpp, quantized "colors" | |
595 | wxBMP_1BPP_BW = 2 // 1bpp, black & white from red | |
596 | }; | |
597 | ||
598 | ||
599 | class wxBMPHandler : public wxImageHandler { | |
600 | public: | |
601 | wxBMPHandler(); | |
602 | }; | |
603 | ||
604 | class wxICOHandler : public wxBMPHandler { | |
605 | public: | |
606 | wxICOHandler(); | |
607 | }; | |
608 | ||
609 | class wxCURHandler : public wxICOHandler { | |
610 | public: | |
611 | wxCURHandler(); | |
612 | }; | |
613 | ||
614 | class wxANIHandler : public wxCURHandler { | |
615 | public: | |
616 | wxANIHandler(); | |
617 | }; | |
618 | ||
619 | ||
620 | //--------------------------------------------------------------------------- | |
621 | ||
622 | class wxPNGHandler : public wxImageHandler { | |
623 | public: | |
624 | wxPNGHandler(); | |
625 | }; | |
626 | ||
627 | ||
628 | class wxGIFHandler : public wxImageHandler { | |
629 | public: | |
630 | wxGIFHandler(); | |
631 | }; | |
632 | ||
633 | ||
634 | class wxPCXHandler : public wxImageHandler { | |
635 | public: | |
636 | wxPCXHandler(); | |
637 | }; | |
638 | ||
639 | ||
640 | class wxJPEGHandler : public wxImageHandler { | |
641 | public: | |
642 | wxJPEGHandler(); | |
643 | }; | |
644 | ||
645 | ||
646 | class wxPNMHandler : public wxImageHandler { | |
647 | public: | |
648 | wxPNMHandler(); | |
649 | }; | |
650 | ||
651 | class wxXPMHandler : public wxImageHandler { | |
652 | public: | |
653 | wxXPMHandler(); | |
654 | }; | |
655 | ||
656 | class wxTIFFHandler : public wxImageHandler { | |
657 | public: | |
658 | wxTIFFHandler(); | |
659 | }; | |
660 | ||
661 | ||
662 | #if wxUSE_IFF | |
663 | class wxIFFHandler : public wxImageHandler { | |
664 | public: | |
665 | wxIFFHandler(); | |
666 | }; | |
667 | #endif | |
668 | ||
669 | //--------------------------------------------------------------------------- | |
670 | ||
671 | %{ | |
672 | #include <wx/quantize.h> | |
673 | %} | |
674 | ||
675 | enum { | |
676 | wxQUANTIZE_INCLUDE_WINDOWS_COLOURS, | |
677 | // wxQUANTIZE_RETURN_8BIT_DATA, | |
678 | wxQUANTIZE_FILL_DESTINATION_IMAGE | |
679 | }; | |
680 | ||
681 | ||
682 | DocStr(wxQuantize, | |
683 | "Performs quantization, or colour reduction, on a wxImage.", ""); | |
684 | ||
685 | class wxQuantize /*: public wxObject */ | |
686 | { | |
687 | public: | |
688 | ||
689 | %extend { | |
690 | DocStr( | |
691 | Quantize, | |
692 | "Reduce the colours in the source image and put the result into the | |
693 | destination image, setting the palette in the destination if | |
694 | needed. Both images may be the same, to overwrite the source image.", " | |
695 | :todo: Create a version that returns the wx.Palette used."); | |
696 | ||
697 | static bool Quantize(const wxImage& src, wxImage& dest, int desiredNoColours = 236, | |
698 | int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE) | |
699 | { | |
700 | return wxQuantize::Quantize(src, dest, | |
701 | //NULL, // palette | |
702 | desiredNoColours, | |
703 | NULL, // eightBitData | |
704 | flags); | |
705 | } | |
706 | } | |
707 | }; | |
708 | ||
709 | ||
710 | //--------------------------------------------------------------------------- |