源码【VS2019可直接运行】
#include <iostream>
#include <windows.h>
#include <dxgi1_6.h>
#pragma comment(lib, "dxgi.lib")
int main() {
// Step 1: Create a DXGI factory
IDXGIFactory6* pFactory = nullptr;
HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&pFactory));
if (FAILED(hr)) {
std::cout << "Failed to create DXGI factory: " << std::hex << hr << std::endl;
return 1;
}
// Step 2: Enumerate the display adapters
IDXGIAdapter1* pAdapter = nullptr;
hr = pFactory->EnumAdapters1(0, &pAdapter);
if (FAILED(hr)) {
std::cout << "Failed to enumerate adapters: " << std::hex << hr << std::endl;
return 1;
}
// Step 3: Enumerate the outputs (display monitors)
IDXGIOutput* pOutput = nullptr;
hr = pAdapter->EnumOutputs(0, &pOutput);
if (FAILED(hr)) {
std::cout << "Failed to enumerate outputs: " << std::hex << hr << std::endl;
return 1;
}
// Step 4: Query IDXGIOutput6 interface
IDXGIOutput6* pOutput6 = nullptr;
hr = pOutput->QueryInterface(IID_PPV_ARGS(&pOutput6));
if (FAILED(hr)) {
std::cout << "Failed to query IDXGIOutput6 interface: " << std::hex << hr << std::endl;
return 1;
}
// Step 5: Get DXGI_OUTPUT_DESC1 structure
DXGI_OUTPUT_DESC1 outputDesc1;
hr = pOutput6->GetDesc1(&outputDesc1);
if (FAILED(hr)) {
std::cout << "Failed to get DXGI_OUTPUT_DESC1: " << std::hex << hr << std::endl;
return 1;
}
printf("R(%.4f %.4f) G(%.4f %.4f) B(%.4f %.4f) W(%.4f %.4f)\nLuminance:%.4f->%.4fcd/m2\n",
outputDesc1.RedPrimary[0], outputDesc1.RedPrimary[1],
outputDesc1.GreenPrimary[0], outputDesc1.GreenPrimary[1],
outputDesc1.BluePrimary[0], outputDesc1.BluePrimary[1],
outputDesc1.WhitePoint[0], outputDesc1.WhitePoint[1],
outputDesc1.MinLuminance, outputDesc1.MaxLuminance
);
std::cout << "Current Color Space: " << outputDesc1.ColorSpace << std::endl;
pOutput6->Release();
pOutput->Release();
pAdapter->Release();
pFactory->Release();
getchar();
return 0;
}
输出
R(0.6846 0.3096) G(0.2695 0.6602) B(0.1504 0.0596) W(0.3135 0.3291)
Luminance:0.5000->270.0000cd/m2
Current Color Space: 0
该输出表示色域坐标为:R(0.6846 0.3096) G(0.2695 0.6602) B(0.1504 0.0596) W(0.3135 0.3291)
最低亮度为0.5,最高亮度为270,对比度约为540,这么差??[存疑]
我们查资料发现和P3-D65非常接近,事实也确实如此(P3-D65色品坐标如下图)
image.png
outputDesc1.ColorSpace 这个值表示当前所在的色彩空间,我这边运行下来是这个DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709,无论通过显示器如何调节显示色域,或者更改windows显示器色彩管理的一直打印的是这个,所以我觉得这个值的参考性不是很好。
image.png
网友评论