summaryrefslogtreecommitdiff
path: root/libcore
diff options
context:
space:
mode:
authorManuel Reimer <manuel.reimer@gmx.de>2014-10-30 16:41:06 +0100
committerManuel Reimer <manuel.reimer@gmx.de>2014-10-30 16:41:06 +0100
commit94542945595f39866f868181f79583d20a019d1f (patch)
treed33a90022c2d4ea4aedb2af0fb3043012d8865b7 /libcore
parent9609e183f26f2335cc282f8e3424a7bd9d0f25b4 (diff)
downloadvdr-plugin-skindesigner-94542945595f39866f868181f79583d20a019d1f.tar.gz
vdr-plugin-skindesigner-94542945595f39866f868181f79583d20a019d1f.tar.bz2
Removed ImageMagick dependency. Final class names for Cairo backend
Diffstat (limited to 'libcore')
-rw-r--r--libcore/imagecache.c3
-rw-r--r--libcore/imagecache.h7
-rw-r--r--libcore/imageloader.c131
-rw-r--r--libcore/imageloader.h53
-rw-r--r--libcore/imagemagickwrapper.c85
-rw-r--r--libcore/imagemagickwrapper.h22
6 files changed, 163 insertions, 138 deletions
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 <vdr/osd.h>
#include <vdr/skins.h>
-#include <Magick++.h>
#include <vector>
-#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 <math.h>
+//#include <math.h>
#include <string>
#include <dirent.h>
#include <iostream>
-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 *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);
}
-bool cImageLoader::LoadImage(const char *path) {
- return cImageMagickWrapper::LoadImage(path);
+// 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 <cairo.h>
#include <vdr/osd.h>
-#include <vdr/skins.h>
-#include <Magick++.h>
-#include "imagemagickwrapper.h"
+#include <vdr/tools.h>
-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:
- cImageLoader();
- ~cImageLoader();
- cImage *GetImage(int width, int height);
+ cImageImporterPNG();
+ ~cImageImporterPNG();
bool LoadImage(const char *path);
- void DeterminateChannelLogoSize(int &width, int &height);
+ 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();
+ 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);
};
#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 <string>
-#include <sstream>
-#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 <cairo.h>
-#include <vdr/osd.h>
-
-
-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