]>
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" |
952ae1e8 | 22 | #include "wx/hashmap.h" |
bf38cbff JS |
23 | |
24 | #if wxUSE_STREAMS | |
b9943f8e | 25 | # include "wx/stream.h" |
bf38cbff | 26 | #endif |
01111366 | 27 | |
775c6f0c VS |
28 | #if wxUSE_IMAGE |
29 | ||
01111366 RR |
30 | //----------------------------------------------------------------------------- |
31 | // classes | |
32 | //----------------------------------------------------------------------------- | |
33 | ||
34 | class WXDLLEXPORT wxImageHandler; | |
01111366 RR |
35 | class WXDLLEXPORT wxImage; |
36 | ||
37 | //----------------------------------------------------------------------------- | |
38 | // wxImageHandler | |
39 | //----------------------------------------------------------------------------- | |
40 | ||
41 | class WXDLLEXPORT wxImageHandler: public wxObject | |
42 | { | |
01111366 | 43 | public: |
be25e480 | 44 | wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; } |
01111366 | 45 | |
bf38cbff | 46 | #if wxUSE_STREAMS |
d394f479 | 47 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=-1 ); |
be25e480 | 48 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); |
8f177c8e | 49 | |
649d13e8 | 50 | virtual int GetImageCount( wxInputStream& stream ); |
0828c087 | 51 | |
be25e480 RR |
52 | bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); } |
53 | bool CanRead( const wxString& name ); | |
8f177c8e | 54 | #endif // wxUSE_STREAMS |
01111366 | 55 | |
be25e480 RR |
56 | void SetName(const wxString& name) { m_name = name; } |
57 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
58 | void SetType(long type) { m_type = type; } | |
59 | void SetMimeType(const wxString& type) { m_mime = type; } | |
60 | wxString GetName() const { return m_name; } | |
61 | wxString GetExtension() const { return m_extension; } | |
62 | long GetType() const { return m_type; } | |
63 | wxString GetMimeType() const { return m_mime; } | |
9e9ee68e | 64 | |
01111366 | 65 | protected: |
8f177c8e | 66 | #if wxUSE_STREAMS |
be25e480 | 67 | virtual bool DoCanRead( wxInputStream& stream ) = 0; |
8f177c8e | 68 | #endif // wxUSE_STREAMS |
995612e2 | 69 | |
be25e480 RR |
70 | wxString m_name; |
71 | wxString m_extension; | |
72 | wxString m_mime; | |
73 | long m_type; | |
aaf46fd6 | 74 | |
be25e480 RR |
75 | private: |
76 | DECLARE_CLASS(wxImageHandler) | |
8f177c8e VZ |
77 | }; |
78 | ||
01111366 | 79 | //----------------------------------------------------------------------------- |
952ae1e8 | 80 | // wxImageHistogram |
01111366 RR |
81 | //----------------------------------------------------------------------------- |
82 | ||
952ae1e8 | 83 | class WXDLLEXPORT wxImageHistogramEntry |
c9d01afd GRG |
84 | { |
85 | public: | |
952ae1e8 | 86 | wxImageHistogramEntry() : index(0), value(0) {} |
c9d01afd GRG |
87 | unsigned long index; |
88 | unsigned long value; | |
89 | }; | |
90 | ||
952ae1e8 VS |
91 | WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry, |
92 | wxIntegerHash, wxIntegerEqual, | |
93 | wxImageHistogram); | |
94 | ||
95 | //----------------------------------------------------------------------------- | |
96 | // wxImage | |
97 | //----------------------------------------------------------------------------- | |
98 | ||
01111366 RR |
99 | class WXDLLEXPORT wxImage: public wxObject |
100 | { | |
01111366 | 101 | public: |
be25e480 RR |
102 | wxImage(); |
103 | wxImage( int width, int height ); | |
f6bcfd97 | 104 | wxImage( int width, int height, unsigned char* data, bool static_data = FALSE ); |
60d43ad8 VS |
105 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); |
106 | wxImage( const wxString& name, const wxString& mimetype, int index = -1 ); | |
aaf46fd6 VZ |
107 | |
108 | #if wxUSE_STREAMS | |
60d43ad8 VS |
109 | wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 ); |
110 | wxImage( wxInputStream& stream, const wxString& mimetype, int index = -1 ); | |
aaf46fd6 | 111 | #endif // wxUSE_STREAMS |
01111366 | 112 | |
be25e480 RR |
113 | wxImage( const wxImage& image ); |
114 | wxImage( const wxImage* image ); | |
9e9ee68e | 115 | |
fd859211 VS |
116 | #if wxUSE_GUI |
117 | // convertion to/from wxBitmap (deprecated, use wxBitmap's methods instead): | |
be25e480 | 118 | wxImage( const wxBitmap &bitmap ); |
be25e480 | 119 | wxBitmap ConvertToBitmap() const; |
82ea63e6 | 120 | #ifdef __WXGTK__ |
f515c25a | 121 | wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const; |
fd859211 | 122 | #endif |
82ea63e6 | 123 | #endif |
23280650 | 124 | |
be25e480 | 125 | void Create( int width, int height ); |
f6bcfd97 | 126 | void Create( int width, int height, unsigned char* data, bool static_data = FALSE ); |
be25e480 | 127 | void Destroy(); |
01111366 | 128 | |
f6bcfd97 BP |
129 | // creates an identical copy of the image (the = operator |
130 | // just raises the ref count) | |
131 | wxImage Copy() const; | |
aaf46fd6 | 132 | |
be25e480 RR |
133 | // return the new image with size width*height |
134 | wxImage GetSubImage( const wxRect& ) const; | |
aaf46fd6 | 135 | |
f6bcfd97 BP |
136 | // pastes image into this instance and takes care of |
137 | // the mask colour and out of bounds problems | |
aaf46fd6 | 138 | void Paste( const wxImage &image, int x, int y ); |
23280650 | 139 | |
be25e480 RR |
140 | // return the new image with size width*height |
141 | wxImage Scale( int width, int height ) const; | |
7b2471a0 | 142 | |
be25e480 RR |
143 | // rescales the image in place |
144 | wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); } | |
ce9a75d2 | 145 | |
7a632f10 JS |
146 | // Rotates the image about the given point, 'angle' radians. |
147 | // Returns the rotated image, leaving this image intact. | |
148 | wxImage Rotate(double angle, const wxPoint & centre_of_rotation, | |
f6bcfd97 BP |
149 | bool interpolating = TRUE, wxPoint * offset_after_rotation = (wxPoint*) NULL) const; |
150 | ||
151 | wxImage Rotate90( bool clockwise = TRUE ) const; | |
152 | wxImage Mirror( bool horizontally = TRUE ) const; | |
7a632f10 | 153 | |
be25e480 RR |
154 | // replace one colour with another |
155 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
156 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
aaf46fd6 | 157 | |
fd859211 | 158 | // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black) |
f515c25a | 159 | wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const; |
ce9a75d2 | 160 | |
be25e480 RR |
161 | // these routines are slow but safe |
162 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
f6bcfd97 BP |
163 | unsigned char GetRed( int x, int y ) const; |
164 | unsigned char GetGreen( int x, int y ) const; | |
165 | unsigned char GetBlue( int x, int y ) const; | |
23280650 | 166 | |
1f5b2017 VS |
167 | // find first colour that is not used in the image and has higher |
168 | // RGB values than <startR,startG,startB> | |
169 | bool FindFirstUnusedColour( unsigned char *r, unsigned char *g, unsigned char *b, | |
aaf46fd6 | 170 | unsigned char startR = 1, unsigned char startG = 0, |
e0a76d8d | 171 | unsigned char startB = 0 ) const; |
1f5b2017 | 172 | // Set image's mask to the area of 'mask' that has <r,g,b> colour |
aaf46fd6 | 173 | bool SetMaskFromImage(const wxImage & mask, |
1f5b2017 | 174 | unsigned char mr, unsigned char mg, unsigned char mb); |
52b64b0a | 175 | |
be25e480 | 176 | static bool CanRead( const wxString& name ); |
649d13e8 | 177 | static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
60d43ad8 VS |
178 | virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); |
179 | virtual bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ); | |
bf38cbff JS |
180 | |
181 | #if wxUSE_STREAMS | |
be25e480 | 182 | static bool CanRead( wxInputStream& stream ); |
649d13e8 | 183 | static int GetImageCount( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); |
60d43ad8 VS |
184 | virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 ); |
185 | virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 ); | |
bf38cbff JS |
186 | #endif |
187 | ||
e0a76d8d VS |
188 | virtual bool SaveFile( const wxString& name, int type ) const; |
189 | virtual bool SaveFile( const wxString& name, const wxString& mimetype ) const; | |
bf38cbff JS |
190 | |
191 | #if wxUSE_STREAMS | |
e0a76d8d VS |
192 | virtual bool SaveFile( wxOutputStream& stream, int type ) const; |
193 | virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ) const; | |
bf38cbff | 194 | #endif |
01111366 | 195 | |
be25e480 RR |
196 | bool Ok() const; |
197 | int GetWidth() const; | |
198 | int GetHeight() const; | |
199 | ||
200 | char unsigned *GetData() const; | |
201 | void SetData( char unsigned *data ); | |
f6bcfd97 | 202 | void SetData( char unsigned *data, int new_width, int new_height ); |
5e5437e0 JS |
203 | |
204 | // Mask functions | |
be25e480 RR |
205 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); |
206 | unsigned char GetMaskRed() const; | |
207 | unsigned char GetMaskGreen() const; | |
208 | unsigned char GetMaskBlue() const; | |
209 | void SetMask( bool mask = TRUE ); | |
210 | bool HasMask() const; | |
211 | ||
d275c7eb | 212 | #if wxUSE_PALETTE |
5e5437e0 JS |
213 | // Palette functions |
214 | bool HasPalette() const; | |
215 | const wxPalette& GetPalette() const; | |
216 | void SetPalette(const wxPalette& palette); | |
d275c7eb | 217 | #endif // wxUSE_PALETTE |
5e5437e0 JS |
218 | |
219 | // Option functions (arbitrary name/value mapping) | |
220 | void SetOption(const wxString& name, const wxString& value); | |
221 | void SetOption(const wxString& name, int value); | |
222 | wxString GetOption(const wxString& name) const; | |
223 | int GetOptionInt(const wxString& name) const; | |
224 | bool HasOption(const wxString& name) const; | |
3f4fc796 | 225 | |
e0a76d8d | 226 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ) const; |
952ae1e8 VS |
227 | |
228 | // Computes the histogram of the image and fills a hash table, indexed | |
229 | // with integer keys built as 0xRRGGBB, containing wxImageHistogramEntry | |
230 | // objects. Each of them contains an 'index' (useful to build a palette | |
231 | // with the image colours) and a 'value', which is the number of pixels | |
232 | // in the image with that colour. | |
233 | // Returned value: # of entries in the histogram | |
e0a76d8d | 234 | unsigned long ComputeHistogram( wxImageHistogram &h ) const; |
be25e480 RR |
235 | |
236 | wxImage& operator = (const wxImage& image) | |
237 | { | |
238 | if ( (*this) != image ) | |
239 | Ref(image); | |
240 | return *this; | |
241 | } | |
242 | ||
243 | bool operator == (const wxImage& image) | |
244 | { return m_refData == image.m_refData; } | |
245 | bool operator != (const wxImage& image) | |
246 | { return m_refData != image.m_refData; } | |
247 | ||
248 | static wxList& GetHandlers() { return sm_handlers; } | |
249 | static void AddHandler( wxImageHandler *handler ); | |
250 | static void InsertHandler( wxImageHandler *handler ); | |
251 | static bool RemoveHandler( const wxString& name ); | |
252 | static wxImageHandler *FindHandler( const wxString& name ); | |
253 | static wxImageHandler *FindHandler( const wxString& extension, long imageType ); | |
254 | static wxImageHandler *FindHandler( long imageType ); | |
255 | static wxImageHandler *FindHandlerMime( const wxString& mimetype ); | |
256 | ||
257 | static void CleanUpHandlers(); | |
258 | static void InitStandardHandlers(); | |
c9d01afd | 259 | |
01111366 | 260 | protected: |
5e5437e0 | 261 | static wxList sm_handlers; |
01111366 | 262 | |
be25e480 RR |
263 | private: |
264 | friend class WXDLLEXPORT wxImageHandler; | |
23280650 | 265 | |
be25e480 | 266 | DECLARE_DYNAMIC_CLASS(wxImage) |
01111366 RR |
267 | }; |
268 | ||
8f493002 | 269 | |
a091d18c | 270 | extern void WXDLLEXPORT wxInitAllImageHandlers(); |
b5a4a47d | 271 | |
fd859211 | 272 | WXDLLEXPORT_DATA(extern wxImage) wxNullImage; |
8f493002 VS |
273 | |
274 | //----------------------------------------------------------------------------- | |
275 | // wxImage handlers | |
276 | //----------------------------------------------------------------------------- | |
277 | ||
278 | #include "wx/imagbmp.h" | |
279 | #include "wx/imagpng.h" | |
280 | #include "wx/imaggif.h" | |
281 | #include "wx/imagpcx.h" | |
282 | #include "wx/imagjpeg.h" | |
283 | #include "wx/imagtiff.h" | |
284 | #include "wx/imagpnm.h" | |
775c6f0c | 285 | #include "wx/imagxpm.h" |
4b6b4dfc | 286 | #include "wx/imagiff.h" |
775c6f0c VS |
287 | |
288 | #endif // wxUSE_IMAGE | |
8f493002 | 289 | |
01111366 RR |
290 | #endif |
291 | // _WX_IMAGE_H_ | |
9e9ee68e | 292 |