Advertisement
Guest User

Ecstatica 2 RAW decompression

a guest
Jan 28th, 2011
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.48 KB | None | 0 0
  1. struct TwoNibbles
  2. {
  3.     signed char low : 4;
  4.     signed char high : 4;
  5. };
  6.  
  7.  
  8. void decode_image_data(unsigned char *input_ptr, unsigned char *output_ptr)
  9. {
  10.     unsigned char cur_val = 0;
  11.    
  12.     while(1)
  13.     {
  14.         unsigned char span_header = *input_ptr++;
  15.         unsigned char span_type = span_header & 3;
  16.         unsigned char span_len = span_header >> 2;
  17.        
  18.         if(span_len == 0)
  19.             break;
  20.        
  21.         switch(span_type)
  22.         {
  23.             case 0:         // Packed delta encoding
  24.                 do
  25.                 {
  26.                     TwoNibbles *two_nibbles_ptr = (TwoNibbles*)input_ptr++;
  27.  
  28.                     cur_val += two_nibbles_ptr->low;
  29.                     *output_ptr++ = cur_val;
  30.                     span_len --;
  31.                    
  32.                     if(span_len == 0)
  33.                         break;
  34.                    
  35.                     cur_val += two_nibbles_ptr->high;
  36.                     *output_ptr++ = cur_val;
  37.                     span_len --;
  38.                 }
  39.                 while(span_len);
  40.                 break;
  41.                
  42.             case 1:         // Fill
  43.             case 3:
  44.                 {
  45.                     cur_val = *input_ptr++;
  46.                    
  47.                     do
  48.                     {
  49.                         *output_ptr++ = cur_val;
  50.                         span_len --;
  51.                     }
  52.                     while(span_len);
  53.                 }
  54.                 break;
  55.                
  56.             case 2:         // Copy
  57.                 do
  58.                 {
  59.                     cur_val = *input_ptr++;
  60.                     *output_ptr++ = cur_val;
  61.                     span_len --;
  62.                 }
  63.                 while(span_len);
  64.                 break;
  65.         }
  66.     }
  67. }
  68.  
  69.  
  70. void decode_depth_data(unsigned char *input_ptr, unsigned short int *output_ptr)
  71. {
  72.     unsigned short int cur_val = 0;
  73.    
  74.     while(1)
  75.     {
  76.         unsigned char span_header = *input_ptr++;
  77.         unsigned char span_type = span_header & 3;
  78.         unsigned char span_len = span_header >> 2;
  79.  
  80.         if(span_len == 0)
  81.             break;
  82.        
  83.         switch(span_type)
  84.         {
  85.             case 0:         // Packed delta encoding
  86.                 do
  87.                 {
  88.                     TwoNibbles *two_nibbles_ptr = (TwoNibbles*)input_ptr++;
  89.  
  90.                     cur_val += two_nibbles_ptr->low << 2;
  91.                     *output_ptr++ = cur_val;
  92.                     span_len--;
  93.  
  94.                     if(span_len == 0)
  95.                         break;
  96.  
  97.                     cur_val += two_nibbles_ptr->high << 2;
  98.                     *output_ptr++ = cur_val;
  99.                     span_len--;
  100.                 }
  101.                 while(span_len);
  102.                 break;
  103.                
  104.             case 1:         // Delta encoding
  105.                 do
  106.                 {
  107.                     cur_val += (*(signed char*)input_ptr++) << 2;
  108.                     *output_ptr++ = cur_val;
  109.                     span_len --;
  110.                 }
  111.                 while(span_len);
  112.                 break;
  113.  
  114.             case 2:         // Copy
  115.                 do
  116.                 {
  117.                     cur_val = *(unsigned short int*)input_ptr << 2;
  118.                     input_ptr += 2;
  119.                     *output_ptr++ = cur_val;
  120.                     span_len --;
  121.                 }
  122.                 while(span_len);
  123.                 break;
  124.  
  125.             case 3:         // Fill
  126.                 {
  127.                     cur_val = *(unsigned short int*)input_ptr << 2;
  128.                     input_ptr += 2;
  129.                     do
  130.                     {
  131.                         *output_ptr++ = cur_val;
  132.                         span_len --;
  133.                     }
  134.                     while(span_len);
  135.                 }
  136.                 break;
  137.         }
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement