Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6070547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:56:45+00:00 2026-05-23T09:56:45+00:00

I’m writing a DX9 renderer and currently working on the ability to play AVI

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:56:45+00:00Added an answer on May 23, 2026 at 9:56 am

    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:

    // Retrieve a frame from the video data as a BITMAPINFOHEADER
    LPBITMAPINFOHEADER pBmpInfoHeader;
    m_pVideoData->GetVideoFrame(0, 0, &pBmpInfoHeader);
    
    // Get dimentions
    long nWidth = pBmpInfoHeader->biWidth;
    long nHeight = pBmpInfoHeader->biHeight;
    
    // Bitmap width correction (might not be needed...)
    if (nWidth % 4 != 0)
        nWidth = nWidth + (4 - nWidth%4);
    
    // Get Pixel data (should be after the header in memory)
    WORD bitCount = pBmpInfoHeader->biBitCount;
    DWORD size = nWidth * nHeight * bitCount/8;
    BYTE *pPixelSrc = (BYTE *)pBmpInfoHeader + sizeof(pBmpInfoHeader);
    
    // Lock the texture so we can write this frame's texel data
    D3DLOCKED_RECT lock;
    if(FAILED(m_pD3DTexture->LockRect(0, &lock, NULL, 0)))
    {
        m_pD3DTexture->UnlockRect(0);
        return;
    }
    
    int iNumBytesPerRowSrc = pBmpInfoHeader->biWidth * (pBmpInfoHeader->biBitCount/8);  
    int iNumBytesPerRowDst = lock.Pitch;
    int iNumBytesToCopyPerRow = min(iNumBytesPerRowSrc, iNumBytesPerRowDst);
    
    // Bitmap data is stored upside down
    // Start at the end and work backwards
    pPixelSrc += (iNumBytesPerRowSrc * nHeight);
    
    // Store a pointer to the texture pixel data and write new data
    BYTE* ucTexDst = (BYTE *)lock.pBits;
    for(int y = 0; y < nHeight; ++y)
    {
        pPixelSrc -= iNumBytesPerRowSrc;
        memcpy(ucTexDst, pPixelSrc, iNumBytesToCopyPerRow);
        ucTexDst += iNumBytesPerRowDst;
    }
    
    // Unlock texture so gfx card can resume its business
    m_pD3DTexture->UnlockRect(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
I am writing an app with both english and french support. The app requests
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.