summaryrefslogtreecommitdiff
path: root/imageloader.c
blob: e989b84d3d6ea183353cfe54e51f761dc6c225dd (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
#include "imageloader.h"
#include <math.h>
#include <string>
#include <dirent.h>
#include <iostream>

using namespace Magick;


cImageLoader::cImageLoader() {
    InitializeMagick(NULL);
    logoExtension = "png";
}

cImageLoader::~cImageLoader() {
}

cImage* cImageLoader::LoadLogo(const char *logo, int width, int height) {
    if( (width == 0) || (height==0) )
        return NULL;
    dsyslog("imageloader LoadLogo: %s", logo);
    std::string logoLower = logo;
    toLowerCase(logoLower);
    cString File = cString::sprintf("%s/%s.%s", *Config.logoPath, logoLower.c_str(), *logoExtension);

    cImage *img;
    img = imgCache.GetImage( *File, width, height );
    if( img != NULL )
        return img;

    bool success = LoadImage(File);
    if( !success ) {
        dsyslog("imageloader LoadLogo: %s could not be loaded", *File);
        return NULL;
    }

    img = CreateImage(width, height);
    if( img == NULL )
        return NULL;
    imgCache.InsertImage(img, logoLower, width, height);
    return img;
}

cImage* cImageLoader::LoadIcon(const char *cIcon, int width, int height, bool preserveAspect) {
    if ((width == 0)||(height==0))
        return NULL;

    cString File = cString::sprintf("%s%s/%s.%s", *Config.iconPath, Setup.OSDTheme, cIcon, *logoExtension);

    cImage *img;
    img = imgCache.GetImage( *File, width, height );
    if( img != NULL )
        return img;

    bool success = LoadImage(File);
    if( !success ) {
        File = cString::sprintf("%s%s/%s.%s", *Config.iconPath, "default", cIcon, *logoExtension);
        img = imgCache.GetImage( *File, width, height );
        if( img != NULL )
            return img;

        success = LoadImage(File);
        if( !success ) {
            dsyslog("imageloader LoadIcon: %s could not be loaded", *File);
            return NULL;
        }
    }
    img = CreateImage(width, height);
    if( img == NULL )
        return NULL;
    imgCache.InsertImage(img, cIcon, width, height);
    return img;
}

/*
bool cImageLoader::LoadIcon(const char *cIcon, int size) {
	if (size==0)
        return false;
    cString File = cString::sprintf("%s%s/%s.%s", *Config.iconPath, Setup.OSDTheme, cIcon, *logoExtension);
    bool success = LoadImage(File);
    if( !success ) {
        File = cString::sprintf("%s%s/%s.%s", *Config.iconPath, "default", cIcon, *logoExtension);
        success = LoadImage(File);
        if( !success ) {
            dsyslog("imageloader LoadIcon: %s could not be loaded", *File);
            return false;
        }
    }
    if( size >= 0 )
        buffer.sample(Geometry(size, size));
    return true;
}
*/

/*
bool cImageLoader::LoadIcon2(const char *cIcon) {
    try {
        cString File = cString::sprintf("%s%s/%s.%s", *Config.iconPath, Setup.OSDTheme, cIcon, *logoExtension);

        bool success = LoadImage(File);
        if( !success ) {
            File = cString::sprintf("%s%s/%s.%s", *Config.iconPath, "default", cIcon, *logoExtension);
            success = LoadImage(File);
            if( !success ) {
                dsyslog("imageloader LoadIcon: %s could not be loaded", *File);
                return false;
            }
        }
        return true;
    }
    catch (...) {
        return false;
    }
}

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

cImage cImageLoader::GetImage(int width, int height, bool preserveAspect) {
    cImage *img;
    img = CreateImage(width, height, preserveAspect);
    return *img;
}
*/

void cImageLoader::toLowerCase(std::string &str) {
    const int length = str.length();
    for(int i=0; i < length; ++i) {
        str[i] = std::tolower(str[i]);
    }
}