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