]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
Added a mask to some of the images
[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
23 #if wxUSE_STREAMS
24 # include "wx/stream.h"
25 #endif
26
27 //-----------------------------------------------------------------------------
28 // classes
29 //-----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxImageHandler;
32 class WXDLLEXPORT wxImage;
33
34 //-----------------------------------------------------------------------------
35 // wxImageHandler
36 //-----------------------------------------------------------------------------
37
38 class WXDLLEXPORT wxImageHandler: public wxObject
39 {
40 public:
41 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
42
43 #if wxUSE_STREAMS
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 );
46
47 virtual int GetImageCount( wxInputStream& stream );
48
49 bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); }
50 bool CanRead( const wxString& name );
51 #endif // wxUSE_STREAMS
52
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; }
61
62 protected:
63 #if wxUSE_STREAMS
64 virtual bool DoCanRead( wxInputStream& stream ) = 0;
65 #endif // wxUSE_STREAMS
66
67 wxString m_name;
68 wxString m_extension;
69 wxString m_mime;
70 long m_type;
71
72 private:
73 DECLARE_CLASS(wxImageHandler)
74 };
75
76 //-----------------------------------------------------------------------------
77 // wxImage
78 //-----------------------------------------------------------------------------
79
80 class WXDLLEXPORT wxHNode
81 {
82 public:
83 unsigned long index;
84 unsigned long value;
85 };
86
87 class WXDLLEXPORT wxImage: public wxObject
88 {
89 public:
90 wxImage();
91 wxImage( int width, int height );
92 wxImage( int width, int height, unsigned char* data, bool static_data = FALSE );
93 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
94 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
95 wxImage( const wxString& name, const wxString& mimetype );
96 wxImage( wxInputStream& stream, const wxString& mimetype );
97
98 wxImage( const wxImage& image );
99 wxImage( const wxImage* image );
100
101 #if wxUSE_GUI
102 // convertion to/from wxBitmap (deprecated, use wxBitmap's methods instead):
103 wxImage( const wxBitmap &bitmap );
104 operator wxBitmap() const { return ConvertToBitmap(); }
105 wxBitmap ConvertToBitmap() const;
106 #ifdef __WXGTK__
107 wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const;
108 #endif
109 #endif
110
111 void Create( int width, int height );
112 void Create( int width, int height, unsigned char* data, bool static_data = FALSE );
113 void Destroy();
114
115 // creates an identical copy of the image (the = operator
116 // just raises the ref count)
117 wxImage Copy() const;
118
119 // return the new image with size width*height
120 wxImage GetSubImage( const wxRect& ) const;
121
122 // pastes image into this instance and takes care of
123 // the mask colour and out of bounds problems
124 void Paste( const wxImage &image, int x, int y );
125
126 // return the new image with size width*height
127 wxImage Scale( int width, int height ) const;
128
129 // rescales the image in place
130 wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); }
131
132 // Rotates the image about the given point, 'angle' radians.
133 // Returns the rotated image, leaving this image intact.
134 wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
135 bool interpolating = TRUE, wxPoint * offset_after_rotation = (wxPoint*) NULL) const;
136
137 wxImage Rotate90( bool clockwise = TRUE ) const;
138 wxImage Mirror( bool horizontally = TRUE ) const;
139
140 // replace one colour with another
141 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
142 unsigned char r2, unsigned char g2, unsigned char b2 );
143
144 // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black)
145 wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const;
146
147 // these routines are slow but safe
148 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
149 unsigned char GetRed( int x, int y ) const;
150 unsigned char GetGreen( int x, int y ) const;
151 unsigned char GetBlue( int x, int y ) const;
152
153 static bool CanRead( const wxString& name );
154 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY );
155 virtual bool LoadFile( const wxString& name, const wxString& mimetype );
156
157 #if wxUSE_STREAMS
158 static bool CanRead( wxInputStream& stream );
159 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
160 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
161 #endif
162
163 virtual bool SaveFile( const wxString& name, int type );
164 virtual bool SaveFile( const wxString& name, const wxString& mimetype );
165
166 #if wxUSE_STREAMS
167 virtual bool SaveFile( wxOutputStream& stream, int type );
168 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
169 #endif
170
171 bool Ok() const;
172 int GetWidth() const;
173 int GetHeight() const;
174
175 char unsigned *GetData() const;
176 void SetData( char unsigned *data );
177 void SetData( char unsigned *data, int new_width, int new_height );
178
179 // Mask functions
180 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
181 unsigned char GetMaskRed() const;
182 unsigned char GetMaskGreen() const;
183 unsigned char GetMaskBlue() const;
184 void SetMask( bool mask = TRUE );
185 bool HasMask() const;
186
187 // Palette functions
188 bool HasPalette() const;
189 const wxPalette& GetPalette() const;
190 void SetPalette(const wxPalette& palette);
191
192 // Option functions (arbitrary name/value mapping)
193 void SetOption(const wxString& name, const wxString& value);
194 void SetOption(const wxString& name, int value);
195 wxString GetOption(const wxString& name) const;
196 int GetOptionInt(const wxString& name) const;
197 bool HasOption(const wxString& name) const;
198
199 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
200 unsigned long ComputeHistogram( wxHashTable &h );
201
202 wxImage& operator = (const wxImage& image)
203 {
204 if ( (*this) != image )
205 Ref(image);
206 return *this;
207 }
208
209 bool operator == (const wxImage& image)
210 { return m_refData == image.m_refData; }
211 bool operator != (const wxImage& image)
212 { return m_refData != image.m_refData; }
213
214 static wxList& GetHandlers() { return sm_handlers; }
215 static void AddHandler( wxImageHandler *handler );
216 static void InsertHandler( wxImageHandler *handler );
217 static bool RemoveHandler( const wxString& name );
218 static wxImageHandler *FindHandler( const wxString& name );
219 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
220 static wxImageHandler *FindHandler( long imageType );
221 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
222
223 static void CleanUpHandlers();
224 static void InitStandardHandlers();
225
226 protected:
227 static wxList sm_handlers;
228
229 private:
230 friend class WXDLLEXPORT wxImageHandler;
231
232 DECLARE_DYNAMIC_CLASS(wxImage)
233 };
234
235
236 extern void WXDLLEXPORT wxInitAllImageHandlers();
237
238 WXDLLEXPORT_DATA(extern wxImage) wxNullImage;
239
240 //-----------------------------------------------------------------------------
241 // wxImage handlers
242 //-----------------------------------------------------------------------------
243
244 #include "wx/imagbmp.h"
245 #include "wx/imagpng.h"
246 #include "wx/imaggif.h"
247 #include "wx/imagpcx.h"
248 #include "wx/imagjpeg.h"
249 #include "wx/imagtiff.h"
250 #include "wx/imagpnm.h"
251
252 #endif
253 // _WX_IMAGE_H_
254