diff options
-rw-r--r-- | glcdgraphics/Makefile | 21 | ||||
-rw-r--r-- | glcdgraphics/extformats.c | 140 | ||||
-rw-r--r-- | glcdgraphics/extformats.h | 35 | ||||
-rw-r--r-- | glcdskin/cache.c | 10 |
4 files changed, 202 insertions, 4 deletions
diff --git a/glcdgraphics/Makefile b/glcdgraphics/Makefile index 399b3ad..d301804 100644 --- a/glcdgraphics/Makefile +++ b/glcdgraphics/Makefile @@ -4,6 +4,11 @@ -include ../Make.config +# External image lib to use: imagemagick, graphicsmagick, or none +# taken from text2skin +IMAGELIB = + + CXXFLAGS += -fPIC VERMAJOR = 2 @@ -14,9 +19,9 @@ BASENAME = libglcdgraphics.so LIBNAME = $(BASENAME).$(VERMAJOR).$(VERMINOR).$(VERMICRO) -OBJS = bitmap.o common.o font.o glcd.o image.o imagefile.o pbm.o +OBJS = bitmap.o common.o font.o glcd.o image.o imagefile.o pbm.o extformats.o -HEADERS = bitmap.h font.h glcd.h image.h imagefile.h pbm.h +HEADERS = bitmap.h font.h glcd.h image.h imagefile.h pbm.h extformats.h ### Implicit rules: @@ -43,6 +48,18 @@ ifdef HAVE_FREETYPE2 DEFINES += -DHAVE_FREETYPE2 endif### Targets: + +ifeq ($(IMAGELIB), imagemagick) + DEFINES += -DHAVE_IMAGEMAGICK + INCLUDES += $(shell pkg-config --cflags ImageMagick++) + LIBS += $(shell pkg-config --libs ImageMagick++) +else ifeq ($(IMAGELIB), graphicsmagick) + DEFINES += -DHAVE_IMAGEMAGICK # yep, really HAVE_IMAGEMAGICK here + INCLUDES += $(shell pkg-config --cflags GraphicsMagick++) + LIBS += $(shell pkg-config --libs GraphicsMagick++) +endif + + all: $(LIBNAME) $(LIBNAME): $(OBJS) diff --git a/glcdgraphics/extformats.c b/glcdgraphics/extformats.c new file mode 100644 index 0000000..0d39880 --- /dev/null +++ b/glcdgraphics/extformats.c @@ -0,0 +1,140 @@ +/* + * GraphLCD graphics library + * + * extformats.c - loading and saving of external formats (via ImageMagick) + * + * based on bitmap.[ch] from text2skin: http://projects.vdr-developer.org/projects/show/plg-text2skin + * + * This file is released under the GNU General Public License. Refer + * to the COPYING file distributed with this package. + * + * (c) 2011 Wolfgang Astleitner <mrwastl AT users sourceforge net> + */ + +#include <stdio.h> +#include <stdint.h> +#include <syslog.h> + +#include <cstring> + +#include "bitmap.h" +#include "extformats.h" +#include "image.h" + +#ifdef HAVE_IMAGEMAGICK +#include <Magick++.h> +using namespace Magick; +//#elif defined(HAVE_IMLIB2) +//#include "quantize.h" +//#include <Imlib2.h> +#endif + + +namespace GLCD +{ + +using namespace std; + + +cExtFormatFile::cExtFormatFile() +{ +#ifdef HAVE_IMAGEMAGICK + InitializeMagick(NULL); +#endif +} + +cExtFormatFile::~cExtFormatFile() +{ +} + +bool cExtFormatFile::Load(cImage & image, const string & fileName) +{ +#ifdef HAVE_IMAGEMAGICK + std::vector<Image> extimages; + try { + uint16_t width = 0; + uint16_t height = 0; + //uint16_t count; + uint32_t delay; + + std::vector<Image>::iterator it; + readImages(&extimages, fileName); + if (extimages.size() == 0) { + syslog(LOG_ERR, "ERROR: graphlcd: Couldn't load %s", fileName.c_str()); + return false; + } + + delay = (uint32_t)(extimages[0].animationDelay() * 10); + + image.Clear(); + image.SetDelay(delay); + + bool firstImage = true; + + for (it = extimages.begin(); it != extimages.end(); ++it) { + bool ignoreImage = false; + + //if (colors != 0){ + (*it).opacity(OpaqueOpacity); + (*it).backgroundColor( Color ( 0,0,0,0) ); + (*it).quantizeColorSpace( RGBColorspace ); + (*it).quantizeColors( 256*256*256 /*colors*/ ); + (*it).quantize(); + //} + + if (firstImage) { + width = (uint16_t)((*it).columns()); + height = (uint16_t)((*it).rows()); + image.SetWidth(width); + image.SetHeight(height); + firstImage = false; + } else { + if ( (width != (uint16_t)((*it).columns())) || (height != (uint16_t)((*it).rows())) ) { + ignoreImage = true; + } + } + + if (! ignoreImage) { + /* + if ((*it).depth() > 8) { + esyslog("ERROR: text2skin: More than 8bpp images are not supported"); + return false; + } + */ + uint32_t * bmpdata = new uint32_t[height * width]; + //Dprintf("this image has %d colors\n", (*it).totalColors()); + + 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)); + ++pix; + } + } + cBitmap * b = new cBitmap(width, height, bmpdata); + b->SetMonochrome(false); + image.AddBitmap(b); + delete[] bmpdata; + bmpdata = NULL; + } + } + } catch (Exception &e) { + syslog(LOG_ERR, "ERROR: graphlcd: Couldn't load %s: %s", fileName.c_str(), e.what()); + return false; + } catch (...) { + syslog(LOG_ERR, "ERROR: graphlcd: Couldn't load %s: Unknown exception caught", fileName.c_str()); + return false; + } + return true; +#else + return false; +#endif +} + +// to be done ... +bool cExtFormatFile::Save(cImage & image, const string & fileName) +{ + return false; +} + +} // end of namespace diff --git a/glcdgraphics/extformats.h b/glcdgraphics/extformats.h new file mode 100644 index 0000000..8a8223c --- /dev/null +++ b/glcdgraphics/extformats.h @@ -0,0 +1,35 @@ +/* + * GraphLCD graphics library + * + * extformats.h - loading and saving of external formats (via ImageMagick) + * + * based on bitmap.[ch] from text2skin: http://projects.vdr-developer.org/projects/show/plg-text2skin + * + * This file is released under the GNU General Public License. Refer + * to the COPYING file distributed with this package. + * + * (c) 2011 Wolfgang Astleitner <mrwastl AT users sourceforge net> + */ + +#ifndef _GLCDGRAPHICS_EXTFORMATS_H_ +#define _GLCDGRAPHICS_EXTFORMATS_H_ + +#include "imagefile.h" + +namespace GLCD +{ + +class cImage; + +class cExtFormatFile : public cImageFile +{ +public: + cExtFormatFile(); + virtual ~cExtFormatFile(); + virtual bool Load(cImage & image, const std::string & fileName); + virtual bool Save(cImage & image, const std::string & fileName); +}; + +} // end of namespace + +#endif diff --git a/glcdskin/cache.c b/glcdskin/cache.c index fdcb4b8..4129eb9 100644 --- a/glcdskin/cache.c +++ b/glcdskin/cache.c @@ -12,6 +12,7 @@ #include <glcdgraphics/image.h> #include <glcdgraphics/glcd.h> #include <glcdgraphics/pbm.h> +#include <glcdgraphics/extformats.h> #include <stdlib.h> #include <string.h> @@ -171,8 +172,13 @@ cImageItem * cImageCache::LoadImage(const std::string & path) } else { - delete image; - return NULL; + cExtFormatFile extformat; + + if (extformat.Load(*image, file) == false) + { + delete image; + return NULL; + } } item = new cImageItem(path, image); |