summaryrefslogtreecommitdiffstats
path: root/ue2/imgsynth2/cwindowsbitmap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ue2/imgsynth2/cwindowsbitmap.cpp')
-rw-r--r--ue2/imgsynth2/cwindowsbitmap.cpp235
1 files changed, 0 insertions, 235 deletions
diff --git a/ue2/imgsynth2/cwindowsbitmap.cpp b/ue2/imgsynth2/cwindowsbitmap.cpp
index 5466dc2..6909136 100644
--- a/ue2/imgsynth2/cwindowsbitmap.cpp
+++ b/ue2/imgsynth2/cwindowsbitmap.cpp
@@ -17,7 +17,6 @@
17using namespace std; 17using namespace std;
18 18
19CWindowsBitmap::CWindowsBitmap() 19CWindowsBitmap::CWindowsBitmap()
20 : m_pixeldata(NULL), m_pixelformat(NULL)
21{ 20{
22 m_types.insert("BMP"); 21 m_types.insert("BMP");
23 22
@@ -113,240 +112,6 @@ void CWindowsBitmap::write(std::ofstream& out)
113 112
114/*----------------------------------------------------------------------------*/ 113/*----------------------------------------------------------------------------*/
115 114
116void CWindowsBitmap::callFunc(const std::string& func, const std::list<std::string>& params)
117{
118 if (func.empty())
119 throw FileError("Function name is empty.");
120
121 if (func == "fillrect")
122 fillrect(params);
123 else if (func == "mirror_x")
124 mirror_x(params);
125 else if (func == "mirror_y")
126 mirror_y(params);
127 else if (func == "invert")
128 invert(params);
129 else
130 throw FileError("Unknown function '" + func + "'.");
131}
132
133/*----------------------------------------------------------------------------*/
134
135void CWindowsBitmap::fillrect(std::list<std::string> params)
136{
137 /* check prerequirements */
138 if (params.size() != 7)
139 throw FileError("Invalid number of function parameters (must be 7).");
140
141 /* do nothing if no pixel exists */
142 if (m_pixeldata == NULL || m_pixelformat == NULL)
143 return;
144
145 /* convert parameters */
146 uint32_t pparams[7];
147 int i = 0;
148 try
149 {
150 for(i = 0; i < 7; i++)
151 {
152 pparams[i] = boost::lexical_cast<uint32_t>(params.front());
153 params.pop_front();
154 }
155 }
156 catch(boost::bad_lexical_cast& ex)
157 {
158 throw FileError("Invalid parameter (" + params.front() + ").");
159 }
160
161 /* width and height can be negativ */
162 uint32_t width = static_cast<uint32_t>(abs(m_infoheader.biWidth));
163 uint32_t height = static_cast<uint32_t>(abs(m_infoheader.biHeight));
164
165 /* check parameter values are in range */
166 if (pparams[0] < 0 || pparams[0] > width
167 || pparams[1] < 0 || pparams[1] > height)
168 throw FileError("At least one x/y-parameter is out of range.");
169
170 /* check parameter values are in range */
171 unsigned int max[3];
172 m_pixelformat->getMaxColor(&max[0], &max[1], &max[2]);
173 if (pparams[4] < 0 || pparams[4] > max[0]
174 || pparams[5] < 0 || pparams[5] > max[1]
175 || pparams[6] < 0 || pparams[6] > max[2])
176 throw FileError("At least one pixel color parameter is out of range.");
177
178 if (pparams[2] < 0 || pparams[2] + pparams[0] > width
179 || pparams[3] < 0 || pparams[3] + pparams[1] > height)
180 throw FileError("At least one w/h-parameter is out of range.");
181
182 /* call setPixel for every pixel in the rectangel */
183 for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++)
184 {
185 for(uint32_t j = pparams[1]; j < pparams[3] + pparams[1]; j++)
186 {
187 try
188 {
189 m_pixelformat->setPixel(&pparams[4], i, j);
190 }
191 catch(CPixelFormat::PixelFormatError& ex)
192 {
193 stringstream errstr;
194 errstr << "Can't set pixel (pos=[" << i << "," << j << "] col=["
195 << pparams[4] << "," << pparams[5] << "," << pparams[6] << "]): "
196 << ex.what();
197 throw FileError(errstr.str());
198 }
199 }
200 }
201}
202
203/*----------------------------------------------------------------------------*/
204
205#include <iostream>
206void CWindowsBitmap::invert(std::list<std::string> params)
207{
208 /* check prerequirements */
209 if (params.size() != 0)
210 throw FileError("Invalid number of function parameters (must be 0).");
211
212 /* do nothing if no pixel exists */
213 if (m_pixeldata == NULL || m_pixelformat == NULL)
214 return;
215
216 /* width and height can be negativ */
217 uint32_t width = static_cast<uint32_t>(abs(m_infoheader.biWidth));
218 uint32_t height = static_cast<uint32_t>(abs(m_infoheader.biHeight));
219 unsigned int pixelwidth = m_pixelformat->getBitCount()/8;
220
221 /* calc rowsize - boundary is 32 */
222 uint32_t rowsize = 4 * static_cast<uint32_t>(
223 ((m_pixelformat->getBitCount() * abs(m_infoheader.biWidth)) + 31) / 32
224 );
225
226 for(uint32_t i = 0; i < height; i++)
227 {
228 for(uint32_t j = 0; j <= width; j++)
229 {
230 cout << j << endl;
231 }
232 }
233
234#if 0
235/* uint32_t offset = i * rowsize;
236
237 for(uint32_t j = 0; j <= width/2; j++)
238 {
239 uint32_t poffset = offset + j * pixelwidth;
240 uint32_t pbackset = offset + width * pixelwidth - j * pixelwidth;
241
242 /* boundary check */
243 if (pbackset > m_infoheader.biSizeImage)
244 throw FileError("Mirrored pixel position is out of range.");
245
246 /* mirroring, backup right data first */
247 copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf);
248 copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth);
249 copy(buf, buf + pixelwidth, m_pixeldata + poffset);
250 }
251 }
252#endif
253}
254
255/*----------------------------------------------------------------------------*/
256
257void CWindowsBitmap::brightness(std::list<std::string> params)
258{
259}
260
261/*----------------------------------------------------------------------------*/
262
263void CWindowsBitmap::mirror_y(std::list<std::string> params)
264{
265 /* check prerequirements */
266 if (params.size() != 0)
267 throw FileError("Invalid number of function parameters (must be 0).");
268
269 /* do nothing if no pixel exists */
270 if (m_pixeldata == NULL || m_pixelformat == NULL)
271 return;
272W
273 /* height can be negativ */
274 uint32_t height = static_cast<uint32_t>(abs(m_infoheader.biHeight));
275
276 /* calc rowsize - boundary is 32 */
277 uint32_t rowsize = 4 * static_cast<uint32_t>(
278 ((m_pixelformat->getBitCount() * abs(m_infoheader.biWidth)) + 31) / 32
279 );
280
281 uint8_t *buf = new uint8_t[rowsize];
282 for(uint32_t i = 0; i < height/2; i++)
283 {
284 uint32_t j = height - i - 1;
285 uint32_t offset = i * rowsize;
286 uint32_t backset = j * rowsize;
287
288 /* boundary check */
289 if (offset + rowsize > m_infoheader.biSizeImage
290 || backset + rowsize > m_infoheader.biSizeImage)
291 throw FileError("Mirrored pixel position is out of range.");
292
293 /* mirroring, backup lower data first */
294 copy(m_pixeldata + backset, m_pixeldata + backset + rowsize, buf);
295 copy(m_pixeldata + offset, m_pixeldata + offset + rowsize, m_pixeldata + backset);
296 copy(buf, buf + rowsize, m_pixeldata + offset);
297 }
298 delete[] buf;
299}
300
301/*----------------------------------------------------------------------------*/
302
303void CWindowsBitmap::mirror_x(std::list<std::string> params)
304{
305 /* check prerequirements */
306 if (params.size() != 0)
307 throw FileError("Invalid number of function parameters (must be 0).");
308
309 /* do nothing if no pixel exists */
310 if (m_pixeldata == NULL || m_pixelformat == NULL)
311 return;
312
313 /* width and height can be negativ */
314 uint32_t width = static_cast<uint32_t>(abs(m_infoheader.biWidth));
315 uint32_t height = static_cast<uint32_t>(abs(m_infoheader.biHeight));
316
317 /* calc rowsize - boundary is 32 */
318 uint32_t rowsize = 4 * static_cast<uint32_t>(
319 ((m_pixelformat->getBitCount() * abs(m_infoheader.biWidth)) + 31) / 32
320 );
321
322 /* calc pixelwidth */
323 unsigned int pixelwidth = m_pixelformat->getBitCount()/8;
324
325 uint8_t *buf = new uint8_t[pixelwidth];
326 for(uint32_t i = 0; i < height; i++)
327 {
328 uint32_t offset = i * rowsize;
329
330 for(uint32_t j = 0; j <= width/2; j++)
331 {
332 uint32_t poffset = offset + j * pixelwidth;
333 uint32_t pbackset = offset + width * pixelwidth - j * pixelwidth;
334
335 /* boundary check */
336 if (pbackset > m_infoheader.biSizeImage)
337 throw FileError("Mirrored pixel position is out of range.");
338
339 /* mirroring, backup right data first */
340 copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf);
341 copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth);
342 copy(buf, buf + pixelwidth, m_pixeldata + poffset);
343 }
344 }
345 delete[] buf;
346}
347
348/*----------------------------------------------------------------------------*/
349
350#ifdef DEBUG 115#ifdef DEBUG
351void CWindowsBitmap::dump(std::ostream& out) 116void CWindowsBitmap::dump(std::ostream& out)
352{ 117{