]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/image.i
undef LoadMenu() (patch #521743)
[wxWidgets.git] / wxPython / src / image.i
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
30 %import streams.i
31
32 //---------------------------------------------------------------------------
33
34 class wxImageHandler : public wxObject {
35 public:
36 // wxImageHandler(); Abstract Base Class
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);
44 //virtual int GetImageCount( wxInputStream& stream );
45 //bool CanRead( wxInputStream& stream );
46
47 bool CanRead( const wxString& name );
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
74 class wxICOHandler : public wxBMPHandler {
75 public:
76 wxICOHandler();
77 };
78
79 class wxCURHandler : public wxICOHandler {
80 public:
81 wxCURHandler();
82 };
83
84 class wxANIHandler : public wxCURHandler {
85 public:
86 wxANIHandler();
87 };
88
89 class wxGIFHandler : public wxImageHandler {
90 public:
91 wxGIFHandler();
92 };
93
94 class wxPNMHandler : public wxImageHandler {
95 public:
96 wxPNMHandler();
97 };
98
99 class wxPCXHandler : public wxImageHandler {
100 public:
101 wxPCXHandler();
102 };
103
104 class wxTIFFHandler : public wxImageHandler {
105 public:
106 wxTIFFHandler();
107 };
108
109
110
111 //---------------------------------------------------------------------------
112
113 class wxImage : public wxObject {
114 public:
115 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
116 ~wxImage();
117
118 wxBitmap ConvertToBitmap(); // deprecated
119 #ifdef __WXGTK__
120 wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const;
121 #endif
122 void Create( int width, int height );
123 void Destroy();
124
125 wxImage Scale( int width, int height );
126 wxImage& Rescale(int width, int height);
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
133 static bool CanRead( const wxString& name );
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 );
138
139 bool SaveFile( const wxString& name, int type );
140 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
141
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
146 bool Ok();
147 int GetWidth();
148 int GetHeight();
149
150 wxImage GetSubImage(const wxRect& rect);
151 wxImage Copy();
152 void Paste( const wxImage &image, int x, int y );
153
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 }
171
172 size_t len = self->GetWidth() * self->GetHeight() * 3;
173 dataPtr = (unsigned char*) malloc(len);
174 memcpy(dataPtr, PyString_AsString(data), len);
175 self->SetData(dataPtr);
176 }
177 }
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
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
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
203 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
204 // TODO: unsigned long ComputeHistogram( wxHashTable &h );
205
206 static void AddHandler( wxImageHandler *handler );
207 static void InsertHandler( wxImageHandler *handler );
208 static bool RemoveHandler( const wxString& name );
209 };
210
211
212 // Alternate constructors
213 %new wxImage* wxEmptyImage(int width=0, int height=0);
214 %new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1);
215 %new wxImage* wxImageFromBitmap(const wxBitmap &bitmap);
216 %new wxImage* wxImageFromData(int width, int height, unsigned char* data);
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
220 %{
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);
226 }
227
228
229 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
230 return new wxImage(name, mimetype, index);
231 }
232
233
234 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
235 return new wxImage(bitmap);
236 }
237
238
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 }
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 }
261 %}
262
263
264
265 void wxInitAllImageHandlers();
266
267
268 %readonly
269 %{
270 #if 0
271 %}
272
273 extern wxImage wxNullImage;
274
275 %readwrite
276 %{
277 #endif
278 %}
279
280
281
282 //---------------------------------------------------------------------------
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
295 //---------------------------------------------------------------------------