Menu

Video, colour format

runningbug
2015-01-19
2015-01-19
  • runningbug

    runningbug - 2015-01-19

    Hi,

    I am trying to get video playback working in DirectX9 using the libtheoraplayer.

    The video is playing fine (performance is fantastic), except the colours are all wrong!

    I am loading the video clip with the theora output mode set to TH_XRGB. I therefore create a texture to paste this data to in DirectX with the flag D3DFMT_X8R8G8B8 specified.

    So I am assuming that TheoraPLayback lib will provide me with data: 4 bytes per pixel, the first byte we don't care about, then then Red, then the Green then the Blue.

    However, when I playback I get a weird colour effect, as though the pixel values I have been returned are wrong:

    img

    http://www.dropbox.com/s/4m754e8124luswz/libtheoraplayer.jpg

    Here is the code I am using to draw to the texture's surface: (texture of the format D3DFMT_X8R8G8B8)

    WritePixelData(unsigned char pixelData, int dataWidth, int dataHeight)
    {
    D3DLOCKED_RECT lockedRect;
    IDirect3DSurface9
    surface;
    _texture->GetSurfaceLevel(0, &surface);

    surface->LockRect(&lockedRect, 0, D3DLOCK_DISCARD);
    
    unsigned char *dst = (unsigned char*)lockedRect.pBits;
    
    for (int y = 0; y < dataHeight; y++)
    {
        memcpy(dst, pixelData, dataWidth * 4);
    
        dst += lockedRect.Pitch;
        pixelData += (dataWidth*4);
    }
    
    surface->UnlockRect();
    surface->Release();
    

    }

    I have obviously got the widths/strides etc correct as the video fills the texture exactly, but it seems the pixel colour information is wrong?

    Can anybody see if I am doing it wrong, or confirm that they have got video working with the same theora output mode and DirectX texture format I am trying to use?

    Thanks for any help!

     
  • Krešimir Špes

    Krešimir Špes - 2015-01-19

    Hi,

    just try using TH_XBGR, that's what I use in my projects on dx9. dx9 has some weird texture byte ordering...

     
  • runningbug

    runningbug - 2015-01-19

    Hi kspes,

    Thanks for the quick reply!

    I have tried to use TH_XBGR... my gfx card does not support D3DFMT_X8B8G8R8, only D3DFMT_A8R8G8B8 and D3DFMT_X8R8G8B8. So as a test I manually twizzled the colour values given from frame->getBuffer() like this just to see if that gave me the correctly coloured image:

    for (int y = 0; y < dataHeight; y++)
    {
    unsigned char* toTwizzle = pixelData;

        for (int i = 0; i < dataWidth; i++)
        {
            unsigned char temp = toTwizzle[1];
            toTwizzle[1] = toTwizzle[3];
            toTwizzle[3] = temp;
    
            toTwizzle += 4;
        }
    
        memcpy(dst, pixelData, dataWidth * 4);
    
        dst += pitchInBytes;
        pixelData += (dataWidth*4);
    }
    

    But the colours are still wrong...

    The performance of the playback is fantastic, (hardly dents my FPS counter at all!). So I would really like to get it going... do you have any other ideas?

    Cheers for any help!

     

    Last edit: runningbug 2015-01-19
  • runningbug

    runningbug - 2015-01-19

    Hi,

    I have sorted this. It was a problem my end... I was using TH_XRGB when I meant to use TH_BGRX!

    Thanks for your help.

     
  • Krešimir Špes

    Krešimir Špes - 2015-01-19

    oh yeah, that one :) that's why I made all those supported formats :)

    And yeah, part of why this library is so useful is because the video decoding is done in separate threads thus not incurring a noticeable penalty on your main thread's FPS. you will notice a speed decrease if you use a lot of videos (or large videos) or are on a single core CPU.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.