c++ - 如何在 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);
}
解决方案
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填充,它描述了可用的色彩空间、每个组件的位数、红/绿/蓝原色、白点以及设备上可用的亮度范围。
推荐阅读
- node.js - 使用 exceljs 并在解析大型 excel 文件时遇到内存泄漏
- javascript - ServiceNow 中的 JavaScript
- python-3.x - 来自 psycopg2 的 ExecuteMany 函数出错
- python - 如何根据具有重复值的列对熊猫中的值进行排序
- python - Selenium Python 单击没有 ID 的按钮
- python - Python 3、concurrent.futures.ProcessPoolExecutor 和 CEF 在达到池大小后崩溃
- debian - E: 软件包 'oracle-java8-installer' 在 Debian 上没有安装候选
- html - 拖动时如何更改书签名称
- python - 注意 OCR 创建数据集问题
- css - 不能为 Label 元素的子元素设置样式