Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HRESULT XboxExecutable::untileR5G6B5XboxTexture( BYTE * pSrc, DWORD dwSrcSize, LPBYTE * pDest, DWORD * dwDestSize )
- {
- // Thanks lprot for the algorithm presented in this function
- // This function is very specific, so do not use it for other purposes
- const int image_size_in_pixels_x = 128;
- const int image_size_in_pixels_y = 128;
- const int pixel_size_in_bytes= 2;
- short pixels[image_size_in_pixels_x][image_size_in_pixels_y];
- short image[image_size_in_pixels_x*image_size_in_pixels_y];
- // Copy our image data to our multidimensional array
- memcpy( image, pSrc, dwSrcSize );
- // Rearrange pixels
- int a,b,c,d,e,f,g,h,i,j,k,l;
- int x=0, y=0, pos=0;
- for (a=0;a<2;a++) {
- for (b=0;b<2;b++) {
- for (c=0;c<2;c++) {
- for (d=0;d<2;d++) {
- for (e=0;e<2;e++) {
- for (f=0;f<2;f++) {
- for (g=0;g<2;g++) {
- for (h=0;h<2;h++) {
- for (i=0;i<2;i++) {
- for (j=0;j<2;j++) {
- for (k=0;k<2;k++) {
- for (l=0;l<2;l++) {
- pixels[x][y]=image[pos];
- pixels[x+1][y]=image[pos+1];
- pixels[x][y+1]=image[pos+2];
- pixels[x+1][y+1]=image[pos+3];
- pos+=4; x+=2;
- }
- x-=4; y+=2;
- }
- x+=4; y-=4;
- }
- x-=8; y+=4;
- }
- x+=8; y-=8;
- }
- x-=16; y+=8;
- }
- x+=16; y-=16;
- }
- x-=32; y+=16;
- }
- x+=32; y-=32;
- }
- x-=64; y+=32;
- }
- x+=64; y-=64;
- }
- x-=128; y+=64;
- }
- // Now we want copy this information into our destination buffer
- DWORD offset = 0;
- for (x=0;x<128;x++) {
- for (y=0;y<128;y++) {
- memcpy( (BYTE*)(*pDest) + offset, &pixels[y][x], 2);
- offset+=2;
- }
- }
- // Return Successfully
- return S_OK;
- }
Add Comment
Please, Sign In to add comment