vdr-plugin-tvguide/imageloader.c

186 lines
6.0 KiB
C
Raw Permalink Normal View History

2013-01-17 13:16:44 +01:00
#include <math.h>
#include <string>
#include <dirent.h>
#include <iostream>
2013-12-21 11:25:03 +01:00
#include <vdr/channels.h>
2013-01-17 13:16:44 +01:00
2013-12-07 15:51:50 +01:00
#include "config.h"
#include "imageloader.h"
2013-12-21 11:25:03 +01:00
#include "tools.h"
2013-12-07 15:51:50 +01:00
2013-01-17 13:16:44 +01:00
using namespace Magick;
cImageLoader::cImageLoader() {
}
cImageLoader::~cImageLoader() {
}
2013-12-21 11:25:03 +01:00
bool cImageLoader::LoadLogo(const cChannel *channel, int width, int height) {
if (!channel || (width == 0)||(height==0))
return false;
2013-12-21 11:25:03 +01:00
std::string channelID = StrToLowerCase(*(channel->GetChannelID().ToString()));
std::string logoLower = StrToLowerCase(channel->Name());
cString extension;
2019-07-11 11:28:11 +02:00
if (config.logoExtension == 0) {
2013-05-26 11:38:05 +02:00
extension = "png";
2019-07-11 11:28:11 +02:00
} else if (config.logoExtension == 1) {
2013-05-26 11:38:05 +02:00
extension = "jpg";
}
2013-12-21 11:25:03 +01:00
bool success = false;
2019-07-11 11:28:11 +02:00
if (config.logoPathSet) {
success = LoadImage(channelID.c_str(), *config.logoPath, *extension);
if (!success) {
2019-07-11 11:28:11 +02:00
success = LoadImage(logoLower.c_str(), *config.logoPath, *extension);
}
2013-12-21 11:25:03 +01:00
}
if (!success)
2019-07-11 11:28:11 +02:00
success = LoadImage(channelID.c_str(), *config.logoPathDefault, *extension);
if (!success)
2019-07-11 11:28:11 +02:00
success = LoadImage(logoLower.c_str(), *config.logoPathDefault, *extension);
2013-12-21 11:25:03 +01:00
if (success)
buffer.sample(Geometry(width, height));
return success;
}
2013-01-17 13:16:44 +01:00
2013-12-21 11:25:03 +01:00
bool cImageLoader::LoadEPGImage(int eventID, int width, int height) {
if ((width == 0)||(height==0))
return false;
bool success = false;
2019-07-11 11:28:11 +02:00
success = LoadImage(*cString::sprintf("%d", eventID), *config.epgImagePath, "jpg");
if (!success)
2019-07-11 11:28:11 +02:00
success = LoadImage(*cString::sprintf("%d_0", eventID), *config.epgImagePath, "jpg");
if (!success)
return false;
2013-12-21 11:25:03 +01:00
buffer.sample( Geometry(width, height));
return true;
2013-01-17 13:16:44 +01:00
}
bool cImageLoader::LoadAdditionalEPGImage(cString name) {
2019-07-11 11:28:11 +02:00
int width = config.epgImageWidthLarge;
int height = config.epgImageHeightLarge;
if ((width == 0)||(height==0))
return false;
bool success = false;
2019-07-11 11:28:11 +02:00
success = LoadImage(*name, *config.epgImagePath, "jpg");
if (!success)
return false;
if (height != 0 || width != 0) {
buffer.sample( Geometry(width, height));
}
return true;
}
2013-08-25 13:57:10 +02:00
bool cImageLoader::LoadPoster(const char *poster, int width, int height) {
if (LoadImage(poster)) {
buffer.sample(Geometry(width, height));
return true;
}
return false;
}
2013-07-09 00:17:42 +02:00
bool cImageLoader::LoadIcon(const char *cIcon, int size) {
if (size==0)
return false;
bool success = false;
2019-07-11 11:28:11 +02:00
if (config.iconsPathSet) {
cString iconPathTheme = cString::sprintf("%s%s/recmenuicons/", *config.iconPath, *config.themeName);
success = LoadImage(cIcon, *iconPathTheme, "png");
if (!success) {
2019-07-11 11:28:11 +02:00
cString iconPath = cString::sprintf("%srecmenuicons/", *config.iconPath);
success = LoadImage(cIcon, *iconPath, "png");
}
}
if (!success) {
2019-07-11 11:28:11 +02:00
cString iconPathTheme = cString::sprintf("%s%s/recmenuicons/", *config.iconPathDefault, *config.themeName);
success = LoadImage(cIcon, *iconPathTheme, "png");
if (!success) {
2019-07-11 11:28:11 +02:00
cString iconPath = cString::sprintf("%srecmenuicons/", *config.iconPathDefault);
success = LoadImage(cIcon, *iconPath, "png");
}
}
2013-07-09 00:17:42 +02:00
if (!success)
return false;
buffer.sample(Geometry(size, size));
return true;
}
2013-12-21 11:25:03 +01:00
bool cImageLoader::LoadOsdElement(cString name, int width, int height) {
if ((width == 0)||(height==0))
return false;
bool success = false;
2019-07-11 11:28:11 +02:00
if (config.iconsPathSet) {
cString path = cString::sprintf("%s%s%s", *config.iconPath, *config.themeName, "/osdElements/");
success = LoadImage(*name, *path, "png");
if (!success) {
2019-07-11 11:28:11 +02:00
path = cString::sprintf("%s%s", *config.iconPath, "/osdElements/");
success = LoadImage(*name, *path, "png");
}
}
if (!success) {
2019-07-11 11:28:11 +02:00
cString path = cString::sprintf("%s%s%s", *config.iconPathDefault, *config.themeName, "/osdElements/");
success = LoadImage(*name, *path, "png");
}
if (!success) {
2019-07-11 11:28:11 +02:00
cString path = cString::sprintf("%s%s", *config.iconPathDefault, "/osdElements/");
success = LoadImage(*name, *path, "png");
}
2013-12-21 11:25:03 +01:00
if (!success)
return false;
Geometry size(width, height);
size.aspect(true);
buffer.sample(size);
2013-12-21 11:25:03 +01:00
return true;
}
bool cImageLoader::DrawBackground(tColor back, tColor blend, int width, int height) {
2013-07-09 00:17:42 +02:00
if ((width < 1) || (height < 1) || (width > 1920) || (height > 1080))
return false;
CreateGradient(back, blend, width, height, 0.8, 0.8);
return true;
2013-01-17 13:16:44 +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;
}
void cImageLoader::CreateGradient(tColor back, tColor blend, int width, int height, double wfactor, double hfactor) {
Color Back = Argb2Color(back);
Color Blend = Argb2Color(blend);
int maxw = MaxRGB * wfactor;
int maxh = MaxRGB * hfactor;
Image imgblend(Geometry(width, height), Blend);
imgblend.modifyImage();
imgblend.type(TrueColorMatteType);
PixelPacket *pixels = imgblend.getPixels(0, 0, width, height);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
PixelPacket *pixel = pixels + y * width + x;
2019-03-23 13:43:37 +01:00
unsigned int opacity = (maxw / width * x + maxh - maxh / height * y) / 2;
pixel->opacity = (opacity <= MaxRGB) ? opacity : MaxRGB;
}
}
imgblend.syncPixels();
Image imgback(Geometry(width, height), Back);
imgback.composite(imgblend, 0, 0, OverCompositeOp);
buffer = imgback;
2019-03-23 13:43:37 +01:00
}