]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/image.i
Removed deprecation warnings in OGL and Gizmos
[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
cf694132
RD
119 void Create( int width, int height );
120 void Destroy();
6c0168c9 121
cf694132 122 wxImage Scale( int width, int height );
f6bcfd97 123 wxImage& Rescale(int width, int height);
cf694132
RD
124
125 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
126 unsigned char GetRed( int x, int y );
127 unsigned char GetGreen( int x, int y );
128 unsigned char GetBlue( int x, int y );
129
68bc8549
RD
130 // find first colour that is not used in the image and has higher
131 // RGB values than <startR,startG,startB>
132 bool FindFirstUnusedColour( byte *OUTPUT, byte *OUTPUT, byte *OUTPUT,
133 byte startR = 0, byte startG = 0, byte startB = 0 ) const;
134
135 // Set image's mask to the area of 'mask' that has <mr,mg,mb> colour
136 bool SetMaskFromImage(const wxImage & mask,
137 byte mr, byte mg, byte mb);
138
db0ff83e
RD
139// void DoFloodFill (wxCoord x, wxCoord y,
140// const wxBrush & fillBrush,
141// const wxColour& testColour,
142// int style = wxFLOOD_SURFACE,
143// int LogicalFunction = wxCOPY /* currently unused */ ) ;
68bc8549 144
96bfd053 145 static bool CanRead( const wxString& name );
b5a5d647
RD
146 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
147
148 bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
149 %name(LoadMimeFile)bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 );
cf694132
RD
150
151 bool SaveFile( const wxString& name, int type );
152 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
153
f74ff5ef
RD
154 %name(CanReadStream) static bool CanRead( wxInputStream& stream );
155 %name(LoadStream) bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 );
156 %name(LoadMimeStream) bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 );
157
cf694132
RD
158 bool Ok();
159 int GetWidth();
160 int GetHeight();
161
9d8bd15f 162 wxImage GetSubImage(const wxRect& rect);
f6bcfd97
BP
163 wxImage Copy();
164 void Paste( const wxImage &image, int x, int y );
9d8bd15f 165
1dc2f865
RD
166 //unsigned char *GetData();
167 //void SetData( unsigned char *data );
168
169 %addmethods {
d55d6b3f
RD
170 PyObject* GetDataBuffer() {
171 unsigned char* data = self->GetData();
172 int len = self->GetWidth() * self->GetHeight() * 3;
173 return PyBuffer_FromReadWriteMemory(data, len);
174 }
175
1dc2f865
RD
176 PyObject* GetData() {
177 unsigned char* data = self->GetData();
178 int len = self->GetWidth() * self->GetHeight() * 3;
179 return PyString_FromStringAndSize((char*)data, len);
180 }
181
1e4a197e
RD
182 void SetDataBuffer(PyObject* data) {
183 unsigned char* buffer;
184 int size;
185
186 if (!PyArg_Parse(data, "w#", &buffer, &size))
187 return;
188
189 if (size != self->GetWidth() * self->GetHeight() * 3) {
190 PyErr_SetString(PyExc_TypeError, "Incorrect buffer size");
191 return;
192 }
193
194 self->SetData(buffer);
195 }
196
1dc2f865
RD
197 void SetData(PyObject* data) {
198 unsigned char* dataPtr;
199
200 if (! PyString_Check(data)) {
201 PyErr_SetString(PyExc_TypeError, "Expected string object");
202 return /* NULL */ ;
203 }
9d8bd15f
RD
204
205 size_t len = self->GetWidth() * self->GetHeight() * 3;
185d7c3e 206 dataPtr = (unsigned char*) malloc(len);
9d8bd15f 207 memcpy(dataPtr, PyString_AsString(data), len);
1dc2f865 208 self->SetData(dataPtr);
3b5ccda1 209 // wxImage takes ownership of dataPtr...
1dc2f865
RD
210 }
211 }
cf694132
RD
212
213 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
214 unsigned char GetMaskRed();
215 unsigned char GetMaskGreen();
216 unsigned char GetMaskBlue();
217 void SetMask( bool mask = TRUE );
218 bool HasMask();
219
f6bcfd97
BP
220 wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
221 bool interpolating = TRUE, wxPoint * offset_after_rotation = NULL) const ;
222 wxImage Rotate90( bool clockwise = TRUE ) ;
223 wxImage Mirror( bool horizontally = TRUE ) ;
224
225 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
226 unsigned char r2, unsigned char g2, unsigned char b2 );
227
6c0168c9
RD
228 // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black)
229 wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const;
230
231 void SetOption(const wxString& name, const wxString& value);
232 %name(SetOptionInt)void SetOption(const wxString& name, int value);
233 wxString GetOption(const wxString& name) const;
234 int GetOptionInt(const wxString& name) const;
235 bool HasOption(const wxString& name) const;
236
f6bcfd97
BP
237 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
238 // TODO: unsigned long ComputeHistogram( wxHashTable &h );
239
96bfd053
RD
240 static void AddHandler( wxImageHandler *handler );
241 static void InsertHandler( wxImageHandler *handler );
242 static bool RemoveHandler( const wxString& name );
b96c7a38
RD
243
244
245 %addmethods {
246 wxBitmap ConvertToBitmap() {
247 wxBitmap bitmap(*self);
248 return bitmap;
249 }
250
251 wxBitmap ConvertToMonoBitmap( unsigned char red,
252 unsigned char green,
253 unsigned char blue ) {
254 wxImage mono = self->ConvertToMono( red, green, blue );
255 wxBitmap bitmap( mono, 1 );
256 return bitmap;
257 }
258 }
cf694132
RD
259};
260
926bb76c 261
cf694132 262// Alternate constructors
0a651eb8 263%new wxImage* wxEmptyImage(int width=0, int height=0);
b5a5d647 264%new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1);
cf694132 265%new wxImage* wxImageFromBitmap(const wxBitmap &bitmap);
b5a5d647 266%new wxImage* wxImageFromData(int width, int height, unsigned char* data);
f74ff5ef
RD
267%new wxImage* wxImageFromStream(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1);
268%new wxImage* wxImageFromStreamMime(wxInputStream& stream, const wxString& mimetype, int index = -1 );
269
cf694132 270%{
0a651eb8
RD
271 wxImage* wxEmptyImage(int width=0, int height=0) {
272 if (width == 0 && height == 0)
273 return new wxImage;
274 else
275 return new wxImage(width, height);
cf694132
RD
276 }
277
f74ff5ef 278
b5a5d647
RD
279 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
280 return new wxImage(name, mimetype, index);
cf694132
RD
281 }
282
f74ff5ef 283
cf694132 284 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
b96c7a38 285 return new wxImage(bitmap.ConvertToImage());
cf694132 286 }
b5a5d647 287
f74ff5ef 288
b5a5d647
RD
289 wxImage* wxImageFromData(int width, int height, unsigned char* data) {
290 // Copy the source data so the wxImage can clean it up later
291 unsigned char* copy = (unsigned char*)malloc(width*height*3);
292 if (copy == NULL) {
293 PyErr_NoMemory();
294 return NULL;
295 }
296 memcpy(copy, data, width*height*3);
297 return new wxImage(width, height, copy, FALSE);
298 }
f74ff5ef
RD
299
300
301 wxImage* wxImageFromStream(wxInputStream& stream,
302 long type = wxBITMAP_TYPE_ANY, int index = -1) {
303 return new wxImage(stream, type, index);
304 }
305
306
307 wxImage* wxImageFromStreamMime(wxInputStream& stream,
308 const wxString& mimetype, int index = -1 ) {
309 return new wxImage(stream, mimetype, index);
310 }
cf694132
RD
311%}
312
f74ff5ef
RD
313
314
06c0fba4
RD
315void wxInitAllImageHandlers();
316
0a651eb8
RD
317
318%readonly
319%{
320#if 0
321%}
322
323extern wxImage wxNullImage;
324
325%readwrite
326%{
327#endif
328%}
329
330
331
cf694132 332//---------------------------------------------------------------------------
926bb76c
RD
333// This one is here to avoid circular imports
334
335%new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1);
336
337%{
338 wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) {
339 return new wxBitmap(img, depth);
340 }
341
342%}
343
344
cf694132 345//---------------------------------------------------------------------------