/// <summary>
		/// Set the current gamma ramp to compensate monitor gamma.
		/// </summary>
		/// <param name="hDC"></param>
		/// <param name="rgamma"></param>
		/// <param name="ggamma"></param>
		/// <param name="bgamma"></param>
		public static void SetGammaRamp(IntPtr hDC, double rgamma, double ggamma, double bgamma)
		{
			GammaRamp ramp = new GammaRamp();

			// Build gamma ramp in order to compensate monitor gamma
			ramp.Red = new UInt16[256];
			ramp.Green = new UInt16[256];
			ramp.Blue = new UInt16[256];

			for (uint v = 0; v < 256; v++) {
				double gamma;

				// Red ramp
				gamma = Math.Min(1.0, Math.Pow((double)v / 255.0, 1.0 / rgamma));
				ramp.Red[v] = (UInt16)((double)UInt16.MaxValue * gamma);

				// Green ramp
				gamma = Math.Min(1.0, Math.Pow((double)v / 255.0, 1.0 / rgamma));
				ramp.Green[v] = (UInt16)((double)UInt16.MaxValue * gamma);

				// Blue ramp
				gamma = Math.Min(1.0, Math.Pow((double)v / 255.0, 1.0 / rgamma));
				ramp.Blue[v] = (UInt16)((double)UInt16.MaxValue * gamma);
			}

			// Set ramp
			SetGammaRamp(hDC, ref ramp);
		}
Example #2
0
        private GammaRamp CreateGammaRamp(ColorBalance colorBalance)
        {
            // Create native ramp object
            var ramp = new GammaRamp
            {
                Red   = new ushort[256],
                Green = new ushort[256],
                Blue  = new ushort[256]
            };

            // Create linear ramps for each color
            for (var i = 0; i < 256; i++)
            {
                ramp.Red[i]   = (ushort)(i * 255 * colorBalance.Red);
                ramp.Green[i] = (ushort)(i * 255 * colorBalance.Green);
                ramp.Blue[i]  = (ushort)(i * 255 * colorBalance.Blue);
            }

            // Some drivers will ignore request to change gamma if the ramp is the same as last time
            // so we randomize it a bit. Even though our ramp may not have changed, other applications
            // could have affected the gamma and we need to "force-refresh" it to ensure it's valid.
            _gammaChannelOffset = ++_gammaChannelOffset % 5;
            ramp.Red[255]       = (ushort)(ramp.Red[255] + _gammaChannelOffset);
            ramp.Green[255]     = (ushort)(ramp.Green[255] + _gammaChannelOffset);
            ramp.Blue[255]      = (ushort)(ramp.Blue[255] + _gammaChannelOffset);

            return(ramp);
        }
Example #3
0

        
Example #4
0

        
Example #5
0
        public void SetGamma(double redMultiplier, double greenMultiplier, double blueMultiplier)
        {
            // Create native ramp object
            var ramp = new GammaRamp
            {
                Red   = new ushort[256],
                Green = new ushort[256],
                Blue  = new ushort[256]
            };

            // Create linear ramps for each color
            for (var i = 0; i < 256; i++)
            {
                ramp.Red[i]   = (ushort)(i * 255 * redMultiplier);
                ramp.Green[i] = (ushort)(i * 255 * greenMultiplier);
                ramp.Blue[i]  = (ushort)(i * 255 * blueMultiplier);
            }

            // Some drivers will ignore request to change gamma if the ramp is the same as last time
            // so we randomize it a bit. Even though our ramp may not have changed, other applications
            // could have affected the gamma and we need to "force-refresh" it to ensure it's valid.
            _gammaChannelOffset = ++_gammaChannelOffset % 5;
            ramp.Red[255]       = (ushort)(ramp.Red[255] + _gammaChannelOffset);
            ramp.Green[255]     = (ushort)(ramp.Green[255] + _gammaChannelOffset);
            ramp.Blue[255]      = (ushort)(ramp.Blue[255] + _gammaChannelOffset);

            // Set gamma
            SetGammaRamp(ramp);
        }
Example #6
0
 public unsafe WithGammaRamp(GammaRamp ramp)
 {
     Ramp          = ramp;
     GammaTable    = Ramp.GammaTable;
     InvGammaTable = Ramp.InvGammaTable;
     PAGray        = _PAGray;
 }
