DDS file is scrambled up, how do I fix?

Get your graphics formats figures out here! Got details for others? Post here!
Post Reply
daddio
ultra-n00b
Posts: 2
Joined: Tue Aug 01, 2006 6:59 am

DDS file is scrambled up, how do I fix?

Post by daddio » Tue Aug 01, 2006 7:06 am

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.

User avatar
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?

Post by Mr.Mouse » Tue Aug 01, 2006 8:28 am

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.
Why not zip it first and then attach it?

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
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?

Post by brienj » Tue Aug 01, 2006 4:05 pm

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.
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
ultra-n00b
Posts: 2
Joined: Tue Aug 01, 2006 6:59 am

Post by daddio » Tue Aug 01, 2006 8:39 pm

I'm sure your correct. its a Forza image file. The rar is too large to attach from here. I will try to find a site to upload it to and post a link to the orignal file.

jasmine
VIP member
VIP member
Posts: 77
Joined: Tue May 10, 2005 6:07 am
Been thanked: 1 time

Post by jasmine » Wed Aug 09, 2006 7:55 am

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);
	}
}

User avatar
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:

Post by Mr.Mouse » Wed Aug 09, 2006 8:54 am

Nice one ! :D

Post Reply