]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
Added rotation to wxImage
[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( 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 );
96
97 wxImage( const wxImage& image );
98 wxImage( const wxImage* image );
99
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;
104 #ifdef __WXGTK__
105 wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue );
106 #endif
107
108 void Create( int width, int height );
109 void Destroy();
110
111 // return the new image with size width*height
112 wxImage GetSubImage( const wxRect& ) const;
113
114 // return the new image with size width*height
115 wxImage Scale( int width, int height ) const;
116
117 // rescales the image in place
118 wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); }
119
120 // Rotates the image about the given point, 'angle' radians.
121 // Returns the rotated image, leaving this image intact.
122 wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
123 bool interpolating = TRUE, wxPoint * offset_after_rotation = (wxPoint*) NULL) const ;
124
125 // replace one colour with another
126 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
127 unsigned char r2, unsigned char g2, unsigned char b2 );
128
129 // these routines are slow but safe
130 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
131 unsigned char GetRed( int x, int y );
132 unsigned char GetGreen( int x, int y );
133 unsigned char GetBlue( int x, int y );
134
135 static bool CanRead( const wxString& name );
136 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY );
137 virtual bool LoadFile( const wxString& name, const wxString& mimetype );
138
139 #if wxUSE_STREAMS
140 static bool CanRead( wxInputStream& stream );
141 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
142 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
143 #endif
144
145 virtual bool SaveFile( const wxString& name, int type );
146 virtual bool SaveFile( const wxString& name, const wxString& mimetype );
147
148 #if wxUSE_STREAMS
149 virtual bool SaveFile( wxOutputStream& stream, int type );
150 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
151 #endif
152
153 bool Ok() const;
154 int GetWidth() const;
155 int GetHeight() const;
156
157 char unsigned *GetData() const;
158 void SetData( char unsigned *data );
159
160 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
161 unsigned char GetMaskRed() const;
162 unsigned char GetMaskGreen() const;
163 unsigned char GetMaskBlue() const;
164 void SetMask( bool mask = TRUE );
165 bool HasMask() const;
166
167 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
168 unsigned long ComputeHistogram( wxHashTable &h );
169
170 wxImage& operator = (const wxImage& image)
171 {
172 if ( (*this) != image )
173 Ref(image);
174 return *this;
175 }
176
177 bool operator == (const wxImage& image)
178 { return m_refData == image.m_refData; }
179 bool operator != (const wxImage& image)
180 { return m_refData != image.m_refData; }
181
182 static wxList& GetHandlers() { return sm_handlers; }
183 static void AddHandler( wxImageHandler *handler );
184 static void InsertHandler( wxImageHandler *handler );
185 static bool RemoveHandler( const wxString& name );
186 static wxImageHandler *FindHandler( const wxString& name );
187 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
188 static wxImageHandler *FindHandler( long imageType );
189 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
190
191 static void CleanUpHandlers();
192 static void InitStandardHandlers();
193
194 protected:
195 static wxList sm_handlers;
196
197 private:
198 friend class WXDLLEXPORT wxImageHandler;
199
200 DECLARE_DYNAMIC_CLASS(wxImage)
201 };
202
203
204 extern void WXDLLEXPORT wxInitAllImageHandlers();
205
206
207 //-----------------------------------------------------------------------------
208 // wxImage handlers
209 //-----------------------------------------------------------------------------
210
211 #include "wx/imagbmp.h"
212 #include "wx/imagpng.h"
213 #include "wx/imaggif.h"
214 #include "wx/imagpcx.h"
215 #include "wx/imagjpeg.h"
216 #include "wx/imagtiff.h"
217 #include "wx/imagpnm.h"
218
219 #endif
220 // _WX_IMAGE_H_
221