summaryrefslogtreecommitdiff
path: root/libcore/imageloader.c
blob: 1b220a60e0681ceb4f1499c550ac1bba03e44b37 (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
#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::LoadImage(const char *path, int width, int height) {
    if (cImageMagickWrapper::LoadImage(path)) {
        buffer.sample(Geometry(width, height));
        return true;
    }
    return false;
}

void cImageLoader::DeterminateChannelLogoSize(int &width, int &height) {
    cString logoPath = cString::sprintf("%s%s/logos/", *config.skinPath, Setup.OSDTheme);
    cString logoExt = config.logoExtension;
    DIR *folder = NULL;
    struct dirent *file;
    folder = opendir(logoPath);
    if (!folder) {
        return;
    }
    while (file = readdir(folder)) {
        if (endswith(file->d_name, *logoExt)) {
            std::stringstream filePath;
            filePath << *logoPath << file->d_name;
            Image logo;
            try {
                logo.read(filePath.str().c_str());
                Geometry g = logo.size();
                int logoWidth = g.width();
                int logoHeight = g.height();
                if (logoWidth > 0 && logoHeight > 0) {
                    width = logoWidth;
                    height = logoHeight;
                    return;
                }
            } catch( ... ) { }
        }
    }
}