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