diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2013-03-21 20:29:45 +0100 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2013-03-21 20:29:45 +0100 |
commit | 60bdec72ecd6bb236f2f1153398c9996fb95730f (patch) | |
tree | 7b6a7667f41002b54dcc78360cef71256b811c94 /glcdgraphics | |
parent | cf926629084ab015873859e759155f9bfe813e6b (diff) | |
download | graphlcd-base-60bdec72ecd6bb236f2f1153398c9996fb95730f.tar.gz graphlcd-base-60bdec72ecd6bb236f2f1153398c9996fb95730f.tar.bz2 |
glcdgraphics: bug fix in glcd.c, moved methods Scale() and Blend() to image.c, added static methods for loading/saving image; showpic and convpic working again; convpic cleaned up; showpic: added parameters for scaling and centering image
Diffstat (limited to 'glcdgraphics')
-rw-r--r-- | glcdgraphics/extformats.c | 10 | ||||
-rw-r--r-- | glcdgraphics/glcd.c | 25 | ||||
-rw-r--r-- | glcdgraphics/image.c | 189 | ||||
-rw-r--r-- | glcdgraphics/image.h | 10 | ||||
-rw-r--r-- | glcdgraphics/imagefile.c | 122 | ||||
-rw-r--r-- | glcdgraphics/imagefile.h | 6 | ||||
-rw-r--r-- | glcdgraphics/pbm.c | 15 |
7 files changed, 229 insertions, 148 deletions
diff --git a/glcdgraphics/extformats.c b/glcdgraphics/extformats.c index 3a0ab36..5734fce 100644 --- a/glcdgraphics/extformats.c +++ b/glcdgraphics/extformats.c @@ -8,7 +8,7 @@ * This file is released under the GNU General Public License. Refer * to the COPYING file distributed with this package. * - * (c) 2011-2012 Wolfgang Astleitner <mrwastl AT users sourceforge net> + * (c) 2011-2013 Wolfgang Astleitner <mrwastl AT users sourceforge net> */ #include <stdio.h> @@ -66,7 +66,7 @@ bool cExtFormatFile::LoadScaled(cImage & image, const string & fileName, uint16_ std::vector<Magick::Image>::iterator it; readImages(&extimages, fileName); if (extimages.size() == 0) { - syslog(LOG_ERR, "ERROR: graphlcd: Couldn't load %s", fileName.c_str()); + syslog(LOG_ERR, "glcdgraphics: Couldn't load '%s' (cExtFormatFile::LoadScaled)", fileName.c_str()); return false; } @@ -163,16 +163,16 @@ bool cExtFormatFile::LoadScaled(cImage & image, const string & fileName, uint16_ } } } catch (Magick::Exception &e) { - syslog(LOG_ERR, "ERROR: graphlcd: Couldn't load %s: %s", fileName.c_str(), e.what()); + syslog(LOG_ERR, "glcdgraphics: Couldn't load '%s': %s (cExtFormatFile::LoadScaled)", fileName.c_str(), e.what()); return false; } catch (...) { - syslog(LOG_ERR, "ERROR: graphlcd: Couldn't load %s: Unknown exception caught", fileName.c_str()); + syslog(LOG_ERR, "glcdgraphics: Couldn't load '%s': Unknown exception caught (cExtFormatFile::LoadScaled)", fileName.c_str()); return false; } return true; #else return false; -#endif +#endif } // to be done ... diff --git a/glcdgraphics/glcd.c b/glcdgraphics/glcd.c index 3b2c3f3..6e97208 100644 --- a/glcdgraphics/glcd.c +++ b/glcdgraphics/glcd.c @@ -10,7 +10,7 @@ * to the COPYING file distributed with this package. * * (c) 2004-2010 Andreas Regel <andreas.regel AT powarman.de> - * (c) 2010-2011 Wolfgang Astleitner <mrwastl AT users sourceforge net> + * (c) 2010-2013 Wolfgang Astleitner <mrwastl AT users sourceforge net> * Andreas 'randy' Weinberger */ @@ -69,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; } @@ -98,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; } @@ -114,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; } @@ -126,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; } @@ -136,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; } @@ -146,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; } @@ -156,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; } @@ -213,7 +213,7 @@ bool cGLCDFile::Load(cImage & image, const string & fileName) 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; } @@ -234,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; } @@ -285,8 +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(bitmap->Data(), height * width, 1, fp) != 1) + if (fwrite( cBitmap::ConvertTo1BPP(*bitmap), height * ((width + 7) / 8), 1, fp) != 1) { fclose(fp); return false; @@ -296,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; } diff --git a/glcdgraphics/image.c b/glcdgraphics/image.c index 72003b1..1240b80 100644 --- a/glcdgraphics/image.c +++ b/glcdgraphics/image.c @@ -10,11 +10,17 @@ * to the COPYING file distributed with this package. * * (c) 2004 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2013 Wolfgang Astleitner <mrwastl AT users sourceforge net> */ #include "bitmap.h" #include "image.h" +#include "imagefile.h" +#include "glcd.h" +#include "pbm.h" +#include "extformats.h" +#include <string.h> namespace GLCD { @@ -64,4 +70,187 @@ void cImage::Clear() lastChange = 0; } + +uint32_t cImage::Blend(uint32_t FgColour, uint32_t BgColour, uint8_t Level, double antiAliasGranularity) const +{ + if (antiAliasGranularity > 0.0) + Level = uint8_t(int(Level / antiAliasGranularity + 0.5) * antiAliasGranularity); + int Af = (FgColour & 0xFF000000) >> 24; + int Rf = (FgColour & 0x00FF0000) >> 16; + int Gf = (FgColour & 0x0000FF00) >> 8; + int Bf = (FgColour & 0x000000FF); + int Ab = (BgColour & 0xFF000000) >> 24; + int Rb = (BgColour & 0x00FF0000) >> 16; + int Gb = (BgColour & 0x0000FF00) >> 8; + int Bb = (BgColour & 0x000000FF); + int A = (Ab + (Af - Ab) * Level / 0xFF) & 0xFF; + int R = (Rb + (Rf - Rb) * Level / 0xFF) & 0xFF; + int G = (Gb + (Gf - Gb) * Level / 0xFF) & 0xFF; + int B = (Bb + (Bf - Bb) * Level / 0xFF) & 0xFF; + return (A << 24) | (R << 16) | (G << 8) | B; +} + +bool cImage::Scale(uint16_t scalew, uint16_t scaleh, bool AntiAlias) +{ + if (! (scalew || scaleh) ) + return false; + + unsigned int orig_w = Width(); + unsigned int orig_h = Height(); + + // one out of scalew/h == 0 ? -> auto aspect ratio + if (scalew && ! scaleh) { + scaleh = (uint16_t)( ((uint32_t)scalew * (uint32_t)orig_h) / (uint32_t)orig_w ); + } else if (!scalew && scaleh) { + scalew = (uint16_t)( ((uint32_t)scaleh * (uint32_t)orig_w) / (uint32_t)orig_h ); + } + + cImage tempImg = cImage(); + tempImg.SetWidth(scalew); + tempImg.SetHeight(scaleh); + + // Scaling/Blending based on VDR / osd.c + // Fixed point scaling code based on www.inversereality.org/files/bitmapscaling.pdf + // by deltener@mindtremors.com + // + // slightly improved by Wolfgang Astleitner (modify factors and ratios so that scaled image is centered when upscaling) + + double FactorX, FactorY; + int RatioX, RatioY; + + if (!AntiAlias) { + FactorX = (double)scalew / (double)orig_w; + FactorY = (double)scaleh / (double)orig_h; + RatioX = (orig_w << 16) / scalew; + RatioY = (orig_h << 16) / scaleh; + } else { + FactorX = (double)scalew / (double)(orig_w-1); + FactorY = (double)scaleh / (double)(orig_h-1); + RatioX = ((orig_w-1) << 16) / scalew; + RatioY = ((orig_h-1) << 16) / scaleh; + } + + bool downscale = (!AntiAlias || (FactorX <= 1.0 && FactorY <= 1.0)); + + for (unsigned int frame = 0; frame < Count() ; frame ++ ) { + cBitmap *b = new cBitmap(scalew, scaleh, GRAPHLCD_Transparent); + + cBitmap *currFrame = GetBitmap(frame); + + b->SetMonochrome(currFrame->IsMonochrome()); + + if (downscale) { + // Downscaling - no anti-aliasing: + const uint32_t *DestRow = b->Data(); + int SourceY = 0; + for (int y = 0; y < scaleh; y++) { + int SourceX = 0; + const uint32_t *SourceRow = currFrame->Data() + (SourceY >> 16) * orig_w; + uint32_t *Dest = (uint32_t*) DestRow; + for (int x = 0; x < scalew; x++) { + *Dest++ = SourceRow[SourceX >> 16]; + SourceX += RatioX; + } + SourceY += RatioY; + DestRow += scalew; + } + } else { + // Upscaling - anti-aliasing: + int SourceY = 0; + for (int y = 0; y < scaleh /*- 1*/; y++) { + int SourceX = 0; + int sy = SourceY >> 16; + uint8_t BlendY = 0xFF - ((SourceY >> 8) & 0xFF); + for (int x = 0; x < scalew /*- 1*/; x++) { + int sx = SourceX >> 16; + uint8_t BlendX = 0xFF - ((SourceX >> 8) & 0xFF); + // TODO: antiAliasGranularity + uint32_t c1 = Blend(currFrame->GetPixel(sx, sy), currFrame->GetPixel(sx + 1, sy), BlendX); + uint32_t c2 = Blend(currFrame->GetPixel(sx, sy + 1), currFrame->GetPixel(sx + 1, sy + 1), BlendX); + uint32_t c3 = Blend(c1, c2, BlendY); + b->DrawPixel(x, y, c3); + SourceX += RatioX; + } + SourceY += RatioY; + } + } + tempImg.AddBitmap(b); + } + // clear all bitmaps from this image + unsigned int temp_delay = Delay(); + Clear(); + // set new resolution + SetWidth(scalew); + SetHeight(scaleh); + SetDelay(temp_delay); + // re-add bitmaps from scaled image container + cBitmap * b; + cBitmap * tempb; + for (unsigned int frame = 0; frame < tempImg.Count(); frame ++) { + tempb = tempImg.GetBitmap(frame); + b = new cBitmap(scalew, scaleh, (uint32_t*)tempb->Data()); + b->SetMonochrome(tempb->IsMonochrome()); + AddBitmap(b); + } + return true; +} + + +/* static methods */ +bool cImage::LoadImage(cImage & image, const std::string & fileName) { + const std::string fext = GetFilenameExtension(fileName); + cImageFile* imgFile = NULL; + bool result = true; + + if (fext == "PBM") { + imgFile = new cPBMFile(); + } else if (fext == "GLCD") { + imgFile = new cGLCDFile(); + } else { + imgFile = new cExtFormatFile(); + } + + uint16_t scale_w = 0; + uint16_t scale_h = 0; + + if (!imgFile || (imgFile->LoadScaled(image, fileName, scale_w, scale_h) == false) ) + result = false; + + if (imgFile) delete imgFile; + return result; +} + + +bool cImage::SaveImage(cImage & image, const std::string & fileName) { + const std::string fext = GetFilenameExtension(fileName); + cImageFile* imgFile = NULL; + bool result = false; + + if (fext == "PBM") { + imgFile = new cPBMFile(); + } else if (fext == "GLCD") { + imgFile = new cGLCDFile(); + } else { + imgFile = new cExtFormatFile(); + } + if ( imgFile && imgFile->Save(image, fileName) ) + result = true; + + if (imgFile) delete imgFile; + return result; +} + + +const std::string cImage::GetFilenameExtension(const std::string & fileName) { + size_t pos = fileName.find_last_of('.'); + std::string ext = ""; + if (pos != std::string::npos) { + ext = fileName.substr(pos+1); + for (size_t i = 0; i < ext.size(); i++) + ext[i] = toupper(ext[i]); + } + return ext; +} + + } // end of namespace diff --git a/glcdgraphics/image.h b/glcdgraphics/image.h index 888d942..f594886 100644 --- a/glcdgraphics/image.h +++ b/glcdgraphics/image.h @@ -10,6 +10,7 @@ * to the COPYING file distributed with this package. * * (c) 2004 Andreas Regel <andreas.regel AT powarman.de> + * (c) 2013 Wolfgang Astleitner <mrwastl AT users sourceforge net> */ #ifndef _GLCDGRAPHICS_IMAGE_H_ @@ -18,6 +19,7 @@ #include <stdint.h> #include <vector> +#include <string> namespace GLCD { @@ -33,6 +35,8 @@ private: unsigned int curBitmap; uint64_t lastChange; std::vector <cBitmap *> bitmaps; + + uint32_t Blend(uint32_t fgcol, uint32_t bgcol, uint8_t level, double antiAliasGranularity = 0.0) const; public: cImage(); ~cImage(); @@ -51,6 +55,12 @@ public: cBitmap * GetBitmap() const; void AddBitmap(cBitmap * Bitmap) { bitmaps.push_back(Bitmap); } void Clear(); + + bool Scale(uint16_t scalew, uint16_t scaleh, bool AntiAlias = false); + + static bool LoadImage(cImage & image, const std::string & fileName); + static bool SaveImage(cImage & image, const std::string & fileName); + static const std::string GetFilenameExtension(const std::string & fileName); }; } // end of namespace diff --git a/glcdgraphics/imagefile.c b/glcdgraphics/imagefile.c index b8c6a42..0f9ec25 100644 --- a/glcdgraphics/imagefile.c +++ b/glcdgraphics/imagefile.c @@ -7,7 +7,7 @@ * to the COPYING file distributed with this package. * * (c) 2006 Andreas Regel <andreas.regel AT powarman.de> - * (c) 2010-2012 Wolfgang Astleitner <mrwastl AT users sourceforge net> + * (c) 2010-2013 Wolfgang Astleitner <mrwastl AT users sourceforge net> */ #include "image.h" @@ -35,130 +35,12 @@ bool cImageFile::Save(cImage & image, const std::string & fileName) } -uint32_t cImageFile::Blend(uint32_t FgColour, uint32_t BgColour, uint8_t Level, double antiAliasGranularity) const -{ - if (antiAliasGranularity > 0.0) - Level = uint8_t(int(Level / antiAliasGranularity + 0.5) * antiAliasGranularity); - int Af = (FgColour & 0xFF000000) >> 24; - int Rf = (FgColour & 0x00FF0000) >> 16; - int Gf = (FgColour & 0x0000FF00) >> 8; - int Bf = (FgColour & 0x000000FF); - int Ab = (BgColour & 0xFF000000) >> 24; - int Rb = (BgColour & 0x00FF0000) >> 16; - int Gb = (BgColour & 0x0000FF00) >> 8; - int Bb = (BgColour & 0x000000FF); - int A = (Ab + (Af - Ab) * Level / 0xFF) & 0xFF; - int R = (Rb + (Rf - Rb) * Level / 0xFF) & 0xFF; - int G = (Gb + (Gf - Gb) * Level / 0xFF) & 0xFF; - int B = (Bb + (Bf - Bb) * Level / 0xFF) & 0xFF; - return (A << 24) | (R << 16) | (G << 8) | B; -} - -bool cImageFile::Scale(cImage & image, uint16_t scalew, uint16_t scaleh, bool AntiAlias) -{ - if (! (scalew || scaleh) ) - return false; - - // one out of scalew/h == 0 ? -> auto aspect ratio - if (scalew && ! scaleh) { - scaleh = (uint16_t)( ((uint32_t)scalew * (uint32_t)image.Height()) / (uint32_t)image.Width() ); - } else if (!scalew && scaleh) { - scalew = (uint16_t)( ((uint32_t)scaleh * (uint32_t)image.Width()) / (uint32_t)image.Height() ); - } - - cImage tempImg = cImage(); - tempImg.SetWidth(scalew); - tempImg.SetHeight(scaleh); - - // Scaling/Blending based on VDR / osd.c - // Fixed point scaling code based on www.inversereality.org/files/bitmapscaling.pdf - // by deltener@mindtremors.com - // - // slightly improved by Wolfgang Astleitner (modify factors and ratios so that scaled image is centered when upscaling) - - double FactorX, FactorY; - int RatioX, RatioY; - - if (!AntiAlias) { - FactorX = (double)scalew / (double)image.Width(); - FactorY = (double)scaleh / (double)image.Height(); - RatioX = (image.Width() << 16) / scalew; - RatioY = (image.Height() << 16) / scaleh; - } else { - FactorX = (double)scalew / (double)(image.Width()-1); - FactorY = (double)scaleh / (double)(image.Height()-1); - RatioX = ((image.Width()-1) << 16) / scalew; - RatioY = ((image.Height()-1) << 16) / scaleh; - } - - bool downscale = (!AntiAlias || (FactorX <= 1.0 && FactorY <= 1.0)); - - for (unsigned int frame = 0; frame < image.Count() ; frame ++ ) { - cBitmap *b = new cBitmap(scalew, scaleh, GRAPHLCD_Transparent); - - cBitmap *currFrame = image.GetBitmap(frame); - - b->SetMonochrome(currFrame->IsMonochrome()); - - if (downscale) { - // Downscaling - no anti-aliasing: - const uint32_t *DestRow = b->Data(); - int SourceY = 0; - for (int y = 0; y < scaleh; y++) { - int SourceX = 0; - const uint32_t *SourceRow = currFrame->Data() + (SourceY >> 16) * image.Width(); - uint32_t *Dest = (uint32_t*) DestRow; - for (int x = 0; x < scalew; x++) { - *Dest++ = SourceRow[SourceX >> 16]; - SourceX += RatioX; - } - SourceY += RatioY; - DestRow += scalew; - } - } else { - // Upscaling - anti-aliasing: - int SourceY = 0; - for (int y = 0; y < scaleh /*- 1*/; y++) { - int SourceX = 0; - int sy = SourceY >> 16; - uint8_t BlendY = 0xFF - ((SourceY >> 8) & 0xFF); - for (int x = 0; x < scalew /*- 1*/; x++) { - int sx = SourceX >> 16; - uint8_t BlendX = 0xFF - ((SourceX >> 8) & 0xFF); - // TODO: antiAliasGranularity - uint32_t c1 = Blend(currFrame->GetPixel(sx, sy), currFrame->GetPixel(sx + 1, sy), BlendX); - uint32_t c2 = Blend(currFrame->GetPixel(sx, sy + 1), currFrame->GetPixel(sx + 1, sy + 1), BlendX); - uint32_t c3 = Blend(c1, c2, BlendY); - b->DrawPixel(x, y, c3); - SourceX += RatioX; - } - SourceY += RatioY; - } - } - tempImg.AddBitmap(b); - } - // clear all bitmaps from image - image.Clear(); - // set new resolution - image.SetWidth(scalew); - image.SetHeight(scaleh); - // re-add bitmaps from scaled image container - cBitmap * b; - cBitmap * tempb; - for (unsigned int frame = 0; frame < tempImg.Count(); frame ++) { - tempb = tempImg.GetBitmap(frame); - b = new cBitmap(scalew, scaleh, (uint32_t*)tempb->Data()); - b->SetMonochrome(tempb->IsMonochrome()); - image.AddBitmap(b); - } - return true; -} bool cImageFile::LoadScaled(cImage & image, const std::string & fileName, uint16_t & scalew, uint16_t & scaleh) { if (Load(image, fileName)) { if (scalew || scaleh) { - return Scale(image, scalew, scaleh, true); + return image.Scale(scalew, scaleh, true); } else { return true; } diff --git a/glcdgraphics/imagefile.h b/glcdgraphics/imagefile.h index 60049ea..fd7dbcc 100644 --- a/glcdgraphics/imagefile.h +++ b/glcdgraphics/imagefile.h @@ -7,7 +7,7 @@ * to the COPYING file distributed with this package. * * (c) 2006 Andreas Regel <andreas.regel AT powarman.de> - * (c) 2010-2012 Wolfgang Astleitner <mrwastl AT users sourceforge net> + * (c) 2010-2013 Wolfgang Astleitner <mrwastl AT users sourceforge net> */ #ifndef _GLCDGRAPHICS_IMAGEFILE_H_ @@ -22,10 +22,6 @@ class cImage; class cImageFile { -private: - uint32_t Blend(uint32_t fgcol, uint32_t bgcol, uint8_t level, double antiAliasGranularity = 0.0) const; -protected: - bool Scale(cImage & image, uint16_t scalew, uint16_t scaleh, bool AntiAlias = false); public: cImageFile(); virtual ~cImageFile(); diff --git a/glcdgraphics/pbm.c b/glcdgraphics/pbm.c index d5c0576..3bf94c1 100644 --- a/glcdgraphics/pbm.c +++ b/glcdgraphics/pbm.c @@ -7,7 +7,7 @@ * to the COPYING file distributed with this package. * * (c) 2006-2010 Andreas Regel <andreas.regel AT powarman.de> - * (c) 2010-2011 Wolfgang Astleitner <mrwastl AT users sourceforge net> + * (c) 2010-2013 Wolfgang Astleitner <mrwastl AT users sourceforge net> * Andreas 'randy' Weinberger */ @@ -152,7 +152,7 @@ bool cPBMFile::Load(cImage & image, const std::string & fileName) return false; } fclose(pbmFile); - syslog(LOG_DEBUG, "glcdgraphics: image %s loaded.", fileName.c_str()); + syslog(LOG_DEBUG, "glcdgraphics: image '%s' loaded.", fileName.c_str()); return true; } @@ -189,7 +189,6 @@ bool cPBMFile::Save(cImage & image, const std::string & fileName) } sprintf(str, "P4\n%d %d\n", bitmap->Width(), bitmap->Height()); fwrite(str, strlen(str), 1, fp); -// fwrite(bitmap->Data(), bitmap->LineSize() * bitmap->Height(), 1, fp); fwrite(rawdata, rawdata_size, 1, fp); } fclose(fp); @@ -201,10 +200,17 @@ bool cPBMFile::Save(cImage & image, const std::string & fileName) { uint16_t i; char tmpStr[256]; + size_t pos = fileName.find_last_of('.'); + std::string fileExt = ""; + std::string fileBase = fileName; + if (pos != std::string::npos) { + fileExt = fileName.substr(pos); + fileBase = fileName.substr(0, fileName.length() - fileExt.length()); + } for (i = 0; i < image.Count(); i++) { - sprintf(tmpStr, "%.248s.%05d", fileName.c_str(), i); + sprintf(tmpStr, "%.244s-%05d%s", fileBase.c_str(), i, fileExt.c_str()); fp = fopen(tmpStr, "wb"); if (fp) { @@ -226,7 +232,6 @@ bool cPBMFile::Save(cImage & image, const std::string & fileName) } sprintf(str, "P4\n%d %d\n", bitmap->Width(), bitmap->Height()); fwrite(str, strlen(str), 1, fp); -// fwrite(bitmap->Data(), bitmap->LineSize() * bitmap->Height(), 1, fp); fwrite(rawdata, rawdata_size, 1, fp); } fclose(fp); |