]>
Commit | Line | Data |
---|---|---|
01111366 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: image.h | |
3 | // Purpose: wxImage class | |
4 | // Author: Robert Roebling | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) Robert Roebling | |
23280650 | 7 | // Licence: wxWindows licence |
01111366 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifndef _WX_IMAGE_H_ | |
11 | #define _WX_IMAGE_H_ | |
12 | ||
13 | #ifdef __GNUG__ | |
14 | #pragma interface "image.h" | |
15 | #endif | |
16 | ||
17 | #include "wx/setup.h" | |
18 | #include "wx/object.h" | |
19 | #include "wx/string.h" | |
20 | #include "wx/gdicmn.h" | |
23280650 | 21 | #include "wx/bitmap.h" |
bf38cbff JS |
22 | |
23 | #if wxUSE_STREAMS | |
b9943f8e | 24 | # include "wx/stream.h" |
bf38cbff | 25 | #endif |
01111366 | 26 | |
775c6f0c VS |
27 | #if wxUSE_IMAGE |
28 | ||
01111366 RR |
29 | //----------------------------------------------------------------------------- |
30 | // classes | |
31 | //----------------------------------------------------------------------------- | |
32 | ||
33 | class WXDLLEXPORT wxImageHandler; | |
01111366 RR |
34 | class WXDLLEXPORT wxImage; |
35 | ||
36 | //----------------------------------------------------------------------------- | |
37 | // wxImageHandler | |
38 | //----------------------------------------------------------------------------- | |
39 | ||
40 | class WXDLLEXPORT wxImageHandler: public wxObject | |
41 | { | |
01111366 | 42 | public: |
be25e480 | 43 | wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; } |
01111366 | 44 | |
bf38cbff | 45 | #if wxUSE_STREAMS |
be25e480 RR |
46 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); |
47 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
8f177c8e | 48 | |
be25e480 | 49 | virtual int GetImageCount( wxInputStream& stream ); |
0828c087 | 50 | |
be25e480 RR |
51 | bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); } |
52 | bool CanRead( const wxString& name ); | |
8f177c8e | 53 | #endif // wxUSE_STREAMS |
01111366 | 54 | |
be25e480 RR |
55 | void SetName(const wxString& name) { m_name = name; } |
56 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
57 | void SetType(long type) { m_type = type; } | |
58 | void SetMimeType(const wxString& type) { m_mime = type; } | |
59 | wxString GetName() const { return m_name; } | |
60 | wxString GetExtension() const { return m_extension; } | |
61 | long GetType() const { return m_type; } | |
62 | wxString GetMimeType() const { return m_mime; } | |
9e9ee68e | 63 | |
01111366 | 64 | protected: |
8f177c8e | 65 | #if wxUSE_STREAMS |
be25e480 | 66 | virtual bool DoCanRead( wxInputStream& stream ) = 0; |
8f177c8e | 67 | #endif // wxUSE_STREAMS |
995612e2 | 68 | |
be25e480 RR |
69 | wxString m_name; |
70 | wxString m_extension; | |
71 | wxString m_mime; | |
72 | long m_type; | |
73 | ||
74 | private: | |
75 | DECLARE_CLASS(wxImageHandler) | |
8f177c8e VZ |
76 | }; |
77 | ||
01111366 RR |
78 | //----------------------------------------------------------------------------- |
79 | // wxImage | |
80 | //----------------------------------------------------------------------------- | |
81 | ||
c9d01afd GRG |
82 | class WXDLLEXPORT wxHNode |
83 | { | |
84 | public: | |
85 | unsigned long index; | |
86 | unsigned long value; | |
87 | }; | |
88 | ||
01111366 RR |
89 | class WXDLLEXPORT wxImage: public wxObject |
90 | { | |
01111366 | 91 | public: |
be25e480 RR |
92 | wxImage(); |
93 | wxImage( int width, int height ); | |
f6bcfd97 | 94 | wxImage( int width, int height, unsigned char* data, bool static_data = FALSE ); |
be25e480 RR |
95 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
96 | wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); | |
97 | wxImage( const wxString& name, const wxString& mimetype ); | |
98 | wxImage( wxInputStream& stream, const wxString& mimetype ); | |
01111366 | 99 | |
be25e480 RR |
100 | wxImage( const wxImage& image ); |
101 | wxImage( const wxImage* image ); | |
9e9ee68e | 102 | |
fd859211 VS |
103 | #if wxUSE_GUI |
104 | // convertion to/from wxBitmap (deprecated, use wxBitmap's methods instead): | |
be25e480 RR |
105 | wxImage( const wxBitmap &bitmap ); |
106 | operator wxBitmap() const { return ConvertToBitmap(); } | |
107 | wxBitmap ConvertToBitmap() const; | |
82ea63e6 | 108 | #ifdef __WXGTK__ |
f515c25a | 109 | wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const; |
fd859211 | 110 | #endif |
82ea63e6 | 111 | #endif |
23280650 | 112 | |
be25e480 | 113 | void Create( int width, int height ); |
f6bcfd97 | 114 | void Create( int width, int height, unsigned char* data, bool static_data = FALSE ); |
be25e480 | 115 | void Destroy(); |
01111366 | 116 | |
f6bcfd97 BP |
117 | // creates an identical copy of the image (the = operator |
118 | // just raises the ref count) | |
119 | wxImage Copy() const; | |
120 | ||
be25e480 RR |
121 | // return the new image with size width*height |
122 | wxImage GetSubImage( const wxRect& ) const; | |
f6bcfd97 BP |
123 | |
124 | // pastes image into this instance and takes care of | |
125 | // the mask colour and out of bounds problems | |
126 | void Paste( const wxImage &image, int x, int y ); | |
23280650 | 127 | |
be25e480 RR |
128 | // return the new image with size width*height |
129 | wxImage Scale( int width, int height ) const; | |
7b2471a0 | 130 | |
be25e480 RR |
131 | // rescales the image in place |
132 | wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); } | |
ce9a75d2 | 133 | |
7a632f10 JS |
134 | // Rotates the image about the given point, 'angle' radians. |
135 | // Returns the rotated image, leaving this image intact. | |
136 | wxImage Rotate(double angle, const wxPoint & centre_of_rotation, | |
f6bcfd97 BP |
137 | bool interpolating = TRUE, wxPoint * offset_after_rotation = (wxPoint*) NULL) const; |
138 | ||
139 | wxImage Rotate90( bool clockwise = TRUE ) const; | |
140 | wxImage Mirror( bool horizontally = TRUE ) const; | |
7a632f10 | 141 | |
be25e480 RR |
142 | // replace one colour with another |
143 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
144 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
fd859211 VS |
145 | |
146 | // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black) | |
f515c25a | 147 | wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const; |
ce9a75d2 | 148 | |
be25e480 RR |
149 | // these routines are slow but safe |
150 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
f6bcfd97 BP |
151 | unsigned char GetRed( int x, int y ) const; |
152 | unsigned char GetGreen( int x, int y ) const; | |
153 | unsigned char GetBlue( int x, int y ) const; | |
23280650 | 154 | |
be25e480 RR |
155 | static bool CanRead( const wxString& name ); |
156 | virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY ); | |
157 | virtual bool LoadFile( const wxString& name, const wxString& mimetype ); | |
bf38cbff JS |
158 | |
159 | #if wxUSE_STREAMS | |
be25e480 RR |
160 | static bool CanRead( wxInputStream& stream ); |
161 | virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); | |
162 | virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype ); | |
bf38cbff JS |
163 | #endif |
164 | ||
be25e480 RR |
165 | virtual bool SaveFile( const wxString& name, int type ); |
166 | virtual bool SaveFile( const wxString& name, const wxString& mimetype ); | |
bf38cbff JS |
167 | |
168 | #if wxUSE_STREAMS | |
be25e480 RR |
169 | virtual bool SaveFile( wxOutputStream& stream, int type ); |
170 | virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ); | |
bf38cbff | 171 | #endif |
01111366 | 172 | |
be25e480 RR |
173 | bool Ok() const; |
174 | int GetWidth() const; | |
175 | int GetHeight() const; | |
176 | ||
177 | char unsigned *GetData() const; | |
178 | void SetData( char unsigned *data ); | |
f6bcfd97 | 179 | void SetData( char unsigned *data, int new_width, int new_height ); |
5e5437e0 JS |
180 | |
181 | // Mask functions | |
be25e480 RR |
182 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); |
183 | unsigned char GetMaskRed() const; | |
184 | unsigned char GetMaskGreen() const; | |
185 | unsigned char GetMaskBlue() const; | |
186 | void SetMask( bool mask = TRUE ); | |
187 | bool HasMask() const; | |
188 | ||
5e5437e0 JS |
189 | // Palette functions |
190 | bool HasPalette() const; | |
191 | const wxPalette& GetPalette() const; | |
192 | void SetPalette(const wxPalette& palette); | |
193 | ||
194 | // Option functions (arbitrary name/value mapping) | |
195 | void SetOption(const wxString& name, const wxString& value); | |
196 | void SetOption(const wxString& name, int value); | |
197 | wxString GetOption(const wxString& name) const; | |
198 | int GetOptionInt(const wxString& name) const; | |
199 | bool HasOption(const wxString& name) const; | |
3f4fc796 | 200 | |
be25e480 RR |
201 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ); |
202 | unsigned long ComputeHistogram( wxHashTable &h ); | |
203 | ||
204 | wxImage& operator = (const wxImage& image) | |
205 | { | |
206 | if ( (*this) != image ) | |
207 | Ref(image); | |
208 | return *this; | |
209 | } | |
210 | ||
211 | bool operator == (const wxImage& image) | |
212 | { return m_refData == image.m_refData; } | |
213 | bool operator != (const wxImage& image) | |
214 | { return m_refData != image.m_refData; } | |
215 | ||
216 | static wxList& GetHandlers() { return sm_handlers; } | |
217 | static void AddHandler( wxImageHandler *handler ); | |
218 | static void InsertHandler( wxImageHandler *handler ); | |
219 | static bool RemoveHandler( const wxString& name ); | |
220 | static wxImageHandler *FindHandler( const wxString& name ); | |
221 | static wxImageHandler *FindHandler( const wxString& extension, long imageType ); | |
222 | static wxImageHandler *FindHandler( long imageType ); | |
223 | static wxImageHandler *FindHandlerMime( const wxString& mimetype ); | |
224 | ||
225 | static void CleanUpHandlers(); | |
226 | static void InitStandardHandlers(); | |
c9d01afd | 227 | |
01111366 | 228 | protected: |
5e5437e0 | 229 | static wxList sm_handlers; |
01111366 | 230 | |
be25e480 RR |
231 | private: |
232 | friend class WXDLLEXPORT wxImageHandler; | |
23280650 | 233 | |
be25e480 | 234 | DECLARE_DYNAMIC_CLASS(wxImage) |
01111366 RR |
235 | }; |
236 | ||
8f493002 | 237 | |
a091d18c | 238 | extern void WXDLLEXPORT wxInitAllImageHandlers(); |
b5a4a47d | 239 | |
fd859211 | 240 | WXDLLEXPORT_DATA(extern wxImage) wxNullImage; |
8f493002 VS |
241 | |
242 | //----------------------------------------------------------------------------- | |
243 | // wxImage handlers | |
244 | //----------------------------------------------------------------------------- | |
245 | ||
246 | #include "wx/imagbmp.h" | |
247 | #include "wx/imagpng.h" | |
248 | #include "wx/imaggif.h" | |
249 | #include "wx/imagpcx.h" | |
250 | #include "wx/imagjpeg.h" | |
251 | #include "wx/imagtiff.h" | |
252 | #include "wx/imagpnm.h" | |
775c6f0c VS |
253 | #include "wx/imagxpm.h" |
254 | ||
255 | #endif // wxUSE_IMAGE | |
8f493002 | 256 | |
01111366 RR |
257 | #endif |
258 | // _WX_IMAGE_H_ | |
9e9ee68e | 259 |