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