summaryrefslogtreecommitdiffstats
path: root/ue2/imgsynth2/cwindowsbitmap.h
blob: 28ad0106fce275a228fda4529986a777a3f609ff (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/**
 * @module cwindowsbitmap
 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
 * @brief  Implementation of CBitmap handling Windows Bitmaps.
 * @date   17.04.2009
 */

#ifndef CWINDOWSBITMAP_H
#define CWINDOWSBITMAP_H

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

/**
 * @class CWindowsBitmap
 * @brief Implementation of CBitmap handling Windows Bitmaps.
 *
 * On error CFile::FileError is thrown.
 */
class CWindowsBitmap : public CBitmap
{
  public:
    /**
     * @method CWindowsBitmap
     * @brief  Default ctor
     * @param  -
     * @return -
     * @globalvars none
     * @exception  none
     * @conditions none
     */
    CWindowsBitmap();

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

    /**
     * @method read
     * @brief  Reads Windows Bitmap 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 Windows Bitmap to filestream.
     * @param  out      filestream to read data from
     * @param  filename filename (maybe useful for some handlers)
     * @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 Windows Bitmap file headers to ostream
     * @param  out output stream
     * @return -
     * @globalvars
     * @exception
     * @conditions
     */
    void dump(std::ostream& out);
#endif

    /**
     * @brief Windows Bitmap File Header structure
     */
#pragma pack(push,1)
    typedef struct
    {
      /** the magic number used to identify the BMP file */
      uint8_t  bfType[2];
      /** the size of the BMP file in bytes */
      uint32_t bfSize;
      /** reserved */
      uint32_t bfReserved;
      /** the offset of the byte where the bitmap data can be found */
      uint32_t bfOffBits;
    } BITMAP_FILEHEADER;
#pragma pack(pop)

    /**
     * @brief Windows Bitmap Info Header structure
     */
#pragma pack(push,1)
    typedef struct
    {
      /** the size of this header (40 bytes) */
      uint32_t biSize;
      /** the bitmap width in pixels (signed integer) */
      int32_t  biWidth;
      /** the bitmap height in pixels (signed integer) */
      int32_t  biHeight;
      /** the number of color planes being used. Must be set to 1 */
      uint16_t biPlanes;
      /** the number of bits per pixel, which is the color depth of the image */
      uint16_t biBitCount;
      /** the compression method being used */
      uint32_t biCompression;
      /** the image size */
      uint32_t biSizeImage;
      /** the horizontal resolution of the image (pixel per meter) */
      int32_t  biXPelsPerMeter;
      /** the vertical resolution of the image (pixel per meter) */
      int32_t  biYPelsPerMeter;
      /** the number of colors in the color palette, or 0 to default to 2^n */
      uint32_t biClrUsed;
      /** the number of important colors used, or 0 when every color is
       * important; generally ignored. */
      uint32_t biClrImportant;
    } BITMAP_INFOHEADER;
#pragma pack(pop)

    /**
     * @method getFileHeader
     * @brief  Returns reference to fileheader structure of bitmap
     * @param  -
     * @return reference to fileheader structure
     * @globalvars none
     * @exception  none
     * @conditions none
     */
    BITMAP_FILEHEADER &getFileHeader()
    {
      return m_fileheader;
    }

    /**
     * @method getInfoHeader
     * @brief  Returns reference to infoheader structure of bitmap
     * @param  -
     * @return reference to infoheader structure
     * @globalvars none
     * @exception  none
     * @conditions none
     */
    BITMAP_INFOHEADER &getInfoHeader()
    {
      return m_infoheader;
    }

    /* TODO */
    const uint32_t getPixelDataSize()
    {
      return m_infoheader.biSizeImage;
    }

    /* TODO */
    const uint32_t getHeight()
    {
      /* width and height can be negativ */
      return static_cast<uint32_t>(abs(m_infoheader.biHeight));
    }

    /* TODO */
    const uint32_t getWidth()
    {
      /* width and height can be negativ */
      return static_cast<uint32_t>(abs(m_infoheader.biWidth));
    }

    /* TODO */
    const bool isMirrored()
    {
      /* if height is positive the y-coordinates are mirrored */
      return (m_infoheader.biHeight > 0) ? true : false;
    }

  protected:
    /* members */
    /** fileheader */
    BITMAP_FILEHEADER m_fileheader;
    /** infoheader */
    BITMAP_INFOHEADER m_infoheader;
};

#endif

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