summaryrefslogtreecommitdiffstats
path: root/ue2/imgsynth2/cpixmap.h
blob: eb219aaea61297224e4d6db2569f3b5101a6aa20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
 * @module CPixmap
 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
 * @brief  Implementation of CFile CBitmap handling XPM.
 * @date   27.04.2009
 */

#ifndef CPixmap_H
#define CPixmap_H

#include <stdint.h>
#include "cbitmap.h"

/**
 * @class CPixmap
 * @brief Implementation of CFile handling Pixmap file format.
 *
 * In order to support operations on pixmaps in color mode an 
 * implementations of CPixelFormat is used. These classe are
 * allowed to modify the pixmap header, pixelbuffer and color table directly.
 *
 * On error CFile::FileError is thrown.
 */
class CPixmap : public CBitmap
{
  public:
    /**
     * @method CPixmap
     * @brief  Default ctor
     * @param  -
     * @return -
     * @globalvars none
     * @exception  none
     * @conditions none
     */
    CPixmap();

    /**
     * @method ~CPixmap
     * @brief  Default dtor
     * @param  -
     * @return -
     * @globalvars none
     * @exception  none
     * @conditions none
     */
    ~CPixmap()
      {}

    /**
     * @method read
     * @brief  Reads Pixmap from filestream.
     *         On error an exception is thrown.
     * @param  in filestream to read data from
     * @return -
     * @globalvars none
     * @exception CFile::FileError
     * @exception bad_alloc
     * @conditions none
     */
    void read(std::ifstream& in);

    /**
     * @method write
     * @brief  Writes Pixmap to filestream.
     * @param  out filestream to read data from
     * @return -
     * @globalvars none
     * @exception  FileError
     * @exception  bad_alloc
     * @conditions none
     */
    void write(std::ofstream& out, std::string& filename);

#ifdef DEBUG
    /**
     * @method dump
     * @brief  Dumps the Pixmap file header and pixel data to ostream
     * @param  out output stream
     * @return -
     * @globalvars
     * @exception
     * @conditions
     */
    void dump(std::ostream& out);
#endif

    /**
     * @brief Pixmap Header structure
     */
#pragma pack(push,1)
    typedef struct
    {
     /** the xpm width in pixels (signed integer) */
      uint32_t  xpmWidth;
      /** the xpm height in pixels (signed integer) */
      uint32_t  xpmHeight;
      /** the number of colors (signed integer) */
      uint32_t  nColor;
      /** the number of characters per pixel (signed integer) */
      uint32_t  nChar;
      /** X-Position Hotspots */
      uint32_t xHotspot;
      /** Y-Position Hotspots */
      uint32_t yHotspot;
      /* is hotspot set */
      bool _HOTSPOT;
      /* XPMEXT extension tag found*/
      bool _XPMEXT;
      /* unchanged extension */
      std::string extension;
   } PIXMAP_FILEHEADER;
#pragma pack(pop)

    /* TODO */
    const uint32_t getPixelDataSize()
    {
      return m_fileheader.xpmWidth * m_fileheader.xpmHeight * m_fileheader.nChar;
    }

    /* TODO */
    const uint32_t getHeight()
    {
      /* width and height can be negativ */
      return m_fileheader.xpmHeight;
    }

    /* TODO */
    const uint32_t getWidth()
    {
      /* width and height can be negativ */
      return m_fileheader.xpmWidth;
    }

    /**
     * @method hasColorTable
     * @brief  Check if bitmap has a colortable
     *         (we don't support this yet for windows bitmaps)
     * @param  -
     * @return true if bitmap has a colortable. false otherwise
     * @globalvars none
     * @exception  none
     * @conditions none
     */
    const bool hasColorTable()
    {
      return true;
    }

    /* TODO */
    const bool isMirrored()
    {
      /* pixmap is never mirrored */
      return false;
    }

  protected:
    /* members */
    /** fileheader */
    PIXMAP_FILEHEADER m_fileheader;
    /** infoheader */
};

#endif

/* vim: set et sw=2 ts=2: */