Download | Plain Text | No Line Numbers


  1. /**
  2.  * @module cbitmap
  3.  * @author Manuel Mausz, 0728348
  4.  * @brief Implementation of CFile handling Windows Bitmaps.
  5.  * @date 17.04.2009
  6.  */
  7.  
  8. #ifndef CBITMAP_H
  9. #define CBITMAP_H
  10.  
  11. #include "cfile.h"
  12.  
  13. class CPixelFormat;
  14. #include "cpixelformat.h"
  15.  
  16. /**
  17.  * @class CBitmap
  18.  * @brief Implementation of CFile handling Windows Bitmaps.
  19.  *
  20.  * In order to support operations on bitmaps with different color bitcounts
  21.  * different implementations of CPixelFormat are used. These classes are
  22.  * allowed to modify the bitmap headers and pixelbuffer directly.
  23.  *
  24.  * On error CFile::FileError is thrown.
  25.  */
  26. class CBitmap : public CFile
  27. {
  28. public:
  29. /**
  30.   * @method CBitmap
  31.   * @brief Default ctor
  32.   * @param -
  33.   * @return -
  34.   * @globalvars none
  35.   * @exception none
  36.   * @conditions none
  37.   */
  38. CBitmap()
  39. : m_pixeldata(NULL), m_pixelformat(NULL)
  40. {
  41. m_types.insert("BMP");
  42. }
  43.  
  44. /**
  45.   * @method ~CBitmap
  46.   * @brief Default dtor
  47.   * @param -
  48.   * @return -
  49.   * @globalvars none
  50.   * @exception none
  51.   * @conditions none
  52.   */
  53. ~CBitmap();
  54.  
  55. /**
  56.   * @method read
  57.   * @brief Reads Windows Bitmap from filestream.
  58.   * On error an exception is thrown.
  59.   * @param in filestream to read data from
  60.   * @return -
  61.   * @globalvars none
  62.   * @exception CFile::FileError
  63.   * @exception bad_alloc
  64.   * @conditions none
  65.   */
  66. void read(std::ifstream& in);
  67.  
  68. /**
  69.   * @method write
  70.   * @brief Writes Windows Bitmap to filestream.
  71.   * @param out filestream to read data from
  72.   * @return -
  73.   * @globalvars none
  74.   * @exception FileError
  75.   * @exception bad_alloc
  76.   * @conditions none
  77.   */
  78. void write(std::ofstream& out);
  79.  
  80. /**
  81.   * @method callFunc
  82.   * @brief Delegates the function and its parameters to the correct
  83.   * internal method
  84.   * @param func function name
  85.   * @param params function parameters as list
  86.   * @return -
  87.   * @globalvars none
  88.   * @exception ParserError
  89.   * @conditions none
  90.   */
  91. void callFunc(const std::string& func, const std::list<std::string>& params);
  92.  
  93. #ifdef DEBUG
  94. /**
  95.   * @method dump
  96.   * @brief Dumps the Windows Bitmap file headers to ostream
  97.   * @param out output stream
  98.   * @return -
  99.   * @globalvars
  100.   * @exception
  101.   * @conditions
  102.   */
  103. void dump(std::ostream& out);
  104. #endif
  105.  
  106. /**
  107.   * @brief Windows Bitmap File Header structure
  108.   */
  109. #pragma pack(push,1)
  110. typedef struct
  111. {
  112. /** the magic number used to identify the BMP file */
  113. uint8_t bfType[2];
  114. /** the size of the BMP file in bytes */
  115. uint32_t bfSize;
  116. /** reserved */
  117. uint32_t bfReserved;
  118. /** the offset of the byte where the bitmap data can be found */
  119. uint32_t bfOffBits;
  120. } BITMAP_FILEHEADER;
  121. #pragma pack(pop)
  122.  
  123. /**
  124.   * @brief Windows Bitmap Info Header structure
  125.   */
  126. #pragma pack(push,1)
  127. typedef struct
  128. {
  129. /** the size of this header (40 bytes) */
  130. uint32_t biSize;
  131. /** the bitmap width in pixels (signed integer) */
  132. int32_t biWidth;
  133. /** the bitmap height in pixels (signed integer) */
  134. int32_t biHeight;
  135. /** the number of color planes being used. Must be set to 1 */
  136. uint16_t biPlanes;
  137. /** the number of bits per pixel, which is the color depth of the image */
  138. uint16_t biBitCount;
  139. /** the compression method being used */
  140. uint32_t biCompression;
  141. /** the image size */
  142. uint32_t biSizeImage;
  143. /** the horizontal resolution of the image (pixel per meter) */
  144. int32_t biXPelsPerMeter;
  145. /** the vertical resolution of the image (pixel per meter) */
  146. int32_t biYPelsPerMeter;
  147. /** the number of colors in the color palette, or 0 to default to 2^n */
  148. uint32_t biClrUsed;
  149. /** the number of important colors used, or 0 when every color is
  150.   * important; generally ignored. */
  151. uint32_t biClrImportant;
  152. } BITMAP_INFOHEADER;
  153. #pragma pack(pop)
  154.  
  155. /**
  156.   * @method getFileHeader
  157.   * @brief Returns reference to fileheader structure of bitmap
  158.   * @param -
  159.   * @return reference to fileheader structure
  160.   * @globalvars none
  161.   * @exception none
  162.   * @conditions none
  163.   */
  164. BITMAP_FILEHEADER &getFileHeader()
  165. {
  166. return m_fileheader;
  167. }
  168.  
  169. /**
  170.   * @method getInfoHeader
  171.   * @brief Returns reference to infoheader structure of bitmap
  172.   * @param -
  173.   * @return reference to infoheader structure
  174.   * @globalvars none
  175.   * @exception none
  176.   * @conditions none
  177.   */
  178. BITMAP_INFOHEADER &getInfoHeader()
  179. {
  180. return m_infoheader;
  181. }
  182.  
  183. /**
  184.   * @method getPixelData
  185.   * @brief Returns pointer to pixelbuffer
  186.   * @param -
  187.   * @return pointer to pixelbuffer
  188.   * @globalvars none
  189.   * @exception none
  190.   * @conditions none
  191.   */
  192. uint8_t *getPixelData()
  193. {
  194. return m_pixeldata;
  195. }
  196.  
  197. protected:
  198. /**
  199.   * @method fillrect
  200.   * @brief Fills rectangle in image starting on position x, y
  201.   * width size width, height and color red, green, blue.
  202.   * @param params function parameters as list
  203.   * @return -
  204.   * @globalvars none
  205.   * @exception FileError
  206.   * @conditions none
  207.   *
  208.   * Scriptfile syntax: fillrect(x, y, width, height, red, green, blue)
  209.   */
  210. void fillrect(std::list<std::string> params);
  211.  
  212. /* members */
  213. /** fileheader */
  214. BITMAP_FILEHEADER m_fileheader;
  215. /** infoheader */
  216. BITMAP_INFOHEADER m_infoheader;
  217. /** pointer to pixelbuffer */
  218. uint8_t *m_pixeldata;
  219. /** pointer to CPixelFormat implementation */
  220. CPixelFormat *m_pixelformat;
  221. };
  222.  
  223. #endif
  224.  
  225. /* vim: set et sw=2 ts=2: */
  226.