From b22395ec4de60326eb629df882b4b8781dbca15c Mon Sep 17 00:00:00 2001 From: manuel Date: Fri, 1 May 2009 14:54:45 +0200 Subject: - removed runtime generated output files - implemented brightness() - implemented invert() - implemented getPixel in CPixelFormat_BGR24 and CPixelFormat_BGR555 --- ue2/imgsynth2/cpixelformat_bgr555.cpp | 43 ++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'ue2/imgsynth2/cpixelformat_bgr555.cpp') 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 @@ #include #include "cpixelformat_bgr555.h" +#include "cbitmap.h" using namespace std; -/* TODO */ -void CPixelFormat_BGR555::getPixel(uint32_t *pixel, uint32_t x, uint32_t y) +void CPixelFormat_BGR555::getPixel(RGBPIXEL& 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."); - throw PixelFormatError("NOT IMPLEMENTED"); + /* calc rowsize - boundary is 32 */ + uint32_t rowsize = 4 * static_cast( + ((getBitCount() * m_bitmap->getWidth()) + 31) / 32 + ); + + /* if the y-coordinates are mirrored */ + if (m_bitmap->isMirrored()) + y = m_bitmap->getHeight() - y - 1; + uint32_t offset = y * rowsize + x * (4 * getBitCount() / 32); + + /* boundary check */ + if (offset + getBitCount()/8 > m_bitmap->getPixelDataSize()) + throw PixelFormatError("Pixel position is out of range."); + + /* get pixel */ + uint8_t *o = m_bitmap->getPixelData() + offset; + pixel.blue = (*(uint16_t *)o & BGR555_BLUE_MASK) >> BGR555_BLUE_SHIFT; + pixel.green = (*(uint16_t *)o & BGR555_GREEN_MASK) >> BGR555_GREEN_SHIFT; + pixel.red = (*(uint16_t *)o & BGR555_RED_MASK) >> BGR555_RED_SHIFT; } /*----------------------------------------------------------------------------*/ -void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) +void CPixelFormat_BGR555::setPixel(const RGBPIXEL& 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."); @@ -54,9 +61,9 @@ void CPixelFormat_BGR555::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y /* 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)); + *(uint16_t *)o = (uint16_t)(((pixel.blue << BGR555_BLUE_SHIFT) & BGR555_BLUE_MASK) | + ((pixel.green << BGR555_GREEN_SHIFT) & BGR555_GREEN_MASK) | + ((pixel.red << BGR555_RED_SHIFT) & BGR555_RED_MASK)); } /* vim: set et sw=2 ts=2: */ -- cgit v1.2.3