diff options
| author | manuel <manuel@clan-server.at> | 2009-04-28 18:32:15 +0200 |
|---|---|---|
| committer | manuel <manuel@clan-server.at> | 2009-04-28 18:32:15 +0200 |
| commit | 5f499a8233c7bb68b52b8fdeddac9a06061ea4d7 (patch) | |
| tree | 894f18cf427eb83c6463a92da76f4a3808a8187c | |
| parent | d7893436cefc6b3cef78ad765dba4fa1740d0f15 (diff) | |
| download | ooprog-5f499a8233c7bb68b52b8fdeddac9a06061ea4d7.tar.gz ooprog-5f499a8233c7bb68b52b8fdeddac9a06061ea4d7.tar.bz2 ooprog-5f499a8233c7bb68b52b8fdeddac9a06061ea4d7.zip | |
Moved a lot of stuff around to get abstract cbitmap working
| -rw-r--r-- | ue2/imgsynth2/Makefile | 9 | ||||
| -rw-r--r-- | ue2/imgsynth2/cbitmap.cpp | 253 | ||||
| -rw-r--r-- | ue2/imgsynth2/cbitmap.h | 77 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixelformat.h | 2 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixelformat_bgr24.cpp | 21 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixelformat_bgr24.h | 6 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixelformat_bgr555.cpp | 26 | ||||
| -rw-r--r-- | ue2/imgsynth2/cpixelformat_bgr555.h | 3 | ||||
| -rw-r--r-- | ue2/imgsynth2/cscriptparser.cpp | 4 | ||||
| -rw-r--r-- | ue2/imgsynth2/cwindowsbitmap.cpp | 235 | ||||
| -rw-r--r-- | ue2/imgsynth2/cwindowsbitmap.h | 77 |
11 files changed, 390 insertions, 323 deletions
diff --git a/ue2/imgsynth2/Makefile b/ue2/imgsynth2/Makefile index cbf3d33..d8f3372 100644 --- a/ue2/imgsynth2/Makefile +++ b/ue2/imgsynth2/Makefile | |||
| @@ -5,15 +5,16 @@ | |||
| 5 | CC= g++ | 5 | CC= g++ |
| 6 | LD= $(CC) | 6 | LD= $(CC) |
| 7 | DEBUGFLAGS= -DNDEBUG | 7 | DEBUGFLAGS= -DNDEBUG |
| 8 | CFLAGS= -O -ansi -pedantic-errors -Wall $(DEBUGFLAGS) | 8 | #TODO CFLAGS= -O -ansi -pedantic-errors -Wall -I/usr/local/include $(DEBUGFLAGS) |
| 9 | CFLAGS= -O -ansi -Wall -I/usr/local/include $(DEBUGFLAGS) | ||
| 9 | LDFLAGS= | 10 | LDFLAGS= |
| 10 | LIBS= -lboost_program_options | 11 | LIBS= -L/usr/local/lib -lboost_program_options |
| 11 | 12 | ||
| 12 | BIN= imgsynth2 | 13 | BIN= imgsynth2 |
| 13 | OBJS= cpixelformat_bgr24.o cpixelformat_bgr555.o \ | 14 | OBJS= cpixelformat_bgr24.o cpixelformat_bgr555.o \ |
| 14 | cbitmap.o cscriptparser.o imgsynth2.o | 15 | cwindowsbitmap.o cbitmap.o cscriptparser.o imgsynth2.o |
| 15 | HEADERS= cpixelformat.h cpixelformat_bgr24.h cpixelformat_bgr555.h \ | 16 | HEADERS= cpixelformat.h cpixelformat_bgr24.h cpixelformat_bgr555.h \ |
| 16 | cfile.h cbitmap.h cscriptparser.h | 17 | cfile.h cbitmap.h cwindowsbitmap.h cscriptparser.h |
| 17 | 18 | ||
| 18 | .SUFFIXES: .cpp .o | 19 | .SUFFIXES: .cpp .o |
| 19 | 20 | ||
diff --git a/ue2/imgsynth2/cbitmap.cpp b/ue2/imgsynth2/cbitmap.cpp new file mode 100644 index 0000000..82ba4ae --- /dev/null +++ b/ue2/imgsynth2/cbitmap.cpp | |||
| @@ -0,0 +1,253 @@ | |||
| 1 | /** | ||
| 2 | * @module cbitmap | ||
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | ||
| 4 | * @brief Abstract implementation of CFile handling Bitmaps. | ||
| 5 | * @date 17.04.2009 | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <boost/lexical_cast.hpp> | ||
| 9 | #include <boost/numeric/conversion/cast.hpp> | ||
| 10 | #include "cbitmap.h" | ||
| 11 | |||
| 12 | using namespace std; | ||
| 13 | |||
| 14 | /*----------------------------------------------------------------------------*/ | ||
| 15 | |||
| 16 | CBitmap::~CBitmap() | ||
| 17 | { | ||
| 18 | /* delete pixeldata */ | ||
| 19 | if (m_pixeldata != NULL) | ||
| 20 | delete[] m_pixeldata; | ||
| 21 | m_pixeldata = NULL; | ||
| 22 | |||
| 23 | /* delete pixelformat handlers */ | ||
| 24 | set<CPixelFormat *>::iterator it; | ||
| 25 | for (it = m_handlers.begin(); it != m_handlers.end(); it++) | ||
| 26 | delete *it; | ||
| 27 | m_pixelformat = NULL; | ||
| 28 | } | ||
| 29 | |||
| 30 | /*----------------------------------------------------------------------------*/ | ||
| 31 | |||
| 32 | void CBitmap::callFunc(const std::string& func, const std::list<std::string>& params) | ||
| 33 | { | ||
| 34 | if (func.empty()) | ||
| 35 | throw FileError("Function name is empty."); | ||
| 36 | |||
| 37 | if (func == "fillrect") | ||
| 38 | fillrect(params); | ||
| 39 | else if (func == "mirror_x") | ||
| 40 | mirror_x(params); | ||
| 41 | else if (func == "mirror_y") | ||
| 42 | mirror_y(params); | ||
| 43 | else if (func == "invert") | ||
| 44 | invert(params); | ||
| 45 | else | ||
| 46 | throw FileError("Unknown function '" + func + "'."); | ||
| 47 | } | ||
| 48 | |||
| 49 | /*----------------------------------------------------------------------------*/ | ||
| 50 | |||
| 51 | void CBitmap::fillrect(std::list<std::string> params) | ||
| 52 | { | ||
| 53 | /* check prerequirements */ | ||
| 54 | if (params.size() != 7) | ||
| 55 | throw FileError("Invalid number of function parameters (must be 7)."); | ||
| 56 | |||
| 57 | /* do nothing if no pixel exists */ | ||
| 58 | if (m_pixeldata == NULL || m_pixelformat == NULL) | ||
| 59 | return; | ||
| 60 | |||
| 61 | /* convert parameters */ | ||
| 62 | uint32_t pparams[7]; | ||
| 63 | int i = 0; | ||
| 64 | try | ||
| 65 | { | ||
| 66 | for(i = 0; i < 7; i++) | ||
| 67 | { | ||
| 68 | pparams[i] = boost::lexical_cast<uint32_t>(params.front()); | ||
| 69 | params.pop_front(); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | catch(boost::bad_lexical_cast& ex) | ||
| 73 | { | ||
| 74 | throw FileError("Invalid parameter (" + params.front() + ")."); | ||
| 75 | } | ||
| 76 | |||
| 77 | /* check parameter values are in range */ | ||
| 78 | if (pparams[0] < 0 || pparams[0] > getWidth() | ||
| 79 | || pparams[1] < 0 || pparams[1] > getHeight()) | ||
| 80 | throw FileError("At least one x/y-parameter is out of range."); | ||
| 81 | |||
| 82 | /* check parameter values are in range */ | ||
| 83 | unsigned int max[3]; | ||
| 84 | m_pixelformat->getMaxColor(&max[0], &max[1], &max[2]); | ||
| 85 | if (pparams[4] < 0 || pparams[4] > max[0] | ||
| 86 | || pparams[5] < 0 || pparams[5] > max[1] | ||
| 87 | || pparams[6] < 0 || pparams[6] > max[2]) | ||
| 88 | throw FileError("At least one pixel color parameter is out of range."); | ||
| 89 | |||
| 90 | if (pparams[2] < 0 || pparams[2] + pparams[0] > getWidth() | ||
| 91 | || pparams[3] < 0 || pparams[3] + pparams[1] > getHeight()) | ||
| 92 | throw FileError("At least one w/h-parameter is out of range."); | ||
| 93 | |||
| 94 | /* call setPixel for every pixel in the rectangel */ | ||
| 95 | for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++) | ||
| 96 | { | ||
| 97 | for(uint32_t j = pparams[1]; j < pparams[3] + pparams[1]; j++) | ||
| 98 | { | ||
| 99 | try | ||
| 100 | { | ||
| 101 | m_pixelformat->setPixel(&pparams[4], i, j); | ||
| 102 | } | ||
| 103 | catch(CPixelFormat::PixelFormatError& ex) | ||
| 104 | { | ||
| 105 | stringstream errstr; | ||
| 106 | errstr << "Can't set pixel (pos=[" << i << "," << j << "] col=[" | ||
| 107 | << pparams[4] << "," << pparams[5] << "," << pparams[6] << "]): " | ||
| 108 | << ex.what(); | ||
| 109 | throw FileError(errstr.str()); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | /*----------------------------------------------------------------------------*/ | ||
| 116 | |||
| 117 | /* TODO */ | ||
| 118 | void CBitmap::invert(std::list<std::string> params) | ||
| 119 | { | ||
| 120 | /* check prerequirements */ | ||
| 121 | if (params.size() != 0) | ||
| 122 | throw FileError("Invalid number of function parameters (must be 0)."); | ||
| 123 | |||
| 124 | /* do nothing if no pixel exists */ | ||
| 125 | if (m_pixeldata == NULL || m_pixelformat == NULL) | ||
| 126 | return; | ||
| 127 | |||
| 128 | /* TODO pixelwidth */ | ||
| 129 | unsigned int pixelwidth = m_pixelformat->getBitCount()/8; | ||
| 130 | |||
| 131 | /* calc rowsize - boundary is 32 */ | ||
| 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 | { | ||
| 138 | for(uint32_t j = 0; j <= getWidth(); j++) | ||
| 139 | { | ||
| 140 | /*TODO cout << j << endl;*/ | ||
| 141 | break; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | #if 0 | ||
| 146 | uint32_t offset = i * rowsize; | ||
| 147 | |||
| 148 | for(uint32_t j = 0; j <= getWidth()/2; j++) | ||
| 149 | { | ||
| 150 | uint32_t poffset = offset + j * pixelwidth; | ||
| 151 | uint32_t pbackset = offset + getWidth() * pixelwidth - j * pixelwidth; | ||
| 152 | |||
| 153 | /* boundary check */ | ||
| 154 | if (pbackset > m_infoheader.biSizeImage) | ||
| 155 | throw FileError("Mirrored pixel position is out of range."); | ||
| 156 | |||
| 157 | /* mirroring, backup right data first */ | ||
| 158 | copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf); | ||
| 159 | copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth); | ||
| 160 | copy(buf, buf + pixelwidth, m_pixeldata + poffset); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | #endif | ||
| 164 | } | ||
| 165 | |||
| 166 | /*----------------------------------------------------------------------------*/ | ||
| 167 | |||
| 168 | /* TODO */ | ||
| 169 | void CBitmap::brightness(std::list<std::string> params) | ||
| 170 | { | ||
| 171 | } | ||
| 172 | |||
| 173 | /*----------------------------------------------------------------------------*/ | ||
| 174 | |||
| 175 | void CBitmap::mirror_y(std::list<std::string> params) | ||
| 176 | { | ||
| 177 | /* check prerequirements */ | ||
| 178 | if (params.size() != 0) | ||
| 179 | throw FileError("Invalid number of function parameters (must be 0)."); | ||
| 180 | |||
| 181 | /* do nothing if no pixel exists */ | ||
| 182 | if (m_pixeldata == NULL || m_pixelformat == NULL) | ||
| 183 | return; | ||
| 184 | |||
| 185 | /* calc rowsize - boundary is 32 */ | ||
| 186 | uint32_t rowsize = 4 * static_cast<uint32_t>( | ||
| 187 | ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32 | ||
| 188 | ); | ||
| 189 | |||
| 190 | uint8_t *buf = new uint8_t[rowsize]; | ||
| 191 | for(uint32_t i = 0; i < getHeight()/2; i++) | ||
| 192 | { | ||
| 193 | uint32_t j = getHeight() - i - 1; | ||
| 194 | uint32_t offset = i * rowsize; | ||
| 195 | uint32_t backset = j * rowsize; | ||
| 196 | |||
| 197 | /* boundary check */ | ||
| 198 | if (offset + rowsize > getPixelDataSize() | ||
| 199 | || backset + rowsize > getPixelDataSize()) | ||
| 200 | throw FileError("Mirrored pixel position is out of range."); | ||
| 201 | |||
| 202 | /* mirroring, backup lower data first */ | ||
| 203 | copy(m_pixeldata + backset, m_pixeldata + backset + rowsize, buf); | ||
| 204 | copy(m_pixeldata + offset, m_pixeldata + offset + rowsize, m_pixeldata + backset); | ||
| 205 | copy(buf, buf + rowsize, m_pixeldata + offset); | ||
| 206 | } | ||
| 207 | delete[] buf; | ||
| 208 | } | ||
| 209 | |||
| 210 | /*----------------------------------------------------------------------------*/ | ||
| 211 | |||
| 212 | void CBitmap::mirror_x(std::list<std::string> params) | ||
| 213 | { | ||
| 214 | /* check prerequirements */ | ||
| 215 | if (params.size() != 0) | ||
| 216 | throw FileError("Invalid number of function parameters (must be 0)."); | ||
| 217 | |||
| 218 | /* do nothing if no pixel exists */ | ||
| 219 | if (m_pixeldata == NULL || m_pixelformat == NULL) | ||
| 220 | return; | ||
| 221 | |||
| 222 | /* calc rowsize - boundary is 32 */ | ||
| 223 | uint32_t rowsize = 4 * static_cast<uint32_t>( | ||
| 224 | ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32 | ||
| 225 | ); | ||
| 226 | |||
| 227 | /* calc pixelwidth */ | ||
| 228 | unsigned int pixelwidth = m_pixelformat->getBitCount()/8; | ||
| 229 | |||
| 230 | uint8_t *buf = new uint8_t[pixelwidth]; | ||
| 231 | for(uint32_t i = 0; i < getHeight(); i++) | ||
| 232 | { | ||
| 233 | uint32_t offset = i * rowsize; | ||
| 234 | |||
| 235 | for(uint32_t j = 0; j <= getWidth()/2; j++) | ||
| 236 | { | ||
| 237 | uint32_t poffset = offset + j * pixelwidth; | ||
| 238 | uint32_t pbackset = offset + getWidth() * pixelwidth - j * pixelwidth; | ||
| 239 | |||
| 240 | /* boundary check */ | ||
| 241 | if (pbackset > getPixelDataSize()) | ||
| 242 | throw FileError("Mirrored pixel position is out of range."); | ||
| 243 | |||
| 244 | /* mirroring, backup right data first */ | ||
| 245 | copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf); | ||
| 246 | copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth); | ||
| 247 | copy(buf, buf + pixelwidth, m_pixeldata + poffset); | ||
| 248 | } | ||
| 249 | } | ||
| 250 | delete[] buf; | ||
| 251 | } | ||
| 252 | |||
| 253 | /* vim: set et sw=2 ts=2: */ | ||
diff --git a/ue2/imgsynth2/cbitmap.h b/ue2/imgsynth2/cbitmap.h index c43e01d..c8a7f0d 100644 --- a/ue2/imgsynth2/cbitmap.h +++ b/ue2/imgsynth2/cbitmap.h | |||
| @@ -1,7 +1,7 @@ | |||
| 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 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 | ||
| @@ -37,8 +37,10 @@ class CBitmap : public CFile | |||
| 37 | * @conditions none | 37 | * @conditions none |
| 38 | */ | 38 | */ |
| 39 | CBitmap() | 39 | CBitmap() |
| 40 | : m_pixeldata(NULL), m_pixelformat(NULL) | ||
| 40 | {} | 41 | {} |
| 41 | 42 | ||
| 43 | |||
| 42 | /** | 44 | /** |
| 43 | * @method ~CBitmap | 45 | * @method ~CBitmap |
| 44 | * @brief Default dtor | 46 | * @brief Default dtor |
| @@ -48,8 +50,7 @@ class CBitmap : public CFile | |||
| 48 | * @exception none | 50 | * @exception none |
| 49 | * @conditions none | 51 | * @conditions none |
| 50 | */ | 52 | */ |
| 51 | virtual ~CBitmap() | 53 | virtual ~CBitmap(); |
| 52 | {}; | ||
| 53 | 54 | ||
| 54 | /** | 55 | /** |
| 55 | * TODO | 56 | * TODO |
| @@ -62,9 +63,75 @@ class CBitmap : public CFile | |||
| 62 | virtual void write(std::ofstream& out) = 0; | 63 | virtual void write(std::ofstream& out) = 0; |
| 63 | 64 | ||
| 64 | /** | 65 | /** |
| 65 | * TODO | 66 | * @method getPixelData |
| 67 | * @brief Returns pointer to pixelbuffer | ||
| 68 | * @param - | ||
| 69 | * @return pointer to pixelbuffer | ||
| 70 | * @globalvars none | ||
| 71 | * @exception none | ||
| 72 | * @conditions none | ||
| 73 | */ | ||
| 74 | uint8_t *getPixelData() | ||
| 75 | { | ||
| 76 | return m_pixeldata; | ||
| 77 | } | ||
| 78 | |||
| 79 | /* TODO */ | ||
| 80 | virtual const uint32_t getPixelDataSize() = 0; | ||
| 81 | /* TODO */ | ||
| 82 | virtual const uint32_t getHeight() = 0; | ||
| 83 | /* TODO */ | ||
| 84 | virtual const uint32_t getWidth() = 0; | ||
| 85 | /* TODO */ | ||
| 86 | virtual const bool isMirrored() = 0; | ||
| 87 | |||
| 88 | protected: | ||
| 89 | /** | ||
| 90 | * @method callFunc | ||
| 91 | * @brief Delegates the function and its parameters to the correct | ||
| 92 | * internal method | ||
| 93 | * @param func function name | ||
| 94 | * @param params function parameters as list | ||
| 95 | * @return - | ||
| 96 | * @globalvars none | ||
| 97 | * @exception ParserError | ||
| 98 | * @conditions none | ||
| 99 | */ | ||
| 100 | void callFunc(const std::string& func, const std::list<std::string>& params); | ||
| 101 | |||
| 102 | /** | ||
| 103 | * @method fillrect | ||
| 104 | * @brief Fills rectangle in image starting on position x, y | ||
| 105 | * width size width, height and color red, green, blue. | ||
| 106 | * @param params function parameters as list | ||
| 107 | * @return - | ||
| 108 | * @globalvars none | ||
| 109 | * @exception FileError | ||
| 110 | * @conditions none | ||
| 111 | * | ||
| 112 | * Scriptfile syntax: fillrect(x, y, width, height, red, green, blue) | ||
| 66 | */ | 113 | */ |
| 67 | virtual void callFunc(const std::string& func, const std::list<std::string>& params) = 0; | 114 | void fillrect(std::list<std::string> params); |
| 115 | |||
| 116 | /* TODO */ | ||
| 117 | void invert(std::list<std::string> params); | ||
| 118 | |||
| 119 | /* TODO */ | ||
| 120 | void brightness(std::list<std::string> params); | ||
| 121 | |||
| 122 | /* TODO */ | ||
| 123 | void mirror_y(std::list<std::string> params); | ||
| 124 | |||
| 125 | /* TODO */ | ||
| 126 | void mirror_x(std::list<std::string> params); | ||
| 127 | |||
| 128 | /* members */ | ||
| 129 | /** pointer to pixelbuffer */ | ||
| 130 | uint8_t *m_pixeldata; | ||
| 131 | /** set of supported PixelFormat handlers */ | ||
| 132 | std::set<CPixelFormat *> m_handlers; | ||
| 133 | /** pointer to CPixelFormat implementation */ | ||
| 134 | CPixelFormat *m_pixelformat; | ||
| 68 | }; | 135 | }; |
| 69 | 136 | ||
| 70 | #endif | 137 | #endif |
diff --git a/ue2/imgsynth2/cpixelformat.h b/ue2/imgsynth2/cpixelformat.h index 0568dd4..911a141 100644 --- a/ue2/imgsynth2/cpixelformat.h +++ b/ue2/imgsynth2/cpixelformat.h | |||
| @@ -95,7 +95,7 @@ class CPixelFormat | |||
| 95 | * @exception PixelFormatError | 95 | * @exception PixelFormatError |
| 96 | * @conditions none | 96 | * @conditions none |
| 97 | */ | 97 | */ |
| 98 | virtual void getPixel(const uint32_t *pixel, const uint32_t x, const uint32_t y) = 0; | 98 | virtual void getPixel(uint32_t *pixel, const uint32_t x, const uint32_t y) = 0; |
| 99 | 99 | ||
| 100 | /** | 100 | /** |
| 101 | * @method getBitCount | 101 | * @method getBitCount |
diff --git a/ue2/imgsynth2/cpixelformat_bgr24.cpp b/ue2/imgsynth2/cpixelformat_bgr24.cpp index cc02dcc..4567ce6 100644 --- a/ue2/imgsynth2/cpixelformat_bgr24.cpp +++ b/ue2/imgsynth2/cpixelformat_bgr24.cpp | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | using namespace std; | 11 | using namespace std; |
| 12 | 12 | ||
| 13 | /* TODO */ | ||
| 13 | void CPixelFormat_BGR24::getPixel(uint32_t *pixel, uint32_t x, uint32_t y) | 14 | void CPixelFormat_BGR24::getPixel(uint32_t *pixel, uint32_t x, uint32_t y) |
| 14 | { | 15 | { |
| 15 | /* | 16 | /* |
| @@ -22,16 +23,16 @@ void CPixelFormat_BGR24::getPixel(uint32_t *pixel, uint32_t x, uint32_t y) | |||
| 22 | 23 | ||
| 23 | /* calc rowsize - boundary is 32 */ | 24 | /* calc rowsize - boundary is 32 */ |
| 24 | uint32_t rowsize = 4 * static_cast<uint32_t>( | 25 | uint32_t rowsize = 4 * static_cast<uint32_t>( |
| 25 | ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32 | 26 | ((getBitCount() * m_bitmap->getWidth()) + 31) / 32 |
| 26 | ); | 27 | ); |
| 27 | 28 | ||
| 28 | /* if height is positive the y-coordinates are mirrored */ | 29 | /* if the y-coordinates are mirrored */ |
| 29 | if (m_bitmap->getInfoHeader().biHeight > 0) | 30 | if (m_bitmap->isMirrored()) |
| 30 | y = m_bitmap->getInfoHeader().biHeight - y - 1; | 31 | y = m_bitmap->getHeight() - y - 1; |
| 31 | uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); | 32 | uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); |
| 32 | 33 | ||
| 33 | /* boundary check */ | 34 | /* boundary check */ |
| 34 | if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) | 35 | if (offset + getBitCount()/8 > m_bitmap->getPixelDataSize()) |
| 35 | throw PixelFormatError("Pixel position is out of range."); | 36 | throw PixelFormatError("Pixel position is out of range."); |
| 36 | 37 | ||
| 37 | /* get pixel */ | 38 | /* get pixel */ |
| @@ -59,16 +60,16 @@ void CPixelFormat_BGR24::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) | |||
| 59 | 60 | ||
| 60 | /* calc rowsize - boundary is 32 */ | 61 | /* calc rowsize - boundary is 32 */ |
| 61 | uint32_t rowsize = 4 * static_cast<uint32_t>( | 62 | uint32_t rowsize = 4 * static_cast<uint32_t>( |
| 62 | ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32 | 63 | ((getBitCount() * m_bitmap->getWidth()) + 31) / 32 |
| 63 | ); | 64 | ); |
| 64 | 65 | ||
| 65 | /* if height is positive the y-coordinates are mirrored */ | 66 | /* if the y-coordinates are mirrored */ |
| 66 | if (m_bitmap->getInfoHeader().biHeight > 0) | 67 | if (m_bitmap->isMirrored()) |
| 67 | y = m_bitmap->getInfoHeader().biHeight - y - 1; | 68 | y = m_bitmap->getHeight() - y - 1; |
| 68 | uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); | 69 | uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); |
| 69 | 70 | ||
| 70 | /* boundary check */ | 71 | /* boundary check */ |
| 71 | if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) | 72 | if (offset + getBitCount()/8 > m_bitmap->getPixelDataSize()) |
| 72 | throw PixelFormatError("Pixel position is out of range."); | 73 | throw PixelFormatError("Pixel position is out of range."); |
| 73 | 74 | ||
| 74 | /* convert color values to correct types */ | 75 | /* convert color values to correct types */ |
diff --git a/ue2/imgsynth2/cpixelformat_bgr24.h b/ue2/imgsynth2/cpixelformat_bgr24.h index c3e1b72..73f22c1 100644 --- a/ue2/imgsynth2/cpixelformat_bgr24.h +++ b/ue2/imgsynth2/cpixelformat_bgr24.h | |||
| @@ -45,6 +45,9 @@ class CPixelFormat_BGR24 : public CPixelFormat | |||
| 45 | ~CPixelFormat_BGR24() | 45 | ~CPixelFormat_BGR24() |
| 46 | {} | 46 | {} |
| 47 | 47 | ||
| 48 | /* TODO */ | ||
| 49 | void getPixel(uint32_t *pixel, uint32_t x, uint32_t y); | ||
| 50 | |||
| 48 | /** | 51 | /** |
| 49 | * @method setPixel | 52 | * @method setPixel |
| 50 | * @brief Modifies pixel at coordinates x, y | 53 | * @brief Modifies pixel at coordinates x, y |
| @@ -58,9 +61,6 @@ class CPixelFormat_BGR24 : public CPixelFormat | |||
| 58 | */ | 61 | */ |
| 59 | void setPixel(const uint32_t *pixel, uint32_t x, uint32_t y); | 62 | void setPixel(const uint32_t *pixel, uint32_t x, uint32_t y); |
| 60 | 63 | ||
| 61 | /* TODO */ | ||
| 62 | void getPixel(uint32_t *pixel, uint32_t x, uint32_t y); | ||
| 63 | |||
| 64 | /** | 64 | /** |
| 65 | * @method getBitCount | 65 | * @method getBitCount |
| 66 | * @brief returns color bitcount supported by this class | 66 | * @brief returns color bitcount supported by this class |
diff --git a/ue2/imgsynth2/cpixelformat_bgr555.cpp b/ue2/imgsynth2/cpixelformat_bgr555.cpp index 4a3c833..19c98a8 100644 --- a/ue2/imgsynth2/cpixelformat_bgr555.cpp +++ b/ue2/imgsynth2/cpixelformat_bgr555.cpp | |||
| @@ -11,6 +11,22 @@ | |||
| 11 | 11 | ||
| 12 | using namespace std; | 12 | using namespace std; |
| 13 | 13 | ||
| 14 | /* TODO */ | ||
| 15 | void CPixelFormat_BGR555::getPixel(uint32_t *pixel, uint32_t x, uint32_t y) | ||
| 16 | { | ||
| 17 | /* | ||
| 18 | * pixel[0] ... red | ||
| 19 | * pixel[1] ... green | ||
| 20 | * pixel[2] ... blue | ||
| 21 | */ | ||
| 22 | if (m_bitmap->getPixelData() == NULL) | ||
| 23 | throw PixelFormatError("No pixelbuffer allocated."); | ||
| 24 | |||
| 25 | throw PixelFormatError("NOT IMPLEMENTED"); | ||
| 26 | } | ||
| 27 | |||
| 28 | /*----------------------------------------------------------------------------*/ | ||
| 29 | |||
| 14 | void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) | 30 | void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) |
| 15 | { | 31 | { |
| 16 | /* | 32 | /* |
| @@ -24,16 +40,16 @@ void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y | |||
| 24 | 40 | ||
| 25 | /* calc rowsize - boundary is 32 */ | 41 | /* calc rowsize - boundary is 32 */ |
| 26 | uint32_t rowsize = 4 * static_cast<uint32_t>( | 42 | uint32_t rowsize = 4 * static_cast<uint32_t>( |
| 27 | ((CPixelFormat_BGR555::getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32 | 43 | ((getBitCount() * m_bitmap->getWidth()) + 31) / 32 |
| 28 | ); | 44 | ); |
| 29 | 45 | ||
| 30 | /* if height is positive the y-coordinates are mirrored */ | 46 | /* if the y-coordinates are mirrored */ |
| 31 | if (m_bitmap->getInfoHeader().biHeight > 0) | 47 | if (m_bitmap->isMirrored()) |
| 32 | y = m_bitmap->getInfoHeader().biHeight - y - 1; | 48 | y = m_bitmap->getHeight() - y - 1; |
| 33 | uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); | 49 | uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); |
| 34 | 50 | ||
| 35 | /* boundary check */ | 51 | /* boundary check */ |
| 36 | if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) | 52 | if (offset + getBitCount()/8 > m_bitmap->getPixelDataSize()) |
| 37 | throw PixelFormatError("Pixel position is out of range."); | 53 | throw PixelFormatError("Pixel position is out of range."); |
| 38 | 54 | ||
| 39 | /* convert color values to correct types */ | 55 | /* convert color values to correct types */ |
diff --git a/ue2/imgsynth2/cpixelformat_bgr555.h b/ue2/imgsynth2/cpixelformat_bgr555.h index 7a49c7c..b04e4be 100644 --- a/ue2/imgsynth2/cpixelformat_bgr555.h +++ b/ue2/imgsynth2/cpixelformat_bgr555.h | |||
| @@ -55,6 +55,9 @@ class CPixelFormat_BGR555 : public CPixelFormat | |||
| 55 | ~CPixelFormat_BGR555() | 55 | ~CPixelFormat_BGR555() |
| 56 | {} | 56 | {} |
| 57 | 57 | ||
| 58 | /* TODO */ | ||
| 59 | void getPixel(uint32_t *pixel, uint32_t x, uint32_t y); | ||
| 60 | |||
| 58 | /** | 61 | /** |
| 59 | * @method setPixel | 62 | * @method setPixel |
| 60 | * @brief Modifies pixel at coordinates x, y | 63 | * @brief Modifies pixel at coordinates x, y |
diff --git a/ue2/imgsynth2/cscriptparser.cpp b/ue2/imgsynth2/cscriptparser.cpp index df3df1e..ea9b242 100644 --- a/ue2/imgsynth2/cscriptparser.cpp +++ b/ue2/imgsynth2/cscriptparser.cpp | |||
| @@ -9,7 +9,7 @@ | |||
| 9 | #include <boost/tokenizer.hpp> | 9 | #include <boost/tokenizer.hpp> |
| 10 | #include <boost/algorithm/string.hpp> | 10 | #include <boost/algorithm/string.hpp> |
| 11 | #include "cscriptparser.h" | 11 | #include "cscriptparser.h" |
| 12 | #include "cbitmap.h" | 12 | #include "cwindowsbitmap.h" |
| 13 | 13 | ||
| 14 | using namespace std; | 14 | using namespace std; |
| 15 | using namespace boost; | 15 | using namespace boost; |
| @@ -18,7 +18,7 @@ CScriptparser::CScriptparser(const std::string& scriptfile) | |||
| 18 | : m_scriptfile(scriptfile), m_handler(NULL) | 18 | : m_scriptfile(scriptfile), m_handler(NULL) |
| 19 | { | 19 | { |
| 20 | /* add our handlers */ | 20 | /* add our handlers */ |
| 21 | m_handlers.insert(new CBitmap); | 21 | m_handlers.insert(new CWindowsBitmap); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | /*----------------------------------------------------------------------------*/ | 24 | /*----------------------------------------------------------------------------*/ |
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 @@ | |||
| 17 | using namespace std; | 17 | using namespace std; |
| 18 | 18 | ||
| 19 | CWindowsBitmap::CWindowsBitmap() | 19 | CWindowsBitmap::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 | ||
| 116 | void 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 | |||
| 135 | void 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> | ||
| 206 | void 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 | |||
| 257 | void CWindowsBitmap::brightness(std::list<std::string> params) | ||
| 258 | { | ||
| 259 | } | ||
| 260 | |||
| 261 | /*----------------------------------------------------------------------------*/ | ||
| 262 | |||
| 263 | void 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; | ||
| 272 | W | ||
| 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 | |||
| 303 | void 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 |
| 351 | void CWindowsBitmap::dump(std::ostream& out) | 116 | void CWindowsBitmap::dump(std::ostream& out) |
| 352 | { | 117 | { |
diff --git a/ue2/imgsynth2/cwindowsbitmap.h b/ue2/imgsynth2/cwindowsbitmap.h index 420ad1e..d348a93 100644 --- a/ue2/imgsynth2/cwindowsbitmap.h +++ b/ue2/imgsynth2/cwindowsbitmap.h | |||
| @@ -11,17 +11,10 @@ | |||
| 11 | #include <stdint.h> | 11 | #include <stdint.h> |
| 12 | #include "cbitmap.h" | 12 | #include "cbitmap.h" |
| 13 | 13 | ||
| 14 | class CPixelFormat; | ||
| 15 | #include "cpixelformat.h" | ||
| 16 | |||
| 17 | /** | 14 | /** |
| 18 | * @class CWindowsBitmap | 15 | * @class CWindowsBitmap |
| 19 | * @brief Implementation of CBitmap handling Windows Bitmaps. | 16 | * @brief Implementation of CBitmap handling Windows Bitmaps. |
| 20 | * | 17 | * |
| 21 | * In order to support operations on bitmaps with different color bitcounts | ||
| 22 | * different implementations of CPixelFormat are used. These classes are | ||
| 23 | * allowed to modify the bitmap headers and pixelbuffer directly. | ||
| 24 | * | ||
| 25 | * On error CFile::FileError is thrown. | 18 | * On error CFile::FileError is thrown. |
| 26 | */ | 19 | */ |
| 27 | class CWindowsBitmap : public CBitmap | 20 | class CWindowsBitmap : public CBitmap |
| @@ -74,19 +67,6 @@ class CWindowsBitmap : public CBitmap | |||
| 74 | */ | 67 | */ |
| 75 | void write(std::ofstream& out); | 68 | void write(std::ofstream& out); |
| 76 | 69 | ||
| 77 | /** | ||
| 78 | * @method callFunc | ||
| 79 | * @brief Delegates the function and its parameters to the correct | ||
| 80 | * internal method | ||
| 81 | * @param func function name | ||
| 82 | * @param params function parameters as list | ||
| 83 | * @return - | ||
| 84 | * @globalvars none | ||
| 85 | * @exception ParserError | ||
| 86 | * @conditions none | ||
| 87 | */ | ||
| 88 | void callFunc(const std::string& func, const std::list<std::string>& params); | ||
| 89 | |||
| 90 | #ifdef DEBUG | 70 | #ifdef DEBUG |
| 91 | /** | 71 | /** |
| 92 | * @method dump | 72 | * @method dump |
| @@ -177,58 +157,39 @@ class CWindowsBitmap : public CBitmap | |||
| 177 | return m_infoheader; | 157 | return m_infoheader; |
| 178 | } | 158 | } |
| 179 | 159 | ||
| 180 | /** | 160 | /* TODO */ |
| 181 | * @method getPixelData | 161 | const uint32_t getPixelDataSize() |
| 182 | * @brief Returns pointer to pixelbuffer | ||
| 183 | * @param - | ||
| 184 | * @return pointer to pixelbuffer | ||
| 185 | * @globalvars none | ||
| 186 | * @exception none | ||
| 187 | * @conditions none | ||
| 188 | */ | ||
| 189 | uint8_t *getPixelData() | ||
| 190 | { | 162 | { |
| 191 | return m_pixeldata; | 163 | return m_infoheader.biSizeImage; |
| 192 | } | 164 | } |
| 193 | 165 | ||
| 194 | protected: | ||
| 195 | /** | ||
| 196 | * @method fillrect | ||
| 197 | * @brief Fills rectangle in image starting on position x, y | ||
| 198 | * width size width, height and color red, green, blue. | ||
| 199 | * @param params function parameters as list | ||
| 200 | * @return - | ||
| 201 | * @globalvars none | ||
| 202 | * @exception FileError | ||
| 203 | * @conditions none | ||
| 204 | * | ||
| 205 | * Scriptfile syntax: fillrect(x, y, width, height, red, green, blue) | ||
| 206 | */ | ||
| 207 | void fillrect(std::list<std::string> params); | ||
| 208 | |||
| 209 | /* TODO */ | ||
| 210 | void invert(std::list<std::string> params); | ||
| 211 | |||
| 212 | /* TODO */ | 166 | /* TODO */ |
| 213 | void brightness(std::list<std::string> params); | 167 | const uint32_t getHeight() |
| 168 | { | ||
| 169 | /* width and height can be negativ */ | ||
| 170 | return static_cast<uint32_t>(abs(m_infoheader.biHeight)); | ||
| 171 | } | ||
| 214 | 172 | ||
| 215 | /* TODO */ | 173 | /* TODO */ |
| 216 | void mirror_y(std::list<std::string> params); | 174 | const uint32_t getWidth() |
| 175 | { | ||
| 176 | /* width and height can be negativ */ | ||
| 177 | return static_cast<uint32_t>(abs(m_infoheader.biWidth)); | ||
| 178 | } | ||
| 217 | 179 | ||
| 218 | /* TODO */ | 180 | /* TODO */ |
| 219 | void mirror_x(std::list<std::string> params); | 181 | const bool isMirrored() |
| 182 | { | ||
| 183 | /* if height is positive the y-coordinates are mirrored */ | ||
| 184 | return (m_infoheader.biHeight > 0) ? true : false; | ||
| 185 | } | ||
| 220 | 186 | ||
| 187 | protected: | ||
| 221 | /* members */ | 188 | /* members */ |
| 222 | /** fileheader */ | 189 | /** fileheader */ |
| 223 | BITMAP_FILEHEADER m_fileheader; | 190 | BITMAP_FILEHEADER m_fileheader; |
| 224 | /** infoheader */ | 191 | /** infoheader */ |
| 225 | BITMAP_INFOHEADER m_infoheader; | 192 | BITMAP_INFOHEADER m_infoheader; |
| 226 | /** pointer to pixelbuffer */ | ||
| 227 | uint8_t *m_pixeldata; | ||
| 228 | /** set of supported PixelFormat handlers */ | ||
| 229 | std::set<CPixelFormat *> m_handlers; | ||
| 230 | /** pointer to CPixelFormat implementation */ | ||
| 231 | CPixelFormat *m_pixelformat; | ||
| 232 | }; | 193 | }; |
| 233 | 194 | ||
| 234 | #endif | 195 | #endif |
