summaryrefslogtreecommitdiff
path: root/glcdgraphics/bitmap.c
diff options
context:
space:
mode:
authormrwastl <mrwastl@users.sourceforge.net>2011-05-24 21:21:52 +0200
committermrwastl <mrwastl@users.sourceforge.net>2011-05-24 21:21:52 +0200
commit84efb00f6b7b30ddbfd0551aae3130e86c90562c (patch)
tree489c4e9e4ff9ae8466caf522cfdaef58efda019b /glcdgraphics/bitmap.c
parent38bea28bf1f88a45f2ada8b7f1c95cd5ea89a6bc (diff)
downloadgraphlcd-base-84efb00f6b7b30ddbfd0551aae3130e86c90562c.tar.gz
graphlcd-base-84efb00f6b7b30ddbfd0551aae3130e86c90562c.tar.bz2
support for transparency (images and text); text and images are transparent per default; bug fix: crash when allocing bitmap object with width=0
Diffstat (limited to 'glcdgraphics/bitmap.c')
-rw-r--r--glcdgraphics/bitmap.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/glcdgraphics/bitmap.c b/glcdgraphics/bitmap.c
index c3d617a..e655c5f 100644
--- a/glcdgraphics/bitmap.c
+++ b/glcdgraphics/bitmap.c
@@ -75,10 +75,11 @@ cBitmap::cBitmap(int width, int height, uint32_t * data)
#ifdef DEBUG
printf("%s:%s(%d) cBitmap Size %03d * %03d\n", __FILE__, __FUNCTION__, __LINE__, width, height);
#endif
-
- bitmap = new uint32_t[width * height];
- if (data) {
- memcpy(bitmap, data, width * height * sizeof(uint32_t));
+ if (width > 0 && height > 0) {
+ bitmap = new uint32_t[width * height];
+ if (data && bitmap) {
+ memcpy(bitmap, data, width * height * sizeof(uint32_t));
+ }
}
backgroundColor = cColor::White;
}
@@ -106,7 +107,7 @@ cBitmap::cBitmap(const cBitmap & b)
backgroundColor = b.backgroundColor;
ismonochrome = b.ismonochrome;
bitmap = new uint32_t[b.width * b.height];
- if (b.bitmap) {
+ if (b.bitmap && bitmap) {
memcpy(bitmap, b.bitmap, b.width * b.height * sizeof(uint32_t));
}
}
@@ -121,7 +122,7 @@ void cBitmap::Clear(uint32_t initcol)
#ifdef DEBUG
printf("%s:%s(%d) %03d * %03d (color %08x)\n", __FILE__, __FUNCTION__, __LINE__, width, height, color);
#endif
- uint32_t col = (initcol == cColor::Transparent) ? backgroundColor : initcol;
+ uint32_t col = initcol; //(initcol == cColor::Transparent) ? backgroundColor : initcol;
for (int i = 0; i < width * height; i++)
bitmap[i] = col;
backgroundColor = col;
@@ -540,10 +541,12 @@ void cBitmap::DrawBitmap(int x, int y, const cBitmap & bitmap, uint32_t color, u
for (xt = 0; xt < bitmap.Width(); xt++)
{
cl = data[(yt * bitmap.Width())+xt];
- if (ismonochrome) {
+ if (cl != cColor::Transparent) {
+ if (ismonochrome) {
DrawPixel(xt+x, yt+y, (cl == cColor::Black) ? color : bgcolor);
- } else {
+ } else {
DrawPixel(xt+x, yt+y, cl);
+ }
}
}
}
@@ -691,8 +694,8 @@ int cBitmap::DrawCharacter(int x, int y, int xmax, uint32_t c, const cFont * fon
const cBitmap * charBitmap;
cBitmap * drawBitmap;
- color = cColor::AlignAlpha(color);
- bgcolor = cColor::AlignAlpha(bgcolor);
+ //color = cColor::AlignAlpha(color);
+ //bgcolor = cColor::AlignAlpha(bgcolor);
uint32_t dot = 0;
int xt, yt;