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/cwindowsbitmap.cpp | 235 --------------------------------------- 1 file changed, 235 deletions(-) (limited to 'ue2/imgsynth2/cwindowsbitmap.cpp') 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) { -- cgit v1.2.3