From bcadfa267f976fe9f29afa50a635cbe3ea174e38 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 2 May 2009 16:44:53 +0200 Subject: - colortable now uses uint32_t as identifier - rewrote xpm colortable parsing to convert their identifiers to our own and vica vi - implemented indexed8::setpixel/getpixel - moved rowsize to member variable in cbitmap - added second test for xpm/indexed8 --- ue2/imgsynth2/cbitmap.cpp | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) (limited to 'ue2/imgsynth2/cbitmap.cpp') diff --git a/ue2/imgsynth2/cbitmap.cpp b/ue2/imgsynth2/cbitmap.cpp index 2e135db..3d206f5 100644 --- a/ue2/imgsynth2/cbitmap.cpp +++ b/ue2/imgsynth2/cbitmap.cpp @@ -28,7 +28,8 @@ CBitmap::~CBitmap() m_pixelformat = NULL; /* delete colortable content */ - map::iterator it2; + //map::iterator it2; + map::iterator it2; for(it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++) delete (*it2).second; } @@ -144,7 +145,7 @@ void CBitmap::invert(std::list params) if (hasColorTable()) { /* invert every entry in the colortable */ - map::iterator it; + map::iterator it; for (it = m_colortable.begin(); it != m_colortable.end(); it++) { (*it).second->red = max.red - (*it).second->red; @@ -212,8 +213,8 @@ void CBitmap::brightness(std::list params) m_pixelformat->getMaxColor(max); if (hasColorTable()) { - /* invert every entry in the colortable */ - map::iterator it; + /* change every entry in the colortable */ + map::iterator it; for (it = m_colortable.begin(); it != m_colortable.end(); it++) { (*it).second->red = min(max.red, static_cast((*it).second->red * factor)); @@ -223,7 +224,7 @@ void CBitmap::brightness(std::list params) } else { - /* invert per pixel */ + /* change per pixel */ for(uint32_t y = 0; y < getHeight(); y++) { for(uint32_t x = 0; x < getWidth(); x++) @@ -260,27 +261,22 @@ void CBitmap::mirror_y(std::list params) 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]; + uint8_t *buf = new uint8_t[m_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; + uint32_t offset = i * m_rowsize; + uint32_t backset = j * m_rowsize; /* boundary check */ - if (offset + rowsize > getPixelDataSize() - || backset + rowsize > getPixelDataSize()) + if (offset + m_rowsize > getPixelDataSize() + || backset + m_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); + copy(m_pixeldata + backset, m_pixeldata + backset + m_rowsize, buf); + copy(m_pixeldata + offset, m_pixeldata + offset + m_rowsize, m_pixeldata + backset); + copy(buf, buf + m_rowsize, m_pixeldata + offset); } delete[] buf; } @@ -297,18 +293,13 @@ void CBitmap::mirror_x(std::list params) 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; + unsigned int pixelwidth = (hasColorTable()) ? sizeof(uint32_t) : m_pixelformat->getBitCount()/8; uint8_t *buf = new uint8_t[pixelwidth]; for(uint32_t i = 0; i < getHeight(); i++) { - uint32_t offset = i * rowsize; + uint32_t offset = i * m_rowsize; for(uint32_t j = 0; j <= getWidth()/2; j++) { -- cgit v1.2.3