image.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/image.h
  3. // Purpose: wxImage class
  4. // Author: Robert Roebling
  5. // Copyright: (c) Robert Roebling
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. #ifndef _WX_IMAGE_H_
  9. #define _WX_IMAGE_H_
  10. #include "wx/defs.h"
  11. #if wxUSE_IMAGE
  12. #include "wx/object.h"
  13. #include "wx/string.h"
  14. #include "wx/gdicmn.h"
  15. #include "wx/hashmap.h"
  16. #include "wx/arrstr.h"
  17. #if wxUSE_STREAMS
  18. # include "wx/stream.h"
  19. #endif
  20. // on some systems (Unixware 7.x) index is defined as a macro in the headers
  21. // which breaks the compilation below
  22. #undef index
  23. #define wxIMAGE_OPTION_QUALITY wxString(wxS("quality"))
  24. #define wxIMAGE_OPTION_FILENAME wxString(wxS("FileName"))
  25. #define wxIMAGE_OPTION_RESOLUTION wxString(wxS("Resolution"))
  26. #define wxIMAGE_OPTION_RESOLUTIONX wxString(wxS("ResolutionX"))
  27. #define wxIMAGE_OPTION_RESOLUTIONY wxString(wxS("ResolutionY"))
  28. #define wxIMAGE_OPTION_RESOLUTIONUNIT wxString(wxS("ResolutionUnit"))
  29. #define wxIMAGE_OPTION_MAX_WIDTH wxString(wxS("MaxWidth"))
  30. #define wxIMAGE_OPTION_MAX_HEIGHT wxString(wxS("MaxHeight"))
  31. #define wxIMAGE_OPTION_ORIGINAL_WIDTH wxString(wxS("OriginalWidth"))
  32. #define wxIMAGE_OPTION_ORIGINAL_HEIGHT wxString(wxS("OriginalHeight"))
  33. // constants used with wxIMAGE_OPTION_RESOLUTIONUNIT
  34. //
  35. // NB: don't change these values, they correspond to libjpeg constants
  36. enum wxImageResolution
  37. {
  38. // Resolution not specified
  39. wxIMAGE_RESOLUTION_NONE = 0,
  40. // Resolution specified in inches
  41. wxIMAGE_RESOLUTION_INCHES = 1,
  42. // Resolution specified in centimeters
  43. wxIMAGE_RESOLUTION_CM = 2
  44. };
  45. // Constants for wxImage::Scale() for determining the level of quality
  46. enum wxImageResizeQuality
  47. {
  48. // different image resizing algorithms used by Scale() and Rescale()
  49. wxIMAGE_QUALITY_NEAREST = 0,
  50. wxIMAGE_QUALITY_BILINEAR = 1,
  51. wxIMAGE_QUALITY_BICUBIC = 2,
  52. wxIMAGE_QUALITY_BOX_AVERAGE = 3,
  53. // default quality is low (but fast)
  54. wxIMAGE_QUALITY_NORMAL = wxIMAGE_QUALITY_NEAREST,
  55. // highest (but best) quality
  56. wxIMAGE_QUALITY_HIGH = 4
  57. };
  58. // alpha channel values: fully transparent, default threshold separating
  59. // transparent pixels from opaque for a few functions dealing with alpha and
  60. // fully opaque
  61. const unsigned char wxIMAGE_ALPHA_TRANSPARENT = 0;
  62. const unsigned char wxIMAGE_ALPHA_THRESHOLD = 0x80;
  63. const unsigned char wxIMAGE_ALPHA_OPAQUE = 0xff;
  64. //-----------------------------------------------------------------------------
  65. // classes
  66. //-----------------------------------------------------------------------------
  67. class WXDLLIMPEXP_FWD_CORE wxImageHandler;
  68. class WXDLLIMPEXP_FWD_CORE wxImage;
  69. class WXDLLIMPEXP_FWD_CORE wxPalette;
  70. //-----------------------------------------------------------------------------
  71. // wxVariant support
  72. //-----------------------------------------------------------------------------
  73. #if wxUSE_VARIANT
  74. #include "wx/variant.h"
  75. DECLARE_VARIANT_OBJECT_EXPORTED(wxImage,WXDLLIMPEXP_CORE)
  76. #endif
  77. //-----------------------------------------------------------------------------
  78. // wxImageHandler
  79. //-----------------------------------------------------------------------------
  80. class WXDLLIMPEXP_CORE wxImageHandler: public wxObject
  81. {
  82. public:
  83. wxImageHandler()
  84. : m_name(wxEmptyString), m_extension(wxEmptyString), m_mime(), m_type(wxBITMAP_TYPE_INVALID)
  85. { }
  86. #if wxUSE_STREAMS
  87. // NOTE: LoadFile and SaveFile are not pure virtuals to allow derived classes
  88. // to implement only one of the two
  89. virtual bool LoadFile( wxImage *WXUNUSED(image), wxInputStream& WXUNUSED(stream),
  90. bool WXUNUSED(verbose)=true, int WXUNUSED(index)=-1 )
  91. { return false; }
  92. virtual bool SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(stream),
  93. bool WXUNUSED(verbose)=true )
  94. { return false; }
  95. int GetImageCount( wxInputStream& stream );
  96. // save the stream position, call DoGetImageCount() and restore the position
  97. bool CanRead( wxInputStream& stream ) { return CallDoCanRead(stream); }
  98. bool CanRead( const wxString& name );
  99. #endif // wxUSE_STREAMS
  100. void SetName(const wxString& name) { m_name = name; }
  101. void SetExtension(const wxString& ext) { m_extension = ext; }
  102. void SetAltExtensions(const wxArrayString& exts) { m_altExtensions = exts; }
  103. void SetType(wxBitmapType type) { m_type = type; }
  104. void SetMimeType(const wxString& type) { m_mime = type; }
  105. const wxString& GetName() const { return m_name; }
  106. const wxString& GetExtension() const { return m_extension; }
  107. const wxArrayString& GetAltExtensions() const { return m_altExtensions; }
  108. wxBitmapType GetType() const { return m_type; }
  109. const wxString& GetMimeType() const { return m_mime; }
  110. #if WXWIN_COMPATIBILITY_2_8
  111. wxDEPRECATED(
  112. void SetType(long type) { SetType((wxBitmapType)type); }
  113. )
  114. #endif // WXWIN_COMPATIBILITY_2_8
  115. protected:
  116. #if wxUSE_STREAMS
  117. // NOTE: this function is allowed to change the current stream position
  118. // since GetImageCount() will take care of restoring it later
  119. virtual int DoGetImageCount( wxInputStream& WXUNUSED(stream) )
  120. { return 1; } // default return value is 1 image
  121. // NOTE: this function is allowed to change the current stream position
  122. // since CallDoCanRead() will take care of restoring it later
  123. virtual bool DoCanRead( wxInputStream& stream ) = 0;
  124. // save the stream position, call DoCanRead() and restore the position
  125. bool CallDoCanRead(wxInputStream& stream);
  126. #endif // wxUSE_STREAMS
  127. // helper for the derived classes SaveFile() implementations: returns the
  128. // values of x- and y-resolution options specified as the image options if
  129. // any
  130. static wxImageResolution
  131. GetResolutionFromOptions(const wxImage& image, int *x, int *y);
  132. wxString m_name;
  133. wxString m_extension;
  134. wxArrayString m_altExtensions;
  135. wxString m_mime;
  136. wxBitmapType m_type;
  137. private:
  138. DECLARE_CLASS(wxImageHandler)
  139. };
  140. //-----------------------------------------------------------------------------
  141. // wxImageHistogram
  142. //-----------------------------------------------------------------------------
  143. class WXDLLIMPEXP_CORE wxImageHistogramEntry
  144. {
  145. public:
  146. wxImageHistogramEntry() { index = value = 0; }
  147. unsigned long index;
  148. unsigned long value;
  149. };
  150. WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
  151. wxIntegerHash, wxIntegerEqual,
  152. wxImageHistogramBase);
  153. class WXDLLIMPEXP_CORE wxImageHistogram : public wxImageHistogramBase
  154. {
  155. public:
  156. wxImageHistogram() : wxImageHistogramBase(256) { }
  157. // get the key in the histogram for the given RGB values
  158. static unsigned long MakeKey(unsigned char r,
  159. unsigned char g,
  160. unsigned char b)
  161. {
  162. return (r << 16) | (g << 8) | b;
  163. }
  164. // find first colour that is not used in the image and has higher
  165. // RGB values than RGB(startR, startG, startB)
  166. //
  167. // returns true and puts this colour in r, g, b (each of which may be NULL)
  168. // on success or returns false if there are no more free colours
  169. bool FindFirstUnusedColour(unsigned char *r,
  170. unsigned char *g,
  171. unsigned char *b,
  172. unsigned char startR = 1,
  173. unsigned char startG = 0,
  174. unsigned char startB = 0 ) const;
  175. };
  176. //-----------------------------------------------------------------------------
  177. // wxImage
  178. //-----------------------------------------------------------------------------
  179. class WXDLLIMPEXP_CORE wxImage: public wxObject
  180. {
  181. public:
  182. // red, green and blue are 8 bit unsigned integers in the range of 0..255
  183. // We use the identifier RGBValue instead of RGB, since RGB is #defined
  184. class RGBValue
  185. {
  186. public:
  187. RGBValue(unsigned char r=0, unsigned char g=0, unsigned char b=0)
  188. : red(r), green(g), blue(b) {}
  189. unsigned char red;
  190. unsigned char green;
  191. unsigned char blue;
  192. };
  193. // hue, saturation and value are doubles in the range 0.0..1.0
  194. class HSVValue
  195. {
  196. public:
  197. HSVValue(double h=0.0, double s=0.0, double v=0.0)
  198. : hue(h), saturation(s), value(v) {}
  199. double hue;
  200. double saturation;
  201. double value;
  202. };
  203. wxImage() {}
  204. wxImage( int width, int height, bool clear = true )
  205. { Create( width, height, clear ); }
  206. wxImage( int width, int height, unsigned char* data, bool static_data = false )
  207. { Create( width, height, data, static_data ); }
  208. wxImage( int width, int height, unsigned char* data, unsigned char* alpha, bool static_data = false )
  209. { Create( width, height, data, alpha, static_data ); }
  210. // ctor variants using wxSize:
  211. wxImage( const wxSize& sz, bool clear = true )
  212. { Create( sz, clear ); }
  213. wxImage( const wxSize& sz, unsigned char* data, bool static_data = false )
  214. { Create( sz, data, static_data ); }
  215. wxImage( const wxSize& sz, unsigned char* data, unsigned char* alpha, bool static_data = false )
  216. { Create( sz, data, alpha, static_data ); }
  217. wxImage( const wxString& name, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1 )
  218. { LoadFile( name, type, index ); }
  219. wxImage( const wxString& name, const wxString& mimetype, int index = -1 )
  220. { LoadFile( name, mimetype, index ); }
  221. wxImage( const char* const* xpmData )
  222. { Create(xpmData); }
  223. #if wxUSE_STREAMS
  224. wxImage( wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1 )
  225. { LoadFile( stream, type, index ); }
  226. wxImage( wxInputStream& stream, const wxString& mimetype, int index = -1 )
  227. { LoadFile( stream, mimetype, index ); }
  228. #endif // wxUSE_STREAMS
  229. bool Create( const char* const* xpmData );
  230. #ifdef __BORLANDC__
  231. // needed for Borland 5.5
  232. wxImage( char** xpmData ) { Create(const_cast<const char* const*>(xpmData)); }
  233. bool Create( char** xpmData ) { return Create(const_cast<const char* const*>(xpmData)); }
  234. #endif
  235. bool Create( int width, int height, bool clear = true );
  236. bool Create( int width, int height, unsigned char* data, bool static_data = false );
  237. bool Create( int width, int height, unsigned char* data, unsigned char* alpha, bool static_data = false );
  238. // Create() variants using wxSize:
  239. bool Create( const wxSize& sz, bool clear = true )
  240. { return Create(sz.GetWidth(), sz.GetHeight(), clear); }
  241. bool Create( const wxSize& sz, unsigned char* data, bool static_data = false )
  242. { return Create(sz.GetWidth(), sz.GetHeight(), data, static_data); }
  243. bool Create( const wxSize& sz, unsigned char* data, unsigned char* alpha, bool static_data = false )
  244. { return Create(sz.GetWidth(), sz.GetHeight(), data, alpha, static_data); }
  245. void Destroy();
  246. // initialize the image data with zeroes
  247. void Clear(unsigned char value = 0);
  248. // creates an identical copy of the image (the = operator
  249. // just raises the ref count)
  250. wxImage Copy() const;
  251. // return the new image with size width*height
  252. wxImage GetSubImage( const wxRect& rect) const;
  253. // Paste the image or part of this image into an image of the given size at the pos
  254. // any newly exposed areas will be filled with the rgb colour
  255. // by default if r = g = b = -1 then fill with this image's mask colour or find and
  256. // set a suitable mask colour
  257. wxImage Size( const wxSize& size, const wxPoint& pos,
  258. int r = -1, int g = -1, int b = -1 ) const;
  259. // pastes image into this instance and takes care of
  260. // the mask colour and out of bounds problems
  261. void Paste( const wxImage &image, int x, int y );
  262. // return the new image with size width*height
  263. wxImage Scale( int width, int height,
  264. wxImageResizeQuality quality = wxIMAGE_QUALITY_NORMAL ) const;
  265. // box averager and bicubic filters for up/down sampling
  266. wxImage ResampleNearest(int width, int height) const;
  267. wxImage ResampleBox(int width, int height) const;
  268. wxImage ResampleBilinear(int width, int height) const;
  269. wxImage ResampleBicubic(int width, int height) const;
  270. // blur the image according to the specified pixel radius
  271. wxImage Blur(int radius) const;
  272. wxImage BlurHorizontal(int radius) const;
  273. wxImage BlurVertical(int radius) const;
  274. wxImage ShrinkBy( int xFactor , int yFactor ) const ;
  275. // rescales the image in place
  276. wxImage& Rescale( int width, int height,
  277. wxImageResizeQuality quality = wxIMAGE_QUALITY_NORMAL )
  278. { return *this = Scale(width, height, quality); }
  279. // resizes the image in place
  280. wxImage& Resize( const wxSize& size, const wxPoint& pos,
  281. int r = -1, int g = -1, int b = -1 ) { return *this = Size(size, pos, r, g, b); }
  282. // Rotates the image about the given point, 'angle' radians.
  283. // Returns the rotated image, leaving this image intact.
  284. wxImage Rotate(double angle, const wxPoint & centre_of_rotation,
  285. bool interpolating = true, wxPoint * offset_after_rotation = NULL) const;
  286. wxImage Rotate90( bool clockwise = true ) const;
  287. wxImage Rotate180() const;
  288. wxImage Mirror( bool horizontally = true ) const;
  289. // replace one colour with another
  290. void Replace( unsigned char r1, unsigned char g1, unsigned char b1,
  291. unsigned char r2, unsigned char g2, unsigned char b2 );
  292. // Convert to greyscale image. Uses the luminance component (Y) of the image.
  293. // The luma value (YUV) is calculated using (R * weight_r) + (G * weight_g) + (B * weight_b), defaults to ITU-T BT.601
  294. wxImage ConvertToGreyscale(double weight_r, double weight_g, double weight_b) const;
  295. wxImage ConvertToGreyscale(void) const;
  296. // convert to monochrome image (<r,g,b> will be replaced by white,
  297. // everything else by black)
  298. wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const;
  299. // Convert to disabled (dimmed) image.
  300. wxImage ConvertToDisabled(unsigned char brightness = 255) const;
  301. // these routines are slow but safe
  302. void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b );
  303. void SetRGB( const wxRect& rect, unsigned char r, unsigned char g, unsigned char b );
  304. unsigned char GetRed( int x, int y ) const;
  305. unsigned char GetGreen( int x, int y ) const;
  306. unsigned char GetBlue( int x, int y ) const;
  307. void SetAlpha(int x, int y, unsigned char alpha);
  308. unsigned char GetAlpha(int x, int y) const;
  309. // find first colour that is not used in the image and has higher
  310. // RGB values than <startR,startG,startB>
  311. bool FindFirstUnusedColour( unsigned char *r, unsigned char *g, unsigned char *b,
  312. unsigned char startR = 1, unsigned char startG = 0,
  313. unsigned char startB = 0 ) const;
  314. // Set image's mask to the area of 'mask' that has <r,g,b> colour
  315. bool SetMaskFromImage(const wxImage & mask,
  316. unsigned char mr, unsigned char mg, unsigned char mb);
  317. // converts image's alpha channel to mask (choosing mask colour
  318. // automatically or using the specified colour for the mask), if it has
  319. // any, does nothing otherwise:
  320. bool ConvertAlphaToMask(unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
  321. bool ConvertAlphaToMask(unsigned char mr, unsigned char mg, unsigned char mb,
  322. unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
  323. // This method converts an image where the original alpha
  324. // information is only available as a shades of a colour
  325. // (actually shades of grey) typically when you draw anti-
  326. // aliased text into a bitmap. The DC drawinf routines
  327. // draw grey values on the black background although they
  328. // actually mean to draw white with differnt alpha values.
  329. // This method reverses it, assuming a black (!) background
  330. // and white text (actually only the red channel is read).
  331. // The method will then fill up the whole image with the
  332. // colour given.
  333. bool ConvertColourToAlpha( unsigned char r, unsigned char g, unsigned char b );
  334. static bool CanRead( const wxString& name );
  335. static int GetImageCount( const wxString& name, wxBitmapType type = wxBITMAP_TYPE_ANY );
  336. virtual bool LoadFile( const wxString& name, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1 );
  337. virtual bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 );
  338. #if wxUSE_STREAMS
  339. static bool CanRead( wxInputStream& stream );
  340. static int GetImageCount( wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY );
  341. virtual bool LoadFile( wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1 );
  342. virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 );
  343. #endif
  344. virtual bool SaveFile( const wxString& name ) const;
  345. virtual bool SaveFile( const wxString& name, wxBitmapType type ) const;
  346. virtual bool SaveFile( const wxString& name, const wxString& mimetype ) const;
  347. #if wxUSE_STREAMS
  348. virtual bool SaveFile( wxOutputStream& stream, wxBitmapType type ) const;
  349. virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ) const;
  350. #endif
  351. bool Ok() const { return IsOk(); }
  352. bool IsOk() const;
  353. int GetWidth() const;
  354. int GetHeight() const;
  355. wxSize GetSize() const
  356. { return wxSize(GetWidth(), GetHeight()); }
  357. // Gets the type of image found by LoadFile or specified with SaveFile
  358. wxBitmapType GetType() const;
  359. // Set the image type, this is normally only called if the image is being
  360. // created from data in the given format but not using LoadFile() (e.g.
  361. // wxGIFDecoder uses this)
  362. void SetType(wxBitmapType type);
  363. // these functions provide fastest access to wxImage data but should be
  364. // used carefully as no checks are done
  365. unsigned char *GetData() const;
  366. void SetData( unsigned char *data, bool static_data=false );
  367. void SetData( unsigned char *data, int new_width, int new_height, bool static_data=false );
  368. unsigned char *GetAlpha() const; // may return NULL!
  369. bool HasAlpha() const { return GetAlpha() != NULL; }
  370. void SetAlpha(unsigned char *alpha = NULL, bool static_data=false);
  371. void InitAlpha();
  372. void ClearAlpha();
  373. // return true if this pixel is masked or has alpha less than specified
  374. // threshold
  375. bool IsTransparent(int x, int y,
  376. unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD) const;
  377. // Mask functions
  378. void SetMaskColour( unsigned char r, unsigned char g, unsigned char b );
  379. // Get the current mask colour or find a suitable colour
  380. // returns true if using current mask colour
  381. bool GetOrFindMaskColour( unsigned char *r, unsigned char *g, unsigned char *b ) const;
  382. unsigned char GetMaskRed() const;
  383. unsigned char GetMaskGreen() const;
  384. unsigned char GetMaskBlue() const;
  385. void SetMask( bool mask = true );
  386. bool HasMask() const;
  387. #if wxUSE_PALETTE
  388. // Palette functions
  389. bool HasPalette() const;
  390. const wxPalette& GetPalette() const;
  391. void SetPalette(const wxPalette& palette);
  392. #endif // wxUSE_PALETTE
  393. // Option functions (arbitrary name/value mapping)
  394. void SetOption(const wxString& name, const wxString& value);
  395. void SetOption(const wxString& name, int value);
  396. wxString GetOption(const wxString& name) const;
  397. int GetOptionInt(const wxString& name) const;
  398. bool HasOption(const wxString& name) const;
  399. unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ) const;
  400. // Computes the histogram of the image and fills a hash table, indexed
  401. // with integer keys built as 0xRRGGBB, containing wxImageHistogramEntry
  402. // objects. Each of them contains an 'index' (useful to build a palette
  403. // with the image colours) and a 'value', which is the number of pixels
  404. // in the image with that colour.
  405. // Returned value: # of entries in the histogram
  406. unsigned long ComputeHistogram( wxImageHistogram &h ) const;
  407. // Rotates the hue of each pixel of the image. angle is a double in the range
  408. // -1.0..1.0 where -1.0 is -360 degrees and 1.0 is 360 degrees
  409. void RotateHue(double angle);
  410. static wxList& GetHandlers() { return sm_handlers; }
  411. static void AddHandler( wxImageHandler *handler );
  412. static void InsertHandler( wxImageHandler *handler );
  413. static bool RemoveHandler( const wxString& name );
  414. static wxImageHandler *FindHandler( const wxString& name );
  415. static wxImageHandler *FindHandler( const wxString& extension, wxBitmapType imageType );
  416. static wxImageHandler *FindHandler( wxBitmapType imageType );
  417. static wxImageHandler *FindHandlerMime( const wxString& mimetype );
  418. static wxString GetImageExtWildcard();
  419. static void CleanUpHandlers();
  420. static void InitStandardHandlers();
  421. static HSVValue RGBtoHSV(const RGBValue& rgb);
  422. static RGBValue HSVtoRGB(const HSVValue& hsv);
  423. #if WXWIN_COMPATIBILITY_2_8
  424. wxDEPRECATED_CONSTRUCTOR(
  425. wxImage(const wxString& name, long type, int index = -1)
  426. {
  427. LoadFile(name, (wxBitmapType)type, index);
  428. }
  429. )
  430. #if wxUSE_STREAMS
  431. wxDEPRECATED_CONSTRUCTOR(
  432. wxImage(wxInputStream& stream, long type, int index = -1)
  433. {
  434. LoadFile(stream, (wxBitmapType)type, index);
  435. }
  436. )
  437. wxDEPRECATED(
  438. bool LoadFile(wxInputStream& stream, long type, int index = -1)
  439. {
  440. return LoadFile(stream, (wxBitmapType)type, index);
  441. }
  442. )
  443. wxDEPRECATED(
  444. bool SaveFile(wxOutputStream& stream, long type) const
  445. {
  446. return SaveFile(stream, (wxBitmapType)type);
  447. }
  448. )
  449. #endif // wxUSE_STREAMS
  450. wxDEPRECATED(
  451. bool LoadFile(const wxString& name, long type, int index = -1)
  452. {
  453. return LoadFile(name, (wxBitmapType)type, index);
  454. }
  455. )
  456. wxDEPRECATED(
  457. bool SaveFile(const wxString& name, long type) const
  458. {
  459. return SaveFile(name, (wxBitmapType)type);
  460. }
  461. )
  462. static wxDEPRECATED(
  463. wxImageHandler *FindHandler(const wxString& ext, long type)
  464. {
  465. return FindHandler(ext, (wxBitmapType)type);
  466. }
  467. )
  468. static wxDEPRECATED(
  469. wxImageHandler *FindHandler(long imageType)
  470. {
  471. return FindHandler((wxBitmapType)imageType);
  472. }
  473. )
  474. #endif // WXWIN_COMPATIBILITY_2_8
  475. protected:
  476. static wxList sm_handlers;
  477. // return the index of the point with the given coordinates or -1 if the
  478. // image is invalid of the coordinates are out of range
  479. //
  480. // note that index must be multiplied by 3 when using it with RGB array
  481. long XYToIndex(int x, int y) const;
  482. virtual wxObjectRefData* CreateRefData() const;
  483. virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const;
  484. private:
  485. friend class WXDLLIMPEXP_FWD_CORE wxImageHandler;
  486. // Possible values for MakeEmptyClone() flags.
  487. enum
  488. {
  489. // Create an image with the same orientation as this one. This is the
  490. // default and only exists for symmetry with SwapOrientation.
  491. Clone_SameOrientation = 0,
  492. // Create an image with the same height as this image width and the
  493. // same width as this image height.
  494. Clone_SwapOrientation = 1
  495. };
  496. // Returns a new blank image with the same dimensions (or with width and
  497. // height swapped if Clone_SwapOrientation flag is given), alpha, and mask
  498. // as this image itself. This is used by several functions creating
  499. // modified versions of this image.
  500. wxImage MakeEmptyClone(int flags = Clone_SameOrientation) const;
  501. #if wxUSE_STREAMS
  502. // read the image from the specified stream updating image type if
  503. // successful
  504. bool DoLoad(wxImageHandler& handler, wxInputStream& stream, int index);
  505. // write the image to the specified stream and also update the image type
  506. // if successful
  507. bool DoSave(wxImageHandler& handler, wxOutputStream& stream) const;
  508. #endif // wxUSE_STREAMS
  509. DECLARE_DYNAMIC_CLASS(wxImage)
  510. };
  511. extern void WXDLLIMPEXP_CORE wxInitAllImageHandlers();
  512. extern WXDLLIMPEXP_DATA_CORE(wxImage) wxNullImage;
  513. //-----------------------------------------------------------------------------
  514. // wxImage handlers
  515. //-----------------------------------------------------------------------------
  516. #include "wx/imagbmp.h"
  517. #include "wx/imagpng.h"
  518. #include "wx/imaggif.h"
  519. #include "wx/imagpcx.h"
  520. #include "wx/imagjpeg.h"
  521. #include "wx/imagtga.h"
  522. #include "wx/imagtiff.h"
  523. #include "wx/imagpnm.h"
  524. #include "wx/imagxpm.h"
  525. #include "wx/imagiff.h"
  526. #endif // wxUSE_IMAGE
  527. #endif
  528. // _WX_IMAGE_H_