Ejemplo n.º 1
0
        public override bool SetGammaDefault(double val)
        {
            RAMP ramp = default(RAMP);

            ramp.Red   = new ushort[256];
            ramp.Green = new ushort[256];
            ramp.Blue  = new ushort[256];

            for (int i = 1; i < 256; i++)
            {
                // gamma 必须在3和44之间
                //ramp.Red[i] = ramp.Green[i] = ramp.Blue[i] =
                //    (ushort)(Math.Min(65535,
                //    Math.Max(0, Math.Pow((i + 1) / 256.0, gamma * 0.1) * 65535 + 0.5)
                //    ));

                //     ramp.Red[i] = ramp.Green[i] = ramp.Blue[i] =
                //(ushort)(Math.Min(65535, Math.Max(0, Math.Pow((i + 1) / 256.0, val * 0.1) * 65535 + 0.5)));

                var tmp = (ushort)(i * 255 * val);

                ramp.Red[i] = ramp.Green[i] = ramp.Blue[i]
                                                  = (ushort)(Math.Max(ushort.MinValue, Math.Min(ushort.MaxValue, tmp)));
            }
            var bok = Native.gdi32.SetDeviceGammaRamp(_screenHandle, ref ramp);

            return(bok);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 设置伽马值(亮度)
        /// </summary>
        /// <param name="gamma">小于等于256</param>
        /// <returns></returns>
        public bool SetGamma(int gamma)
        {
            if (gamma <= 256 && gamma >= 1)
            {
                RAMP ramp = new RAMP();
                ramp.Red   = new ushort[256];
                ramp.Green = new ushort[256];
                ramp.Blue  = new ushort[256];
                for (int i = 1; i < 256; i++)
                {
                    int iArrayValue = i * (gamma + 128);

                    if (iArrayValue > 65535)
                    {
                        iArrayValue = 65535;
                    }
                    ramp.Red[i] = ramp.Blue[i] = ramp.Green[i] = (ushort)iArrayValue;
                }
                return(SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp));
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 返回伽马值
        /// </summary>
        /// <returns></returns>
        public RAMP GetGamma()
        {
            RAMP r = new RAMP();

            GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref r);
            return(r);
        }
Ejemplo n.º 4
0
        public static void CustomRamp(int[] transformR, int[] transformG, int[] transformB)
        {
            var ramp = new RAMP();

            ramp.Red   = new ushort[256];
            ramp.Green = new ushort[256];
            ramp.Blue  = new ushort[256];


            for (int i = 0; i <= 255; i++)
            {
                int value = i;
                ramp.Red[i]   = (ushort)(transformR[i] << 8); // bitwise shift left
                ramp.Green[i] = (ushort)(transformG[i] << 8); // by 8
                ramp.Blue[i]  = (ushort)(transformB[i] << 8); // same as multiplying by 256
            }

            var screenDC = GetDC(IntPtr.Zero);
            var result   = SetDeviceGammaRamp(screenDC, ref ramp);

            ReleaseDC(IntPtr.Zero, screenDC); // required otherwise will leak GDI objects

            if (result == false)
            {
                // Can't go below 0.50 (3400K) unless flux is installed
                // and "Expand range" feature activated (flux.exe /unlockwingamma)
                throw new Exception("Failed to set gamma ramp");
            }
        }
Ejemplo n.º 5
0
        public void SetGamma(int gamma)
        {
            if (gamma < 0)
            {
                gamma = 0;
            }
            else if (gamma > 100)
            {
                gamma = 100;
            }
            gamma = ((gamma * 255) / 100) + 1;

            var ramp = new RAMP {
                Green = new ushort[256],
                Blue  = new ushort[256],
                Red   = new ushort[256]
            };

            for (var i = 1; i < 256; i++)
            {
                var iArrayValue = i * (gamma + 128);
                if (iArrayValue > 65535)
                {
                    iArrayValue = 65535;
                }
                ramp.Red[i] = ramp.Blue[i] = ramp.Green[i] = (ushort)iArrayValue;
            }
            SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
        }
Ejemplo n.º 6
0
        public static RAMP getGamma()
        {
            RAMP originalGamma = new RAMP();

            GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref originalGamma);
            return(originalGamma);
        }
