Download | Plain Text | No Line Numbers


  1. /**
  2.  * @module CPixmap
  3.  * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
  4.  * @brief Implementation of CFile CBitmap handling XPM.
  5.  * @date 27.04.2009
  6.  */
  7.  
  8. #ifndef CPixmap_H
  9. #define CPixmap_H
  10.  
  11. #include <stdint.h>
  12. #include "cbitmap.h"
  13.  
  14. #define PIXMAP_IDENTIFIER "/* XPM */"
  15. #define PIXMAP_COLORCHARS ".#abcdefghijklmnopqrstuvwxyzABCD" \
  16.   "EFGHIJKLMNOPQRSTUVWXYZ0123456789"
  17.  
  18. /**
  19.  * @class CPixmap
  20.  * @brief Implementation of CFile handling Pixmap file format.
  21.  *
  22.  * In order to support operations on pixmaps in color mode an
  23.  * implementations of CPixelFormat is used. These classe are
  24.  * allowed to modify the pixmap header, pixelbuffer and color table directly.
  25.  *
  26.  * On error CFile::FileError is thrown.
  27.  */
  28. class CPixmap : public CBitmap
  29. {
  30. public:
  31. /**
  32.   * @method CPixmap
  33.   * @brief Default ctor
  34.   * @param -
  35.   * @return -
  36.   * @globalvars none
  37.   * @exception none
  38.   * @conditions none
  39.   */
  40. CPixmap();
  41.  
  42. /**
  43.   * @method ~CPixmap
  44.   * @brief Default dtor
  45.   * @param -
  46.   * @return -
  47.   * @globalvars none
  48.   * @exception none
  49.   * @conditions none
  50.   */
  51. ~CPixmap()
  52. {}
  53.  
  54. /**
  55.   * @method read
  56.   * @brief Reads Pixmap 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. void read(std::ifstream& in);
  66.  
  67. /**
  68.   * @method write
  69.   * @brief Writes Pixmap 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. void write(std::ofstream& out);
  78.  
  79. #ifdef DEBUG
  80. /**
  81.   * @method dump
  82.   * @brief Dumps the Pixmap file header and pixel data to ostream
  83.   * @param out output stream
  84.   * @return -
  85.   * @globalvars
  86.   * @exception
  87.   * @conditions
  88.   */
  89. void dump(std::ostream& out);
  90. #endif
  91.  
  92. /**
  93.   * @method getPixelDataSize
  94.   * @brief Return size of pixelbuffer
  95.   * @param -
  96.   * @return size of pixelbuffer
  97.   * @globalvars none
  98.   * @exception none
  99.   * @conditions none
  100.   */
  101. const uint32_t getPixelDataSize()
  102. {
  103. return m_fileheader.width * m_fileheader.height * sizeof(uint32_t);
  104. }
  105.  
  106. /**
  107.   * @method getHeight
  108.   * @brief Return height of bitmap in pixel
  109.   * @param -
  110.   * @return height of bitmap in pixel
  111.   * @globalvars none
  112.   * @exception none
  113.   * @conditions none
  114.   */
  115. const uint32_t getHeight()
  116. {
  117. return m_fileheader.height;
  118. }
  119.  
  120. /**
  121.   * @method getWidth
  122.   * @brief Return width of bitmap in pixel
  123.   * @param -
  124.   * @return width of bitmap in pixel
  125.   * @globalvars none
  126.   * @exception none
  127.   * @conditions none
  128.   */
  129. const uint32_t getWidth()
  130. {
  131. return m_fileheader.width;
  132. }
  133.  
  134. /**
  135.   * @method hasColorTable
  136.   * @brief Check if bitmap has a colortable
  137.   * (we don't support this yet for windows bitmaps)
  138.   * @param -
  139.   * @return true if bitmap has a colortable. false otherwise
  140.   * @globalvars none
  141.   * @exception none
  142.   * @conditions none
  143.   */
  144. const bool hasColorTable()
  145. {
  146. return true;
  147. }
  148.  
  149. /**
  150.   * @method isMirrored
  151.   * @brief Windows Bitmaps can be stored upside down
  152.   * @param -
  153.   * @return true if bitmap is stored upside down. false otherwise
  154.   * @globalvars none
  155.   * @exception none
  156.   * @conditions none
  157.   */
  158. const bool isMirrored()
  159. {
  160. /* pixmap is never mirrored */
  161. return false;
  162. }
  163.  
  164. protected:
  165. /**
  166.   * @method getLine
  167.   * @brief read trimmed line (terminated by \n) from filestream
  168.   * @param in filestream to read data from
  169.   * @param ignore_comments true: ignore c-like comments
  170.   * @return return trimmed line from filestream
  171.   * @globalvars none
  172.   * @exception none
  173.   * @conditions none
  174.   */
  175. std::string getLine(std::ifstream& in, bool ignore_comments = true);
  176.  
  177. /**
  178.   * @method getArrayLine
  179.   * @brief read trimmed c-arrayline from filestream
  180.   * @param in filestream to read data from
  181.   * @return return trimmed c-arrayline from filestream
  182.   * @globalvars none
  183.   * @exception FileError
  184.   * @conditions none
  185.   */
  186. std::string getCArrayLine(std::ifstream& in);
  187.  
  188. /**
  189.   * @method getXPMColorID
  190.   * @brief get xpm color identifier, generated using an index
  191.   * @param index index used to generate the xpm color identifier
  192.   * @param length length of xpm color identifier
  193.   * @return return xpm color identifier, generated using index
  194.   * @globalvars none
  195.   * @exception FileError
  196.   * @conditions none
  197.   */
  198. const std::string getXPMColorID(unsigned int index, unsigned int length);
  199.  
  200. /**
  201.   * @brief Pixmap Header structure
  202.   */
  203. typedef struct
  204. {
  205. /** the xpm width in pixels (signed integer) */
  206. uint32_t width;
  207. /** the xpm height in pixels (signed integer) */
  208. uint32_t height;
  209. /** the number of colors (signed integer) */
  210. uint32_t nColor;
  211. /** the number of characters per pixel (signed integer) */
  212. uint32_t nChar;
  213. /** X-Position Hotspots */
  214. uint32_t xHotspot;
  215. /** Y-Position Hotspots */
  216. uint32_t yHotspot;
  217. /** is hotspot set */
  218. bool _HOTSPOT;
  219. /** XPMEXT extension tag found*/
  220. bool _XPMEXT;
  221. /** unchanged extension */
  222. std::string extension;
  223. } PIXMAP_FILEHEADER;
  224.  
  225. /* members */
  226. /** fileheader */
  227. PIXMAP_FILEHEADER m_fileheader;
  228. /** name of image/c-array */
  229. std::string m_imagename;
  230. };
  231.  
  232. #endif
  233.  
  234. /* vim: set et sw=2 ts=2: */
  235.