2015-06-13 10:46:11 +02:00
|
|
|
#ifndef __SKINDESIGNER_IMAGELOADER_H
|
|
|
|
#define __SKINDESIGNER_IMAGELOADER_H
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2015-06-13 10:46:11 +02:00
|
|
|
#include <string>
|
2014-10-30 16:41:06 +01:00
|
|
|
#include <cairo.h>
|
2014-10-30 21:07:26 +01:00
|
|
|
#include <librsvg/rsvg.h>
|
2014-11-23 13:07:43 +01:00
|
|
|
#ifndef LIBRSVG_CHECK_VERSION // Workaround for librsvg < 2.36.2
|
2014-11-09 18:45:37 +01:00
|
|
|
#include <librsvg/rsvg-cairo.h>
|
2014-11-23 13:07:43 +01:00
|
|
|
#include <librsvg/librsvg-features.h>
|
2014-11-09 18:45:37 +01:00
|
|
|
#endif
|
2014-11-02 13:41:21 +01:00
|
|
|
#include <jpeglib.h>
|
|
|
|
#include <setjmp.h>
|
2014-09-27 09:25:14 +02:00
|
|
|
#include <vdr/osd.h>
|
2014-10-30 16:41:06 +01:00
|
|
|
#include <vdr/tools.h>
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2015-06-13 10:46:11 +02:00
|
|
|
using namespace std;
|
|
|
|
|
2014-10-30 16:41:06 +01:00
|
|
|
//
|
|
|
|
// Image importers
|
|
|
|
//
|
|
|
|
class cImageImporter {
|
|
|
|
public:
|
|
|
|
cImageImporter() {};
|
|
|
|
virtual ~cImageImporter() {};
|
2014-11-04 16:55:45 +01:00
|
|
|
virtual bool LoadImage(const char *path) { return false; };
|
2014-10-30 16:41:06 +01:00
|
|
|
virtual void DrawToCairo(cairo_t *cr) {};
|
|
|
|
virtual void GetImageSize(int &width, int &height) {};
|
2015-04-02 07:50:14 +02:00
|
|
|
static cImageImporter* CreateImageImporter(const char* path);
|
2014-10-30 16:41:06 +01:00
|
|
|
};
|
2014-09-27 09:25:14 +02:00
|
|
|
|
2014-10-30 16:41:06 +01:00
|
|
|
// Image importer for PNG
|
|
|
|
class cImageImporterPNG : public cImageImporter {
|
2014-09-27 09:25:14 +02:00
|
|
|
public:
|
2014-10-30 16:41:06 +01:00
|
|
|
cImageImporterPNG();
|
|
|
|
~cImageImporterPNG();
|
2014-10-28 16:54:37 +01:00
|
|
|
bool LoadImage(const char *path);
|
2014-10-30 16:41:06 +01:00
|
|
|
void DrawToCairo(cairo_t *cr);
|
|
|
|
void GetImageSize(int &width, int &height);
|
|
|
|
private:
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Image importer for SVG
|
2014-11-23 13:07:43 +01:00
|
|
|
#if !LIBRSVG_CHECK_VERSION(2, 36, 0)
|
|
|
|
#error librsvg version 2.36.0 or above required!
|
|
|
|
#endif
|
|
|
|
|
2014-10-30 16:41:06 +01:00
|
|
|
class cImageImporterSVG : public cImageImporter {
|
|
|
|
public:
|
2014-10-30 21:07:26 +01:00
|
|
|
cImageImporterSVG();
|
2014-10-30 16:41:06 +01:00
|
|
|
~cImageImporterSVG();
|
|
|
|
bool LoadImage(const char *path);
|
2014-10-30 21:07:26 +01:00
|
|
|
void DrawToCairo(cairo_t *cr);
|
2014-10-30 16:41:06 +01:00
|
|
|
void GetImageSize(int &width, int &height);
|
2014-11-23 13:07:43 +01:00
|
|
|
static void InitLibRSVG();
|
2014-10-30 16:41:06 +01:00
|
|
|
private:
|
2014-10-30 21:07:26 +01:00
|
|
|
RsvgHandle *handle;
|
|
|
|
};
|
|
|
|
|
2014-11-02 13:41:21 +01:00
|
|
|
// Image importer for JPG
|
|
|
|
#if BITS_IN_JSAMPLE != 8
|
2014-11-04 16:55:45 +01:00
|
|
|
#error libjpeg has to be compiled with 8-bit samples!
|
2014-11-02 13:41:21 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
class cImageImporterJPG : public cImageImporter {
|
|
|
|
public:
|
|
|
|
cImageImporterJPG();
|
|
|
|
~cImageImporterJPG();
|
|
|
|
bool LoadImage(const char *path);
|
|
|
|
void DrawToCairo(cairo_t *cr);
|
|
|
|
void GetImageSize(int &width, int &height);
|
|
|
|
private:
|
|
|
|
j_decompress_ptr cinfo;
|
|
|
|
FILE *infile;
|
|
|
|
};
|
|
|
|
|
2014-11-10 16:32:38 +01:00
|
|
|
//
|
|
|
|
// Image loader class
|
|
|
|
//
|
2014-10-30 16:41:06 +01:00
|
|
|
class cImageLoader {
|
2014-09-27 09:25:14 +02:00
|
|
|
private:
|
2014-11-04 16:55:45 +01:00
|
|
|
cImageImporter *importer;
|
2014-10-30 16:41:06 +01:00
|
|
|
public:
|
|
|
|
cImageLoader();
|
|
|
|
virtual ~cImageLoader();
|
|
|
|
cImage *CreateImage(int width, int height, bool preserveAspect = true);
|
2014-10-30 21:07:26 +01:00
|
|
|
bool LoadImage(std::string Path, std::string FileName, std::string Extension);
|
2014-10-30 16:41:06 +01:00
|
|
|
bool LoadImage(const char *fullpath);
|
2014-09-27 09:25:14 +02:00
|
|
|
};
|
|
|
|
|
2015-06-13 10:46:11 +02:00
|
|
|
//
|
|
|
|
// SVG Template class
|
|
|
|
//
|
|
|
|
|
|
|
|
class cSVGTemplate {
|
|
|
|
private:
|
|
|
|
string imageName;
|
|
|
|
string templatePath;
|
|
|
|
string filePath;
|
|
|
|
string startTokenColor;
|
|
|
|
string startTokenOpac;
|
|
|
|
string endToken;
|
|
|
|
vector<string> svgTemplate;
|
|
|
|
string GetColorName(string line, size_t tokenStart, size_t tokenEnd);
|
|
|
|
void ReplaceTokens(string &line, size_t tokenStart, size_t tokenEnd, tColor color);
|
|
|
|
public:
|
|
|
|
cSVGTemplate(string imageName, string templatePath);
|
|
|
|
virtual ~cSVGTemplate(void);
|
|
|
|
bool Exists(void);
|
|
|
|
void ReadTemplate(void);
|
|
|
|
bool ParseTemplate(void);
|
|
|
|
string WriteImage(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //__SKINDESIGNER_IMAGELOADER_H
|