DDS file is scrambled up, how do I fix?
DDS file is scrambled up, how do I fix?
I have a DDS image that is scrambled somehow. It was unpacked from a XPR file. Any clue how to unscramble the image? I can't load the DDS file as attachment here for you to work with but will attach as a JPG if that would help.
- Mr.Mouse
- Site Admin
- Posts: 4051
- Joined: Wed Jan 15, 2003 6:45 pm
- Location: Dungeons of Doom
- Has thanked: 421 times
- Been thanked: 575 times
- Contact:
Re: DDS file is scrambled up, how do I fix?
Why not zip it first and then attach it?daddio wrote:I have a DDS image that is scrambled somehow. It was unpacked from a XPR file. Any clue how to unscramble the image? I can't load the DDS file as attachment here for you to work with but will attach as a JPG if that would help.
Also, you may want to read this: viewtopic.php?t=1048&highlight=xpr
The DDS files have missing headers, if I'm not mistaken. You can replace / add them yourself.
-
brienj
- VIP member

- Posts: 288
- Joined: Mon May 02, 2005 1:48 pm
- Location: Louisville, KY
- Has thanked: 10 times
- Been thanked: 68 times
- Contact:
Re: DDS file is scrambled up, how do I fix?
This sounds like an image for an Xbox game, since it is the most common platform to do it to DDS files, but I would bet that the DDS file is swizzled. There are a few threads at Xbox Scene that explain swizzled DDS images. There are no programs made, just to unswizzle/reswizzle DDS files, they are usually part of other programs that also extract the DDS files. It's mainly trial and error on finding the correct swizzle algorithm that is being used on the DDS file, but they all follow a similar pattern. Hope this has helped you some.daddio wrote:I have a DDS image that is scrambled somehow. It was unpacked from a XPR file. Any clue how to unscramble the image? I can't load the DDS file as attachment here for you to work with but will attach as a JPG if that would help.
Here's a code algorithm for xbox swizzle and unswizzle
Code: Select all
void UnSwizzle(void *ReadArray, void *WriteArray,unsigned long int &ReadOffset,unsigned long int WriteOffset, unsigned long int SegWidth, unsigned long int SegHeight, unsigned long int DataWidth)
{
if(SegWidth == 2 && SegHeight == 2)
{
((byte *)WriteArray)[WriteOffset ] = ((byte *)ReadArray)[ReadOffset + 0];
((byte *)WriteArray)[WriteOffset + 1 ] = ((byte *)ReadArray)[ReadOffset + 1];
((byte *)WriteArray)[WriteOffset + DataWidth ] = ((byte *)ReadArray)[ReadOffset + 2];
((byte *)WriteArray)[WriteOffset + DataWidth + 1] = ((byte *)ReadArray)[ReadOffset + 3];
ReadOffset += 4;
}
else
{
UnSwizzle(ReadArray, WriteArray, ReadOffset, WriteOffset, SegWidth/2, SegHeight/2, DataWidth);
UnSwizzle(ReadArray, WriteArray, ReadOffset, WriteOffset + SegWidth/2, SegWidth/2, SegHeight/2, DataWidth);
UnSwizzle(ReadArray, WriteArray, ReadOffset, WriteOffset + DataWidth*(SegHeight/2), SegWidth/2, SegHeight/2, DataWidth);
UnSwizzle(ReadArray, WriteArray, ReadOffset, WriteOffset + DataWidth*(SegHeight/2) + SegWidth/2, SegWidth/2, SegHeight/2, DataWidth);
}
}
void Swizzle(void *WriteArray, void *ReadArray, unsigned long int &WriteOffset, unsigned long int ReadOffset, unsigned long int SegWidth, unsigned long int SegHeight, unsigned long int DataWidth)
{
if(SegWidth == 2 && SegHeight == 2)
{
((byte *)WriteArray)[WriteOffset ] = ((byte *)ReadArray)[ReadOffset + 0];
((byte *)WriteArray)[WriteOffset + 1 ] = ((byte *)ReadArray)[ReadOffset + 1];
((byte *)WriteArray)[WriteOffset + 2 ] = ((byte *)ReadArray)[ReadOffset + DataWidth];
((byte *)WriteArray)[WriteOffset + 3 ] = ((byte *)ReadArray)[ReadOffset + DataWidth + 1];
WriteOffset += 4;
}
else
{
Swizzle(WriteArray, ReadArray, WriteOffset, ReadOffset, SegWidth/2, SegHeight/2, DataWidth);
Swizzle(WriteArray, ReadArray, WriteOffset, ReadOffset + SegWidth/2, SegWidth/2, SegHeight/2, DataWidth);
Swizzle(WriteArray, ReadArray, WriteOffset, ReadOffset + DataWidth*(SegHeight/2), SegWidth/2, SegHeight/2, DataWidth);
Swizzle(WriteArray, ReadArray, WriteOffset, ReadOffset + DataWidth*(SegHeight/2) + SegWidth/2, SegWidth/2, SegHeight/2, DataWidth);
}
}

