microsoft / DirectXTex

DirectXTex texture processing library
https://walbourn.github.io/directxtex/
MIT License
1.79k stars 441 forks source link

Texconv fails to read DXT compressed file #79

Closed JT8D-17 closed 6 years ago

JT8D-17 commented 6 years ago

When trying to read a DXT1/3/5 compressed texture file, Texconv shows the following error:

[filename] FAILED (88982f07)

The same error message also appears when tryng to read the file with Texdiag.

Converting the file to 32bit and then trying again works fine.

The file in question is attached below.

sample.zip

walbourn commented 6 years ago

That BMP is not supported by Windows Imaging Component (WIC). The HRESULT 88982f07 translates to "The image format is unknown." (You can look it up by using Visual Studio | Tools -> Error Lookup)

If you try viewing that BMP in the Windows Photo app, it also fails there.

What created that BMP file?

Trying my BMPDUMP tool I see:

BMP c:\Users\Chuck\Desktop\sample.bmp
        INFO header (40 bytes)
1024 x 1024
1 planes
16 bits
861165636 compression type
1048576 image size
0 x 0 pels per meter
0 colors used
0 colors important

Which is an examination of the file header (which is not a v4 or v5 header):

struct BITMAPINFOHEADER
{
    DWORD      biSize;
    LONG       biWidth;
    LONG       biHeight;
    WORD       biPlanes;
    WORD       biBitCount;
    DWORD      biCompression;
    DWORD      biSizeImage;
    LONG       biXPelsPerMeter;
    LONG       biYPelsPerMeter;
    DWORD      biClrUsed;
    DWORD      biClrImportant;
}

The biCompression type is not one of:

BI_RGB (0)
BI_RLE8 (1)
BI_RLE4 (2)
BI_BITFIELDS (3)
BI_JPEG (4)
BI_PNG (5)
JT8D-17 commented 6 years ago

Thanks for the reply. Yes, both image viewer apps delivered with Windows 10 fail to display it. This is normal. Nconvert, however, has no problems reading the file.

I'm not the original author of the file, so I can only make an assumption which tool was used to compress it. Since it's a texture for use in Microsoft Flight Simulator/Lockheed Martin Prepar3D, there's only two possibilites. Either ACES' ImageTool, shipped with the Flight Simulator SDK or DXTBMP. The latter is available here: http://www.mwgfx.co.uk/programs/dxtbmp.htm The former can't be obtained without installing the rest of the MSFS/P3D SDK, so I've attached it here for convienience. (May be deleted after the next reply by you or me.) (Attachment deleted 22/02/18)

Either tool fails to produce a Texconv compliant file when saving with BC1/DXT1 to BC3/DXT5 compression. Only files saved in 32bit by either tool is correctly read by Texconv.

When reading a 32bit file produced by ImageTool or DXTBMP, Texconv shows that it's read as B8G8R8X8_UNORM. Converting this file into R8B8G8A8_UNORM format (DDS filetype) again produces a file that can not be read by Imagetool. Only selecting B8G8R8A8_UNORM as output format produces a usable file. So I assume that ImageTool/DXTBMP saves files with a non-regular order of channels and that this is what throws WIC and Texconv off.

Hope this helps.

walbourn commented 6 years ago

OK, I now see what's happening here. Someone in the FlightSim team got clever and decided to containerize a DXTn texture in a BMP rather than used the long-established DDS format. It's not an officially supported way to write a DXTn, but I might be able to do something about that...

A few notes about the "FS70" BMP variant:

walbourn commented 6 years ago

I added support for loading these Extended BMP files, but I don't support writing them.

See this commit.

JT8D-17 commented 6 years ago

I would support writing to such a weird format either, to be honest. Reading these files is all I need and I'll check that feature out in the next release.

I've also edited my previous post to remove the attachment and iron out some mistakes. For example, I don't know why I stated that BCn compression produces files that are not Imagetool compliant. I've just checked the results from a batch texture conversion to BC2_UNORM (DXT3) DDS again and randomly picked samples opened in Imagetool just fine.

You're correct on the vertical flip requirement and yes, -vflip does the job.

Thank you for investigating and implementing this!

walbourn commented 6 years ago

I made a preview release that includes the new version of texconv if you'd like to try it out here

JT8D-17 commented 6 years ago

I've just tried a conversion using both the "exotic" input compression and the new aliases for the output format and got a good output file. Excellent work, thanks!