1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface file for wxImage, wxImageHandler, etc.
7 // Created: 28-Apr-1999
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
21 //----------------------------------------------------------------------
24 %include my_typemaps.i
26 // Import some definitions of other classes, etc.
32 //---------------------------------------------------------------------------
34 class wxImageHandler : public wxObject {
36 // wxImageHandler(); Abstract Base Class
38 wxString GetExtension();
40 wxString GetMimeType();
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 );
47 bool CanRead( const wxString& name );
49 void SetName(const wxString& name);
50 void SetExtension(const wxString& extension);
51 void SetType(long type);
52 void SetMimeType(const wxString& mimetype);
55 //---------------------------------------------------------------------------
57 class wxPNGHandler : public wxImageHandler {
63 class wxJPEGHandler : public wxImageHandler {
69 class wxBMPHandler : public wxImageHandler {
74 class wxICOHandler : public wxBMPHandler {
79 class wxCURHandler : public wxICOHandler {
84 class wxANIHandler : public wxCURHandler {
89 class wxGIFHandler : public wxImageHandler {
94 class wxPNMHandler : public wxImageHandler {
99 class wxPCXHandler : public wxImageHandler {
104 class wxTIFFHandler : public wxImageHandler {
111 //---------------------------------------------------------------------------
113 class wxImage : public wxObject {
115 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
118 wxBitmap ConvertToBitmap(); // deprecated
120 wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const;
122 void Create( int width, int height );
125 wxImage Scale( int width, int height );
126 wxImage& Rescale(int width, int height);
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 );
133 static bool CanRead( const wxString& name );
134 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
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 );
139 bool SaveFile( const wxString& name, int type );
140 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
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 );
150 wxImage GetSubImage(const wxRect& rect);
152 void Paste( const wxImage &image, int x, int y );
154 //unsigned char *GetData();
155 //void SetData( unsigned char *data );
158 PyObject* GetData() {
159 unsigned char* data = self->GetData();
160 int len = self->GetWidth() * self->GetHeight() * 3;
161 return PyString_FromStringAndSize((char*)data, len);
164 void SetData(PyObject* data) {
165 unsigned char* dataPtr;
167 if (! PyString_Check(data)) {
168 PyErr_SetString(PyExc_TypeError, "Expected string object");
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);
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 );
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 ) ;
191 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
192 unsigned char r2, unsigned char g2, unsigned char b2 );
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;
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;
203 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
204 // TODO: unsigned long ComputeHistogram( wxHashTable &h );
206 static void AddHandler( wxImageHandler *handler );
207 static void InsertHandler( wxImageHandler *handler );
208 static bool RemoveHandler( const wxString& name );
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 );
221 wxImage* wxEmptyImage(int width=0, int height=0) {
222 if (width == 0 && height == 0)
225 return new wxImage(width, height);
229 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
230 return new wxImage(name, mimetype, index);
234 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
235 return new wxImage(bitmap);
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);
246 memcpy(copy, data, width*height*3);
247 return new wxImage(width, height, copy, FALSE);
251 wxImage* wxImageFromStream(wxInputStream& stream,
252 long type = wxBITMAP_TYPE_ANY, int index = -1) {
253 return new wxImage(stream, type, index);
257 wxImage* wxImageFromStreamMime(wxInputStream& stream,
258 const wxString& mimetype, int index = -1 ) {
259 return new wxImage(stream, mimetype, index);
265 void wxInitAllImageHandlers();
273 extern wxImage wxNullImage;
282 //---------------------------------------------------------------------------
283 // This one is here to avoid circular imports
285 %new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1);
288 wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) {
289 return new wxBitmap(img, depth);
295 //---------------------------------------------------------------------------