Example #7
0
 public static unsafe void SetGammaRamp(Monitor monitor, ushort[] red, ushort[] green, ushort[] blue)
 {
     var ramp = new GammaRamp();
     ramp.Red = Marshal.UnsafeAddrOfPinnedArrayElement(red, 0);
     ramp.Green = Marshal.UnsafeAddrOfPinnedArrayElement(green, 0);
     ramp.Blue = Marshal.UnsafeAddrOfPinnedArrayElement(blue, 0);
     glfwSetGammaRamp(monitor.Ptr, new IntPtr(&ramp));
 }
		/// <summary>
		/// Get the current gamma ramp.
		/// </summary>
		/// <param name="hDC"></param>
		/// <returns></returns>
		public static GammaRamp GetGammaRamp(IntPtr hDC)
		{
			GammaRamp ramp = new GammaRamp();

			if (GetDeviceGammaRamp(hDC, ref ramp) == false)
				throw new InvalidOperationException("GetDeviceGammaRamp has failed");

			return (ramp);
		}
Example #9
0

        
Example #10
0
        /// <inheritdoc />
        public void SetDisplayGammaLinear(ColorIntensity intensity)
        {
            var ramp = new GammaRamp(256);

            for (var i = 1; i < 256; i++)
            {
                ramp.Red[i]   = (ushort)(i * 255 * intensity.Red);
                ramp.Green[i] = (ushort)(i * 255 * intensity.Green);
                ramp.Blue[i]  = (ushort)(i * 255 * intensity.Blue);
            }

            SetDisplayGammaRamp(ramp);
        }
        static public void UpdateGammaCorrection()
        {
            short[] gray_gamma = new short[256];
            //GammaRamp gr = MdxRender.Dev.GetGammaRamp(0);
            //short[] red_gamma = gr.GetRed();
            //short[] green_gamma = gr.GetGreen();
            //short[] blue_gamma = gr.GetBlue();
            GammaRamp gr = new GammaRamp();

            float recip_gray = recip_gamma(GammaFactor);

            // compute i**(1/gamma) for all i and scale to range
            for (short i = 0; i < 256; i++)
            {
                gray_gamma[i] = ramp_val(i, recip_gray, 255);
            }

            gr.SetRed(gray_gamma);
            gr.SetGreen(gray_gamma);
            gr.SetBlue(gray_gamma);

            MdxRender.Dev.SetGammaRamp(0, false, gr);


            /*
             * m_gamma[G_GRAY] = m_gamma[G_RED] = m_gamma[G_GREEN] = m_gamma[G_BLUE]
             * = INITIAL_GAMMA;
             *
             * if (m_test_gamma && m_can_gamma_ramp)
             * {
             * if (m_single_gamma)
             * {
             *  // compute 1/gamma
             *  const float recip_gray = recip_gamma(m_gamma[G_GRAY]);
             *  // compute i**(1/gamma) for all i and scale to range
             *  for (UINT i = 0; i < 256; i++)
             *  {
             *    m_ramp.red[i] = m_ramp.green[i] = m_ramp.blue[i] =
             *      ramp_val(i, recip_gray);
             *  }
             * }
             * }
             * else
             * {
             * for (UINT i = 0; i < 256; i++)
             * {
             *  m_ramp.red[i] = m_ramp.green[i] = m_ramp.blue[i] = 65535*i/255;
             * }
             * }
             */
        }
Example #12
0
        /// <summary>
        /// Change the display gamma based on given curve
        /// </summary>
        private void SetDisplayGammaRamp(GammaRamp ramp)
        {
            // Offset the values in ramp slightly...
            // ... this forces the ramp to refresh every time
            // ... because some drivers will ignore stale ramps
            // ... while the gamma itself might have been changed
            _gammaChannelOffset = ++_gammaChannelOffset % 5;
            ramp.Red[255]       = (ushort)(ramp.Red[255] + _gammaChannelOffset);
            ramp.Green[255]     = (ushort)(ramp.Green[255] + _gammaChannelOffset);
            ramp.Blue[255]      = (ushort)(ramp.Blue[255] + _gammaChannelOffset);

            // Set ramp
            NativeMethods.SetDeviceGammaRamp(_dc, ref ramp);
        }
