Files
archived-g-helper/app/Display/ScreenControl.cs
2024-03-05 15:21:26 +01:00

299 lines
25 KiB
C#

using System.Diagnostics;
namespace GHelper.Display
{
enum VisualMode
{
Default,
Racing,
Scenery,
RPG,
FPS,
Cinema,
Eyecare,
Vivid
}
public class ScreenControl
{
public const int MAX_REFRESH = 1000;
public static int activeProfile = 0;
public static DisplayGammaRamp? gammaRamp;
private GammaRamp GetGamma(VisualMode mode)
{
ushort[] GammaR, GammaG, GammaB;
switch (mode)
{
case VisualMode.Racing:
GammaR = new ushort[] { 0, 256, 512, 768, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5888, 6144, 6400, 6656, 6912, 7168, 7424, 7680, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, 10496, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12288, 12544, 12800, 13056, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 15104, 15360, 15360, 15616, 15872, 16128, 16384, 16640, 16896, 17152, 17408, 17664, 17920, 18176, 18432, 18688, 18688, 18944, 19200, 19456, 19712, 19968, 20224, 20480, 20736, 20992, 21248, 21504, 21760, 22016, 22272, 22528, 22528, 22784, 23040, 23296, 23552, 23808, 24064, 24320, 24576, 24832, 25088, 25344, 25600, 25856, 26112, 26368, 26368, 26624, 26880, 27136, 27392, 27648, 27904, 28160, 28416, 28672, 28928, 29184, 29440, 29696, 29952, 30208, 30208, 30464, 30720, 30976, 31232, 31488, 31744, 32000, 32256, 32512, 32768, 33024, 33280, 33536, 33792, 34048, 34304, 34560, 34816, 35072, 35328, 35584, 35840, 36096, 36352, 36608, 36864, 37120, 37376, 37632, 37888, 38144, 38400, 38656, 38912, 39168, 39424, 39680, 39936, 40192, 40448, 40704, 40960, 41216, 41472, 41728, 41984, 42240, 42496, 42752, 43008, 43264, 43520, 43776, 44032, 44288, 44544, 44800, 45056, 45312, 45568, 45824, 46080, 46336, 46592, 46848, 47104, 47360, 47616, 47872, 48128, 48384, 48640, 48896, 49152, 49408, 49664, 49920, 50176, 50432, 50688, 50944, 51200, 51456, 51712, 51968, 52224, 52736, 52992, 53248, 53504, 53760, 54016, 54272, 54528, 54784, 55040, 55296, 55552, 55808, 56064, 56320, 56576, 56832, 57088, 57344, 57600, 57856, 58112, 58368, 58624, 59136, 59392, 59648, 59904, 60160, 60416, 60672, 60928, 61184, 61440, 61696, 61952, 62208, 62464, 62720, 62976, 63488, 63744, 64000, 64256, 64512, 64768, 65024, 65280};
GammaG = new ushort[] { 0, 256, 512, 768, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5888, 6144, 6400, 6656, 6912, 7168, 7424, 7680, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, 10496, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12288, 12544, 12800, 13056, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 15104, 15360, 15360, 15616, 15872, 16128, 16384, 16640, 16896, 17152, 17408, 17664, 17920, 18176, 18432, 18688, 18688, 18944, 19200, 19456, 19712, 19968, 20224, 20480, 20736, 20992, 21248, 21504, 21760, 22016, 22272, 22528, 22528, 22784, 23040, 23296, 23552, 23808, 24064, 24320, 24576, 24832, 25088, 25344, 25600, 25600, 25856, 26112, 26368, 26624, 26880, 27136, 27392, 27648, 27904, 28160, 28160, 28416, 28672, 28928, 29184, 29440, 29696, 29952, 30208, 30464, 30464, 30720, 30976, 31232, 31488, 31744, 32000, 32256, 32512, 32768, 33024, 33280, 33536, 33792, 34048, 34304, 34560, 34816, 35072, 35328, 35584, 35840, 36096, 36352, 36608, 36864, 37120, 37376, 37632, 37888, 38144, 38400, 38656, 38912, 39168, 39424, 39680, 39936, 40192, 40448, 40704, 40960, 41216, 41472, 41728, 41984, 41984, 42240, 42496, 42752, 43008, 43264, 43520, 43776, 44032, 44288, 44544, 44800, 45056, 45312, 45568, 45824, 45824, 46080, 46336, 46592, 46848, 47104, 47360, 47616, 47872, 48128, 48384, 48640, 48896, 49152, 49408, 49920, 50176, 50432, 50688, 50944, 51200, 51456, 51712, 51968, 52224, 52480, 52736, 52992, 53248, 53504, 53760, 54272, 54528, 54784, 55040, 55296, 55552, 55808, 56064, 56320, 56576, 56832, 57088, 57344, 57600, 57856, 58112, 58368, 58624, 58880, 59136, 59392, 59648, 59904, 60160, 60416, 60672, 60928, 61184, 61440, 61696, 61952, 62208, 62464, 62720, 62976, 63232, 63488, 63744, 64000, 64256};
GammaB = new ushort[] { 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400, 6656, 6912, 7168, 7424, 7680, 7936, 8192, 8448, 8704, 8960, 9216, 9216, 9472, 9728, 9984, 10240, 10496, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12032, 12288, 12544, 12800, 13056, 13312, 13312, 13568, 13824, 14080, 14336, 14592, 14592, 14848, 15104, 15360, 15616, 15872, 16128, 16384, 16640, 16640, 16896, 17152, 17408, 17664, 17920, 18176, 18432, 18688, 18944, 19200, 19200, 19456, 19712, 19968, 20224, 20480, 20736, 20992, 21248, 21504, 21504, 21760, 22016, 22272, 22528, 22784, 23040, 23296, 23552, 23808, 23808, 24064, 24320, 24576, 24832, 25088, 25344, 25600, 25600, 25856, 26112, 26368, 26624, 26880, 27136, 27392, 27392, 27648, 27904, 28160, 28416, 28672, 28928, 29184, 29184, 29440, 29696, 29952, 30208, 30464, 30720, 30976, 31232, 31232, 31488, 31744, 32000, 32256, 32512, 32768, 33024, 33280, 33536, 33792, 33792, 34048, 34304, 34560, 34816, 35072, 35328, 35584, 35840, 36096, 36096, 36352, 36608, 36864, 37120, 37376, 37632, 37888, 38144, 38400, 38656, 38912, 39168, 39424, 39424, 39680, 39936, 40192, 40448, 40704, 40960, 41216, 41472, 41728, 41984, 42240, 42496, 42752, 43008, 43264, 43264, 43520, 43776, 44032, 44288, 44544, 44800, 45056, 45312, 45568, 45824, 46080, 46336, 46592, 46848, 47104, 47104, 47360, 47616, 47872, 48128, 48384, 48640, 48896, 49152, 49408, 49664, 49920, 50176, 50432, 50688, 50944, 50944, 51200, 51456, 51712, 51968, 52224, 52480, 52736, 52992, 53248, 53504, 53760, 54016, 54272, 54528, 54784, 55040, 55296, 55552, 55808, 56064, 56320, 56576, 56576, 56832, 57088, 57344, 57600, 57856, 58112, 58368, 58624, 58880, 59136, 59392, 59648, 59904, 60160, 60416};
break;
case VisualMode.Scenery:
GammaR = new ushort[] { 7424, 7680, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, 10496, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12288, 12544, 12800, 13056, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 15104, 15360, 15360, 15616, 15872, 16128, 16384, 16640, 16896, 17152, 17408, 17664, 17920, 18176, 18432, 18688, 18688, 18944, 19200, 19456, 19712, 19968, 20224, 20480, 20736, 20992, 21248, 21504, 21760, 22016, 22272, 22528, 22528, 22784, 23040, 23296, 23552, 23808, 24064, 24320, 24576, 24832, 25088, 25344, 25600, 25856, 26112, 26368, 26368, 26624, 26880, 27136, 27392, 27648, 27904, 28160, 28416, 28672, 28928, 29184, 29440, 29696, 29952, 30208, 30208, 30464, 30720, 30976, 31232, 31488, 31744, 32000, 32256, 32512, 32768, 33024, 33280, 33536, 33792, 34048, 34304, 34560, 34816, 35072, 35328, 35584, 35840, 36096, 36352, 36608, 36864, 37120, 37376, 37632, 37888, 38144, 38400, 38656, 38912, 39168, 39424, 39680, 39936, 40192, 40448, 40704, 40960, 41216, 41472, 41728, 41984, 42240, 42496, 42752, 43008, 43264, 43520, 43776, 44032, 44288, 44544, 44800, 45056, 45312, 45568, 45824, 46080, 46336, 46592, 46848, 47104, 47360, 47616, 47872, 48128, 48384, 48640, 48896, 49152, 49408, 49664, 49920, 50176, 50432, 50688, 50944, 51200, 51456, 51712, 51968, 52224, 52736, 52992, 53248, 53504, 53760, 54016, 54272, 54528, 54784, 55040, 55296, 55552, 55808, 56064, 56320, 56576, 56832, 57088, 57344, 57600, 57856, 58112, 58624, 59136, 59392, 59648, 59904, 60160, 60416, 60672, 60928, 61184, 61440, 61696, 61952, 62208, 62464, 62720, 62976, 63488, 63744, 64000, 64256, 64512, 64768, 65024, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280, 65280};
GammaG = new ushort[] { 7424, 7680, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, 10496, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12288, 12544, 12800, 13056, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 15104, 15360, 15360, 15616, 15872, 16128, 16384, 16640, 16896, 17152, 17408, 17664, 17920, 18176, 18432, 18688, 18688, 18944, 19200, 19456, 19712, 19968, 20224, 20480, 20736, 20992, 21248, 21504, 21760, 22016, 22272, 22528, 22528, 22784, 23040, 23296, 23552, 23808, 24064, 24320, 24576, 24832, 25088, 25344, 25600, 25600, 25856, 26112, 26368, 26624, 26880, 27136, 27392, 27648, 27904, 28160, 28160, 28416, 28672, 28928, 29184, 29440, 29696, 29952, 30208, 30464, 30464, 30720, 30976, 31232, 31488, 31744, 32000, 32256, 32512, 32768, 33024, 33280, 33536, 33792, 34048, 34304, 34560, 34816, 35072, 35328, 35584, 35840, 36096, 36352, 36608, 36864, 37120, 37376, 37632, 37888, 38144, 38400, 38656, 38912, 39168, 39424, 39680, 39936, 40192, 40448, 40704, 40960, 41216, 41472, 41728, 41984, 42240, 42496, 42752, 43008, 43264, 43520, 43776, 44032, 44032, 44288, 44544, 44800, 45056, 45312, 45568, 45824, 46080, 46336, 46592, 46848, 47104, 47360, 47616, 47872, 48128, 48384, 48640, 48896, 49152, 49408, 49664, 49920, 50176, 50432, 50688, 50944, 51200, 51456, 51712, 52224, 52480, 52736, 52992, 53248, 53504, 53760, 54016, 54272, 54528, 54784, 55040, 55296, 55552, 55808, 56064, 56320, 56576, 56832, 57088, 57344, 57600, 58112, 58368, 58624, 58880, 59136, 59392, 59648, 59904, 60160, 60672, 60928, 61184, 61440, 61696, 61952, 62208, 62464, 62720, 62976, 63232, 63488, 63744, 64000, 64256, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512, 64512};
GammaB = new ushort[] { 6912, 7168, 7424, 7680, 7936, 8192, 8448, 8704, 8960, 9216, 9472, 9472, 9728, 9984, 10240, 10496, 10752, 11008, 11264, 11264, 11520, 11776, 12032, 12288, 12544, 12800, 13056, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 14848, 15104, 15360, 15616, 15872, 16128, 16384, 16640, 16896, 16896, 17152, 17408, 17664, 17920, 18176, 18432, 18688, 18944, 19200, 19456, 19456, 19712, 19968, 20224, 20480, 20736, 20992, 21248, 21504, 21760, 21760, 22016, 22272, 22528, 22784, 23040, 23296, 23552, 23808, 24064, 24064, 24320, 24576, 24832, 25088, 25344, 25600, 25856, 25856, 26112, 26368, 26624, 26880, 27136, 27392, 27648, 27648, 27904, 28160, 28416, 28672, 28928, 29184, 29440, 29440, 29696, 29952, 30208, 30464, 30720, 30976, 31232, 31488, 31488, 31744, 32000, 32256, 32512, 32768, 33024, 33280, 33536, 33792, 34048, 34048, 34304, 34560, 34816, 35072, 35328, 35584, 35840, 36096, 36352, 36352, 36608, 36864, 37120, 37376, 37632, 37888, 38144, 38400, 38656, 38912, 39168, 39424, 39680, 39936, 40192, 40448, 40704, 40960, 41216, 41472, 41728, 41728, 41984, 42240, 42496, 42752, 43008, 43264, 43520, 43776, 44032, 44288, 44544, 44800, 45056, 45312, 45568, 45824, 46080, 46336, 46592, 46848, 47104, 47360, 47616, 47872, 48128, 48384, 48640, 48896, 49152, 49408, 49664, 49664, 49920, 50176, 50432, 50688, 50944, 51200, 51456, 51712, 51968, 52224, 52480, 52736, 52992, 53248, 53504, 53760, 54016, 54272, 54528, 54784, 55296, 55296, 55552, 55808, 56064, 56320, 56576, 56832, 57088, 57344, 57600, 57856, 58112, 58368, 58624, 58880, 59136, 59136, 59392, 59648, 59904, 60160, 60416, 60672, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928, 60928};
break;
default:
GammaR = new ushort[] { 0, 256, 512, 768, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5888, 6144, 6400, 6656, 6912, 7168, 7424, 7680, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, 10496, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12288, 12544, 12800, 13056, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 15104, 15360, 15360, 15616, 15872, 16128, 16384, 16640, 16896, 17152, 17408, 17664, 17920, 18176, 18432, 18688, 18688, 18944, 19200, 19456, 19712, 19968, 20224, 20480, 20736, 20992, 21248, 21504, 21760, 22016, 22272, 22528, 22528, 22784, 23040, 23296, 23552, 23808, 24064, 24320, 24576, 24832, 25088, 25344, 25600, 25856, 26112, 26368, 26368, 26624, 26880, 27136, 27392, 27648, 27904, 28160, 28416, 28672, 28928, 29184, 29440, 29696, 29952, 30208, 30208, 30464, 30720, 30976, 31232, 31488, 31744, 32000, 32256, 32512, 32768, 33024, 33280, 33536, 33792, 34048, 34304, 34560, 34816, 35072, 35328, 35584, 35840, 36096, 36352, 36608, 36864, 37120, 37376, 37632, 37888, 38144, 38400, 38656, 38912, 39168, 39424, 39680, 39936, 40192, 40448, 40704, 40960, 41216, 41472, 41728, 41984, 42240, 42496, 42752, 43008, 43264, 43520, 43776, 44032, 44288, 44544, 44800, 45056, 45312, 45568, 45824, 46080, 46336, 46592, 46848, 47104, 47360, 47616, 47872, 48128, 48384, 48640, 48896, 49152, 49408, 49664, 49920, 50176, 50432, 50688, 50944, 51200, 51456, 51712, 51968, 52224, 52736, 52992, 53248, 53504, 53760, 54016, 54272, 54528, 54784, 55040, 55296, 55552, 55808, 56064, 56320, 56576, 56832, 57088, 57344, 57600, 57856, 58112, 58368, 58624, 59136, 59392, 59648, 59904, 60160, 60416, 60672, 60928, 61184, 61440, 61696, 61952, 62208, 62464, 62720, 62976, 63488, 63744, 64000, 64256, 64512, 64768, 65024, 65280 };
GammaG = new ushort[] { 0, 256, 512, 768, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3584, 3840, 4096, 4352, 4608, 4864, 5120, 5376, 5888, 6144, 6400, 6656, 6912, 7168, 7424, 7680, 8192, 8448, 8704, 8960, 9216, 9472, 9728, 9984, 10240, 10496, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12288, 12544, 12800, 13056, 13056, 13312, 13568, 13824, 14080, 14336, 14592, 14848, 15104, 15360, 15360, 15616, 15872, 16128, 16384, 16640, 16896, 17152, 17408, 17664, 17920, 18176, 18432, 18688, 18688, 18944, 19200, 19456, 19712, 19968, 20224, 20480, 20736, 20992, 21248, 21504, 21760, 22016, 22272, 22528, 22528, 22784, 23040, 23296, 23552, 23808, 24064, 24320, 24576, 24832, 25088, 25344, 25600, 25600, 25856, 26112, 26368, 26624, 26880, 27136, 27392, 27648, 27904, 28160, 28160, 28416, 28672, 28928, 29184, 29440, 29696, 29952, 30208, 30464, 30464, 30720, 30976, 31232, 31488, 31744, 32000, 32256, 32512, 32768, 33024, 33280, 33536, 33792, 34048, 34304, 34560, 34816, 35072, 35328, 35584, 35840, 36096, 36352, 36608, 36864, 37120, 37376, 37632, 37888, 38144, 38400, 38656, 38912, 39168, 39424, 39680, 39936, 40192, 40448, 40704, 40960, 41216, 41472, 41728, 41984, 41984, 42240, 42496, 42752, 43008, 43264, 43520, 43776, 44032, 44288, 44544, 44800, 45056, 45312, 45568, 45824, 45824, 46080, 46336, 46592, 46848, 47104, 47360, 47616, 47872, 48128, 48384, 48640, 48896, 49152, 49408, 49920, 50176, 50432, 50688, 50944, 51200, 51456, 51712, 51968, 52224, 52480, 52736, 52992, 53248, 53504, 53760, 54272, 54528, 54784, 55040, 55296, 55552, 55808, 56064, 56320, 56576, 56832, 57088, 57344, 57600, 57856, 58112, 58368, 58624, 58880, 59136, 59392, 59648, 59904, 60160, 60416, 60672, 60928, 61184, 61440, 61696, 61952, 62208, 62464, 62720, 62976, 63232, 63488, 63744, 64000, 64256 };
GammaB = new ushort[] { 0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304, 2560, 2816, 3072, 3328, 3584, 3840, 4352, 4608, 4864, 5120, 5376, 5632, 5888, 6144, 6400, 6656, 6912, 7168, 7424, 7680, 7936, 8192, 8448, 8704, 8960, 9216, 9216, 9472, 9728, 9984, 10240, 10496, 10496, 10752, 11008, 11264, 11520, 11776, 12032, 12032, 12288, 12544, 12800, 13056, 13312, 13312, 13568, 13824, 14080, 14336, 14592, 14592, 14848, 15104, 15360, 15616, 15872, 16128, 16384, 16640, 16640, 16896, 17152, 17408, 17664, 17920, 18176, 18432, 18688, 18944, 19200, 19200, 19456, 19712, 19968, 20224, 20480, 20736, 20992, 21248, 21504, 21504, 21760, 22016, 22272, 22528, 22784, 23040, 23296, 23552, 23808, 23808, 24064, 24320, 24576, 24832, 25088, 25344, 25600, 25600, 25856, 26112, 26368, 26624, 26880, 27136, 27392, 27392, 27648, 27904, 28160, 28416, 28672, 28928, 29184, 29184, 29440, 29696, 29952, 30208, 30464, 30720, 30976, 31232, 31232, 31488, 31744, 32000, 32256, 32512, 32768, 33024, 33280, 33536, 33792, 33792, 34048, 34304, 34560, 34816, 35072, 35328, 35584, 35840, 36096, 36096, 36352, 36608, 36864, 37120, 37376, 37632, 37888, 38144, 38400, 38656, 38912, 39168, 39424, 39424, 39680, 39936, 40192, 40448, 40704, 40960, 41216, 41472, 41728, 41984, 42240, 42496, 42752, 43008, 43264, 43264, 43520, 43776, 44032, 44288, 44544, 44800, 45056, 45312, 45568, 45824, 46080, 46336, 46592, 46848, 47104, 47104, 47360, 47616, 47872, 48128, 48384, 48640, 48896, 49152, 49408, 49664, 49920, 50176, 50432, 50688, 50944, 50944, 51200, 51456, 51712, 51968, 52224, 52480, 52736, 52992, 53248, 53504, 53760, 54016, 54272, 54528, 54784, 55040, 55296, 55552, 55808, 56064, 56320, 56576, 56576, 56832, 57088, 57344, 57600, 57856, 58112, 58368, 58624, 58880, 59136, 59392, 59648, 59904, 60160, 60416 };
break;
}
return new GammaRamp(GammaR, GammaG, GammaB);
}
public void AutoScreen(bool force = false)
{
if (force || AppConfig.Is("screen_auto"))
{
if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)
SetScreen(MAX_REFRESH, 1);
else
SetScreen(60, 0);
}
else
{
SetScreen(overdrive: AppConfig.Get("overdrive"));
}
}
public bool GetSRGB()
{
var screenName = ScreenNative.FindLaptopScreen();
if (screenName is null) return false;
bool userProfiles = CCD.GetUsePerUserDisplayProfiles(screenName);
var defaultProfile = CCD.GetDisplayDefaultColorProfile(screenName);
return defaultProfile is not null && defaultProfile.ToLower().Contains("srgb") && userProfiles;
}
public void ToggleSRGB()
{
var screenName = ScreenNative.FindLaptopScreen();
if (screenName is null) return;
bool userProfiles = CCD.GetUsePerUserDisplayProfiles(screenName);
if (!userProfiles) CCD.SetUsePerUserDisplayProfiles(screenName, true);
var profiles = CCD.GetDisplayColorProfiles(screenName);
var defaultProfile = CCD.GetDisplayDefaultColorProfile(screenName);
Debug.WriteLine($"Default Profile {screenName}: {defaultProfile}");
bool isSRGB = defaultProfile is not null && defaultProfile.ToLower().Contains("srgb") && userProfiles;
bool changed = false;
foreach (var profile in profiles)
{
Debug.WriteLine(profile);
if (!changed && !isSRGB && profile.ToLower().Contains("srgb"))
{
CCD.SetDisplayDefaultColorProfile(screenName, profile);
changed = true;
}
if (!changed && isSRGB && !profile.ToLower().Contains("srgb"))
{
CCD.SetDisplayDefaultColorProfile(screenName, profile);
changed = true;
}
}
if (!changed)
{
if (isSRGB) CCD.SetUsePerUserDisplayProfiles(screenName, false);
else
{
var profile = Application.StartupPath + "ASUS_sRGB.icm";
CCD.AddDisplayColorProfile(screenName, profile, true, false);
}
}
//var colorparams = CCD.GetColorParams(screenName);
//Debug.WriteLine($"{colorparams.MaxLuminance} = {colorparams.RedPointX},{colorparams.RedPointY} {colorparams.GreenPointX},{colorparams.GreenPointY} {colorparams.BluePointX},{colorparams.BluePointY}");
//CCD.SetMinMaxLuminance(0, 0.6, 0.6, screenName);
}
public void SetBrightness(int brightness = -1)
{
if (!AppConfig.IsOLED()) return;
if (brightness >= 0) AppConfig.Set("brightness", brightness);
else brightness = AppConfig.Get("brightness");
if (brightness >= 0) SetGamma(brightness);
}
public void SetGamma(int brightness = 100)
{
var bright = Math.Round((float)brightness / 200 + 0.5, 2);
var screenName = ScreenNative.FindLaptopScreen();
if (screenName is null) return;
try
{
var handle = ScreenNative.CreateDC(screenName, screenName, null, IntPtr.Zero);
if (true || gammaRamp is null)
{
var gammaDump = new GammaRamp();
if (ScreenNative.GetDeviceGammaRamp(handle, ref gammaDump))
{
gammaRamp = new DisplayGammaRamp(gammaDump);
Logger.WriteLine("GammaR = {" + string.Join(", ", gammaRamp.Red) + "};");
Logger.WriteLine("GammaG = {" + string.Join(", ", gammaRamp.Green) + "};");
Logger.WriteLine("GammaB = {" + string.Join(", ", gammaRamp.Blue) + "};");
}
}
return;
if (gammaRamp is null || !gammaRamp.IsOriginal())
{
Logger.WriteLine("Not default Gamma");
gammaRamp = new DisplayGammaRamp();
}
var ramp = gammaRamp.AsBrightnessRamp(bright);
bool result = ScreenNative.SetDeviceGammaRamp(handle, ref ramp);
Logger.WriteLine("Brightness " + bright.ToString() + ": " + result);
}
catch (Exception ex)
{
Logger.WriteLine(ex.ToString());
}
//ScreenBrightness.Set(60 + (int)(40 * bright));
}
public void SetScreen(int frequency = -1, int overdrive = -1, int miniled = -1)
{
var laptopScreen = ScreenNative.FindLaptopScreen(true);
if (laptopScreen is null) return;
if (ScreenNative.GetRefreshRate(laptopScreen) < 0) return;
if (frequency >= MAX_REFRESH)
{
frequency = ScreenNative.GetMaxRefreshRate(laptopScreen);
}
if (frequency > 0)
{
ScreenNative.SetRefreshRate(laptopScreen, frequency);
}
if (overdrive >= 0)
{
if (AppConfig.Get("no_overdrive") == 1) overdrive = 0;
Program.acpi.DeviceSet(AsusACPI.ScreenOverdrive, overdrive, "ScreenOverdrive");
}
if (miniled >= 0)
{
if (Program.acpi.DeviceGet(AsusACPI.ScreenMiniled1) >= 0)
Program.acpi.DeviceSet(AsusACPI.ScreenMiniled1, miniled, "Miniled1");
else
Program.acpi.DeviceSet(AsusACPI.ScreenMiniled2, miniled, "Miniled2");
}
InitScreen();
}
public int ToogleMiniled()
{
int miniled1 = Program.acpi.DeviceGet(AsusACPI.ScreenMiniled1);
int miniled2 = Program.acpi.DeviceGet(AsusACPI.ScreenMiniled2);
Logger.WriteLine($"MiniledToggle: {miniled1} {miniled2}");
int miniled;
if (miniled1 >= 0)
{
miniled = (miniled1 == 1) ? 0 : 1;
}
else
{
switch (miniled2)
{
case 1: miniled = 2; break;
case 2: miniled = 0; break;
default: miniled = 1; break;
}
}
AppConfig.Set("miniled", miniled);
SetScreen(-1, -1, miniled);
return miniled;
}
public void InitScreen()
{
var laptopScreen = ScreenNative.FindLaptopScreen();
int frequency = ScreenNative.GetRefreshRate(laptopScreen);
int maxFrequency = ScreenNative.GetMaxRefreshRate(laptopScreen);
bool screenAuto = AppConfig.Is("screen_auto");
bool overdriveSetting = !AppConfig.Is("no_overdrive");
int overdrive = Program.acpi.DeviceGet(AsusACPI.ScreenOverdrive);
int miniled1 = Program.acpi.DeviceGet(AsusACPI.ScreenMiniled1);
int miniled2 = Program.acpi.DeviceGet(AsusACPI.ScreenMiniled2);
int miniled = (miniled1 >= 0) ? miniled1 : miniled2;
bool hdr = false;
if (miniled >= 0)
{
Logger.WriteLine($"Miniled: {miniled1} {miniled2}");
AppConfig.Set("miniled", miniled);
hdr = ScreenCCD.GetHDRStatus();
}
bool screenEnabled = (frequency >= 0);
AppConfig.Set("frequency", frequency);
AppConfig.Set("overdrive", overdrive);
Program.settingsForm.Invoke(delegate
{
Program.settingsForm.VisualiseScreen(
screenEnabled: screenEnabled,
screenAuto: screenAuto,
frequency: frequency,
maxFrequency: maxFrequency,
overdrive: overdrive,
overdriveSetting: overdriveSetting,
miniled1: miniled1,
miniled2: miniled2,
hdr: hdr
);
});
}
}
}