home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
MediaPortal 1 Talk
Automatic Refreshrate Changer
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="davidf" data-source="post: 571781" data-attributes="member: 19484"><p>I noticed that there is an open Mantis item opened against picking a rate which is not valid. I had a slight issue where my 1:1 Pixel mapping was only available at 60Hz and as I live in a PAL region I had startred to modify the code to allow the resolution to change to get the desired refresh rate (I think refresh rate is more important than perfect pixel mapping) and the code I have started may solve the issue for Sythe42. This is the code I added to Monitor.cs:</p><p></p><p>[code]</p><p> //assume total pixels count will be a good match</p><p> static int MatchAlgorithm(uint Xpels, uint yPels)</p><p> {</p><p> return (int)Xpels * (int)yPels;</p><p> }</p><p></p><p> static DEVMODE_Display GetClosestRefreshRate(Monitor.Win32.DISPLAY_DEVICE displayDevice, uint xPrefered, uint yPrefered, uint refreshRate)</p><p> {</p><p> List<Monitor.Win32.DEVMODE_Display> validModes = new List<DEVMODE_Display>();</p><p> Monitor.Win32.DEVMODE_Display ret = null;</p><p> uint bpp=32;</p><p> Monitor.Win32.DEVMODE_Display display = new DEVMODE_Display();</p><p> if (0!=Monitor.Win32.EnumDisplaySettingsEx(displayDevice.DeviceName,</p><p> Monitor.Win32.EnumDisplaySettings_EnumMode.ENUM_CURRENT_SETTINGS,</p><p> display,</p><p> 0))</p><p> {</p><p> bpp = display.dmBitsPerPel;</p><p> }</p><p> int currMode = 0;</p><p> while (0!=Monitor.Win32.EnumDisplaySettingsEx(displayDevice.DeviceName,</p><p> (Monitor.Win32.EnumDisplaySettings_EnumMode) currMode++,</p><p> display,</p><p> 0))</p><p> {</p><p> if (refreshRate==display.dmDisplayFrequency)</p><p> {</p><p> validModes.Add(display);</p><p> display = new DEVMODE_Display();</p><p> }</p><p> }</p><p> //exactMatch?</p><p> foreach (Monitor.Win32.DEVMODE_Display mode in validModes)</p><p> {</p><p> if (mode.dmPelsWidth == xPrefered && mode.dmPelsHeight == yPrefered && mode.dmBitsPerPel == bpp)</p><p> {</p><p> ret = mode;</p><p> break;</p><p> }</p><p> }</p><p> if (ret == null)</p><p> {</p><p> int currScore,bestResult = int.MaxValue;</p><p> foreach (Monitor.Win32.DEVMODE_Display mode in validModes)</p><p> {</p><p> currScore = MatchAlgorithm(mode.dmPelsHeight,mode.dmPelsWidth);</p><p> if (Math.Abs(MatchAlgorithm(xPrefered,yPrefered) - currScore) < bestResult && mode.dmBitsPerPel == bpp)</p><p> {</p><p> bestResult = (int)Math.Abs(MatchAlgorithm(xPrefered , yPrefered) - currScore);</p><p> ret = mode;</p><p> }</p><p> }</p><p> }</p><p> return ret;</p><p> }</p><p></p><p> public static void CycleRefreshRate(uint monitorIndex, uint refreshRate, uint xPrefered, uint yPrefered)</p><p> {</p><p></p><p> Monitor.Win32.DISPLAY_DEVICE displayDevice = new Monitor.Win32.DISPLAY_DEVICE();</p><p> int result = Monitor.Win32.EnumDisplayDevices(null, monitorIndex, displayDevice, 0);</p><p></p><p> if (result != 0)</p><p> {</p><p> Monitor.Win32.DEVMODE_Display devMode = new Monitor.Win32.DEVMODE_Display();</p><p></p><p> devMode = GetClosestRefreshRate(displayDevice, xPrefered, yPrefered, refreshRate);</p><p> if (devMode == null) return; // no valid mode at all.</p><p> devMode.dmDisplayFrequency = refreshRate;</p><p> Monitor.Win32.ChangeDisplaySettings_Result r = Monitor.Win32.ChangeDisplaySettingsEx(displayDevice.DeviceName, devMode,</p><p> IntPtr.Zero, Monitor.Win32.ChangeDisplaySettings_Flags.None, IntPtr.Zero);</p><p> }</p><p> }</p><p></p><p>Removing </p><p> if (ret == null)</p><p> {</p><p> int currScore,bestResult = int.MaxValue;</p><p> foreach (Monitor.Win32.DEVMODE_Display mode in validModes)</p><p> {</p><p> currScore = MatchAlgorithm(mode.dmPelsHeight,mode.dmPelsWidth);</p><p> if (Math.Abs(MatchAlgorithm(xPrefered,yPrefered) - currScore) < bestResult && mode.dmBitsPerPel == bpp)</p><p> {</p><p> bestResult = (int)Math.Abs(MatchAlgorithm(xPrefered , yPrefered) - currScore);</p><p> ret = mode;</p><p> }</p><p> }</p><p> }</p><p></p><p>[/code]</p><p>from GetClosestRefreshRate</p><p></p><p>and passing the current resolution to CycleRefreshRate would solve the problem. A bool return would probably be useful too.</p><p></p><p>I haven't include the Desktop Window Manager code as I haven't got around to that yet.</p></blockquote><p></p>
[QUOTE="davidf, post: 571781, member: 19484"] I noticed that there is an open Mantis item opened against picking a rate which is not valid. I had a slight issue where my 1:1 Pixel mapping was only available at 60Hz and as I live in a PAL region I had startred to modify the code to allow the resolution to change to get the desired refresh rate (I think refresh rate is more important than perfect pixel mapping) and the code I have started may solve the issue for Sythe42. This is the code I added to Monitor.cs: [code] //assume total pixels count will be a good match static int MatchAlgorithm(uint Xpels, uint yPels) { return (int)Xpels * (int)yPels; } static DEVMODE_Display GetClosestRefreshRate(Monitor.Win32.DISPLAY_DEVICE displayDevice, uint xPrefered, uint yPrefered, uint refreshRate) { List<Monitor.Win32.DEVMODE_Display> validModes = new List<DEVMODE_Display>(); Monitor.Win32.DEVMODE_Display ret = null; uint bpp=32; Monitor.Win32.DEVMODE_Display display = new DEVMODE_Display(); if (0!=Monitor.Win32.EnumDisplaySettingsEx(displayDevice.DeviceName, Monitor.Win32.EnumDisplaySettings_EnumMode.ENUM_CURRENT_SETTINGS, display, 0)) { bpp = display.dmBitsPerPel; } int currMode = 0; while (0!=Monitor.Win32.EnumDisplaySettingsEx(displayDevice.DeviceName, (Monitor.Win32.EnumDisplaySettings_EnumMode) currMode++, display, 0)) { if (refreshRate==display.dmDisplayFrequency) { validModes.Add(display); display = new DEVMODE_Display(); } } //exactMatch? foreach (Monitor.Win32.DEVMODE_Display mode in validModes) { if (mode.dmPelsWidth == xPrefered && mode.dmPelsHeight == yPrefered && mode.dmBitsPerPel == bpp) { ret = mode; break; } } if (ret == null) { int currScore,bestResult = int.MaxValue; foreach (Monitor.Win32.DEVMODE_Display mode in validModes) { currScore = MatchAlgorithm(mode.dmPelsHeight,mode.dmPelsWidth); if (Math.Abs(MatchAlgorithm(xPrefered,yPrefered) - currScore) < bestResult && mode.dmBitsPerPel == bpp) { bestResult = (int)Math.Abs(MatchAlgorithm(xPrefered , yPrefered) - currScore); ret = mode; } } } return ret; } public static void CycleRefreshRate(uint monitorIndex, uint refreshRate, uint xPrefered, uint yPrefered) { Monitor.Win32.DISPLAY_DEVICE displayDevice = new Monitor.Win32.DISPLAY_DEVICE(); int result = Monitor.Win32.EnumDisplayDevices(null, monitorIndex, displayDevice, 0); if (result != 0) { Monitor.Win32.DEVMODE_Display devMode = new Monitor.Win32.DEVMODE_Display(); devMode = GetClosestRefreshRate(displayDevice, xPrefered, yPrefered, refreshRate); if (devMode == null) return; // no valid mode at all. devMode.dmDisplayFrequency = refreshRate; Monitor.Win32.ChangeDisplaySettings_Result r = Monitor.Win32.ChangeDisplaySettingsEx(displayDevice.DeviceName, devMode, IntPtr.Zero, Monitor.Win32.ChangeDisplaySettings_Flags.None, IntPtr.Zero); } } Removing if (ret == null) { int currScore,bestResult = int.MaxValue; foreach (Monitor.Win32.DEVMODE_Display mode in validModes) { currScore = MatchAlgorithm(mode.dmPelsHeight,mode.dmPelsWidth); if (Math.Abs(MatchAlgorithm(xPrefered,yPrefered) - currScore) < bestResult && mode.dmBitsPerPel == bpp) { bestResult = (int)Math.Abs(MatchAlgorithm(xPrefered , yPrefered) - currScore); ret = mode; } } } [/code] from GetClosestRefreshRate and passing the current resolution to CycleRefreshRate would solve the problem. A bool return would probably be useful too. I haven't include the Desktop Window Manager code as I haven't got around to that yet. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
MediaPortal 1 Talk
Automatic Refreshrate Changer
Contact us
RSS
Top
Bottom