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