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/cbitmap.cpp | 151 +++++++++++++++++++------- ue2/imgsynth2/cbitmap.h | 130 +++++++++++++++++++--- ue2/imgsynth2/cpixelformat.h | 43 ++++++-- ue2/imgsynth2/cpixelformat_bgr24.cpp | 37 ++----- ue2/imgsynth2/cpixelformat_bgr24.h | 33 ++++-- ue2/imgsynth2/cpixelformat_bgr555.cpp | 43 +++++--- ue2/imgsynth2/cpixelformat_bgr555.h | 35 ++++-- ue2/imgsynth2/cwindowsbitmap.h | 55 +++++++++- ue2/imgsynth2/test/input_yellow_man2_rgb24 | 4 +- ue2/imgsynth2/test/input_yellow_man2_rgb555 | 6 +- ue2/imgsynth2/test/yellow_man1_rgb24_out.bmp | Bin 530 -> 0 bytes ue2/imgsynth2/test/yellow_man1_rgb555_out.bmp | Bin 394 -> 0 bytes ue2/imgsynth2/test/yellow_man2_rgb24_out.bmp | Bin 530 -> 0 bytes ue2/imgsynth2/test/yellow_man2_rgb555_out.bmp | Bin 394 -> 0 bytes 14 files changed, 405 insertions(+), 132 deletions(-) delete mode 100644 ue2/imgsynth2/test/yellow_man1_rgb24_out.bmp delete mode 100644 ue2/imgsynth2/test/yellow_man1_rgb555_out.bmp delete mode 100644 ue2/imgsynth2/test/yellow_man2_rgb24_out.bmp delete mode 100644 ue2/imgsynth2/test/yellow_man2_rgb555_out.bmp (limited to 'ue2') diff --git a/ue2/imgsynth2/cbitmap.cpp b/ue2/imgsynth2/cbitmap.cpp index b9cfc62..a064130 100644 --- a/ue2/imgsynth2/cbitmap.cpp +++ b/ue2/imgsynth2/cbitmap.cpp @@ -5,6 +5,7 @@ * @date 17.04.2009 */ +#include #include #include #include "cbitmap.h" @@ -25,6 +26,11 @@ CBitmap::~CBitmap() for (it = m_handlers.begin(); it != m_handlers.end(); it++) delete *it; m_pixelformat = NULL; + + /* delete colortable content */ + map::iterator it2; + for (it2 = m_colortable.begin(); it2 != m_colortable.end(); it2++) + delete (*it2).second; } /*----------------------------------------------------------------------------*/ @@ -36,6 +42,8 @@ void CBitmap::callFunc(const std::string& func, const std::list& pa if (func == "fillrect") fillrect(params); + else if (func == "brightness") + brightness(params); else if (func == "mirror_x") mirror_x(params); else if (func == "mirror_y") @@ -80,17 +88,22 @@ void CBitmap::fillrect(std::list params) throw FileError("At least one x/y-parameter is out of range."); /* check parameter values are in range */ - unsigned int max[3]; - m_pixelformat->getMaxColor(&max[0], &max[1], &max[2]); - if (pparams[4] < 0 || pparams[4] > max[0] - || pparams[5] < 0 || pparams[5] > max[1] - || pparams[6] < 0 || pparams[6] > max[2]) + CPixelFormat::RGBPIXEL pixel; + m_pixelformat->getMaxColor(pixel); + if (pparams[4] < 0 || pparams[4] > pixel.red + || pparams[5] < 0 || pparams[5] > pixel.green + || pparams[6] < 0 || pparams[6] > pixel.blue) throw FileError("At least one pixel color parameter is out of range."); if (pparams[2] < 0 || pparams[2] + pparams[0] > getWidth() || pparams[3] < 0 || pparams[3] + pparams[1] > getHeight()) throw FileError("At least one w/h-parameter is out of range."); + /* new pixel data */ + pixel.red = pparams[4]; + pixel.green = pparams[5]; + pixel.blue = pparams[6]; + /* call setPixel for every pixel in the rectangel */ for(uint32_t i = pparams[0]; i < pparams[2] + pparams[0]; i++) { @@ -98,7 +111,7 @@ void CBitmap::fillrect(std::list params) { try { - m_pixelformat->setPixel(&pparams[4], i, j); + m_pixelformat->setPixel(pixel, i, j); } catch(CPixelFormat::PixelFormatError& ex) { @@ -114,7 +127,6 @@ void CBitmap::fillrect(std::list params) /*----------------------------------------------------------------------------*/ -/* TODO */ void CBitmap::invert(std::list params) { /* check prerequirements */ @@ -125,49 +137,114 @@ void CBitmap::invert(std::list params) if (m_pixeldata == NULL || m_pixelformat == NULL) return; - /* TODO pixelwidth */ - unsigned int pixelwidth = m_pixelformat->getBitCount()/8; - - /* calc rowsize - boundary is 32 */ - uint32_t rowsize = 4 * static_cast( - ((m_pixelformat->getBitCount() * getWidth()) + 31) / 32 - ); - - for(uint32_t i = 0; i < getHeight(); i++) + CPixelFormat::RGBPIXEL pixel; + CPixelFormat::RGBPIXEL max; + m_pixelformat->getMaxColor(max); + if (hasColorTable()) { - for(uint32_t j = 0; j <= getWidth(); j++) + /* invert every entry in the colortable */ + map::iterator it; + for (it = m_colortable.begin(); it != m_colortable.end(); it++) { - /*TODO cout << j << endl;*/ - break; + (*it).second->red = max.red - (*it).second->red; + (*it).second->green = max.green - (*it).second->green; + (*it).second->blue = max.blue - (*it).second->blue; } } - -#if 0 - uint32_t offset = i * rowsize; - - for(uint32_t j = 0; j <= getWidth()/2; j++) + else + { + /* invert per pixel */ + for(uint32_t y = 0; y < getHeight(); y++) { - uint32_t poffset = offset + j * pixelwidth; - uint32_t pbackset = offset + getWidth() * pixelwidth - j * pixelwidth; - - /* boundary check */ - if (pbackset > m_infoheader.biSizeImage) - throw FileError("Mirrored pixel position is out of range."); - - /* mirroring, backup right data first */ - copy(m_pixeldata + pbackset - pixelwidth, m_pixeldata + pbackset, buf); - copy(m_pixeldata + poffset, m_pixeldata + poffset + pixelwidth, m_pixeldata + pbackset - pixelwidth); - copy(buf, buf + pixelwidth, m_pixeldata + poffset); + for(uint32_t x = 0; x < getWidth(); x++) + { + try + { + m_pixelformat->getPixel(pixel, x, y); + pixel.red = max.red - pixel.red; + pixel.green = max.green - pixel.green; + pixel.blue = max.blue - pixel.blue; + m_pixelformat->setPixel(pixel, x, y); + } + catch(CPixelFormat::PixelFormatError& ex) + { + stringstream errstr; + errstr << "Can't invert pixel (pos=[" << x << "," << y << "]): " + << ex.what(); + throw FileError(errstr.str()); + } + } } } -#endif } /*----------------------------------------------------------------------------*/ -/* TODO */ void CBitmap::brightness(std::list params) { + /* check prerequirements */ + if (params.size() != 1) + throw FileError("Invalid number of function parameters (must be 1)."); + + /* do nothing if no pixel exists */ + if (m_pixeldata == NULL || m_pixelformat == NULL) + return; + + /* convert parameters */ + float factor; + try + { + factor = boost::lexical_cast(params.front()); + params.pop_front(); + } + catch(boost::bad_lexical_cast& ex) + { + throw FileError("Invalid parameter (" + params.front() + ")."); + } + + /* negative factor doesn't make sense */ + if (factor < 0) + throw FileError("Brightness parameter must be positive."); + + CPixelFormat::RGBPIXEL pixel; + CPixelFormat::RGBPIXEL max; + m_pixelformat->getMaxColor(max); + if (hasColorTable()) + { + /* invert every entry in the colortable */ + map::iterator it; + for (it = m_colortable.begin(); it != m_colortable.end(); it++) + { + (*it).second->red = min(max.red, static_cast((*it).second->red * factor)); + (*it).second->green = min(max.green, static_cast((*it).second->green * factor)); + (*it).second->blue = min(max.blue, static_cast((*it).second->blue * factor)); + } + } + else + { + /* invert per pixel */ + for(uint32_t y = 0; y < getHeight(); y++) + { + for(uint32_t x = 0; x < getWidth(); x++) + { + try + { + m_pixelformat->getPixel(pixel, x, y); + pixel.red = min(max.red, static_cast(pixel.red * factor)); + pixel.green = min(max.green, static_cast(pixel.green * factor)); + pixel.blue = min(max.blue, static_cast(pixel.blue * factor)); + m_pixelformat->setPixel(pixel, x, y); + } + catch(CPixelFormat::PixelFormatError& ex) + { + stringstream errstr; + errstr << "Can't invert pixel (pos=[" << x << "," << y << "]): " + << ex.what(); + throw FileError(errstr.str()); + } + } + } + } } /*----------------------------------------------------------------------------*/ diff --git a/ue2/imgsynth2/cbitmap.h b/ue2/imgsynth2/cbitmap.h index f8f8850..df7dc84 100644 --- a/ue2/imgsynth2/cbitmap.h +++ b/ue2/imgsynth2/cbitmap.h @@ -9,9 +9,8 @@ #define CBITMAP_H #include +#include #include "cfile.h" - -class CPixelFormat; #include "cpixelformat.h" /** @@ -53,12 +52,28 @@ class CBitmap : public CFile virtual ~CBitmap(); /** - * TODO + * @method read + * @brief Reads Windows Bitmap from filestream. + * On error an exception is thrown. + * @param in filestream to read data from + * @return - + * @globalvars none + * @exception CFile::FileError + * @exception bad_alloc + * @conditions none */ virtual void read(std::ifstream& in) = 0; /** - * TODO + * @method write + * @brief Writes Windows Bitmap to filestream. + * @param out filestream to read data from + * @param filename filename (maybe useful for some handlers) + * @return - + * @globalvars none + * @exception FileError + * @exception bad_alloc + * @conditions none */ virtual void write(std::ofstream& out, std::string& filename) = 0; @@ -76,15 +91,62 @@ class CBitmap : public CFile return m_pixeldata; } - /* TODO */ + /** + * @method getPixelDataSize + * @brief Return size of pixelbuffer + * @param - + * @return size of pixelbuffer + * @globalvars none + * @exception none + * @conditions none + */ virtual const uint32_t getPixelDataSize() = 0; - /* TODO */ + + /** + * @method getHeight + * @brief Return height of bitmap in pixel + * @param - + * @return height of bitmap in pixel + * @globalvars none + * @exception none + * @conditions none + */ virtual const uint32_t getHeight() = 0; - /* TODO */ + + /** + * @method getWidth + * @brief Return width of bitmap in pixel + * @param - + * @return width of bitmap in pixel + * @globalvars none + * @exception none + * @conditions none + */ virtual const uint32_t getWidth() = 0; - /* TODO */ + + /** + * @method isMirrored + * @brief Windows Bitmaps can be stored upside down + * @param - + * @return true if bitmap is stored upside down. false otherwise + * @globalvars none + * @exception none + * @conditions none + */ virtual const bool isMirrored() = 0; + /** + * @method hasColorTable + * @brief Check if bitmap has a colortable + * (we don't support this yet for windows bitmaps) + * @param - + * @return true if bitmap has a colortable. false otherwise + * @globalvars none + * @exception none + * @conditions none + */ + virtual const bool hasColorTable() = 0; + protected: /** * @method callFunc @@ -99,7 +161,7 @@ class CBitmap : public CFile */ void callFunc(const std::string& func, const std::list& params); - /** + /** * @method fillrect * @brief Fills rectangle in image starting on position x, y * width size width, height and color red, green, blue. @@ -113,21 +175,63 @@ class CBitmap : public CFile */ void fillrect(std::list params); - /* TODO */ + /** + * @method invert + * @brief Invert image + * @param params function parameters as list + * @return - + * @globalvars none + * @exception FileError + * @conditions none + * + * Scriptfile syntax: invert() + */ void invert(std::list params); - /* TODO */ + /** + * @method brightness + * @brief Increase/decrease brightness of image + * @param params function parameters as list + * @return - + * @globalvars none + * @exception FileError + * @conditions none + * + * Scriptfile syntax: brightness(factor) + */ void brightness(std::list params); - /* TODO */ + /** + * @method mirror_y + * @brief Mirror image around the y-axis + * @param params function parameters as list + * @return - + * @globalvars none + * @exception FileError + * @conditions none + * + * Scriptfile syntax: mirror_y() + */ void mirror_y(std::list params); - /* TODO */ + /** + * @method mirror_x + * @brief Mirror image around the x-axis + * @param params function parameters as list + * @return - + * @globalvars none + * @exception FileError + * @conditions none + * + * Scriptfile syntax: mirror_y() + */ void mirror_x(std::list params); /* members */ /** pointer to pixelbuffer */ uint8_t *m_pixeldata; + /** colortable map */ + std::map m_colortable; /** set of supported PixelFormat handlers */ std::set m_handlers; /** pointer to CPixelFormat implementation */ diff --git a/ue2/imgsynth2/cpixelformat.h b/ue2/imgsynth2/cpixelformat.h index 911a141..a9e1e26 100644 --- a/ue2/imgsynth2/cpixelformat.h +++ b/ue2/imgsynth2/cpixelformat.h @@ -13,7 +13,7 @@ #include class CBitmap; -#include "cbitmap.h" +//#include "cbitmap.h" /** * @class CPixelFormat @@ -72,9 +72,22 @@ class CPixelFormat {}; /** - * @method setPixel - * @brief Modifies pixel at coordinates x, y - * @param pixel pointer to new pixel data + * @brief RGB Pixel structure + */ + typedef struct + { + /** red */ + uint32_t red; + /** green */ + uint32_t green; + /** blue */ + uint32_t blue; + } RGBPIXEL; + + /** + * @method getPixel + * @brief Get pixel at coordinates x, y + * @param pixel reference to pixel data * @param x x-coordinate * @param y y-coordinate * @return - @@ -82,12 +95,12 @@ class CPixelFormat * @exception PixelFormatError * @conditions none */ - virtual void setPixel(const uint32_t *pixel, const uint32_t x, const uint32_t y) = 0; + virtual void getPixel(RGBPIXEL& pixel, const uint32_t x, const uint32_t y) = 0; /** - * @method getPixel - * @brief Get pixel at coordinates x, y - * @param pixel pointer to pixel data + * @method setPixel + * @brief Modifies pixel at coordinates x, y + * @param pixel reference to new pixel data * @param x x-coordinate * @param y y-coordinate * @return - @@ -95,7 +108,7 @@ class CPixelFormat * @exception PixelFormatError * @conditions none */ - virtual void getPixel(uint32_t *pixel, const uint32_t x, const uint32_t y) = 0; + virtual void setPixel(const RGBPIXEL& pixel, const uint32_t x, const uint32_t y) = 0; /** * @method getBitCount @@ -108,10 +121,16 @@ class CPixelFormat */ virtual uint32_t getBitCount() = 0; - /* - * TODO + /** + * @method getMaxColor + * @brief Get maximum values for RGB pixel + * @param pixel reference to pixel struct + * @return - + * @globalvars none + * @exception none + * @conditions none */ - virtual void getMaxColor(unsigned int *red, unsigned int *green, unsigned int *blue) = 0; + virtual void getMaxColor(RGBPIXEL& pixel) = 0; protected: /* members */ diff --git a/ue2/imgsynth2/cpixelformat_bgr24.cpp b/ue2/imgsynth2/cpixelformat_bgr24.cpp index 4567ce6..e7476d7 100644 --- a/ue2/imgsynth2/cpixelformat_bgr24.cpp +++ b/ue2/imgsynth2/cpixelformat_bgr24.cpp @@ -7,17 +7,12 @@ #include #include "cpixelformat_bgr24.h" +#include "cbitmap.h" using namespace std; -/* TODO */ -void CPixelFormat_BGR24::getPixel(uint32_t *pixel, uint32_t x, uint32_t y) +void CPixelFormat_BGR24::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."); @@ -36,25 +31,15 @@ void CPixelFormat_BGR24::getPixel(uint32_t *pixel, uint32_t x, uint32_t y) throw PixelFormatError("Pixel position is out of range."); /* get pixel */ - try - { - pixel[0] = boost::numeric_cast(*(m_bitmap->getPixelData() + offset + 2)); - pixel[1] = boost::numeric_cast(*(m_bitmap->getPixelData() + offset + 1)); - pixel[2] = boost::numeric_cast(*(m_bitmap->getPixelData() + offset)); - } - catch(boost::numeric::bad_numeric_cast& ex) - { - throw PixelFormatError("Unable to convert pixelcolor to correct size: " + string(ex.what())); - } + pixel.red = *(m_bitmap->getPixelData() + offset + 2); + pixel.green = *(m_bitmap->getPixelData() + offset + 1); + pixel.blue = *(m_bitmap->getPixelData() + offset); } -void CPixelFormat_BGR24::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) +/*----------------------------------------------------------------------------*/ + +void CPixelFormat_BGR24::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."); @@ -76,9 +61,9 @@ void CPixelFormat_BGR24::setPixel(const uint32_t *pixel, uint32_t x, uint32_t y) uint8_t data[3]; try { - data[0] = boost::numeric_cast(pixel[2]); - data[1] = boost::numeric_cast(pixel[1]); - data[2] = boost::numeric_cast(pixel[0]); + data[0] = boost::numeric_cast(pixel.blue); + data[1] = boost::numeric_cast(pixel.green); + data[2] = boost::numeric_cast(pixel.red); } catch(boost::numeric::bad_numeric_cast& ex) { diff --git a/ue2/imgsynth2/cpixelformat_bgr24.h b/ue2/imgsynth2/cpixelformat_bgr24.h index 73f22c1..242eadf 100644 --- a/ue2/imgsynth2/cpixelformat_bgr24.h +++ b/ue2/imgsynth2/cpixelformat_bgr24.h @@ -45,13 +45,23 @@ class CPixelFormat_BGR24 : public CPixelFormat ~CPixelFormat_BGR24() {} - /* TODO */ - void getPixel(uint32_t *pixel, uint32_t x, uint32_t y); + /** + * @method getPixel + * @brief Get pixel at coordinates x, y + * @param pixel reference to pixel data + * @param x x-coordinate + * @param y y-coordinate + * @return - + * @globalvars none + * @exception PixelFormatError + * @conditions none + */ + void getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y); /** * @method setPixel * @brief Modifies pixel at coordinates x, y - * @param pixel pointer to new pixel data + * @param pixel reference to new pixel data * @param x x-coordinate * @param y y-coordinate * @return - @@ -59,7 +69,7 @@ class CPixelFormat_BGR24 : public CPixelFormat * @exception PixelFormatError * @conditions none */ - void setPixel(const uint32_t *pixel, uint32_t x, uint32_t y); + void setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y); /** * @method getBitCount @@ -75,12 +85,19 @@ class CPixelFormat_BGR24 : public CPixelFormat return 24; } - /* - * TODO + /** + * @method getMaxColor + * @brief Get maximum values for RGB pixel + * @param pixel reference to pixel struct + * @return - + * @globalvars none + * @exception none + * @conditions none */ - void getMaxColor(unsigned int *red, unsigned int *green, unsigned int *blue) + void getMaxColor(RGBPIXEL& pixel) { - *red = *green = *blue = 255; /* 2^8 - 1 */ + /* value = 2^8 - 1 */ + pixel.red = pixel.green = pixel.blue = 255; } }; 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: */ diff --git a/ue2/imgsynth2/cpixelformat_bgr555.h b/ue2/imgsynth2/cpixelformat_bgr555.h index b04e4be..f131214 100644 --- a/ue2/imgsynth2/cpixelformat_bgr555.h +++ b/ue2/imgsynth2/cpixelformat_bgr555.h @@ -12,7 +12,7 @@ #include #include "cpixelformat.h" -/* TODO */ +/* to (un-)pack pixel values */ #define BGR555_RED_SHIFT 10 #define BGR555_GREEN_SHIFT 5 #define BGR555_BLUE_SHIFT 0 @@ -55,13 +55,23 @@ class CPixelFormat_BGR555 : public CPixelFormat ~CPixelFormat_BGR555() {} - /* TODO */ - void getPixel(uint32_t *pixel, uint32_t x, uint32_t y); + /** + * @method getPixel + * @brief Get pixel at coordinates x, y + * @param pixel reference to pixel data + * @param x x-coordinate + * @param y y-coordinate + * @return - + * @globalvars none + * @exception PixelFormatError + * @conditions none + */ + void getPixel(RGBPIXEL& pixel, uint32_t x, uint32_t y); /** * @method setPixel * @brief Modifies pixel at coordinates x, y - * @param pixel pointer to new pixel data + * @param pixel reference to new pixel data * @param x x-coordinate * @param y y-coordinate * @return - @@ -69,7 +79,7 @@ class CPixelFormat_BGR555 : public CPixelFormat * @exception PixelFormatError * @conditions none */ - void setPixel(const uint32_t *pixel, uint32_t x, uint32_t y); + void setPixel(const RGBPIXEL& pixel, uint32_t x, uint32_t y); /** * @method getBitCount @@ -85,12 +95,19 @@ class CPixelFormat_BGR555 : public CPixelFormat return 16; } - /* - * TODO + /** + * @method getMaxColor + * @brief Get maximum values for RGB pixel + * @param pixel reference to pixel struct + * @return - + * @globalvars none + * @exception none + * @conditions none */ - void getMaxColor(unsigned int *red, unsigned int *green, unsigned int *blue) + void getMaxColor(RGBPIXEL& pixel) { - *red = *green = *blue = 31; /* 2^5 -1 */ + /* value = 2^5 - 1 */ + pixel.red = pixel.green = pixel.blue = 31; } }; diff --git a/ue2/imgsynth2/cwindowsbitmap.h b/ue2/imgsynth2/cwindowsbitmap.h index 28ad010..9fb40db 100644 --- a/ue2/imgsynth2/cwindowsbitmap.h +++ b/ue2/imgsynth2/cwindowsbitmap.h @@ -159,33 +159,80 @@ class CWindowsBitmap : public CBitmap return m_infoheader; } - /* TODO */ + /** + * @method getPixelDataSize + * @brief Return size of pixelbuffer + * @param - + * @return size of pixelbuffer + * @globalvars none + * @exception none + * @conditions none + */ const uint32_t getPixelDataSize() { return m_infoheader.biSizeImage; } - /* TODO */ + /** + * @method getHeight + * @brief Return height of bitmap in pixel + * @param - + * @return height of bitmap in pixel + * @globalvars none + * @exception none + * @conditions none + */ const uint32_t getHeight() { /* width and height can be negativ */ return static_cast(abs(m_infoheader.biHeight)); } - /* TODO */ + /** + * @method getWidth + * @brief Return width of bitmap in pixel + * @param - + * @return width of bitmap in pixel + * @globalvars none + * @exception none + * @conditions none + */ const uint32_t getWidth() { /* width and height can be negativ */ return static_cast(abs(m_infoheader.biWidth)); } - /* TODO */ + /** + * @method isMirrored + * @brief Windows Bitmaps can be stored upside down + * @param - + * @return true if bitmap is stored upside down. false otherwise + * @globalvars none + * @exception none + * @conditions none + */ const bool isMirrored() { /* if height is positive the y-coordinates are mirrored */ return (m_infoheader.biHeight > 0) ? true : false; } + /** + * @method hasColorTable + * @brief Check if bitmap has a colortable + * (we don't support this yet for windows bitmaps) + * @param - + * @return true if bitmap has a colortable. false otherwise + * @globalvars none + * @exception none + * @conditions none + */ + const bool hasColorTable() + { + return false; + } + protected: /* members */ /** fileheader */ diff --git a/ue2/imgsynth2/test/input_yellow_man2_rgb24 b/ue2/imgsynth2/test/input_yellow_man2_rgb24 index 37108b8..7c3253c 100644 --- a/ue2/imgsynth2/test/input_yellow_man2_rgb24 +++ b/ue2/imgsynth2/test/input_yellow_man2_rgb24 @@ -5,9 +5,9 @@ read(BMP, test/yellow_man2_rgb24_in.bmp) fillrect(0,3,6,5,0,255,0) -fillrect(2,13,6,4,0,0,255) +fillrect(2,13,7,4,0,0,255) mirror_x() mirror_y() -#invert() +invert() write(BMP, "test/yellow_man2_rgb24_out.bmp") diff --git a/ue2/imgsynth2/test/input_yellow_man2_rgb555 b/ue2/imgsynth2/test/input_yellow_man2_rgb555 index 3c00301..0fdcbc4 100644 --- a/ue2/imgsynth2/test/input_yellow_man2_rgb555 +++ b/ue2/imgsynth2/test/input_yellow_man2_rgb555 @@ -4,10 +4,10 @@ read(BMP, test/yellow_man2_rgb555_in.bmp) -fillrect(0,3,6,5,0,24,0) -fillrect(2,13,7,4,0,0,24) +fillrect(0,3,6,5,0,31,0) +fillrect(2,13,7,4,0,0,31) mirror_x() mirror_y() -#invert() +invert() write(BMP, "test/yellow_man2_rgb555_out.bmp") diff --git a/ue2/imgsynth2/test/yellow_man1_rgb24_out.bmp b/ue2/imgsynth2/test/yellow_man1_rgb24_out.bmp deleted file mode 100644 index 340eab9..0000000 Binary files a/ue2/imgsynth2/test/yellow_man1_rgb24_out.bmp and /dev/null differ diff --git a/ue2/imgsynth2/test/yellow_man1_rgb555_out.bmp b/ue2/imgsynth2/test/yellow_man1_rgb555_out.bmp deleted file mode 100644 index 1c35ab5..0000000 Binary files a/ue2/imgsynth2/test/yellow_man1_rgb555_out.bmp and /dev/null differ diff --git a/ue2/imgsynth2/test/yellow_man2_rgb24_out.bmp b/ue2/imgsynth2/test/yellow_man2_rgb24_out.bmp deleted file mode 100644 index c859cda..0000000 Binary files a/ue2/imgsynth2/test/yellow_man2_rgb24_out.bmp and /dev/null differ diff --git a/ue2/imgsynth2/test/yellow_man2_rgb555_out.bmp b/ue2/imgsynth2/test/yellow_man2_rgb555_out.bmp deleted file mode 100644 index 60588e3..0000000 Binary files a/ue2/imgsynth2/test/yellow_man2_rgb555_out.bmp and /dev/null differ -- cgit v1.2.3