Removed ImageMagick dependency. Final class names for Cairo backend

This commit is contained in:
Manuel Reimer 2014-10-30 16:41:06 +01:00
parent 9609e183f2
commit 9454294559
8 changed files with 164 additions and 152 deletions

View File

@ -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 \

View File

@ -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;
}

View File

@ -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();

View File

@ -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 *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);
}
}

View File

@ -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:
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

View File

@ -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());
}

View File

@ -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

View File

@ -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);
}