diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2011-06-19 21:20:29 +0200 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2011-06-19 21:20:29 +0200 |
commit | ec46b70bd4d1a1450a2bdc197d9e5935c885c40c (patch) | |
tree | ffaeaa90fdfa6dab8c635ddbdbf4a31e73c47f69 | |
parent | a1e556cdb0648769ccb1fa03f468cdcc3b7b9e72 (diff) | |
download | graphlcd-base-ec46b70bd4d1a1450a2bdc197d9e5935c885c40c.tar.gz graphlcd-base-ec46b70bd4d1a1450a2bdc197d9e5935c885c40c.tar.bz2 |
rename SetSupportAlpha()/IsSupportAlpha() to SetProcessAlpha()/IsProcessAlpha() to better reflect it's purpose; add / enhance some comments (alpha channel support)
-rw-r--r-- | glcdgraphics/bitmap.c | 29 | ||||
-rw-r--r-- | glcdgraphics/bitmap.h | 6 | ||||
-rw-r--r-- | glcdskin/object.c | 2 |
3 files changed, 13 insertions, 24 deletions
diff --git a/glcdgraphics/bitmap.c b/glcdgraphics/bitmap.c index 686e6e3..40b851f 100644 --- a/glcdgraphics/bitmap.c +++ b/glcdgraphics/bitmap.c @@ -71,7 +71,7 @@ cBitmap::cBitmap(int width, int height, uint32_t * data) height(height), bitmap(NULL), ismonochrome(false), - supportAlpha(true) + processAlpha(true) { #ifdef DEBUG printf("%s:%s(%d) cBitmap Size %03d * %03d\n", __FILE__, __FUNCTION__, __LINE__, width, height); @@ -91,7 +91,7 @@ cBitmap::cBitmap(int width, int height, uint32_t initcol) height(height), bitmap(NULL), ismonochrome(false), - supportAlpha(true) + processAlpha(true) { #ifdef DEBUG printf("%s:%s(%d) cBitmap Size %03d * %03d\n", __FILE__, __FUNCTION__, __LINE__, width, height); @@ -108,7 +108,7 @@ cBitmap::cBitmap(const cBitmap & b) lineSize = b.lineSize; backgroundColor = b.backgroundColor; ismonochrome = b.ismonochrome; - supportAlpha = b.supportAlpha; + processAlpha = b.processAlpha; bitmap = new uint32_t[b.width * b.height]; if (b.bitmap && bitmap) { memcpy(bitmap, b.bitmap, b.width * b.height * sizeof(uint32_t)); @@ -127,7 +127,7 @@ void cBitmap::Clear(uint32_t color) #endif //uint32_t col = initcol; //(initcol == cColor::Transparent) ? backgroundColor : initcol; - // force clearing colour to contain alpha level = 0xFF + // force clearing (== background) colour to contain alpha level = 0xFF if ( color != cColor::Transparent ) color = (color & 0x00FFFFFF) | 0xFF000000; @@ -155,7 +155,7 @@ void cBitmap::DrawPixel(int x, int y, uint32_t color) if (color != GLCD::cColor::Transparent) { uint32_t col = cColor::AlignAlpha(color); - if (supportAlpha) { + if (processAlpha) { uint32_t bg = bitmap[x + (width * y)]; uint32_t afg = (col & 0xFF000000) >> 24; uint32_t rfg = (col & 0x00FF0000) >> 16; @@ -166,10 +166,13 @@ void cBitmap::DrawPixel(int x, int y, uint32_t color) uint32_t gbg = (bg & 0x0000FF00) >> 8; uint32_t bbg = (bg & 0x000000FF); + // calculate colour channels of new colour depending on alpha channel and background colour rfg = (rfg * afg ) / 255 + ( rbg * ( 255 - afg ) ) / 255; gfg = (gfg * afg ) / 255 + ( gbg * ( 255 - afg ) ) / 255; bfg = (bfg * afg ) / 255 + ( bbg * ( 255 - afg ) ) / 255; + // as we don't support z-buffering, the new colour will always have alpha level == 0xFF + // (it will serve as background colour for future objects that will be drawn onto the current object) col = 0xFF000000 | (rfg << 16) | (gfg << 8) | bfg; } bitmap[x + (width * y)] = col; @@ -178,20 +181,6 @@ void cBitmap::DrawPixel(int x, int y, uint32_t color) // bitmap[x + (width * y)] = cColor::AlignAlpha(backgroundColor); } -/* -void cBitmap::Draw8Pixels(int x, int y, unsigned char pixels, eColor color) -{ - if (x < 0 || x > width - 1) - return; - if (y < 0 || y > height - 1) - return; - - if (color == clrBlack) - bitmap[lineSize * y + x / 8] |= pixels; - else - bitmap[lineSize * y + x / 8] &= ~pixels; -} -*/ void cBitmap::DrawLine(int x1, int y1, int x2, int y2, uint32_t color) { @@ -709,7 +698,7 @@ int cBitmap::DrawCharacter(int x, int y, int xmax, uint32_t c, const cFont * fon drawBitmap = new cBitmap(drawWidth /*charBitmap->Width()-skipPixels*/,charBitmap->Height()); if (drawBitmap) { - drawBitmap->SetSupportAlpha(false); + drawBitmap->SetProcessAlpha(false); drawBitmap->Clear(bgcolor); for (xt = 0; xt < drawWidth; xt++) { diff --git a/glcdgraphics/bitmap.h b/glcdgraphics/bitmap.h index c20ce33..f0e010e 100644 --- a/glcdgraphics/bitmap.h +++ b/glcdgraphics/bitmap.h @@ -94,7 +94,7 @@ protected: int lineSize; uint32_t * bitmap; bool ismonochrome; - bool supportAlpha; + bool processAlpha; uint32_t backgroundColor; @@ -131,8 +131,8 @@ public: void SetMonochrome(bool mono) { ismonochrome = mono; } bool IsMonochrome(void) const { return ismonochrome; } - void SetSupportAlpha(bool suppAlpha) { supportAlpha = suppAlpha; } - bool IsSupportAlpha(void) const { return supportAlpha; } + void SetProcessAlpha(bool procAlpha) { processAlpha = procAlpha; } + bool IsProcessAlpha(void) const { return processAlpha; } bool LoadPBM(const std::string & fileName); void SavePBM(const std::string & fileName); diff --git a/glcdskin/object.c b/glcdskin/object.c index fe8c17d..336f21e 100644 --- a/glcdskin/object.c +++ b/glcdskin/object.c @@ -545,7 +545,7 @@ void cSkinObject::Render(GLCD::cBitmap * screen) { cBitmap* pane = new cBitmap(Size().w, Size().h, cColor::Transparent); - pane->SetSupportAlpha(false); + pane->SetProcessAlpha(false); const cFont * font = skinFont->Font(); std::string text = ""; |