What format is this image *really* in? - Printable Version +- The VG Resource (https://www.vg-resource.com) +-- Forum: The Resources (https://www.vg-resource.com/forum-109.html) +--- Forum: The Textures Resource (https://www.vg-resource.com/forum-113.html) +---- Forum: Ripping Help (https://www.vg-resource.com/forum-117.html) +---- Thread: What format is this image *really* in? (/thread-41401.html) |
What format is this image *really* in? - Sir Teatei Moonlight - 01-14-2023 I am working in an environment where I can't pull in any external modules/libraries, so I have to create my own image decoder for the BCn format. I am encountering a problem with BC7 in particular - or rather, something that everything is claiming is BC7, but fundamentally cannot be. I can't attach the image itself because .dds isn't an allowed file type, but here's how it begins: Code: 44 44 53 20 7c 00 00 00 07 10 00 00 00 02 00 00 Each "30 ff 03 00 c0 ff af aa aa aa 4a 92 24 49 92 24" is a solid chunk of red pixels, as evidenced by opening the file in Visual Studio or XNViewMP (top left corner). In addition, the entire image is completely opaque and has no blue at all. Multiple programs including Visual Studio list the image as being BC7. I'm using these references to understand the format:
According to all of these, this data is a "mode 2" block, and thus should be broken up like this: Code: 00110000111111110000001100000000110000001111111110101111101010101010101010101010010010101001001000100100010010011001001000100100 The problem is that this is impossible. There are two pieces of proof:
So this image claims to be BC7, but the only way it can be is if all documentation on the format is extremely incorrect. Therefore, I ask: What is the actual format of this image, and how do I decode it? RE: What format is this image *really* in? - scurest - 01-14-2023 Your problem is the order of the bits. The 16 bytes of a BC7 block are treated as a stream of 128 bits, but it goes from the lowest bit of each byte to the highest. So 0x30 isn't 00110000, it's the reverse, 00001100. Similarly, when you read a number from the stream, the first bit is the lowest bit of the result, etc. Btw this is the usual order for storing a bitstream as bytes. That makes the mode 00001 = 4, so the whole block parses as Code: mode 00001 which does look like opaque red. It seems like you could just copy/port an existing decoder. bc7decomp.h / bc7decomp.cpp from bc7enc has essentially no dependencies if that's the problem. RE: What format is this image *really* in? - Sir Teatei Moonlight - 01-14-2023 (01-14-2023, 07:39 PM)scurest Wrote: Btw this is the usual order for storing a bitstream as bytes. All the other BCn formats (well, BC1-5) seem to function properly when read with no byte reversal. I wouldn't have gotten stuck here if this made sense. Unless the code I have working for them is secretly doing it in the background without being clear about it. That's a possibility. (01-14-2023, 07:39 PM)scurest Wrote: It seems like you could just copy/port an existing decoder. bc7decomp.h / bc7decomp.cpp from bc7enc has essentially no dependencies if that's the problem. I'm using Python in Blender. It's honestly easier to do it from scratch using references. EDIT: I am getting improved results now, you have helped unblock me. RE: What format is this image *really* in? - scurest - 01-15-2023 You probably just don't notice it when bit fields fall on nice byte boundaries, but when you read eg two bytes as a little-endian 16 bit int, the first bit in the stream (the lowest bit of the first byte) becomes the first (lowest) bit of the result, etc. Quote:I'm using Python in Blender I thought for sure you could just slap a DDS header in front of the BC7 blocks and have Blender load it in a few lines. But sure enough. Blender doesn't support BC7 and the issue for it is moving at the usual glacial pace.... |