源碼【VS2019可直接運(yùn)行】
#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
該輸出表示色域坐標(biāo)為:R(0.6846 0.3096) G(0.2695 0.6602) B(0.1504 0.0596) W(0.3135 0.3291)
最低亮度為0.5捂龄,最高亮度為270予颤,對比度約為540,這么差尝苇?愧旦?[存疑]
我們查資料發(fā)現(xiàn)和P3-D65非常接近世剖,事實(shí)也確實(shí)如此(P3-D65色品坐標(biāo)如下圖)
outputDesc1.ColorSpace 這個(gè)值表示當(dāng)前所在的色彩空間,我這邊運(yùn)行下來是這個(gè)DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709笤虫,無論通過顯示器如何調(diào)節(jié)顯示色域旁瘫,或者更改windows顯示器色彩管理的一直打印的是這個(gè),所以我覺得這個(gè)值的參考性不是很好琼蚯。