diff options
Diffstat (limited to 'glcdgraphics/glcd.c')
-rw-r--r-- | glcdgraphics/glcd.c | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/glcdgraphics/glcd.c b/glcdgraphics/glcd.c index e79b6b8..6e97208 100644 --- a/glcdgraphics/glcd.c +++ b/glcdgraphics/glcd.c @@ -9,7 +9,9 @@ * This file is released under the GNU General Public License. Refer * to the COPYING file distributed with this package. * - * (c) 2004 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2004-2010 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2010-2013 Wolfgang Astleitner <mrwastl AT users sourceforge net> + * Andreas 'randy' Weinberger */ #include <stdio.h> @@ -67,7 +69,7 @@ bool cGLCDFile::Load(cImage & image, const string & fileName) fp = fopen(fileName.c_str(), "rb"); if (!fp) { - syslog(LOG_ERR, "glcdgraphics: open %s failed (cGLCDFile::Load).", fileName.c_str()); + syslog(LOG_ERR, "glcdgraphics: opening of '%s' failed (cGLCDFile::Load).", fileName.c_str()); return false; } @@ -96,7 +98,7 @@ bool cGLCDFile::Load(cImage & image, const string & fileName) // check header sign if (strncmp(sign, kGLCDFileSign, 3) != 0) { - syslog(LOG_ERR, "glcdgraphics: load %s failed, wrong header (cGLCDFile::Load).", fileName.c_str()); + syslog(LOG_ERR, "glcdgraphics: loading of '%s' failed, wrong header (cGLCDFile::Load).", fileName.c_str()); fclose(fp); return false; } @@ -112,7 +114,7 @@ bool cGLCDFile::Load(cImage & image, const string & fileName) height = (buf[3] << 8) | buf[2]; if (width == 0 || height == 0) { - syslog(LOG_ERR, "glcdgraphics: load %s failed, wrong header (cGLCDFile::Load).", fileName.c_str()); + syslog(LOG_ERR, "glcdgraphics: loading of '%s' failed, wrong header (cGLCDFile::Load).", fileName.c_str()); fclose(fp); return false; } @@ -124,7 +126,7 @@ bool cGLCDFile::Load(cImage & image, const string & fileName) // check file length if (fileSize != (long) (height * ((width + 7) / 8) + 8)) { - syslog(LOG_ERR, "glcdgraphics: load %s failed, wrong size (cGLCDFile::Load).", fileName.c_str()); + syslog(LOG_ERR, "glcdgraphics: loading of '%s' failed, wrong size (cGLCDFile::Load).", fileName.c_str()); fclose(fp); return false; } @@ -134,7 +136,7 @@ bool cGLCDFile::Load(cImage & image, const string & fileName) // read count and delay if (fread(buf, 6, 1, fp) != 1) { - syslog(LOG_ERR, "glcdgraphics: load %s failed, wrong header (cGLCDFile::Load).", fileName.c_str()); + syslog(LOG_ERR, "glcdgraphics: loading of '%s' failed, wrong header (cGLCDFile::Load).", fileName.c_str()); fclose(fp); return false; } @@ -144,7 +146,7 @@ bool cGLCDFile::Load(cImage & image, const string & fileName) if (count == 0 || fileSize != (long) (count * (height * ((width + 7) / 8)) + 14)) { - syslog(LOG_ERR, "glcdgraphics: load %s failed, wrong size (cGLCDFile::Load).", fileName.c_str()); + syslog(LOG_ERR, "glcdgraphics: loading of '%s' failed, wrong size (cGLCDFile::Load).", fileName.c_str()); fclose(fp); return false; } @@ -154,7 +156,7 @@ bool cGLCDFile::Load(cImage & image, const string & fileName) } else { - syslog(LOG_ERR, "glcdgraphics: load %s failed, wrong header (cGLCDFile::Load).", fileName.c_str()); + syslog(LOG_ERR, "glcdgraphics: loading of '%s' failed, wrong header (cGLCDFile::Load).", fileName.c_str()); fclose(fp); return false; } @@ -163,32 +165,55 @@ bool cGLCDFile::Load(cImage & image, const string & fileName) image.SetWidth(width); image.SetHeight(height); image.SetDelay(delay); - unsigned char * bmpdata = new unsigned char[height * ((width + 7) / 8)]; - if (bmpdata) + unsigned char * bmpdata_raw = new unsigned char[height * ((width + 7) / 8)]; + uint32_t * bmpdata = new uint32_t[height * width]; + if (bmpdata && bmpdata_raw) { for (unsigned int n = 0; n < count; n++) { - if (fread(bmpdata, height * ((width + 7) / 8), 1, fp) != 1) + if (fread(bmpdata_raw, height * ((width + 7) / 8), 1, fp) != 1) { delete[] bmpdata; fclose(fp); image.Clear(); return false; } - image.AddBitmap(new cBitmap(width, height, bmpdata)); + int colsize = (width+7)/8; + for (int j = 0; j < height; j++) { + for (int i = 0; i < width; i++) { + if ( bmpdata_raw[j*colsize + (i>>3)] & (1 << (7-(i%8))) ) { + bmpdata[j*width+i] = cColor::Black; + } else { + bmpdata[j*width+i] = cColor::White; + } + } + } +#ifdef HAVE_DEBUG + printf("%s:%s(%d) - filename: '%s', count %d\n", __FILE__, __FUNCTION__, __LINE__, fileName.c_str(), n); +#endif + cBitmap * b = new cBitmap(width, height, bmpdata); + b->SetMonochrome(true); + //image.AddBitmap(new cBitmap(width, height, bmpdata)); + image.AddBitmap(b); } delete[] bmpdata; } else { syslog(LOG_ERR, "glcdgraphics: malloc failed (cGLCDFile::Load)."); + if (bmpdata) + delete[] bmpdata; + if (bmpdata_raw) + delete[] bmpdata_raw; fclose(fp); image.Clear(); return false; } fclose(fp); + if (bmpdata_raw) + delete[] bmpdata_raw; - syslog(LOG_DEBUG, "glcdgraphics: image %s loaded.", fileName.c_str()); + syslog(LOG_DEBUG, "glcdgraphics: image '%s' loaded.", fileName.c_str()); return true; } @@ -209,7 +234,7 @@ bool cGLCDFile::Save(cImage & image, const string & fileName) fp = fopen(fileName.c_str(), "wb"); if (!fp) { - syslog(LOG_ERR, "glcdgraphics: open %s failed (cGLCDFile::Save).", fileName.c_str()); + syslog(LOG_ERR, "glcdgraphics: opening '%s' failed (cGLCDFile::Save).", fileName.c_str()); return false; } @@ -260,7 +285,7 @@ bool cGLCDFile::Save(cImage & image, const string & fileName) { if (bitmap->Width() == width && bitmap->Height() == height) { - if (fwrite(bitmap->Data(), height * ((width + 7) / 8), 1, fp) != 1) + if (fwrite( cBitmap::ConvertTo1BPP(*bitmap), height * ((width + 7) / 8), 1, fp) != 1) { fclose(fp); return false; @@ -270,7 +295,7 @@ bool cGLCDFile::Save(cImage & image, const string & fileName) } fclose(fp); - syslog(LOG_DEBUG, "glcdgraphics: image %s saved.", fileName.c_str()); + syslog(LOG_DEBUG, "glcdgraphics: image '%s' saved.", fileName.c_str()); return true; } |