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/cpixelformat_indexed8.cpp | 88 +++++++++++++++------------------ 1 file changed, 41 insertions(+), 47 deletions(-) (limited to 'ue2/imgsynth2/cpixelformat_indexed8.cpp') diff --git a/ue2/imgsynth2/cpixelformat_indexed8.cpp b/ue2/imgsynth2/cpixelformat_indexed8.cpp index 6453fad..21b0988 100644 --- a/ue2/imgsynth2/cpixelformat_indexed8.cpp +++ b/ue2/imgsynth2/cpixelformat_indexed8.cpp @@ -1,8 +1,8 @@ /** * @module CPixelFormat_Indexed8 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) - * @brief Implementation of CPixelFormat handling 24bit color Windows Bitmaps TODO. - * @date 18.04.2009 + * @brief Implementation of CPixelFormat handling 24bit indexed bitmaps. + * @date 02.05.2009 */ #include @@ -12,73 +12,67 @@ using namespace std; void CPixelFormat_Indexed8::getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y) { -#if 0 if (m_bitmap->getPixelData() == NULL) throw PixelFormatError("No pixelbuffer allocated."); + if (m_bitmap->getColorTable().size() == 0) + return; - /* calc rowsize - boundary is 32 */ - uint32_t rowsize = 4 * static_cast( - ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32 - );*/ - - /* if height is positive the y-coordinates are mirrored */ - if (m_bitmap->getInfoHeader().biHeight > 0) - y = m_bitmap->getInfoHeader().biHeight - y - 1; - uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); + uint32_t offset = y * m_bitmap->getWidth() + x; /* boundary check */ - if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) + if (offset * sizeof(uint32_t) + sizeof(uint32_t) > m_bitmap->getPixelDataSize()) throw PixelFormatError("Pixel position is out of range."); - /* get pixel */ - try - { - pixel[0] = boost::numeric_cast(*(m_bitmap->getPixelData() + offset + 2)); - pixel[1] = boost::numeric_cast(*(m_bitmap->getPixelData() + offset + 1)); - pixel[2] = boost::numeric_cast(*(m_bitmap->getPixelData() + offset)); - } - catch(boost::numeric::bad_numeric_cast& ex) - { - throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what())); - } -#endif + uint32_t color = *((uint32_t *)m_bitmap->getPixelData() + offset); + + map::iterator it; + if ((it = m_bitmap->getColorTable().find(color)) == m_bitmap->getColorTable().end()) + throw PixelFormatError("Pixel has no reference in colortable."); + + pixel.red = (*it).second->red; + pixel.green = (*it).second->green; + pixel.blue = (*it).second->blue; } +/*----------------------------------------------------------------------------*/ + void CPixelFormat_Indexed8::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y) { -#if 0 - if (m_bitmap->getPixelData() == NULL) + if (m_bitmap->getPixelData() == NULL) throw PixelFormatError("No pixelbuffer allocated."); + if (m_bitmap->getColorTable().size() == 0) + return; - /* calc rowsize - boundary is 32 */ - uint32_t rowsize = 4 * static_cast( - ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32 - ); - - /* if height is positive the y-coordinates are mirrored */ - if (m_bitmap->getInfoHeader().biHeight > 0) - y = m_bitmap->getInfoHeader().biHeight - y - 1; - uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); + uint32_t offset = y * m_bitmap->getWidth() + x; /* boundary check */ - if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) + if (offset * sizeof(uint32_t) + sizeof(uint32_t) > m_bitmap->getPixelDataSize()) throw PixelFormatError("Pixel position is out of range."); - /* convert color values to correct types */ - uint8_t data[3]; - try + /* try to look up color in colortable */ + map::iterator it; + for(it = m_bitmap->getColorTable().begin(); it != m_bitmap->getColorTable().end(); it++) { - data[0] = boost::numeric_cast(pixel[2]); - data[1] = boost::numeric_cast(pixel[1]); - data[2] = boost::numeric_cast(pixel[0]); + if ((*it).second->red == pixel.red && + (*it).second->green == pixel.green && + (*it).second->blue == pixel.blue) + break; } - catch(boost::numeric::bad_numeric_cast& ex) + + uint32_t index = (*it).first; + /* need to get a new character for our color */ + if (it == m_bitmap->getColorTable().end()) { - throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what())); + index = (*it).first + 1; + RGBPIXEL *pixelptr = new RGBPIXEL; + pixelptr->red = pixel.red; + pixelptr->green = pixel.green; + pixelptr->blue = pixel.blue; + m_bitmap->getColorTable()[ index ] = pixelptr; } - copy(data, data + 3, m_bitmap->getPixelData() + offset); -#endif + /* set color */ + *((uint32_t *)m_bitmap->getPixelData() + offset) = index; } /* vim: set et sw=2 ts=2: */ -- cgit v1.2.3