Ejemplo n.º 7
0
        public void SetBri(int Value)
        {
            IntPtr DC = GetDC(GetDesktopWindow());

            if (DC != null)
            {
                RAMP _Rp = new RAMP();

                _Rp.Blue  = new ushort[256];
                _Rp.Green = new ushort[256];
                _Rp.Red   = new ushort[256];

                for (int i = 1; i < 256; i++)
                {
                    int value = i * (Value + 128);

                    if (value > 65535)
                    {
                        value = 65535;
                    }

                    _Rp.Red[i] = _Rp.Green[i] = _Rp.Blue[i] = Convert.ToUInt16(value);
                }

                SetDeviceGammaRamp(DC, ref _Rp);
            }
        }
Ejemplo n.º 8
0
        public static void SetGammaRamp(ref RAMP rmp)
        {
            IntPtr DC = GetDC(GetDesktopWindow());

            if (DC != null)
            {
                SetDeviceGammaRamp(DC, ref rmp);
            }
        }
Ejemplo n.º 9
0
        public static void SetGamma(double red, double green, double blue, bool posterise)
        {
            if (red < 0.0 || red > 1.0 ||
                green < 0.0 || green > 1.0 ||
                blue < 0.0 || blue > 1.0)
            {
                throw new Exception("Multiplier out of range");
            }

            var ramp = new RAMP();

            ramp.Red   = new ushort[256];
            ramp.Green = new ushort[256];
            ramp.Blue  = new ushort[256];

            if (_posteriseLookup == null)
            {
                _posteriseLookup = new Posterise().ApplyMethod("posterise_5level_custom2");
                // posterise_5level (125 colours)
                // posterise_5level_custom (125 colours)
                // posterise_4level_custom (64 colours)
            }

            for (int i = 0; i <= 255; i++)
            {
                int R_value = posterise ? _posteriseLookup.Red[i] : i;
                int G_value = posterise ? _posteriseLookup.Green[i] : i;
                int B_value = posterise ? _posteriseLookup.Blue[i] : i;

                ramp.Red[i]   = (ushort)(Convert.ToByte(R_value * red) << 8);   // bitwise shift left
                ramp.Green[i] = (ushort)(Convert.ToByte(G_value * green) << 8); // by 8
                ramp.Blue[i]  = (ushort)(Convert.ToByte(B_value * blue) << 8);  // same as multiplying by 256
            }

            var screenDC = GetDC(IntPtr.Zero);
            var result   = SetDeviceGammaRamp(screenDC, ref ramp);

            ReleaseDC(IntPtr.Zero, screenDC); // required otherwise will leak GDI objects

            if (result == false)
            {
                // Can't go below 0.50 (3400K) unless flux is installed
                // and "Expand range" feature activated (flux.exe /unlockwingamma)
                throw new Exception("Failed to set gamma ramp");
            }
            // Here's the reason why:
            //     "[SetDeviceGammaRamp], in contrast to the [other APIs] described later in this section,
            //     allows only a small deviation from an identity function. In fact, any entry
            //     in the ramp must be within 32768 of the identity value. This restriction means
            //     that no app can turn the display completely black or to some other unreadable color."
            //  -- https://msdn.microsoft.com/en-us/library/windows/desktop/jj635732(v=vs.85).aspx#setting_gamma_control_with_dxgi
            // See also http://jonls.dk/2010/09/windows-gamma-adjustments/
            // (via https://stackoverflow.com/a/33268698/58241)
        }
Ejemplo n.º 10
0
        public static RAMP GetGammaRampFromMonitor()
        {
            IntPtr DC     = GetDC(GetDesktopWindow());
            RAMP   result = new RAMP();

            if (DC != null)
            {
                GetDeviceGammaRamp(DC, ref result);
            }
            return(result);
        }
Ejemplo n.º 11
0
 private static RAMP CalcRAMP(byte p_Brightness)
 {
     RAMP c_Ramp = new RAMP { Red = new ushort[256], Green = new ushort[256], Blue = new ushort[256] };
         for (int c_Index = 0; c_Index < 256; c_Index++)
         {
             c_Ramp.Red[c_Index] = (ushort)(c_Index * (p_Brightness + 128));
             c_Ramp.Green[c_Index] = (ushort)(c_Index * (p_Brightness + 128));
             c_Ramp.Blue[c_Index] = (ushort)(c_Index * (p_Brightness + 128));
         }
         return c_Ramp;
 }
Ejemplo n.º 12
0
    public static bool SetBrightness(byte brightness)
    {
        if (brightness < minimumBrightness || brightness > maximumBrightness)
        {
            return(false);
        }
        currentBrightness = brightness;
        RAMP c_Ramp = CalcRAMP(brightness);

        SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref c_Ramp);
        return(true);
    }
