简体   繁体   English

如何在Windows中捕获HDR帧缓冲区?

[英]How to capture HDR framebuffer in Windows?

I use the following code to read the standard 8-bit framebuffer, however I need to read the 10-bit HDR framebuffer that's used for HDR content on my HDR monitor. 我使用以下代码来读取标准的8位帧缓冲区,但是我需要读取用于HDR监视器上的HDR内容的10位HDR帧缓冲区。

As far as I can tell, BI_RGB is the only relevant enum option. 据我所知, BI_RGB是唯一相关的枚举选项。 Here's what I have so far, which works for 8-bit channels: 这是我到目前为止所使用的,适用于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 has added HDR-related features to recent API updates, which use a new interface with the last digits. Direct3D已将HDR相关功能添加到最近的API更新中,这些更新使用带有最后数字的新接口。 To access them, you must first query their underlying objects. 要访问它们,必须首先查询其基础对象。

Example: 例:

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

You will be able to successfully compile this code only if you have sufficiently new version of Windows SDK installed. 只有安装了足够新版本的Windows SDK,才能成功编译此代码。 The code will execute successfully (as opposed to failing with an error code) only if the user has sufficiently new version of Windows 10. 仅当用户具有足够新版本的Windows 10时,代码才会成功执行(而不是使用错误代码失败)。

You can then query for monitor capabilities by calling function IDXGIOutput6::GetDesc1 . 然后,您可以通过调用函数IDXGIOutput6 :: GetDesc1来查询监视器功能。 You get structure DXGI_OUTPUT_DESC1 filled, which describes available color space, bits per component, red/green/blue primaries, white point, and the range of luminances available on the device. 您将获得结构DXGI_OUTPUT_DESC1 ,其中描述了可用的颜色空间,每个组件的位数,红色/绿色/蓝色原色,白点以及设备上可用的亮度范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM