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