Ejemplo n.º 13
0
    private static RAMP CalcRAMP(byte p_Brightness)

    {
        RAMP c_Ramp = new RAMP {
            Red = new ushort[256], Green = new ushort[256], Blue = new ushort[256]
        };

        for (int c_Index = 0; c_Index < 256; c_Index++)
        {
            c_Ramp.Red[c_Index]   = (ushort)(c_Index * (p_Brightness + 128));
            c_Ramp.Green[c_Index] = (ushort)(c_Index * (p_Brightness + 128));
            c_Ramp.Blue[c_Index]  = (ushort)(c_Index * (p_Brightness + 128));
        }
        return(c_Ramp);
    }
Ejemplo n.º 14
0
        public static bool SetBrightness(byte p_Brightness)
        {
            if (p_Brightness < MIN_BRIGHTNESS || p_Brightness > MAX_BRIGHTNESS)
            {
                return(false);
            }

            m_CurrentBrightness = p_Brightness;

            RAMP c_Ramp = CalculateRAMP(p_Brightness);

            SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref c_Ramp);

            return(true);
        }
Ejemplo n.º 15
0
// ReSharper disable InconsistentNaming
        private static RAMP CalculateRAMP(byte p_Brightness)
// ReSharper restore InconsistentNaming
        {
            RAMP c_Ramp = new RAMP {
                Red = new ushort[256], Green = new ushort[256], Blue = new ushort[256]
            };

            for (int c_Index = 0; c_Index < 256; c_Index++)
            {
                c_Ramp.Red[c_Index]   = (ushort)(c_Index * (p_Brightness + 128));
                c_Ramp.Green[c_Index] = (ushort)(c_Index * (p_Brightness + 128));
                c_Ramp.Blue[c_Index]  = (ushort)(c_Index * (p_Brightness + 128));
            }

            return(c_Ramp);
        }
Ejemplo n.º 16
0
        public static void SetGamma(int gamma)
        {
            RAMP ramp = new RAMP();

            ramp.Red = new ushort[256];
            ramp.Green = new ushort[256];
            ramp.Blue = new ushort[256];

            for (int i = 1; i < 256; i++)
            {
                // gamma is a value between 3 and 44
                ramp.Red[i] = ramp.Green[i] = ramp.Blue[i] = (ushort)(Math.Min(65535, Math.Max(0, Math.Pow((i + 1) / 256.0, gamma * 0.1) * 65535 + 0.5)));
            }

            bool ret = SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
            System.Diagnostics.Trace.WriteLine(ret.ToString());
        }
Ejemplo n.º 17
0
    void UpdateLeadLine()
    {
        if (targetIndicatorEnabled)
        {
            if (!leadLine.enabled)
            {
                leadLine.enabled = true;
            }

            Vector3 lineStart = new Vector3(0f, 0f, 0f);
            Vector3 lineEnd   = new Vector3(0f, 0f, 0f);

            if (ship.activeWeapon.GetComponent <WepContr>().weaponCategory == WepContr.WeapCat.missile)
            {
                Vector3 vToTarget = ship.radar.target.transform.position - gameObject.transform.position;
                lineStart = gameObject.transform.position + vToTarget.normalized * 2;
                lineEnd   = ship.radar.target.transform.position;
            }
            else
            {
                Vector2 aimpoint = RAMP.GetLeadPoint(
                    new Vector2(gameObject.transform.position.x, gameObject.transform.position.y),
                    new Vector2(ship.radar.target.transform.position.x, ship.radar.target.transform.position.y),
                    ship.radar.target.GetComponent <Rigidbody2D>().velocity,
                    gameObject.GetComponent <Rigidbody2D>().velocity,
                    ship.GetProjectileSpeed()
                    );

                Vector3 v2aimpoint = new Vector3(aimpoint.x, aimpoint.y, 0f) - gameObject.transform.position;

                lineStart = gameObject.transform.position + v2aimpoint.normalized * 2;
                lineEnd   = new Vector3(aimpoint.x, aimpoint.y, 0f);
            }

            leadLine.SetPosition(0, lineStart);
            leadLine.SetPosition(1, lineEnd);
        }
        else
        {
            if (leadLine.enabled)
            {
                leadLine.enabled = false;
            }
        }
    }
