vdr-plugin-skindesigner/libcore/imageloader.h

104 lines
2.5 KiB
C
Raw Normal View History

2014-09-27 09:25:14 +02:00
#ifndef __NOPACITY_IMAGELOADER_H
#define __NOPACITY_IMAGELOADER_H
#include <cairo.h>
2014-10-30 21:07:26 +01:00
#include <librsvg/rsvg.h>
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>
#include <vdr/tools.h>
2014-09-27 09:25:14 +02: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; };
virtual void DrawToCairo(cairo_t *cr) {};
virtual void GetImageSize(int &width, int &height) {};
};
2014-09-27 09:25:14 +02:00
// Image importer for PNG
class cImageImporterPNG : public cImageImporter {
2014-09-27 09:25:14 +02:00
public:
cImageImporterPNG();
~cImageImporterPNG();
2014-10-28 16:54:37 +01:00
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:
2014-10-30 21:07:26 +01:00
cImageImporterSVG();
~cImageImporterSVG();
bool LoadImage(const char *path);
2014-10-30 21:07:26 +01:00
void DrawToCairo(cairo_t *cr);
void GetImageSize(int &width, int &height);
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
struct my_error_mgr {
2014-11-04 16:55:45 +01:00
struct jpeg_error_mgr pub; // "public" fields
jmp_buf setjmp_buffer; // for return to caller
2014-11-02 13:41:21 +01:00
};
METHODDEF(void)
my_error_exit(j_common_ptr cinfo) {
// cinfo->err really points to a my_error_mgr struct, so coerce pointer
my_error_mgr *myerr = (my_error_mgr*) cinfo->err;
// Always display the message.
(*cinfo->err->output_message) (cinfo);
// Return control to the setjmp point
longjmp(myerr->setjmp_buffer, 1);
}
METHODDEF(void)
my_output_message(j_common_ptr cinfo) {
char buf[JMSG_LENGTH_MAX];
cinfo->err->format_message(cinfo, buf);
dsyslog("skindesigner: libjpeg error: %s", buf);
}
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;
};
class cImageLoader {
2014-09-27 09:25:14 +02:00
private:
2014-11-04 16:55:45 +01:00
cImageImporter *importer;
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);
bool LoadImage(const char *fullpath);
void DeterminateChannelLogoSize(int &width, int &height);
2014-09-27 09:25:14 +02:00
};
#endif //__NOPACITY_IMAGELOADER_H