Example #13
0
        public static void SetGammaRamp(IntPtr monitor, ref GammaRamp ramp)
        {
            unsafe
            {
                fixed(ushort *rampRed = ramp.Red, rampGreen = ramp.Green, rampBlue = ramp.Blue)
                {
                    var internalRamp = new UnmanagedGammaRamp {
                        red = rampRed, green = rampGreen, blue = rampBlue, size = ramp.Size
                    };

                    _SetGammaRamp(monitor, new IntPtr(&internalRamp));
                }
            }
        }
Example #14
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 GammaRamp()//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);
            int counter;

            for (counter = 1; counter <= 10; counter++)
            {
                var result = SetDeviceGammaRamp(screenDC, ref ramp);
                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");
                }
            }
            ReleaseDC(IntPtr.Zero, screenDC); // required otherwise will leak GDI objects
        }
Example #15
0
        public static GammaRamp GetGammaRamp(Monitor monitor)
        {
            GammaRamp         ramp;
            GammaRampInternal rampI = Imports.glfwGetGammaRamp(monitor);
            uint length             = rampI.Length;

            ramp       = new GammaRamp();
            ramp.Red   = new uint[length];
            ramp.Green = new uint[length];
            ramp.Blue  = new uint[length];
            for (int i = 0; i < ramp.Red.Length; ++i)
            {
                ramp.Red[i] = rampI.Red[i];
            }
            for (int i = 0; i < ramp.Green.Length; ++i)
            {
                ramp.Green[i] = rampI.Green[i];
            }
            for (int i = 0; i < ramp.Blue.Length; ++i)
            {
                ramp.Blue[i] = rampI.Blue[i];
            }
            return(ramp);
        }
Example #16
0
        public static GammaRamp GetGammaRamp(IntPtr monitor)
        {
            unsafe
            {
                var internalRamp = _GetGammaRamp(monitor);

                var ramp = new GammaRamp
                {
                    Red   = new ushort[internalRamp->size],
                    Green = new ushort[internalRamp->size],
                    Blue  = new ushort[internalRamp->size],
                    Size  = internalRamp->size
                };

                for (uint i = 0; i < ramp.Size; i++)
                {
                    ramp.Red[i]   = internalRamp->red[i];
                    ramp.Green[i] = internalRamp->green[i];
                    ramp.Blue[i]  = internalRamp->blue[i];
                }

                return(ramp);
            }
        }
Example #17
0
		private static extern bool GetDeviceGammaRamp(IntPtr hDC, ref GammaRamp lpRamp);
Example #18
0
		/// <summary>
		/// Set the current gamma ramp to any ramp supplied.
		/// </summary>
		/// <param name="hDC"></param>
		/// <param name="ramp"></param>
		public static void SetGammaRamp(IntPtr hDC, ref GammaRamp ramp)
		{
			if (SetDeviceGammaRamp(hDC, ref ramp) == false)
				throw new InvalidOperationException("SetDeviceGammaRamp has failed");
		}
Example #19
0
 public static extern void SetGammaRamp(IntPtr monitor, ref GammaRamp ramp);
Example #20
0

        
Example #21
0
 public static void SetGammaRamp(Monitor monitor, GammaRamp ramp)
 {
     Imports.glfwSetGammaRamp(monitor, ramp);
 }
Example #22
0
 internal static extern bool SetDeviceGammaRamp(DeviceContextHandle deviceContextHandle, ref GammaRamp ramp);
Example #23
0
 public void SetGammaRamp(int swapChain, ref GammaRamp rampRef, bool calibrate)
 {
     _device.SetGammaRamp(swapChain, ref rampRef, calibrate);
 }
Example #24
0
 public static extern bool GetDeviceGammaRamp(IntPtr hMonitor, out GammaRamp ramp);
Example #25
0

        
Example #26
0
 public static extern bool GetDeviceGammaRamp(IntPtr hdc, out GammaRamp lpRamp);
Example #27
0
 public static extern bool SetDeviceGammaRamp(IntPtr hdc, ref GammaRamp lpRamp);
 internal static extern bool SetDeviceGammaRamp(DCHandle dcHandle, ref GammaRamp ramp);
Example #29
0
 private void SetGammaRamp(GammaRamp ramp) => NativeMethods.SetDeviceGammaRamp(Handle, ref ramp);
Example #30
0
 public static extern bool SetDeviceGammaRamp(IntPtr hMonitor, ref GammaRamp ramp);