]>
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 | |
d07d2bc9 | 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)", | |
d07d2bc9 RD |
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.", ""); | |
9b3d3bc4 RD |
71 | }; |
72 | ||
73 | ||
cf694132 RD |
74 | //--------------------------------------------------------------------------- |
75 | ||
d14a1e28 | 76 | |
9416aa89 | 77 | class wxImage : public wxObject { |
cf694132 | 78 | public: |
1b8c7ba6 RD |
79 | DocCtorStr( |
80 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ), | |
81 | "", ""); | |
82 | ||
cf694132 RD |
83 | ~wxImage(); |
84 | ||
d14a1e28 | 85 | // Alternate constructors |
1b8c7ba6 RD |
86 | DocCtorStrName( |
87 | wxImage(const wxString& name, const wxString& mimetype, int index = -1), | |
88 | "", "", | |
89 | ImageFromMime); | |
90 | ||
91 | DocCtorStrName( | |
92 | wxImage(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1), | |
93 | "", "", | |
94 | ImageFromStream); | |
95 | ||
96 | DocCtorStrName( | |
97 | wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1 ), | |
98 | "", "", | |
99 | ImageFromStreamMime); | |
100 | ||
d14a1e28 | 101 | %extend { |
1b8c7ba6 RD |
102 | %rename(EmptyImage) wxImage(int width=0, int height=0, bool clear = true); |
103 | wxImage(int width=0, int height=0, bool clear = true) | |
104 | { | |
d14a1e28 RD |
105 | if (width > 0 && height > 0) |
106 | return new wxImage(width, height, clear); | |
107 | else | |
108 | return new wxImage; | |
be43ef04 | 109 | } |
ab1f7d2a RD |
110 | |
111 | MustHaveApp(wxImage(const wxBitmap &bitmap)); | |
1b8c7ba6 RD |
112 | %rename(ImageFromBitmap) wxImage(const wxBitmap &bitmap); |
113 | wxImage(const wxBitmap &bitmap) | |
114 | { | |
d14a1e28 RD |
115 | return new wxImage(bitmap.ConvertToImage()); |
116 | } | |
be43ef04 | 117 | |
1b8c7ba6 RD |
118 | %rename(ImageFromData) wxImage(int width, int height, unsigned char* data); |
119 | wxImage(int width, int height, unsigned char* data) | |
120 | { | |
d14a1e28 RD |
121 | // Copy the source data so the wxImage can clean it up later |
122 | unsigned char* copy = (unsigned char*)malloc(width*height*3); | |
123 | if (copy == NULL) { | |
124 | PyErr_NoMemory(); | |
125 | return NULL; | |
126 | } | |
127 | memcpy(copy, data, width*height*3); | |
a72f4631 | 128 | return new wxImage(width, height, copy, false); |
d14a1e28 | 129 | } |
1b8c7ba6 RD |
130 | |
131 | ||
132 | %rename(ImageFromDataWithAlpha) wxImage(int width, int height, unsigned char* data, unsigned char* alpha); | |
133 | wxImage(int width, int height, unsigned char* data, unsigned char* alpha) | |
134 | { | |
c6d42899 RD |
135 | // Copy the source data so the wxImage can clean it up later |
136 | unsigned char* dcopy = (unsigned char*)malloc(width*height*3); | |
137 | if (dcopy == NULL) { | |
138 | PyErr_NoMemory(); | |
139 | return NULL; | |
140 | } | |
141 | memcpy(dcopy, data, width*height*3); | |
142 | unsigned char* acopy = (unsigned char*)malloc(width*height); | |
143 | if (acopy == NULL) { | |
144 | PyErr_NoMemory(); | |
145 | return NULL; | |
146 | } | |
147 | memcpy(acopy, alpha, width*height); | |
148 | ||
149 | return new wxImage(width, height, dcopy, acopy, false); | |
150 | } | |
d14a1e28 | 151 | } |
be43ef04 | 152 | |
9df51bd0 RD |
153 | // TODO: wxImage( char** xpmData ); |
154 | ||
155 | ||
cf694132 RD |
156 | void Create( int width, int height ); |
157 | void Destroy(); | |
6c0168c9 | 158 | |
cf694132 | 159 | wxImage Scale( int width, int height ); |
9cbf6f6e | 160 | wxImage ShrinkBy( int xFactor , int yFactor ) const ; |
f6bcfd97 | 161 | wxImage& Rescale(int width, int height); |
cf694132 | 162 | |
f5bac082 RD |
163 | // resizes the image in place |
164 | wxImage& Resize( const wxSize& size, const wxPoint& pos, | |
165 | int r = -1, int g = -1, int b = -1 ); | |
166 | ||
cf694132 | 167 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); |
f5bac082 RD |
168 | |
169 | %Rename(SetRGBRect, | |
170 | void, SetRGB( const wxRect& rect, | |
171 | unsigned char r, unsigned char g, unsigned char b )); | |
172 | ||
cf694132 RD |
173 | unsigned char GetRed( int x, int y ); |
174 | unsigned char GetGreen( int x, int y ); | |
175 | unsigned char GetBlue( int x, int y ); | |
176 | ||
9cbf6f6e RD |
177 | void SetAlpha(int x, int y, unsigned char alpha); |
178 | unsigned char GetAlpha(int x, int y); | |
179 | bool HasAlpha(); | |
180 | ||
655e17cf RD |
181 | DocDeclStr( |
182 | void , InitAlpha(), | |
183 | "Initializes the image alpha channel data. It is an error to call it if | |
184 | the image already has alpha data. If it doesn't, alpha data will be by | |
185 | default initialized to all pixels being fully opaque. But if the image | |
186 | has a a mask colour, all mask pixels will be completely transparent.", ""); | |
187 | ||
188 | ||
9cbf6f6e | 189 | // find first colour that is not used in the image and has higher |
68bc8549 | 190 | // RGB values than <startR,startG,startB> |
dd9f7fea RD |
191 | DocDeclAStr( |
192 | bool, FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT, | |
193 | byte startR = 0, byte startG = 0, byte startB = 0 ) const, | |
194 | "FindFirstUnusedColour(int startR=1, int startG=0, int startB=0) -> (success, r, g, b)", | |
d07d2bc9 RD |
195 | "Find first colour that is not used in the image and has higher RGB |
196 | values than startR, startG, startB. Returns a tuple consisting of a | |
197 | success flag and rgb values.", ""); | |
dd9f7fea | 198 | |
125c972b RD |
199 | |
200 | DocDeclStr( | |
201 | bool , ConvertAlphaToMask(byte threshold = 128), | |
202 | "If the image has alpha channel, this method converts it to mask. All pixels | |
203 | with alpha value less than ``threshold`` are replaced with mask colour and the | |
204 | alpha channel is removed. Mask colour is chosen automatically using | |
205 | `FindFirstUnusedColour`. | |
206 | ||
207 | If the image image doesn't have alpha channel, ConvertAlphaToMask does | |
208 | nothing.", ""); | |
209 | ||
210 | ||
6f7ecb3b RD |
211 | DocDeclStr( |
212 | bool , ConvertColourToAlpha( unsigned char r, unsigned char g, unsigned char b ), | |
213 | "This method converts an image where the original alpha information is | |
214 | only available as a shades of a colour (actually shades of grey) | |
215 | typically when you draw anti-aliased text into a bitmap. The DC | |
216 | drawing routines draw grey values on the black background although | |
217 | they actually mean to draw white with differnt alpha values. This | |
218 | method reverses it, assuming a black (!) background and white text. | |
219 | The method will then fill up the whole image with the colour given.", ""); | |
220 | ||
221 | ||
125c972b | 222 | |
68bc8549 RD |
223 | // Set image's mask to the area of 'mask' that has <mr,mg,mb> colour |
224 | bool SetMaskFromImage(const wxImage & mask, | |
225 | byte mr, byte mg, byte mb); | |
226 | ||
db0ff83e RD |
227 | // void DoFloodFill (wxCoord x, wxCoord y, |
228 | // const wxBrush & fillBrush, | |
229 | // const wxColour& testColour, | |
230 | // int style = wxFLOOD_SURFACE, | |
231 | // int LogicalFunction = wxCOPY /* currently unused */ ) ; | |
68bc8549 | 232 | |
96bfd053 | 233 | static bool CanRead( const wxString& name ); |
b5a5d647 RD |
234 | static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
235 | ||
236 | bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); | |
1b8c7ba6 | 237 | %Rename(LoadMimeFile, bool, LoadFile( const wxString& name, const wxString& mimetype, int index = -1 )); |
cf694132 RD |
238 | |
239 | bool SaveFile( const wxString& name, int type ); | |
1b8c7ba6 | 240 | %Rename(SaveMimeFile, bool, SaveFile( const wxString& name, const wxString& mimetype )); |
cf694132 | 241 | |
1b8c7ba6 RD |
242 | %Rename(CanReadStream, static bool, CanRead( wxInputStream& stream )); |
243 | %Rename(LoadStream, bool, LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 )); | |
244 | %Rename(LoadMimeStream, bool, LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 )); | |
f74ff5ef | 245 | |
cf694132 RD |
246 | bool Ok(); |
247 | int GetWidth(); | |
248 | int GetHeight(); | |
249 | ||
ba938c3d RD |
250 | %extend { |
251 | wxSize GetSize() { | |
252 | wxSize size(self->GetWidth(), self->GetHeight()); | |
253 | return size; | |
254 | } | |
255 | } | |
256 | ||
9d8bd15f | 257 | wxImage GetSubImage(const wxRect& rect); |
f5bac082 RD |
258 | |
259 | // Paste the image or part of this image into an image of the given size at the pos | |
260 | // any newly exposed areas will be filled with the rgb colour | |
261 | // by default if r = g = b = -1 then fill with this image's mask colour or find and | |
262 | // set a suitable mask colour | |
263 | wxImage Size( const wxSize& size, const wxPoint& pos, | |
264 | int r = -1, int g = -1, int b = -1 ) const; | |
265 | ||
f6bcfd97 BP |
266 | wxImage Copy(); |
267 | void Paste( const wxImage &image, int x, int y ); | |
9d8bd15f | 268 | |
1dc2f865 RD |
269 | //unsigned char *GetData(); |
270 | //void SetData( unsigned char *data ); | |
271 | ||
d14a1e28 | 272 | %extend { |
9cbf6f6e | 273 | PyObject* GetData() { |
d55d6b3f RD |
274 | unsigned char* data = self->GetData(); |
275 | int len = self->GetWidth() * self->GetHeight() * 3; | |
d14a1e28 RD |
276 | PyObject* rv; |
277 | wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len)); | |
278 | return rv; | |
d55d6b3f | 279 | } |
9cbf6f6e RD |
280 | void SetData(PyObject* data) { |
281 | unsigned char* dataPtr; | |
d55d6b3f | 282 | |
9cbf6f6e | 283 | if (! PyString_Check(data)) { |
debff7aa RD |
284 | wxPyBLOCK_THREADS(PyErr_SetString(PyExc_TypeError, |
285 | "Expected string object")); | |
9cbf6f6e RD |
286 | return /* NULL */ ; |
287 | } | |
288 | ||
289 | size_t len = self->GetWidth() * self->GetHeight() * 3; | |
290 | dataPtr = (unsigned char*) malloc(len); | |
d14a1e28 | 291 | wxPyBLOCK_THREADS( memcpy(dataPtr, PyString_AsString(data), len) ); |
9cbf6f6e RD |
292 | self->SetData(dataPtr); |
293 | // wxImage takes ownership of dataPtr... | |
294 | } | |
295 | ||
296 | ||
297 | ||
298 | PyObject* GetDataBuffer() { | |
1dc2f865 RD |
299 | unsigned char* data = self->GetData(); |
300 | int len = self->GetWidth() * self->GetHeight() * 3; | |
d14a1e28 RD |
301 | PyObject* rv; |
302 | wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) ); | |
303 | return rv; | |
1dc2f865 | 304 | } |
1e4a197e RD |
305 | void SetDataBuffer(PyObject* data) { |
306 | unsigned char* buffer; | |
307 | int size; | |
308 | ||
da32eb53 | 309 | bool blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
310 | if (!PyArg_Parse(data, "t#", &buffer, &size)) |
311 | goto done; | |
1e4a197e RD |
312 | |
313 | if (size != self->GetWidth() * self->GetHeight() * 3) { | |
314 | PyErr_SetString(PyExc_TypeError, "Incorrect buffer size"); | |
d14a1e28 | 315 | goto done; |
1e4a197e | 316 | } |
1e4a197e | 317 | self->SetData(buffer); |
d14a1e28 | 318 | done: |
da32eb53 | 319 | wxPyEndBlockThreads(blocked); |
1e4a197e RD |
320 | } |
321 | ||
9cbf6f6e RD |
322 | |
323 | ||
324 | PyObject* GetAlphaData() { | |
325 | unsigned char* data = self->GetAlpha(); | |
326 | if (! data) { | |
327 | RETURN_NONE(); | |
328 | } else { | |
329 | int len = self->GetWidth() * self->GetHeight(); | |
d14a1e28 RD |
330 | PyObject* rv; |
331 | wxPyBLOCK_THREADS( rv = PyString_FromStringAndSize((char*)data, len) ); | |
332 | return rv; | |
9cbf6f6e RD |
333 | } |
334 | } | |
335 | void SetAlphaData(PyObject* data) { | |
1dc2f865 RD |
336 | unsigned char* dataPtr; |
337 | ||
338 | if (! PyString_Check(data)) { | |
339 | PyErr_SetString(PyExc_TypeError, "Expected string object"); | |
340 | return /* NULL */ ; | |
341 | } | |
9d8bd15f | 342 | |
9cbf6f6e | 343 | size_t len = self->GetWidth() * self->GetHeight(); |
185d7c3e | 344 | dataPtr = (unsigned char*) malloc(len); |
d14a1e28 | 345 | wxPyBLOCK_THREADS( memcpy(dataPtr, PyString_AsString(data), len) ); |
9cbf6f6e | 346 | self->SetAlpha(dataPtr); |
3b5ccda1 | 347 | // wxImage takes ownership of dataPtr... |
1dc2f865 | 348 | } |
9cbf6f6e RD |
349 | |
350 | ||
351 | ||
352 | PyObject* GetAlphaBuffer() { | |
353 | unsigned char* data = self->GetAlpha(); | |
354 | int len = self->GetWidth() * self->GetHeight(); | |
d14a1e28 RD |
355 | PyObject* rv; |
356 | wxPyBLOCK_THREADS( rv = PyBuffer_FromReadWriteMemory(data, len) ); | |
357 | return rv; | |
9cbf6f6e RD |
358 | } |
359 | void SetAlphaBuffer(PyObject* data) { | |
360 | unsigned char* buffer; | |
361 | int size; | |
362 | ||
da32eb53 | 363 | bool blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
364 | if (!PyArg_Parse(data, "t#", &buffer, &size)) |
365 | goto done; | |
9cbf6f6e RD |
366 | |
367 | if (size != self->GetWidth() * self->GetHeight()) { | |
368 | PyErr_SetString(PyExc_TypeError, "Incorrect buffer size"); | |
d14a1e28 | 369 | goto done; |
9cbf6f6e RD |
370 | } |
371 | self->SetAlpha(buffer); | |
d14a1e28 | 372 | done: |
da32eb53 | 373 | wxPyEndBlockThreads(blocked); |
9cbf6f6e | 374 | } |
1dc2f865 | 375 | } |
cf694132 RD |
376 | |
377 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); | |
f5bac082 RD |
378 | |
379 | DocDeclAStr( | |
380 | /*bool*/ void , GetOrFindMaskColour( unsigned char *OUTPUT, | |
381 | unsigned char *OUTPUT, | |
382 | unsigned char *OUTPUT ) const, | |
383 | "GetOrFindMaskColour() -> (r,g,b)", | |
384 | "Get the current mask colour or find a suitable colour.", ""); | |
385 | ||
386 | ||
cf694132 RD |
387 | unsigned char GetMaskRed(); |
388 | unsigned char GetMaskGreen(); | |
389 | unsigned char GetMaskBlue(); | |
a72f4631 | 390 | void SetMask( bool mask = true ); |
cf694132 RD |
391 | bool HasMask(); |
392 | ||
f6bcfd97 | 393 | wxImage Rotate(double angle, const wxPoint & centre_of_rotation, |
a72f4631 RD |
394 | bool interpolating = true, wxPoint * offset_after_rotation = NULL) const ; |
395 | wxImage Rotate90( bool clockwise = true ) ; | |
396 | wxImage Mirror( bool horizontally = true ) ; | |
f6bcfd97 BP |
397 | |
398 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
399 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
400 | ||
6c0168c9 RD |
401 | // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black) |
402 | wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const; | |
403 | ||
404 | void SetOption(const wxString& name, const wxString& value); | |
1b8c7ba6 | 405 | %Rename(SetOptionInt, void, SetOption(const wxString& name, int value)); |
6c0168c9 RD |
406 | wxString GetOption(const wxString& name) const; |
407 | int GetOptionInt(const wxString& name) const; | |
408 | bool HasOption(const wxString& name) const; | |
409 | ||
f6bcfd97 | 410 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ); |
9cbf6f6e | 411 | unsigned long ComputeHistogram( wxImageHistogram& h ); |
f6bcfd97 | 412 | |
96bfd053 RD |
413 | static void AddHandler( wxImageHandler *handler ); |
414 | static void InsertHandler( wxImageHandler *handler ); | |
415 | static bool RemoveHandler( const wxString& name ); | |
3ef86e32 | 416 | static wxString GetImageExtWildcard(); |
b96c7a38 RD |
417 | |
418 | ||
ab1f7d2a RD |
419 | MustHaveApp(ConvertToBitmap); |
420 | MustHaveApp(ConvertToMonoBitmap); | |
be43ef04 | 421 | |
d14a1e28 | 422 | %extend { |
12523ae4 RD |
423 | wxBitmap ConvertToBitmap(int depth=-1) { |
424 | wxBitmap bitmap(*self, depth); | |
b96c7a38 RD |
425 | return bitmap; |
426 | } | |
427 | ||
428 | wxBitmap ConvertToMonoBitmap( unsigned char red, | |
429 | unsigned char green, | |
430 | unsigned char blue ) { | |
431 | wxImage mono = self->ConvertToMono( red, green, blue ); | |
432 | wxBitmap bitmap( mono, 1 ); | |
433 | return bitmap; | |
434 | } | |
435 | } | |
1fded56b | 436 | |
d14a1e28 | 437 | %pythoncode { def __nonzero__(self): return self.Ok() } |
cf694132 RD |
438 | }; |
439 | ||
926bb76c | 440 | |
f74ff5ef | 441 | |
a3150741 RD |
442 | ///void wxInitAllImageHandlers(); |
443 | ||
444 | %pythoncode { | |
445 | def InitAllImageHandlers(): | |
446 | """ | |
447 | The former functionality of InitAllImageHanders is now done internal to | |
448 | the _core_ extension module and so this function has become a simple NOP. | |
449 | """ | |
450 | pass | |
451 | } | |
452 | ||
cf694132 | 453 | |
f74ff5ef | 454 | |
d14a1e28 RD |
455 | // See also wxPy_ReinitStockObjects in helpers.cpp |
456 | %immutable; | |
457 | const wxImage wxNullImage; | |
458 | %mutable; | |
cf694132 | 459 | |
d14a1e28 | 460 | //--------------------------------------------------------------------------- |
f74ff5ef | 461 | |
655e17cf | 462 | MAKE_CONST_WXSTRING(IMAGE_OPTION_FILENAME); |
d14a1e28 RD |
463 | MAKE_CONST_WXSTRING(IMAGE_OPTION_BMP_FORMAT); |
464 | MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_X); | |
465 | MAKE_CONST_WXSTRING(IMAGE_OPTION_CUR_HOTSPOT_Y); | |
466 | MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTION); | |
655e17cf RD |
467 | MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONX); |
468 | MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONY); | |
be43ef04 | 469 | MAKE_CONST_WXSTRING(IMAGE_OPTION_RESOLUTIONUNIT); |
97185340 | 470 | MAKE_CONST_WXSTRING(IMAGE_OPTION_QUALITY); |
f74ff5ef | 471 | |
d14a1e28 RD |
472 | enum |
473 | { | |
474 | wxIMAGE_RESOLUTION_INCHES = 1, | |
475 | wxIMAGE_RESOLUTION_CM = 2 | |
476 | }; | |
f74ff5ef RD |
477 | |
478 | ||
655e17cf RD |
479 | MAKE_CONST_WXSTRING(IMAGE_OPTION_BITSPERSAMPLE); |
480 | MAKE_CONST_WXSTRING(IMAGE_OPTION_SAMPLESPERPIXEL); | |
481 | MAKE_CONST_WXSTRING(IMAGE_OPTION_COMPRESSION); | |
482 | MAKE_CONST_WXSTRING(IMAGE_OPTION_IMAGEDESCRIPTOR); | |
483 | ||
9df51bd0 RD |
484 | MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_FORMAT); |
485 | MAKE_CONST_WXSTRING(IMAGE_OPTION_PNG_BITDEPTH); | |
486 | ||
487 | enum | |
488 | { | |
489 | wxPNG_TYPE_COLOUR = 0, | |
490 | wxPNG_TYPE_GREY = 2, | |
491 | wxPNG_TYPE_GREY_RED = 3 | |
492 | }; | |
493 | ||
d14a1e28 RD |
494 | enum |
495 | { | |
496 | wxBMP_24BPP = 24, // default, do not need to set | |
497 | //wxBMP_16BPP = 16, // wxQuantize can only do 236 colors? | |
498 | wxBMP_8BPP = 8, // 8bpp, quantized colors | |
499 | wxBMP_8BPP_GREY = 9, // 8bpp, rgb averaged to greys | |
500 | wxBMP_8BPP_GRAY = wxBMP_8BPP_GREY, | |
501 | wxBMP_8BPP_RED = 10, // 8bpp, red used as greyscale | |
502 | wxBMP_8BPP_PALETTE = 11, // 8bpp, use the wxImage's palette | |
503 | wxBMP_4BPP = 4, // 4bpp, quantized colors | |
504 | wxBMP_1BPP = 1, // 1bpp, quantized "colors" | |
505 | wxBMP_1BPP_BW = 2 // 1bpp, black & white from red | |
506 | }; | |
f74ff5ef RD |
507 | |
508 | ||
d14a1e28 RD |
509 | class wxBMPHandler : public wxImageHandler { |
510 | public: | |
511 | wxBMPHandler(); | |
512 | }; | |
cf694132 | 513 | |
d14a1e28 RD |
514 | class wxICOHandler : public wxBMPHandler { |
515 | public: | |
516 | wxICOHandler(); | |
517 | }; | |
f74ff5ef | 518 | |
d14a1e28 RD |
519 | class wxCURHandler : public wxICOHandler { |
520 | public: | |
521 | wxCURHandler(); | |
522 | }; | |
f74ff5ef | 523 | |
d14a1e28 RD |
524 | class wxANIHandler : public wxCURHandler { |
525 | public: | |
526 | wxANIHandler(); | |
527 | }; | |
06c0fba4 | 528 | |
0a651eb8 | 529 | |
d14a1e28 | 530 | //--------------------------------------------------------------------------- |
0a651eb8 | 531 | |
d14a1e28 RD |
532 | class wxPNGHandler : public wxImageHandler { |
533 | public: | |
534 | wxPNGHandler(); | |
535 | }; | |
0a651eb8 | 536 | |
0a651eb8 | 537 | |
d14a1e28 RD |
538 | class wxGIFHandler : public wxImageHandler { |
539 | public: | |
540 | wxGIFHandler(); | |
541 | }; | |
0a651eb8 RD |
542 | |
543 | ||
d14a1e28 RD |
544 | class wxPCXHandler : public wxImageHandler { |
545 | public: | |
546 | wxPCXHandler(); | |
547 | }; | |
926bb76c | 548 | |
926bb76c | 549 | |
d14a1e28 RD |
550 | class wxJPEGHandler : public wxImageHandler { |
551 | public: | |
552 | wxJPEGHandler(); | |
553 | }; | |
926bb76c | 554 | |
926bb76c | 555 | |
d14a1e28 RD |
556 | class wxPNMHandler : public wxImageHandler { |
557 | public: | |
558 | wxPNMHandler(); | |
559 | }; | |
560 | ||
561 | class wxXPMHandler : public wxImageHandler { | |
562 | public: | |
563 | wxXPMHandler(); | |
564 | }; | |
565 | ||
566 | class wxTIFFHandler : public wxImageHandler { | |
567 | public: | |
568 | wxTIFFHandler(); | |
569 | }; | |
570 | ||
571 | ||
572 | #if wxUSE_IFF | |
573 | class wxIFFHandler : public wxImageHandler { | |
574 | public: | |
575 | wxIFFHandler(); | |
576 | }; | |
577 | #endif | |
926bb76c | 578 | |
be43ef04 RD |
579 | //--------------------------------------------------------------------------- |
580 | ||
581 | %{ | |
582 | #include <wx/quantize.h> | |
583 | %} | |
584 | ||
585 | enum { | |
586 | wxQUANTIZE_INCLUDE_WINDOWS_COLOURS, | |
587 | // wxQUANTIZE_RETURN_8BIT_DATA, | |
588 | wxQUANTIZE_FILL_DESTINATION_IMAGE | |
589 | }; | |
590 | ||
591 | ||
592 | DocStr(wxQuantize, | |
593 | "Performs quantization, or colour reduction, on a wxImage.", ""); | |
594 | ||
595 | class wxQuantize /*: public wxObject */ | |
596 | { | |
597 | public: | |
598 | ||
599 | %extend { | |
600 | DocStr( | |
601 | Quantize, | |
602 | "Reduce the colours in the source image and put the result into the | |
39101468 | 603 | destination image, setting the palette in the destination if |
be43ef04 RD |
604 | needed. Both images may be the same, to overwrite the source image.", " |
605 | :todo: Create a version that returns the wx.Palette used."); | |
606 | ||
607 | static bool Quantize(const wxImage& src, wxImage& dest, int desiredNoColours = 236, | |
608 | int flags = wxQUANTIZE_INCLUDE_WINDOWS_COLOURS|wxQUANTIZE_FILL_DESTINATION_IMAGE) | |
609 | { | |
610 | return wxQuantize::Quantize(src, dest, | |
611 | //NULL, // palette | |
612 | desiredNoColours, | |
613 | NULL, // eightBitData | |
614 | flags); | |
615 | } | |
616 | } | |
617 | }; | |
618 | ||
619 | ||
cf694132 | 620 | //--------------------------------------------------------------------------- |