]> git.saurik.com Git - wxWidgets.git/blame - include/wx/image.h
Slightly better style?
[wxWidgets.git] / include / wx / image.h
CommitLineData
01111366
RR
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"
bf38cbff
JS
21
22#if wxUSE_STREAMS
3d05544e 23#include "wx/stream.h"
bf38cbff 24#endif
01111366
RR
25
26//-----------------------------------------------------------------------------
27// classes
28//-----------------------------------------------------------------------------
29
30class WXDLLEXPORT wxImageHandler;
9838df2c 31#if wxUSE_LIBPNG
01111366 32class WXDLLEXPORT wxPNGHandler;
ac57418f 33#endif
56b9c741
VS
34#if wxUSE_LIBJPEG
35class WXDLLEXPORT wxJPEGHandler;
36#endif
01111366
RR
37class WXDLLEXPORT wxBMPHandler;
38class WXDLLEXPORT wxImage;
39
4bc67cc5
RR
40class WXDLLEXPORT wxBitmap;
41
01111366
RR
42//-----------------------------------------------------------------------------
43// wxImageHandler
44//-----------------------------------------------------------------------------
45
46class WXDLLEXPORT wxImageHandler: public wxObject
47{
48 DECLARE_DYNAMIC_CLASS(wxImageHandler)
49
50public:
51 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
52
bf38cbff 53#if wxUSE_STREAMS
3d05544e
JS
54 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
55 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
bf38cbff 56#endif
01111366
RR
57
58 inline void SetName(const wxString& name) { m_name = name; }
59 inline void SetExtension(const wxString& ext) { m_extension = ext; }
60 inline void SetType(long type) { m_type = type; }
9e9ee68e 61 inline void SetMimeType(const wxString& type) { m_mime = type; }
01111366
RR
62 inline wxString GetName() const { return m_name; }
63 inline wxString GetExtension() const { return m_extension; }
64 inline long GetType() const { return m_type; }
9e9ee68e
VS
65 inline wxString GetMimeType() const { return m_mime; }
66
01111366
RR
67protected:
68 wxString m_name;
69 wxString m_extension;
9e9ee68e 70 wxString m_mime;
01111366
RR
71 long m_type;
72
73};
74
75//-----------------------------------------------------------------------------
76// wxPNGHandler
77//-----------------------------------------------------------------------------
78
9838df2c 79#if wxUSE_LIBPNG
01111366
RR
80class WXDLLEXPORT wxPNGHandler: public wxImageHandler
81{
82 DECLARE_DYNAMIC_CLASS(wxPNGHandler)
83
84public:
85
fd0eed64
RR
86 inline wxPNGHandler()
87 {
88 m_name = "PNG file";
89 m_extension = "png";
90 m_type = wxBITMAP_TYPE_PNG;
9e9ee68e 91 m_mime = "image/png";
fd0eed64
RR
92 };
93
bf38cbff 94#if wxUSE_STREAMS
3d05544e
JS
95 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
96 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
bf38cbff
JS
97#endif
98
01111366 99};
ac57418f 100#endif
01111366 101
56b9c741
VS
102//-----------------------------------------------------------------------------
103// wxJPEGHandler
104//-----------------------------------------------------------------------------
105
9ef4a31e 106#if wxUSE_LIBJPEG
56b9c741
VS
107class WXDLLEXPORT wxJPEGHandler: public wxImageHandler
108{
109 DECLARE_DYNAMIC_CLASS(wxJPEGHandler)
110
111public:
112
113 inline wxJPEGHandler()
114 {
115 m_name = "JPEG file";
116 m_extension = "jpg";
117 m_type = wxBITMAP_TYPE_JPEG;
9e9ee68e 118 m_mime = "image/jpeg";
56b9c741
VS
119 };
120
121 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
122 virtual bool SaveFile( wxImage *image, wxOutputStream& stream );
123};
124#endif
125
01111366
RR
126//-----------------------------------------------------------------------------
127// wxBMPHandler
128//-----------------------------------------------------------------------------
129
130class WXDLLEXPORT wxBMPHandler: public wxImageHandler
131{
132 DECLARE_DYNAMIC_CLASS(wxBMPHandler)
133
134public:
135
fd0eed64
RR
136 inline wxBMPHandler()
137 {
138 m_name = "BMP file";
139 m_extension = "bmp";
140 m_type = wxBITMAP_TYPE_BMP;
9e9ee68e 141 m_mime = "image/bmp";
fd0eed64 142 };
01111366 143
bf38cbff 144#if wxUSE_STREAMS
3d05544e 145 virtual bool LoadFile( wxImage *image, wxInputStream& stream );
bf38cbff 146#endif
01111366 147};
fd0eed64 148
01111366
RR
149//-----------------------------------------------------------------------------
150// wxImage
151//-----------------------------------------------------------------------------
152
153class WXDLLEXPORT wxImage: public wxObject
154{
155 DECLARE_DYNAMIC_CLASS(wxImage)
156
157 friend class WXDLLEXPORT wxImageHandler;
158
159public:
160
161 wxImage();
162 wxImage( int width, int height );
163 wxImage( const wxString& name, long type = wxBITMAP_TYPE_PNG );
3d05544e 164 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
9e9ee68e
VS
165 wxImage( const wxString& name, const wxString& mimetype );
166 wxImage( wxInputStream& stream, const wxString& mimetype );
167
01111366
RR
168 wxImage( const wxImage& image );
169 wxImage( const wxImage* image );
4bc67cc5
RR
170
171 // these functions get implemented in /src/(platform)/bitmap.cpp
172 wxImage( const wxBitmap &bitmap );
173 wxBitmap ConvertToBitmap() const;
01111366
RR
174
175 void Create( int width, int height );
176 void Destroy();
177
4bc67cc5
RR
178 wxImage Scale( int width, int height );
179
ef539066
RR
180 // these routines are slow but safe
181 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
182 unsigned char GetRed( int x, int y );
183 unsigned char GetGreen( int x, int y );
184 unsigned char GetBlue( int x, int y );
185
01111366 186 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG );
9e9ee68e 187 virtual bool LoadFile( const wxString& name, const wxString& mimetype );
bf38cbff
JS
188
189#if wxUSE_STREAMS
3d05544e 190 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG );
9e9ee68e 191 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
bf38cbff
JS
192#endif
193
01111366 194 virtual bool SaveFile( const wxString& name, int type );
9e9ee68e 195 virtual bool SaveFile( const wxString& name, const wxString& mimetype );
bf38cbff
JS
196
197#if wxUSE_STREAMS
3d05544e 198 virtual bool SaveFile( wxOutputStream& stream, int type );
9e9ee68e 199 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
bf38cbff 200#endif
01111366
RR
201
202 bool Ok() const;
203 int GetWidth() const;
204 int GetHeight() const;
205
206 char unsigned *GetData() const;
207 void SetData( char unsigned *data );
208
209 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
210 unsigned char GetMaskRed() const;
211 unsigned char GetMaskGreen() const;
212 unsigned char GetMaskBlue() const;
213 void SetMask( bool mask = TRUE );
214 bool HasMask() const;
215
a3ef5bf5 216 inline wxImage& operator = (const wxImage& image)
ce3ed50d
JS
217 { if ((*this) == image)
218 return (*this);
219 Ref(image);
220 return *this; }
221
a3ef5bf5 222 inline bool operator == (const wxImage& image)
01111366
RR
223 { return m_refData == image.m_refData; }
224 inline bool operator != (const wxImage& image)
225 { return m_refData != image.m_refData; }
226
227 static inline wxList& GetHandlers() { return sm_handlers; }
228 static void AddHandler( wxImageHandler *handler );
229 static void InsertHandler( wxImageHandler *handler );
230 static bool RemoveHandler( const wxString& name );
231 static wxImageHandler *FindHandler( const wxString& name );
232 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
233 static wxImageHandler *FindHandler( long imageType );
9e9ee68e
VS
234 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
235
01111366 236 static void CleanUpHandlers();
fd0eed64 237 static void InitStandardHandlers();
01111366
RR
238
239protected:
240
241 static wxList sm_handlers;
242
243};
244
245#endif
246 // _WX_IMAGE_H_
9e9ee68e 247