]>
Commit | Line | Data |
---|---|---|
cf694132 RD |
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 <wx/image.h> | |
19 | %} | |
20 | ||
21 | //---------------------------------------------------------------------- | |
22 | ||
23 | %include typemaps.i | |
24 | %include my_typemaps.i | |
25 | ||
26 | // Import some definitions of other classes, etc. | |
27 | %import _defs.i | |
28 | %import misc.i | |
29 | %import gdi.i | |
f74ff5ef | 30 | %import streams.i |
cf694132 RD |
31 | |
32 | //--------------------------------------------------------------------------- | |
33 | ||
9416aa89 | 34 | class wxImageHandler : public wxObject { |
cf694132 | 35 | public: |
1dec68aa | 36 | // wxImageHandler(); Abstract Base Class |
cf694132 RD |
37 | wxString GetName(); |
38 | wxString GetExtension(); | |
39 | long GetType(); | |
40 | wxString GetMimeType(); | |
41 | ||
42 | //bool LoadFile(wxImage* image, wxInputStream& stream); | |
43 | //bool SaveFile(wxImage* image, wxOutputStream& stream); | |
b5a5d647 RD |
44 | //virtual int GetImageCount( wxInputStream& stream ); |
45 | //bool CanRead( wxInputStream& stream ); | |
46 | ||
47 | bool CanRead( const wxString& name ); | |
cf694132 RD |
48 | |
49 | void SetName(const wxString& name); | |
50 | void SetExtension(const wxString& extension); | |
51 | void SetType(long type); | |
52 | void SetMimeType(const wxString& mimetype); | |
53 | }; | |
54 | ||
55 | //--------------------------------------------------------------------------- | |
56 | ||
57 | class wxPNGHandler : public wxImageHandler { | |
58 | public: | |
59 | wxPNGHandler(); | |
60 | }; | |
61 | ||
62 | ||
63 | class wxJPEGHandler : public wxImageHandler { | |
64 | public: | |
65 | wxJPEGHandler(); | |
66 | }; | |
67 | ||
68 | ||
69 | class wxBMPHandler : public wxImageHandler { | |
70 | public: | |
71 | wxBMPHandler(); | |
72 | }; | |
73 | ||
b5a5d647 RD |
74 | class wxICOHandler : public wxBMPHandler { |
75 | public: | |
76 | wxICOHandler(); | |
77 | }; | |
cf694132 | 78 | |
68320e40 RD |
79 | class wxCURHandler : public wxICOHandler { |
80 | public: | |
81 | wxCURHandler(); | |
82 | }; | |
83 | ||
84 | class wxANIHandler : public wxCURHandler { | |
85 | public: | |
86 | wxANIHandler(); | |
87 | }; | |
88 | ||
cf694132 RD |
89 | class wxGIFHandler : public wxImageHandler { |
90 | public: | |
91 | wxGIFHandler(); | |
92 | }; | |
93 | ||
06c0fba4 RD |
94 | class wxPNMHandler : public wxImageHandler { |
95 | public: | |
96 | wxPNMHandler(); | |
97 | }; | |
cf694132 | 98 | |
06c0fba4 RD |
99 | class wxPCXHandler : public wxImageHandler { |
100 | public: | |
101 | wxPCXHandler(); | |
102 | }; | |
cf694132 | 103 | |
9b3d3bc4 RD |
104 | class wxTIFFHandler : public wxImageHandler { |
105 | public: | |
106 | wxTIFFHandler(); | |
107 | }; | |
108 | ||
109 | ||
68320e40 | 110 | |
cf694132 RD |
111 | //--------------------------------------------------------------------------- |
112 | ||
9416aa89 | 113 | class wxImage : public wxObject { |
cf694132 | 114 | public: |
b5a5d647 | 115 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); |
cf694132 RD |
116 | ~wxImage(); |
117 | ||
b5a5d647 | 118 | wxBitmap ConvertToBitmap(); // deprecated |
926bb76c RD |
119 | #ifdef __WXGTK__ |
120 | wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const; | |
121 | #endif | |
cf694132 RD |
122 | void Create( int width, int height ); |
123 | void Destroy(); | |
6c0168c9 | 124 | |
cf694132 | 125 | wxImage Scale( int width, int height ); |
f6bcfd97 | 126 | wxImage& Rescale(int width, int height); |
cf694132 RD |
127 | |
128 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
129 | unsigned char GetRed( int x, int y ); | |
130 | unsigned char GetGreen( int x, int y ); | |
131 | unsigned char GetBlue( int x, int y ); | |
132 | ||
96bfd053 | 133 | static bool CanRead( const wxString& name ); |
b5a5d647 RD |
134 | static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
135 | ||
136 | bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); | |
137 | %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ); | |
cf694132 RD |
138 | |
139 | bool SaveFile( const wxString& name, int type ); | |
140 | %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype ); | |
141 | ||
f74ff5ef RD |
142 | %name(CanReadStream) static bool CanRead( wxInputStream& stream ); |
143 | %name(LoadStream) bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 ); | |
144 | %name(LoadMimeStream) bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 ); | |
145 | ||
cf694132 RD |
146 | bool Ok(); |
147 | int GetWidth(); | |
148 | int GetHeight(); | |
149 | ||
9d8bd15f | 150 | wxImage GetSubImage(const wxRect& rect); |
f6bcfd97 BP |
151 | wxImage Copy(); |
152 | void Paste( const wxImage &image, int x, int y ); | |
9d8bd15f | 153 | |
1dc2f865 RD |
154 | //unsigned char *GetData(); |
155 | //void SetData( unsigned char *data ); | |
156 | ||
157 | %addmethods { | |
158 | PyObject* GetData() { | |
159 | unsigned char* data = self->GetData(); | |
160 | int len = self->GetWidth() * self->GetHeight() * 3; | |
161 | return PyString_FromStringAndSize((char*)data, len); | |
162 | } | |
163 | ||
164 | void SetData(PyObject* data) { | |
165 | unsigned char* dataPtr; | |
166 | ||
167 | if (! PyString_Check(data)) { | |
168 | PyErr_SetString(PyExc_TypeError, "Expected string object"); | |
169 | return /* NULL */ ; | |
170 | } | |
9d8bd15f RD |
171 | |
172 | size_t len = self->GetWidth() * self->GetHeight() * 3; | |
185d7c3e | 173 | dataPtr = (unsigned char*) malloc(len); |
9d8bd15f | 174 | memcpy(dataPtr, PyString_AsString(data), len); |
1dc2f865 RD |
175 | self->SetData(dataPtr); |
176 | } | |
177 | } | |
cf694132 RD |
178 | |
179 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); | |
180 | unsigned char GetMaskRed(); | |
181 | unsigned char GetMaskGreen(); | |
182 | unsigned char GetMaskBlue(); | |
183 | void SetMask( bool mask = TRUE ); | |
184 | bool HasMask(); | |
185 | ||
f6bcfd97 BP |
186 | wxImage Rotate(double angle, const wxPoint & centre_of_rotation, |
187 | bool interpolating = TRUE, wxPoint * offset_after_rotation = NULL) const ; | |
188 | wxImage Rotate90( bool clockwise = TRUE ) ; | |
189 | wxImage Mirror( bool horizontally = TRUE ) ; | |
190 | ||
191 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
192 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
193 | ||
6c0168c9 RD |
194 | // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black) |
195 | wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const; | |
196 | ||
197 | void SetOption(const wxString& name, const wxString& value); | |
198 | %name(SetOptionInt)void SetOption(const wxString& name, int value); | |
199 | wxString GetOption(const wxString& name) const; | |
200 | int GetOptionInt(const wxString& name) const; | |
201 | bool HasOption(const wxString& name) const; | |
202 | ||
f6bcfd97 BP |
203 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ); |
204 | // TODO: unsigned long ComputeHistogram( wxHashTable &h ); | |
205 | ||
96bfd053 RD |
206 | static void AddHandler( wxImageHandler *handler ); |
207 | static void InsertHandler( wxImageHandler *handler ); | |
208 | static bool RemoveHandler( const wxString& name ); | |
cf694132 RD |
209 | }; |
210 | ||
926bb76c | 211 | |
cf694132 | 212 | // Alternate constructors |
0a651eb8 | 213 | %new wxImage* wxEmptyImage(int width=0, int height=0); |
b5a5d647 | 214 | %new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1); |
cf694132 | 215 | %new wxImage* wxImageFromBitmap(const wxBitmap &bitmap); |
b5a5d647 | 216 | %new wxImage* wxImageFromData(int width, int height, unsigned char* data); |
f74ff5ef RD |
217 | %new wxImage* wxImageFromStream(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1); |
218 | %new wxImage* wxImageFromStreamMime(wxInputStream& stream, const wxString& mimetype, int index = -1 ); | |
219 | ||
cf694132 | 220 | %{ |
0a651eb8 RD |
221 | wxImage* wxEmptyImage(int width=0, int height=0) { |
222 | if (width == 0 && height == 0) | |
223 | return new wxImage; | |
224 | else | |
225 | return new wxImage(width, height); | |
cf694132 RD |
226 | } |
227 | ||
f74ff5ef | 228 | |
b5a5d647 RD |
229 | wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) { |
230 | return new wxImage(name, mimetype, index); | |
cf694132 RD |
231 | } |
232 | ||
f74ff5ef | 233 | |
cf694132 RD |
234 | wxImage* wxImageFromBitmap(const wxBitmap &bitmap) { |
235 | return new wxImage(bitmap); | |
236 | } | |
b5a5d647 | 237 | |
f74ff5ef | 238 | |
b5a5d647 RD |
239 | wxImage* wxImageFromData(int width, int height, unsigned char* data) { |
240 | // Copy the source data so the wxImage can clean it up later | |
241 | unsigned char* copy = (unsigned char*)malloc(width*height*3); | |
242 | if (copy == NULL) { | |
243 | PyErr_NoMemory(); | |
244 | return NULL; | |
245 | } | |
246 | memcpy(copy, data, width*height*3); | |
247 | return new wxImage(width, height, copy, FALSE); | |
248 | } | |
f74ff5ef RD |
249 | |
250 | ||
251 | wxImage* wxImageFromStream(wxInputStream& stream, | |
252 | long type = wxBITMAP_TYPE_ANY, int index = -1) { | |
253 | return new wxImage(stream, type, index); | |
254 | } | |
255 | ||
256 | ||
257 | wxImage* wxImageFromStreamMime(wxInputStream& stream, | |
258 | const wxString& mimetype, int index = -1 ) { | |
259 | return new wxImage(stream, mimetype, index); | |
260 | } | |
cf694132 RD |
261 | %} |
262 | ||
f74ff5ef RD |
263 | |
264 | ||
06c0fba4 RD |
265 | void wxInitAllImageHandlers(); |
266 | ||
0a651eb8 RD |
267 | |
268 | %readonly | |
269 | %{ | |
270 | #if 0 | |
271 | %} | |
272 | ||
273 | extern wxImage wxNullImage; | |
274 | ||
275 | %readwrite | |
276 | %{ | |
277 | #endif | |
278 | %} | |
279 | ||
280 | ||
281 | ||
cf694132 | 282 | //--------------------------------------------------------------------------- |
926bb76c RD |
283 | // This one is here to avoid circular imports |
284 | ||
285 | %new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1); | |
286 | ||
287 | %{ | |
288 | wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) { | |
289 | return new wxBitmap(img, depth); | |
290 | } | |
291 | ||
292 | %} | |
293 | ||
294 | ||
cf694132 | 295 | //--------------------------------------------------------------------------- |