diff options
| author | manuel <manuel@nc8430.lan> | 2009-04-27 00:25:16 +0200 |
|---|---|---|
| committer | manuel <manuel@nc8430.lan> | 2009-04-27 00:25:16 +0200 |
| commit | aa139a7d2b3f26af7590edbf413df67195c5d900 (patch) | |
| tree | ba99ea3b2af9aa191386550f025520117f18f4f8 /ue2/imgsynth2/cpixelformat_bgr555.cpp | |
| parent | 384539f7cc9feaa7ef7cee385cce472c6966c843 (diff) | |
| download | ooprog-aa139a7d2b3f26af7590edbf413df67195c5d900.tar.gz ooprog-aa139a7d2b3f26af7590edbf413df67195c5d900.tar.bz2 ooprog-aa139a7d2b3f26af7590edbf413df67195c5d900.zip | |
Adding ue2
Diffstat (limited to 'ue2/imgsynth2/cpixelformat_bgr555.cpp')
| -rw-r--r-- | ue2/imgsynth2/cpixelformat_bgr555.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ue2/imgsynth2/cpixelformat_bgr555.cpp b/ue2/imgsynth2/cpixelformat_bgr555.cpp new file mode 100644 index 0000000..4a3c833 --- /dev/null +++ b/ue2/imgsynth2/cpixelformat_bgr555.cpp | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | /** | ||
| 2 | * @module cpixelformat_BGR555 | ||
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | ||
| 4 | * @brief Implementation of CPixelFormat handling BGR555 color (real color) | ||
| 5 | * Windows Bitmaps. | ||
| 6 | * @date 18.04.2009 | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <boost/numeric/conversion/cast.hpp> | ||
| 10 | #include "cpixelformat_bgr555.h" | ||
| 11 | |||
| 12 | using namespace std; | ||
| 13 | |||
| 14 | void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) | ||
| 15 | { | ||
| 16 | /* | ||
| 17 | * pixel[0] ... red | ||
| 18 | * pixel[1] ... green | ||
| 19 | * pixel[2] ... blue | ||
| 20 | */ | ||
| 21 | |||
| 22 | if (m_bitmap->getPixelData() == NULL) | ||
| 23 | throw PixelFormatError("No pixelbuffer allocated."); | ||
| 24 | |||
| 25 | /* calc rowsize - boundary is 32 */ | ||
| 26 | uint32_t rowsize = 4 * static_cast<uint32_t>( | ||
| 27 | ((CPixelFormat_BGR555::getBitCount() * abs(m_bitmap->getInfoHeader().biWidth)) + 31) / 32 | ||
| 28 | ); | ||
| 29 | |||
| 30 | /* if height is positive the y-coordinates are mirrored */ | ||
| 31 | if (m_bitmap->getInfoHeader().biHeight > 0) | ||
| 32 | y = m_bitmap->getInfoHeader().biHeight - y - 1; | ||
| 33 | uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); | ||
| 34 | |||
| 35 | /* boundary check */ | ||
| 36 | if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) | ||
| 37 | throw PixelFormatError("Pixel position is out of range."); | ||
| 38 | |||
| 39 | /* convert color values to correct types */ | ||
| 40 | uint8_t *o = m_bitmap->getPixelData() + offset; | ||
| 41 | *(uint16_t *)o = (uint16_t)(((pixel[2] << BGR555_BLUE_SHIFT) & BGR555_BLUE_MASK) | | ||
| 42 | ((pixel[1] << BGR555_GREEN_SHIFT) & BGR555_GREEN_MASK) | | ||
| 43 | ((pixel[0] << BGR555_RED_SHIFT) & BGR555_RED_MASK)); | ||
| 44 | } | ||
| 45 | |||
| 46 | /* vim: set et sw=2 ts=2: */ | ||
