diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2011-10-15 18:41:49 +0200 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2011-10-15 18:41:49 +0200 |
commit | cb4534730274a32e7c4e64c7f282bd258375b1f9 (patch) | |
tree | e14bfcce71b13d802a31cdae9ed7b43cff9dc1b1 /glcdgraphics/extformats.c | |
parent | ab3acde2326a9d8f942995325b71b3aeaf24b918 (diff) | |
download | graphlcd-base-cb4534730274a32e7c4e64c7f282bd258375b1f9.tar.gz graphlcd-base-cb4534730274a32e7c4e64c7f282bd258375b1f9.tar.bz2 |
support for scaling of images (image/graphicsmagick supported images only at the moment); skins: additional paraemter 'scale' for <image/>; added method for emptying of image cache (cImageCache::Clear())
Diffstat (limited to 'glcdgraphics/extformats.c')
-rw-r--r-- | glcdgraphics/extformats.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/glcdgraphics/extformats.c b/glcdgraphics/extformats.c index ee87a32..764f85c 100644 --- a/glcdgraphics/extformats.c +++ b/glcdgraphics/extformats.c @@ -49,6 +49,13 @@ cExtFormatFile::~cExtFormatFile() bool cExtFormatFile::Load(cImage & image, const string & fileName) { + uint16_t scalew = 0; + uint16_t scaleh = 0; + return LoadScaled(image, fileName, scalew, scaleh); +} + +bool cExtFormatFile::LoadScaled(cImage & image, const string & fileName, uint16_t & scalew, uint16_t & scaleh) +{ #ifdef HAVE_IMAGEMAGICK std::vector<Image> extimages; try { @@ -81,10 +88,32 @@ bool cExtFormatFile::Load(cImage & image, const string & fileName) if (firstImage) { width = (uint16_t)((*it).columns()); height = (uint16_t)((*it).rows()); + firstImage = false; + + // one out of scalew/h == 0 ? -> auto aspect ratio + if (scalew && ! scaleh) { + scaleh = (uint16_t)( ((uint32_t)scalew * (uint32_t)height) / (uint32_t)width ); + } else if (!scalew && scaleh) { + scalew = (uint16_t)( ((uint32_t)scaleh * (uint32_t)width) / (uint32_t)height ); + } + + // scale image + if (scalew && ! (scalew == width && scaleh == height)) { + (*it).scale(Geometry(scalew, scaleh)); + width = scalew; + height = scaleh; + } else { + // not scaled => reset to 0 + scalew = 0; + scaleh = 0; + } + image.SetWidth(width); image.SetHeight(height); - firstImage = false; } else { + if (scalew && scaleh) { + (*it).scale(Geometry(scalew, scaleh)); + } else if ( (width != (uint16_t)((*it).columns())) || (height != (uint16_t)((*it).rows())) ) { ignoreImage = true; } |