imagbmp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/imagbmp.h
  3. // Purpose: wxImage BMP, ICO, CUR and ANI handlers
  4. // Author: Robert Roebling, Chris Elliott
  5. // Copyright: (c) Robert Roebling, Chris Elliott
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. #ifndef _WX_IMAGBMP_H_
  9. #define _WX_IMAGBMP_H_
  10. #include "wx/image.h"
  11. // defines for saving the BMP file in different formats, Bits Per Pixel
  12. // USE: wximage.SetOption( wxIMAGE_OPTION_BMP_FORMAT, wxBMP_xBPP );
  13. #define wxIMAGE_OPTION_BMP_FORMAT wxString(wxT("wxBMP_FORMAT"))
  14. // These two options are filled in upon reading CUR file and can (should) be
  15. // specified when saving a CUR file - they define the hotspot of the cursor:
  16. #define wxIMAGE_OPTION_CUR_HOTSPOT_X wxT("HotSpotX")
  17. #define wxIMAGE_OPTION_CUR_HOTSPOT_Y wxT("HotSpotY")
  18. enum
  19. {
  20. wxBMP_24BPP = 24, // default, do not need to set
  21. //wxBMP_16BPP = 16, // wxQuantize can only do 236 colors?
  22. wxBMP_8BPP = 8, // 8bpp, quantized colors
  23. wxBMP_8BPP_GREY = 9, // 8bpp, rgb averaged to greys
  24. wxBMP_8BPP_GRAY = wxBMP_8BPP_GREY,
  25. wxBMP_8BPP_RED = 10, // 8bpp, red used as greyscale
  26. wxBMP_8BPP_PALETTE = 11, // 8bpp, use the wxImage's palette
  27. wxBMP_4BPP = 4, // 4bpp, quantized colors
  28. wxBMP_1BPP = 1, // 1bpp, quantized "colors"
  29. wxBMP_1BPP_BW = 2 // 1bpp, black & white from red
  30. };
  31. // ----------------------------------------------------------------------------
  32. // wxBMPHandler
  33. // ----------------------------------------------------------------------------
  34. class WXDLLIMPEXP_CORE wxBMPHandler : public wxImageHandler
  35. {
  36. public:
  37. wxBMPHandler()
  38. {
  39. m_name = wxT("Windows bitmap file");
  40. m_extension = wxT("bmp");
  41. m_type = wxBITMAP_TYPE_BMP;
  42. m_mime = wxT("image/x-bmp");
  43. }
  44. #if wxUSE_STREAMS
  45. virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
  46. virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
  47. protected:
  48. virtual bool DoCanRead( wxInputStream& stream );
  49. bool SaveDib(wxImage *image, wxOutputStream& stream, bool verbose,
  50. bool IsBmp, bool IsMask);
  51. bool DoLoadDib(wxImage *image, int width, int height, int bpp, int ncolors,
  52. int comp, wxFileOffset bmpOffset, wxInputStream& stream,
  53. bool verbose, bool IsBmp, bool hasPalette);
  54. bool LoadDib(wxImage *image, wxInputStream& stream, bool verbose, bool IsBmp);
  55. #endif // wxUSE_STREAMS
  56. private:
  57. DECLARE_DYNAMIC_CLASS(wxBMPHandler)
  58. };
  59. #if wxUSE_ICO_CUR
  60. // ----------------------------------------------------------------------------
  61. // wxICOHandler
  62. // ----------------------------------------------------------------------------
  63. class WXDLLIMPEXP_CORE wxICOHandler : public wxBMPHandler
  64. {
  65. public:
  66. wxICOHandler()
  67. {
  68. m_name = wxT("Windows icon file");
  69. m_extension = wxT("ico");
  70. m_type = wxBITMAP_TYPE_ICO;
  71. m_mime = wxT("image/x-ico");
  72. }
  73. #if wxUSE_STREAMS
  74. virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=true );
  75. virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
  76. virtual bool DoLoadFile( wxImage *image, wxInputStream& stream, bool verbose, int index );
  77. protected:
  78. virtual int DoGetImageCount( wxInputStream& stream );
  79. virtual bool DoCanRead( wxInputStream& stream );
  80. #endif // wxUSE_STREAMS
  81. private:
  82. DECLARE_DYNAMIC_CLASS(wxICOHandler)
  83. };
  84. // ----------------------------------------------------------------------------
  85. // wxCURHandler
  86. // ----------------------------------------------------------------------------
  87. class WXDLLIMPEXP_CORE wxCURHandler : public wxICOHandler
  88. {
  89. public:
  90. wxCURHandler()
  91. {
  92. m_name = wxT("Windows cursor file");
  93. m_extension = wxT("cur");
  94. m_type = wxBITMAP_TYPE_CUR;
  95. m_mime = wxT("image/x-cur");
  96. }
  97. // VS: This handler's meat is implemented inside wxICOHandler (the two
  98. // formats are almost identical), but we hide this fact at
  99. // the API level, since it is a mere implementation detail.
  100. protected:
  101. #if wxUSE_STREAMS
  102. virtual bool DoCanRead( wxInputStream& stream );
  103. #endif // wxUSE_STREAMS
  104. private:
  105. DECLARE_DYNAMIC_CLASS(wxCURHandler)
  106. };
  107. // ----------------------------------------------------------------------------
  108. // wxANIHandler
  109. // ----------------------------------------------------------------------------
  110. class WXDLLIMPEXP_CORE wxANIHandler : public wxCURHandler
  111. {
  112. public:
  113. wxANIHandler()
  114. {
  115. m_name = wxT("Windows animated cursor file");
  116. m_extension = wxT("ani");
  117. m_type = wxBITMAP_TYPE_ANI;
  118. m_mime = wxT("image/x-ani");
  119. }
  120. #if wxUSE_STREAMS
  121. virtual bool SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(stream), bool WXUNUSED(verbose=true) ){return false ;}
  122. virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1 );
  123. protected:
  124. virtual int DoGetImageCount( wxInputStream& stream );
  125. virtual bool DoCanRead( wxInputStream& stream );
  126. #endif // wxUSE_STREAMS
  127. private:
  128. DECLARE_DYNAMIC_CLASS(wxANIHandler)
  129. };
  130. #endif // wxUSE_ICO_CUR
  131. #endif // _WX_IMAGBMP_H_