diff options
author | louis <louis.braun@gmx.de> | 2013-01-17 14:33:53 +0100 |
---|---|---|
committer | louis <louis.braun@gmx.de> | 2013-01-17 14:33:53 +0100 |
commit | 68928cb9f07eb2461f25a5d082fea4f9bfc94d7f (patch) | |
tree | a2a97ac3f649212319ea56506403d98f6939aa0d /imageloader.c | |
parent | 47c3fea545a1b4607deda1e7d2fa51cbcf89a656 (diff) | |
download | vdr-plugin-tvguide-68928cb9f07eb2461f25a5d082fea4f9bfc94d7f.tar.gz vdr-plugin-tvguide-68928cb9f07eb2461f25a5d082fea4f9bfc94d7f.tar.bz2 |
Changed color buttons to nOpacity style
Diffstat (limited to 'imageloader.c')
-rw-r--r-- | imageloader.c | 144 |
1 files changed, 90 insertions, 54 deletions
diff --git a/imageloader.c b/imageloader.c index 015f805..6221cac 100644 --- a/imageloader.c +++ b/imageloader.c @@ -1,5 +1,8 @@ #include "imageloader.h" #include <math.h> +#include <string> +#include <dirent.h> +#include <iostream> using namespace Magick; @@ -9,70 +12,103 @@ cImageLoader::cImageLoader() { cImageLoader::~cImageLoader() { } -bool cImageLoader::LoadLogo(const char *logo) -{ - try - { - int width = tvguideConfig.logoWidth; - int height = tvguideConfig.logoHeight; - cString extension; - if (tvguideConfig.logoExtension == 0) { +bool cImageLoader::LoadLogo(const char *logo, int width = tvguideConfig.logoWidth, int height = tvguideConfig.logoHeight) { + if ((width == 0)||(height==0)) + return false; + std::string logoLower = logo; + toLowerCase(logoLower); + cString extension; + if (tvguideConfig.logoExtension == 0) { extension = "png"; } else if (tvguideConfig.logoExtension == 1) { extension = "jpg"; } - cString Filename = cString::sprintf("%s%s.%s", *tvguideConfig.logoPath, logo, *extension); - osdImage.read(*Filename); + if (!LoadImage(logoLower.c_str(), tvguideConfig.logoPath, extension)) + return false; + if (height != 0 || width != 0) { + buffer.sample( Geometry(width, height)); + } + return true; +} - if (height != 0 || width != 0) { - osdImage.sample( Geometry(width, height)); - - } - return true; - } - catch (...) - { - return false; - } +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; } -bool cImageLoader::LoadEPGImage(int eventID) -{ - try - { - int width = tvguideConfig.epgImageWidth; - int height = tvguideConfig.epgImageHeight; - cString Filename = cString::sprintf("%s%d.jpg", *tvguideConfig.epgImagePath, eventID); - osdImage.read(*Filename); +void cImageLoader::DrawBackground(tColor back, tColor blend, int width, int height) { + 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; +} - if (height != 0 || width != 0) - osdImage.sample( Geometry(width, height)); - - return true; - } - catch (...) - { - return false; - } +void cImageLoader::DrawBackground2(tColor back, tColor blend, int width, int height) { + Color Back = Argb2Color(back); + Color Blend = Argb2Color(blend); + Image tmp(Geometry(width, height), Blend); + double arguments[9] = {0.0,(double)height,0.0,-0.5*(double)width,0.0,0.0,0.75*(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; } +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; +} -cImage cImageLoader::GetImage() -{ - int w, h; - w = osdImage.columns(); - h = osdImage.rows(); - cImage image (cSize(w, h)); - const PixelPacket *pixels = osdImage.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; +void cImageLoader::toLowerCase(std::string &str) { + const int length = str.length(); + for(int i=0; i < length; ++i) { + str[i] = std::tolower(str[i]); } - } - return image; } + +bool cImageLoader::LoadImage(cString FileName, cString Path, cString Extension) { + try { + cString File = cString::sprintf("%s%s.%s", *Path, *FileName, *Extension); + dsyslog("tvguide: trying to load: %s", *File); + buffer.read(*File); + dsyslog("tvguide: %s sucessfully loaded", *File); + } catch (...) { + return false; + } + return true; +}
\ No newline at end of file |