Closed FiftyTifty closed 8 years ago
You can't reliably parse a DDS file just by seeking to fixed offsets. You will need to understand the format and write proper parsing code to understand the various different header options that a file might contain.
You could look at the DirectXTex source code for an example of how to do this.
Alternatively, you could just call into the existing DirectXTex implementation. This is a C++ library, not C#, so you would have to make a managed -> native wrapper for it (for instance using C++/CLI).
Details of the DDS file format are covered on MSDN. There's also a little utility you can download and build for for C++ called ddsdump which can be useful for exploring the information in a DDS file--you need the dds.h header file from the DirectXTex library to build it.
DDS is a very primitive format, and it's little more than a binary dump of the memory layout used by the Direct3D runtime for system memory resources with a header prepended. All the details of exactly where the different surfaces are stored is implicit from the metadata in the format, which is a lot of what DirectXTex is built to compute.
Native code interop using the DirectXTex library is probably the easiest and most robust solution.
Damn, so there's not just some standard "DDS Format is @ Offset +xy"? Cor.
That DDS article o'er on Microsoft seems more like a refresher course for veterans that know this stuff, but for the completely fresh-faced infants like yours truly...It's pretty Greeky.
Same situation with allowing intractability between C++ & C# code. And aye, the documentation is not really even there; no explanations on how to actually modify existing code to use, err, native code interop. Best I could find were:
https://msdn.microsoft.com/en-us/library/ms173253.aspx https://msdn.microsoft.com/en-us/library/ms235282.aspx
The former is written by someone that worked for Ikea's manual department, and the latter is just "Here's code" with no actual explanation. And never mind that, I couldn't even get ddsdump to compile. Add it as an existing item to the DirectXTex project, compile 'n' VS throws this ol' error:
Warning 1 warning C4627: '#include
': skipped when looking for precompiled header use Warning 2 warning C4627: '#include ': skipped when looking for precompiled header use Warning 3 warning C4627: '#include ': skipped when looking for precompiled header use Warning 4 warning C4627: '#include "dds.h"': skipped when looking for precompiled header use Error 5 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "DirectXTexP.h"' to your source?
I take it that this is awfully low level, 'n' pretty damn impossible for me 'n' my 3 days worth of c# programmin' experience. There any decent, hand-holdy tutorials kicking about, that'd get me on my way to nabbing the texture format o' an existing dds file?
Hullo there!
For the past few days, I've been making me first foray into C# through making a program to resize modern .dds files en masse. Me initial intention was to gear it towards Fallout 4, but it's probably usable for all games, so long as ya have the right textures.
Anywho, I've hit a stump. I think texconv.exe wants me to give it the format for the output texture, as there's some blatant texture corruption (super colorful edges around transparent textures, for example) going on. Thing is, I don't know how to rip out the file format from the .dds header.
Now, I have been able to get the first & second texture dimensions (x and y respectively?), with the first being @ offset +0c and the second @ offset +10, both of them being two bytes in size. The number of mipmap levels is @ offset +1c, but that's about as much as I could discern. Ya can read in detail here: https://github.com/MajinCry/Fallout-4-Texture-Resizer/blob/master/DDS%20Header%20Info.txt
So aye, any idea what the offset is to get the .dds format, and what the values at the offset correspond to?
Now, the above is fairly hackish, but I'm resorting to viewing & copying raw bytes, as I can't for the life of me add DirectXTex as a reference to my C# project. The wiki was fairly curt in regards to integrating DirectXTex with Visual Studio, sadly.
If it's possible, would ya be able to explain it like I'm a five year old? Me version of VS is 2013, if that's of any use.
Tah in advance!