Guest User

Untitled

a guest
Apr 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. HRESULT XboxExecutable::untileR5G6B5XboxTexture( BYTE * pSrc, DWORD dwSrcSize, LPBYTE * pDest, DWORD * dwDestSize )
  2. {
  3.     // Thanks lprot for the algorithm presented in this function
  4.     // This function is very specific, so do not use it for other purposes
  5.     const int image_size_in_pixels_x = 128;
  6.     const int image_size_in_pixels_y = 128;
  7.     const int pixel_size_in_bytes= 2;
  8.  
  9.     short pixels[image_size_in_pixels_x][image_size_in_pixels_y];
  10.     short image[image_size_in_pixels_x*image_size_in_pixels_y];
  11.  
  12.     // Copy our image data to our multidimensional array
  13.     memcpy( image, pSrc, dwSrcSize );
  14.    
  15.     // Rearrange pixels
  16.     int a,b,c,d,e,f,g,h,i,j,k,l;
  17.     int x=0, y=0, pos=0;
  18.  
  19.     for (a=0;a<2;a++) {
  20.         for (b=0;b<2;b++) {
  21.             for (c=0;c<2;c++) {
  22.                 for (d=0;d<2;d++) {
  23.                     for (e=0;e<2;e++) {
  24.                         for (f=0;f<2;f++) {
  25.                             for (g=0;g<2;g++) {
  26.                                 for (h=0;h<2;h++) {
  27.                                     for (i=0;i<2;i++) {
  28.                                         for (j=0;j<2;j++) {
  29.                                             for (k=0;k<2;k++) {
  30.                                                 for (l=0;l<2;l++) {
  31.                                                         pixels[x][y]=image[pos];
  32.                                                         pixels[x+1][y]=image[pos+1];
  33.                                                         pixels[x][y+1]=image[pos+2];
  34.                                                         pixels[x+1][y+1]=image[pos+3];
  35.                                                         pos+=4; x+=2;
  36.                                                 }
  37.                                                 x-=4; y+=2;
  38.                                             }
  39.                                             x+=4; y-=4;
  40.                                         }
  41.                                         x-=8; y+=4;
  42.                                     }
  43.                                     x+=8; y-=8;
  44.                                 }
  45.                                 x-=16; y+=8;
  46.                             }
  47.                             x+=16; y-=16;
  48.                         }
  49.                         x-=32; y+=16;
  50.                     }
  51.                     x+=32; y-=32;
  52.                 }
  53.                 x-=64; y+=32;
  54.             }
  55.             x+=64; y-=64;
  56.         }
  57.         x-=128; y+=64;
  58.     }
  59.  
  60.     // Now we want copy this information into our destination buffer
  61.     DWORD offset = 0;
  62.     for (x=0;x<128;x++) {
  63.         for (y=0;y<128;y++) {
  64.             memcpy( (BYTE*)(*pDest) + offset, &pixels[y][x], 2);
  65.             offset+=2;
  66.         }
  67.     }  
  68.  
  69.     // Return Successfully
  70.     return S_OK;
  71. }
Add Comment
Please, Sign In to add comment