Ejemplo n.º 18
0
    public static void SetGamma(int gammar, int gammag, int gammab)
    {
        if (gammar <= 256 && gammar >= 1)
        {
            RAMP ramp = new RAMP();
            ramp.Red   = new ushort[256];
            ramp.Green = new ushort[256];
            ramp.Blue  = new ushort[256];
            for (int i = 1; i < 256; i++)
            {
                int iArrayValue = i * (gammar + 128);

                if (iArrayValue > 65535)
                {
                    iArrayValue = 65535;
                }
                ramp.Red[i] = (ushort)iArrayValue;
            }

            for (int i = 1; i < 256; i++)
            {
                int iArrayValue = i * (gammag + 128);

                if (iArrayValue > 65535)
                {
                    iArrayValue = 65535;
                }
                ramp.Green[i] = (ushort)iArrayValue;
            }

            for (int i = 1; i < 256; i++)
            {
                int iArrayValue = i * (gammab + 128);

                if (iArrayValue > 65535)
                {
                    iArrayValue = 65535;
                }
                ramp.Blue[i] = (ushort)iArrayValue;
            }
            SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
        }
    }
Ejemplo n.º 19
0
    void Pursue()
    {
        // check for radar lock


        if (targetObject)
        {
            sqrToTarget = (gameObject.GetComponent <Rigidbody2D>().position - targetObject.GetComponent <Rigidbody2D>().position).sqrMagnitude;

            if (sqrToTarget < armingSQRDistance * armingSQRDistance)
            {
                if (sqrToTarget > minSqrToTarget)
                {
                    Detonate();
                }
            }


            if (debug)
            {
                statusText.text = statusText.text + " " + targetObject.name;
            }

            Vector2 killBurn = RAMP.GetHitBurn(targetObject.transform, gameObject.transform, missile.fuel, mass);
            desiredHeading = killBurn.x;
            LateralCorrection();
            missile.Rotate(desiredHeading, Time.deltaTime);

            if (Mathf.Abs(desiredHeading - missile.transform.eulerAngles.z) < 0.5f)
            {
                ExecuteThrust(killBurn.y);
            }
        }
        else
        {
            stateChanging = true;
            missileState  = MissileState.mine;
        }

        minSqrToTarget = sqrToTarget;
    }
Ejemplo n.º 20
0
        public static void SetGammaColor(int red, int blue, int green)
        {
            if (red <= 256 && red >= 0)
            {
                if (blue <= 256 && blue >= 0)
                {
                    if (green <= 256 && green >= 0)
                    {
                        RAMP ramp = new RAMP();
                        ramp.Red   = new ushort[256];
                        ramp.Green = new ushort[256];
                        ramp.Blue  = new ushort[256];
                        for (int i = 1; i < 256; i++)
                        {
                            int RedValue = i * (red + 128);
                            int BluValue = i * (blue + 128);
                            int GreValue = i * (green + 128);

                            if (RedValue > 65535)
                            {
                                RedValue = 65535;
                            }
                            if (BluValue > 65535)
                            {
                                BluValue = 65535;
                            }
                            if (GreValue > 65535)
                            {
                                GreValue = 65535;
                            }

                            ramp.Red[i]   = (ushort)RedValue;
                            ramp.Blue[i]  = (ushort)BluValue;
                            ramp.Green[i] = (ushort)GreValue;
                        }
                        SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
                    }
                }
            }
        }
Ejemplo n.º 21
0
        private static void SetGamma(int gamma)
        {
            if (gamma <= 255 && gamma >= 0)
            {
                var ramp = new RAMP
                {
                    Red   = new ushort[256],
                    Green = new ushort[256],
                    Blue  = new ushort[256]
                };
                for (var i = 0; i < 256; ++i)
                {
                    var iArrayValue = i * (gamma + 128);

                    if (iArrayValue > 65535)
                    {
                        iArrayValue = 65535;
                    }
                    ramp.Red[i] = ramp.Blue[i] = ramp.Green[i] = (ushort)iArrayValue;
                }
                SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
            }
        }
Ejemplo n.º 22
0
        private static int GetGamma()
        {
            var ramp = new RAMP
            {
                Red   = new ushort[256],
                Green = new ushort[256],
                Blue  = new ushort[256]
            };

            GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
            for (var i = 1; i < 256; ++i)
            {
                if (ramp.Red[i] != 65535)
                {
                    var gamma = ramp.Red[i] / i - 128;
                    if (gamma <= 255 && gamma >= 0)
                    {
                        return(gamma);
                    }
                }
            }
            return(128);
        }
