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.
31 //---------------------------------------------------------------------------
33 class wxImageHandler : public wxObject {
35 // wxImageHandler(); Abstract Base Class
37 wxString GetExtension();
39 wxString GetMimeType();
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 );
46 bool CanRead( const wxString& name );
48 void SetName(const wxString& name);
49 void SetExtension(const wxString& extension);
50 void SetType(long type);
51 void SetMimeType(const wxString& mimetype);
54 //---------------------------------------------------------------------------
56 class wxPNGHandler : public wxImageHandler {
62 class wxJPEGHandler : public wxImageHandler {
68 class wxBMPHandler : public wxImageHandler {
73 class wxICOHandler : public wxBMPHandler {
78 class wxCURHandler : public wxICOHandler {
83 class wxANIHandler : public wxCURHandler {
88 class wxGIFHandler : public wxImageHandler {
93 class wxPNMHandler : public wxImageHandler {
98 class wxPCXHandler : public wxImageHandler {
103 class wxTIFFHandler : public wxImageHandler {
110 //---------------------------------------------------------------------------
112 class wxImage : public wxObject {
114 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
117 wxBitmap ConvertToBitmap(); // deprecated
119 wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const;
121 void Create( int width, int height );
124 wxImage Scale( int width, int height );
125 wxImage& Rescale(int width, int height);
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 );
132 static bool CanRead( const wxString& name );
133 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
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 );
138 bool SaveFile( const wxString& name, int type );
139 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
145 wxImage GetSubImage(const wxRect& rect);
147 void Paste( const wxImage &image, int x, int y );
149 //unsigned char *GetData();
150 //void SetData( unsigned char *data );
153 PyObject* GetData() {
154 unsigned char* data = self->GetData();
155 int len = self->GetWidth() * self->GetHeight() * 3;
156 return PyString_FromStringAndSize((char*)data, len);
159 void SetData(PyObject* data) {
160 unsigned char* dataPtr;
162 if (! PyString_Check(data)) {
163 PyErr_SetString(PyExc_TypeError, "Expected string object");
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);
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 );
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 ) ;
186 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
187 unsigned char r2, unsigned char g2, unsigned char b2 );
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;
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;
198 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
199 // TODO: unsigned long ComputeHistogram( wxHashTable &h );
201 static void AddHandler( wxImageHandler *handler );
202 static void InsertHandler( wxImageHandler *handler );
203 static bool RemoveHandler( const wxString& name );
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);
213 wxImage* wxEmptyImage(int width=0, int height=0) {
214 if (width == 0 && height == 0)
217 return new wxImage(width, height);
220 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
221 return new wxImage(name, mimetype, index);
224 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
225 return new wxImage(bitmap);
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);
235 memcpy(copy, data, width*height*3);
236 return new wxImage(width, height, copy, FALSE);
240 void wxInitAllImageHandlers();
248 extern wxImage wxNullImage;
257 //---------------------------------------------------------------------------
258 // This one is here to avoid circular imports
260 %new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1);
263 wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) {
264 return new wxBitmap(img, depth);
270 //---------------------------------------------------------------------------