What is the most efficient pixel format for handling a WIC bitmap?

I am trying to create a simple video player like a program with Direct2D and WIC Bitmap.
This requires a fast and economical drawing of a processor (stretched) YUV frame data.

I've already tested with GDI. Hopefully switching to Direct2D will give at least a 10x performance increase (lower CPU costs).

What will I do basically like below:

  • Create a blank WIC bitmap A (for canvas to draw)
  • Create another WIC bit-bit with YUV frame data (format conversion)
  • Draw a bitmap B to A, then paint A to the D2D render target.

For 1, 2 steps, I have to choose the pixel format.
Built-in WIC pixel formats

There is an MSDN page recommending WICPixelFormat32bppPBGRA

.
http://msdn.microsoft.com/en-us/library/windows/desktop/hh780393(v=vs.85).aspx

What's the difference WICPixelFormat32bppPBGRA

and WICPixelFormat32bppBGRA

? (the former has an extra P)

If WICPixelFormat32bppPBGRA

- the way, is it always so? Regardless of hardware and / or configuration?

What is the most efficient pixel format for handling a WIC bitmap?

+2


source to share


1 answer


Unfortunately, using Direct2D 1.1 or below, you cannot use pixelformat other than DXGI_FORMAT_B8G8R8A8_UNORM, which is the WIC equivalent of WICPixelFormat32bppPBGRA ("P" - if you are using D2D1_ALPHA_MODE_PREMULTIPLIED alpha mode) in D2D1_ALPHA_MODE_PREMULTIPLIED alpha mode

If your target OS is Windows 8, then you can use the new Direct2D features. As far as I remember there is some YUV support for D2D bitmaps. ( Edit: No, no. RGB32 remains the only pixel format supported alongside some alpha formats)

What is the most efficient pixel format for handling a WIC bitmap?

I'm not sure how to measure pixel efficiency of pixels, but if you want to use hardware acceleration, you should paint using D2D instead of WIC, and only use WIC for color space conversion. (GDI is also hardware accelerated btw).

What is the difference between WICPixelFormat32bppPBGRA and WICPixelFormat32bppBGRA? (former optional P)

P means RGB components are pre-multiplied. ( see here )



What will I do basically like below:

  • Create a blank WIC bitmap A (for canvas to draw)
  • Create another WIC bit-bit with YUV frame data (format conversion)
  • Draw a bitmap B to A, then paint A to the D2D render target.

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

Instead of frame B for frame A, you can use software pixel converters to convert the WIC (for example, IWICFormatConverter ). Another way would be to write (or find) a normal conversion routine using SIMD operations. Or use shaders to convert the format (color space) on the GPU side. But the last two require advanced knowledge.

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

And the last step is to render the bitmap for the render target. And you can use transformation matrices to implement stretching.

+5


source







All Articles