【问题标题】:How to capture HDR framebuffer in Windows?如何在 Windows 中捕获 HDR 帧缓冲区?
【发布时间】:2019-06-27 19:35:09
【问题描述】:

我使用以下代码读取标准的 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);
}

【问题讨论】:

  • 在 Win 8 及更高版本中,您最好使用 Desktop Duplication API 来捕获桌面

标签: c++ windows winapi framebuffer hdr


【解决方案1】:

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 填充,它描述了可用的色彩空间、每个组件的位数、红/绿/蓝原色、白点以及设备上可用的亮度范围。

【讨论】:

  • 谢谢!一些事情:首先,我应该如何初始化IDXGIOutput? (我对 C++ 很陌生)。另外,是否可以使用这个来获取特定的像素值?
  • @RichardRobinson 很抱歉现在回复您。由于您是该领域的新手,因此我为您提供了一些示例。 github.com/Microsoft/Windows-universal-samples/tree/master/…
  • 用这种方法甚至可以得到每个像素的rgb分量吗?
  • @RichardRobinson 我没有尝试使用DirectX 来获取HDR 的特定像素值,但是根据目前的数据,DirectX 更多的是关于渲染颜色。可以参考directx的官方文档,里面展示了如何获取metadata结构体。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多