]>
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 RR |
26 | |
27 | //----------------------------------------------------------------------------- | |
28 | // classes | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | class WXDLLEXPORT wxImageHandler; | |
01111366 RR |
32 | class WXDLLEXPORT wxImage; |
33 | ||
34 | //----------------------------------------------------------------------------- | |
35 | // wxImageHandler | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
38 | class WXDLLEXPORT wxImageHandler: public wxObject | |
39 | { | |
01111366 | 40 | public: |
be25e480 | 41 | wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; } |
01111366 | 42 | |
bf38cbff | 43 | #if wxUSE_STREAMS |
be25e480 RR |
44 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 ); |
45 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); | |
8f177c8e | 46 | |
be25e480 | 47 | virtual int GetImageCount( wxInputStream& stream ); |
0828c087 | 48 | |
be25e480 RR |
49 | bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); } |
50 | bool CanRead( const wxString& name ); | |
8f177c8e | 51 | #endif // wxUSE_STREAMS |
01111366 | 52 | |
be25e480 RR |
53 | void SetName(const wxString& name) { m_name = name; } |
54 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
55 | void SetType(long type) { m_type = type; } | |
56 | void SetMimeType(const wxString& type) { m_mime = type; } | |
57 | wxString GetName() const { return m_name; } | |
58 | wxString GetExtension() const { return m_extension; } | |
59 | long GetType() const { return m_type; } | |
60 | wxString GetMimeType() const { return m_mime; } | |
9e9ee68e | 61 | |
01111366 | 62 | protected: |
8f177c8e | 63 | #if wxUSE_STREAMS |
be25e480 | 64 | virtual bool DoCanRead( wxInputStream& stream ) = 0; |
8f177c8e | 65 | #endif // wxUSE_STREAMS |
995612e2 | 66 | |
be25e480 RR |
67 | wxString m_name; |
68 | wxString m_extension; | |
69 | wxString m_mime; | |
70 | long m_type; | |
71 | ||
72 | private: | |
73 | DECLARE_CLASS(wxImageHandler) | |
8f177c8e VZ |
74 | }; |
75 | ||
01111366 RR |
76 | //----------------------------------------------------------------------------- |
77 | // wxImage | |
78 | //----------------------------------------------------------------------------- | |
79 | ||
c9d01afd GRG |
80 | class WXDLLEXPORT wxHNode |
81 | { | |
82 | public: | |
83 | unsigned long index; | |
84 | unsigned long value; | |
85 | }; | |
86 | ||
01111366 RR |
87 | class WXDLLEXPORT wxImage: public wxObject |
88 | { | |
01111366 | 89 | public: |
be25e480 RR |
90 | wxImage(); |
91 | wxImage( int width, int height ); | |
92 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY ); | |
93 | wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); | |
94 | wxImage( const wxString& name, const wxString& mimetype ); | |
95 | wxImage( wxInputStream& stream, const wxString& mimetype ); | |
01111366 | 96 | |
be25e480 RR |
97 | wxImage( const wxImage& image ); |
98 | wxImage( const wxImage* image ); | |
9e9ee68e | 99 | |
be25e480 RR |
100 | // these functions get implemented in /src/(platform)/bitmap.cpp |
101 | wxImage( const wxBitmap &bitmap ); | |
102 | operator wxBitmap() const { return ConvertToBitmap(); } | |
103 | wxBitmap ConvertToBitmap() const; | |
82ea63e6 RR |
104 | #ifdef __WXGTK__ |
105 | wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ); | |
106 | #endif | |
23280650 | 107 | |
be25e480 RR |
108 | void Create( int width, int height ); |
109 | void Destroy(); | |
01111366 | 110 | |
be25e480 RR |
111 | // return the new image with size width*height |
112 | wxImage GetSubImage( const wxRect& ) const; | |
23280650 | 113 | |
be25e480 RR |
114 | // return the new image with size width*height |
115 | wxImage Scale( int width, int height ) const; | |
7b2471a0 | 116 | |
be25e480 RR |
117 | // rescales the image in place |
118 | wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); } | |
ce9a75d2 | 119 | |
be25e480 RR |
120 | // replace one colour with another |
121 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
122 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
ce9a75d2 | 123 | |
be25e480 RR |
124 | // these routines are slow but safe |
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 ); | |
23280650 | 129 | |
be25e480 RR |
130 | static bool CanRead( const wxString& name ); |
131 | virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY ); | |
132 | virtual bool LoadFile( const wxString& name, const wxString& mimetype ); | |
bf38cbff JS |
133 | |
134 | #if wxUSE_STREAMS | |
be25e480 RR |
135 | static bool CanRead( wxInputStream& stream ); |
136 | virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); | |
137 | virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype ); | |
bf38cbff JS |
138 | #endif |
139 | ||
be25e480 RR |
140 | virtual bool SaveFile( const wxString& name, int type ); |
141 | virtual bool SaveFile( const wxString& name, const wxString& mimetype ); | |
bf38cbff JS |
142 | |
143 | #if wxUSE_STREAMS | |
be25e480 RR |
144 | virtual bool SaveFile( wxOutputStream& stream, int type ); |
145 | virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ); | |
bf38cbff | 146 | #endif |
01111366 | 147 | |
be25e480 RR |
148 | bool Ok() const; |
149 | int GetWidth() const; | |
150 | int GetHeight() const; | |
151 | ||
152 | char unsigned *GetData() const; | |
153 | void SetData( char unsigned *data ); | |
154 | ||
155 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); | |
156 | unsigned char GetMaskRed() const; | |
157 | unsigned char GetMaskGreen() const; | |
158 | unsigned char GetMaskBlue() const; | |
159 | void SetMask( bool mask = TRUE ); | |
160 | bool HasMask() const; | |
161 | ||
162 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ); | |
163 | unsigned long ComputeHistogram( wxHashTable &h ); | |
164 | ||
165 | wxImage& operator = (const wxImage& image) | |
166 | { | |
167 | if ( (*this) != image ) | |
168 | Ref(image); | |
169 | return *this; | |
170 | } | |
171 | ||
172 | bool operator == (const wxImage& image) | |
173 | { return m_refData == image.m_refData; } | |
174 | bool operator != (const wxImage& image) | |
175 | { return m_refData != image.m_refData; } | |
176 | ||
177 | static wxList& GetHandlers() { return sm_handlers; } | |
178 | static void AddHandler( wxImageHandler *handler ); | |
179 | static void InsertHandler( wxImageHandler *handler ); | |
180 | static bool RemoveHandler( const wxString& name ); | |
181 | static wxImageHandler *FindHandler( const wxString& name ); | |
182 | static wxImageHandler *FindHandler( const wxString& extension, long imageType ); | |
183 | static wxImageHandler *FindHandler( long imageType ); | |
184 | static wxImageHandler *FindHandlerMime( const wxString& mimetype ); | |
185 | ||
186 | static void CleanUpHandlers(); | |
187 | static void InitStandardHandlers(); | |
c9d01afd | 188 | |
01111366 | 189 | protected: |
be25e480 | 190 | static wxList sm_handlers; |
01111366 | 191 | |
be25e480 RR |
192 | private: |
193 | friend class WXDLLEXPORT wxImageHandler; | |
23280650 | 194 | |
be25e480 | 195 | DECLARE_DYNAMIC_CLASS(wxImage) |
01111366 RR |
196 | }; |
197 | ||
8f493002 | 198 | |
a091d18c | 199 | extern void WXDLLEXPORT wxInitAllImageHandlers(); |
b5a4a47d | 200 | |
8f493002 VS |
201 | |
202 | //----------------------------------------------------------------------------- | |
203 | // wxImage handlers | |
204 | //----------------------------------------------------------------------------- | |
205 | ||
206 | #include "wx/imagbmp.h" | |
207 | #include "wx/imagpng.h" | |
208 | #include "wx/imaggif.h" | |
209 | #include "wx/imagpcx.h" | |
210 | #include "wx/imagjpeg.h" | |
211 | #include "wx/imagtiff.h" | |
212 | #include "wx/imagpnm.h" | |
213 | ||
01111366 RR |
214 | #endif |
215 | // _WX_IMAGE_H_ | |
9e9ee68e | 216 |