如何在Windows中捕获HDR Framebuffer

How to capture HDR framebuffer in Windows?

本文关键字:HDR Framebuffer Windows      更新时间:2023-10-16

我使用以下代码读取标准的8位Framebuffer,但是我需要读取用于HDR Monitor上HDR内容的10位HDR Framebuffer。

据我所知,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);
}

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填充,其中描述了可用的颜色空间,每个组件,红色/绿色/蓝色初选,白点以及设备上可用的亮度范围。