summaryrefslogtreecommitdiffstats
path: root/ue2
diff options
context:
space:
mode:
Diffstat (limited to 'ue2')
-rw-r--r--ue2/imgsynth2/cbitmap.cpp151
-rw-r--r--ue2/imgsynth2/cbitmap.h130
-rw-r--r--ue2/imgsynth2/cpixelformat.h43
-rw-r--r--ue2/imgsynth2/cpixelformat_bgr24.cpp37
-rw-r--r--ue2/imgsynth2/cpixelformat_bgr24.h33
-rw-r--r--ue2/imgsynth2/cpixelformat_bgr555.cpp43
-rw-r--r--ue2/imgsynth2/cpixelformat_bgr555.h35
-rw-r--r--ue2/imgsynth2/cwindowsbitmap.h55
-rw-r--r--ue2/imgsynth2/test/input_yellow_man2_rgb244
-rw-r--r--ue2/imgsynth2/test/input_yellow_man2_rgb5556
-rw-r--r--ue2/imgsynth2/test/yellow_man1_rgb24_out.bmpbin530 -> 0 bytes
-rw-r--r--ue2/imgsynth2/test/yellow_man1_rgb555_out.bmpbin394 -> 0 bytes
-rw-r--r--ue2/imgsynth2/test/yellow_man2_rgb24_out.bmpbin530 -> 0 bytes
-rw-r--r--ue2/imgsynth2/test/yellow_man2_rgb555_out.bmpbin394 -> 0 bytes
14 files changed, 405 insertions, 132 deletions
diff --git a/ue2/imgsynth2/cbitmap.cpp b/ue2/imgsynth2/cbitmap.cpp
index b9cfc62..a064130 100644
--- a/ue2/imgsynth2/cbitmap.cpp
+++ b/ue2/imgsynth2/cbitmap.cpp
@@ -5,6 +5,7 @@
5 * @date 17.04.2009 5 * @date 17.04.2009
6 */ 6 */
7 7
8#include <algorithm>
8#include <boost/lexical_cast.hpp> 9#include <boost/lexical_cast.hpp>
9#include <boost/numeric/conversion/cast.hpp> 10#include <boost/numeric/conversion/cast.hpp>
10#include "cbitmap.h" 11#include "cbitmap.h"
@@ -25,6 +26,11 @@ CBitmap::~CBitmap()
25 for (it = m_handlers.begin(); it != m_handlers.end(); it++) 26 for (it = m_handlers.begin(); it != m_handlers.end(); it++)
26 delete *it; 27 delete *it;
27 m_pixelformat = NULL; 28 m_pixelformat = NULL;
29
30 /* delete colortable content */
31 map<string, CPixelFormat::RGBPIXEL *>::iterator it2;
32 for (it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++)
33 delete (*it2).second;
28} 34}
29 35
30/*----------------------------------------------------------------------------*/ 36/*----------------------------------------------------------------------------*/
@@ -36,6 +42,8 @@ void CBitmap::callFunc(const std::string& func, const std::list<std::string>& pa
36 42
37 if (func == "fillrect") 43 if (func == "fillrect")
38 fillrect(params); 44 fillrect(params);
45 else if (func == "brightness")
46 brightness(params);
39 else if (func == "mirror_x") 47 else if (func == "mirror_x")
40 mirror_x(params); 48 mirror_x(params);
41 else if (func == "mirror_y") 49 else if (func == "mirror_y")
@@ -80,17 +88,22 @@ void CBitmap::fillrect(std::list<std::string> params)
80 throw FileError("At least one x/y-parameter is out of range."); 88 throw FileError("At least one x/y-parameter is out of range.");
81 89
82 /* check parameter values are in range */ 90 /* check parameter values are in range */
83 unsigned int max[3]; 91 CPixelFormat::RGBPIXEL pixel;
84 m_pixelformat->getMaxColor(&max[0], &max[1], &max[2]); 92 m_pixelformat->getMaxColor(pixel);
85 if (pparams[4] < 0 || pparams[4] > max[0] 93 if (pparams[4] < 0 || pparams[4] > pixel.red
86 || pparams[5] < 0 || pparams[5] > max[1] 94 || pparams[5] < 0 || pparams[5] > pixel.green
87 || pparams[6] < 0 || pparams[6] > max[2]) 95 || pparams[6] < 0 || pparams[6] > pixel.blue)
88 throw FileError("At least one pixel color parameter is out of range."); 96 throw FileError("At least one pixel color parameter is out of range.");
89 97
90 if (pparams[2] < 0 || pparams[2] + pparams[0] > getWidth() 98 if (pparams[2] < 0 || pparams[2] + pparams[0] > getWidth()
91 || pparams[3] < 0 || pparams[3] + pparams[1] > getHeight()) 99 || pparams[3] < 0 || pparams[3] + pparams[1] > getHeight())
92 throw FileError("At least one w/h-parameter is out of range."); 100 throw FileError("At least one w/h-parameter is out of range.");
93 101
102 /* new pixel data */
103 pixel.red = pparams[4];
104 pixel.green = pparams[5];
105 pixel.blue = pparams[6];
106
94 /* call setPixel for every pixel in the rectangel */ 107 /* call setPixel for every pixel in the rectangel */
95 for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++) 108 for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++)
96 { 109 {
@@ -98,7 +111,7 @@ void CBitmap::fillrect(std::list<std::string> params)
98 { 111 {
99 try 112 try
100 { 113 {
101 m_pixelformat->setPixel(&pparams[4], i, j); 114 m_pixelformat->setPixel(pixel, i, j);
102 } 115 }
103 catch(CPixelFormat::PixelFormatError& ex) 116 catch(CPixelFormat::PixelFormatError& ex)
104 { 117 {
@@ -114,7 +127,6 @@ void CBitmap::fillrect(std::list<std::string> params)
114 127
115/*----------------------------------------------------------------------------*/ 128/*----------------------------------------------------------------------------*/
116 129
117/* TODO */
118void CBitmap::invert(std::list<std::string> params) 130void CBitmap::invert(std::list<std::string> params)
119{ 131{
120 /* check prerequirements */ 132 /* check prerequirements */
@@ -125,49 +137,114 @@ void CBitmap::invert(std::list<std::string> params)
125 if (m_pixeldata == NULL || m_pixelformat == NULL) 137 if (m_pixeldata == NULL || m_pixelformat == NULL)
126 return; 138 return;
127 139
128 /* TODO pixelwidth */ 140 CPixelFormat::RGBPIXEL pixel;
129 unsigned int pixelwidth = m_pixelformat->getBitCount()/8; 141 CPixelFormat::RGBPIXEL max;
130 142 m_pixelformat->getMaxColor(max);
131 /* calc rowsize - boundary is 32 */ 143 if (hasColorTable())
132 uint32_t rowsize = 4 * static_cast<uint32_t>(
133 ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32
134 );
135
136 for(uint32_t i = 0; i < getHeight(); i++)
137 { 144 {
138 for(uint32_t j = 0; j <= getWidth(); j++) 145 /* invert every entry in the colortable */
146 map<string, CPixelFormat::RGBPIXEL *>::iterator it;
147 for (it = m_colortable.begin(); it != m_colortable.end(); it++)
139 { 148 {
140 /*TODO cout << j << endl;*/ 149 (*it).second->red = max.red - (*it).second->red;
141 break; 150 (*it).second->green = max.green - (*it).second->green;
151 (*it).second->blue = max.blue - (*it).second->blue;
142 } 152 }
143 } 153 }
144 154 else
145#if 0 155 {
146 uint32_t offset = i * rowsize; 156 /* invert per pixel */
147 157 for(uint32_t y = 0; y < getHeight(); y++)
148 for(uint32_t j = 0; j <= getWidth()/2; j++)
149 { 158 {
150 uint32_t poffset = offset + j * pixelwidth; 159 for(uint32_t x = 0; x < getWidth(); x++)
151 uint32_t pbackset = offset + getWidth() * pixelwidth - j * pixelwidth; 160 {
152 161 try
153 /* boundary check */ 162 {
154 if (pbackset > m_infoheader.biSizeImage) 163 m_pixelformat->getPixel(pixel, x, y);
155 throw FileError("Mirrored pixel position is out of range."); 164 pixel.red = max.red - pixel.red;
156 165 pixel.green = max.green - pixel.green;
157 /* mirroring, backup right data first */ 166 pixel.blue = max.blue - pixel.blue;
158 copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf); 167 m_pixelformat->setPixel(pixel, x, y);
159 copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth); 168 }
160 copy(buf, buf + pixelwidth, m_pixeldata + poffset); 169 catch(CPixelFormat::PixelFormatError& ex)
170 {
171 stringstream errstr;
172 errstr << "Can't invert pixel (pos=[" << x << "," << y << "]): "
173 << ex.what();
174 throw FileError(errstr.str());
175 }
176 }
161 } 177 }
162 } 178 }
163#endif
164} 179}
165 180
166/*----------------------------------------------------------------------------*/ 181/*----------------------------------------------------------------------------*/
167 182
168/* TODO */
169void CBitmap::brightness(std::list<std::string> params) 183void CBitmap::brightness(std::list<std::string> params)
170{ 184{
185 /* check prerequirements */
186 if (params.size() != 1)
187 throw FileError("Invalid number of function parameters (must be 1).");
188
189 /* do nothing if no pixel exists */
190 if (m_pixeldata == NULL || m_pixelformat == NULL)
191 return;
192
193 /* convert parameters */
194 float factor;
195 try
196 {
197 factor = boost::lexical_cast<float>(params.front());
198 params.pop_front();
199 }
200 catch(boost::bad_lexical_cast& ex)
201 {
202 throw FileError("Invalid parameter (" + params.front() + ").");
203 }
204
205 /* negative factor doesn't make sense */
206 if (factor < 0)
207 throw FileError("Brightness parameter must be positive.");
208
209 CPixelFormat::RGBPIXEL pixel;
210 CPixelFormat::RGBPIXEL max;
211 m_pixelformat->getMaxColor(max);
212 if (hasColorTable())
213 {
214 /* invert every entry in the colortable */
215 map<string, CPixelFormat::RGBPIXEL *>::iterator it;
216 for (it = m_colortable.begin(); it != m_colortable.end(); it++)
217 {
218 (*it).second->red = min(max.red, static_cast<uint32_t>((*it).second->red * factor));
219 (*it).second->green = min(max.green, static_cast<uint32_t>((*it).second->green * factor));
220 (*it).second->blue = min(max.blue, static_cast<uint32_t>((*it).second->blue * factor));
221 }
222 }
223 else
224 {
225 /* invert per pixel */
226 for(uint32_t y = 0; y < getHeight(); y++)
227 {
228 for(uint32_t x = 0; x < getWidth(); x++)
229 {
230 try
231 {
232 m_pixelformat->getPixel(pixel, x, y);
233 pixel.red = min(max.red, static_cast<uint32_t>(pixel.red * factor));
234 pixel.green = min(max.green, static_cast<uint32_t>(pixel.green * factor));
235 pixel.blue = min(max.blue, static_cast<uint32_t>(pixel.blue * factor));
236 m_pixelformat->setPixel(pixel, x, y);
237 }
238 catch(CPixelFormat::PixelFormatError& ex)
239 {
240 stringstream errstr;
241 errstr << "Can't invert pixel (pos=[" << x << "," << y << "]): "
242 << ex.what();
243 throw FileError(errstr.str());
244 }
245 }
246 }
247 }
171} 248}
172 249
173/*----------------------------------------------------------------------------*/ 250/*----------------------------------------------------------------------------*/
diff --git a/ue2/imgsynth2/cbitmap.h b/ue2/imgsynth2/cbitmap.h
index f8f8850..df7dc84 100644
--- a/ue2/imgsynth2/cbitmap.h
+++ b/ue2/imgsynth2/cbitmap.h
@@ -9,9 +9,8 @@
9#define CBITMAP_H 9#define CBITMAP_H
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include <map>
12#include "cfile.h" 13#include "cfile.h"
13
14class CPixelFormat;
15#include "cpixelformat.h" 14#include "cpixelformat.h"
16 15
17/** 16/**
@@ -53,12 +52,28 @@ class CBitmap : public CFile
53 virtual ~CBitmap(); 52 virtual ~CBitmap();
54 53
55 /** 54 /**
56 * TODO 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
57 */ 64 */
58 virtual void read(std::ifstream& in) = 0; 65 virtual void read(std::ifstream& in) = 0;
59 66
60 /** 67 /**
61 * TODO 68 * @method write
69 * @brief Writes Windows Bitmap to filestream.
70 * @param out filestream to read data from
71 * @param filename filename (maybe useful for some handlers)
72 * @return -
73 * @globalvars none
74 * @exception FileError
75 * @exception bad_alloc
76 * @conditions none
62 */ 77 */
63 virtual void write(std::ofstream& out, std::string& filename) = 0; 78 virtual void write(std::ofstream& out, std::string& filename) = 0;
64 79
@@ -76,15 +91,62 @@ class CBitmap : public CFile
76 return m_pixeldata; 91 return m_pixeldata;
77 } 92 }
78 93
79 /* TODO */ 94 /**
95 * @method getPixelDataSize
96 * @brief Return size of pixelbuffer
97 * @param -
98 * @return size of pixelbuffer
99 * @globalvars none
100 * @exception none
101 * @conditions none
102 */
80 virtual const uint32_t getPixelDataSize() = 0; 103 virtual const uint32_t getPixelDataSize() = 0;
81 /* TODO */ 104
105 /**
106 * @method getHeight
107 * @brief Return height of bitmap in pixel
108 * @param -
109 * @return height of bitmap in pixel
110 * @globalvars none
111 * @exception none
112 * @conditions none
113 */
82 virtual const uint32_t getHeight() = 0; 114 virtual const uint32_t getHeight() = 0;
83 /* TODO */ 115
116 /**
117 * @method getWidth
118 * @brief Return width of bitmap in pixel
119 * @param -
120 * @return width of bitmap in pixel
121 * @globalvars none
122 * @exception none
123 * @conditions none
124 */
84 virtual const uint32_t getWidth() = 0; 125 virtual const uint32_t getWidth() = 0;
85 /* TODO */ 126
127 /**
128 * @method isMirrored
129 * @brief Windows Bitmaps can be stored upside down
130 * @param -
131 * @return true if bitmap is stored upside down. false otherwise
132 * @globalvars none
133 * @exception none
134 * @conditions none
135 */
86 virtual const bool isMirrored() = 0; 136 virtual const bool isMirrored() = 0;
87 137
138 /**
139 * @method hasColorTable
140 * @brief Check if bitmap has a colortable
141 * (we don't support this yet for windows bitmaps)
142 * @param -
143 * @return true if bitmap has a colortable. false otherwise
144 * @globalvars none
145 * @exception none
146 * @conditions none
147 */
148 virtual const bool hasColorTable() = 0;
149
88 protected: 150 protected:
89 /** 151 /**
90 * @method callFunc 152 * @method callFunc
@@ -99,7 +161,7 @@ class CBitmap : public CFile
99 */ 161 */
100 void callFunc(const std::string& func, const std::list<std::string>& params); 162 void callFunc(const std::string& func, const std::list<std::string>& params);
101 163
102 /** 164 /**
103 * @method fillrect 165 * @method fillrect
104 * @brief Fills rectangle in image starting on position x, y 166 * @brief Fills rectangle in image starting on position x, y
105 * width size width, height and color red, green, blue. 167 * width size width, height and color red, green, blue.
@@ -113,21 +175,63 @@ class CBitmap : public CFile
113 */ 175 */
114 void fillrect(std::list<std::string> params); 176 void fillrect(std::list<std::string> params);
115 177
116 /* TODO */ 178 /**
179 * @method invert
180 * @brief Invert image
181 * @param params function parameters as list
182 * @return -
183 * @globalvars none
184 * @exception FileError
185 * @conditions none
186 *
187 * Scriptfile syntax: invert()
188 */
117 void invert(std::list<std::string> params); 189 void invert(std::list<std::string> params);
118 190
119 /* TODO */ 191 /**
192 * @method brightness
193 * @brief Increase/decrease brightness of image
194 * @param params function parameters as list
195 * @return -
196 * @globalvars none
197 * @exception FileError
198 * @conditions none
199 *
200 * Scriptfile syntax: brightness(factor)
201 */
120 void brightness(std::list<std::string> params); 202 void brightness(std::list<std::string> params);
121 203
122 /* TODO */ 204 /**
205 * @method mirror_y
206 * @brief Mirror image around the y-axis
207 * @param params function parameters as list
208 * @return -
209 * @globalvars none
210 * @exception FileError
211 * @conditions none
212 *
213 * Scriptfile syntax: mirror_y()
214 */
123 void mirror_y(std::list<std::string> params); 215 void mirror_y(std::list<std::string> params);
124 216
125 /* TODO */ 217 /**
218 * @method mirror_x
219 * @brief Mirror image around the x-axis
220 * @param params function parameters as list
221 * @return -
222 * @globalvars none
223 * @exception FileError
224 * @conditions none
225 *
226 * Scriptfile syntax: mirror_y()
227 */
126 void mirror_x(std::list<std::string> params); 228 void mirror_x(std::list<std::string> params);
127 229
128 /* members */ 230 /* members */
129 /** pointer to pixelbuffer */ 231 /** pointer to pixelbuffer */
130 uint8_t *m_pixeldata; 232 uint8_t *m_pixeldata;
233 /** colortable map */
234 std::map<std::string, CPixelFormat::RGBPIXEL *> m_colortable;
131 /** set of supported PixelFormat handlers */ 235 /** set of supported PixelFormat handlers */
132 std::set<CPixelFormat *> m_handlers; 236 std::set<CPixelFormat *> m_handlers;
133 /** pointer to CPixelFormat implementation */ 237 /** pointer to CPixelFormat implementation */
diff --git a/ue2/imgsynth2/cpixelformat.h b/ue2/imgsynth2/cpixelformat.h
index 911a141..a9e1e26 100644
--- a/ue2/imgsynth2/cpixelformat.h
+++ b/ue2/imgsynth2/cpixelformat.h
@@ -13,7 +13,7 @@
13#include <stdexcept> 13#include <stdexcept>
14 14
15class CBitmap; 15class CBitmap;
16#include "cbitmap.h" 16//#include "cbitmap.h"
17 17
18/** 18/**
19 * @class CPixelFormat 19 * @class CPixelFormat
@@ -72,9 +72,22 @@ class CPixelFormat
72 {}; 72 {};
73 73
74 /** 74 /**
75 * @method setPixel 75 * @brief RGB Pixel structure
76 * @brief Modifies pixel at coordinates x, y 76 */
77 * @param pixel pointer to new pixel data 77 typedef struct
78 {
79 /** red */
80 uint32_t red;
81 /** green */
82 uint32_t green;
83 /** blue */
84 uint32_t blue;
85 } RGBPIXEL;
86
87 /**
88 * @method getPixel
89 * @brief Get pixel at coordinates x, y
90 * @param pixel reference to pixel data
78 * @param x x-coordinate 91 * @param x x-coordinate
79 * @param y y-coordinate 92 * @param y y-coordinate
80 * @return - 93 * @return -
@@ -82,12 +95,12 @@ class CPixelFormat
82 * @exception PixelFormatError 95 * @exception PixelFormatError
83 * @conditions none 96 * @conditions none
84 */ 97 */
85 virtual void setPixel(const uint32_t *pixel, const uint32_t x, const uint32_t y) = 0; 98 virtual void getPixel(RGBPIXEL& pixel, const uint32_t x, const uint32_t y) = 0;
86 99
87 /** 100 /**
88 * @method getPixel 101 * @method setPixel
89 * @brief Get pixel at coordinates x, y 102 * @brief Modifies pixel at coordinates x, y
90 * @param pixel pointer to pixel data 103 * @param pixel reference to new pixel data
91 * @param x x-coordinate 104 * @param x x-coordinate
92 * @param y y-coordinate 105 * @param y y-coordinate
93 * @return - 106 * @return -
@@ -95,7 +108,7 @@ class CPixelFormat
95 * @exception PixelFormatError 108 * @exception PixelFormatError
96 * @conditions none 109 * @conditions none
97 */ 110 */
98 virtual void getPixel(uint32_t *pixel, const uint32_t x, const uint32_t y) = 0; 111 virtual void setPixel(const RGBPIXEL& pixel, const uint32_t x, const uint32_t y) = 0;
99 112
100 /** 113 /**
101 * @method getBitCount 114 * @method getBitCount
@@ -108,10 +121,16 @@ class CPixelFormat
108 */ 121 */
109 virtual uint32_t getBitCount() = 0; 122 virtual uint32_t getBitCount() = 0;
110 123
111 /* 124 /**
112 * TODO 125 * @method getMaxColor
126 * @brief Get maximum values for RGB pixel
127 * @param pixel reference to pixel struct
128 * @return -
129 * @globalvars none
130 * @exception none
131 * @conditions none
113 */ 132 */
114 virtual void getMaxColor(unsigned int *red, unsigned int *green, unsigned int *blue) = 0; 133 virtual void getMaxColor(RGBPIXEL& pixel) = 0;
115 134
116 protected: 135 protected:
117 /* members */ 136 /* members */
diff --git a/ue2/imgsynth2/cpixelformat_bgr24.cpp b/ue2/imgsynth2/cpixelformat_bgr24.cpp
index 4567ce6..e7476d7 100644
--- a/ue2/imgsynth2/cpixelformat_bgr24.cpp
+++ b/ue2/imgsynth2/cpixelformat_bgr24.cpp
@@ -7,17 +7,12 @@
7 7
8#include <boost/numeric/conversion/cast.hpp> 8#include <boost/numeric/conversion/cast.hpp>
9#include "cpixelformat_bgr24.h" 9#include "cpixelformat_bgr24.h"
10#include "cbitmap.h"
10 11
11using namespace std; 12using namespace std;
12 13
13/* TODO */ 14void CPixelFormat_BGR24::getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y)
14void CPixelFormat_BGR24::getPixel(uint32_t *pixel, uint32_t x, uint32_t y)
15{ 15{
16 /*
17 * pixel[0] ... red
18 * pixel[1] ... green
19 * pixel[2] ... blue
20 */
21 if (m_bitmap->getPixelData() == NULL) 16 if (m_bitmap->getPixelData() == NULL)
22 throw PixelFormatError("No pixelbuffer allocated."); 17 throw PixelFormatError("No pixelbuffer allocated.");
23 18
@@ -36,25 +31,15 @@ void CPixelFormat_BGR24::getPixel(uint32_t *pixel, uint32_t x, uint32_t y)
36 throw PixelFormatError("Pixel position is out of range."); 31 throw PixelFormatError("Pixel position is out of range.");
37 32
38 /* get pixel */ 33 /* get pixel */
39 try 34 pixel.red = *(m_bitmap->getPixelData() + offset + 2);
40 { 35 pixel.green = *(m_bitmap->getPixelData() + offset + 1);
41 pixel[0] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 2)); 36 pixel.blue = *(m_bitmap->getPixelData() + offset);
42 pixel[1] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 1));
43 pixel[2] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset));
44 }
45 catch(boost::numeric::bad_numeric_cast& ex)
46 {
47 throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what()));
48 }
49} 37}
50 38
51void CPixelFormat_BGR24::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) 39/*----------------------------------------------------------------------------*/
40
41void CPixelFormat_BGR24::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y)
52{ 42{
53 /*
54 * pixel[0] ... red
55 * pixel[1] ... green
56 * pixel[2] ... blue
57 */
58 if (m_bitmap->getPixelData() == NULL) 43 if (m_bitmap->getPixelData() == NULL)
59 throw PixelFormatError("No pixelbuffer allocated."); 44 throw PixelFormatError("No pixelbuffer allocated.");
60 45
@@ -76,9 +61,9 @@ void CPixelFormat_BGR24::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y)
76 uint8_t data[3]; 61 uint8_t data[3];
77 try 62 try
78 { 63 {
79 data[0] = boost::numeric_cast<uint8_t>(pixel[2]); 64 data[0] = boost::numeric_cast<uint8_t>(pixel.blue);
80 data[1] = boost::numeric_cast<uint8_t>(pixel[1]); 65 data[1] = boost::numeric_cast<uint8_t>(pixel.green);
81 data[2] = boost::numeric_cast<uint8_t>(pixel[0]); 66 data[2] = boost::numeric_cast<uint8_t>(pixel.red);
82 } 67 }
83 catch(boost::numeric::bad_numeric_cast& ex) 68 catch(boost::numeric::bad_numeric_cast& ex)
84 { 69 {
diff --git a/ue2/imgsynth2/cpixelformat_bgr24.h b/ue2/imgsynth2/cpixelformat_bgr24.h
index 73f22c1..242eadf 100644
--- a/ue2/imgsynth2/cpixelformat_bgr24.h
+++ b/ue2/imgsynth2/cpixelformat_bgr24.h
@@ -45,13 +45,23 @@ class CPixelFormat_BGR24 : public CPixelFormat
45 ~CPixelFormat_BGR24() 45 ~CPixelFormat_BGR24()
46 {} 46 {}
47 47
48 /* TODO */ 48 /**
49 void getPixel(uint32_t *pixel, uint32_t x, uint32_t y); 49 * @method getPixel
50 * @brief Get pixel at coordinates x, y
51 * @param pixel reference to pixel data
52 * @param x x-coordinate
53 * @param y y-coordinate
54 * @return -
55 * @globalvars none
56 * @exception PixelFormatError
57 * @conditions none
58 */
59 void getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y);
50 60
51 /** 61 /**
52 * @method setPixel 62 * @method setPixel
53 * @brief Modifies pixel at coordinates x, y 63 * @brief Modifies pixel at coordinates x, y
54 * @param pixel pointer to new pixel data 64 * @param pixel reference to new pixel data
55 * @param x x-coordinate 65 * @param x x-coordinate
56 * @param y y-coordinate 66 * @param y y-coordinate
57 * @return - 67 * @return -
@@ -59,7 +69,7 @@ class CPixelFormat_BGR24 : public CPixelFormat
59 * @exception PixelFormatError 69 * @exception PixelFormatError
60 * @conditions none 70 * @conditions none
61 */ 71 */
62 void setPixel(const uint32_t *pixel, uint32_t x, uint32_t y); 72 void setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y);
63 73
64 /** 74 /**
65 * @method getBitCount 75 * @method getBitCount
@@ -75,12 +85,19 @@ class CPixelFormat_BGR24 : public CPixelFormat
75 return 24; 85 return 24;
76 } 86 }
77 87
78 /* 88 /**
79 * TODO 89 * @method getMaxColor
90 * @brief Get maximum values for RGB pixel
91 * @param pixel reference to pixel struct
92 * @return -
93 * @globalvars none
94 * @exception none
95 * @conditions none
80 */ 96 */
81 void getMaxColor(unsigned int *red, unsigned int *green, unsigned int *blue) 97 void getMaxColor(RGBPIXEL& pixel)
82 { 98 {
83 *red = *green = *blue = 255; /* 2^8 - 1 */ 99 /* value = 2^8 - 1 */
100 pixel.red = pixel.green = pixel.blue = 255;
84 } 101 }
85}; 102};
86 103
diff --git a/ue2/imgsynth2/cpixelformat_bgr555.cpp b/ue2/imgsynth2/cpixelformat_bgr555.cpp
index 19c98a8..2f98cc7 100644
--- a/ue2/imgsynth2/cpixelformat_bgr555.cpp
+++ b/ue2/imgsynth2/cpixelformat_bgr555.cpp
@@ -8,33 +8,40 @@
8 8
9#include <boost/numeric/conversion/cast.hpp> 9#include <boost/numeric/conversion/cast.hpp>
10#include "cpixelformat_bgr555.h" 10#include "cpixelformat_bgr555.h"
11#include "cbitmap.h"
11 12
12using namespace std; 13using namespace std;
13 14
14/* TODO */ 15void CPixelFormat_BGR555::getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y)
15void CPixelFormat_BGR555::getPixel(uint32_t *pixel, uint32_t x, uint32_t y)
16{ 16{
17 /*
18 * pixel[0] ... red
19 * pixel[1] ... green
20 * pixel[2] ... blue
21 */
22 if (m_bitmap->getPixelData() == NULL) 17 if (m_bitmap->getPixelData() == NULL)
23 throw PixelFormatError("No pixelbuffer allocated."); 18 throw PixelFormatError("No pixelbuffer allocated.");
24 19
25 throw PixelFormatError("NOT IMPLEMENTED"); 20 /* calc rowsize - boundary is 32 */
21 uint32_t rowsize = 4 * static_cast<uint32_t>(
22 ((getBitCount() * m_bitmap->getWidth()) + 31) / 32
23 );
24
25 /* if the y-coordinates are mirrored */
26 if (m_bitmap->isMirrored())
27 y = m_bitmap->getHeight() - y - 1;
28 uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32);
29
30 /* boundary check */
31 if (offset + getBitCount()/8 > m_bitmap->getPixelDataSize())
32 throw PixelFormatError("Pixel position is out of range.");
33
34 /* get pixel */
35 uint8_t *o = m_bitmap->getPixelData() + offset;
36 pixel.blue = (*(uint16_t *)o & BGR555_BLUE_MASK) >> BGR555_BLUE_SHIFT;
37 pixel.green = (*(uint16_t *)o & BGR555_GREEN_MASK) >> BGR555_GREEN_SHIFT;
38 pixel.red = (*(uint16_t *)o & BGR555_RED_MASK) >> BGR555_RED_SHIFT;
26} 39}
27 40
28/*----------------------------------------------------------------------------*/ 41/*----------------------------------------------------------------------------*/
29 42
30void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) 43void CPixelFormat_BGR555::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y)
31{ 44{
32 /*
33 * pixel[0] ... red
34 * pixel[1] ... green
35 * pixel[2] ... blue
36 */
37
38 if (m_bitmap->getPixelData() == NULL) 45 if (m_bitmap->getPixelData() == NULL)
39 throw PixelFormatError("No pixelbuffer allocated."); 46 throw PixelFormatError("No pixelbuffer allocated.");
40 47
@@ -54,9 +61,9 @@ void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y
54 61
55 /* convert color values to correct types */ 62 /* convert color values to correct types */
56 uint8_t *o = m_bitmap->getPixelData() + offset; 63 uint8_t *o = m_bitmap->getPixelData() + offset;
57 *(uint16_t *)o = (uint16_t)(((pixel[2] << BGR555_BLUE_SHIFT) & BGR555_BLUE_MASK) | 64 *(uint16_t *)o = (uint16_t)(((pixel.blue << BGR555_BLUE_SHIFT) & BGR555_BLUE_MASK) |
58 ((pixel[1] << BGR555_GREEN_SHIFT) & BGR555_GREEN_MASK) | 65 ((pixel.green << BGR555_GREEN_SHIFT) & BGR555_GREEN_MASK) |
59 ((pixel[0] << BGR555_RED_SHIFT) & BGR555_RED_MASK)); 66 ((pixel.red << BGR555_RED_SHIFT) & BGR555_RED_MASK));
60} 67}
61 68
62/* vim: set et sw=2 ts=2: */ 69/* vim: set et sw=2 ts=2: */
diff --git a/ue2/imgsynth2/cpixelformat_bgr555.h b/ue2/imgsynth2/cpixelformat_bgr555.h
index b04e4be..f131214 100644
--- a/ue2/imgsynth2/cpixelformat_bgr555.h
+++ b/ue2/imgsynth2/cpixelformat_bgr555.h
@@ -12,7 +12,7 @@
12#include <fstream> 12#include <fstream>
13#include "cpixelformat.h" 13#include "cpixelformat.h"
14 14
15/* TODO */ 15/* to (un-)pack pixel values */
16#define BGR555_RED_SHIFT 10 16#define BGR555_RED_SHIFT 10
17#define BGR555_GREEN_SHIFT 5 17#define BGR555_GREEN_SHIFT 5
18#define BGR555_BLUE_SHIFT 0 18#define BGR555_BLUE_SHIFT 0
@@ -55,13 +55,23 @@ class CPixelFormat_BGR555 : public CPixelFormat
55 ~CPixelFormat_BGR555() 55 ~CPixelFormat_BGR555()
56 {} 56 {}
57 57
58 /* TODO */ 58 /**
59 void getPixel(uint32_t *pixel, uint32_t x, uint32_t y); 59 * @method getPixel
60 * @brief Get pixel at coordinates x, y
61 * @param pixel reference to pixel data
62 * @param x x-coordinate
63 * @param y y-coordinate
64 * @return -
65 * @globalvars none
66 * @exception PixelFormatError
67 * @conditions none
68 */
69 void getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y);
60 70
61 /** 71 /**
62 * @method setPixel 72 * @method setPixel
63 * @brief Modifies pixel at coordinates x, y 73 * @brief Modifies pixel at coordinates x, y
64 * @param pixel pointer to new pixel data 74 * @param pixel reference to new pixel data
65 * @param x x-coordinate 75 * @param x x-coordinate
66 * @param y y-coordinate 76 * @param y y-coordinate
67 * @return - 77 * @return -
@@ -69,7 +79,7 @@ class CPixelFormat_BGR555 : public CPixelFormat
69 * @exception PixelFormatError 79 * @exception PixelFormatError
70 * @conditions none 80 * @conditions none
71 */ 81 */
72 void setPixel(const uint32_t *pixel, uint32_t x, uint32_t y); 82 void setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y);
73 83
74 /** 84 /**
75 * @method getBitCount 85 * @method getBitCount
@@ -85,12 +95,19 @@ class CPixelFormat_BGR555 : public CPixelFormat
85 return 16; 95 return 16;
86 } 96 }
87 97
88 /* 98 /**
89 * TODO 99 * @method getMaxColor
100 * @brief Get maximum values for RGB pixel
101 * @param pixel reference to pixel struct
102 * @return -
103 * @globalvars none
104 * @exception none
105 * @conditions none
90 */ 106 */
91 void getMaxColor(unsigned int *red, unsigned int *green, unsigned int *blue) 107 void getMaxColor(RGBPIXEL& pixel)
92 { 108 {
93 *red = *green = *blue = 31; /* 2^5 -1 */ 109 /* value = 2^5 - 1 */
110 pixel.red = pixel.green = pixel.blue = 31;
94 } 111 }
95}; 112};
96 113
diff --git a/ue2/imgsynth2/cwindowsbitmap.h b/ue2/imgsynth2/cwindowsbitmap.h
index 28ad010..9fb40db 100644
--- a/ue2/imgsynth2/cwindowsbitmap.h
+++ b/ue2/imgsynth2/cwindowsbitmap.h
@@ -159,33 +159,80 @@ class CWindowsBitmap : public CBitmap
159 return m_infoheader; 159 return m_infoheader;
160 } 160 }
161 161
162 /* TODO */ 162 /**
163 * @method getPixelDataSize
164 * @brief Return size of pixelbuffer
165 * @param -
166 * @return size of pixelbuffer
167 * @globalvars none
168 * @exception none
169 * @conditions none
170 */
163 const uint32_t getPixelDataSize() 171 const uint32_t getPixelDataSize()
164 { 172 {
165 return m_infoheader.biSizeImage; 173 return m_infoheader.biSizeImage;
166 } 174 }
167 175
168 /* TODO */ 176 /**
177 * @method getHeight
178 * @brief Return height of bitmap in pixel
179 * @param -
180 * @return height of bitmap in pixel
181 * @globalvars none
182 * @exception none
183 * @conditions none
184 */
169 const uint32_t getHeight() 185 const uint32_t getHeight()
170 { 186 {
171 /* width and height can be negativ */ 187 /* width and height can be negativ */
172 return static_cast<uint32_t>(abs(m_infoheader.biHeight)); 188 return static_cast<uint32_t>(abs(m_infoheader.biHeight));
173 } 189 }
174 190
175 /* TODO */ 191 /**
192 * @method getWidth
193 * @brief Return width of bitmap in pixel
194 * @param -
195 * @return width of bitmap in pixel
196 * @globalvars none
197 * @exception none
198 * @conditions none
199 */
176 const uint32_t getWidth() 200 const uint32_t getWidth()
177 { 201 {
178 /* width and height can be negativ */ 202 /* width and height can be negativ */
179 return static_cast<uint32_t>(abs(m_infoheader.biWidth)); 203 return static_cast<uint32_t>(abs(m_infoheader.biWidth));
180 } 204 }
181 205
182 /* TODO */ 206 /**
207 * @method isMirrored
208 * @brief Windows Bitmaps can be stored upside down
209 * @param -
210 * @return true if bitmap is stored upside down. false otherwise
211 * @globalvars none
212 * @exception none
213 * @conditions none
214 */
183 const bool isMirrored() 215 const bool isMirrored()
184 { 216 {
185 /* if height is positive the y-coordinates are mirrored */ 217 /* if height is positive the y-coordinates are mirrored */
186 return (m_infoheader.biHeight > 0) ? true : false; 218 return (m_infoheader.biHeight > 0) ? true : false;
187 } 219 }
188 220
221 /**
222 * @method hasColorTable
223 * @brief Check if bitmap has a colortable
224 * (we don't support this yet for windows bitmaps)
225 * @param -
226 * @return true if bitmap has a colortable. false otherwise
227 * @globalvars none
228 * @exception none
229 * @conditions none
230 */
231 const bool hasColorTable()
232 {
233 return false;
234 }
235
189 protected: 236 protected:
190 /* members */ 237 /* members */
191 /** fileheader */ 238 /** fileheader */
diff --git a/ue2/imgsynth2/test/input_yellow_man2_rgb24 b/ue2/imgsynth2/test/input_yellow_man2_rgb24
index 37108b8..7c3253c 100644
--- a/ue2/imgsynth2/test/input_yellow_man2_rgb24
+++ b/ue2/imgsynth2/test/input_yellow_man2_rgb24
@@ -5,9 +5,9 @@
5read(BMP, test/yellow_man2_rgb24_in.bmp) 5read(BMP, test/yellow_man2_rgb24_in.bmp)
6 6
7fillrect(0,3,6,5,0,255,0) 7fillrect(0,3,6,5,0,255,0)
8fillrect(2,13,6,4,0,0,255) 8fillrect(2,13,7,4,0,0,255)
9mirror_x() 9mirror_x()
10mirror_y() 10mirror_y()
11#invert() 11invert()
12 12
13write(BMP, "test/yellow_man2_rgb24_out.bmp") 13write(BMP, "test/yellow_man2_rgb24_out.bmp")
diff --git a/ue2/imgsynth2/test/input_yellow_man2_rgb555 b/ue2/imgsynth2/test/input_yellow_man2_rgb555
index 3c00301..0fdcbc4 100644
--- a/ue2/imgsynth2/test/input_yellow_man2_rgb555
+++ b/ue2/imgsynth2/test/input_yellow_man2_rgb555
@@ -4,10 +4,10 @@
4 4
5read(BMP, test/yellow_man2_rgb555_in.bmp) 5read(BMP, test/yellow_man2_rgb555_in.bmp)
6 6
7fillrect(0,3,6,5,0,24,0) 7fillrect(0,3,6,5,0,31,0)
8fillrect(2,13,7,4,0,0,24) 8fillrect(2,13,7,4,0,0,31)
9mirror_x() 9mirror_x()
10mirror_y() 10mirror_y()
11#invert() 11invert()
12 12
13write(BMP, "test/yellow_man2_rgb555_out.bmp") 13write(BMP, "test/yellow_man2_rgb555_out.bmp")
diff --git a/ue2/imgsynth2/test/yellow_man1_rgb24_out.bmp b/ue2/imgsynth2/test/yellow_man1_rgb24_out.bmp
deleted file mode 100644
index 340eab9..0000000
--- a/ue2/imgsynth2/test/yellow_man1_rgb24_out.bmp
+++ /dev/null
Binary files differ
diff --git a/ue2/imgsynth2/test/yellow_man1_rgb555_out.bmp b/ue2/imgsynth2/test/yellow_man1_rgb555_out.bmp
deleted file mode 100644
index 1c35ab5..0000000
--- a/ue2/imgsynth2/test/yellow_man1_rgb555_out.bmp
+++ /dev/null
Binary files differ
diff --git a/ue2/imgsynth2/test/yellow_man2_rgb24_out.bmp b/ue2/imgsynth2/test/yellow_man2_rgb24_out.bmp
deleted file mode 100644
index c859cda..0000000
--- a/ue2/imgsynth2/test/yellow_man2_rgb24_out.bmp
+++ /dev/null
Binary files differ
diff --git a/ue2/imgsynth2/test/yellow_man2_rgb555_out.bmp b/ue2/imgsynth2/test/yellow_man2_rgb555_out.bmp
deleted file mode 100644
index 60588e3..0000000
--- a/ue2/imgsynth2/test/yellow_man2_rgb555_out.bmp
+++ /dev/null
Binary files differ