コード例 #1
0
ファイル: ColorTemperature.cs プロジェクト: jvanegmond/mlux
        /// <summary>
        /// Turns a temperature (between 0K and 70000K) into a color profile.
        /// </summary>
        public static ColorAdjustment GetColorProfile(double temperature)
        {
            var result = new ColorAdjustment();

            // Code from http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/

            temperature = temperature / 100;

            if (temperature <= 66)
            {
                result.Red = 255;
            }
            else
            {
                result.Red = temperature - 60;
                result.Red = 329.698727446 * (Math.Pow(result.Red, -0.1332047592));
                if (result.Red < 0) result.Red = 0;
                if (result.Red > 255) result.Red = 255;
            }

            if (temperature <= 66)
            {
                result.Green = temperature;
                result.Green = 99.4708025861 * Math.Log(result.Green) - 161.1195681661;
                if (result.Green < 0) result.Green = 0;
                if (result.Green > 255) result.Green = 255;
            }
            else
            {
                result.Green = temperature - 60;
                result.Green = 288.1221695283 * (Math.Pow(result.Green, -0.0755148492));
                if (result.Green < 0) result.Green = 0;
                if (result.Green > 255) result.Green = 255;
            }

            if (temperature >= 66)
            {
                result.Blue = 255;
            }
            else
            {
                result.Blue = temperature - 10;
                result.Blue = 138.5177312231 * Math.Log(result.Blue) - 305.0447927307;
                if (result.Blue < 0) result.Blue = 0;
                if (result.Blue > 255) result.Blue = 255;
            }

            result.Red /= 255;
            result.Green /= 255;
            result.Blue /= 255;

            return result;
        }
コード例 #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
 public void SetColorProfile(ColorAdjustment adjustment, int gamma)
 {
     _monitor.SetColorProfile(adjustment, gamma);
 }
コード例 #4
0
 public void SetColorProfile(ColorAdjustment adjustment)
 {
     _monitor.SetColorProfile(adjustment);
 }
コード例 #5
0
ファイル: Monitor.cs プロジェクト: jvanegmond/mlux
 public void SetColorProfile(ColorAdjustment adjustment)
 {
     SetColorProfile(adjustment, DefaultGamma);
 }
コード例 #6
0
ファイル: Monitor.cs プロジェクト: jvanegmond/mlux
        public void SetColorProfile(ColorAdjustment adjustment, int gamma = DefaultGamma)
        {
            if (_baseRamp.Blue == null || _baseRamp.Red == null || _baseRamp.Green == null)
            {
                Log.Warn("The monitors current gamma ramp is unavailable. Falling back to default gamma ramp.");
            }

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

                for (int i = 1; i < 256; i++)
                {

                    ushort r, g, b;
                    if (_baseRamp.Red == null)
                    {
                        r = (ushort)(i * (gamma + 128));
                    }
                    else
                    {
                        r = _baseRamp.Red[i];
                    }
                    if (_baseRamp.Blue == null)
                    {
                        b = (ushort)(i * (gamma + 128));
                    }
                    else
                    {
                        b = _baseRamp.Blue[i];
                    }
                    if (_baseRamp.Green == null)
                    {
                        g = (ushort)(i * (gamma + 128));
                    }
                    else
                    {
                        g = _baseRamp.Green[i];
                    }

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

                SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
            }
        }