|
From: <lk...@us...> - 2007-08-08 09:28:26
|
Revision: 810
http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=810&view=rev
Author: lkuech
Date: 2007-08-08 02:28:23 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
Initial Upload
Added Paths:
-----------
trunk/plugins/ViewModeSwitcher/IconDisabled.GIF
trunk/plugins/ViewModeSwitcher/IconDisabled.png
trunk/plugins/ViewModeSwitcher/IconEnabled.GIF
trunk/plugins/ViewModeSwitcher/IconEnabled.png
trunk/plugins/ViewModeSwitcher/PlugInBase.cs
trunk/plugins/ViewModeSwitcher/Properties/
trunk/plugins/ViewModeSwitcher/Properties/AssemblyInfo.cs
trunk/plugins/ViewModeSwitcher/Rule.cs
trunk/plugins/ViewModeSwitcher/Settings.cs
trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.cs
trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.csproj
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherConfig.Designer.cs
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherConfig.cs
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherConfig.resx
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelper.sln
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelper.suo
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV02/
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV02/Properties/
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV02/Properties/AssemblyInfo.cs
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV02/ViewModeSwitcherHelper.cs
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV02/ViewModeSwitcherHelper.sln
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV02/ViewModeSwitcherHelper.suo
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV02/ViewModeSwitcherHelperTVE2.csproj
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV03/
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV03/Properties/
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV03/Properties/AssemblyInfo.cs
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV03/ViewModeSwitcherHelper.cs
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV03/ViewModeSwitcherHelper.sln
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV03/ViewModeSwitcherHelper.suo
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherHelperTV03/ViewModeSwitcherHelperTVE3.csproj
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherRuleDetail.Designer.cs
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherRuleDetail.cs
trunk/plugins/ViewModeSwitcher/ViewModeSwitcherRuleDetail.resx
Added: trunk/plugins/ViewModeSwitcher/IconDisabled.GIF
===================================================================
(Binary files differ)
Property changes on: trunk/plugins/ViewModeSwitcher/IconDisabled.GIF
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/ViewModeSwitcher/IconDisabled.png
===================================================================
(Binary files differ)
Property changes on: trunk/plugins/ViewModeSwitcher/IconDisabled.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/ViewModeSwitcher/IconEnabled.GIF
===================================================================
(Binary files differ)
Property changes on: trunk/plugins/ViewModeSwitcher/IconEnabled.GIF
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/ViewModeSwitcher/IconEnabled.png
===================================================================
(Binary files differ)
Property changes on: trunk/plugins/ViewModeSwitcher/IconEnabled.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/plugins/ViewModeSwitcher/PlugInBase.cs
===================================================================
--- trunk/plugins/ViewModeSwitcher/PlugInBase.cs (rev 0)
+++ trunk/plugins/ViewModeSwitcher/PlugInBase.cs 2007-08-08 09:28:23 UTC (rev 810)
@@ -0,0 +1,83 @@
+/* Copyright (C) 2005-2007 Team MediaPortal
+ * http://www.team-mediaportal.com
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Make; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using MediaPortal.GUI.Library;
+using MediaPortal.Configuration;
+
+namespace ProcessPlugins.ViewModeSwitcher
+{
+ [PluginIcons("IconEnabled.GIF", "IconDisabled.GIF")]
+ public abstract class PlugInBase : IPlugin, ISetupForm
+ {
+ public abstract void Stop();
+ public abstract void Start();
+
+ public string PluginName()
+ {
+ return "ViewModeSwitcher";
+ }
+
+ public string Description()
+ {
+ return "Switches to a predefined viewmode depending on the aspect ratio of the source format. It also allows crop settings dependig on the source format.";
+ }
+
+ public string Author()
+ {
+ return "LKuech";
+ }
+
+ public void ShowPlugin()
+ {
+ ViewModeSwitcherConfig form = new ViewModeSwitcherConfig();
+ form.ShowDialog();
+ }
+
+ public int GetWindowId()
+ {
+ return 4711667;
+ }
+
+ public bool CanEnable()
+ {
+ return true;
+ }
+
+ public bool DefaultEnabled()
+ {
+ return false;
+ }
+
+ public bool HasSetup()
+ {
+ return true;
+ }
+
+ public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage)
+ {
+ strButtonText = null; strButtonImage = null; strButtonImageFocus = null; strPictureImage = null;
+
+ return false;
+ }
+ }
+}
Added: trunk/plugins/ViewModeSwitcher/Properties/AssemblyInfo.cs
===================================================================
--- trunk/plugins/ViewModeSwitcher/Properties/AssemblyInfo.cs (rev 0)
+++ trunk/plugins/ViewModeSwitcher/Properties/AssemblyInfo.cs 2007-08-08 09:28:23 UTC (rev 810)
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// Allgemeine Informationen über eine Assembly werden über die folgenden
+// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
+// die mit einer Assembly verknüpft sind.
+[assembly: AssemblyTitle("ViewModeSwitcher process plugin for MediaPortal")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ViewModeSwitcher")]
+[assembly: AssemblyCopyright("Copyright © 2007")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
+// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
+// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
+[assembly: ComVisible(false)]
+
+// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
+[assembly: Guid("80d659b8-9c9c-40fd-b6dd-b878db9fc0d1")]
+
+// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
+//
+// Hauptversion
+// Nebenversion
+// Buildnummer
+// Revision
+//
+// Sie können alle Werte angeben oder die standardmäßigen Revisions- und Buildnummern
+// übernehmen, indem Sie "*" eingeben:
+[assembly: AssemblyVersion("0.3.0.0")]
+[assembly: AssemblyFileVersion("0.3.0.0")]
Added: trunk/plugins/ViewModeSwitcher/Rule.cs
===================================================================
--- trunk/plugins/ViewModeSwitcher/Rule.cs (rev 0)
+++ trunk/plugins/ViewModeSwitcher/Rule.cs 2007-08-08 09:28:23 UTC (rev 810)
@@ -0,0 +1,52 @@
+/* Copyright (C) 2005-2007 Team MediaPortal
+ * http://www.team-mediaportal.com
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Make; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using MediaPortal.GUI.Library;
+
+namespace ProcessPlugins.ViewModeSwitcher
+{
+ public class Rule
+ {
+ public bool Enabled = true;
+ public string Name = "new rule";
+ public float ARFrom = 0;
+ public float ARTo = 0;
+ public int MinWidth = 0;
+ public int MaxWidth = 9999;
+ public int MinHeight = 0;
+ public int MaxHeight = 9999;
+ public bool ChangeAR = true;
+ public Geometry.Type ViewMode = Geometry.Type.Normal;
+ public bool ChangeOs = true;
+ public int OverScan = 0;
+ public bool EnableLBDetection = false;
+ public int VerticalOffSetZoom = 0;
+ public int VerticalOffSet14_9 = 0;
+ public int VerticalOffSetWide14_9 = 0;
+ }
+
+ public class RuleSet : List<Rule>
+ {
+ }
+
+}
Added: trunk/plugins/ViewModeSwitcher/Settings.cs
===================================================================
--- trunk/plugins/ViewModeSwitcher/Settings.cs (rev 0)
+++ trunk/plugins/ViewModeSwitcher/Settings.cs 2007-08-08 09:28:23 UTC (rev 810)
@@ -0,0 +1,229 @@
+/* Copyright (C) 2005-2007 Team MediaPortal
+ * http://www.team-mediaportal.com
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Make; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using MediaPortal.Configuration;
+using MediaPortal.GUI.Library;
+
+namespace ProcessPlugins.ViewModeSwitcher
+{
+ public class ViewModeswitcherSettings
+ {
+ public RuleSet ViewModeRules = new RuleSet();
+ public bool verboseLog = false;
+ public bool ShowSwitchMsg = false;
+ public bool SuppressInitialMsg = false;
+ public bool DisableLBGlobaly = false;
+ public int LBCheckInterval = 3000;
+ public bool UpperBoxEnabled = true;
+ public int UpperBoxWidth = 25;
+ public int UpperBoxHeight = 8;
+ public int UpperBoxStartPos = 1;
+ public int CenterBoxWidth = 25;
+ public int CenterBoxHeight = 8;
+ public bool LowerBoxEnabled = true;
+ public int LowerBoxWidth = 25;
+ public int LowerBoxHeight = 8;
+ public int LowerBoxStartPos = 92;
+ public float LBBlackLevel = 0.10f;
+ public int LBDetectionCount = 1;
+ public bool LBOverScanEnabled = false;
+ public int LBOberScan = 0;
+ public int VerticalOffSetZoom = 0;
+ public int VerticalOffSet14_9 = 0;
+ public int VerticalOffSetWide14_9 = 0;
+
+ // parameter names
+ public static string ViewModeSwitcherSectionName = "ViewModeSwitcher";
+ string ParmVerboselog = "parmverboselog";
+ string ParmRuleCount = "parmrulecount";
+ string ParmRulePrefix = "parmrule";
+ string ParmShowSwitchMsg = "parmshowswitchmsg";
+ string ParmSuppressInitalMsg = "parmsuppressinitialmsg";
+ string ParmDisableLBGlobaly = "parmdisablelbglobaly";
+ string ParmLBCheckInterval = "parmlbcheckinterval";
+ string ParmUpBoxEnabled = "parmupboxenabled";
+ string ParmUpBoxWidth = "parmupboxwidth";
+ string ParmUpBoxHeight = "parmupboxheight";
+ string ParmUpBoxStart = "parmupboxstart";
+ string ParmCentBoxWidth = "parmcentboxwidth";
+ string ParmCentBoxHeight = "parmcentboxheight";
+ string ParmLowBoxEnabled = "parmlowboxenabled";
+ string ParmLowBoxWidth = "parmlowboxwidth";
+ string ParmLowBoxHeight = "parmlowboxheight";
+ string ParmLowBoxStart = "parmlowboxstart";
+ string ParmBlackLevel = "parmblacklevel";
+ string ParmLBDetectionCount = "parmlbdetectioncount";
+ string ParmLBOverScanEnabled = "parmlboverscanenabled";
+ string ParmLBOverScan = "parmlboverscan";
+ string ParmVOffsetZoom = "parmvoffsetzoom";
+ string ParmVOffset14_9 = "parmvoffset149";
+ string ParmVOffsetWide14_9 = "parmvoffsetwide149";
+ public static string ParmTVChannelPrefix = "parmtvchannelprefix";
+
+ /// <summary>
+ /// load settings from MediaPortal configuration
+ /// </summary>
+ /// <returns></returns>
+ public bool LoadSettings()
+ {
+ using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")))
+ {
+ bool tmpReturn = false;
+ ViewModeRules.Clear();
+ int tmpRuleCount = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmRuleCount, 0);
+ for (int i = 1; i <= tmpRuleCount; i++)
+ {
+ Rule tmpRule = new Rule();
+ tmpRule.Enabled = reader.GetValueAsBool(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "Enabled", false);
+ if (tmpRule.Enabled) tmpReturn = true;
+ tmpRule.Name = reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "Name", "noname");
+ tmpRule.ARFrom = (float)Convert.ToDouble(reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "ARFrom", "0"));
+ tmpRule.ARTo = (float)Convert.ToDouble(reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "ARTo", "0"));
+ tmpRule.MinWidth = Convert.ToInt16(reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "MinWidth", "0"));
+ tmpRule.MaxWidth = Convert.ToInt16(reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "MaxWidth", "0"));
+ tmpRule.MinHeight = Convert.ToInt16(reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "MinHeight", "0"));
+ tmpRule.MaxHeight = Convert.ToInt16(reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "MaxHeight", "0"));
+ tmpRule.ChangeAR = reader.GetValueAsBool(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "ChangeAR", true);
+ String tmpViewMode = reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "ViewMode", "Normal");
+
+ switch (tmpViewMode)
+ {
+ case "Zoom": tmpRule.ViewMode = Geometry.Type.Zoom;
+ break;
+ case "Normal": tmpRule.ViewMode = Geometry.Type.Normal;
+ break;
+ case "Stretch": tmpRule.ViewMode = Geometry.Type.Stretch;
+ break;
+ case "Original": tmpRule.ViewMode = Geometry.Type.Original;
+ break;
+ case "LetterBox43": tmpRule.ViewMode = Geometry.Type.LetterBox43;
+ break;
+ case "PanScan43": tmpRule.ViewMode = Geometry.Type.PanScan43;
+ break;
+ case "Zoom14to9": tmpRule.ViewMode = Geometry.Type.Zoom14to9;
+ break;
+ }
+ tmpRule.ChangeOs = reader.GetValueAsBool(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "ChangeOS", true);
+ tmpRule.OverScan = Convert.ToInt16(reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "Overscan", "0"));
+ tmpRule.EnableLBDetection = reader.GetValueAsBool(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "EnableLBDetection", false);
+
+ tmpRule.VerticalOffSetZoom = Convert.ToInt16(reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "VerticalOffSetZoom", "0"));
+ tmpRule.VerticalOffSet14_9 = Convert.ToInt16(reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "VerticalOffSet14_9", "0"));
+ tmpRule.VerticalOffSetWide14_9 = Convert.ToInt16(reader.GetValueAsString(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "VerticalOffSetWide14_9", "0"));
+
+ ViewModeRules.Add(tmpRule);
+ }
+ verboseLog = reader.GetValueAsBool(ViewModeSwitcherSectionName, ParmVerboselog, false);
+ ShowSwitchMsg = reader.GetValueAsBool(ViewModeSwitcherSectionName, ParmShowSwitchMsg, false);
+ SuppressInitialMsg = reader.GetValueAsBool(ViewModeSwitcherSectionName, ParmSuppressInitalMsg, false);
+
+ DisableLBGlobaly = reader.GetValueAsBool(ViewModeSwitcherSectionName, ParmDisableLBGlobaly, false);
+ LBCheckInterval = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmLBCheckInterval, 3000);
+
+ UpperBoxEnabled = reader.GetValueAsBool(ViewModeSwitcherSectionName, ParmUpBoxEnabled, true);
+ UpperBoxWidth = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmUpBoxWidth, 25);
+ UpperBoxHeight = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmUpBoxHeight, 8);
+ UpperBoxStartPos = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmUpBoxStart, 1);
+
+ CenterBoxWidth = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmCentBoxWidth, 35);
+ CenterBoxHeight = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmCentBoxHeight, 10);
+
+ LowerBoxEnabled = reader.GetValueAsBool(ViewModeSwitcherSectionName, ParmLowBoxEnabled, false);
+ LowerBoxWidth = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmLowBoxWidth, 25);
+ LowerBoxHeight = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmLowBoxHeight, 8);
+ LowerBoxStartPos = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmLowBoxStart, 92);
+
+ LBBlackLevel = (float)Convert.ToDouble(reader.GetValueAsString(ViewModeSwitcherSectionName, ParmBlackLevel, ((float).10f).ToString() ));
+ LBDetectionCount = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmLBDetectionCount, 1);
+ LBOverScanEnabled = reader.GetValueAsBool(ViewModeSwitcherSectionName, ParmLBOverScanEnabled, false);
+ LBOberScan = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmLBOverScan, 0);
+
+ VerticalOffSetZoom = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmVOffsetZoom, 0);
+ VerticalOffSet14_9= reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmVOffset14_9, 0);
+ VerticalOffSetWide14_9 = reader.GetValueAsInt(ViewModeSwitcherSectionName, ParmVOffsetWide14_9, 0);
+
+ return tmpReturn;
+ }
+ }
+
+ public void SaveSettings()
+ {
+ using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")))
+ {
+ xmlwriter.SetValueAsBool(ViewModeSwitcherSectionName, ParmVerboselog, verboseLog);
+ xmlwriter.SetValueAsBool(ViewModeSwitcherSectionName, ParmShowSwitchMsg, ShowSwitchMsg);
+ xmlwriter.SetValueAsBool(ViewModeSwitcherSectionName, ParmSuppressInitalMsg, SuppressInitialMsg);
+ // write ruleset
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRuleCount, ViewModeRules.Count.ToString());
+
+ for (int i = 1; i <= ViewModeRules.Count; i++)
+ {
+ Rule tmpRule = new Rule();
+ tmpRule = ViewModeRules[i - 1];
+ xmlwriter.SetValueAsBool(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "Enabled", tmpRule.Enabled);
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "Name", tmpRule.Name);
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "ARFrom", tmpRule.ARFrom.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "ARTo", tmpRule.ARTo.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "MinWidth", tmpRule.MinWidth.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "MaxWidth", tmpRule.MaxWidth.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "MinHeight", tmpRule.MinHeight.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "MaxHeight", tmpRule.MaxHeight.ToString());
+ xmlwriter.SetValueAsBool(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "ChangeAR", tmpRule.ChangeAR);
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "ViewMode", tmpRule.ViewMode.ToString());
+ xmlwriter.SetValueAsBool(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "ChangeOS", tmpRule.ChangeOs);
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "Overscan", tmpRule.OverScan.ToString());
+ xmlwriter.SetValueAsBool(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "EnableLBDetection", tmpRule.EnableLBDetection);
+
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "VerticalOffSetZoom", tmpRule.VerticalOffSetZoom.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "VerticalOffSet14_9", tmpRule.VerticalOffSet14_9.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmRulePrefix + i.ToString() + "VerticalOffSetWide14_9", tmpRule.VerticalOffSetWide14_9.ToString());
+ }
+ xmlwriter.SetValueAsBool(ViewModeSwitcherSectionName, ParmDisableLBGlobaly, DisableLBGlobaly);
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmLBCheckInterval, LBCheckInterval.ToString());
+
+ xmlwriter.SetValueAsBool(ViewModeSwitcherSectionName, ParmUpBoxEnabled, UpperBoxEnabled);
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmUpBoxWidth, UpperBoxWidth.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmUpBoxHeight, UpperBoxHeight.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmUpBoxStart, UpperBoxStartPos.ToString());
+
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmCentBoxWidth, CenterBoxWidth.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmCentBoxHeight, CenterBoxHeight.ToString());
+
+ xmlwriter.SetValueAsBool(ViewModeSwitcherSectionName, ParmLowBoxEnabled, LowerBoxEnabled);
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmLowBoxWidth, LowerBoxWidth.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmLowBoxHeight, LowerBoxHeight.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmLowBoxStart, LowerBoxStartPos.ToString());
+
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmBlackLevel, LBBlackLevel.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmLBDetectionCount, LBDetectionCount.ToString());
+ xmlwriter.SetValueAsBool(ViewModeSwitcherSectionName, ParmLBOverScanEnabled, LBOverScanEnabled);
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmLBOverScan, LBOberScan.ToString());
+
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmVOffsetZoom, VerticalOffSetZoom.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmVOffset14_9, VerticalOffSet14_9.ToString());
+ xmlwriter.SetValue(ViewModeSwitcherSectionName, ParmVOffsetWide14_9, VerticalOffSetWide14_9.ToString());
+ }
+ }
+
+ }
+}
Added: trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.cs
===================================================================
--- trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.cs (rev 0)
+++ trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.cs 2007-08-08 09:28:23 UTC (rev 810)
@@ -0,0 +1,1047 @@
+/* Copyright (C) 2005-2007 Team MediaPortal
+ * http://www.team-mediaportal.com
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Make; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows.Forms;
+using MediaPortal.GUI.Library;
+using MediaPortal.Configuration;
+using MediaPortal.Util;
+using MediaPortal.Player;
+using MediaPortal.Dialogs;
+using MediaPortal.TV.Recording;
+using System.Threading;
+using System.Diagnostics;
+using System.Drawing;
+using ViewModeSwitcherHelper;
+
+namespace ProcessPlugins.ViewModeSwitcher
+{
+ public delegate bool IsPlaying();
+ public delegate bool getPlayBackJustStarted();
+ public delegate bool getPlayBackJustEnded();
+ public delegate float getLastSwitchedAspectRatio();
+ public delegate void ProcessRules(float AspectRatio, int width, int height);
+ public delegate bool IsLetterbox();
+
+ public class ViewModeSwitcher : ProcessPlugins.ViewModeSwitcher.PlugInBase
+ {
+ ViewModeswitcherSettings currentSettings = new ViewModeswitcherSettings();
+
+ private static ViewModeSwitcher instance;
+ private AutoResetEvent workerEvent = new AutoResetEvent(false);
+ private bool stopWorkerThread = false;
+ private bool PlaybackJustStarted = false; // used in worker to differ between waiting for a playback or sleeping after it
+ private bool PlaybackJustEnded = false; // used in worker to differ between waiting for a playback or sleeping after it
+ private float LastSwitchedAspectRatio = 0f; // stores the last automatically set ratio.
+ private MediaPortal.FrameGrabber grabber = MediaPortal.FrameGrabber.GetInstance();
+ private int LastLetterBoxDetectionTime = System.Environment.TickCount;
+ private bool LastLetterboxDetectionResult = false;
+ private bool LetterboxActive = false;
+ private bool ViewModeSwitcherEnabled = true;
+ private int LBDetections = 0;
+ private int currentOverScan = 0;
+ private Geometry.Type curZoomMode;
+ private string curTVChannelName = "";
+ private System.ComponentModel.BackgroundWorker backgroundMenuWorker;
+ private bool MenuShown = false;
+ private int CurrentRule = -1;
+ private int RecentGuiWindowID = 0;
+
+ enum MoveDirection
+ {
+ UP,
+ Down
+ }
+
+ /// <summary>
+ /// starts the process plugin
+ /// </summary>
+ public override void Start()
+ {
+ Log.Debug("ViewModeSwitcher: Start()");
+ ViewModeSwitcher.instance = this;
+
+ if (!currentSettings.LoadSettings())
+ {
+ Log.Info("ViewModeSwitcher: No enabled rule found. Process stopped!");
+ return;
+ }
+
+ // start the thread that will execute ratio switch
+ Thread t = new Thread(new ThreadStart(instance.Worker));
+ t.IsBackground = true;
+ t.Priority = ThreadPriority.BelowNormal;
+ t.Name = "ViewModeSwitcherThread";
+ t.Start();
+
+ // register to handle playback events so we can wake
+ // the above thread when playback starts
+ Recorder.OnTvViewingStarted += new Recorder.OnTvViewHandler(OnTVStarted);
+ Recorder.OnTvViewingStopped += new Recorder.OnTvViewHandler(OnTVStopped);
+ //Recorder.OnTvChannelChanged += new Recorder.OnTvChannelChangeHandler(OnTVChannelChange);
+
+ g_Player.PlayBackStarted += new g_Player.StartedHandler(OnVideoStarted);
+ g_Player.PlayBackEnded += new g_Player.EndedHandler(OnVideoEnded);
+ g_Player.PlayBackStopped += new g_Player.StoppedHandler(OnVideoStopped);
+
+ GUIGraphicsContext.OnNewAction += new OnActionHandler(OnAction);
+
+ }
+
+ public void OnAction(Action action)
+ {
+ switch (action.wID)
+ {
+ case Action.ActionType.ACTION_VIEWMODESWITCHER_MENU:
+ {
+ ShowMenu();
+ }
+ break;
+ case Action.ActionType.ACTION_VIEWMODESWITCHER_DOWN:
+ {
+ MoveVisibleWindow(MoveDirection.Down);
+ }
+ break;
+ case Action.ActionType.ACTION_VIEWMODESWITCHER_UP:
+ {
+ MoveVisibleWindow(MoveDirection.UP);
+ }
+ break;
+ }
+ }
+
+
+ public void ShowMenu_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
+ {
+ if (MenuShown) return;
+ MenuShown = true;
+ RecentGuiWindowID = GUIWindowManager.ActiveWindow;
+
+ #region MainMenu
+
+ string tmpChannel = curTVChannelName;
+ Geometry.Type tmpAR = GUIGraphicsContext.ARType;
+
+ GUIDialogMenu Menu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
+ bool tmpSpecialTVChannelState = false;
+
+ Menu.Reset();
+ Menu.SetHeading("ViewModeSwitcher Settings");
+
+ Menu.Add("ViewModeSwitcher enabled : " + ViewModeSwitcherEnabled.ToString());
+ Menu.Add("Letterbox detection: " + (!currentSettings.DisableLBGlobaly).ToString());
+ Menu.Add("Set Letterbox detection interval");
+ Menu.Add("Set Letterbox detection count");
+
+ if (curTVChannelName != "" && (tmpAR == Geometry.Type.Zoom || tmpAR == Geometry.Type.Zoom14to9 || tmpAR == Geometry.Type.LetterBox43))
+ if (!IsCurrentChannelViewSpecial())
+ {
+ Menu.Add("Create a special \"" + tmpAR.ToString() + "\" offset for this channel (" + tmpChannel + ")");
+ tmpSpecialTVChannelState = true;
+ }
+ else
+ {
+ Menu.Add("Delete the special \"" + tmpAR.ToString() + "\" offset for this channel (" + tmpChannel + ")");
+ tmpSpecialTVChannelState = false;
+ }
+
+ Menu.DoModal(GUIWindowManager.ActiveWindow);
+
+ #endregion
+
+ if (Menu.SelectedLabel == -1)
+ return;
+ switch (Menu.SelectedLabel)
+ {
+ case 0:
+ {
+ ViewModeSwitcherEnabled = !ViewModeSwitcherEnabled;
+ }
+ break;
+ case 1:
+ {
+ currentSettings.DisableLBGlobaly = !currentSettings.DisableLBGlobaly;
+ }
+ break;
+ case 2:
+ {
+ #region LB interval menu
+
+ Menu.Reset();
+ Menu.SetHeading("Set letterbox detection interval");
+
+ for (int i = 500; i < 20000; i += 500)
+ {
+ Menu.Add(i.ToString() + " ms");
+ }
+ Menu.SelectedLabel = ((int)(currentSettings.LBCheckInterval / 500)-1);
+
+ Menu.DoModal(GUIWindowManager.ActiveWindow);
+
+ if (Menu.SelectedLabel == -1)
+ break;
+ currentSettings.LBCheckInterval = 500 * (Menu.SelectedLabel + 1);
+
+ #endregion
+ }
+ break;
+ case 3:
+ {
+ #region LB count menu
+
+ Menu.Reset();
+ Menu.SetHeading("Set letterbox detection count");
+
+ for (int i = 1; i <= 10; i++)
+ {
+ Menu.Add("");
+ }
+ Menu.SelectedLabel = currentSettings.LBDetectionCount-1;
+
+ Menu.DoModal(GUIWindowManager.ActiveWindow);
+
+ if (Menu.SelectedLabel == -1)
+ break;
+ currentSettings.LBDetectionCount = (Menu.SelectedLabel + 1);
+
+ #endregion
+ }
+ break;
+ case 4:
+ {
+ #region SpecialTVChannel menu entry
+ if (tmpSpecialTVChannelState)
+ {
+ int tmpOffset;
+
+ switch (tmpAR)
+ {
+ case Geometry.Type.Zoom: tmpOffset = currentSettings.VerticalOffSetZoom;
+ break;
+ case Geometry.Type.Zoom14to9: tmpOffset = currentSettings.VerticalOffSet14_9;
+ break;
+ case Geometry.Type.LetterBox43: tmpOffset = currentSettings.VerticalOffSetWide14_9;
+ break;
+ default: return;
+ }
+
+ SetSpecialChannelOffset(tmpChannel, tmpAR, tmpOffset);
+ }
+ else
+ {
+ RemoveSpecialChannelOffset(tmpChannel, tmpAR);
+ }
+ #endregion
+ }
+ break;
+ }
+
+ }
+
+ private void ShowMenu_WorkCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
+ {
+ backgroundMenuWorker.Dispose();
+ if (RecentGuiWindowID != 0) GUIWindowManager.RouteToWindow(RecentGuiWindowID);
+ MenuShown = false;
+ }
+
+ private void ShowMenu()
+ {
+
+ if (!MenuShown)
+ {
+ //load menu in different thread (as it requires the UI thread, and dialogs steal the UI thread when modal)
+ backgroundMenuWorker = new System.ComponentModel.BackgroundWorker();
+ backgroundMenuWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(ShowMenu_DoWork);
+ backgroundMenuWorker.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(ShowMenu_WorkCompleted);
+ backgroundMenuWorker.RunWorkerAsync();
+ }
+
+ }
+
+ /// <summary>
+ /// stops the process plugin
+ /// </summary>
+ public override void Stop()
+ {
+ stopWorkerThread = true;
+ Log.Debug("ViewModeSwitcher: Stop()");
+ currentSettings.SaveSettings();
+ }
+
+ public void ResetWorkerPlaybackValues()
+ {
+ LastSwitchedAspectRatio = 0f;
+ PlaybackJustStarted = true;
+ PlaybackJustEnded = false;
+ //LetterboxActive = false;
+ LastLetterboxDetectionResult = false;
+ LBDetections = 0;
+ }
+
+ /// <summary>
+ /// Handles the recorder.OnTvChannelChangeHandler event
+ /// </summary>
+ public void OnTVChannelChange(string tvChannelName)
+ {
+ if (currentSettings.verboseLog) Log.Info("ViewModeSwitcher: OnTVChannelChange... Reseting rule processing!");
+ LastSwitchedAspectRatio = 0f;
+ LastLetterboxDetectionResult = false;
+ LBDetections = 0;
+ }
+
+ /// <summary>
+ /// Handles the recorder.OnTVStarted event
+ /// </summary>
+ public void OnTVStarted(int j, TVCaptureDevice dev)
+ {
+ if (currentSettings.verboseLog) Log.Debug("ViewModeSwitcher: OnTVStarted");
+ ResetWorkerPlaybackValues();
+ if (ViewModeSwitcherEnabled) workerEvent.Set();
+ }
+
+ /// <summary>
+ /// Handles the recorder.OnTVStopped event
+ /// </summary>
+ public void OnTVStopped(int j, TVCaptureDevice dev)
+ {
+ if (currentSettings.verboseLog) Log.Debug("ViewModeSwitcher: OnTVStopped");
+ LastSwitchedAspectRatio = 0f;
+ PlaybackJustEnded = true;
+ }
+
+ /// <summary>
+ /// Handles the g_Player.PlayBackStarted event
+ /// </summary>
+ public void OnVideoStarted(g_Player.MediaType type, string s)
+ {
+ // do not handle e.g. visualization window, last.fm player, etc
+ if (type == g_Player.MediaType.Music)
+ return;
+
+ if (currentSettings.verboseLog) Log.Debug("ViewModeSwitcher: On Video Started");
+
+ ResetWorkerPlaybackValues();
+
+ if (ViewModeSwitcherEnabled) workerEvent.Set();
+ }
+
+ /// <summary>
+ /// Handles the g_Player.PlayBackEnded event
+ /// </summary>
+ /// <param name="type"></param>
+ /// <param name="s"></param>
+ public void OnVideoEnded(g_Player.MediaType type, string s)
+ {
+ // do not handle e.g. visualization window, last.fm player, etc
+ if (type == g_Player.MediaType.Music)
+ return;
+
+ if (currentSettings.verboseLog) Log.Debug("ViewModeSwitcher: On Video Ended");
+ LastSwitchedAspectRatio = 0f;
+ PlaybackJustEnded = true;
+ }
+
+ /// <summary>
+ /// Handles the g_Player.PlayBackStopped event
+ /// </summary>
+ /// <param name="type"></param>
+ /// <param name="i"></param>
+ /// <param name="s"></param>
+ public void OnVideoStopped(g_Player.MediaType type, int i, string s)
+ {
+ // do not handle e.g. visualization window, last.fm player, etc
+ if (type == g_Player.MediaType.Music)
+ return;
+
+ if (currentSettings.verboseLog) Log.Debug("ViewModeSwitcher: On Video Stopped");
+ LastSwitchedAspectRatio = 0f;
+ PlaybackJustEnded = true;
+ }
+
+
+ /// <summary>
+ /// Used for checking whether there is any purpose to change the aspect ratio
+ /// </summary>
+ /// <returns></returns>
+ private bool IsPlaying()
+ {
+ return g_Player.Playing || MediaPortal.TV.Recording.Recorder.IsViewing();
+ }
+
+
+ /// <summary>
+ /// checks if a defined rule is fitting the current media
+ /// </summary>
+ /// <param name="width">the width of the media</param>
+ /// <param name="height">the height of the media</param>
+ /// <returns>the index of the fitting rule, or -1 if no rule fits</returns>
+ public int GetAffectedRuleIndex(float AspectRatio, int width, int height)
+ {
+ for(int i=0; i< currentSettings.ViewModeRules.Count; i++)
+ {
+ Rule tmpRule = new Rule();
+ tmpRule = currentSettings.ViewModeRules[i];
+
+ if (tmpRule.Enabled
+ && AspectRatio >= tmpRule.ARFrom
+ && AspectRatio <= tmpRule.ARTo
+ && width >= tmpRule.MinWidth
+ && width <= tmpRule.MaxWidth
+ && height >= tmpRule.MinHeight
+ && height <= tmpRule.MaxHeight)
+ {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /// <summary>
+ /// checks if a rule is fitting and executes it
+ /// </summary>
+ /// <param name="AspectRatio">Aspect ratio</param>
+ /// <param name="width">video width</param>
+ /// <param name="height">video height</param>
+ public void ProcessRules(float AspectRatio, int width, int height)
+ {
+ CurrentRule = -1;
+ for (int i = 0; i < currentSettings.ViewModeRules.Count; i++)
+ {
+ Rule tmpRule = new Rule();
+ tmpRule = currentSettings.ViewModeRules[i];
+
+ if (tmpRule.Enabled
+ && AspectRatio >= tmpRule.ARFrom
+ && AspectRatio <= tmpRule.ARTo
+ && width >= tmpRule.MinWidth
+ && width <= tmpRule.MaxWidth
+ && height >= tmpRule.MinHeight
+ && height <= tmpRule.MaxHeight)
+ {
+ if (AspectRatio != LastSwitchedAspectRatio)
+ {
+ Log.Info("Rule \"" + tmpRule.Name + "\" fits conditions.");
+ if (tmpRule.ChangeOs)
+ {
+ CropSettings tmpCropSettings = new CropSettings(tmpRule.OverScan, tmpRule.OverScan, (int)(tmpRule.OverScan * AspectRatio), (int)(tmpRule.OverScan * AspectRatio));
+ SetCropMode(tmpCropSettings);
+ }
+
+ if (tmpRule.ChangeAR)
+ {
+ SetAspectRatio(tmpRule.Name, tmpRule.ViewMode);
+ LastSwitchedAspectRatio = AspectRatio;
+ }
+ }
+ else if (!currentSettings.DisableLBGlobaly && tmpRule.EnableLBDetection && IsLetterbox())
+ {
+ if (!LetterboxActive)
+ {
+ Log.Info("Letterbox detected! Switching to \"Zoom\" mode");
+ if (currentSettings.LBOverScanEnabled)
+ {
+ CropSettings tmpCropSettings = new CropSettings(currentSettings.LBOberScan, currentSettings.LBOberScan, (int)(currentSettings.LBOberScan * AspectRatio), (int)(currentSettings.LBOberScan * AspectRatio));
+ SetCropMode(tmpCropSettings);
+ }
+ SetAspectRatio("Letterbox detected!", Geometry.Type.Zoom);
+ LastSwitchedAspectRatio = AspectRatio;
+ LetterboxActive = true;
+ }
+ }
+ else if (LetterboxActive)
+ {
+ Log.Info("Letterbox is gone! Reseting rule processing");
+ LastSwitchedAspectRatio = 0f; // make sure rules getting processed again
+ LetterboxActive = false;
+ continue;
+ }
+ CurrentRule = i;
+ break; // do not process any additional rule after a rule fits (better for offset function)
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// Checks if the currently playing file is a letterbox file
+ /// </summary>
+ /// <returns>true if letterbox</returns>
+ private bool IsLetterbox()
+ {
+ if ((LastLetterBoxDetectionTime + currentSettings.LBCheckInterval) > System.Environment.TickCount) // if it is too sone for a new detection, return with the previos result
+ {
+ return LastLetterboxDetectionResult;
+ }
+
+ if (currentSettings.verboseLog) Log.Info("Letterbox detection started");
+ Bitmap frame = grabber.GetCurrentImage(); // grab a frame from the player
+
+ if (frame == null)
+ {
+ if (currentSettings.verboseLog) Log.Error ("Framegrabber delivers null!");
+ return LastLetterboxDetectionResult;
+ }
+
+ // analyse the two boxes
+ bool tmpCenterBoxNearlyBlack = IsCenterBoxNearlyBlack(frame);
+ bool tmpOuterBoxesNearlyBlack = AreOuterBoxesNearlyBlack(frame);
+ LastLetterBoxDetectionTime = System.Environment.TickCount;
+
+ if (!tmpCenterBoxNearlyBlack && tmpOuterBoxesNearlyBlack) // say yes if the center box has content and the others don't
+ {
+ if (LBDetections < 0)
+ {
+ LBDetections = 0; // reset detection count
+ if (currentSettings.verboseLog) Log.Info("Letterbox detection count was reseted to 0");
+ }
+
+ LBDetections += 1;
+ if (LBDetections > currentSettings.LBDetectionCount) LBDetections = currentSettings.LBDetectionCount; // let LBDetections not getting bigger than required
+
+ if (currentSettings.verboseLog) Log.Info("Letterbox detection count is {0} of maximal {1} allowed", LBDetections, currentSettings.LBDetectionCount);
+
+ if (LBDetections == currentSettings.LBDetectionCount)
+ {
+ LastLetterboxDetectionResult = true;
+ if (currentSettings.verboseLog) Log.Info("Letterbox detection ended - Result: True");
+ return true;
+ }
+ else
+ {
+ if (currentSettings.verboseLog) Log.Info("Letterbox detection ended - with the previous result: " + LastLetterboxDetectionResult.ToString());
+ return LastLetterboxDetectionResult; // else return the last result
+ }
+ }
+ else if (!tmpCenterBoxNearlyBlack && !tmpOuterBoxesNearlyBlack) // say no if all boxes have content
+ {
+ if (LBDetections > 0)
+ {
+ LBDetections = 0; // reset detection count
+ if (currentSettings.verboseLog) Log.Info("Letterbox detection count was reseted to 0");
+ }
+
+ LBDetections -= 1;
+ if (LBDetections < (currentSettings.LBDetectionCount * -1)) LBDetections = (currentSettings.LBDetectionCount * -1); // let LBDetections not getting smaller than required
+
+ if (currentSettings.verboseLog) Log.Info("Letterbox detection count is {0} of maximal {1} allowed", LBDetections, (currentSettings.LBDetectionCount * -1));
+
+ if (LBDetections == (currentSettings.LBDetectionCount * -1))
+ {
+ LastLetterboxDetectionResult = false;
+ if (currentSettings.verboseLog) Log.Info("Letterbox detection ended - Result: False");
+ return false;
+ }
+ else
+ {
+ if (currentSettings.verboseLog) Log.Info("Letterbox detection ended - with the previous result: " + LastLetterboxDetectionResult.ToString());
+ return LastLetterboxDetectionResult; // else return the last result
+ }
+ }
+ else
+ {
+ if (currentSettings.verboseLog) Log.Info("Letterbox detection ended - with the previous result: " + LastLetterboxDetectionResult.ToString());
+ return LastLetterboxDetectionResult; // else return the last result
+ }
+ }
+
+ private bool AreOuterBoxesNearlyBlack(Bitmap frame)
+ {
+ bool tmpResult = true;
+
+ if (currentSettings.UpperBoxEnabled) tmpResult = IsUpperBoxNearlyBlack(frame);
+
+ if (currentSettings.LowerBoxEnabled)
+ {
+ bool lowerResult = IsLowerBoxNearlyBlack(frame);
+ tmpResult = tmpResult && lowerResult;
+ }
+
+ if (!currentSettings.UpperBoxEnabled && !currentSettings.LowerBoxEnabled) tmpResult = false;
+
+ return tmpResult;
+ }
+
+ /// <summary>
+ /// analyses the upper box of a given frame
+ /// </summary>
+ /// <param name="frame">the frame to analyse as bitmap</param>
+ /// <returns></returns>
+ private bool IsUpperBoxNearlyBlack(Bitmap frame)
+ {
+ float UpperAnalyseRectWidthBase = currentSettings.UpperBoxWidth;
+ float UpperAnalyseRectHeightBase = currentSettings.UpperBoxHeight;
+ float UpperAnalyseRectStartBase = currentSettings.UpperBoxStartPos;
+
+ UpperAnalyseRectWidthBase /= 100;
+ UpperAnalyseRectHeightBase /= 100;
+ UpperAnalyseRectStartBase /= 100;
+
+ int tmpX = (int)((frame.Width - (frame.Width * UpperAnalyseRectWidthBase)) / 2);
+ int tmpY = (int)(frame.Height * UpperAnalyseRectStartBase); // skip the first lines (may contain teletect and other cr...)
+ int tmpWidth = (int)(frame.Width * UpperAnalyseRectWidthBase);
+ int tmpHeight = (int)(frame.Height * UpperAnalyseRectHeightBase);
+
+ Rectangle tmpUpperRect = new Rectangle(tmpX, tmpY, tmpWidth, tmpHeight);
+
+ bool tmpResult = IsNearlyBlack(frame, tmpUpperRect);
+ if (currentSettings.verboseLog) Log.Info("Upper box is nearly black: " + tmpResult.ToString());
+ return tmpResult;
+ }
+
+ /// <summary>
+ /// analyses the lower box of a given frame
+ /// </summary>
+ /// <param name="frame">the frame to analyse as bitmap</param>
+ /// <returns></returns>
+ private bool IsLowerBoxNearlyBlack(Bitmap frame)
+ {
+ float LowerAnalyseRectWidthBase = currentSettings.LowerBoxWidth;
+ float LowerAnalyseRectHeightBase = currentSettings.LowerBoxHeight;
+ float LowerAnalyseRectStartBase = currentSettings.LowerBoxStartPos;
+
+ LowerAnalyseRectWidthBase /= 100;
+ LowerAnalyseRectHeightBase /= 100;
+ LowerAnalyseRectStartBase /= 100;
+
+ int tmpX = (int)((frame.Width - (frame.Width * LowerAnalyseRectWidthBase)) / 2);
+ int tmpY = (int)(frame.Height * LowerAnalyseRectStartBase); // skip the first lines (may contain teletect and other cr...)
+ int tmpWidth = (int)(frame.Width * LowerAnalyseRectWidthBase);
+ int tmpHeight = (int)(frame.Height * LowerAnalyseRectHeightBase);
+
+ Rectangle tmpLowerRect = new Rectangle(tmpX, tmpY, tmpWidth, tmpHeight);
+
+ bool tmpResult = IsNearlyBlack(frame, tmpLowerRect);
+ if (currentSettings.verboseLog) Log.Info("Lower box is nearly black: " + tmpResult.ToString());
+ return tmpResult;
+ }
+
+ /// <summary>
+ /// analyses the center box of a given frame
+ /// </summary>
+ /// <param name="frame">the frame to analyse as bitmap</param>
+ /// <returns></returns>
+ private bool IsCenterBoxNearlyBlack(Bitmap frame)
+ {
+ float CenterAnalyseRectWidthBase = currentSettings.CenterBoxWidth;
+ float CenterAnalyseRectHeightBase = currentSettings.CenterBoxHeight;
+
+ CenterAnalyseRectWidthBase /= 100;
+ CenterAnalyseRectHeightBase /= 100;
+
+ int tmpX = (int)((frame.Width - (frame.Width * CenterAnalyseRectWidthBase)) / 2);
+ int tmpY = (int)((frame.Height - (frame.Height * CenterAnalyseRectHeightBase)) / 2);
+ int tmpWidth = (int)(frame.Width * CenterAnalyseRectWidthBase);
+ int tmpHeight = (int)(frame.Height * CenterAnalyseRectHeightBase);
+
+ Rectangle tmpCenterRect = new Rectangle(tmpX, tmpY, tmpWidth, tmpHeight);
+
+ bool tmpResult = IsNearlyBlack(frame, tmpCenterRect);
+ if (currentSettings.verboseLog) Log.Info("Center box is nearly black: " + tmpResult.ToString());
+ return tmpResult;
+
+ }
+
+ /// <summary>
+ /// Checks if the content of a given rectangle is nearly black
+ /// </summary>
+ /// <param name="frame">the frame to analyse as bitmap</param>
+ /// <param name="AnalyseRect">the rectangle to analyse</param>
+ /// <returns>true if nearly black</returns>
+ private bool IsNearlyBlack(Bitmap frame, Rectangle AnalyseRect)
+ {
+ float brightestColor = 0;
+ for (int y = AnalyseRect.Top; y < AnalyseRect.Bottom; y++)
+ {
+ for (int x = AnalyseRect.Left; x < AnalyseRect.Right; x++)
+ {
+ Color c = frame.GetPixel(x, y);
+ if (c.GetBrightness() > brightestColor) brightestColor = c.GetBrightness();
+ }
+ }
+
+ if(currentSettings.verboseLog) Log.Info("BrightesColor in box ( {0}, {1}, {2}, {3} ) is {4}", AnalyseRect.Left, AnalyseRect.Top, AnalyseRect.Width, AnalyseRect.Height, brightestColor);
+
+ if (brightestColor <= currentSettings.LBBlackLevel)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Changes the aspect ratio of MediaPortal
+ /// </summary>
+ /// <param name="MessageString">Message text of the switch message</param>
+ /// <param name="AR">the aspect ratio to switch to</param>
+ private void SetAspectRatio(string MessageString, Geometry.Type AR)
+ {
+ Log.Info("Switching to viewmode: " + AR.ToString());
+ GUIGraphicsContext.ARType = AR;
+ LastLetterBoxDetectionTime = System.Environment.TickCount;
+
+ if (currentSettings.ShowSwitchMsg)
+ {
+ if (!(currentSettings.SuppressInitialMsg && getPlayBackJustStarted()))
+ {
+ GUIDialogNotify SwitchMsg = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
+ SwitchMsg.SetHeading("ViewModeSwitcher");
+ SwitchMsg.SetText(MessageString + " > " + AR.ToString());
+ SwitchMsg.TimeOut = 2;
+ SwitchMsg.DoModal(GUIWindowManager.ActiveWindow);
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// set the oversan of MediaPortal by setting crop parameters
+ /// </summary>
+ private void SetCropMode(CropSettings crops)
+ {
+ Log.Info("Using overscan: " + crops.Top.ToString());
+ currentOverScan = crops.Top;
+ CropSettings newCropSettings = new CropSettings();
+ newCropSettings = crops;
+
+ MediaPortal.GUI.Library.GUIMessage msg = new GUIMessage();
+ msg.Message = GUIMessage.MessageType.GUI_MSG_PLANESCENE_CROP;
+ msg.Object = newCropSettings;
+ GUIWindowManager.SendMessage(msg);
+ }
+
+ /// <summary>
+ /// delegated access for the worker
+ /// </summary>
+ private bool getPlayBackJustStarted()
+ {
+ return PlaybackJustStarted;
+ }
+
+ /// <summary>
+ /// delegated access for the worker
+ /// </summary>
+ private bool getPlayBackJustEnded()
+ {
+ return PlaybackJustEnded;
+ }
+
+ /// <summary>
+ /// delegated access for the worker
+ /// </summary>
+ private float getLastSwitchedAspectRatio()
+ {
+ return LastSwitchedAspectRatio;
+ }
+
+ /// <summary>
+ /// This method runs in a thread and calculates the aspect ratio
+ /// checks if a rule is affected
+ /// </summary>
+ private void Worker()
+ {
+ bool PlayingMediaDetected = new bool();
+
+ while (true)
+ {
+ if (currentSettings.verboseLog) Log.Debug("IsPlaying : " + IsPlaying() + " PlayingMediaDetected: " + PlayingMediaDetected.ToString() + " PlayBackJustStarted: " + PlaybackJustStarted.ToString() + " PlaybackStopped: " + PlaybackJustEnded.ToString());
+ if (stopWorkerThread)
+ {
+ stopWorkerThread = false;
+ PlayingMediaDetected = false;
+ workerEvent.WaitOne();
+ return;
+ }
+ if (ViewModeSwitcherEnabled && IsPlaying())
+ {
+ if (!PlaybackJustEnded)
+ {
+ PlayingMediaDetected = true;
+ // calculate the current aspect ratio
+ if (VMR9Util.g_vmr9 != null)
+ {
+ float ARCalc = (float)VMR9Util.g_vmr9.VideoAspectRatioX / (float)VMR9Util.g_vmr9.VideoAspectRatioY;
+
+ if (currentSettings.verboseLog)
+ {
+ Log.Debug("VideoAspectRatioX " + VMR9Util.g_vmr9.VideoAspectRatioX.ToString());
+ Log.Debug("VideoAspectRatioY " + VMR9Util.g_vmr9.VideoAspectRatioY.ToString());
+ Log.Debug("VideoWidth " + g_Player.Width.ToString());
+ Log.Debug("VideoHeight " + g_Player.Height.ToString());
+ //Log.Info("TV Client Channel: {0}",Recorder.GetTVChannelName());
+ //Log.Info("TV Plugin Channel: {0}", TVstatusWrapper.GetChannelName());
+ }
+
+ if (currentSettings.verboseLog) Log.Debug("AR:" + g_Player.ARType + " AR Calc: " + ARCalc.ToString());
+ if (!g_Player.Paused)
+ {
+ ProcessRules(ARCalc, g_Player.Width, g_Player.Height); // check if a rule fits the conditions and process it
+ }
+ //else Thread.Sleep(2500);
+
+ // Do something after the rules have been scanned
+ if (curZoomMode != GUIGraphicsContext.ARType)
+ {
+ curZoomMode = GUIGraphicsContext.ARType;
+ if (currentSettings.verboseLog) Log.Info("The viewmode has been change to {0}", curZoomMode);
+ SetZoomModeOffset(curZoomMode);
+ }
+
+ if (TVstatusWrapper.IsViewingTV())
+ {
+ string tmpChannelName = TVstatusWrapper.GetChannelName();
+ if (curTVChannelName != tmpChannelName)
+ {
+ curTVChannelName = tmpChannelName;
+ if (currentSettings.verboseLog) Log.Info("The TV channel is now: {0}", curTVChannelName);
+
+ LastSwitchedAspectRatio = 0f;
+ LastLetterboxDetectionResult = false;
+ LBDetections = 0;
+
+ if (IsCurrentChannelViewSpecial())
+ {
+ if (currentSettings.verboseLog) Log.Info("There is a special offset defined for {0} and {1}",curTVChannelName,GUIGraphicsContext.ARType);
+ SetVisibleWindowPos(GetSpecialChannelOffset(curTVChannelName, GUIGraphicsContext.ARType));
+ }
+ }
+ }
+ else curTVChannelName = "";
+ }
+ PlaybackJustStarted = false;
+ Thread.Sleep(500);
+ }
+ else Thread.Sleep(1000);
+ }
+ else
+ {
+
+ if (PlayingMediaDetected)
+ {
+ PlayingMediaDetected = false;
+ PlaybackJustEnded = false;
+ LastSwitchedAspectRatio = 0f;
+ if (currentSettings.verboseLog) Log.Info("Worker halting, waiting for next event");
+
+ workerEvent.WaitOne(); // reset automatically
+ }
+ else
+ {
+ Thread.Sleep(1000);
+ if (!PlaybackJustStarted) workerEvent.WaitOne(); // reset automatically
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Changes the values of the zoom mode offsets
+ /// </summary>
+ private void MoveVisibleWindow(MoveDirection direction)
+ {
+ int tmpOffset;
+ bool isSpecialTV = IsCurrentChannelViewSpecial();
+
+ if (isSpecialTV)
+ {
+ tmpOffset = GetSpecialChannelOffset(curTVChannelName, GUIGraphicsContext.ARType);
+ }
+ else
+ {
+ if (CurrentRule == -1)
+ {
+ switch (GUIGraphicsContext.ARType)
+ {
+ case Geometry.Type.Zoom: tmpOffset = currentSettings.VerticalOffSetZoom;
+ break;
+ case Geometry.Type.Zoom14to9: tmpOffset = currentSettings.VerticalOffSet14_9;
+ break;
+ case Geometry.Type.LetterBox43: tmpOffset = currentSettings.VerticalOffSetWide14_9;
+ break;
+ default: return;
+ }
+ }
+ else
+ {
+ switch (GUIGraphicsContext.ARType)
+ {
+ case Geometry.Type.Zoom: tmpOffset = currentSettings.ViewModeRules[CurrentRule].VerticalOffSetZoom;
+ break;
+ case Geometry.Type.Zoom14to9: tmpOffset = currentSettings.ViewModeRules[CurrentRule].VerticalOffSet14_9;
+ break;
+ case Geometry.Type.LetterBox43: tmpOffset = currentSettings.ViewModeRules[CurrentRule].VerticalOffSetWide14_9;
+ break;
+ default: return;
+ }
+ }
+ }
+
+ if (direction == MoveDirection.Down) tmpOffset -= 1;
+ else tmpOffset += 1;
+
+ Rectangle tmpSourceRect = new Rectangle();
+ Rectangle tmpDestRect = new Rectangle();
+
+ VMR9Util.g_vmr9.GetVideoWindows(out tmpSourceRect, out tmpDestRect);
+
+ if (tmpOffset < ( (tmpSourceRect.Y - currentOverScan) * -1)) tmpOffset = ( (tmpSourceRect.Y-currentOverScan) * -1);
+ if (tmpOffset > tmpSourceRect.Y) tmpOffset = tmpSourceRect.Y;
+ //if (tmpOffset > -5 && tmpOffset < 5) tmpOffset = 0;
+
+ SetVisibleWindowPos(tmpOffset);
+
+ if (isSpecialTV)
+ {
+ SetSpecialChannelOffset(curTVChannelName, GUIGraphicsContext.ARType, tmpOffset);
+ }
+ else
+ {
+ if (CurrentRule == -1)
+ {
+ switch (GUIGraphicsContext.ARType)
+ {
+ case Geometry.Type.Zoom: currentSettings.VerticalOffSetZoom = tmpOffset;
+ break;
+ case Geometry.Type.Zoom14to9: currentSettings.VerticalOffSet14_9 = tmpOffset;
+ break;
+ case Geometry.Type.LetterBox43: currentSettings.VerticalOffSetWide14_9 = tmpOffset;
+ break;
+ }
+ }
+ else
+ {
+ switch (GUIGraphicsContext.ARType)
+ {
+ case Geometry.Type.Zoom: currentSettings.ViewModeRules[CurrentRule].VerticalOffSetZoom = tmpOffset;
+ break;
+ case Geometry.Type.Zoom14to9: currentSettings.ViewModeRules[CurrentRule].VerticalOffSet14_9 = tmpOffset;
+ break;
+ case Geometry.Type.LetterBox43: currentSettings.ViewModeRules[CurrentRule].VerticalOffSetWide14_9 = tmpOffset;
+ break;
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Set the offset of the currently visible window
+ /// </summary>
+ private void SetVisibleWindowPos(int offset)
+ {
+ if (VMR9Util.g_vmr9 == null) return;
+
+ if (currentSettings.verboseLog) L...
[truncated message content] |