diff options
| author | manuel <manuel@nc8430.lan> | 2009-05-01 15:41:07 +0200 |
|---|---|---|
| committer | manuel <manuel@nc8430.lan> | 2009-05-01 15:41:07 +0200 |
| commit | 766a0da4ab39c26e1d3b591f46cdadcfbe0f8a73 (patch) | |
| tree | f383a621f2ad762e5be250c2ba9bd4c18bb02a0c /ue2/imgsynth2/cpixelformat_indexed8.cpp | |
| parent | f0442c8d058ae6007023ba1b898197db921e6ce1 (diff) | |
| parent | b0442de485dcb6328366d9b05a62af345e5fa39f (diff) | |
| download | ooprog-766a0da4ab39c26e1d3b591f46cdadcfbe0f8a73.tar.gz ooprog-766a0da4ab39c26e1d3b591f46cdadcfbe0f8a73.tar.bz2 ooprog-766a0da4ab39c26e1d3b591f46cdadcfbe0f8a73.zip | |
merge
Diffstat (limited to 'ue2/imgsynth2/cpixelformat_indexed8.cpp')
| -rw-r--r-- | ue2/imgsynth2/cpixelformat_indexed8.cpp | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/ue2/imgsynth2/cpixelformat_indexed8.cpp b/ue2/imgsynth2/cpixelformat_indexed8.cpp new file mode 100644 index 0000000..546daaf --- /dev/null +++ b/ue2/imgsynth2/cpixelformat_indexed8.cpp | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | /** | ||
| 2 | * @module CPixelFormat_Indexed8 | ||
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | ||
| 4 | * @brief Implementation of CPixelFormat handling 24bit color Windows Bitmaps. | ||
| 5 | * @date 18.04.2009 | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <boost/numeric/conversion/cast.hpp> | ||
| 9 | #include "cpixelformat_indexed8.h" | ||
| 10 | |||
| 11 | using namespace std; | ||
| 12 | |||
| 13 | void CPixelFormat_Indexed8::getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y) | ||
| 14 | { | ||
| 15 | #if 0 | ||
| 16 | if (m_bitmap->getPixelData() == NULL) | ||
| 17 | throw PixelFormatError("No pixelbuffer allocated."); | ||
| 18 | |||
| 19 | /* calc rowsize - boundary is 32 */ | ||
| 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 | |||
| 29 | /* boundary check */ | ||
| 30 | if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) | ||
| 31 | throw PixelFormatError("Pixel position is out of range."); | ||
| 32 | |||
| 33 | /* get pixel */ | ||
| 34 | try | ||
| 35 | { | ||
| 36 | pixel[0] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 2)); | ||
| 37 | pixel[1] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset + 1)); | ||
| 38 | pixel[2] = boost::numeric_cast<uint32_t>(*(m_bitmap->getPixelData() + offset)); | ||
| 39 | } | ||
| 40 | catch(boost::numeric::bad_numeric_cast& ex) | ||
| 41 | { | ||
| 42 | throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what())); | ||
| 43 | } | ||
| 44 | #endif | ||
| 45 | } | ||
| 46 | |||
| 47 | void CPixelFormat_Indexed8::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y) | ||
| 48 | { | ||
| 49 | #if 0 | ||
| 50 | if (m_bitmap->getPixelData() == NULL) | ||
| 51 | throw PixelFormatError("No pixelbuffer allocated."); | ||
| 52 | |||
| 53 | /* calc rowsize - boundary is 32 */ | ||
| 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 | |||
| 63 | /* boundary check */ | ||
| 64 | if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) | ||
| 65 | throw PixelFormatError("Pixel position is out of range."); | ||
| 66 | |||
| 67 | /* convert color values to correct types */ | ||
| 68 | uint8_t data[3]; | ||
| 69 | try | ||
| 70 | { | ||
| 71 | data[0] = boost::numeric_cast<uint8_t>(pixel[2]); | ||
| 72 | data[1] = boost::numeric_cast<uint8_t>(pixel[1]); | ||
| 73 | data[2] = boost::numeric_cast<uint8_t>(pixel[0]); | ||
| 74 | } | ||
| 75 | catch(boost::numeric::bad_numeric_cast& ex) | ||
| 76 | { | ||
| 77 | throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what())); | ||
| 78 | } | ||
| 79 | |||
| 80 | copy(data, data + 3, m_bitmap->getPixelData() + offset); | ||
| 81 | #endif | ||
| 82 | } | ||
| 83 | |||
| 84 | /* vim: set et sw=2 ts=2: */ | ||
