From 5f499a8233c7bb68b52b8fdeddac9a06061ea4d7 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 28 Apr 2009 18:32:15 +0200 Subject: Moved a lot of stuff around to get abstract cbitmap working --- ue2/imgsynth2/Makefile | 9 +- ue2/imgsynth2/cbitmap.cpp | 253 ++++++++++++++++++++++++++++++++++ ue2/imgsynth2/cbitmap.h | 77 ++++++++++- ue2/imgsynth2/cpixelformat.h | 2 +- ue2/imgsynth2/cpixelformat_bgr24.cpp | 21 +-- ue2/imgsynth2/cpixelformat_bgr24.h | 6 +- ue2/imgsynth2/cpixelformat_bgr555.cpp | 26 +++- ue2/imgsynth2/cpixelformat_bgr555.h | 3 + ue2/imgsynth2/cscriptparser.cpp | 4 +- ue2/imgsynth2/cwindowsbitmap.cpp | 235 ------------------------------- ue2/imgsynth2/cwindowsbitmap.h | 77 +++-------- 11 files changed, 390 insertions(+), 323 deletions(-) create mode 100644 ue2/imgsynth2/cbitmap.cpp (limited to 'ue2/imgsynth2') 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 @@ CC= g++ LD= $(CC) DEBUGFLAGS= -DNDEBUG -CFLAGS= -O -ansi -pedantic-errors -Wall $(DEBUGFLAGS) +#TODO CFLAGS= -O -ansi -pedantic-errors -Wall -I/usr/local/include $(DEBUGFLAGS) +CFLAGS= -O -ansi -Wall -I/usr/local/include $(DEBUGFLAGS) LDFLAGS= -LIBS= -lboost_program_options +LIBS= -L/usr/local/lib -lboost_program_options BIN= imgsynth2 OBJS= cpixelformat_bgr24.o cpixelformat_bgr555.o \ - cbitmap.o cscriptparser.o imgsynth2.o + cwindowsbitmap.o cbitmap.o cscriptparser.o imgsynth2.o HEADERS= cpixelformat.h cpixelformat_bgr24.h cpixelformat_bgr555.h \ - cfile.h cbitmap.h cscriptparser.h + cfile.h cbitmap.h cwindowsbitmap.h cscriptparser.h .SUFFIXES: .cpp .o 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 @@ +/** + * @module cbitmap + * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) + * @brief Abstract implementation of CFile handling Bitmaps. + * @date 17.04.2009 + */ + +#include +#include +#include "cbitmap.h" + +using namespace std; + +/*----------------------------------------------------------------------------*/ + +CBitmap::~CBitmap() +{ + /* delete pixeldata */ + if (m_pixeldata != NULL) + delete[] m_pixeldata; + m_pixeldata = NULL; + + /* delete pixelformat handlers */ + set::iterator it; + for (it = m_handlers.begin(); it != m_handlers.end(); it++) + delete *it; + m_pixelformat = NULL; +} + +/*----------------------------------------------------------------------------*/ + +void CBitmap::callFunc(const std::string& func, const std::list& params) +{ + if (func.empty()) + throw FileError("Function name is empty."); + + if (func == "fillrect") + fillrect(params); + else if (func == "mirror_x") + mirror_x(params); + else if (func == "mirror_y") + mirror_y(params); + else if (func == "invert") + invert(params); + else + throw FileError("Unknown function '" + func + "'."); +} + +/*----------------------------------------------------------------------------*/ + +void CBitmap::fillrect(std::list params) +{ + /* check prerequirements */ + if (params.size() != 7) + throw FileError("Invalid number of function parameters (must be 7)."); + + /* do nothing if no pixel exists */ + if (m_pixeldata == NULL || m_pixelformat == NULL) + return; + + /* convert parameters */ + uint32_t pparams[7]; + int i = 0; + try + { + for(i = 0; i < 7; i++) + { + pparams[i] = boost::lexical_cast(params.front()); + params.pop_front(); + } + } + catch(boost::bad_lexical_cast& ex) + { + throw FileError("Invalid parameter (" + params.front() + ")."); + } + + /* check parameter values are in range */ + if (pparams[0] < 0 || pparams[0] > getWidth() + || pparams[1] < 0 || pparams[1] > getHeight()) + throw FileError("At least one x/y-parameter is out of range."); + + /* check parameter values are in range */ + unsigned int max[3]; + m_pixelformat->getMaxColor(&max[0], &max[1], &max[2]); + if (pparams[4] < 0 || pparams[4] > max[0] + || pparams[5] < 0 || pparams[5] > max[1] + || pparams[6] < 0 || pparams[6] > max[2]) + throw FileError("At least one pixel color parameter is out of range."); + + if (pparams[2] < 0 || pparams[2] + pparams[0] > getWidth() + || pparams[3] < 0 || pparams[3] + pparams[1] > getHeight()) + throw FileError("At least one w/h-parameter is out of range."); + + /* call setPixel for every pixel in the rectangel */ + for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++) + { + for(uint32_t j = pparams[1]; j < pparams[3] + pparams[1]; j++) + { + try + { + m_pixelformat->setPixel(&pparams[4], i, j); + } + catch(CPixelFormat::PixelFormatError& ex) + { + stringstream errstr; + errstr << "Can't set pixel (pos=[" << i << "," << j << "] col=[" + << pparams[4] << "," << pparams[5] << "," << pparams[6] << "]): " + << ex.what(); + throw FileError(errstr.str()); + } + } + } +} + +/*----------------------------------------------------------------------------*/ + +/* TODO */ +void CBitmap::invert(std::list params) +{ + /* check prerequirements */ + if (params.size() != 0) + throw FileError("Invalid number of function parameters (must be 0)."); + + /* do nothing if no pixel exists */ + if (m_pixeldata == NULL || m_pixelformat == NULL) + return; + + /* TODO pixelwidth */ + unsigned int pixelwidth = m_pixelformat->getBitCount()/8; + + /* calc rowsize - boundary is 32 */ + uint32_t rowsize = 4 * static_cast( + ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32 + ); + + for(uint32_t i = 0; i < getHeight(); i++) + { + for(uint32_t j = 0; j <= getWidth(); j++) + { + /*TODO cout << j << endl;*/ + break; + } + } + +#if 0 + uint32_t offset = i * rowsize; + + for(uint32_t j = 0; j <= getWidth()/2; j++) + { + uint32_t poffset = offset + j * pixelwidth; + uint32_t pbackset = offset + getWidth() * pixelwidth - j * pixelwidth; + + /* boundary check */ + if (pbackset > m_infoheader.biSizeImage) + throw FileError("Mirrored pixel position is out of range."); + + /* mirroring, backup right data first */ + copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf); + copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth); + copy(buf, buf + pixelwidth, m_pixeldata + poffset); + } + } +#endif +} + +/*----------------------------------------------------------------------------*/ + +/* TODO */ +void CBitmap::brightness(std::list params) +{ +} + +/*----------------------------------------------------------------------------*/ + +void CBitmap::mirror_y(std::list params) +{ + /* check prerequirements */ + if (params.size() != 0) + throw FileError("Invalid number of function parameters (must be 0)."); + + /* do nothing if no pixel exists */ + if (m_pixeldata == NULL || m_pixelformat == NULL) + return; + + /* calc rowsize - boundary is 32 */ + uint32_t rowsize = 4 * static_cast( + ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32 + ); + + uint8_t *buf = new uint8_t[rowsize]; + for(uint32_t i = 0; i < getHeight()/2; i++) + { + uint32_t j = getHeight() - i - 1; + uint32_t offset = i * rowsize; + uint32_t backset = j * rowsize; + + /* boundary check */ + if (offset + rowsize > getPixelDataSize() + || backset + rowsize > getPixelDataSize()) + throw FileError("Mirrored pixel position is out of range."); + + /* mirroring, backup lower data first */ + copy(m_pixeldata + backset, m_pixeldata + backset + rowsize, buf); + copy(m_pixeldata + offset, m_pixeldata + offset + rowsize, m_pixeldata + backset); + copy(buf, buf + rowsize, m_pixeldata + offset); + } + delete[] buf; +} + +/*----------------------------------------------------------------------------*/ + +void CBitmap::mirror_x(std::list params) +{ + /* check prerequirements */ + if (params.size() != 0) + throw FileError("Invalid number of function parameters (must be 0)."); + + /* do nothing if no pixel exists */ + if (m_pixeldata == NULL || m_pixelformat == NULL) + return; + + /* calc rowsize - boundary is 32 */ + uint32_t rowsize = 4 * static_cast( + ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32 + ); + + /* calc pixelwidth */ + unsigned int pixelwidth = m_pixelformat->getBitCount()/8; + + uint8_t *buf = new uint8_t[pixelwidth]; + for(uint32_t i = 0; i < getHeight(); i++) + { + uint32_t offset = i * rowsize; + + for(uint32_t j = 0; j <= getWidth()/2; j++) + { + uint32_t poffset = offset + j * pixelwidth; + uint32_t pbackset = offset + getWidth() * pixelwidth - j * pixelwidth; + + /* boundary check */ + if (pbackset > getPixelDataSize()) + throw FileError("Mirrored pixel position is out of range."); + + /* mirroring, backup right data first */ + copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf); + copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth); + copy(buf, buf + pixelwidth, m_pixeldata + poffset); + } + } + delete[] buf; +} + +/* 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 @@ /** * @module cbitmap * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) - * @brief Implementation of CFile handling Bitmaps. + * @brief Abstract implementation of CFile handling Bitmaps. * @date 17.04.2009 */ @@ -37,8 +37,10 @@ class CBitmap : public CFile * @conditions none */ CBitmap() + : m_pixeldata(NULL), m_pixelformat(NULL) {} + /** * @method ~CBitmap * @brief Default dtor @@ -48,8 +50,7 @@ class CBitmap : public CFile * @exception none * @conditions none */ - virtual ~CBitmap() - {}; + virtual ~CBitmap(); /** * TODO @@ -62,9 +63,75 @@ class CBitmap : public CFile virtual void write(std::ofstream& out) = 0; /** - * TODO + * @method getPixelData + * @brief Returns pointer to pixelbuffer + * @param - + * @return pointer to pixelbuffer + * @globalvars none + * @exception none + * @conditions none + */ + uint8_t *getPixelData() + { + return m_pixeldata; + } + + /* TODO */ + virtual const uint32_t getPixelDataSize() = 0; + /* TODO */ + virtual const uint32_t getHeight() = 0; + /* TODO */ + virtual const uint32_t getWidth() = 0; + /* TODO */ + virtual const bool isMirrored() = 0; + + protected: + /** + * @method callFunc + * @brief Delegates the function and its parameters to the correct + * internal method + * @param func function name + * @param params function parameters as list + * @return - + * @globalvars none + * @exception ParserError + * @conditions none + */ + void callFunc(const std::string& func, const std::list& params); + + /** + * @method fillrect + * @brief Fills rectangle in image starting on position x, y + * width size width, height and color red, green, blue. + * @param params function parameters as list + * @return - + * @globalvars none + * @exception FileError + * @conditions none + * + * Scriptfile syntax: fillrect(x, y, width, height, red, green, blue) */ - virtual void callFunc(const std::string& func, const std::list& params) = 0; + void fillrect(std::list params); + + /* TODO */ + void invert(std::list params); + + /* TODO */ + void brightness(std::list params); + + /* TODO */ + void mirror_y(std::list params); + + /* TODO */ + void mirror_x(std::list params); + + /* members */ + /** pointer to pixelbuffer */ + uint8_t *m_pixeldata; + /** set of supported PixelFormat handlers */ + std::set m_handlers; + /** pointer to CPixelFormat implementation */ + CPixelFormat *m_pixelformat; }; #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 * @exception PixelFormatError * @conditions none */ - virtual void getPixel(const uint32_t *pixel, const uint32_t x, const uint32_t y) = 0; + virtual void getPixel(uint32_t *pixel, const uint32_t x, const uint32_t y) = 0; /** * @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 @@ using namespace std; +/* TODO */ void CPixelFormat_BGR24::getPixel(uint32_t *pixel, uint32_t x, uint32_t y) { /* @@ -22,16 +23,16 @@ void CPixelFormat_BGR24::getPixel(uint32_t *pixel, uint32_t x, uint32_t y) /* calc rowsize - boundary is 32 */ uint32_t rowsize = 4 * static_cast( - ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32 + ((getBitCount() * m_bitmap->getWidth()) + 31) / 32 ); - /* if height is positive the y-coordinates are mirrored */ - if (m_bitmap->getInfoHeader().biHeight > 0) - y = m_bitmap->getInfoHeader().biHeight - y - 1; + /* if the y-coordinates are mirrored */ + if (m_bitmap->isMirrored()) + y = m_bitmap->getHeight() - y - 1; uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); /* boundary check */ - if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) + if (offset + getBitCount()/8 > m_bitmap->getPixelDataSize()) throw PixelFormatError("Pixel position is out of range."); /* get pixel */ @@ -59,16 +60,16 @@ void CPixelFormat_BGR24::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) /* calc rowsize - boundary is 32 */ uint32_t rowsize = 4 * static_cast( - ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32 + ((getBitCount() * m_bitmap->getWidth()) + 31) / 32 ); - /* if height is positive the y-coordinates are mirrored */ - if (m_bitmap->getInfoHeader().biHeight > 0) - y = m_bitmap->getInfoHeader().biHeight - y - 1; + /* if the y-coordinates are mirrored */ + if (m_bitmap->isMirrored()) + y = m_bitmap->getHeight() - y - 1; uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); /* boundary check */ - if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) + if (offset + getBitCount()/8 > m_bitmap->getPixelDataSize()) throw PixelFormatError("Pixel position is out of range."); /* 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 ~CPixelFormat_BGR24() {} + /* TODO */ + void getPixel(uint32_t *pixel, uint32_t x, uint32_t y); + /** * @method setPixel * @brief Modifies pixel at coordinates x, y @@ -58,9 +61,6 @@ class CPixelFormat_BGR24 : public CPixelFormat */ void setPixel(const uint32_t *pixel, uint32_t x, uint32_t y); - /* TODO */ - void getPixel(uint32_t *pixel, uint32_t x, uint32_t y); - /** * @method getBitCount * @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 @@ using namespace std; +/* TODO */ +void CPixelFormat_BGR555::getPixel(uint32_t *pixel, uint32_t x, uint32_t y) +{ + /* + * pixel[0] ... red + * pixel[1] ... green + * pixel[2] ... blue + */ + if (m_bitmap->getPixelData() == NULL) + throw PixelFormatError("No pixelbuffer allocated."); + + throw PixelFormatError("NOT IMPLEMENTED"); +} + +/*----------------------------------------------------------------------------*/ + void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) { /* @@ -24,16 +40,16 @@ void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y /* calc rowsize - boundary is 32 */ uint32_t rowsize = 4 * static_cast( - ((CPixelFormat_BGR555::getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32 + ((getBitCount() * m_bitmap->getWidth()) + 31) / 32 ); - /* if height is positive the y-coordinates are mirrored */ - if (m_bitmap->getInfoHeader().biHeight > 0) - y = m_bitmap->getInfoHeader().biHeight - y - 1; + /* if the y-coordinates are mirrored */ + if (m_bitmap->isMirrored()) + y = m_bitmap->getHeight() - y - 1; uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); /* boundary check */ - if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) + if (offset + getBitCount()/8 > m_bitmap->getPixelDataSize()) throw PixelFormatError("Pixel position is out of range."); /* 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 ~CPixelFormat_BGR555() {} + /* TODO */ + void getPixel(uint32_t *pixel, uint32_t x, uint32_t y); + /** * @method setPixel * @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 @@ #include #include #include "cscriptparser.h" -#include "cbitmap.h" +#include "cwindowsbitmap.h" using namespace std; using namespace boost; @@ -18,7 +18,7 @@ CScriptparser::CScriptparser(const std::string& scriptfile) : m_scriptfile(scriptfile), m_handler(NULL) { /* add our handlers */ - m_handlers.insert(new CBitmap); + m_handlers.insert(new CWindowsBitmap); } /*----------------------------------------------------------------------------*/ 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 @@ using namespace std; CWindowsBitmap::CWindowsBitmap() - : m_pixeldata(NULL), m_pixelformat(NULL) { m_types.insert("BMP"); @@ -113,240 +112,6 @@ void CWindowsBitmap::write(std::ofstream& out) /*----------------------------------------------------------------------------*/ -void CWindowsBitmap::callFunc(const std::string& func, const std::list& params) -{ - if (func.empty()) - throw FileError("Function name is empty."); - - if (func == "fillrect") - fillrect(params); - else if (func == "mirror_x") - mirror_x(params); - else if (func == "mirror_y") - mirror_y(params); - else if (func == "invert") - invert(params); - else - throw FileError("Unknown function '" + func + "'."); -} - -/*----------------------------------------------------------------------------*/ - -void CWindowsBitmap::fillrect(std::list params) -{ - /* check prerequirements */ - if (params.size() != 7) - throw FileError("Invalid number of function parameters (must be 7)."); - - /* do nothing if no pixel exists */ - if (m_pixeldata == NULL || m_pixelformat == NULL) - return; - - /* convert parameters */ - uint32_t pparams[7]; - int i = 0; - try - { - for(i = 0; i < 7; i++) - { - pparams[i] = boost::lexical_cast(params.front()); - params.pop_front(); - } - } - catch(boost::bad_lexical_cast& ex) - { - throw FileError("Invalid parameter (" + params.front() + ")."); - } - - /* width and height can be negativ */ - uint32_t width = static_cast(abs(m_infoheader.biWidth)); - uint32_t height = static_cast(abs(m_infoheader.biHeight)); - - /* check parameter values are in range */ - if (pparams[0] < 0 || pparams[0] > width - || pparams[1] < 0 || pparams[1] > height) - throw FileError("At least one x/y-parameter is out of range."); - - /* check parameter values are in range */ - unsigned int max[3]; - m_pixelformat->getMaxColor(&max[0], &max[1], &max[2]); - if (pparams[4] < 0 || pparams[4] > max[0] - || pparams[5] < 0 || pparams[5] > max[1] - || pparams[6] < 0 || pparams[6] > max[2]) - throw FileError("At least one pixel color parameter is out of range."); - - if (pparams[2] < 0 || pparams[2] + pparams[0] > width - || pparams[3] < 0 || pparams[3] + pparams[1] > height) - throw FileError("At least one w/h-parameter is out of range."); - - /* call setPixel for every pixel in the rectangel */ - for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++) - { - for(uint32_t j = pparams[1]; j < pparams[3] + pparams[1]; j++) - { - try - { - m_pixelformat->setPixel(&pparams[4], i, j); - } - catch(CPixelFormat::PixelFormatError& ex) - { - stringstream errstr; - errstr << "Can't set pixel (pos=[" << i << "," << j << "] col=[" - << pparams[4] << "," << pparams[5] << "," << pparams[6] << "]): " - << ex.what(); - throw FileError(errstr.str()); - } - } - } -} - -/*----------------------------------------------------------------------------*/ - -#include -void CWindowsBitmap::invert(std::list params) -{ - /* check prerequirements */ - if (params.size() != 0) - throw FileError("Invalid number of function parameters (must be 0)."); - - /* do nothing if no pixel exists */ - if (m_pixeldata == NULL || m_pixelformat == NULL) - return; - - /* width and height can be negativ */ - uint32_t width = static_cast(abs(m_infoheader.biWidth)); - uint32_t height = static_cast(abs(m_infoheader.biHeight)); - unsigned int pixelwidth = m_pixelformat->getBitCount()/8; - - /* calc rowsize - boundary is 32 */ - uint32_t rowsize = 4 * static_cast( - ((m_pixelformat->getBitCount() * abs(m_infoheader.biWidth)) + 31) / 32 - ); - - for(uint32_t i = 0; i < height; i++) - { - for(uint32_t j = 0; j <= width; j++) - { - cout << j << endl; - } - } - -#if 0 -/* uint32_t offset = i * rowsize; - - for(uint32_t j = 0; j <= width/2; j++) - { - uint32_t poffset = offset + j * pixelwidth; - uint32_t pbackset = offset + width * pixelwidth - j * pixelwidth; - - /* boundary check */ - if (pbackset > m_infoheader.biSizeImage) - throw FileError("Mirrored pixel position is out of range."); - - /* mirroring, backup right data first */ - copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf); - copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth); - copy(buf, buf + pixelwidth, m_pixeldata + poffset); - } - } -#endif -} - -/*----------------------------------------------------------------------------*/ - -void CWindowsBitmap::brightness(std::list params) -{ -} - -/*----------------------------------------------------------------------------*/ - -void CWindowsBitmap::mirror_y(std::list params) -{ - /* check prerequirements */ - if (params.size() != 0) - throw FileError("Invalid number of function parameters (must be 0)."); - - /* do nothing if no pixel exists */ - if (m_pixeldata == NULL || m_pixelformat == NULL) - return; -W - /* height can be negativ */ - uint32_t height = static_cast(abs(m_infoheader.biHeight)); - - /* calc rowsize - boundary is 32 */ - uint32_t rowsize = 4 * static_cast( - ((m_pixelformat->getBitCount() * abs(m_infoheader.biWidth)) + 31) / 32 - ); - - uint8_t *buf = new uint8_t[rowsize]; - for(uint32_t i = 0; i < height/2; i++) - { - uint32_t j = height - i - 1; - uint32_t offset = i * rowsize; - uint32_t backset = j * rowsize; - - /* boundary check */ - if (offset + rowsize > m_infoheader.biSizeImage - || backset + rowsize > m_infoheader.biSizeImage) - throw FileError("Mirrored pixel position is out of range."); - - /* mirroring, backup lower data first */ - copy(m_pixeldata + backset, m_pixeldata + backset + rowsize, buf); - copy(m_pixeldata + offset, m_pixeldata + offset + rowsize, m_pixeldata + backset); - copy(buf, buf + rowsize, m_pixeldata + offset); - } - delete[] buf; -} - -/*----------------------------------------------------------------------------*/ - -void CWindowsBitmap::mirror_x(std::list params) -{ - /* check prerequirements */ - if (params.size() != 0) - throw FileError("Invalid number of function parameters (must be 0)."); - - /* do nothing if no pixel exists */ - if (m_pixeldata == NULL || m_pixelformat == NULL) - return; - - /* width and height can be negativ */ - uint32_t width = static_cast(abs(m_infoheader.biWidth)); - uint32_t height = static_cast(abs(m_infoheader.biHeight)); - - /* calc rowsize - boundary is 32 */ - uint32_t rowsize = 4 * static_cast( - ((m_pixelformat->getBitCount() * abs(m_infoheader.biWidth)) + 31) / 32 - ); - - /* calc pixelwidth */ - unsigned int pixelwidth = m_pixelformat->getBitCount()/8; - - uint8_t *buf = new uint8_t[pixelwidth]; - for(uint32_t i = 0; i < height; i++) - { - uint32_t offset = i * rowsize; - - for(uint32_t j = 0; j <= width/2; j++) - { - uint32_t poffset = offset + j * pixelwidth; - uint32_t pbackset = offset + width * pixelwidth - j * pixelwidth; - - /* boundary check */ - if (pbackset > m_infoheader.biSizeImage) - throw FileError("Mirrored pixel position is out of range."); - - /* mirroring, backup right data first */ - copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf); - copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth); - copy(buf, buf + pixelwidth, m_pixeldata + poffset); - } - } - delete[] buf; -} - -/*----------------------------------------------------------------------------*/ - #ifdef DEBUG void CWindowsBitmap::dump(std::ostream& out) { 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 @@ #include #include "cbitmap.h" -class CPixelFormat; -#include "cpixelformat.h" - /** * @class CWindowsBitmap * @brief Implementation of CBitmap handling Windows Bitmaps. * - * In order to support operations on bitmaps with different color bitcounts - * different implementations of CPixelFormat are used. These classes are - * allowed to modify the bitmap headers and pixelbuffer directly. - * * On error CFile::FileError is thrown. */ class CWindowsBitmap : public CBitmap @@ -74,19 +67,6 @@ class CWindowsBitmap : public CBitmap */ void write(std::ofstream& out); - /** - * @method callFunc - * @brief Delegates the function and its parameters to the correct - * internal method - * @param func function name - * @param params function parameters as list - * @return - - * @globalvars none - * @exception ParserError - * @conditions none - */ - void callFunc(const std::string& func, const std::list& params); - #ifdef DEBUG /** * @method dump @@ -177,58 +157,39 @@ class CWindowsBitmap : public CBitmap return m_infoheader; } - /** - * @method getPixelData - * @brief Returns pointer to pixelbuffer - * @param - - * @return pointer to pixelbuffer - * @globalvars none - * @exception none - * @conditions none - */ - uint8_t *getPixelData() + /* TODO */ + const uint32_t getPixelDataSize() { - return m_pixeldata; + return m_infoheader.biSizeImage; } - protected: - /** - * @method fillrect - * @brief Fills rectangle in image starting on position x, y - * width size width, height and color red, green, blue. - * @param params function parameters as list - * @return - - * @globalvars none - * @exception FileError - * @conditions none - * - * Scriptfile syntax: fillrect(x, y, width, height, red, green, blue) - */ - void fillrect(std::list params); - - /* TODO */ - void invert(std::list params); - /* TODO */ - void brightness(std::list params); + const uint32_t getHeight() + { + /* width and height can be negativ */ + return static_cast(abs(m_infoheader.biHeight)); + } /* TODO */ - void mirror_y(std::list params); + const uint32_t getWidth() + { + /* width and height can be negativ */ + return static_cast(abs(m_infoheader.biWidth)); + } /* TODO */ - void mirror_x(std::list params); + const bool isMirrored() + { + /* if height is positive the y-coordinates are mirrored */ + return (m_infoheader.biHeight > 0) ? true : false; + } + protected: /* members */ /** fileheader */ BITMAP_FILEHEADER m_fileheader; /** infoheader */ BITMAP_INFOHEADER m_infoheader; - /** pointer to pixelbuffer */ - uint8_t *m_pixeldata; - /** set of supported PixelFormat handlers */ - std::set m_handlers; - /** pointer to CPixelFormat implementation */ - CPixelFormat *m_pixelformat; }; #endif -- cgit v1.2.3