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