diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2011-05-24 21:21:52 +0200 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2011-05-24 21:21:52 +0200 |
commit | 84efb00f6b7b30ddbfd0551aae3130e86c90562c (patch) | |
tree | 489c4e9e4ff9ae8466caf522cfdaef58efda019b /glcdgraphics | |
parent | 38bea28bf1f88a45f2ada8b7f1c95cd5ea89a6bc (diff) | |
download | graphlcd-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')
-rw-r--r-- | glcdgraphics/bitmap.c | 23 | ||||
-rw-r--r-- | glcdgraphics/bitmap.h | 10 | ||||
-rw-r--r-- | glcdgraphics/extformats.c | 10 |
3 files changed, 29 insertions, 14 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; diff --git a/glcdgraphics/bitmap.h b/glcdgraphics/bitmap.h index 7f17e51..0528441 100644 --- a/glcdgraphics/bitmap.h +++ b/glcdgraphics/bitmap.h @@ -71,7 +71,15 @@ public: operator uint32_t(void) { return GetColor(); } static cColor ParseColor (std::string col); - static uint32_t AlignAlpha (uint32_t col) { return (col & 0xFF000000) ? col : (col | 0xFF000000); } + static uint32_t AlignAlpha (uint32_t col) { + switch (col) { + case Transparent: + case ERRCOL: + return col; + default: + return (col & 0xFF000000) ? col : (col | 0xFF000000); + } + } }; diff --git a/glcdgraphics/extformats.c b/glcdgraphics/extformats.c index 0d39880..6a8de20 100644 --- a/glcdgraphics/extformats.c +++ b/glcdgraphics/extformats.c @@ -75,8 +75,8 @@ bool cExtFormatFile::Load(cImage & image, const string & fileName) bool ignoreImage = false; //if (colors != 0){ - (*it).opacity(OpaqueOpacity); - (*it).backgroundColor( Color ( 0,0,0,0) ); + //(*it).opacity(OpaqueOpacity); + //(*it).backgroundColor( Color ( 0,0,0,0) ); (*it).quantizeColorSpace( RGBColorspace ); (*it).quantizeColors( 256*256*256 /*colors*/ ); (*it).quantize(); @@ -107,7 +107,11 @@ bool cExtFormatFile::Load(cImage & image, const string & fileName) const PixelPacket *pix = (*it).getConstPixels(0, 0, (int)width, (int)height); for (int iy = 0; iy < (int)height; ++iy) { for (int ix = 0; ix < (int)width; ++ix) { - bmpdata[iy*width+ix] = (uint32_t)((~int(pix->opacity * 255 / MaxRGB) << 24) | (int(pix->red * 255 / MaxRGB) << 16) | (int(pix->green * 255 / MaxRGB) << 8) | int(pix->blue * 255 / MaxRGB)); + if ( (int(pix->opacity * 255 / MaxRGB)) < 225 ) { // just an arbitrary border ... + bmpdata[iy*width+ix] = (uint32_t)((~int(pix->opacity * 255 / MaxRGB) << 24) | (int(pix->red * 255 / MaxRGB) << 16) | (int(pix->green * 255 / MaxRGB) << 8) | int(pix->blue * 255 / MaxRGB)); + } else { + bmpdata[iy*width+ix] = cColor::Transparent; + } ++pix; } } |