Comments (13)
Gamma, brightness, and contrast are controlled via the Windows API even when modified from the NVidia Control panel. There is no API in NVAPI for them. NvAPI_VIO_SetGamma
is about NVidia Capture Cards (VIO) and has nothing to do with monitors.
Specifically for gamma, the related methods are GetDeviceGammaRamp()
and SetDeviceGammaRamp()
.
from nvapiwrapper.
It might also be possible to ask the monitor to change the related settings via I2C.
Take a look into the I2CSample.cs
for an example about changing the brightness by communicating with the monitor. It might be possible to modify the code to change the monitor's gamma value. I know the contrast index but I don't have any info about the gamma.
This might be useful:
https://cgit.freedesktop.org/~aplattner/nvidia-settings/tree/src/libXNVCtrl/NVCtrl.h?id=b27db3d10d58b821e87fbe3f46166e02dc589855#n1329
And this:
http://boichat.ch/nicolas/ddcci/specs.html
Specially:
https://milek7.pl/ddcbacklight/mccs.pdf
@ Page 26 - 7.1 Image Adjustments
from nvapiwrapper.
Ah, ok I see. Thanks for the information. I found this wrapper and was giving it a try because I had already done some testing using SetDeviceGammaRamp(), but even though it appeared to run, my monitor's gamma never changed. I'd assumed it was because I had to deal with gamma through Nvidia instead, but now I see I was wrong. I'll be doing some more testing using the information you've provided, thanks again.
from nvapiwrapper.
I recently wrote a function to change the gamma ramp similar to what NVidia Control Panel sends to the API. Check it out:
private static ushort[] CalculateLUT(double brightness = 0.5, double contrast = 0.5, double gamma = 1)
{
const int dataPoints = 256;
// Limit gamma in range [0.4-2.8]
gamma = Math.Min(Math.Max(gamma, 0.4), 2.8);
// Normalize contrast in range [-1,1]
contrast = (Math.Min(Math.Max(contrast, 0), 1) - 0.5) * 2;
// Normalize brightness in range [-1,1]
brightness = (Math.Min(Math.Max(brightness, 0), 1) - 0.5) * 2;
// Calculate curve offset resulted from contrast
var offset = contrast > 0 ? contrast * -25.4 : contrast * -32;
// Calculate the total range of curve
var range = (dataPoints - 1) + offset * 2;
// Add brightness to the curve offset
offset += brightness * (range / 5);
// Fill the gamma curve
var result = new ushort[dataPoints];
for (var i = 0; i < result.Length; i++)
{
var factor = (i + offset) / range;
factor = Math.Pow(factor, 1 / gamma);
factor = Math.Min(Math.Max(factor, 0), 1);
result[i] = (ushort)Math.Round(factor * ushort.MaxValue);
}
return result;
}
from nvapiwrapper.
Use this along with SetDeviceGammaRamp()
Windows API to change the gamma, brightness, and/or contrast.
from nvapiwrapper.
That looks awesome, will check it out!
from nvapiwrapper.
I recently wrote a function to change the gamma ramp similar to what NVidia Control Panel sends to the API. Check it out:
private static ushort[] CalculateLUT(double brightness = 0.5, double contrast = 0.5, double gamma = 1) { const int dataPoints = 256; // Limit gamma in range [0.4-2.8] gamma = Math.Min(Math.Max(gamma, 0.4), 2.8); // Normalize contrast in range [-1,1] contrast = (Math.Min(Math.Max(contrast, 0), 1) - 0.5) * 2; // Normalize brightness in range [-1,1] brightness = (Math.Min(Math.Max(brightness, 0), 1) - 0.5) * 2; // Calculate curve offset resulted from contrast var offset = contrast > 0 ? contrast * -25.4 : contrast * -32; // Calculate the total range of curve var range = (dataPoints - 1) + offset * 2; // Add brightness to the curve offset offset += brightness * (range / 5); // Fill the gamma curve var result = new ushort[dataPoints]; for (var i = 0; i < result.Length; i++) { var factor = (i + offset) / range; factor = Math.Pow(factor, 1 / gamma); factor = Math.Min(Math.Max(factor, 0), 1); result[i] = (ushort)Math.Round(factor * ushort.MaxValue); } return result; }
This code saved my day! Brilliant! Thanks.
from nvapiwrapper.
When I use the above code along with SetDeviceGammaRamp() function, it tries to change the display momentarily and then reverts back. I think it might be due to the way I am accessing the display handle or something else but not because of the CalculateLUT() function. Can you see what is the problem?
`
public class Win32
{
// Get Display control
[DllImport("user32")]
public static extern IntPtr GetDC(IntPtr hWnd);
// Get Display control
[DllImport("user32")]
public static extern IntPtr ReleaseDC(IntPtr n, IntPtr hWnd);
// Ramp function
[DllImport("gdi32")]
public static extern bool GetDeviceGammaRamp(IntPtr hDC, [Out] ushort[] lpRamp);
[DllImport("gdi32")]
public static extern bool GetGammaRamp(IntPtr hDC, [Out] ushort[] lpRamp);
[DllImport("gdi32")]
public static extern bool SetDeviceGammaRamp(IntPtr hDC, ushort[] lpRamp);
[DllImport("gdi32")]
public static extern bool SetGammaRamp(IntPtr hDC, ushort[] lpRamp);
[DllImport("gdi32")]
public static extern bool SupportsFullscreenGamma();
public static IntPtr hDC;
public static ushort[] originalRamps;
}
class Program
{
// Color Matchingg dictionary
static void Main(string[] args)
{
// Control the display brightness, contrast and gamma
ushort[] newValues = CalculateLUT(0.1, 0.4, 1.1);
Win32.hDC = Win32.GetDC(IntPtr.Zero);
Win32.originalRamps = new ushort[256];
Win32.GetDeviceGammaRamp(Win32.hDC, Win32.originalRamps);
// Change the brightness, gamma and contrast
Win32.SetDeviceGammaRamp(Win32.hDC, newValues);
Win32.ReleaseDC(IntPtr.Zero, Win32.hDC);
}
}`
from nvapiwrapper.
My WindowsDisplayAPI library can be used to get information about monitors and manipulate their config including the GammaRamp. Take a look. You are probably interested in Display.GamaRamp
property.
from nvapiwrapper.
Great! It worked, Thanks. I also want to extract the current values for brightness, contrast, gamma for the display. Is there any property in the API for this?
Can gamma ramp values be decomposed some way to get these values?
from nvapiwrapper.
No, unfortunately, the algorithm used is one way. NVidia control panel keeps the raw values in the registry for UI porpuses, otherwise guessing the values from the ramp is not practical.
from nvapiwrapper.
My WindowsDisplayAPI library can be used to get information about monitors and manipulate their config including the GammaRamp. Take a look. You are probably interested in
Display.GamaRamp
property.
Hey, did the Diplay.GammaRamp Property and Display.IsPrimary() Method removed?
from nvapiwrapper.
@LikeyX no, but I think they are on the prerelease package.
from nvapiwrapper.
Related Issues (20)
- Add LED Control and Information Support HOT 1
- Set fan speed to automatic HOT 2
- Overclocking
- How to set custom resolution? HOT 7
- Available settings by display HOT 3
- Scale and layout settings HOT 1
- Reading EDID? HOT 2
- Accessing locations of each display in a Mosaic mode
- Recent nvidia GPU fans aren't able to be controlled HOT 3
- GPU sensor lost after driver update
- Geforce MX150 HOT 4
- Virtual custom resolution: reported and real refresh rate don't match HOT 4
- evga 3080 xc3 black inconsistent RPM
- SetThermalPoliciesStatus does not accept reduced values
- Unable to edit existing profiles of existing applications
- per process usage? HOT 2
- Issue with Intel A750 GPU HOT 1
- Change DSR Smoothnes factor HOT 1
- Compatibility with latest Nvidia drivers? (re: age of project?) HOT 1
- Which API can I use to modify the brightness, I can't seem to find it, can someone tell me? Thanks!~~~ HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvapiwrapper.