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