From aa139a7d2b3f26af7590edbf413df67195c5d900 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 27 Apr 2009 00:25:16 +0200 Subject: Adding ue2 --- ue2/imgsynth2/cpixelformat_bgr555.cpp | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ue2/imgsynth2/cpixelformat_bgr555.cpp (limited to 'ue2/imgsynth2/cpixelformat_bgr555.cpp') 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 @@ +/** + * @module cpixelformat_BGR555 + * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) + * @brief Implementation of CPixelFormat handling BGR555 color (real color) + * Windows Bitmaps. + * @date 18.04.2009 + */ + +#include +#include "cpixelformat_bgr555.h" + +using namespace std; + +void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) +{ + /* + * pixel[0] ... red + * pixel[1] ... green + * pixel[2] ... blue + */ + + if (m_bitmap->getPixelData() == NULL) + throw PixelFormatError("No pixelbuffer allocated."); + + /* calc rowsize - boundary is 32 */ + uint32_t rowsize = 4 * static_cast( + ((CPixelFormat_BGR555::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); + + /* boundary check */ + if (offset + getBitCount()/8 > m_bitmap->getInfoHeader().biSizeImage) + throw PixelFormatError("Pixel position is out of range."); + + /* convert color values to correct types */ + uint8_t *o = m_bitmap->getPixelData() + offset; + *(uint16_t *)o = (uint16_t)(((pixel[2] << BGR555_BLUE_SHIFT) & BGR555_BLUE_MASK) | + ((pixel[1] << BGR555_GREEN_SHIFT) & BGR555_GREEN_MASK) | + ((pixel[0] << BGR555_RED_SHIFT) & BGR555_RED_MASK)); +} + +/* vim: set et sw=2 ts=2: */ -- cgit v1.2.3