From cb4534730274a32e7c4e64c7f282bd258375b1f9 Mon Sep 17 00:00:00 2001 From: mrwastl Date: Sat, 15 Oct 2011 18:41:49 +0200 Subject: support for scaling of images (image/graphicsmagick supported images only at the moment); skins: additional paraemter 'scale' for ; added method for emptying of image cache (cImageCache::Clear()) --- glcdgraphics/extformats.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'glcdgraphics/extformats.c') diff --git a/glcdgraphics/extformats.c b/glcdgraphics/extformats.c index ee87a32..764f85c 100644 --- a/glcdgraphics/extformats.c +++ b/glcdgraphics/extformats.c @@ -48,6 +48,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 extimages; @@ -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; } -- cgit v1.2.3