将 BITMAPINFOHEADER 图像数据写入 IDirect3DTexture9
我正在编写 DX9 渲染器,目前正在研究播放 AVI 电影文件的功能。我已经能够使用 AVIStreamGetFrame() 检索任何指定的帧,它返回打包的 DIB,并且从那里我希望能够将该位图数据复制到已经存在的 IDirect3DTexture9 * 。
我的问题是缺乏对位图文件格式的理解,也不知道如何将从 BITMAPINFOHEADER
给出的像素数据转换为 IDirect3DTexture9
可以解释的格式。
我首先像这样创建 DX9 纹理:
LPBITMAPINFO bmpInfo = m_pVideoData->GetVideoFormat();
D3DXCreateTexture(LtGEngine::GetInstance()->GetDevice(),
bmpInfo->bmiHeader.biWidth,
bmpInfo->bmiHeader.biHeight,
D3DX_DEFAULT,
0,
D3DFMT_A8R8G8B8, // <- DETERMINE HOW?
D3DPOOL_MANAGED, // <- OR D3DPOOL_SYSTEMMEM?
&m_pD3DTexture);
我在这里遇到的问题在上面的评论中列出。当我获得 BITMAPINFO 时,例如它读取 bmpInfo.bmiHeader.biBitCount = 8 (或 16 等),这是否意味着我需要相应地更改 D3DFMT_* ?
稍后,当我获得要渲染的帧的 LPBITMAPINFOHEADER 时,我不知道如何处理从 IDirect3DTexture9::LockRect( ) 函数。这是我到目前为止所得到的:
// Retrieve a frame from the video data as a BITMAPINFOHEADER
LPBITMAPINFOHEADER pBmpInfoHeader;
m_pVideoData->GetVideoFrame(0, 0, &pBmpInfoHeader);
D3DLOCKED_RECT rect;
if(FAILED(m_pD3DTexture->LockRect(0, &rect, NULL, 0)))
{
m_pD3DTexture->UnlockRect(0);
}
DWORD* pDest = (DWORD*)rect.pBits;
// Now what to copy from pBmpInfoHeader?
是否有任何我没有见过的 API 调用可以为我执行此操作?或者有谁知道比这更简单的方法?感谢您的阅读/帮助。
I'm writing a DX9 renderer and currently working on the ability to play AVI movie files. I've been able to retrieve any specified frame using AVIStreamGetFrame()
, which returns a packed DIB, and from there I want to be able to copy that bitmap data to an already existing IDirect3DTexture9 *
.
My issue is a lack of understanding of the bitmap file format and knowing how to convert the pixel data given from a BITMAPINFOHEADER
to a format that IDirect3DTexture9
can interpret.
I first create my DX9 texture like this:
LPBITMAPINFO bmpInfo = m_pVideoData->GetVideoFormat();
D3DXCreateTexture(LtGEngine::GetInstance()->GetDevice(),
bmpInfo->bmiHeader.biWidth,
bmpInfo->bmiHeader.biHeight,
D3DX_DEFAULT,
0,
D3DFMT_A8R8G8B8, // <- DETERMINE HOW?
D3DPOOL_MANAGED, // <- OR D3DPOOL_SYSTEMMEM?
&m_pD3DTexture);
Questions I have here are listed as comments above. When I get the BITMAPINFO and for instance it reads bmpInfo.bmiHeader.biBitCount = 8 (or 16, etc.) does this mean I need to change the D3DFMT_* accordingly?
Later on when I get a LPBITMAPINFOHEADER
for the frame I want to render, I'm lost on what to do with pBits
returned from the IDirect3DTexture9::LockRect()
function. Here is what I have so far:
// Retrieve a frame from the video data as a BITMAPINFOHEADER
LPBITMAPINFOHEADER pBmpInfoHeader;
m_pVideoData->GetVideoFrame(0, 0, &pBmpInfoHeader);
D3DLOCKED_RECT rect;
if(FAILED(m_pD3DTexture->LockRect(0, &rect, NULL, 0)))
{
m_pD3DTexture->UnlockRect(0);
}
DWORD* pDest = (DWORD*)rect.pBits;
// Now what to copy from pBmpInfoHeader?
Are there any API calls that do this for me that I haven't seen? Or does anyone know of an easier way than this? Thanks for reading/helping.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以开始工作了!
需要考虑的几个注意事项。我的 AVI 文件(在本例中为单帧/位图)采用 16 位格式,因此我必须使用 D3DFMT_X1R5G5B5 创建目标纹理。另外,位图存储颠倒,因此我必须反转指针并向后读取每一行。
这是代码:
Got it to work!
Couple notes to consider. My AVI file (a single frame/bitmap in this case) was in a 16 bit format, therefore I had to create my destination texture with D3DFMT_X1R5G5B5. Also, bitmaps are stored upside down, so I had to reverse my pointer and read each row backwards.
Here's the code: