summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--glcdgraphics/bitmap.c50
-rw-r--r--glcdgraphics/bitmap.h15
-rw-r--r--glcdgraphics/extformats.c3
3 files changed, 45 insertions, 23 deletions
diff --git a/glcdgraphics/bitmap.c b/glcdgraphics/bitmap.c
index cf10885..686e6e3 100644
--- a/glcdgraphics/bitmap.c
+++ b/glcdgraphics/bitmap.c
@@ -70,7 +70,8 @@ cBitmap::cBitmap(int width, int height, uint32_t * data)
: width(width),
height(height),
bitmap(NULL),
- ismonochrome(false)
+ ismonochrome(false),
+ supportAlpha(true)
{
#ifdef DEBUG
printf("%s:%s(%d) cBitmap Size %03d * %03d\n", __FILE__, __FUNCTION__, __LINE__, width, height);
@@ -89,7 +90,8 @@ cBitmap::cBitmap(int width, int height, uint32_t initcol)
: width(width),
height(height),
bitmap(NULL),
- ismonochrome(false)
+ ismonochrome(false),
+ supportAlpha(true)
{
#ifdef DEBUG
printf("%s:%s(%d) cBitmap Size %03d * %03d\n", __FILE__, __FUNCTION__, __LINE__, width, height);
@@ -106,6 +108,7 @@ cBitmap::cBitmap(const cBitmap & b)
lineSize = b.lineSize;
backgroundColor = b.backgroundColor;
ismonochrome = b.ismonochrome;
+ supportAlpha = b.supportAlpha;
bitmap = new uint32_t[b.width * b.height];
if (b.bitmap && bitmap) {
memcpy(bitmap, b.bitmap, b.width * b.height * sizeof(uint32_t));
@@ -117,15 +120,20 @@ cBitmap::~cBitmap()
delete[] bitmap;
}
-void cBitmap::Clear(uint32_t initcol)
+void cBitmap::Clear(uint32_t color)
{
#ifdef DEBUG
printf("%s:%s(%d) %03d * %03d (color %08x)\n", __FILE__, __FUNCTION__, __LINE__, width, height, color);
#endif
- uint32_t col = initcol; //(initcol == cColor::Transparent) ? backgroundColor : initcol;
+ //uint32_t col = initcol; //(initcol == cColor::Transparent) ? backgroundColor : initcol;
+
+ // force clearing colour to contain alpha level = 0xFF
+ if ( color != cColor::Transparent )
+ color = (color & 0x00FFFFFF) | 0xFF000000;
+
for (int i = 0; i < width * height; i++)
- bitmap[i] = col;
- backgroundColor = col;
+ bitmap[i] = color;
+ backgroundColor = color;
}
void cBitmap::Invert()
@@ -145,10 +153,29 @@ void cBitmap::DrawPixel(int x, int y, uint32_t color)
if (y < 0 || y > height - 1)
return;
- if (color != GLCD::cColor::Transparent)
- bitmap[x + (width * y)] = cColor::AlignAlpha(color);
- else
- bitmap[x + (width * y)] = cColor::AlignAlpha(backgroundColor);
+ if (color != GLCD::cColor::Transparent) {
+ uint32_t col = cColor::AlignAlpha(color);
+ if (supportAlpha) {
+ uint32_t bg = bitmap[x + (width * y)];
+ uint32_t afg = (col & 0xFF000000) >> 24;
+ uint32_t rfg = (col & 0x00FF0000) >> 16;
+ uint32_t gfg = (col & 0x0000FF00) >> 8;
+ uint32_t bfg = (col & 0x000000FF);
+
+ uint32_t rbg = (bg & 0x00FF0000) >> 16;
+ uint32_t gbg = (bg & 0x0000FF00) >> 8;
+ uint32_t bbg = (bg & 0x000000FF);
+
+ rfg = (rfg * afg ) / 255 + ( rbg * ( 255 - afg ) ) / 255;
+ gfg = (gfg * afg ) / 255 + ( gbg * ( 255 - afg ) ) / 255;
+ bfg = (bfg * afg ) / 255 + ( bbg * ( 255 - afg ) ) / 255;
+
+ col = 0xFF000000 | (rfg << 16) | (gfg << 8) | bfg;
+ }
+ bitmap[x + (width * y)] = col;
+ }
+ //else
+ // bitmap[x + (width * y)] = cColor::AlignAlpha(backgroundColor);
}
/*
@@ -681,8 +708,9 @@ int cBitmap::DrawCharacter(int x, int y, int xmax, uint32_t c, const cFont * fon
drawWidth = xmax - x + 1;
drawBitmap = new cBitmap(drawWidth /*charBitmap->Width()-skipPixels*/,charBitmap->Height());
- drawBitmap->Clear(bgcolor);
if (drawBitmap) {
+ drawBitmap->SetSupportAlpha(false);
+ drawBitmap->Clear(bgcolor);
for (xt = 0; xt < drawWidth; xt++) {
for (yt = 0; yt < charBitmap->Height() ; yt++) {
diff --git a/glcdgraphics/bitmap.h b/glcdgraphics/bitmap.h
index c9fd0e0..c20ce33 100644
--- a/glcdgraphics/bitmap.h
+++ b/glcdgraphics/bitmap.h
@@ -94,6 +94,7 @@ protected:
int lineSize;
uint32_t * bitmap;
bool ismonochrome;
+ bool supportAlpha;
uint32_t backgroundColor;
@@ -108,7 +109,7 @@ public:
int LineSize() const { return lineSize; }
const uint32_t * Data() const { return bitmap; }
- void Clear(uint32_t initcol = cColor::Transparent);
+ void Clear(uint32_t color = cColor::Transparent);
void Invert();
void DrawPixel(int x, int y, uint32_t color);
void DrawLine(int x1, int y1, int x2, int y2, uint32_t color);
@@ -130,16 +131,8 @@ public:
void SetMonochrome(bool mono) { ismonochrome = mono; }
bool IsMonochrome(void) const { return ismonochrome; }
-#if 0
- int DrawText(int x, int y, int xmax, const std::string & text, const cFont * font,
- uint32_t color, bool proportional = true, int skipPixels = 0) {
- return DrawText(x, y, xmax, text, font, color, cColor::Black, proportional, skipPixels);
- }
- int DrawCharacter(int x, int y, int xmax, char c, const cFont * font,
- uint32_t color, int skipPixels = 0) {
- return DrawCharacter(x, y, xmax, c, font, color, cColor::Black, skipPixels);
- }
-#endif
+ void SetSupportAlpha(bool suppAlpha) { supportAlpha = suppAlpha; }
+ bool IsSupportAlpha(void) const { return supportAlpha; }
bool LoadPBM(const std::string & fileName);
void SavePBM(const std::string & fileName);
diff --git a/glcdgraphics/extformats.c b/glcdgraphics/extformats.c
index c69ee13..75d3693 100644
--- a/glcdgraphics/extformats.c
+++ b/glcdgraphics/extformats.c
@@ -112,7 +112,8 @@ bool cExtFormatFile::Load(cImage & image, const string & fileName)
if ( isMatte && pix->opacity == MaxRGB ) {
bmpdata[iy*width+ix] = cColor::Transparent;
} else {
- bmpdata[iy*width+ix] = (uint32_t)( 0xFF000000 | (int(pix->red * 255 / MaxRGB) << 16) | (int(pix->green * 255 / MaxRGB) << 8) | int(pix->blue * 255 / MaxRGB));
+ //bmpdata[iy*width+ix] = (uint32_t)( 0xFF000000 | (int(pix->red * 255 / MaxRGB) << 16) | (int(pix->green * 255 / MaxRGB) << 8) | int(pix->blue * 255 / MaxRGB));
+ bmpdata[iy*width+ix] = (uint32_t)( (int(255 - (pix->opacity * 255 / MaxRGB)) << 24) | (int(pix->red * 255 / MaxRGB) << 16) | (int(pix->green * 255 / MaxRGB) << 8) | int(pix->blue * 255 / MaxRGB));
}
++pix;
}