]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/image.h
removed wxITALIC/wxSLANT stuff from wxHTML (no longer neccessary, we have intelligent...
[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#include "wx/bitmap.h"
22
23#if wxUSE_STREAMS
24# include "wx/stream.h"
25#endif
26
27//-----------------------------------------------------------------------------
28// classes
29//-----------------------------------------------------------------------------
30
31class WXDLLEXPORT wxImageHandler;
32class WXDLLEXPORT wxImage;
33
34//-----------------------------------------------------------------------------
35// wxImageHandler
36//-----------------------------------------------------------------------------
37
38class WXDLLEXPORT wxImageHandler: public wxObject
39{
40 DECLARE_CLASS(wxImageHandler)
41
42public:
43 wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; }
44
45#if wxUSE_STREAMS
46 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=0 );
47 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE );
48
49 virtual int GetImageCount( wxInputStream& stream );
50
51 bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); }
52 bool CanRead( const wxString& name );
53#endif // wxUSE_STREAMS
54
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; }
63
64protected:
65#if wxUSE_STREAMS
66 virtual bool DoCanRead( wxInputStream& stream ) = 0;
67#endif // wxUSE_STREAMS
68
69 wxString m_name;
70 wxString m_extension;
71 wxString m_mime;
72 long m_type;
73};
74
75
76//-----------------------------------------------------------------------------
77// wxImage
78//-----------------------------------------------------------------------------
79
80
81// GRG: Dic/99
82class WXDLLEXPORT wxHNode
83{
84public:
85 unsigned long index;
86 unsigned long value;
87};
88
89
90class WXDLLEXPORT wxImage: public wxObject
91{
92 DECLARE_DYNAMIC_CLASS(wxImage)
93
94 friend class WXDLLEXPORT wxImageHandler;
95
96public:
97
98 wxImage();
99 wxImage( int width, int height );
100 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY );
101 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
102 wxImage( const wxString& name, const wxString& mimetype );
103 wxImage( wxInputStream& stream, const wxString& mimetype );
104
105 wxImage( const wxImage& image );
106 wxImage( const wxImage* image );
107
108 // these functions get implemented in /src/(platform)/bitmap.cpp
109 wxImage( const wxBitmap &bitmap );
110 operator wxBitmap() const { return ConvertToBitmap(); }
111 wxBitmap ConvertToBitmap() const;
112
113 void Create( int width, int height );
114 void Destroy();
115
116 // return the new image with size width*height
117 wxImage GetSubImage( const wxRect& ) const;
118
119 // return the new image with size width*height
120 wxImage Scale( int width, int height ) const;
121
122 // rescales the image in place
123 wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); }
124
125 // these routines are slow but safe
126 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
127 unsigned char GetRed( int x, int y );
128 unsigned char GetGreen( int x, int y );
129 unsigned char GetBlue( int x, int y );
130
131 static bool CanRead( const wxString& name );
132 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY );
133 virtual bool LoadFile( const wxString& name, const wxString& mimetype );
134
135#if wxUSE_STREAMS
136 static bool CanRead( wxInputStream& stream );
137 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
138 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype );
139#endif
140
141 virtual bool SaveFile( const wxString& name, int type );
142 virtual bool SaveFile( const wxString& name, const wxString& mimetype );
143
144#if wxUSE_STREAMS
145 virtual bool SaveFile( wxOutputStream& stream, int type );
146 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype );
147#endif
148
149 bool Ok() const;
150 int GetWidth() const;
151 int GetHeight() const;
152
153 char unsigned *GetData() const;
154 void SetData( char unsigned *data );
155
156 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
157 unsigned char GetMaskRed() const;
158 unsigned char GetMaskGreen() const;
159 unsigned char GetMaskBlue() const;
160 void SetMask( bool mask = TRUE );
161 bool HasMask() const;
162
163 wxImage& operator = (const wxImage& image)
164 {
165 if ( (*this) != image )
166 Ref(image);
167 return *this;
168 }
169
170 bool operator == (const wxImage& image)
171 { return m_refData == image.m_refData; }
172 bool operator != (const wxImage& image)
173 { return m_refData != image.m_refData; }
174
175 static wxList& GetHandlers() { return sm_handlers; }
176 static void AddHandler( wxImageHandler *handler );
177 static void InsertHandler( wxImageHandler *handler );
178 static bool RemoveHandler( const wxString& name );
179 static wxImageHandler *FindHandler( const wxString& name );
180 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
181 static wxImageHandler *FindHandler( long imageType );
182 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
183
184 static void CleanUpHandlers();
185 static void InitStandardHandlers();
186
187 // GRG: Dic/99
188 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 );
189 unsigned long ComputeHistogram( wxHashTable &h );
190
191
192protected:
193
194 static wxList sm_handlers;
195
196};
197
198
199extern void WXDLLEXPORT wxInitAllImageHandlers();
200
201
202//-----------------------------------------------------------------------------
203// wxImage handlers
204//-----------------------------------------------------------------------------
205
206#include "wx/imagbmp.h"
207#include "wx/imagpng.h"
208#include "wx/imaggif.h"
209#include "wx/imagpcx.h"
210#include "wx/imagjpeg.h"
211#include "wx/imagtiff.h"
212#include "wx/imagpnm.h"
213
214#endif
215 // _WX_IMAGE_H_
216