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