summaryrefslogtreecommitdiff
path: root/libcore/imageloader.h
blob: 6a83dec8250c5a5ed6b682940d781f9a7451eac5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef __NOPACITY_IMAGELOADER_H
#define __NOPACITY_IMAGELOADER_H

#include <cairo.h>
#include <librsvg/rsvg.h>
#ifndef LIBRSVG_CHECK_VERSION // Workaround for librsvg < 2.36.2
    #include <librsvg/rsvg-cairo.h>
    #include <librsvg/librsvg-features.h>
#endif
#include <jpeglib.h>
#include <setjmp.h>
#include <vdr/osd.h>
#include <vdr/tools.h>

//
// Image importers
//
class cImageImporter {
public:
    cImageImporter() {};
    virtual ~cImageImporter() {};
    virtual bool LoadImage(const char *path) { return false; };
    virtual void DrawToCairo(cairo_t *cr) {};
    virtual void GetImageSize(int &width, int &height) {};
};

// 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
#if !LIBRSVG_CHECK_VERSION(2, 36, 0)
    #error librsvg version 2.36.0 or above required!
#endif

class cImageImporterSVG : public cImageImporter {
public:
    cImageImporterSVG();
    ~cImageImporterSVG();
    bool LoadImage(const char *path);
    void DrawToCairo(cairo_t *cr);
    void GetImageSize(int &width, int &height);
    static void InitLibRSVG();
private:
    RsvgHandle *handle;
};

// Image importer for JPG
#if BITS_IN_JSAMPLE != 8
    #error libjpeg has to be compiled with 8-bit samples!
#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;
};

//
// Image loader class
//
class cImageLoader {
private:
    cImageImporter *importer;
public:
    cImageLoader();
    virtual ~cImageLoader();
    cImage *CreateImage(int width, int height, bool preserveAspect = true);
    bool LoadImage(std::string Path, std::string FileName, std::string Extension);
    bool LoadImage(const char *fullpath);
};

#endif //__NOPACITY_IMAGELOADER_H