summaryrefslogtreecommitdiffstats
path: root/ue2/imgsynth2/cpixelformat_indexed8.cpp
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-05-02 16:44:53 +0200
committermanuel <manuel@nc8430.lan>2009-05-02 16:44:53 +0200
commitbcadfa267f976fe9f29afa50a635cbe3ea174e38 (patch)
treeb069a34c9d100dcc9229311b47cbfa0697ee7fc9 /ue2/imgsynth2/cpixelformat_indexed8.cpp
parentbca08c6de2b156cbec90944c809e5e7faecd231d (diff)
downloadooprog-bcadfa267f976fe9f29afa50a635cbe3ea174e38.tar.gz
ooprog-bcadfa267f976fe9f29afa50a635cbe3ea174e38.tar.bz2
ooprog-bcadfa267f976fe9f29afa50a635cbe3ea174e38.zip
- 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
Diffstat (limited to 'ue2/imgsynth2/cpixelformat_indexed8.cpp')
-rw-r--r--ue2/imgsynth2/cpixelformat_indexed8.cpp88
1 files changed, 41 insertions, 47 deletions
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 @@
1/** 1/**
2 * @module CPixelFormat_Indexed8 2 * @module CPixelFormat_Indexed8
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) 3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief Implementation of CPixelFormat handling 24bit color Windows Bitmaps TODO. 4 * @brief Implementation of CPixelFormat handling 24bit indexed bitmaps.
5 * @date 18.04.2009 5 * @date 02.05.2009
6 */ 6 */
7 7
8#include <boost/numeric/conversion/cast.hpp> 8#include <boost/numeric/conversion/cast.hpp>
@@ -12,73 +12,67 @@ using namespace std;
12 12
13void CPixelFormat_Indexed8::getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y) 13void CPixelFormat_Indexed8::getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y)
14{ 14{
15#if 0
16 if (m_bitmap->getPixelData() == NULL) 15 if (m_bitmap->getPixelData() == NULL)
17 throw PixelFormatError("No pixelbuffer allocated."); 16 throw PixelFormatError("No pixelbuffer allocated.");
17 if (m_bitmap->getColorTable().size() == 0)
18 return;
18 19
19 /* calc rowsize - boundary is 32 */ 20 uint32_t offset = y * m_bitmap->getWidth() + x;
20 uint32_t rowsize = 4 * static_cast<uint32_t>(
21 ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32
22 );*/
23
24 /* if height is positive the y-coordinates are mirrored */
25 if (m_bitmap->getInfoHeader().biHeight > 0)
26 y = m_bitmap->getInfoHeader().biHeight - y - 1;
27 uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32);
28 21
29 /* boundary check */ 22 /* boundary check */
30 if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) 23 if (offset * sizeof(uint32_t) + sizeof(uint32_t) > m_bitmap->getPixelDataSize())
31 throw PixelFormatError("Pixel position is out of range."); 24 throw PixelFormatError("Pixel position is out of range.");
32 25
33 /* get pixel */ 26 uint32_t color = *((uint32_t *)m_bitmap->getPixelData() + offset);
34 try 27
35 { 28 map<uint32_t, RGBPIXEL *>::iterator it;
36 pixel[0] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 2)); 29 if ((it = m_bitmap->getColorTable().find(color)) == m_bitmap->getColorTable().end())
37 pixel[1] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 1)); 30 throw PixelFormatError("Pixel has no reference in colortable.");
38 pixel[2] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset)); 31
39 } 32 pixel.red = (*it).second->red;
40 catch(boost::numeric::bad_numeric_cast& ex) 33 pixel.green = (*it).second->green;
41 { 34 pixel.blue = (*it).second->blue;
42 throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what()));
43 }
44#endif
45} 35}
46 36
37/*----------------------------------------------------------------------------*/
38
47void CPixelFormat_Indexed8::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y) 39void CPixelFormat_Indexed8::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y)
48{ 40{
49#if 0 41 if (m_bitmap->getPixelData() == NULL)
50 if (m_bitmap->getPixelData() == NULL)
51 throw PixelFormatError("No pixelbuffer allocated."); 42 throw PixelFormatError("No pixelbuffer allocated.");
43 if (m_bitmap->getColorTable().size() == 0)
44 return;
52 45
53 /* calc rowsize - boundary is 32 */ 46 uint32_t offset = y * m_bitmap->getWidth() + x;
54 uint32_t rowsize = 4 * static_cast<uint32_t>(
55 ((getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32
56 );
57
58 /* if height is positive the y-coordinates are mirrored */
59 if (m_bitmap->getInfoHeader().biHeight > 0)
60 y = m_bitmap->getInfoHeader().biHeight - y - 1;
61 uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32);
62 47
63 /* boundary check */ 48 /* boundary check */
64 if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) 49 if (offset * sizeof(uint32_t) + sizeof(uint32_t) > m_bitmap->getPixelDataSize())
65 throw PixelFormatError("Pixel position is out of range."); 50 throw PixelFormatError("Pixel position is out of range.");
66 51
67 /* convert color values to correct types */ 52 /* try to look up color in colortable */
68 uint8_t data[3]; 53 map<uint32_t, RGBPIXEL *>::iterator it;
69 try 54 for(it = m_bitmap->getColorTable().begin(); it != m_bitmap->getColorTable().end(); it++)
70 { 55 {
71 data[0] = boost::numeric_cast<uint8_t>(pixel[2]); 56 if ((*it).second->red == pixel.red &&
72 data[1] = boost::numeric_cast<uint8_t>(pixel[1]); 57 (*it).second->green == pixel.green &&
73 data[2] = boost::numeric_cast<uint8_t>(pixel[0]); 58 (*it).second->blue == pixel.blue)
59 break;
74 } 60 }
75 catch(boost::numeric::bad_numeric_cast& ex) 61
62 uint32_t index = (*it).first;
63 /* need to get a new character for our color */
64 if (it == m_bitmap->getColorTable().end())
76 { 65 {
77 throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what())); 66 index = (*it).first + 1;
67 RGBPIXEL *pixelptr = new RGBPIXEL;
68 pixelptr->red = pixel.red;
69 pixelptr->green = pixel.green;
70 pixelptr->blue = pixel.blue;
71 m_bitmap->getColorTable()[ index ] = pixelptr;
78 } 72 }
79 73
80 copy(data, data + 3, m_bitmap->getPixelData() + offset); 74 /* set color */
81#endif 75 *((uint32_t *)m_bitmap->getPixelData() + offset) = index;
82} 76}
83 77
84/* vim: set et sw=2 ts=2: */ 78/* vim: set et sw=2 ts=2: */