]> git.saurik.com Git - wxWidgets.git/blame - include/wx/image.h
added MSLU reference to wxUSE_UNICODE
[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
23280650 7// Licence: wxWindows licence
01111366
RR
8/////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_IMAGE_H_
11#define _WX_IMAGE_H_
12
af49c4b8 13#if defined(__GNUG__) && !defined(__APPLE__)
01111366
RR
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"
23280650 21#include "wx/bitmap.h"
952ae1e8 22#include "wx/hashmap.h"
bf38cbff
JS
23
24#if wxUSE_STREAMS
b9943f8e 25# include "wx/stream.h"
bf38cbff 26#endif
01111366 27
775c6f0c
VS
28#if wxUSE_IMAGE
29
fd94e8aa
VS
30#define wxIMAGE_OPTION_FILENAME wxString(_T("FileName"))
31
01111366
RR
32//-----------------------------------------------------------------------------
33// classes
34//-----------------------------------------------------------------------------
35
36class WXDLLEXPORT wxImageHandler;
01111366
RR
37class WXDLLEXPORT wxImage;
38
39//-----------------------------------------------------------------------------
40// wxImageHandler
41//-----------------------------------------------------------------------------
42
43class WXDLLEXPORT wxImageHandler: public wxObject
44{
01111366 45public:
d84afea9 46 wxImageHandler()
2b5f62a0 47 : m_name(wxT("")), m_extension(wxT("")), m_mime(), m_type(0)
d84afea9 48 { }
01111366 49
bf38cbff 50#if wxUSE_STREAMS
d394f479 51 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=-1 );
be25e480 52 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
8f177c8e 53
649d13e8 54 virtual int GetImageCount( wxInputStream& stream );
0828c087 55
39d16996 56 bool CanRead( wxInputStream& stream ) { return CallDoCanRead(stream); }
be25e480 57 bool CanRead( const wxString& name );
8f177c8e 58#endif // wxUSE_STREAMS
01111366 59
be25e480
RR
60 void SetName(const wxString& name) { m_name = name; }
61 void SetExtension(const wxString& ext) { m_extension = ext; }
62 void SetType(long type) { m_type = type; }
63 void SetMimeType(const wxString& type) { m_mime = type; }
64 wxString GetName() const { return m_name; }
65 wxString GetExtension() const { return m_extension; }
66 long GetType() const { return m_type; }
67 wxString GetMimeType() const { return m_mime; }
9e9ee68e 68
01111366 69protected:
8f177c8e 70#if wxUSE_STREAMS
be25e480 71 virtual bool DoCanRead( wxInputStream& stream ) = 0;
995612e2 72
39d16996
VZ
73 // save the stream position, call DoCanRead() and restore the position
74 bool CallDoCanRead(wxInputStream& stream);
55472691 75#endif // wxUSE_STREAMS
39d16996 76
be25e480
RR
77 wxString m_name;
78 wxString m_extension;
79 wxString m_mime;
80 long m_type;
aaf46fd6 81
be25e480
RR
82private:
83 DECLARE_CLASS(wxImageHandler)
8f177c8e
VZ
84};
85
01111366 86//-----------------------------------------------------------------------------
952ae1e8 87// wxImageHistogram
01111366
RR
88//-----------------------------------------------------------------------------
89
952ae1e8 90class WXDLLEXPORT wxImageHistogramEntry
c9d01afd
GRG
91{
92public:
952ae1e8 93 wxImageHistogramEntry() : index(0), value(0) {}
c9d01afd
GRG
94 unsigned long index;
95 unsigned long value;
96};
97
952ae1e8
VS
98WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
99 wxIntegerHash, wxIntegerEqual,
dac7d53a 100 wxImageHistogram);
952ae1e8
VS
101
102//-----------------------------------------------------------------------------
103// wxImage
104//-----------------------------------------------------------------------------
105
01111366
RR
106class WXDLLEXPORT wxImage: public wxObject
107{
01111366 108public:
be25e480
RR
109 wxImage();
110 wxImage( int width, int height );
f6bcfd97 111 wxImage( int width, int height, unsigned char* data, bool static_data = FALSE );
60d43ad8
VS
112 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
113 wxImage( const wxString& name, const wxString& mimetype, int index = -1 );
aaf46fd6
VZ
114
115#if wxUSE_STREAMS
60d43ad8
VS
116 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 );
117 wxImage( wxInputStream& stream, const wxString& mimetype, int index = -1 );
aaf46fd6 118#endif // wxUSE_STREAMS
01111366 119
be25e480
RR
120 wxImage( const wxImage& image );
121 wxImage( const wxImage* image );
9e9ee68e 122
ef8f37e0 123#if WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI
2b5f62a0 124 // conversion to/from wxBitmap (deprecated, use wxBitmap's methods instead):
b254d1fe
VS
125 wxDEPRECATED( wxImage(const wxBitmap &bitmap) );
126 wxDEPRECATED( wxBitmap ConvertToBitmap() const );
82ea63e6 127#ifdef __WXGTK__
f515c25a 128 wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const;
fd859211 129#endif
82ea63e6 130#endif
23280650 131
be25e480 132 void Create( int width, int height );
f6bcfd97 133 void Create( int width, int height, unsigned char* data, bool static_data = FALSE );
be25e480 134 void Destroy();
01111366 135
f6bcfd97
BP
136 // creates an identical copy of the image (the = operator
137 // just raises the ref count)
138 wxImage Copy() const;
aaf46fd6 139
be25e480
RR
140 // return the new image with size width*height
141 wxImage GetSubImage( const wxRect& ) const;
aaf46fd6 142
f6bcfd97
BP
143 // pastes image into this instance and takes care of
144 // the mask colour and out of bounds problems
aaf46fd6 145 void Paste( const wxImage &image, int x, int y );
23280650 146
be25e480
RR
147 // return the new image with size width*height
148 wxImage Scale( int width, int height ) const;
7b2471a0 149
be25e480
RR
150 // rescales the image in place
151 wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); }
ce9a75d2 152
7a632f10
JS
153 // Rotates the image about the given point, 'angle' radians.
154 // Returns the rotated image, leaving this image intact.
155 wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
f6bcfd97
BP
156 bool interpolating = TRUE, wxPoint * offset_after_rotation = (wxPoint*) NULL) const;
157
158 wxImage Rotate90( bool clockwise = TRUE ) const;
159 wxImage Mirror( bool horizontally = TRUE ) const;
7a632f10 160
be25e480
RR
161 // replace one colour with another
162 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
163 unsigned char r2, unsigned char g2, unsigned char b2 );
aaf46fd6 164
fd859211 165 // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black)
f515c25a 166 wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const;
ce9a75d2 167
be25e480
RR
168 // these routines are slow but safe
169 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
f6bcfd97
BP
170 unsigned char GetRed( int x, int y ) const;
171 unsigned char GetGreen( int x, int y ) const;
172 unsigned char GetBlue( int x, int y ) const;
23280650 173
1f5b2017
VS
174 // find first colour that is not used in the image and has higher
175 // RGB values than <startR,startG,startB>
176 bool FindFirstUnusedColour( unsigned char *r, unsigned char *g, unsigned char *b,
aaf46fd6 177 unsigned char startR = 1, unsigned char startG = 0,
e0a76d8d 178 unsigned char startB = 0 ) const;
1f5b2017 179 // Set image's mask to the area of 'mask' that has <r,g,b> colour
aaf46fd6 180 bool SetMaskFromImage(const wxImage & mask,
1f5b2017 181 unsigned char mr, unsigned char mg, unsigned char mb);
52b64b0a 182
be25e480 183 static bool CanRead( const wxString& name );
649d13e8 184 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
60d43ad8
VS
185 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
186 virtual bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 );
bf38cbff
JS
187
188#if wxUSE_STREAMS
be25e480 189 static bool CanRead( wxInputStream& stream );
649d13e8 190 static int GetImageCount( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
60d43ad8
VS
191 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 );
192 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 );
bf38cbff
JS
193#endif
194
45647dcf 195 virtual bool SaveFile( const wxString& name ) const;
e0a76d8d
VS
196 virtual bool SaveFile( const wxString& name, int type ) const;
197 virtual bool SaveFile( const wxString& name, const wxString& mimetype ) const;
bf38cbff
JS
198
199#if wxUSE_STREAMS
e0a76d8d
VS
200 virtual bool SaveFile( wxOutputStream& stream, int type ) const;
201 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ) const;
bf38cbff 202#endif
01111366 203
be25e480
RR
204 bool Ok() const;
205 int GetWidth() const;
206 int GetHeight() const;
207
208 char unsigned *GetData() const;
209 void SetData( char unsigned *data );
f6bcfd97 210 void SetData( char unsigned *data, int new_width, int new_height );
5e5437e0
JS
211
212 // Mask functions
be25e480
RR
213 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
214 unsigned char GetMaskRed() const;
215 unsigned char GetMaskGreen() const;
216 unsigned char GetMaskBlue() const;
217 void SetMask( bool mask = TRUE );
218 bool HasMask() const;
219
d275c7eb 220#if wxUSE_PALETTE
5e5437e0
JS
221 // Palette functions
222 bool HasPalette() const;
223 const wxPalette& GetPalette() const;
224 void SetPalette(const wxPalette& palette);
d275c7eb 225#endif // wxUSE_PALETTE
5e5437e0
JS
226
227 // Option functions (arbitrary name/value mapping)
228 void SetOption(const wxString& name, const wxString& value);
229 void SetOption(const wxString& name, int value);
230 wxString GetOption(const wxString& name) const;
231 int GetOptionInt(const wxString& name) const;
232 bool HasOption(const wxString& name) const;
3f4fc796 233
e0a76d8d 234 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ) const;
952ae1e8
VS
235
236 // Computes the histogram of the image and fills a hash table, indexed
237 // with integer keys built as 0xRRGGBB, containing wxImageHistogramEntry
238 // objects. Each of them contains an 'index' (useful to build a palette
239 // with the image colours) and a 'value', which is the number of pixels
240 // in the image with that colour.
241 // Returned value: # of entries in the histogram
e0a76d8d 242 unsigned long ComputeHistogram( wxImageHistogram &h ) const;
be25e480
RR
243
244 wxImage& operator = (const wxImage& image)
245 {
246 if ( (*this) != image )
247 Ref(image);
248 return *this;
249 }
250
2b5f62a0 251 bool operator == (const wxImage& image) const
be25e480 252 { return m_refData == image.m_refData; }
2b5f62a0 253 bool operator != (const wxImage& image) const
be25e480
RR
254 { return m_refData != image.m_refData; }
255
256 static wxList& GetHandlers() { return sm_handlers; }
257 static void AddHandler( wxImageHandler *handler );
258 static void InsertHandler( wxImageHandler *handler );
259 static bool RemoveHandler( const wxString& name );
260 static wxImageHandler *FindHandler( const wxString& name );
261 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
262 static wxImageHandler *FindHandler( long imageType );
263 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
264
265 static void CleanUpHandlers();
266 static void InitStandardHandlers();
c9d01afd 267
01111366 268protected:
5e5437e0 269 static wxList sm_handlers;
01111366 270
be25e480
RR
271private:
272 friend class WXDLLEXPORT wxImageHandler;
23280650 273
be25e480 274 DECLARE_DYNAMIC_CLASS(wxImage)
01111366
RR
275};
276
8f493002 277
a091d18c 278extern void WXDLLEXPORT wxInitAllImageHandlers();
b5a4a47d 279
fd859211 280WXDLLEXPORT_DATA(extern wxImage) wxNullImage;
8f493002
VS
281
282//-----------------------------------------------------------------------------
283// wxImage handlers
284//-----------------------------------------------------------------------------
285
286#include "wx/imagbmp.h"
287#include "wx/imagpng.h"
288#include "wx/imaggif.h"
289#include "wx/imagpcx.h"
290#include "wx/imagjpeg.h"
291#include "wx/imagtiff.h"
292#include "wx/imagpnm.h"
775c6f0c 293#include "wx/imagxpm.h"
4b6b4dfc 294#include "wx/imagiff.h"
775c6f0c
VS
295
296#endif // wxUSE_IMAGE
8f493002 297
01111366
RR
298#endif
299 // _WX_IMAGE_H_
9e9ee68e 300