Unswizzling a texture

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Unswizzling a texture

Post by Brunni »

Hello ^^

I'm trying to unswizzle a texture but I can't understand correctly what is written here :( It's sooo complicated, especially for me who doesn't understand english very well :(
I've searched a lot but didn't found any code that does unswizzling.
So I'm asking here: can someone post a routine for unswizzling a texture please? :)

Thank you very much in advance,
Brunni
Sorry for my bad english
Image Oldschool library for PSP - PC version released
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Code: Select all

void unswizzle_fast(u8* out, const u8* in, unsigned int width, unsigned int height)
{
   unsigned int blockx, blocky;
   unsigned int i,j;
 
   unsigned int width_blocks = (width / 16);
   unsigned int height_blocks = (height / 8);
 
   unsigned int dst_pitch = (width-16)/4;
   unsigned int dst_row = width * 8;
 
   u32* src = (u32*)in;
   u8* ydst = out;
 
   for &#40;blocky = 0; blocky < height_blocks; ++blocky&#41;
   &#123;
      const u8* xdst = ydst;
      for &#40;blockx = 0; blockx < width_blocks; ++blockx&#41;
      &#123;
         const u32* dst= &#40;u32*&#41;xdst;
         for &#40;j = 0; j < 8; ++j&#41;
         &#123;
            *&#40;dst++&#41; = *&#40;src++&#41;;
            *&#40;dst++&#41; = *&#40;src++&#41;;
            *&#40;dst++&#41; = *&#40;src++&#41;;
            *&#40;dst++&#41; = *&#40;src++&#41;;
            dst += dst_pitch;
         &#125;
         xdst += 16;
     &#125;
     ydst += dst_row;
   &#125;
&#125;
Try with that. It's untested though, but you can work from there if it doesn't give correct results immediately. Basically, you just revert the code from the swizzle function.
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

Soooo kind of you :)
It works, thank you so much :D
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Post Reply