<p>In my engine I have a need to be able to detect DXT1 textures that have texels with 0 alpha (e.g. a cutout for a window frame). This is easy for textures I compress myself, but I'm not sure about textures that are already compressed.</p>

<p>Is there an easy way to tell from the header whether a DDS image contains alpha?</p>

[{'answer_id': 19495, 'author': 'James Sutherland', 'author_id': 1739, 'author_profile': 'https://Stackoverflow.com/users/1739', 'pm_score': 3, 'selected': True, 'text': "<p>As far as I know, there's no way to tell from the header. There's a DDPF_ALPHAPIXELS flag, but I don't think that will get set based on what's in the pixel data. You'd need to parse the DXT1 blocks, and look for colours that have 0 alpha in them (making sure to check that the colour is actually used in the block, too, I suppose).</p>\n"}, {'answer_id': 26756, 'author': 'Chris Blackwell', 'author_id': 1329401, 'author_profile': 'https://Stackoverflow.com/users/1329401', 'pm_score': 0, 'selected': False, 'text': '<p>I agree with the accepted answer. Your job may be made a bit easier by using the "squish" library to decompress the blocks for you.</p>\n\n<p><a href="http://www.sjbrown.co.uk/?code=squish" rel="nofollow noreferrer">http://www.sjbrown.co.uk/?code=squish</a></p>\n'}, {'answer_id': 10698423, 'author': 'starmole', 'author_id': 360270, 'author_profile': 'https://Stackoverflow.com/users/360270', 'pm_score': 0, 'selected': False, 'text': '<p>DDS is a very poor wrapper for DXT (or BTC) data. The header will not help you.\nPlain original DXT1 did not have any alpha. I believe d3d nowadays does actually decode DXT1 with alpha though. Every DXT1 block looks like this: color1(16 bits) color2(16 bits) indices(32 bits). If the 16 bit color1 value is less than color2 (just a uint16 comparison, nothing fancy!) the block has no alpha. Otherwise it does. So to answer you question: Skip the header, read 16 bits a, read 16 bits b, if a>b there is alpha. otherwise skip 32 bits and repeat until eof. Other DXT formats like DXT5 always have alpha. It is very rare that people rely on the DXT1 alpha trick because some hw (intel..) does not support it reliably.</p>\n'}, {'answer_id': 41958367, 'author': 'Alundaio', 'author_id': 5113346, 'author_profile': 'https://Stackoverflow.com/users/5113346', 'pm_score': 1, 'selected': False, 'text': '<p>No, the DDS header only uses alpha flags for uncompressed images. I had a similar need to figure out if a DXT1 image was using 1-bit alpha and after a long search I came across this reference here: <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb147243(v=vs.85).aspx" rel="nofollow noreferrer">https://msdn.microsoft.com/en-us/library/windows/desktop/bb147243(v=vs.85).aspx</a></p>\n\n<p>Basically if color_0 &lt;= color_1 then there is a possibility the texture has 1-Bit alpha. To further verify it, you need to check the next 32-bits in 2-bit pairs if they are 11. Then continue this for every block if not found.</p>\n'}]
['https://Stackoverflow.com/questions/19448', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1043/']