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