Download | Plain Text | No Line Numbers


  1. /**
  2.  * @module cwindowsbitmap
  3.  * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
  4.  * @brief Implementation of CBitmap handling Windows Bitmaps.
  5.  * @date 17.04.2009
  6.  */
  7.  
  8. #ifndef CWINDOWSBITMAP_H
  9. #define CWINDOWSBITMAP_H
  10.  
  11. #include <stdint.h>
  12. #include "cbitmap.h"
  13.  
  14. /**
  15.  * @class CWindowsBitmap
  16.  * @brief Implementation of CBitmap handling Windows Bitmaps.
  17.  *
  18.  * On error CFile::FileError is thrown.
  19.  */
  20. class CWindowsBitmap : public CBitmap
  21. {
  22. public:
  23. /**
  24.   * @method CWindowsBitmap
  25.   * @brief Default ctor
  26.   * @param -
  27.   * @return -
  28.   * @globalvars none
  29.   * @exception none
  30.   * @conditions none
  31.   */
  32. CWindowsBitmap();
  33.  
  34. /**
  35.   * @method ~CWindowsBitmap
  36.   * @brief Default dtor
  37.   * @param -
  38.   * @return -
  39.   * @globalvars none
  40.   * @exception none
  41.   * @conditions none
  42.   */
  43. ~CWindowsBitmap()
  44. {}
  45.  
  46. /**
  47.   * @method read
  48.   * @brief Reads Windows Bitmap from filestream.
  49.   * On error an exception is thrown.
  50.   * @param in filestream to read data from
  51.   * @return -
  52.   * @globalvars none
  53.   * @exception CFile::FileError
  54.   * @exception bad_alloc
  55.   * @conditions none
  56.   */
  57. void read(std::ifstream& in);
  58.  
  59. /**
  60.   * @method write
  61.   * @brief Writes Windows Bitmap to filestream.
  62.   * @param out filestream to read data from
  63.   * @return -
  64.   * @globalvars none
  65.   * @exception FileError
  66.   * @exception bad_alloc
  67.   * @conditions none
  68.   */
  69. void write(std::ofstream& out);
  70.  
  71. #ifdef DEBUG
  72. /**
  73.   * @method dump
  74.   * @brief Dumps the Windows Bitmap file headers to ostream
  75.   * @param out output stream
  76.   * @return -
  77.   * @globalvars
  78.   * @exception
  79.   * @conditions
  80.   */
  81. void dump(std::ostream& out);
  82. #endif
  83.  
  84. /**
  85.   * @method getPixelDataSize
  86.   * @brief Return size of pixelbuffer
  87.   * @param -
  88.   * @return size of pixelbuffer
  89.   * @globalvars none
  90.   * @exception none
  91.   * @conditions none
  92.   */
  93. const uint32_t getPixelDataSize()
  94. {
  95. return m_infoheader.biSizeImage;
  96. }
  97.  
  98. /**
  99.   * @method getHeight
  100.   * @brief Return height of bitmap in pixel
  101.   * @param -
  102.   * @return height of bitmap in pixel
  103.   * @globalvars none
  104.   * @exception none
  105.   * @conditions none
  106.   */
  107. const uint32_t getHeight()
  108. {
  109. /* width and height can be negativ */
  110. return static_cast<uint32_t>(abs(m_infoheader.biHeight));
  111. }
  112.  
  113. /**
  114.   * @method getWidth
  115.   * @brief Return width of bitmap in pixel
  116.   * @param -
  117.   * @return width of bitmap in pixel
  118.   * @globalvars none
  119.   * @exception none
  120.   * @conditions none
  121.   */
  122. const uint32_t getWidth()
  123. {
  124. /* width and height can be negativ */
  125. return static_cast<uint32_t>(abs(m_infoheader.biWidth));
  126. }
  127.  
  128. /**
  129.   * @method isMirrored
  130.   * @brief Windows Bitmaps can be stored upside down
  131.   * @param -
  132.   * @return true if bitmap is stored upside down. false otherwise
  133.   * @globalvars none
  134.   * @exception none
  135.   * @conditions none
  136.   */
  137. const bool isMirrored()
  138. {
  139. /* if height is positive the y-coordinates are mirrored */
  140. return (m_infoheader.biHeight > 0) ? true : false;
  141. }
  142.  
  143. /**
  144.   * @method hasColorTable
  145.   * @brief Check if bitmap has a colortable
  146.   * (we don't support this yet for windows bitmaps)
  147.   * @param -
  148.   * @return true if bitmap has a colortable. false otherwise
  149.   * @globalvars none
  150.   * @exception none
  151.   * @conditions none
  152.   */
  153. const bool hasColorTable()
  154. {
  155. return false;
  156. }
  157.  
  158. protected:
  159. /**
  160.   * @brief Windows Bitmap File Header structure
  161.   */
  162. #pragma pack(push,1)
  163. typedef struct
  164. {
  165. /** the magic number used to identify the BMP file */
  166. uint8_t bfType[2];
  167. /** the size of the BMP file in bytes */
  168. uint32_t bfSize;
  169. /** reserved */
  170. uint32_t bfReserved;
  171. /** the offset of the byte where the bitmap data can be found */
  172. uint32_t bfOffBits;
  173. } BITMAP_FILEHEADER;
  174. #pragma pack(pop)
  175.  
  176. /**
  177.   * @brief Windows Bitmap Info Header structure
  178.   */
  179. #pragma pack(push,1)
  180. typedef struct
  181. {
  182. /** the size of this header (40 bytes) */
  183. uint32_t biSize;
  184. /** the bitmap width in pixels (signed integer) */
  185. int32_t biWidth;
  186. /** the bitmap height in pixels (signed integer) */
  187. int32_t biHeight;
  188. /** the number of color planes being used. Must be set to 1 */
  189. uint16_t biPlanes;
  190. /** the number of bits per pixel, which is the color depth of the image */
  191. uint16_t biBitCount;
  192. /** the compression method being used */
  193. uint32_t biCompression;
  194. /** the image size */
  195. uint32_t biSizeImage;
  196. /** the horizontal resolution of the image (pixel per meter) */
  197. int32_t biXPelsPerMeter;
  198. /** the vertical resolution of the image (pixel per meter) */
  199. int32_t biYPelsPerMeter;
  200. /** the number of colors in the color palette, or 0 to default to 2^n */
  201. uint32_t biClrUsed;
  202. /** the number of important colors used, or 0 when every color is
  203.   * important; generally ignored. */
  204. uint32_t biClrImportant;
  205. } BITMAP_INFOHEADER;
  206. #pragma pack(pop)
  207.  
  208. /* members */
  209. /** fileheader */
  210. BITMAP_FILEHEADER m_fileheader;
  211. /** infoheader */
  212. BITMAP_INFOHEADER m_infoheader;
  213. };
  214.  
  215. #endif
  216.  
  217. /* vim: set et sw=2 ts=2: */
  218.