diff options
Diffstat (limited to 'ue2/imgsynth2/cpixelformat_bgr555.cpp')
| -rw-r--r-- | ue2/imgsynth2/cpixelformat_bgr555.cpp | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/ue2/imgsynth2/cpixelformat_bgr555.cpp b/ue2/imgsynth2/cpixelformat_bgr555.cpp index 19c98a8..2f98cc7 100644 --- a/ue2/imgsynth2/cpixelformat_bgr555.cpp +++ b/ue2/imgsynth2/cpixelformat_bgr555.cpp | |||
| @@ -8,33 +8,40 @@ | |||
| 8 | 8 | ||
| 9 | #include <boost/numeric/conversion/cast.hpp> | 9 | #include <boost/numeric/conversion/cast.hpp> |
| 10 | #include "cpixelformat_bgr555.h" | 10 | #include "cpixelformat_bgr555.h" |
| 11 | #include "cbitmap.h" | ||
| 11 | 12 | ||
| 12 | using namespace std; | 13 | using namespace std; |
| 13 | 14 | ||
| 14 | /* TODO */ | 15 | void CPixelFormat_BGR555::getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y) |
| 15 | void CPixelFormat_BGR555::getPixel(uint32_t *pixel, uint32_t x, uint32_t y) | ||
| 16 | { | 16 | { |
| 17 | /* | ||
| 18 | * pixel[0] ... red | ||
| 19 | * pixel[1] ... green | ||
| 20 | * pixel[2] ... blue | ||
| 21 | */ | ||
| 22 | if (m_bitmap->getPixelData() == NULL) | 17 | if (m_bitmap->getPixelData() == NULL) |
| 23 | throw PixelFormatError("No pixelbuffer allocated."); | 18 | throw PixelFormatError("No pixelbuffer allocated."); |
| 24 | 19 | ||
| 25 | throw PixelFormatError("NOT IMPLEMENTED"); | 20 | /* calc rowsize - boundary is 32 */ |
| 21 | uint32_t rowsize = 4 * static_cast<uint32_t>( | ||
| 22 | ((getBitCount() * m_bitmap->getWidth()) + 31) / 32 | ||
| 23 | ); | ||
| 24 | |||
| 25 | /* if the y-coordinates are mirrored */ | ||
| 26 | if (m_bitmap->isMirrored()) | ||
| 27 | y = m_bitmap->getHeight() - y - 1; | ||
| 28 | uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); | ||
| 29 | |||
| 30 | /* boundary check */ | ||
| 31 | if (offset + getBitCount()/8 > m_bitmap->getPixelDataSize()) | ||
| 32 | throw PixelFormatError("Pixel position is out of range."); | ||
| 33 | |||
| 34 | /* get pixel */ | ||
| 35 | uint8_t *o = m_bitmap->getPixelData() + offset; | ||
| 36 | pixel.blue = (*(uint16_t *)o & BGR555_BLUE_MASK) >> BGR555_BLUE_SHIFT; | ||
| 37 | pixel.green = (*(uint16_t *)o & BGR555_GREEN_MASK) >> BGR555_GREEN_SHIFT; | ||
| 38 | pixel.red = (*(uint16_t *)o & BGR555_RED_MASK) >> BGR555_RED_SHIFT; | ||
| 26 | } | 39 | } |
| 27 | 40 | ||
| 28 | /*----------------------------------------------------------------------------*/ | 41 | /*----------------------------------------------------------------------------*/ |
| 29 | 42 | ||
| 30 | void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) | 43 | void CPixelFormat_BGR555::setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y) |
| 31 | { | 44 | { |
| 32 | /* | ||
| 33 | * pixel[0] ... red | ||
| 34 | * pixel[1] ... green | ||
| 35 | * pixel[2] ... blue | ||
| 36 | */ | ||
| 37 | |||
| 38 | if (m_bitmap->getPixelData() == NULL) | 45 | if (m_bitmap->getPixelData() == NULL) |
| 39 | throw PixelFormatError("No pixelbuffer allocated."); | 46 | throw PixelFormatError("No pixelbuffer allocated."); |
| 40 | 47 | ||
| @@ -54,9 +61,9 @@ void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y | |||
| 54 | 61 | ||
| 55 | /* convert color values to correct types */ | 62 | /* convert color values to correct types */ |
| 56 | uint8_t *o = m_bitmap->getPixelData() + offset; | 63 | uint8_t *o = m_bitmap->getPixelData() + offset; |
| 57 | *(uint16_t *)o = (uint16_t)(((pixel[2] << BGR555_BLUE_SHIFT) & BGR555_BLUE_MASK) | | 64 | *(uint16_t *)o = (uint16_t)(((pixel.blue << BGR555_BLUE_SHIFT) & BGR555_BLUE_MASK) | |
| 58 | ((pixel[1] << BGR555_GREEN_SHIFT) & BGR555_GREEN_MASK) | | 65 | ((pixel.green << BGR555_GREEN_SHIFT) & BGR555_GREEN_MASK) | |
| 59 | ((pixel[0] << BGR555_RED_SHIFT) & BGR555_RED_MASK)); | 66 | ((pixel.red << BGR555_RED_SHIFT) & BGR555_RED_MASK)); |
| 60 | } | 67 | } |
| 61 | 68 | ||
| 62 | /* vim: set et sw=2 ts=2: */ | 69 | /* vim: set et sw=2 ts=2: */ |
