mayingzhen / nvidia-texture-tools

Automatically exported from code.google.com/p/nvidia-texture-tools
Other
0 stars 0 forks source link

DirectDrawSurface::readBlock() issue #145

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I'm still trying to get a handle on C++ (coming from Objective-C & C), so I 
apologize if this turns out to be nothing.

I'm wondering if there might be a potential bug in 
DirectDrawSurface::readBlock(). For reference, here's the code I'm referring to:

----------------------------------------------------------------
void DirectDrawSurface::readBlock(ColorBlock * rgba)
{
    nvDebugCheck(stream != NULL);
    nvDebugCheck(rgba != NULL);

    uint fourcc = header.pf.fourcc;

    // Map DX10 block formats to fourcc codes.
    if (header.hasDX10Header())
    {
        if (header.header10.dxgiFormat == DXGI_FORMAT_BC1_UNORM) fourcc = FOURCC_DXT1;
        if (header.header10.dxgiFormat == DXGI_FORMAT_BC2_UNORM) fourcc = FOURCC_DXT3;
        if (header.header10.dxgiFormat == DXGI_FORMAT_BC3_UNORM) fourcc = FOURCC_DXT5;
        if (header.header10.dxgiFormat == DXGI_FORMAT_BC4_UNORM) fourcc = FOURCC_ATI1;
        if (header.header10.dxgiFormat == DXGI_FORMAT_BC5_UNORM) fourcc = FOURCC_ATI2;
    }

    if (fourcc == FOURCC_DXT1)
    {
        BlockDXT1 block;
        *stream << block;
        block.decodeBlock(rgba);
    }
    else if (fourcc == FOURCC_DXT2 ||
        header.pf.fourcc == FOURCC_DXT3)    //// notice "header.pf.fourcc" instead of "fourcc"
    {
        BlockDXT3 block;
        *stream << block;
        block.decodeBlock(rgba);
    }
    else if (fourcc == FOURCC_DXT4 ||
        header.pf.fourcc == FOURCC_DXT5 ||    //// notice "header.pf.fourcc" instead of "fourcc"
        header.pf.fourcc == FOURCC_RXGB)    //// notice "header.pf.fourcc" instead of "fourcc"
    {
        BlockDXT5 block;
        *stream << block;
        block.decodeBlock(rgba);
        ...........

----------------------------------------------------------------

What I'm wondering about are the 3 lines I marked with the comment. Am I right 
in thinking you probably want to use "fourcc" there instead of 
"header.pf.fourcc"?

Otherwise there could be a couple of cases that would slip through, so to 
speak. For example, if you had a DirectX 10 container dds file whose format was 
DXGI_FORMAT_BC3_UNORM (which is mapped to FOURCC_DXT5), then it wouldn't be 
caught by the "header.pf.fourcc == FOURCC_DXT5" (since, if I understand things 
correctly, in a DX10 file, header.pf.fourcc is, by definition, equal to 
FOURCC_DX10).

I've included a patch in case it should be changed.

Original issue reported on code.google.com by markdoum...@gmail.com on 21 Oct 2010 at 6:22

Attachments:

GoogleCodeExporter commented 8 years ago
Good catch! Thanks for the bug report, I'll fix it shortly.

Original comment by cast...@gmail.com on 21 Oct 2010 at 6:42

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r1168.

Original comment by cast...@gmail.com on 21 Oct 2010 at 6:58