using System.Runtime.InteropServices;
using NvAPIWrapper.Native.Helpers;
namespace NvAPIWrapper.Native.Display.Structures
{
///
/// Contains info-frame video information
///
[StructLayout(LayoutKind.Explicit, Pack = 8)]
public struct InfoFrameVideo
{
[FieldOffset(0)] private readonly uint _WordAt0;
[FieldOffset(4)] private readonly uint _WordAt4;
[FieldOffset(8)] private readonly uint _WordAt8;
[FieldOffset(12)] private readonly uint _WordAt12;
[FieldOffset(16)] private readonly uint _WordAt16;
[FieldOffset(20)] private readonly uint _WordAt20;
///
/// Creates an instance of .
///
/// The video identification code (VIC)
/// The video pixel repetition
/// The video color format
/// The video color space
/// The extended video color space
/// The RGB quantization configuration
/// The YCC quantization configuration
/// The video content mode
/// The video content type
/// The video scan information
/// A value indicating if the active format information is present
/// The active format aspect ratio
/// The picture aspect ratio
/// The non uniform picture scaling direction
/// The video bar information
/// The top bar value if not auto and present; otherwise null
/// The bottom bar value if not auto and present; otherwise null
/// The left bar value if not auto and present; otherwise null
/// The right bar value if not auto and present; otherwise null
public InfoFrameVideo(
byte videoIdentificationCode,
InfoFrameVideoPixelRepetition pixelRepetition,
InfoFrameVideoColorFormat colorFormat,
InfoFrameVideoColorimetry colorimetry,
InfoFrameVideoExtendedColorimetry extendedColorimetry,
InfoFrameVideoRGBQuantization rgbQuantization,
InfoFrameVideoYCCQuantization yccQuantization,
InfoFrameVideoITC contentMode,
InfoFrameVideoContentType contentType,
InfoFrameVideoScanInfo scanInfo,
InfoFrameBoolean isActiveFormatInfoPresent,
InfoFrameVideoAspectRatioActivePortion activeFormatAspectRatio,
InfoFrameVideoAspectRatioCodedFrame pictureAspectRatio,
InfoFrameVideoNonUniformPictureScaling nonUniformPictureScaling,
InfoFrameVideoBarData barInfo,
uint? topBar,
uint? bottomBar,
uint? leftBar,
uint? rightBar
)
{
_WordAt0 = 0u
.SetBits(0, 8, videoIdentificationCode)
.SetBits(8, 5, (uint) pixelRepetition)
.SetBits(13, 3, (uint) colorFormat)
.SetBits(16, 3, (uint) colorimetry)
.SetBits(19, 4, (uint) extendedColorimetry)
.SetBits(23, 3, (uint) rgbQuantization)
.SetBits(26, 3, (uint) yccQuantization)
.SetBits(29, 2, (uint) contentMode);
_WordAt4 = 0u
.SetBits(0, 3, (uint) contentType)
.SetBits(3, 3, (uint) scanInfo)
.SetBits(6, 2, (uint) isActiveFormatInfoPresent)
.SetBits(8, 5, (uint) activeFormatAspectRatio)
.SetBits(13, 3, (uint) pictureAspectRatio)
.SetBits(16, 3, (uint) nonUniformPictureScaling)
.SetBits(19, 3, (uint) barInfo);
_WordAt8 = topBar == null ? 0x1FFFF : 0u.SetBits(0, 17, topBar.Value);
_WordAt12 = bottomBar == null ? 0x1FFFF : 0u.SetBits(0, 17, bottomBar.Value);
_WordAt16 = leftBar == null ? 0x1FFFF : 0u.SetBits(0, 17, leftBar.Value);
_WordAt20 = rightBar == null ? 0x1FFFF : 0u.SetBits(0, 17, rightBar.Value);
}
///
/// Gets the video identification code (VIC)
///
// ReSharper disable once ConvertToAutoProperty
public byte? VideoIdentificationCode
{
get
{
var value = (byte) _WordAt0.GetBits(0, 8);
if (value == 0xFF)
{
return null;
}
return value;
}
}
///
/// Gets the video pixel repetition
///
public InfoFrameVideoPixelRepetition PixelRepetition
{
get => (InfoFrameVideoPixelRepetition) _WordAt0.GetBits(8, 5);
}
///
/// Gets the video color format
///
public InfoFrameVideoColorFormat ColorFormat
{
get => (InfoFrameVideoColorFormat) _WordAt0.GetBits(13, 3);
}
///
/// Gets the video color space
///
public InfoFrameVideoColorimetry Colorimetry
{
get => (InfoFrameVideoColorimetry) _WordAt0.GetBits(16, 3);
}
///
/// Gets the extended video color space; only valid when ==
///
///
public InfoFrameVideoExtendedColorimetry? ExtendedColorimetry
{
get
{
if (Colorimetry != InfoFrameVideoColorimetry.UseExtendedColorimetry)
{
return null;
}
return (InfoFrameVideoExtendedColorimetry) _WordAt0.GetBits(19, 4);
}
}
///
/// Gets the RGB quantization configuration
///
public InfoFrameVideoRGBQuantization RGBQuantization
{
get => (InfoFrameVideoRGBQuantization) _WordAt0.GetBits(23, 3);
}
///
/// Gets the YCC quantization configuration
///
public InfoFrameVideoYCCQuantization YCCQuantization
{
get => (InfoFrameVideoYCCQuantization) _WordAt0.GetBits(26, 3);
}
///
/// Gets the video content mode
///
public InfoFrameVideoITC ContentMode
{
get => (InfoFrameVideoITC) _WordAt0.GetBits(29, 2);
}
///
/// Gets the video content type
///
public InfoFrameVideoContentType ContentType
{
get => (InfoFrameVideoContentType) _WordAt4.GetBits(0, 3);
}
///
/// Gets the video scan information
///
public InfoFrameVideoScanInfo ScanInfo
{
get => (InfoFrameVideoScanInfo) _WordAt4.GetBits(3, 3);
}
///
/// Gets a value indicating if the active format information is present
///
public InfoFrameBoolean IsActiveFormatInfoPresent
{
get => (InfoFrameBoolean) _WordAt4.GetBits(6, 2);
}
///
/// Gets the active format aspect ratio
///
public InfoFrameVideoAspectRatioActivePortion ActiveFormatAspectRatio
{
get => (InfoFrameVideoAspectRatioActivePortion) _WordAt4.GetBits(8, 5);
}
///
/// Gets the picture aspect ratio
///
public InfoFrameVideoAspectRatioCodedFrame PictureAspectRatio
{
get => (InfoFrameVideoAspectRatioCodedFrame) _WordAt4.GetBits(13, 3);
}
///
/// Gets the non uniform picture scaling direction
///
public InfoFrameVideoNonUniformPictureScaling NonUniformPictureScaling
{
get => (InfoFrameVideoNonUniformPictureScaling) _WordAt4.GetBits(16, 3);
}
///
/// Gets the video bar information
///
public InfoFrameVideoBarData BarInfo
{
get => (InfoFrameVideoBarData) _WordAt4.GetBits(19, 3);
}
///
/// Gets the top bar value if not auto and present; otherwise null
///
public uint? TopBar
{
get
{
if (BarInfo == InfoFrameVideoBarData.NotPresent || BarInfo == InfoFrameVideoBarData.Horizontal)
{
return null;
}
var val = _WordAt8.GetBits(0, 17);
if (val == 0x1FFFF)
{
return null;
}
return (uint) val;
}
}
///
/// Gets the bottom bar value if not auto and present; otherwise null
///
public uint? BottomBar
{
get
{
if (BarInfo == InfoFrameVideoBarData.NotPresent || BarInfo == InfoFrameVideoBarData.Horizontal)
{
return null;
}
var val = _WordAt12.GetBits(0, 17);
if (val == 0x1FFFF)
{
return null;
}
return (uint) val;
}
}
///
/// Gets the left bar value if not auto and present; otherwise null
///
public uint? LeftBar
{
get
{
if (BarInfo == InfoFrameVideoBarData.NotPresent || BarInfo == InfoFrameVideoBarData.Vertical)
{
return null;
}
var val = _WordAt16.GetBits(0, 17);
if (val == 0x1FFFF)
{
return null;
}
return (uint) val;
}
}
///
/// Gets the right bar value if not auto and present; otherwise null
///
public uint? RightBar
{
get
{
if (BarInfo == InfoFrameVideoBarData.NotPresent || BarInfo == InfoFrameVideoBarData.Vertical)
{
return null;
}
var val = _WordAt20.GetBits(0, 17);
if (val == 0x1FFFF)
{
return null;
}
return (uint) val;
}
}
}
}