summaryrefslogtreecommitdiff
path: root/imageloader.c
blob: c36837075177ab249a0a282be60e3e4b41513077 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "config.h"
#include "helpers.h"
#include "imageloader.h"
#include <math.h>
#include <string>
#include <dirent.h>
#include <iostream>

using namespace Magick;

cImageLoader::cImageLoader() : cImageMagickWrapper() {
}

cImageLoader::~cImageLoader() {
}

cImage cImageLoader::GetImage() {
    return CreateImageCopy();
}

bool cImageLoader::LoadLogo(const char *logo, int width, int height ) {
    if ((width == 0)||(height==0))
        return false;
    std::string logoLower = StrToLowerCase(logo);
    bool success = false;
    if (config.logoPathSet) {
        //theme dependend logo
        cString logoPath = cString::sprintf("%s%s/", *config.logoPath, Setup.OSDTheme);
        success = LoadImage(logoLower.c_str(), *logoPath, *config.logoExtension);
        if (!success)
            success = LoadImage(logoLower.c_str(), *config.logoPath, *config.logoExtension);
    }
    if (!success) {
        //theme dependend logo
        cString logoPath = cString::sprintf("%s%s/", *config.logoPathDefault, Setup.OSDTheme);
        success = LoadImage(logoLower.c_str(), *logoPath, *config.logoExtension);
        if (!success)
            success = LoadImage(logoLower.c_str(), *config.logoPathDefault, *config.logoExtension);
    }
    if (!success)
        return false;
    if (height != 0 || width != 0) {
        buffer.sample( Geometry(width, height));
    }
    return true;
}

bool cImageLoader::LoadEPGImage(int eventID) {
    int width = config.GetValue("epgImageWidth");
    int height = config.GetValue("epgImageHeight");
    if ((width == 0)||(height==0))
        return false;
    bool success = false;
    if (config.epgImagePathSet) {
        success = LoadImage(*cString::sprintf("%d", eventID), *config.epgImagePath, "jpg");
    }
    if (!success) {
        success = LoadImage(*cString::sprintf("%d", eventID), *config.epgImagePathDefault, "jpg");
    }
    if (!success && config.epgImagePathSet) {
        success = LoadImage(*cString::sprintf("%d_0", eventID), *config.epgImagePath, "jpg");
    }
    if (!success) {
        success = LoadImage(*cString::sprintf("%d_0", eventID), *config.epgImagePathDefault, "jpg");
    }
    if (!success)
        return false;
    if (height != 0 || width != 0) {
        buffer.sample( Geometry(width, height));
    }
    return true;
}

bool cImageLoader::LoadAdditionalEPGImage(cString name) {
    int width = config.GetValue("epgImageWidthLarge");
    int height = config.GetValue("epgImageHeightLarge");
    if ((width == 0)||(height==0))
        return false;
    bool success = false;
    if (config.epgImagePathSet) {
        success = LoadImage(*name, *config.epgImagePath, "jpg");
    }
    if (!success) {
        success = LoadImage(*name, *config.epgImagePathDefault, "jpg");
    }
    if (!success)
        return false;
    if (height != 0 || width != 0) {
        buffer.sample( Geometry(width, height));
    }
    return true;
}

bool cImageLoader::LoadRecordingImage(cString Path) {
    int width = config.GetValue("epgImageWidth");
    int height = config.GetValue("epgImageHeight");
    if ((width == 0)||(height==0))
        return false;
    cString recImage("");
    if (FirstImageInFolder(Path, "jpg", &recImage)) {
        recImage = cString::sprintf("/%s", *recImage);
        if (!LoadImage(*recImage, *Path, "jpg"))
            return false;
        buffer.sample( Geometry(width, height));
        return true;
    }
    return false;
}

bool cImageLoader::LoadAdditionalRecordingImage(cString path, cString name) {
    int width = config.GetValue("epgImageWidthLarge");
    int height = config.GetValue("epgImageHeightLarge");
    if ((width == 0)||(height==0))
        return false;
    if (LoadImage(*name, *path, "jpg")) {
        buffer.sample( Geometry(width, height));
        return true;
    }
    return false;
}

bool cImageLoader::LoadPoster(const char *poster, int width, int height) {
    if (LoadImage(poster)) {
        buffer.sample(Geometry(width, height));
        return true;
    }
    return false;
}

bool cImageLoader::SearchRecordingPoster(cString recPath, cString &found) {
    cString manualPoster = cString::sprintf("%s/cover_vdr.jpg", *recPath);
    if (FileSize(*manualPoster) != -1) {
        found = manualPoster;
        return true;
    }
    manualPoster = cString::sprintf("%s/../../../cover_vdr.jpg", *recPath);
    if (FileSize(*manualPoster) != -1) {
        found = manualPoster;
        return true;
    }
    manualPoster = cString::sprintf("%s/../../cover_vdr.jpg", *recPath);
    if (FileSize(*manualPoster) != -1) {
        found = manualPoster;
        return true;
    }
    return false;
}

bool cImageLoader::FirstImageInFolder(cString Path, cString Extension, cString *recImage) {
    DIR *folder;
    struct dirent *file;
    folder = opendir(Path);
    while (file = readdir(folder)) {
        if (endswith(file->d_name, *Extension)) {
            std::string fileName = file->d_name;
            if (!fileName.compare(fileName.size()-8, 8, "_vdr.jpg"))
                continue;
            if (fileName.length() > 4)
                fileName = fileName.substr(0, fileName.length() - 4);
            else
                return false;
            *recImage = fileName.c_str();
            return true;
        }
    }
    return false;
}