首页 > 解决方案 > 如何在 Windows 中捕获 HDR 帧缓冲区?

问题描述

我使用以下代码读取标准的 8 位帧缓冲区,但是我需要读取用于 HDR 显示器上 HDR 内容的 10 位 HDR 帧缓冲区。

据我所知,BI_RGB是唯一相关的枚举选项。这是我目前所拥有的,适用于 8 位通道:

#include <iostream>
#include <windows.h>
#include <fstream>

void capture_screen() {
 int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
 int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);

 HWND hDesktopWnd = GetDesktopWindow();
 HDC hDesktopDC = GetDC(NULL);
 HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);

 HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, nScreenWidth, nScreenHeight);
 SelectObject(hCaptureDC, hCaptureBitmap);

 BitBlt(hCaptureDC, 0, 0, nScreenWidth, nScreenHeight, hDesktopDC, 0, 0, SRCCOPY | CAPTUREBLT);

 BITMAPINFO bmi = { 0 };

 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
 bmi.bmiHeader.biWidth = nScreenWidth;
 bmi.bmiHeader.biHeight = nScreenHeight;

 bmi.bmiHeader.biPlanes = 1;
 bmi.bmiHeader.biBitCount = 32;
 bmi.bmiHeader.biCompression = BI_RGB;

 auto* pPixels = new RGBQUAD[nScreenWidth * nScreenHeight];

 GetDIBits(hCaptureDC, hCaptureBitmap, 0,nScreenHeight, pPixels, &bmi, DIB_RGB_COLORS);

 //...               
 delete[] pPixels;

 ReleaseDC(hDesktopWnd, hDesktopDC);
 DeleteDC(hCaptureDC);
 DeleteObject(hCaptureBitmap);
}

标签: c++windowswinapiframebufferhdr

解决方案


Direct3D在最近的 API 更新中添加了与 HDR 相关的功能,这些更新使用带有最后一位数字的新界面。要访问它们,您必须首先查询它们的底层对象。

例子:

IDXGIOutput* output = /* initialize output */;
IDXGIOutput6* output6;
HRESULT hr = output->QueryInterface(__uuidof(IDXGIOutput6), (void**)&output6);
if(SUCCEEDED(hr)) {
    // Use output6...
    output6->Release();
} else {
    // Error!
}

只有安装了足够新版本的 Windows SDK,您才能成功编译此代码。只有当用户拥有足够新的 Windows 10 版本时,代码才会成功执行(而不是因为错误代码而失败)。

然后,您可以通过调用函数IDXGIOutput6::GetDesc1来查询监视器功能。你得到结构DXGI_OUTPUT_DESC1填充,它描述了可用的色彩空间、每个组件的位数、红/绿/蓝原色、白点以及设备上可用的亮度范围。


推荐阅读