From 24262eefa031a9d5ef243205719e8edc45d66ea4 Mon Sep 17 00:00:00 2001
From: louis <louis.braun@gmx.de>
Date: Fri, 13 Sep 2013 16:38:04 +0200
Subject: changed channel logo handling and added logo converter script with
 some backgrounds

---
 HISTORY                           |   8 ++++++++
 README                            |  10 ++++++++++
 displaychannel.c                  |   2 ++
 imageloader.c                     |  12 ++++++++++--
 logoconverter/backgrounds/bg1.png | Bin 0 -> 16135 bytes
 logoconverter/backgrounds/bg2.png | Bin 0 -> 16239 bytes
 logoconverter/backgrounds/bg3.png | Bin 0 -> 17074 bytes
 logoconverter/backgrounds/bg4.png | Bin 0 -> 14402 bytes
 logoconverter/backgrounds/fg1.png | Bin 0 -> 27916 bytes
 logoconverter/backgrounds/fg2.png | Bin 0 -> 25492 bytes
 logoconverter/backgrounds/fg3.png | Bin 0 -> 25123 bytes
 logoconverter/backgrounds/fg4.png | Bin 0 -> 17836 bytes
 logoconverter/make_background.sh  |  33 +++++++++++++++++++++++++++++++++
 menudetailview.c                  |   2 ++
 menuitem.c                        |   8 +++++++-
 timers.c                          |   2 ++
 16 files changed, 74 insertions(+), 3 deletions(-)
 create mode 100644 logoconverter/backgrounds/bg1.png
 create mode 100644 logoconverter/backgrounds/bg2.png
 create mode 100644 logoconverter/backgrounds/bg3.png
 create mode 100644 logoconverter/backgrounds/bg4.png
 create mode 100644 logoconverter/backgrounds/fg1.png
 create mode 100644 logoconverter/backgrounds/fg2.png
 create mode 100644 logoconverter/backgrounds/fg3.png
 create mode 100644 logoconverter/backgrounds/fg4.png
 create mode 100644 logoconverter/make_background.sh

diff --git a/HISTORY b/HISTORY
index 95e512a..8669761 100644
--- a/HISTORY
+++ b/HISTORY
@@ -249,3 +249,11 @@ Version 0.1.4
   Feature 1403)
 - Display stereo symbol in displayChannel if at least one mpeg track 
   is available (and not two, closes Feature 1404)
+- Added script and background images to create fancy channel logos with
+  theme dependend background
+- searching channel logos first in <logopath>/theme, then in 
+  <defaltlogopath>/theme, then in <logopath> and finally in <defaultlogopath>
+  to allow theme dependend channel logos
+- if no channel logo is found for channel name, the ChannelID is used to allow
+  logos for (feed) channels with changing names. Analog to the channel name
+  the ChannelID is also converted to lower case letters. 
diff --git a/README b/README
index a0872bb..db1c49b 100644
--- a/README
+++ b/README
@@ -107,10 +107,20 @@ immediately after placing the channel logos in the correct place. So if you have
 the name of a channel logo (may be by inserting a space or a hyphen) so that it fits to
 the channel name, only use lower case letters, and not the name of the channel with upper 
 and lower letters as displayed inside VDR.
+If no logo is found for the channel name, additionally a search for a logo named as the
+ChannelID is performed. Analog to the channel name the ChannelID is also convertted to lower 
+case letters. This allows channel logos for channels with changing names (for instance
+Sky Feed Channels).
 Additional hint: some channels have slashes in their name (in germany nick/comedy for instance).
 In this example, as a dirty hack just create a folder in your channel logo directory named 
 "nick" and place an image named "comedy.png" inside this folder.
 
+In the folder "logoconverter" a script and some backgrounds are provided to create logos
+with fancy backgrounds from the transparent logos. Before running the script, just adapt the 
+config variables in the header of the script according to your needs. If you place the newly 
+created logos in a subfolder of your logo directory named exactly as the used Theme name, 
+nOpacity uses these logos only for the appropriate theme automatically.
+
 RSS Feeds
 ---------
 
diff --git a/displaychannel.c b/displaychannel.c
index 082b43c..e8389fa 100644
--- a/displaychannel.c
+++ b/displaychannel.c
@@ -567,6 +567,8 @@ void cNopacityDisplayChannel::SetChannel(const cChannel *Channel, int Number) {
             cImageLoader imgLoader;
             if (imgLoader.LoadLogo(*ChannelName)) {
                 pixmapLogo->DrawImage(cPoint(config.logoBorder, (height-config.logoHeight)/2), imgLoader.GetImage());
+            } else if (imgLoader.LoadLogo(*(Channel->GetChannelID().ToString()))) {
+                pixmapLogo->DrawImage(cPoint(config.logoBorder, (height-config.logoHeight)/2), imgLoader.GetImage());
             }
         }
         ShowSignalMeter();
