Download | Plain Text | No Line Numbers


  1. /**
  2.  * @module cbitmap
  3.  * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
  4.  * @brief Abstract implementation of CFile handling Bitmaps.
  5.  * @date 17.04.2009
  6.  */
  7.  
  8. #ifndef CBITMAP_H
  9. #define CBITMAP_H
  10.  
  11. #include <stdint.h>
  12. #include <map>
  13. #include "cfile.h"
  14. #include "cpixelformat.h"
  15.  
  16. /**
  17.  * @class CBitmap
  18.  * @brief Implementation of CFile handling 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), m_rowsize(0)
  40. {}
  41.  
  42.  
  43. /**
  44.   * @method ~CBitmap
  45.   * @brief Default dtor
  46.   * @param -
  47.   * @return -
  48.   * @globalvars none
  49.   * @exception none
  50.   * @conditions none
  51.   */
  52. virtual ~CBitmap();
  53.  
  54. /**
  55.   * @method read
  56.   * @brief Reads Windows Bitmap from filestream.
  57.   * On error an exception is thrown.
  58.   * @param in filestream to read data from
  59.   * @return -
  60.   * @globalvars none
  61.   * @exception CFile::FileError
  62.   * @exception bad_alloc
  63.   * @conditions none
  64.   */
  65. virtual void read(std::ifstream& in) = 0;
  66.  
  67. /**
  68.   * @method write
  69.   * @brief Writes Windows Bitmap to filestream.
  70.   * @param out filestream to read data from
  71.   * @return -
  72.   * @globalvars none
  73.   * @exception FileError
  74.   * @exception bad_alloc
  75.   * @conditions none
  76.   */
  77. virtual void write(std::ofstream& out) = 0;
  78.  
  79. /**
  80.   * @method getPixelData
  81.   * @brief Returns pointer to pixelbuffer
  82.   * @param -
  83.   * @return pointer to pixelbuffer
  84.   * @globalvars none
  85.   * @exception none
  86.   * @conditions none
  87.   */
  88. uint8_t *getPixelData()
  89. {
  90. return m_pixeldata;
  91. }
  92.  
  93. /**
  94.   * @method getColorTable
  95.   * @brief Returns reference to colortable
  96.   * @param -
  97.   * @return reference to colortable
  98.   * @globalvars none
  99.   * @exception none
  100.   * @conditions none
  101.   */
  102. std::map<uint32_t, CPixelFormat::RGBPIXEL *>& getColorTable()
  103. {
  104. return m_colortable;
  105. }
  106.  
  107. /**
  108.   * @method getRowSize
  109.   * @brief Returns number of bytes of one row
  110.   * @param -
  111.   * @return number of bytes of one row
  112.   * @globalvars none
  113.   * @exception none
  114.   * @conditions none
  115.   */
  116. uint32_t getRowSize()
  117. {
  118. return m_rowsize;
  119. }
  120.  
  121. /**
  122.   * @method getPixelDataSize
  123.   * @brief Return size of pixelbuffer
  124.   * @param -
  125.   * @return size of pixelbuffer
  126.   * @globalvars none
  127.   * @exception none
  128.   * @conditions none
  129.   */
  130. virtual const uint32_t getPixelDataSize() = 0;
  131.  
  132. /**
  133.   * @method getHeight
  134.   * @brief Return height of bitmap in pixel
  135.   * @param -
  136.   * @return height of bitmap in pixel
  137.   * @globalvars none
  138.   * @exception none
  139.   * @conditions none
  140.   */
  141. virtual const uint32_t getHeight() = 0;
  142.  
  143. /**
  144.   * @method getWidth
  145.   * @brief Return width of bitmap in pixel
  146.   * @param -
  147.   * @return width of bitmap in pixel
  148.   * @globalvars none
  149.   * @exception none
  150.   * @conditions none
  151.   */
  152. virtual const uint32_t getWidth() = 0;
  153.  
  154. /**
  155.   * @method isMirrored
  156.   * @brief Windows Bitmaps can be stored upside down
  157.   * @param -
  158.   * @return true if bitmap is stored upside down. false otherwise
  159.   * @globalvars none
  160.   * @exception none
  161.   * @conditions none
  162.   */
  163. virtual const bool isMirrored() = 0;
  164.  
  165. /**
  166.   * @method hasColorTable
  167.   * @brief Check if bitmap has a colortable
  168.   * (we don't support this yet for windows bitmaps)
  169.   * @param -
  170.   * @return true if bitmap has a colortable. false otherwise
  171.   * @globalvars none
  172.   * @exception none
  173.   * @conditions none
  174.   */
  175. virtual const bool hasColorTable() = 0;
  176.  
  177. protected:
  178. /**
  179.   * @method callFunc
  180.   * @brief Delegates the function and its parameters to the correct
  181.   * internal method
  182.   * @param func function name
  183.   * @param params function parameters as list
  184.   * @return -
  185.   * @globalvars none
  186.   * @exception ParserError
  187.   * @conditions none
  188.   */
  189. void callFunc(const std::string& func, const std::list<std::string>& params);
  190.  
  191. /**
  192.   * @method fillrect
  193.   * @brief Fills rectangle in image starting on position x, y
  194.   * width size width, height and color red, green, blue.
  195.   * @param params function parameters as list
  196.   * @return -
  197.   * @globalvars none
  198.   * @exception FileError
  199.   * @conditions none
  200.   *
  201.   * Scriptfile syntax: fillrect(x, y, width, height, red, green, blue)
  202.   */
  203. void fillrect(std::list<std::string> params);
  204.  
  205. /**
  206.   * @method invert
  207.   * @brief Invert image
  208.   * @param params function parameters as list
  209.   * @return -
  210.   * @globalvars none
  211.   * @exception FileError
  212.   * @conditions none
  213.   *
  214.   * Scriptfile syntax: invert()
  215.   */
  216. void invert(std::list<std::string> params);
  217.  
  218. /**
  219.   * @method brightness
  220.   * @brief Increase/decrease brightness of image
  221.   * @param params function parameters as list
  222.   * @return -
  223.   * @globalvars none
  224.   * @exception FileError
  225.   * @conditions none
  226.   *
  227.   * Scriptfile syntax: brightness(factor)
  228.   */
  229. void brightness(std::list<std::string> params);
  230.  
  231. /**
  232.   * @method mirror_y
  233.   * @brief Mirror image around the y-axis
  234.   * @param params function parameters as list
  235.   * @return -
  236.   * @globalvars none
  237.   * @exception FileError
  238.   * @conditions none
  239.   *
  240.   * Scriptfile syntax: mirror_y()
  241.   */
  242. void mirror_y(std::list<std::string> params);
  243.  
  244. /**
  245.   * @method mirror_x
  246.   * @brief Mirror image around the x-axis
  247.   * @param params function parameters as list
  248.   * @return -
  249.   * @globalvars none
  250.   * @exception FileError
  251.   * @conditions none
  252.   *
  253.   * Scriptfile syntax: mirror_y()
  254.   */
  255. void mirror_x(std::list<std::string> params);
  256.  
  257. /* members */
  258. /** pointer to pixelbuffer */
  259. uint8_t *m_pixeldata;
  260. /** colortable map */
  261. std::map<uint32_t, CPixelFormat::RGBPIXEL *> m_colortable;
  262. /** set of supported PixelFormat handlers */
  263. std::set<CPixelFormat *> m_handlers;
  264. /** pointer to CPixelFormat implementation */
  265. CPixelFormat *m_pixelformat;
  266. /** number of bytes of one row in the image */
  267. uint32_t m_rowsize;
  268. };
  269.  
  270. #endif
  271.  
  272. /* vim: set et sw=2 ts=2: */
  273.