From 94542945595f39866f868181f79583d20a019d1f Mon Sep 17 00:00:00 2001 From: Manuel Reimer Date: Thu, 30 Oct 2014 16:41:06 +0100 Subject: [PATCH] Removed ImageMagick dependency. Final class names for Cairo backend --- Makefile | 13 ---- libcore/imagecache.c | 3 +- libcore/imagecache.h | 7 +- libcore/imageloader.c | 131 +++++++++++++++++++++++++++++++---- libcore/imageloader.h | 53 +++++++++++--- libcore/imagemagickwrapper.c | 85 ----------------------- libcore/imagemagickwrapper.h | 22 ------ views/view.c | 2 +- 8 files changed, 164 insertions(+), 152 deletions(-) delete mode 100644 libcore/imagemagickwrapper.c delete mode 100644 libcore/imagemagickwrapper.h diff --git a/Makefile b/Makefile index 7b2b7d8..8277229 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,6 @@ # # $Id$ Makefile 1.0 2014/07/24 louis Exp $ -# External image lib to use: imagemagick, graphicsmagick -IMAGELIB = imagemagick - # The official name of this plugin. PLUGIN = skindesigner @@ -47,14 +44,6 @@ DEFINES += $(shell xml2-config --cflags) INCLUDES += $(shell pkg-config --cflags freetype2 fontconfig) -ifeq ($(IMAGELIB), imagemagick) - INCLUDES += $(shell pkg-config --cflags Magick++) - LIBS += $(shell pkg-config --libs Magick++) -else ifeq ($(IMAGELIB), graphicsmagick) - INCLUDES += $(shell pkg-config --cflags GraphicsMagick++) - LIBS += $(shell pkg-config --libs GraphicsMagick++) -endif - INCLUDES += $(shell pkg-config --cflags cairo-png) LIBS += $(shell pkg-config --libs cairo-png) @@ -74,8 +63,6 @@ OBJS = $(PLUGIN).o \ libcore/pixmapcontainer.o \ libcore/fontmanager.o \ libcore/imagecache.o \ - libcore/imagemagickwrapper.o \ - libcore/imagescaler.o \ libcore/helpers.o \ libcore/imageloader.o \ libcore/recfolderinfo.o \ diff --git a/libcore/imagecache.c b/libcore/imagecache.c index 9ad9918..7c96438 100644 --- a/libcore/imagecache.c +++ b/libcore/imagecache.c @@ -7,14 +7,13 @@ #include "../config.h" #include "helpers.h" -using namespace Magick; cMutex cImageCache::mutex; string cImageCache::items[16] = { "Schedule", "Channels", "Timers", "Recordings", "Setup", "Commands", "OSD", "EPG", "DVB", "LNB", "CAM", "Recording", "Replay", "Miscellaneous", "Plugins", "Restart"}; -cImageCache::cImageCache() : cImageMagickWrapper() { +cImageCache::cImageCache() { tempStaticLogo = NULL; } diff --git a/libcore/imagecache.h b/libcore/imagecache.h index db56a67..4e88600 100644 --- a/libcore/imagecache.h +++ b/libcore/imagecache.h @@ -5,14 +5,11 @@ #include #include -#include #include -#include "imagemagickwrapper.h" +#include "imageloader.h" #include "../libtemplate/templatefunction.h" -using namespace Magick; - -class cImageCache : public cImageMagickWrapper { +class cImageCache : public cImageLoader { public: cImageCache(); ~cImageCache(); diff --git a/libcore/imageloader.c b/libcore/imageloader.c index 07b324e..0c20fda 100644 --- a/libcore/imageloader.c +++ b/libcore/imageloader.c @@ -1,25 +1,84 @@ #include "../config.h" #include "helpers.h" #include "imageloader.h" -#include +//#include #include #include #include -using namespace Magick; - -cImageLoader::cImageLoader() : cImageMagickWrapper() { +cImageLoader::cImageLoader() { + importer = NULL; } cImageLoader::~cImageLoader() { + delete(importer); } -cImage *cImageLoader::GetImage(int width, int height) { - return CreateImage(width, height, false); +cImage *cImageLoader::CreateImage(int width, int height, bool preserveAspect) { + if (!importer) return NULL; + + int w, h; + importer->GetImageSize(w, h); + if (width == 0) + width = w; + if (height == 0) + height = h; + + cairo_surface_t *surface; + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); + + cairo_t *cr; + cr = cairo_create(surface); + + double sx = width / (double)w; + double sy = height / (double)h; + if (preserveAspect) { + if (sx < sy) + sy = sx; + if (sy < sx) + sx = sy; + } + cairo_scale(cr, sx, sy); + + importer->DrawToCairo(cr); + cairo_paint(cr); + + cairo_status_t status = cairo_status(cr); + if (status) + dsyslog("skindesigner: Cairo CreateImage Error %s", cairo_status_to_string(status)); + + unsigned char *data = cairo_image_surface_get_data(surface); + cImage *image = new cImage(cSize(width, height), (tColor*)data); + + cairo_destroy(cr); + + return image; } -bool cImageLoader::LoadImage(const char *path) { - return cImageMagickWrapper::LoadImage(path); +bool cImageLoader::LoadImage(const char *fullpath) { + if ((fullpath == NULL) || (strlen(fullpath) < 5)) + return false; + + if (config.debugImageLoading) + dsyslog("skindesigner: trying to load: %s", fullpath); + + delete(importer); + importer = NULL; + + if (endswith(fullpath, ".png")) + importer = new cImageImporterPNG; + else + return false; + + return importer->LoadImage(fullpath); +} + +// Just a different way to call LoadImage. Calls the above one. +bool cImageLoader::LoadImage(std::string FileName, std::string Path, std::string Extension) { + std::stringstream sstrImgFile; + sstrImgFile << Path << FileName << "." << Extension; + std::string imgFile = sstrImgFile.str(); + return LoadImage(imgFile.c_str()); } void cImageLoader::DeterminateChannelLogoSize(int &width, int &height) { @@ -41,18 +100,60 @@ void cImageLoader::DeterminateChannelLogoSize(int &width, int &height) { if (endswith(file->d_name, *logoExt)) { std::stringstream filePath; filePath << *logoPath << file->d_name; - Image logo; - try { - logo.read(filePath.str().c_str()); - Geometry g = logo.size(); - int logoWidth = g.width(); - int logoHeight = g.height(); + if (LoadImage(filePath.str().c_str())) { + int logoWidth = 0; + int logoHeight = 0; + importer->GetImageSize(logoWidth, logoHeight); if (logoWidth > 0 && logoHeight > 0) { width = logoWidth; height = logoHeight; + delete(importer); + importer = NULL; return; } - } catch( ... ) { } + } } } } + + +// +// Image importer for PNG +// + +cImageImporterPNG::cImageImporterPNG() { + surface = NULL; +} + +cImageImporterPNG::~cImageImporterPNG() { + if (surface) + cairo_surface_destroy(surface); +} + +bool cImageImporterPNG::LoadImage(const char *path) { + if (surface) + cairo_surface_destroy(surface); + + surface = cairo_image_surface_create_from_png(path); + + if (cairo_surface_status(surface)) { + if (config.debugImageLoading) + dsyslog("skindesigner: Cairo LoadImage Error: %s", cairo_status_to_string(cairo_surface_status(surface))); + surface = NULL; + return false; + } + + return true; +} + +void cImageImporterPNG::DrawToCairo(cairo_t *cr) { + if (surface) + cairo_set_source_surface(cr, surface, 0, 0); +} + +void cImageImporterPNG::GetImageSize(int &width, int &height) { + if (surface) { + width = cairo_image_surface_get_width(surface); + height = cairo_image_surface_get_height(surface); + } +} diff --git a/libcore/imageloader.h b/libcore/imageloader.h index b2966c9..30e47b7 100644 --- a/libcore/imageloader.h +++ b/libcore/imageloader.h @@ -3,21 +3,56 @@ #define X_DISPLAY_MISSING +#include #include -#include -#include -#include "imagemagickwrapper.h" +#include -using namespace Magick; +// +// Image importers +// +class cImageImporter { +public: + cImageImporter() {}; + virtual ~cImageImporter() {}; + virtual bool LoadImage(const char *path) {}; + virtual void DrawToCairo(cairo_t *cr) {}; + virtual void GetImageSize(int &width, int &height) {}; +}; -class cImageLoader : public cImageMagickWrapper { +// Image importer for PNG +class cImageImporterPNG : public cImageImporter { +public: + cImageImporterPNG(); + ~cImageImporterPNG(); + bool LoadImage(const char *path); + void DrawToCairo(cairo_t *cr); + void GetImageSize(int &width, int &height); +private: + cairo_surface_t *surface; +}; + +// Image importer for SVG +/* +class cImageImporterSVG : public cImageImporter { +public: + ~cImageImporterSVG(); + bool LoadImage(const char *path); + bool RenderToCairo(cairo_t *cr); + void GetImageSize(int &width, int &height); +private: + RsvgHandle *handle = NULL; +}*/ + +class cImageLoader { +private: + cImageImporter *importer = NULL; public: cImageLoader(); - ~cImageLoader(); - cImage *GetImage(int width, int height); - bool LoadImage(const char *path); + virtual ~cImageLoader(); + cImage *CreateImage(int width, int height, bool preserveAspect = true); + bool LoadImage(std::string FileName, std::string Path, std::string Extension); + bool LoadImage(const char *fullpath); void DeterminateChannelLogoSize(int &width, int &height); -private: }; #endif //__NOPACITY_IMAGELOADER_H diff --git a/libcore/imagemagickwrapper.c b/libcore/imagemagickwrapper.c deleted file mode 100644 index 79e48e7..0000000 --- a/libcore/imagemagickwrapper.c +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include -#include "imagemagickwrapper.h" -#include "../config.h" -#include "imagescaler.h" - -cImageMagickWrapper::cImageMagickWrapper() { - InitializeMagick(NULL); -} - -cImageMagickWrapper::~cImageMagickWrapper() { -} - -cImage *cImageMagickWrapper::CreateImage(int width, int height, bool preserveAspect) { - if (image == NULL) return NULL; - - int w, h; - w = cairo_image_surface_get_width(image); - h = cairo_image_surface_get_height(image); - if (width == 0) - width = w; - if (height == 0) - height = h; - - cairo_surface_t *surface; - surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); - - cairo_t *cr; - cr = cairo_create(surface); - - double sx = width / (double)w; - double sy = height / (double)h; - if (preserveAspect) { - if (sx < sy) - sy = sx; - if (sy < sx) - sx = sy; - } - cairo_scale(cr, sx, sy); - - cairo_set_source_surface(cr, image, 0, 0); - cairo_paint(cr); - - cairo_status_t status = cairo_status (cr); - if (status) - dsyslog("skindesigner: Cairo CreateImage Error %s", cairo_status_to_string(status)); - - unsigned char *data = cairo_image_surface_get_data(surface); - cImage *cimage = new cImage(cSize(width, height), (tColor*)data); - - cairo_destroy(cr); - cairo_surface_destroy(image); - image = NULL; - - return cimage; -} - -bool cImageMagickWrapper::LoadImage(const char *fullpath) { - if ((fullpath == NULL) || (strlen(fullpath) < 5)) - return false; - - if (image != NULL) cairo_surface_destroy(image); - - if (config.debugImageLoading) - dsyslog("skindesigner: trying to load: %s", fullpath); - - image = cairo_image_surface_create_from_png(fullpath); - - if (cairo_surface_status(image)) { - if (config.debugImageLoading) - dsyslog("skindesigner: Cairo LoadImage Error: %s", cairo_status_to_string(cairo_surface_status(image))); - image = NULL; - return false; - } - - return true; -} - -// Just a different way to call LoadImage. Calls the above one. -bool cImageMagickWrapper::LoadImage(std::string FileName, std::string Path, std::string Extension) { - std::stringstream sstrImgFile; - sstrImgFile << Path << FileName << "." << Extension; - std::string imgFile = sstrImgFile.str(); - return LoadImage(imgFile.c_str()); -} diff --git a/libcore/imagemagickwrapper.h b/libcore/imagemagickwrapper.h deleted file mode 100644 index b0c19e8..0000000 --- a/libcore/imagemagickwrapper.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __NOPACITY_IMAGEMAGICKWRAPPER_H -#define __NOPACITY_IMAGEMAGICKWRAPPER_H - -#define X_DISPLAY_MISSING - -#include -#include - - -class cImageMagickWrapper { -private: -public: - cImageMagickWrapper(); - ~cImageMagickWrapper(); -protected: - cairo_surface_t *image = NULL; - cImage *CreateImage(int width, int height, bool preserveAspect = true); - bool LoadImage(std::string FileName, std::string Path, std::string Extension); - bool LoadImage(const char *fullpath); -}; - -#endif //__NOPACITY_IMAGEMAGICKWRAPPER_H diff --git a/views/view.c b/views/view.c index 8711136..864eb45 100644 --- a/views/view.c +++ b/views/view.c @@ -712,7 +712,7 @@ void cView::DoDrawImage(int num, cTemplateFunction *func, int x0, int y0) { case itImage: { cImageLoader imgLoader; if (imgLoader.LoadImage(path.c_str())) { - cImage *image = imgLoader.GetImage(width, height); + cImage *image = imgLoader.CreateImage(width, height); DrawImage(num, pos, *image); delete(image); }