WIC 位图处理最有效的像素格式是什么? [英] What is the most effective pixel format for WIC bitmap processing?

查看:43
本文介绍了WIC 位图处理最有效的像素格式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Direct2D 和 WIC 位图制作一个简单的视频播放器,例如程序.
它需要对 YUV 像素格式的帧数据进行快速且 CPU 经济的绘制(带拉伸).

I'm trying to make a simple video player like program with Direct2D and WIC Bitmap.
It requires fast and CPU economic drawing (with stretch) of YUV pixel format frame data.

我已经用 GDI 测试过了.我希望切换到 Direct2D 至少能带来 10 倍的性能提升(更小的 CPU 开销).

I've already tested with GDI. I hope switching to Direct2D give at least 10x performance gain (smaller CPU overhead).

我要做的基本上如下:

  1. 创建一个空的 WIC 位图 A(用于画布)
  2. 用YUV帧数据创建另一个WIC位图B(格式转换)
  3. 将位图 B 绘制到 A 上,然后将 A 绘制到 D2D 渲染目标

对于 1、2 步,我必须选择像素格式.
WIC 原生像素格式

For 1, 2 step, I must select a pixel format.
WIC Native Pixel Formats

有一个 MSDN 页面推荐 WICPixelFormat32bppPBGRA.
http://msdn.microsoft.com/en-us/library/windows/desktop/hh780393(v=vs.85).aspx

There is a MSDN page recommends WICPixelFormat32bppPBGRA.
http://msdn.microsoft.com/en-us/library/windows/desktop/hh780393(v=vs.85).aspx

WICPixelFormat32bppPBGRAWICPixelFormat32bppBGRA 有什么区别?(前者有附加P)

What's the difference WICPixelFormat32bppPBGRA and WICPixelFormat32bppBGRA? (former has additional P)

如果 WICPixelFormat32bppPBGRA 是要走的路,它总是这样吗?不管硬件和/或配置?

If WICPixelFormat32bppPBGRA is the way to go, is it always the case? Regardless hardware and/or configuration?

实际上,WIC 位图处理最有效的像素格式是什么?

What is the most effective pixel format for WIC bitmap processing actually?

推荐答案

遗憾的是,使用 Direct2D 1.1 或更低版本,您不能使用与 DXGI_FORMAT_B8G8R8A8_UNORM 不同的像素格式,后者等效于 WIC 的 WICPixelFormat32bppPBGRAem>(如果您在 D2D 中使用 D2D1_ALPHA_MODE_PREMULTIPLIED alpha 模式,则为P").

Unfortunately, using Direct2D 1.1 or lower, you cannot use pixelformat different from DXGI_FORMAT_B8G8R8A8_UNORM which is equivalent to WIC's WICPixelFormat32bppPBGRA ("P" is if you use D2D1_ALPHA_MODE_PREMULTIPLIED alpha mode in D2D).

如果您的目标操作系统是 Windows 8,那么您可以使用 Direct2D 的更新功能.据我所知,对 D2D 位图有某种 YUV 支持.(不,没有.RGB32 仍然是唯一支持的像素格式以及一些仅支持 alpha 的格式)

If your target OS in Windows 8 then you can use Direct2D's newer features. As far as I remember there is some kind of YUV support for D2D bitmaps. ( No, there is not. RGB32 remains the only pixelformat supported along with some alpha-only formats)

实际上对于 WIC 位图处理最有效的像素格式是什么?

What is the most effective pixel format for WIC bitmap processing actually?

我不确定如何衡量像素格式的有效性,但如果您想使用硬件加速,您应该使用 D2D 而不是 WIC 进行绘制,并且仅将 WIC 用于色彩空间转换.(顺便说一下,GDI 也是硬件加速的).

I'm not sure how to measure pixel format effectiveness, but if you want to use hardware acceleration you should draw using D2D instead of WIC, and use WIC only for colorspace conversion. (GDI is also hardware accelarated btw).

WICPixelFormat32bppPBGRA 和 WICPixelFormat32bppBGRA 有什么区别?(以前有附加P)

What's the difference WICPixelFormat32bppPBGRA and WICPixelFormat32bppBGRA? (former has additional P)

P 表示预乘 RGB 分量.(见这里)

P means that RGB components are premultiplied. (see here)

我要做的基本上如下:

  1. 创建一个空的 WIC 位图 A(用于画布)
  2. 使用 YUV 帧数据创建另一个 WIC 位图 B(格式转换)
  3. 将位图 B 绘制到 A 上,然后将 A 绘制到 D2D 渲染目标

如果您以性能为目标,则应尽量减少位图复制操作,还应避免使用 WIC 位图渲染目标,因为它使用软件渲染.如果您的播放器只渲染到一个窗口,您可以使用 HWND 呈现目标,或DeviceContext 与交换链(取决于您使用的 Direct2D 版本).

If you target for performance, you should minimize the bitmap copy operations, also you should avoid using WIC bitmap render target, because it is uses software rendering. If your player would only render to a window, you can use HWND render target, or DeviceContext with Swap Chain (depending of Direct2D version you use).

您可以使用 WIC 的软件像素格式转换功能(例如 IWICFormatConverter).另一种方法是使用 SIMD 操作编写(或查找)自定义转换例程.或者使用着色器在 GPU 端转换格式(色彩空间).但后两者需要高级知识.

Instead of rendering frame B to frame A, you can use software pixel format conversion featuers of WIC (e.g. IWICFormatConverter). Another way would be to write (or find) a custom conversion routine using SIMD operations. Or use shaders to convert the format (colorspace) on the GPU side. But the latter two require advanced knowledge.

转换后,您可以锁定像素以获取像素数据并将该数据直接复制到 D2D 位图 (ID2D1Bitmap::CopyFromMemory()).鉴于您已经准备好了 d2d 位图.

When it is converted you can lock the pixels to get the pixel data and directly copy that data to a D2D bitmap (ID2D1Bitmap::CopyFromMemory()). Given that you already have a ready d2d bitmap.

最后一步是将位图渲染到渲染目标.并且可以使用变换矩阵来实现拉伸.

And the last step would be to render the bitmap to the render target. And you can use transformation matrices to realize stretching.

这篇关于WIC 位图处理最有效的像素格式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