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