Ejemplo n.º 23
0
        public static void SetGamma(double red, double green, double blue)
        {
            if (red < 0.0 || red > 1.0 ||
                green < 0.0 || green > 1.0 ||
                blue < 0.0 || blue > 1.0)
            {
                throw new Exception("Multiplier out of range");
            }

            var ramp = new RAMP()
            {
                Red   = new ushort[256],
                Green = new ushort[256],
                Blue  = new ushort[256]
            };

            for (int i = 0; i <= 255; i++)
            {
                int value = i;

                ramp.Red[i]   = (ushort)(Convert.ToByte(value * red) << 8);   // bitwise shift left
                ramp.Green[i] = (ushort)(Convert.ToByte(value * green) << 8); // by 8
                ramp.Blue[i]  = (ushort)(Convert.ToByte(value * blue) << 8);  // same as multiplying by 256
            }

            var screenDC = GetDC(IntPtr.Zero);
            var result   = SetDeviceGammaRamp(screenDC, ref ramp);

            ReleaseDC(IntPtr.Zero, screenDC); // required otherwise will leak GDI objects

            if (result == false)
            {
                // Can't go below 0.50 (3400K) unless flux is installed
                // and "Expand range" feature activated (flux.exe /unlockwingamma)
                throw new Exception("Failed to set gamma ramp");
            }
        }
Ejemplo n.º 24
0
 private static extern bool GetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
Ejemplo n.º 25
0
 public static void setGamma(RAMP ramp)
 {
     SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
 }
Ejemplo n.º 26
0
// ReSharper disable InconsistentNaming
        private static byte GetBrightnessFromRAMP(RAMP p_Ramp)
// ReSharper restore InconsistentNaming
        {
            return((byte)(p_Ramp.Blue[1] - 128));
        }
Ejemplo n.º 27
0
 private static byte GetBrightnessFromRAMP(RAMP p_Ramp)
 {
     return (byte)(p_Ramp.Blue[1] - 128);
 }
Ejemplo n.º 28
0
 static Screen()
 {
     ramp = new RAMP();
 }
Ejemplo n.º 29
0
 public static extern int SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp); [DllImport("user32.dll")]
Ejemplo n.º 30
0
 public static extern bool GetDeviceGammaRamp(IntPtr hdc, ref RAMP lpRamp);
Ejemplo n.º 31
0
 public static extern bool SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
Ejemplo n.º 32
0
        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);
            }
        }
Ejemplo n.º 33
0
 static extern bool SetDeviceGammaRamp(IntPtr hdc, ref RAMP lpRamp);
Ejemplo n.º 34
0
 internal static extern int GetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
Ejemplo n.º 35
0
 public void SetBaseGammaRAMP(RAMP baseRamp)
 {
     this._baseRamp = baseRamp;
 }
Ejemplo n.º 36
0
 public static extern int SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
Ejemplo n.º 37
0
 private void setGamma(int gamma)
 {
     RAMP ramp = new RAMP();
     IntPtr gammaDC = GetDC(IntPtr.Zero);
     ramp.Red = new ushort[256];
     ramp.Green = new ushort[256];
     ramp.Blue = new ushort[256];
     for (int i = 1; i < 256; i++)
     {
         // gamma is a value between 3 and 44
         ramp.Red[i] = ramp.Green[i] = ramp.Blue[i] = (ushort)(Math.Min(65535, Math.Max(0, Math.Pow((i + 1) / 256.0, gamma * 0.1) * 65535 + 0.5)));
     }
     SetDeviceGammaRamp(gammaDC, ref ramp);
     ReleaseDC(IntPtr.Zero, gammaDC);
 }
Ejemplo n.º 38
0
 public RAMP GetCurrentGammaRAMP()
 {
     var result = new RAMP();
     GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref result);
     return result;
 }
Ejemplo n.º 39
0
 private double CalAllGammaVal(RAMP ramp)
 {
     return(Math.Round(((CalColorGammaVal(ramp.Blue) + CalColorGammaVal(ramp.Red) +
                         CalColorGammaVal(ramp.Green)) / 3), 2));
 }
Ejemplo n.º 40
0
        public static void SetGamma(int gamma)
        {
            if (gamma <= 256 && gamma >= 1)
            {
                RAMP ramp = new RAMP();
                ramp.Red = new ushort[256];
                ramp.Green = new ushort[256];
                ramp.Blue = new ushort[256];
                for (int i = 1; i < 256; i++)
                {
                    int iArrayValue = i * (gamma + 128);

                    if (iArrayValue > 65535)
                        iArrayValue = 65535;
                    ramp.Red[i] = ramp.Blue[i] = ramp.Green[i] = (ushort)iArrayValue;
                }
                SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp);
            }
        }