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); }
/// <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); } }
/// <summary> /// 返回伽马值 /// </summary> /// <returns></returns> public RAMP GetGamma() { RAMP r = new RAMP(); GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref r); return(r); }
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"); } }
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); }
public static RAMP getGamma() { RAMP originalGamma = new RAMP(); GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref originalGamma); return(originalGamma); }
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); } }
public static void SetGammaRamp(ref RAMP rmp) { IntPtr DC = GetDC(GetDesktopWindow()); if (DC != null) { SetDeviceGammaRamp(DC, ref rmp); } }
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) }
public static RAMP GetGammaRampFromMonitor() { IntPtr DC = GetDC(GetDesktopWindow()); RAMP result = new RAMP(); if (DC != null) { GetDeviceGammaRamp(DC, ref result); } return(result); }
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; }
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); }
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); }
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); }
// 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); }
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()); }
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; } } }
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); } }
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; }
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); } } } }
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); } }
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); }
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"); } }
private static extern bool GetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
public static void setGamma(RAMP ramp) { SetDeviceGammaRamp(GetDC(IntPtr.Zero), ref ramp); }
// ReSharper disable InconsistentNaming private static byte GetBrightnessFromRAMP(RAMP p_Ramp) // ReSharper restore InconsistentNaming { return((byte)(p_Ramp.Blue[1] - 128)); }
private static byte GetBrightnessFromRAMP(RAMP p_Ramp) { return (byte)(p_Ramp.Blue[1] - 128); }
static Screen() { ramp = new RAMP(); }
public static extern int SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp); [DllImport("user32.dll")]
public static extern bool GetDeviceGammaRamp(IntPtr hdc, ref RAMP lpRamp);
public static extern bool SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
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); } }
static extern bool SetDeviceGammaRamp(IntPtr hdc, ref RAMP lpRamp);
internal static extern int GetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
public void SetBaseGammaRAMP(RAMP baseRamp) { this._baseRamp = baseRamp; }
public static extern int SetDeviceGammaRamp(IntPtr hDC, ref RAMP lpRamp);
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); }
public RAMP GetCurrentGammaRAMP() { var result = new RAMP(); GetDeviceGammaRamp(GetDC(IntPtr.Zero), ref result); return result; }
private double CalAllGammaVal(RAMP ramp) { return(Math.Round(((CalColorGammaVal(ramp.Blue) + CalColorGammaVal(ramp.Red) + CalColorGammaVal(ramp.Green)) / 3), 2)); }
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); } }