2013-01-17 13:16:44 +01:00
|
|
|
#include "imageloader.h"
|
|
|
|
#include <math.h>
|
2013-01-17 14:33:53 +01:00
|
|
|
#include <string>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <iostream>
|
2013-01-17 13:16:44 +01:00
|
|
|
|
|
|
|
using namespace Magick;
|
|
|
|
|
|
|
|
cImageLoader::cImageLoader() {
|
2013-02-03 17:38:05 +01:00
|
|
|
InitializeMagick(NULL);
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cImageLoader::~cImageLoader() {
|
|
|
|
}
|
|
|
|
|
2013-05-24 16:23:23 +02:00
|
|
|
bool cImageLoader::LoadLogo(const char *logo, int width, int height) {
|
|
|
|
|
2013-01-17 14:33:53 +01:00
|
|
|
if ((width == 0)||(height==0))
|
|
|
|
return false;
|
|
|
|
std::string logoLower = logo;
|
|
|
|
toLowerCase(logoLower);
|
|
|
|
cString extension;
|
|
|
|
if (tvguideConfig.logoExtension == 0) {
|
2013-05-26 11:38:05 +02:00
|
|
|
extension = "png";
|
|
|
|
} else if (tvguideConfig.logoExtension == 1) {
|
|
|
|
extension = "jpg";
|
|
|
|
}
|
2013-01-17 14:33:53 +01:00
|
|
|
if (!LoadImage(logoLower.c_str(), tvguideConfig.logoPath, extension))
|
|
|
|
return false;
|
2013-05-24 16:23:23 +02:00
|
|
|
buffer.sample( Geometry(width, height));
|
2013-01-17 14:33:53 +01:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-17 13:16:44 +01:00
|
|
|
|
2013-01-17 14:33:53 +01:00
|
|
|
bool cImageLoader::LoadEPGImage(int eventID) {
|
|
|
|
int width = tvguideConfig.epgImageWidth;
|
|
|
|
int height = tvguideConfig.epgImageHeight;
|
|
|
|
if ((width == 0)||(height==0))
|
|
|
|
return false;
|
|
|
|
if (!LoadImage(cString::sprintf("%d", eventID), tvguideConfig.epgImagePath, "jpg"))
|
|
|
|
return false;
|
|
|
|
if (height != 0 || width != 0) {
|
|
|
|
buffer.sample( Geometry(width, height));
|
|
|
|
}
|
|
|
|
return true;
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
2013-01-17 16:19:37 +01:00
|
|
|
bool cImageLoader::DrawBackground(tColor back, tColor blend, int width, int height) {
|
2013-05-24 16:23:23 +02:00
|
|
|
if ((width < 1) || (height < 1))
|
2013-01-17 16:19:37 +01:00
|
|
|
return false;
|
2013-01-17 14:33:53 +01:00
|
|
|
Color Back = Argb2Color(back);
|
|
|
|
Color Blend = Argb2Color(blend);
|
|
|
|
Image tmp(Geometry(width, height), Blend);
|
|
|
|
double arguments[9] = {0.0,(double)height,0.0,-1*(double)width,0.0,0.0,1.5*(double)width,0.0,1.0};
|
|
|
|
tmp.sparseColor(MatteChannel, BarycentricColorInterpolate, 9, arguments);
|
|
|
|
Image tmp2(Geometry(width, height), Back);
|
|
|
|
tmp.composite(tmp2, 0, 0, OverlayCompositeOp);
|
|
|
|
buffer = tmp;
|
2013-01-17 16:19:37 +01:00
|
|
|
return true;
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
|
2013-01-17 14:33:53 +01:00
|
|
|
cImage cImageLoader::GetImage() {
|
|
|
|
int w, h;
|
|
|
|
w = buffer.columns();
|
|
|
|
h = buffer.rows();
|
|
|
|
cImage image (cSize(w, h));
|
|
|
|
const PixelPacket *pixels = buffer.getConstPixels(0, 0, w, h);
|
|
|
|
for (int iy = 0; iy < h; ++iy) {
|
|
|
|
for (int ix = 0; ix < w; ++ix) {
|
|
|
|
tColor col = (~int(pixels->opacity * 255 / MaxRGB) << 24)
|
|
|
|
| (int(pixels->green * 255 / MaxRGB) << 8)
|
|
|
|
| (int(pixels->red * 255 / MaxRGB) << 16)
|
|
|
|
| (int(pixels->blue * 255 / MaxRGB) );
|
|
|
|
image.SetPixel(cPoint(ix, iy), col);
|
|
|
|
++pixels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color cImageLoader::Argb2Color(tColor col) {
|
|
|
|
tIndex alpha = (col & 0xFF000000) >> 24;
|
|
|
|
tIndex red = (col & 0x00FF0000) >> 16;
|
|
|
|
tIndex green = (col & 0x0000FF00) >> 8;
|
|
|
|
tIndex blue = (col & 0x000000FF);
|
|
|
|
Color color(MaxRGB*red/255, MaxRGB*green/255, MaxRGB*blue/255, MaxRGB*(0xFF-alpha)/255);
|
|
|
|
return color;
|
|
|
|
}
|
2013-01-17 13:16:44 +01:00
|
|
|
|
2013-01-17 14:33:53 +01:00
|
|
|
void cImageLoader::toLowerCase(std::string &str) {
|
|
|
|
const int length = str.length();
|
|
|
|
for(int i=0; i < length; ++i) {
|
|
|
|
str[i] = std::tolower(str[i]);
|
2013-01-17 13:16:44 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-17 14:33:53 +01:00
|
|
|
|
|
|
|
bool cImageLoader::LoadImage(cString FileName, cString Path, cString Extension) {
|
|
|
|
try {
|
|
|
|
cString File = cString::sprintf("%s%s.%s", *Path, *FileName, *Extension);
|
2013-05-20 11:37:37 +02:00
|
|
|
//dsyslog("tvguide: trying to load: %s", *File);
|
2013-01-17 14:33:53 +01:00
|
|
|
buffer.read(*File);
|
2013-05-20 11:37:37 +02:00
|
|
|
//dsyslog("tvguide: %s sucessfully loaded", *File);
|
2013-01-17 14:33:53 +01:00
|
|
|
} catch (...) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2013-02-03 17:38:05 +01:00
|
|
|
}
|