summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-04-28 18:38:07 +0200
committermanuel <manuel@nc8430.lan>2009-04-28 18:38:07 +0200
commit88a84e3bc371d1b1b3533143658ad192476c59ab (patch)
treed97287b96173f82b5373017fbcf2ef829933b093
parent5f499a8233c7bb68b52b8fdeddac9a06061ea4d7 (diff)
downloadooprog-88a84e3bc371d1b1b3533143658ad192476c59ab.tar.gz
ooprog-88a84e3bc371d1b1b3533143658ad192476c59ab.tar.bz2
ooprog-88a84e3bc371d1b1b3533143658ad192476c59ab.zip
forgot to remove dtor...
-rw-r--r--ue2/imgsynth2/Makefile3
-rw-r--r--ue2/imgsynth2/cbitmap.cpp506
-rw-r--r--ue2/imgsynth2/cwindowsbitmap.cpp16
-rw-r--r--ue2/imgsynth2/cwindowsbitmap.h3
4 files changed, 256 insertions, 272 deletions
diff --git a/ue2/imgsynth2/Makefile b/ue2/imgsynth2/Makefile
index d8f3372..376abac 100644
--- a/ue2/imgsynth2/Makefile
+++ b/ue2/imgsynth2/Makefile
@@ -5,8 +5,7 @@
5CC= g++ 5CC= g++
6LD= $(CC) 6LD= $(CC)
7DEBUGFLAGS= -DNDEBUG 7DEBUGFLAGS= -DNDEBUG
8#TODO CFLAGS= -O -ansi -pedantic-errors -Wall -I/usr/local/include $(DEBUGFLAGS) 8CFLAGS= -O -ansi -pedantic-errors -Wall -I/usr/local/include $(DEBUGFLAGS)
9CFLAGS= -O -ansi -Wall -I/usr/local/include $(DEBUGFLAGS)
10LDFLAGS= 9LDFLAGS=
11LIBS= -L/usr/local/lib -lboost_program_options 10LIBS= -L/usr/local/lib -lboost_program_options
12 11
diff --git a/ue2/imgsynth2/cbitmap.cpp b/ue2/imgsynth2/cbitmap.cpp
index 82ba4ae..b9cfc62 100644
--- a/ue2/imgsynth2/cbitmap.cpp
+++ b/ue2/imgsynth2/cbitmap.cpp
@@ -1,253 +1,253 @@
1/** 1/**
2 * @module cbitmap 2 * @module cbitmap
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) 3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief Abstract implementation of CFile handling Bitmaps. 4 * @brief Abstract implementation of CFile handling Bitmaps.
5 * @date 17.04.2009 5 * @date 17.04.2009
6 */ 6 */
7 7
8#include <boost/lexical_cast.hpp> 8#include <boost/lexical_cast.hpp>
9#include <boost/numeric/conversion/cast.hpp> 9#include <boost/numeric/conversion/cast.hpp>
10#include "cbitmap.h" 10#include "cbitmap.h"
11 11
12using namespace std; 12using namespace std;
13 13
14/*----------------------------------------------------------------------------*/ 14/*----------------------------------------------------------------------------*/
15 15
16CBitmap::~CBitmap() 16CBitmap::~CBitmap()
17{ 17{
18 /* delete pixeldata */ 18 /* delete pixeldata */
19 if (m_pixeldata != NULL) 19 if (m_pixeldata != NULL)
20 delete[] m_pixeldata; 20 delete[] m_pixeldata;
21 m_pixeldata = NULL; 21 m_pixeldata = NULL;
22 22
23 /* delete pixelformat handlers */ 23 /* delete pixelformat handlers */
24 set<CPixelFormat *>::iterator it; 24 set<CPixelFormat *>::iterator it;
25 for (it = m_handlers.begin(); it != m_handlers.end(); it++) 25 for (it = m_handlers.begin(); it != m_handlers.end(); it++)
26 delete *it; 26 delete *it;
27 m_pixelformat = NULL; 27 m_pixelformat = NULL;
28} 28}
29 29
30/*----------------------------------------------------------------------------*/ 30/*----------------------------------------------------------------------------*/
31 31
32void CBitmap::callFunc(const std::string& func, const std::list<std::string>& params) 32void CBitmap::callFunc(const std::string& func, const std::list<std::string>& params)
33{ 33{
34 if (func.empty()) 34 if (func.empty())
35 throw FileError("Function name is empty."); 35 throw FileError("Function name is empty.");
36 36
37 if (func == "fillrect") 37 if (func == "fillrect")
38 fillrect(params); 38 fillrect(params);
39 else if (func == "mirror_x") 39 else if (func == "mirror_x")
40 mirror_x(params); 40 mirror_x(params);
41 else if (func == "mirror_y") 41 else if (func == "mirror_y")
42 mirror_y(params); 42 mirror_y(params);
43 else if (func == "invert") 43 else if (func == "invert")
44 invert(params); 44 invert(params);
45 else 45 else
46 throw FileError("Unknown function '" + func + "'."); 46 throw FileError("Unknown function '" + func + "'.");
47} 47}
48 48
49/*----------------------------------------------------------------------------*/ 49/*----------------------------------------------------------------------------*/
50 50
51void CBitmap::fillrect(std::list<std::string> params) 51void CBitmap::fillrect(std::list<std::string> params)
52{ 52{
53 /* check prerequirements */ 53 /* check prerequirements */
54 if (params.size() != 7) 54 if (params.size() != 7)
55 throw FileError("Invalid number of function parameters (must be 7)."); 55 throw FileError("Invalid number of function parameters (must be 7).");
56 56
57 /* do nothing if no pixel exists */ 57 /* do nothing if no pixel exists */
58 if (m_pixeldata == NULL || m_pixelformat == NULL) 58 if (m_pixeldata == NULL || m_pixelformat == NULL)
59 return; 59 return;
60 60
61 /* convert parameters */ 61 /* convert parameters */
62 uint32_t pparams[7]; 62 uint32_t pparams[7];
63 int i = 0; 63 int i = 0;
64 try 64 try
65 { 65 {
66 for(i = 0; i < 7; i++) 66 for(i = 0; i < 7; i++)
67 { 67 {
68 pparams[i] = boost::lexical_cast<uint32_t>(params.front()); 68 pparams[i] = boost::lexical_cast<uint32_t>(params.front());
69 params.pop_front(); 69 params.pop_front();
70 } 70 }
71 } 71 }
72 catch(boost::bad_lexical_cast& ex) 72 catch(boost::bad_lexical_cast& ex)
73 { 73 {
74 throw FileError("Invalid parameter (" + params.front() + ")."); 74 throw FileError("Invalid parameter (" + params.front() + ").");
75 } 75 }
76 76
77 /* check parameter values are in range */ 77 /* check parameter values are in range */
78 if (pparams[0] < 0 || pparams[0] > getWidth() 78 if (pparams[0] < 0 || pparams[0] > getWidth()
79 || pparams[1] < 0 || pparams[1] > getHeight()) 79 || pparams[1] < 0 || pparams[1] > getHeight())
80 throw FileError("At least one x/y-parameter is out of range."); 80 throw FileError("At least one x/y-parameter is out of range.");
81 81
82 /* check parameter values are in range */ 82 /* check parameter values are in range */
83 unsigned int max[3]; 83 unsigned int max[3];
84 m_pixelformat->getMaxColor(&max[0], &max[1], &max[2]); 84 m_pixelformat->getMaxColor(&max[0], &max[1], &max[2]);
85 if (pparams[4] < 0 || pparams[4] > max[0] 85 if (pparams[4] < 0 || pparams[4] > max[0]
86 || pparams[5] < 0 || pparams[5] > max[1] 86 || pparams[5] < 0 || pparams[5] > max[1]
87 || pparams[6] < 0 || pparams[6] > max[2]) 87 || pparams[6] < 0 || pparams[6] > max[2])
88 throw FileError("At least one pixel color parameter is out of range."); 88 throw FileError("At least one pixel color parameter is out of range.");
89 89
90 if (pparams[2] < 0 || pparams[2] + pparams[0] > getWidth() 90 if (pparams[2] < 0 || pparams[2] + pparams[0] > getWidth()
91 || pparams[3] < 0 || pparams[3] + pparams[1] > getHeight()) 91 || pparams[3] < 0 || pparams[3] + pparams[1] > getHeight())
92 throw FileError("At least one w/h-parameter is out of range."); 92 throw FileError("At least one w/h-parameter is out of range.");
93 93
94 /* call setPixel for every pixel in the rectangel */ 94 /* call setPixel for every pixel in the rectangel */
95 for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++) 95 for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++)
96 { 96 {
97 for(uint32_t j = pparams[1]; j < pparams[3] + pparams[1]; j++) 97 for(uint32_t j = pparams[1]; j < pparams[3] + pparams[1]; j++)
98 { 98 {
99 try 99 try
100 { 100 {
101 m_pixelformat->setPixel(&pparams[4], i, j); 101 m_pixelformat->setPixel(&pparams[4], i, j);
102 } 102 }
103 catch(CPixelFormat::PixelFormatError& ex) 103 catch(CPixelFormat::PixelFormatError& ex)
104 { 104 {
105 stringstream errstr; 105 stringstream errstr;
106 errstr << "Can't set pixel (pos=[" << i << "," << j << "] col=[" 106 errstr << "Can't set pixel (pos=[" << i << "," << j << "] col=["
107 << pparams[4] << "," << pparams[5] << "," << pparams[6] << "]): " 107 << pparams[4] << "," << pparams[5] << "," << pparams[6] << "]): "
108 << ex.what(); 108 << ex.what();
109 throw FileError(errstr.str()); 109 throw FileError(errstr.str());
110 } 110 }
111 } 111 }
112 } 112 }
113} 113}
114 114
115/*----------------------------------------------------------------------------*/ 115/*----------------------------------------------------------------------------*/
116 116
117/* TODO */ 117/* TODO */
118void CBitmap::invert(std::list<std::string> params) 118void CBitmap::invert(std::list<std::string> params)
119{ 119{
120 /* check prerequirements */ 120 /* check prerequirements */
121 if (params.size() != 0) 121 if (params.size() != 0)
122 throw FileError("Invalid number of function parameters (must be 0)."); 122 throw FileError("Invalid number of function parameters (must be 0).");
123 123
124 /* do nothing if no pixel exists */ 124 /* do nothing if no pixel exists */
125 if (m_pixeldata == NULL || m_pixelformat == NULL) 125 if (m_pixeldata == NULL || m_pixelformat == NULL)
126 return; 126 return;
127 127
128 /* TODO pixelwidth */ 128 /* TODO pixelwidth */
129 unsigned int pixelwidth = m_pixelformat->getBitCount()/8; 129 unsigned int pixelwidth = m_pixelformat->getBitCount()/8;
130 130
131 /* calc rowsize - boundary is 32 */ 131 /* calc rowsize - boundary is 32 */
132 uint32_t rowsize = 4 * static_cast<uint32_t>( 132 uint32_t rowsize = 4 * static_cast<uint32_t>(
133 ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32 133 ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32
134 ); 134 );
135 135
136 for(uint32_t i = 0; i < getHeight(); i++) 136 for(uint32_t i = 0; i < getHeight(); i++)
137 { 137 {
138 for(uint32_t j = 0; j <= getWidth(); j++) 138 for(uint32_t j = 0; j <= getWidth(); j++)
139 { 139 {
140 /*TODO cout << j << endl;*/ 140 /*TODO cout << j << endl;*/
141 break; 141 break;
142 } 142 }
143 } 143 }
144 144
145#if 0 145#if 0
146 uint32_t offset = i * rowsize; 146 uint32_t offset = i * rowsize;
147 147
148 for(uint32_t j = 0; j <= getWidth()/2; j++) 148 for(uint32_t j = 0; j <= getWidth()/2; j++)
149 { 149 {
150 uint32_t poffset = offset + j * pixelwidth; 150 uint32_t poffset = offset + j * pixelwidth;
151 uint32_t pbackset = offset + getWidth() * pixelwidth - j * pixelwidth; 151 uint32_t pbackset = offset + getWidth() * pixelwidth - j * pixelwidth;
152 152
153 /* boundary check */ 153 /* boundary check */
154 if (pbackset > m_infoheader.biSizeImage) 154 if (pbackset > m_infoheader.biSizeImage)
155 throw FileError("Mirrored pixel position is out of range."); 155 throw FileError("Mirrored pixel position is out of range.");
156 156
157 /* mirroring, backup right data first */ 157 /* mirroring, backup right data first */
158 copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf); 158 copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf);
159 copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth); 159 copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth);
160 copy(buf, buf + pixelwidth, m_pixeldata + poffset); 160 copy(buf, buf + pixelwidth, m_pixeldata + poffset);
161 } 161 }
162 } 162 }
163#endif 163#endif
164} 164}
165 165
166/*----------------------------------------------------------------------------*/ 166/*----------------------------------------------------------------------------*/
167 167
168/* TODO */ 168/* TODO */
169void CBitmap::brightness(std::list<std::string> params) 169void CBitmap::brightness(std::list<std::string> params)
170{ 170{
171} 171}
172 172
173/*----------------------------------------------------------------------------*/ 173/*----------------------------------------------------------------------------*/
174 174
175void CBitmap::mirror_y(std::list<std::string> params) 175void CBitmap::mirror_y(std::list<std::string> params)
176{ 176{
177 /* check prerequirements */ 177 /* check prerequirements */
178 if (params.size() != 0) 178 if (params.size() != 0)
179 throw FileError("Invalid number of function parameters (must be 0)."); 179 throw FileError("Invalid number of function parameters (must be 0).");
180 180
181 /* do nothing if no pixel exists */ 181 /* do nothing if no pixel exists */
182 if (m_pixeldata == NULL || m_pixelformat == NULL) 182 if (m_pixeldata == NULL || m_pixelformat == NULL)
183 return; 183 return;
184 184
185 /* calc rowsize - boundary is 32 */ 185 /* calc rowsize - boundary is 32 */
186 uint32_t rowsize = 4 * static_cast<uint32_t>( 186 uint32_t rowsize = 4 * static_cast<uint32_t>(
187 ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32 187 ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32
188 ); 188 );
189 189
190 uint8_t *buf = new uint8_t[rowsize]; 190 uint8_t *buf = new uint8_t[rowsize];
191 for(uint32_t i = 0; i < getHeight()/2; i++) 191 for(uint32_t i = 0; i < getHeight()/2; i++)
192 { 192 {
193 uint32_t j = getHeight() - i - 1; 193 uint32_t j = getHeight() - i - 1;
194 uint32_t offset = i * rowsize; 194 uint32_t offset = i * rowsize;
195 uint32_t backset = j * rowsize; 195 uint32_t backset = j * rowsize;
196 196
197 /* boundary check */ 197 /* boundary check */
198 if (offset + rowsize > getPixelDataSize() 198 if (offset + rowsize > getPixelDataSize()
199 || backset + rowsize > getPixelDataSize()) 199 || backset + rowsize > getPixelDataSize())
200 throw FileError("Mirrored pixel position is out of range."); 200 throw FileError("Mirrored pixel position is out of range.");
201 201
202 /* mirroring, backup lower data first */ 202 /* mirroring, backup lower data first */
203 copy(m_pixeldata + backset, m_pixeldata + backset + rowsize, buf); 203 copy(m_pixeldata + backset, m_pixeldata + backset + rowsize, buf);
204 copy(m_pixeldata + offset, m_pixeldata + offset + rowsize, m_pixeldata + backset); 204 copy(m_pixeldata + offset, m_pixeldata + offset + rowsize, m_pixeldata + backset);
205 copy(buf, buf + rowsize, m_pixeldata + offset); 205 copy(buf, buf + rowsize, m_pixeldata + offset);
206 } 206 }
207 delete[] buf; 207 delete[] buf;
208} 208}
209 209
210/*----------------------------------------------------------------------------*/ 210/*----------------------------------------------------------------------------*/
211 211
212void CBitmap::mirror_x(std::list<std::string> params) 212void CBitmap::mirror_x(std::list<std::string> params)
213{ 213{
214 /* check prerequirements */ 214 /* check prerequirements */
215 if (params.size() != 0) 215 if (params.size() != 0)
216 throw FileError("Invalid number of function parameters (must be 0)."); 216 throw FileError("Invalid number of function parameters (must be 0).");
217 217
218 /* do nothing if no pixel exists */ 218 /* do nothing if no pixel exists */
219 if (m_pixeldata == NULL || m_pixelformat == NULL) 219 if (m_pixeldata == NULL || m_pixelformat == NULL)
220 return; 220 return;
221 221
222 /* calc rowsize - boundary is 32 */ 222 /* calc rowsize - boundary is 32 */
223 uint32_t rowsize = 4 * static_cast<uint32_t>( 223 uint32_t rowsize = 4 * static_cast<uint32_t>(
224 ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32 224 ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32
225 ); 225 );
226 226
227 /* calc pixelwidth */ 227 /* calc pixelwidth */
228 unsigned int pixelwidth = m_pixelformat->getBitCount()/8; 228 unsigned int pixelwidth = m_pixelformat->getBitCount()/8;
229 229
230 uint8_t *buf = new uint8_t[pixelwidth]; 230 uint8_t *buf = new uint8_t[pixelwidth];
231 for(uint32_t i = 0; i < getHeight(); i++) 231 for(uint32_t i = 0; i < getHeight(); i++)
232 { 232 {
233 uint32_t offset = i * rowsize; 233 uint32_t offset = i * rowsize;
234 234
235 for(uint32_t j = 0; j <= getWidth()/2; j++) 235 for(uint32_t j = 0; j <= getWidth()/2; j++)
236 { 236 {
237 uint32_t poffset = offset + j * pixelwidth; 237 uint32_t poffset = offset + j * pixelwidth;
238 uint32_t pbackset = offset + getWidth() * pixelwidth - j * pixelwidth; 238 uint32_t pbackset = offset + getWidth() * pixelwidth - j * pixelwidth;
239 239
240 /* boundary check */ 240 /* boundary check */
241 if (pbackset > getPixelDataSize()) 241 if (pbackset > getPixelDataSize())
242 throw FileError("Mirrored pixel position is out of range."); 242 throw FileError("Mirrored pixel position is out of range.");
243 243
244 /* mirroring, backup right data first */ 244 /* mirroring, backup right data first */
245 copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf); 245 copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf);
246 copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth); 246 copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth);
247 copy(buf, buf + pixelwidth, m_pixeldata + poffset); 247 copy(buf, buf + pixelwidth, m_pixeldata + poffset);
248 } 248 }
249 } 249 }
250 delete[] buf; 250 delete[] buf;
251} 251}
252 252
253/* vim: set et sw=2 ts=2: */ 253/* vim: set et sw=2 ts=2: */
diff --git a/ue2/imgsynth2/cwindowsbitmap.cpp b/ue2/imgsynth2/cwindowsbitmap.cpp
index 6909136..ebbdd4c 100644
--- a/ue2/imgsynth2/cwindowsbitmap.cpp
+++ b/ue2/imgsynth2/cwindowsbitmap.cpp
@@ -27,22 +27,6 @@ CWindowsBitmap::CWindowsBitmap()
27 27
28/*----------------------------------------------------------------------------*/ 28/*----------------------------------------------------------------------------*/
29 29
30CWindowsBitmap::~CWindowsBitmap()
31{
32 /* delete pixeldata */
33 if (m_pixeldata != NULL)
34 delete[] m_pixeldata;
35 m_pixeldata = NULL;
36
37 /* delete pixelformat handlers */
38 set<CPixelFormat *>::iterator it;
39 for (it = m_handlers.begin(); it != m_handlers.end(); it++)
40 delete *it;
41 m_pixelformat = NULL;
42}
43
44/*----------------------------------------------------------------------------*/
45
46void CWindowsBitmap::read(std::ifstream& in) 30void CWindowsBitmap::read(std::ifstream& in)
47{ 31{
48 /* read and check file header */ 32 /* read and check file header */
diff --git a/ue2/imgsynth2/cwindowsbitmap.h b/ue2/imgsynth2/cwindowsbitmap.h
index d348a93..3367952 100644
--- a/ue2/imgsynth2/cwindowsbitmap.h
+++ b/ue2/imgsynth2/cwindowsbitmap.h
@@ -40,7 +40,8 @@ class CWindowsBitmap : public CBitmap
40 * @exception none 40 * @exception none
41 * @conditions none 41 * @conditions none
42 */ 42 */
43 ~CWindowsBitmap(); 43 ~CWindowsBitmap()
44 {}
44 45
45 /** 46 /**
46 * @method read 47 * @method read