diff --git a/imageloader.c b/imageloader.c
index ba90353..cc1f329 100644
--- a/imageloader.c
+++ b/imageloader.c
@@ -20,10 +20,18 @@ bool cImageLoader::LoadLogo(const char *logo, int width = config.logoWidth, int
     toLowerCase(logoLower);
     bool success = false;
     if (config.logoPathSet) {
-        success = LoadImage(logoLower.c_str(), config.logoPath, config.logoExtension);
+        //theme dependend logo
+        cString logoPath = cString::sprintf("%s%s/", *config.logoPath, Setup.OSDTheme);
+        success = LoadImage(logoLower.c_str(), logoPath, config.logoExtension);
+        if (!success)
+            success = LoadImage(logoLower.c_str(), config.logoPath, config.logoExtension);
     }
     if (!success) {
-        success = LoadImage(logoLower.c_str(), config.logoPathDefault, config.logoExtension);
+        //theme dependend logo
+        cString logoPath = cString::sprintf("%s%s/", *config.logoPathDefault, Setup.OSDTheme);
+        success = LoadImage(logoLower.c_str(), logoPath, config.logoExtension);
+        if (!success)
+            success = LoadImage(logoLower.c_str(), config.logoPathDefault, config.logoExtension);
     }
     if (!success)
         return false;
diff --git a/logoconverter/backgrounds/bg1.png b/logoconverter/backgrounds/bg1.png
new file mode 100644
index 0000000..3260391
Binary files /dev/null and b/logoconverter/backgrounds/bg1.png differ
diff --git a/logoconverter/backgrounds/bg2.png b/logoconverter/backgrounds/bg2.png
new file mode 100644
index 0000000..9cf789d
Binary files /dev/null and b/logoconverter/backgrounds/bg2.png differ
diff --git a/logoconverter/backgrounds/bg3.png b/logoconverter/backgrounds/bg3.png
new file mode 100644
index 0000000..87d1f1c
Binary files /dev/null and b/logoconverter/backgrounds/bg3.png differ
diff --git a/logoconverter/backgrounds/bg4.png b/logoconverter/backgrounds/bg4.png
new file mode 100644
index 0000000..fd1e222
Binary files /dev/null and b/logoconverter/backgrounds/bg4.png differ
diff --git a/logoconverter/backgrounds/fg1.png b/logoconverter/backgrounds/fg1.png
new file mode 100644
index 0000000..b87e1d1
Binary files /dev/null and b/logoconverter/backgrounds/fg1.png differ
diff --git a/logoconverter/backgrounds/fg2.png b/logoconverter/backgrounds/fg2.png
new file mode 100644
index 0000000..f970b0b
Binary files /dev/null and b/logoconverter/backgrounds/fg2.png differ
diff --git a/logoconverter/backgrounds/fg3.png b/logoconverter/backgrounds/fg3.png
new file mode 100644
index 0000000..96932ca
Binary files /dev/null and b/logoconverter/backgrounds/fg3.png differ
diff --git a/logoconverter/backgrounds/fg4.png b/logoconverter/backgrounds/fg4.png
new file mode 100644
index 0000000..1b58ebf
Binary files /dev/null and b/logoconverter/backgrounds/fg4.png differ
diff --git a/logoconverter/make_background.sh b/logoconverter/make_background.sh
new file mode 100644
index 0000000..a2acbcb
--- /dev/null
+++ b/logoconverter/make_background.sh
@@ -0,0 +1,33 @@
+#!/bin/bash -e
+#set -x
+
+#CONFIG
+
+SOURCEDIR=/etc/vdr/plugins/skinnopacity/logos
+OUTPUTDIR=/etc/vdr/plugins/skinnopacity/logos_darkred
+FOREGROUND=/usr/local/src/VDR/PLUGINS/src/skinnopacity/logoconverter/backgrounds/fg4.png
+BACKGROUND=/usr/local/src/VDR/PLUGINS/src/skinnopacity/logoconverter/backgrounds/bg2.png
+
+#MAIN
+IFS=$'\n'
+FILES=$(find $SOURCEDIR -name *.png | sort)
+sedstring="s!$SOURCEDIR!$OUTPUTDIR!g"
+
+[ ! -d $SOURCEDIR ] && (echo "ERR: $SOURCEDIR1 not found"; exit 1);
+[ ! -f $FOREGROUND ] && (echo "ERR: $FOREGROUND not found"; exit 1);
+[ ! -f $BACKGROUND ] && (echo "ERR: $BACKGROUND not found"; exit 1);
+
+echo "Convert new logos to format $(basename $OUTPUTDIR)"
+for file in $FILES; do
+  targetdir=`dirname $file | sed -e $sedstring`
+  targetfile="$targetdir/$(basename $file)"
+  if [ ! -f $targetfile ] ; then
+    echo $targetfile
+    [ ! -d $targetdir ]  && mkdir -p $targetdir
+    convert +dither -background 'transparent' -resize '220x164' -extent '268x200' -gravity 'center' "$file" png:- 2> /dev/null | \
+      composite - $BACKGROUND png:- 2> /dev/null | \
+      composite -compose screen -blend 50x100 $FOREGROUND - "$targetfile" 2> /dev/null
+  fi
+done
+
+exit 0
diff --git a/menudetailview.c b/menudetailview.c
index 66a1428..160e6c3 100644
--- a/menudetailview.c
+++ b/menudetailview.c
@@ -445,6 +445,8 @@ void cNopacityMenuDetailEventView::DrawHeader(void) {
     cChannel *channel = Channels.GetByChannelID(event->ChannelID(), true);
     if (channel && channel->Name() && imgLoader.LoadLogo(channel->Name(), logoWidth, config.detailViewLogoHeight)) {        
         pixmapLogo->DrawImage(cPoint(0, max((headerHeight - config.detailViewLogoHeight - border)/2, 0)), imgLoader.GetImage());
+    } else if (channel && imgLoader.LoadLogo(*(channel->GetChannelID().ToString()), logoWidth, config.detailViewLogoHeight)) {
+        pixmapLogo->DrawImage(cPoint(0, max((headerHeight - config.detailViewLogoHeight - border)/2, 0)), imgLoader.GetImage());
     }
     int widthTextHeader = width - 4 * border - logoWidth;
     if (imgLoader.LoadEPGImage(event->EventID())) {
diff --git a/menuitem.c b/menuitem.c
index 1516481..6d17892 100644
--- a/menuitem.c
+++ b/menuitem.c
@@ -524,6 +524,8 @@ void cNopacityScheduleMenuItem::DrawLogo(int logoWidth, int logoHeight) {
         cImageLoader imgLoader;
         if (imgLoader.LoadLogo(Channel->Name(), logoWidth, logoHeight)) {
             pixmapIcon->DrawImage(cPoint(1, 1), imgLoader.GetImage());
+        } else if (imgLoader.LoadLogo(*(Channel->GetChannelID().ToString()), logoWidth, logoHeight)) {
+            pixmapIcon->DrawImage(cPoint(1, 1), imgLoader.GetImage());
         } else {
             cTextWrapper channel;
             channel.Set(Channel->Name(), font, logoWidth);
@@ -764,7 +766,9 @@ void cNopacityChannelMenuItem::Render() {
             cImageLoader imgLoader;
             if (imgLoader.LoadLogo(Channel->Name(), logoWidth, logoHeight)) {
                 pixmapIcon->DrawImage(cPoint(1, 1), imgLoader.GetImage());
-            }
+            } else if (imgLoader.LoadLogo(*(Channel->GetChannelID().ToString()), logoWidth, logoHeight)) {
+                pixmapIcon->DrawImage(cPoint(1, 1), imgLoader.GetImage());
+            } 
             drawn = true;
         }
         SetTextShort();
@@ -934,6 +938,8 @@ void cNopacityTimerMenuItem::DrawLogo(int logoWidth, int logoHeight) {
         cImageLoader imgLoader;
         if (imgLoader.LoadLogo(Timer->Channel()->Name(), logoWidth, logoHeight)) {
             pixmapIcon->DrawImage(cPoint(1, 1), imgLoader.GetImage());
+        } else if (imgLoader.LoadLogo(*(Timer->Channel()->GetChannelID().ToString()), logoWidth, logoHeight)) {
+            pixmapIcon->DrawImage(cPoint(1, 1), imgLoader.GetImage());
         } else {
             cTextWrapper channel;
             channel.Set(Timer->Channel()->Name(), font, logoWidth);
diff --git a/timers.c b/timers.c
index 930df48..a077333 100644
--- a/timers.c
+++ b/timers.c
@@ -172,6 +172,8 @@ void cNopacityTimer::DrawLogo(void) {
         cImageLoader imgLoader;
         if (imgLoader.LoadLogo(Channel->Name(), logoWidth, logoHeight)) {
             pixmapLogo->DrawImage(cPoint((width - logoWidth)/2, 1), imgLoader.GetImage());
+        } else if (imgLoader.LoadLogo(*(Channel->GetChannelID().ToString()), logoWidth, logoHeight)) {
+            pixmapLogo->DrawImage(cPoint((width - logoWidth)/2, 1), imgLoader.GetImage());
         } else {
             cTextWrapper channel;
             channel.Set(Channel->Name(), fontLarge, width - 10);
-- 
cgit v1.2.3