]> git.saurik.com Git - wxWidgets.git/blob - include/wx/image.h
no message
[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/stream.h"
22
23 //-----------------------------------------------------------------------------
24 // classes
25 //-----------------------------------------------------------------------------
26
27 class WXDLLEXPORT wxImageHandler;
28 #ifdef wxUSE_LIBPNG
29 class WXDLLEXPORT wxPNGHandler;
30 #endif
31 class WXDLLEXPORT wxBMPHandler;
32 class WXDLLEXPORT wxImage;
33
34 class WXDLLEXPORT wxBitmap;
35
36 //-----------------------------------------------------------------------------
37 // wxImageHandler
38 //-----------------------------------------------------------------------------
39
40 class WXDLLEXPORT wxImageHandler: public wxObject
41 {
42 DECLARE_DYNAMIC_CLASS(wxImageHandler)
43
44 public:
45 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
46
47 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
48 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
49
50 inline void SetName(const wxString& name) { m_name = name; }
51 inline void SetExtension(const wxString& ext) { m_extension = ext; }
52 inline void SetType(long type) { m_type = type; }
53 inline wxString GetName() const { return m_name; }
54 inline wxString GetExtension() const { return m_extension; }
55 inline long GetType() const { return m_type; }
56
57 protected:
58 wxString m_name;
59 wxString m_extension;
60 long m_type;
61
62 };
63
64 //-----------------------------------------------------------------------------
65 // wxPNGHandler
66 //-----------------------------------------------------------------------------
67
68 #ifdef wxUSE_LIBPNG
69 class WXDLLEXPORT wxPNGHandler: public wxImageHandler
70 {
71 DECLARE_DYNAMIC_CLASS(wxPNGHandler)
72
73 public:
74
75 inline wxPNGHandler()
76 {
77 m_name = "PNG file";
78 m_extension = "png";
79 m_type = wxBITMAP_TYPE_PNG;
80 };
81
82 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
83 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
84 };
85 #endif
86
87 //-----------------------------------------------------------------------------
88 // wxBMPHandler
89 //-----------------------------------------------------------------------------
90
91 class WXDLLEXPORT wxBMPHandler: public wxImageHandler
92 {
93 DECLARE_DYNAMIC_CLASS(wxBMPHandler)
94
95 public:
96
97 inline wxBMPHandler()
98 {
99 m_name = "BMP file";
100 m_extension = "bmp";
101 m_type = wxBITMAP_TYPE_BMP;
102 };
103
104 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
105 };
106
107 //-----------------------------------------------------------------------------
108 // wxImage
109 //-----------------------------------------------------------------------------
110
111 class WXDLLEXPORT wxImage: public wxObject
112 {
113 DECLARE_DYNAMIC_CLASS(wxImage)
114
115 friend class WXDLLEXPORT wxImageHandler;
116
117 public:
118
119 wxImage();
120 wxImage( int width, int height );
121 wxImage( const wxString& name, long type = wxBITMAP_TYPE_PNG );
122 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
123
124 wxImage( const wxImage& image );
125 wxImage( const wxImage* image );
126
127 // these functions get implemented in /src/(platform)/bitmap.cpp
128 wxImage( const wxBitmap &bitmap );
129 wxBitmap ConvertToBitmap() const;
130
131 void Create( int width, int height );
132 void Destroy();
133
134 wxImage Scale( int width, int height );
135
136 // these routines are slow but safe
137 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
138 unsigned char GetRed( int x, int y );
139 unsigned char GetGreen( int x, int y );
140 unsigned char GetBlue( int x, int y );
141
142 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG );
143 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
144 virtual bool SaveFile( const wxString& name, int type );
145 virtual bool SaveFile( wxOutputStream& stream, int type );
146
147 bool Ok() const;
148 int GetWidth() const;
149 int GetHeight() const;
150
151 char unsigned *GetData() const;
152 void SetData( char unsigned *data );
153
154 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
155 unsigned char GetMaskRed() const;
156 unsigned char GetMaskGreen() const;
157 unsigned char GetMaskBlue() const;
158 void SetMask( bool mask = TRUE );
159 bool HasMask() const;
160
161 inline wxImage& operator = (const wxImage& image)
162 { if (*this == image) return (*this); Ref(image); return *this; }
163 inline bool operator == (const wxImage& image)
164 { return m_refData == image.m_refData; }
165 inline bool operator != (const wxImage& image)
166 { return m_refData != image.m_refData; }
167
168 static inline wxList& GetHandlers() { return sm_handlers; }
169 static void AddHandler( wxImageHandler *handler );
170 static void InsertHandler( wxImageHandler *handler );
171 static bool RemoveHandler( const wxString& name );
172 static wxImageHandler *FindHandler( const wxString& name );
173 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
174 static wxImageHandler *FindHandler( long imageType );
175
176 static void CleanUpHandlers();
177 static void InitStandardHandlers();
178
179 protected:
180
181 static wxList sm_handlers;
182
183 };
184
185 #endif
186 // _WX_IMAGE_H_