00001
00002
00003
00004
00005
00006
00007
00009
00010 #ifndef _WX_IMAGE_H_
00011 #define _WX_IMAGE_H_
00012
00013 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
00014 #pragma interface "image.h"
00015 #endif
00016
00017 #include "wx/defs.h"
00018 #include "wx/object.h"
00019 #include "wx/string.h"
00020 #include "wx/gdicmn.h"
00021 #include "wx/hashmap.h"
00022
00023 #if wxUSE_STREAMS
00024 # include "wx/stream.h"
00025 #endif
00026
00027 #if wxUSE_IMAGE
00028
00029
00030
00031 #undef index
00032
00033 #define wxIMAGE_OPTION_QUALITY wxString(_T("quality"))
00034 #define wxIMAGE_OPTION_FILENAME wxString(_T("FileName"))
00035
00036 #define wxIMAGE_OPTION_RESOLUTION wxString(_T("Resolution"))
00037 #define wxIMAGE_OPTION_RESOLUTIONX wxString(_T("ResolutionX"))
00038 #define wxIMAGE_OPTION_RESOLUTIONY wxString(_T("ResolutionY"))
00039
00040 #define wxIMAGE_OPTION_RESOLUTIONUNIT wxString(_T("ResolutionUnit"))
00041
00042
00043 enum
00044 {
00045 wxIMAGE_RESOLUTION_INCHES = 1,
00046 wxIMAGE_RESOLUTION_CM = 2
00047 };
00048
00049
00050
00051
00052 const unsigned char wxIMAGE_ALPHA_TRANSPARENT = 0;
00053 const unsigned char wxIMAGE_ALPHA_THRESHOLD = 0x80;
00054 const unsigned char wxIMAGE_ALPHA_OPAQUE = 0xff;
00055
00056
00057
00058
00059
00060 class WXDLLEXPORT wxImageHandler;
00061 class WXDLLEXPORT wxImage;
00062 class WXDLLEXPORT wxPalette;
00063
00064
00065
00066
00067
00068 class WXDLLEXPORT wxImageHandler: public wxObject
00069 {
00070 public:
00071 wxImageHandler()
00072 : m_name(wxEmptyString), m_extension(wxEmptyString), m_mime(), m_type(0)
00073 { }
00074
00075 #if wxUSE_STREAMS
00076 virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
00077 virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
00078
00079 virtual int GetImageCount( wxInputStream& stream );
00080
00081 bool CanRead( wxInputStream& stream ) { return CallDoCanRead(stream); }
00082 bool CanRead( const wxString& name );
00083 #endif // wxUSE_STREAMS
00084
00085 void SetName(const wxString& name) { m_name = name; }
00086 void SetExtension(const wxString& ext) { m_extension = ext; }
00087 void SetType(long type) { m_type = type; }
00088 void SetMimeType(const wxString& type) { m_mime = type; }
00089 wxString GetName() const { return m_name; }
00090 wxString GetExtension() const { return m_extension; }
00091 long GetType() const { return m_type; }
00092 wxString GetMimeType() const { return m_mime; }
00093
00094 protected:
00095 #if wxUSE_STREAMS
00096 virtual bool DoCanRead( wxInputStream& stream ) = 0;
00097
00098
00099 bool CallDoCanRead(wxInputStream& stream);
00100 #endif // wxUSE_STREAMS
00101
00102 wxString m_name;
00103 wxString m_extension;
00104 wxString m_mime;
00105 long m_type;
00106
00107 private:
00108 DECLARE_CLASS(wxImageHandler)
00109 };
00110
00111
00112
00113
00114
00115 class WXDLLEXPORT wxImageHistogramEntry
00116 {
00117 public:
00118 wxImageHistogramEntry() { index = value = 0; }
00119 unsigned long index;
00120 unsigned long value;
00121 };
00122
00123 WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
00124 wxIntegerHash, wxIntegerEqual,
00125 wxImageHistogramBase);
00126
00127 class WXDLLEXPORT wxImageHistogram : public wxImageHistogramBase
00128 {
00129 public:
00130 wxImageHistogram() : wxImageHistogramBase(256) { }
00131
00132
00133 static unsigned long MakeKey(unsigned char r,
00134 unsigned char g,
00135 unsigned char b)
00136 {
00137 return (r << 16) | (g << 8) | b;
00138 }
00139
00140
00141
00142
00143
00144
00145 bool FindFirstUnusedColour(unsigned char *r,
00146 unsigned char *g,
00147 unsigned char *b,
00148 unsigned char startR = 1,
00149 unsigned char startG = 0,
00150 unsigned char startB = 0 ) const;
00151 };
00152
00153
00154
00155
00156
00157 class WXDLLEXPORT wxImage: public wxObject
00158 {
00159 public:
00160 #if wxABI_VERSION >= 20602
00161
00162
00163 class RGBValue
00164 {
00165 public:
00166 RGBValue(unsigned char r=0, unsigned char g=0, unsigned char b=0)
00167 : red(r), green(g), blue(b) {}
00168 unsigned char red;
00169 unsigned char green;
00170 unsigned char blue;
00171 };
00172
00173
00174 class HSVValue
00175 {
00176 public:
00177 HSVValue(double h=0.0, double s=0.0, double v=0.0)
00178 : hue(h), saturation(s), value(v) {}
00179 double hue;
00180 double saturation;
00181 double value;
00182 };
00183 #endif // wxABI_VERSION >= 2.6.2
00184
00185 wxImage(){}
00186 wxImage( int width, int height, bool clear = true );
00187 wxImage( int width, int height, unsigned char* data, bool static_data = false );
00188 wxImage( int width, int height, unsigned char* data, unsigned char* alpha, bool static_data = false );
00189 wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
00190 wxImage( const wxString& name, const wxString& mimetype, int index = -1 );
00191 wxImage( const char** xpmData );
00192 wxImage( char** xpmData );
00193
00194 #if wxUSE_STREAMS
00195 wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 );
00196 wxImage( wxInputStream& stream, const wxString& mimetype, int index = -1 );
00197 #endif // wxUSE_STREAMS
00198
00199 wxImage( const wxImage& image );
00200 wxImage( const wxImage* image );
00201
00202 bool Create( int width, int height, bool clear = true );
00203 bool Create( int width, int height, unsigned char* data, bool static_data = false );
00204 bool Create( int width, int height, unsigned char* data, unsigned char* alpha, bool static_data = false );
00205 bool Create( const char** xpmData );
00206 void Destroy();
00207
00208
00209
00210 wxImage Copy() const;
00211
00212
00213 wxImage GetSubImage( const wxRect& rect) const;
00214
00215
00216
00217
00218
00219 wxImage Size( const wxSize& size, const wxPoint& pos,
00220 int r = -1, int g = -1, int b = -1 ) const;
00221
00222
00223
00224 void Paste( const wxImage &image, int x, int y );
00225
00226
00227 wxImage Scale( int width, int height ) const;
00228
00229 wxImage ShrinkBy( int xFactor , int yFactor ) const ;
00230
00231
00232 wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); }
00233
00234
00235 wxImage& Resize( const wxSize& size, const wxPoint& pos,
00236 int r = -1, int g = -1, int b = -1 ) { return *this = Size(size, pos, r, g, b); }
00237
00238
00239
00240 wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
00241 bool interpolating = true, wxPoint * offset_after_rotation = (wxPoint*) NULL) const;
00242
00243 wxImage Rotate90( bool clockwise = true ) const;
00244 wxImage Mirror( bool horizontally = true ) const;
00245
00246
00247 void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
00248 unsigned char r2, unsigned char g2, unsigned char b2 );
00249
00250
00251
00252 wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const;
00253
00254
00255 void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
00256 void SetRGB( const wxRect& rect, unsigned char r, unsigned char g, unsigned char b );
00257 unsigned char GetRed( int x, int y ) const;
00258 unsigned char GetGreen( int x, int y ) const;
00259 unsigned char GetBlue( int x, int y ) const;
00260
00261 void SetAlpha(int x, int y, unsigned char alpha);
00262 unsigned char GetAlpha(int x, int y) const;
00263
00264
00265
00266 bool FindFirstUnusedColour( unsigned char *r, unsigned char *g, unsigned char *b,
00267 unsigned char startR = 1, unsigned char startG = 0,
00268 unsigned char startB = 0 ) const;
00269
00270 bool SetMaskFromImage(const wxImage & mask,
00271 unsigned char mr, unsigned char mg, unsigned char mb);
00272
00273
00274
00275 bool ConvertAlphaToMask(unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 bool ConvertColourToAlpha( unsigned char r, unsigned char g, unsigned char b );
00288
00289 static bool CanRead( const wxString& name );
00290 static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY );
00291 virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 );
00292 virtual bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 );
00293
00294 #if wxUSE_STREAMS
00295 static bool CanRead( wxInputStream& stream );
00296 static int GetImageCount( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY );
00297 virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 );
00298 virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 );
00299 #endif
00300
00301 virtual bool SaveFile( const wxString& name ) const;
00302 virtual bool SaveFile( const wxString& name, int type ) const;
00303 virtual bool SaveFile( const wxString& name, const wxString& mimetype ) const;
00304
00305 #if wxUSE_STREAMS
00306 virtual bool SaveFile( wxOutputStream& stream, int type ) const;
00307 virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ) const;
00308 #endif
00309
00310 bool Ok() const;
00311 int GetWidth() const;
00312 int GetHeight() const;
00313
00314
00315
00316 unsigned char *GetData() const;
00317 void SetData( unsigned char *data, bool static_data=false );
00318 void SetData( unsigned char *data, int new_width, int new_height, bool static_data=false );
00319
00320 unsigned char *GetAlpha() const;
00321 bool HasAlpha() const { return GetAlpha() != NULL; }
00322 void SetAlpha(unsigned char *alpha = NULL, bool static_data=false);
00323 void InitAlpha();
00324
00325
00326
00327 bool IsTransparent(int x, int y,
00328 unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD) const;
00329
00330
00331 void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
00332
00333
00334 bool GetOrFindMaskColour( unsigned char *r, unsigned char *g, unsigned char *b ) const;
00335 unsigned char GetMaskRed() const;
00336 unsigned char GetMaskGreen() const;
00337 unsigned char GetMaskBlue() const;
00338 void SetMask( bool mask = true );
00339 bool HasMask() const;
00340
00341 #if wxUSE_PALETTE
00342
00343 bool HasPalette() const;
00344 const wxPalette& GetPalette() const;
00345 void SetPalette(const wxPalette& palette);
00346 #endif // wxUSE_PALETTE
00347
00348
00349 void SetOption(const wxString& name, const wxString& value);
00350 void SetOption(const wxString& name, int value);
00351 wxString GetOption(const wxString& name) const;
00352 int GetOptionInt(const wxString& name) const;
00353 bool HasOption(const wxString& name) const;
00354
00355 unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ) const;
00356
00357
00358
00359
00360
00361
00362
00363 unsigned long ComputeHistogram( wxImageHistogram &h ) const;
00364
00365 #if wxABI_VERSION >= 20602
00366
00367
00368 void RotateHue(double angle);
00369 #endif // wxABI_VERSION >= 2.6.2
00370
00371 wxImage& operator = (const wxImage& image)
00372 {
00373 if ( (*this) != image )
00374 Ref(image);
00375 return *this;
00376 }
00377
00378 bool operator == (const wxImage& image) const
00379 { return m_refData == image.m_refData; }
00380 bool operator != (const wxImage& image) const
00381 { return m_refData != image.m_refData; }
00382
00383 static wxList& GetHandlers() { return sm_handlers; }
00384 static void AddHandler( wxImageHandler *handler );
00385 static void InsertHandler( wxImageHandler *handler );
00386 static bool RemoveHandler( const wxString& name );
00387 static wxImageHandler *FindHandler( const wxString& name );
00388 static wxImageHandler *FindHandler( const wxString& extension, long imageType );
00389 static wxImageHandler *FindHandler( long imageType );
00390 static wxImageHandler *FindHandlerMime( const wxString& mimetype );
00391
00392 static wxString GetImageExtWildcard();
00393
00394 static void CleanUpHandlers();
00395 static void InitStandardHandlers();
00396
00397 #if wxABI_VERSION >= 20602
00398 static HSVValue RGBtoHSV(const RGBValue& rgb);
00399 static RGBValue HSVtoRGB(const HSVValue& hsv);
00400 #endif // wxABI_VERSION >= 2.6.2
00401
00402
00403 protected:
00404 static wxList sm_handlers;
00405
00406
00407
00408
00409
00410 long XYToIndex(int x, int y) const;
00411
00412 private:
00413 friend class WXDLLEXPORT wxImageHandler;
00414
00415 DECLARE_DYNAMIC_CLASS(wxImage)
00416 };
00417
00418
00419 extern void WXDLLEXPORT wxInitAllImageHandlers();
00420
00421 extern WXDLLEXPORT_DATA(wxImage) wxNullImage;
00422
00423
00424
00425
00426
00427 #include "wx/imagbmp.h"
00428 #include "wx/imagpng.h"
00429 #include "wx/imaggif.h"
00430 #include "wx/imagpcx.h"
00431 #include "wx/imagjpeg.h"
00432 #include "wx/imagtiff.h"
00433 #include "wx/imagpnm.h"
00434 #include "wx/imagxpm.h"
00435 #include "wx/imagiff.h"
00436
00437 #endif
00438
00439 #endif
00440
00441