]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/image.i
Changes for wxOGL since wxFatalError has been deprecated.
[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"
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
9416aa89 33class wxImageHandler : public wxObject {
cf694132 34public:
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);
b5a5d647
RD
43 //virtual int GetImageCount( wxInputStream& stream );
44 //bool CanRead( wxInputStream& stream );
45
46 bool CanRead( const wxString& name );
cf694132
RD
47
48 void SetName(const wxString& name);
49 void SetExtension(const wxString& extension);
50 void SetType(long type);
51 void SetMimeType(const wxString& mimetype);
52};
53
54//---------------------------------------------------------------------------
55
56class wxPNGHandler : public wxImageHandler {
57public:
58 wxPNGHandler();
59};
60
61
62class wxJPEGHandler : public wxImageHandler {
63public:
64 wxJPEGHandler();
65};
66
67
68class wxBMPHandler : public wxImageHandler {
69public:
70 wxBMPHandler();
71};
72
b5a5d647
RD
73class wxICOHandler : public wxBMPHandler {
74public:
75 wxICOHandler();
76};
cf694132 77
68320e40
RD
78class wxCURHandler : public wxICOHandler {
79public:
80 wxCURHandler();
81};
82
83class wxANIHandler : public wxCURHandler {
84public:
85 wxANIHandler();
86};
87
cf694132
RD
88class wxGIFHandler : public wxImageHandler {
89public:
90 wxGIFHandler();
91};
92
06c0fba4
RD
93class wxPNMHandler : public wxImageHandler {
94public:
95 wxPNMHandler();
96};
cf694132 97
06c0fba4
RD
98class wxPCXHandler : public wxImageHandler {
99public:
100 wxPCXHandler();
101};
cf694132 102
9b3d3bc4
RD
103class wxTIFFHandler : public wxImageHandler {
104public:
105 wxTIFFHandler();
106};
107
108
68320e40 109
cf694132
RD
110//---------------------------------------------------------------------------
111
9416aa89 112class wxImage : public wxObject {
cf694132 113public:
b5a5d647 114 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
cf694132
RD
115 ~wxImage();
116
b5a5d647 117 wxBitmap ConvertToBitmap(); // deprecated
926bb76c
RD
118#ifdef __WXGTK__
119 wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const;
120#endif
cf694132
RD
121 void Create( int width, int height );
122 void Destroy();
6c0168c9 123
cf694132 124 wxImage Scale( int width, int height );
f6bcfd97 125 wxImage& Rescale(int width, int height);
cf694132
RD
126
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 );
131
96bfd053 132 static bool CanRead( const wxString& name );
b5a5d647
RD
133 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
134
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 );
cf694132
RD
137
138 bool SaveFile( const wxString& name, int type );
139 %name(SaveMimeFile)bool SaveFile( const wxString& name, const wxString& mimetype );
140
141 bool Ok();
142 int GetWidth();
143 int GetHeight();
144
9d8bd15f 145 wxImage GetSubImage(const wxRect& rect);
f6bcfd97
BP
146 wxImage Copy();
147 void Paste( const wxImage &image, int x, int y );
9d8bd15f 148
1dc2f865
RD
149 //unsigned char *GetData();
150 //void SetData( unsigned char *data );
151
152 %addmethods {
153 PyObject* GetData() {
154 unsigned char* data = self->GetData();
155 int len = self->GetWidth() * self->GetHeight() * 3;
156 return PyString_FromStringAndSize((char*)data, len);
157 }
158
159 void SetData(PyObject* data) {
160 unsigned char* dataPtr;
161
162 if (! PyString_Check(data)) {
163 PyErr_SetString(PyExc_TypeError, "Expected string object");
164 return /* NULL */ ;
165 }
9d8bd15f
RD
166
167 size_t len = self->GetWidth() * self->GetHeight() * 3;
185d7c3e 168 dataPtr = (unsigned char*) malloc(len);
9d8bd15f 169 memcpy(dataPtr, PyString_AsString(data), len);
1dc2f865
RD
170 self->SetData(dataPtr);
171 }
172 }
cf694132
RD
173
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 );
179 bool HasMask();
180
f6bcfd97
BP
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 ) ;
185
186 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
187 unsigned char r2, unsigned char g2, unsigned char b2 );
188
6c0168c9
RD
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;
191
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;
197
f6bcfd97
BP
198 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
199 // TODO: unsigned long ComputeHistogram( wxHashTable &h );
200
96bfd053
RD
201 static void AddHandler( wxImageHandler *handler );
202 static void InsertHandler( wxImageHandler *handler );
203 static bool RemoveHandler( const wxString& name );
cf694132
RD
204};
205
926bb76c 206
cf694132 207// Alternate constructors
0a651eb8 208%new wxImage* wxEmptyImage(int width=0, int height=0);
b5a5d647 209%new wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index = -1);
cf694132 210%new wxImage* wxImageFromBitmap(const wxBitmap &bitmap);
b5a5d647 211%new wxImage* wxImageFromData(int width, int height, unsigned char* data);
cf694132 212%{
0a651eb8
RD
213 wxImage* wxEmptyImage(int width=0, int height=0) {
214 if (width == 0 && height == 0)
215 return new wxImage;
216 else
217 return new wxImage(width, height);
cf694132
RD
218 }
219
b5a5d647
RD
220 wxImage* wxImageFromMime(const wxString& name, const wxString& mimetype, int index) {
221 return new wxImage(name, mimetype, index);
cf694132
RD
222 }
223
224 wxImage* wxImageFromBitmap(const wxBitmap &bitmap) {
225 return new wxImage(bitmap);
226 }
b5a5d647
RD
227
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);
231 if (copy == NULL) {
232 PyErr_NoMemory();
233 return NULL;
234 }
235 memcpy(copy, data, width*height*3);
236 return new wxImage(width, height, copy, FALSE);
237 }
cf694132
RD
238%}
239
06c0fba4
RD
240void wxInitAllImageHandlers();
241
0a651eb8
RD
242
243%readonly
244%{
245#if 0
246%}
247
248extern wxImage wxNullImage;
249
250%readwrite
251%{
252#endif
253%}
254
255
256
cf694132 257//---------------------------------------------------------------------------
926bb76c
RD
258// This one is here to avoid circular imports
259
260%new wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1);
261
262%{
263 wxBitmap* wxBitmapFromImage(const wxImage& img, int depth=-1) {
264 return new wxBitmap(img, depth);
265 }
266
267%}
268
269
cf694132 270//---------------------------------------------------------------------------