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