Gamma Init

This commit is contained in:
Serge
2024-02-16 15:55:37 +01:00
parent 42a598f177
commit cf84fa0616
103 changed files with 7907 additions and 41 deletions

View File

@@ -0,0 +1,133 @@
using System.Runtime.InteropServices;
using WindowsDisplayAPI.Native.Structures;
namespace WindowsDisplayAPI.Native.DeviceContext.Structures
{
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd183565(v=vs.85).aspx
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
internal struct DeviceMode
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] [FieldOffset(0)]
public readonly string DeviceName;
[MarshalAs(UnmanagedType.U2)] [FieldOffset(32)]
public readonly ushort SpecificationVersion;
[MarshalAs(UnmanagedType.U2)] [FieldOffset(34)]
public readonly ushort DriverVersion;
[MarshalAs(UnmanagedType.U2)] [FieldOffset(36)]
public readonly ushort Size;
[MarshalAs(UnmanagedType.U2)] [FieldOffset(38)]
public readonly ushort DriverExtra;
[MarshalAs(UnmanagedType.U4)] [FieldOffset(40)]
public readonly DeviceModeFields Fields;
[MarshalAs(UnmanagedType.Struct)] [FieldOffset(44)]
public readonly PointL Position;
[MarshalAs(UnmanagedType.U4)] [FieldOffset(52)]
public readonly DisplayOrientation DisplayOrientation;
[MarshalAs(UnmanagedType.U4)] [FieldOffset(56)]
public readonly DisplayFixedOutput DisplayFixedOutput;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(60)]
public readonly short Color;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(62)]
public readonly short Duplex;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(64)]
public readonly short YResolution;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(66)]
public readonly short TrueTypeOption;
[MarshalAs(UnmanagedType.I2)] [FieldOffset(68)]
public readonly short Collate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] [FieldOffset(72)]
private readonly string FormName;
[MarshalAs(UnmanagedType.U2)] [FieldOffset(102)]
public readonly ushort LogicalInchPixels;
[MarshalAs(UnmanagedType.U4)] [FieldOffset(104)]
public readonly uint BitsPerPixel;
[MarshalAs(UnmanagedType.U4)] [FieldOffset(108)]
public readonly uint PixelsWidth;
[MarshalAs(UnmanagedType.U4)] [FieldOffset(112)]
public readonly uint PixelsHeight;
[MarshalAs(UnmanagedType.U4)] [FieldOffset(116)]
public readonly DisplayFlags DisplayFlags;
[MarshalAs(UnmanagedType.U4)] [FieldOffset(120)]
public readonly uint DisplayFrequency;
public DeviceMode(DeviceModeFields fields) : this()
{
SpecificationVersion = 0x0320;
Size = (ushort) Marshal.SizeOf(GetType());
Fields = fields;
}
public DeviceMode(string deviceName, DeviceModeFields fields) : this(fields)
{
DeviceName = deviceName;
}
public DeviceMode(
string deviceName,
PointL position,
DisplayOrientation orientation,
DisplayFixedOutput fixedOutput,
uint bpp,
uint width,
uint height,
DisplayFlags displayFlags,
uint displayFrequency) : this(
deviceName,
DeviceModeFields.Position |
DeviceModeFields.DisplayOrientation |
DeviceModeFields.DisplayFixedOutput |
DeviceModeFields.BitsPerPixel |
DeviceModeFields.PelsWidth |
DeviceModeFields.PelsHeight |
DeviceModeFields.DisplayFlags |
DeviceModeFields.DisplayFrequency
)
{
Position = position;
DisplayOrientation = orientation;
DisplayFixedOutput = fixedOutput;
BitsPerPixel = bpp;
PixelsWidth = width;
PixelsHeight = height;
DisplayFlags = displayFlags;
DisplayFrequency = displayFrequency;
}
public DeviceMode(string deviceName, PointL position, uint bpp, uint width, uint height, uint displayFrequency)
: this(
deviceName,
DeviceModeFields.Position |
DeviceModeFields.BitsPerPixel |
DeviceModeFields.PelsWidth |
DeviceModeFields.PelsHeight |
DeviceModeFields.DisplayFrequency
)
{
Position = position;
BitsPerPixel = bpp;
PixelsWidth = width;
PixelsHeight = height;
DisplayFrequency = displayFrequency;
}
}
}

View File

@@ -0,0 +1,32 @@
using System.Runtime.InteropServices;
namespace WindowsDisplayAPI.Native.DeviceContext.Structures
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct DisplayDevice
{
[MarshalAs(UnmanagedType.U4)] internal uint Size;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public readonly string DeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public readonly string DeviceString;
[MarshalAs(UnmanagedType.U4)] public readonly DisplayDeviceStateFlags StateFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public readonly string DeviceId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public readonly string DeviceKey;
public static DisplayDevice Initialize()
{
return new DisplayDevice
{
Size = (uint) Marshal.SizeOf(typeof(DisplayDevice))
};
}
}
}

View File

@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace WindowsDisplayAPI.Native.DeviceContext.Structures
{
[StructLayout(LayoutKind.Sequential)]
internal struct GammaRamp
{
public const int DataPoints = 256;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = DataPoints)]
public readonly ushort[] Red;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = DataPoints)]
public readonly ushort[] Green;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = DataPoints)]
public readonly ushort[] Blue;
public GammaRamp(ushort[] red, ushort[] green, ushort[] blue)
{
if (red == null)
{
throw new ArgumentNullException(nameof(red));
}
if (green == null)
{
throw new ArgumentNullException(nameof(green));
}
if (blue == null)
{
throw new ArgumentNullException(nameof(blue));
}
if (red.Length != DataPoints)
{
throw new ArgumentOutOfRangeException(nameof(red));
}
if (green.Length != DataPoints)
{
throw new ArgumentOutOfRangeException(nameof(green));
}
if (blue.Length != DataPoints)
{
throw new ArgumentOutOfRangeException(nameof(blue));
}
Red = red;
Green = green;
Blue = blue;
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using WindowsDisplayAPI.Native.Structures;
namespace WindowsDisplayAPI.Native.DeviceContext.Structures
{
[StructLayout(LayoutKind.Sequential)]
internal struct MonitorInfo
{
internal uint Size;
public readonly RectangleL Bounds;
public readonly RectangleL WorkingArea;
public readonly MonitorInfoFlags Flags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public readonly string DisplayName;
public static MonitorInfo Initialize()
{
return new MonitorInfo
{
Size = (uint)Marshal.SizeOf(typeof(MonitorInfo))
};
}
}
}