]>
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 | |
30 | ||
31 | //--------------------------------------------------------------------------- | |
32 | ||
33 | class wxImageHandler { | |
34 | public: | |
1dec68aa | 35 | // wxImageHandler(); Abstract Base Class |
cf694132 RD |
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 | ||
44 | void SetName(const wxString& name); | |
45 | void SetExtension(const wxString& extension); | |
46 | void SetType(long type); | |
47 | void SetMimeType(const wxString& mimetype); | |
48 | }; | |
49 | ||
50 | //--------------------------------------------------------------------------- | |
51 | ||
52 | class wxPNGHandler : public wxImageHandler { | |
53 | public: | |
54 | wxPNGHandler(); | |
55 | }; | |
56 | ||
57 | ||
58 | class wxJPEGHandler : public wxImageHandler { | |
59 | public: | |
60 | wxJPEGHandler(); | |
61 | }; | |
62 | ||
63 | ||
64 | class wxBMPHandler : public wxImageHandler { | |
65 | public: | |
66 | wxBMPHandler(); | |
67 | }; | |
68 | ||
69 | ||
70 | class wxGIFHandler : public wxImageHandler { | |
71 | public: | |
72 | wxGIFHandler(); | |
73 | }; | |
74 | ||
06c0fba4 RD |
75 | class wxPNMHandler : public wxImageHandler { |
76 | public: | |
77 | wxPNMHandler(); | |
78 | }; | |
cf694132 | 79 | |
06c0fba4 RD |
80 | class wxPCXHandler : public wxImageHandler { |
81 | public: | |
82 | wxPCXHandler(); | |
83 | }; | |
cf694132 | 84 | |
9b3d3bc4 RD |
85 | class wxTIFFHandler : public wxImageHandler { |
86 | public: | |
87 | wxTIFFHandler(); | |
88 | }; | |
89 | ||
90 | ||
cf694132 RD |
91 | //--------------------------------------------------------------------------- |
92 | ||
93 | class wxImage { | |
94 | public: | |
f6bcfd97 | 95 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
cf694132 RD |
96 | ~wxImage(); |
97 | ||
98 | wxBitmap ConvertToBitmap(); | |
926bb76c RD |
99 | #ifdef __WXGTK__ |
100 | wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const; | |
101 | #endif | |
cf694132 RD |
102 | void Create( int width, int height ); |
103 | void Destroy(); | |
104 | wxImage Scale( int width, int height ); | |
f6bcfd97 | 105 | wxImage& Rescale(int width, int height); |
cf694132 RD |
106 | |
107 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
108 | unsigned char GetRed( int x, int y ); | |
109 | unsigned char GetGreen( int x, int y ); | |
110 | unsigned char GetBlue( int x, int y ); | |
111 | ||
96bfd053 RD |
112 | static bool CanRead( const wxString& name ); |
113 | bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY ); | |
cf694132 RD |
114 | %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype ); |
115 | ||
116 | bool SaveFile( const wxString& name, int type ); | |
117 | %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype ); | |
118 | ||
119 | bool Ok(); | |
120 | int GetWidth(); | |
121 | int GetHeight(); | |
122 | ||
9d8bd15f | 123 | wxImage GetSubImage(const wxRect& rect); |
f6bcfd97 BP |
124 | wxImage Copy(); |
125 | void Paste( const wxImage &image, int x, int y ); | |
9d8bd15f | 126 | |
1dc2f865 RD |
127 | //unsigned char *GetData(); |
128 | //void SetData( unsigned char *data ); | |
129 | ||
130 | %addmethods { | |
131 | PyObject* GetData() { | |
132 | unsigned char* data = self->GetData(); | |
133 | int len = self->GetWidth() * self->GetHeight() * 3; | |
134 | return PyString_FromStringAndSize((char*)data, len); | |
135 | } | |
136 | ||
137 | void SetData(PyObject* data) { | |
138 | unsigned char* dataPtr; | |
139 | ||
140 | if (! PyString_Check(data)) { | |
141 | PyErr_SetString(PyExc_TypeError, "Expected string object"); | |
142 | return /* NULL */ ; | |
143 | } | |
9d8bd15f RD |
144 | |
145 | size_t len = self->GetWidth() * self->GetHeight() * 3; | |
185d7c3e | 146 | dataPtr = (unsigned char*) malloc(len); |
9d8bd15f | 147 | memcpy(dataPtr, PyString_AsString(data), len); |
1dc2f865 RD |
148 | self->SetData(dataPtr); |
149 | } | |
150 | } | |
cf694132 RD |
151 | |
152 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); | |
153 | unsigned char GetMaskRed(); | |
154 | unsigned char GetMaskGreen(); | |
155 | unsigned char GetMaskBlue(); | |
156 | void SetMask( bool mask = TRUE ); | |
157 | bool HasMask(); | |
158 | ||
f6bcfd97 BP |
159 | wxImage Rotate(double angle, const wxPoint & centre_of_rotation, |
160 | bool interpolating = TRUE, wxPoint * offset_after_rotation = NULL) const ; | |
161 | wxImage Rotate90( bool clockwise = TRUE ) ; | |
162 | wxImage Mirror( bool horizontally = TRUE ) ; | |
163 | ||
164 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
165 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
166 | ||
167 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ); | |
168 | // TODO: unsigned long ComputeHistogram( wxHashTable &h ); | |
169 | ||
96bfd053 RD |
170 | static void AddHandler( wxImageHandler *handler ); |
171 | static void InsertHandler( wxImageHandler *handler ); | |
172 | static bool RemoveHandler( const wxString& name ); | |
cf694132 RD |
173 | }; |
174 | ||
926bb76c | 175 | |
cf694132 | 176 | // Alternate constructors |
0a651eb8 | 177 | %new wxImage* wxEmptyImage(int width=0, int height=0); |
cf694132 RD |
178 | %new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype); |
179 | %new wxImage* wxImageFromBitmap(const wxBitmap &bitmap); | |
180 | %{ | |
0a651eb8 RD |
181 | wxImage* wxEmptyImage(int width=0, int height=0) { |
182 | if (width == 0 && height == 0) | |
183 | return new wxImage; | |
184 | else | |
185 | return new wxImage(width, height); | |
cf694132 RD |
186 | } |
187 | ||
188 | wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype) { | |
189 | return new wxImage(name, mimetype); | |
190 | } | |
191 | ||
192 | wxImage* wxImageFromBitmap(const wxBitmap &bitmap) { | |
193 | return new wxImage(bitmap); | |
194 | } | |
195 | %} | |
196 | ||
06c0fba4 RD |
197 | void wxInitAllImageHandlers(); |
198 | ||
0a651eb8 RD |
199 | |
200 | %readonly | |
201 | %{ | |
202 | #if 0 | |
203 | %} | |
204 | ||
205 | extern wxImage wxNullImage; | |
206 | ||
207 | %readwrite | |
208 | %{ | |
209 | #endif | |
210 | %} | |
211 | ||
212 | ||
213 | ||
cf694132 | 214 | //--------------------------------------------------------------------------- |
926bb76c RD |
215 | // This one is here to avoid circular imports |
216 | ||
217 | %new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1); | |
218 | ||
219 | %{ | |
220 | wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) { | |
221 | return new wxBitmap(img, depth); | |
222 | } | |
223 | ||
224 | %} | |
225 | ||
226 | ||
cf694132 | 227 | //--------------------------------------------------------------------------- |