コード例 #1
0
ファイル: Monitor.cs プロジェクト: jvanegmond/mlux
        public Monitor(IntPtr hMonitor, IntPtr hdcMonitor)
        {
            _hMonitor   = hMonitor;
            _hdcMonitor = hdcMonitor;

            Log.Info($"Create monitor hMonitor:{_hMonitor} hdcMonitor:{_hdcMonitor}");

            // Get the current brightness
            try
            {
                SupportBrightness = true;

                if (!MonitorMethods.GetNumberOfPhysicalMonitorsFromHMONITOR(_hMonitor, ref _physicalMonitorsCount))
                {
                    throw new ApplicationException($"Cannot GetNumberOfPhysicalMonitorsFromHMONITOR for hmonitor {_hMonitor}");
                }

                _physicalMonitors = new MonitorStructures.PhysicalMonitor[_physicalMonitorsCount];

                if (!MonitorMethods.GetPhysicalMonitorsFromHMONITOR(_hMonitor, _physicalMonitorsCount, _physicalMonitors))
                {
                    throw new ApplicationException($"Cannot GetPhysicalMonitorsFromHMONITOR for hmonitor {_hMonitor}");
                }

                InitialBrightness = GetBrightness();

                foreach (var monitor in _physicalMonitors)
                {
                    Log.Info($"Monitor physicalmonitor handle:{monitor.hPhysicalMonitor} description:{monitor.szPhysicalMonitorDescription} with brightness {InitialBrightness}");
                }
            }
            catch (Exception err)
            {
                Log.Log(LogLevel.Error, err, "Unable to get brightness. Brightness will not be supported.");
                SupportBrightness = false;
            }

            // Get the current gamma Ramp
            try
            {
                _linearGammaRamp = GetDefaultGammaRamp();
                SetDeviceGammaRamp(_hdcMonitor, ref _linearGammaRamp);
            }
            catch (Exception err)
            {
                Log.Log(LogLevel.Error, err, "Unable to get base gamma ramp");
            }
        }
コード例 #2
0
ファイル: Monitor.cs プロジェクト: jvanegmond/mlux
        public void SetColorProfile(ColorAdjustment adjustment, int gamma)
        {
            Log.Info($"SetColorProfile {adjustment}, gamma {gamma}");

            if (gamma <= 256 && gamma >= 1)
            {
                var ramp = new GammaRamp {
                    Red = new ushort[256], Green = new ushort[256], Blue = new ushort[256]
                };

                for (int i = 1; i < 256; i++)
                {
                    ushort r, g, b;
                    if (_linearGammaRamp.Red == null)
                    {
                        r = (ushort)(i * (gamma + 128));
                    }
                    else
                    {
                        r = _linearGammaRamp.Red[i];
                    }
                    if (_linearGammaRamp.Blue == null)
                    {
                        b = (ushort)(i * (gamma + 128));
                    }
                    else
                    {
                        b = _linearGammaRamp.Blue[i];
                    }
                    if (_linearGammaRamp.Green == null)
                    {
                        g = (ushort)(i * (gamma + 128));
                    }
                    else
                    {
                        g = _linearGammaRamp.Green[i];
                    }

                    ramp.Red[i]   = (ushort)(r * adjustment.Red);
                    ramp.Green[i] = (ushort)(g * adjustment.Green);
                    ramp.Blue[i]  = (ushort)(b * adjustment.Blue);
                }

                var success = SetDeviceGammaRamp(_hdcMonitor, ref ramp);
                Log.Debug($"SetDeviceGammaRamp {_hdcMonitor} with result {success}");
            }
        }
コード例 #3
0
ファイル: Monitor.cs プロジェクト: jvanegmond/mlux
        public static GammaRamp GetDefaultGammaRamp()
        {
            var result = new GammaRamp
            {
                Red   = new ushort[256],
                Blue  = new ushort[256],
                Green = new ushort[256]
            };

            for (var n = 0; n < 256; n++)
            {
                var value = (ushort)((n / 255d) * ushort.MaxValue);
                result.Red[n] = result.Blue[n] = result.Green[n] = value;
            }

            return(result);
        }
コード例 #4
0
ファイル: Monitor.cs プロジェクト: jvanegmond/mlux
 public static extern bool SetDeviceGammaRamp(IntPtr hDc, ref GammaRamp lpGammaRamp);