Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct TwoNibbles
- {
- signed char low : 4;
- signed char high : 4;
- };
- void decode_image_data(unsigned char *input_ptr, unsigned char *output_ptr)
- {
- unsigned char cur_val = 0;
- while(1)
- {
- unsigned char span_header = *input_ptr++;
- unsigned char span_type = span_header & 3;
- unsigned char span_len = span_header >> 2;
- if(span_len == 0)
- break;
- switch(span_type)
- {
- case 0: // Packed delta encoding
- do
- {
- TwoNibbles *two_nibbles_ptr = (TwoNibbles*)input_ptr++;
- cur_val += two_nibbles_ptr->low;
- *output_ptr++ = cur_val;
- span_len --;
- if(span_len == 0)
- break;
- cur_val += two_nibbles_ptr->high;
- *output_ptr++ = cur_val;
- span_len --;
- }
- while(span_len);
- break;
- case 1: // Fill
- case 3:
- {
- cur_val = *input_ptr++;
- do
- {
- *output_ptr++ = cur_val;
- span_len --;
- }
- while(span_len);
- }
- break;
- case 2: // Copy
- do
- {
- cur_val = *input_ptr++;
- *output_ptr++ = cur_val;
- span_len --;
- }
- while(span_len);
- break;
- }
- }
- }
- void decode_depth_data(unsigned char *input_ptr, unsigned short int *output_ptr)
- {
- unsigned short int cur_val = 0;
- while(1)
- {
- unsigned char span_header = *input_ptr++;
- unsigned char span_type = span_header & 3;
- unsigned char span_len = span_header >> 2;
- if(span_len == 0)
- break;
- switch(span_type)
- {
- case 0: // Packed delta encoding
- do
- {
- TwoNibbles *two_nibbles_ptr = (TwoNibbles*)input_ptr++;
- cur_val += two_nibbles_ptr->low << 2;
- *output_ptr++ = cur_val;
- span_len--;
- if(span_len == 0)
- break;
- cur_val += two_nibbles_ptr->high << 2;
- *output_ptr++ = cur_val;
- span_len--;
- }
- while(span_len);
- break;
- case 1: // Delta encoding
- do
- {
- cur_val += (*(signed char*)input_ptr++) << 2;
- *output_ptr++ = cur_val;
- span_len --;
- }
- while(span_len);
- break;
- case 2: // Copy
- do
- {
- cur_val = *(unsigned short int*)input_ptr << 2;
- input_ptr += 2;
- *output_ptr++ = cur_val;
- span_len --;
- }
- while(span_len);
- break;
- case 3: // Fill
- {
- cur_val = *(unsigned short int*)input_ptr << 2;
- input_ptr += 2;
- do
- {
- *output_ptr++ = cur_val;
- span_len --;
- }
- while(span_len);
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement