/[rdesktop]/jpeg/rdesktop/trunk/mppc.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /jpeg/rdesktop/trunk/mppc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

sourceforge.net/trunk/rdesktop/mppc.c revision 689 by n-ki, Tue May 4 09:48:45 2004 UTC jpeg/rdesktop/trunk/mppc.c revision 1507 by dpavlin, Mon Jul 20 16:45:11 2009 UTC
# Line 1  Line 1 
1  /* -*- c-basic-offset: 8 -*-  /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     Protocol services - RDP decompression     Protocol services - RDP decompression
4     Copyright (C) Matthew Chapman 1999-2004     Copyright (C) Matthew Chapman 1999-2008
5    
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
# Line 59  int Line 59  int
59  mppc_expand(uint8 * data, uint32 clen, uint8 ctype, uint32 * roff, uint32 * rlen)  mppc_expand(uint8 * data, uint32 clen, uint8 ctype, uint32 * roff, uint32 * rlen)
60  {  {
61          int k, walker_len = 0, walker;          int k, walker_len = 0, walker;
62          int i = 0;          uint32 i = 0;
63          int next_offset, match_off;          int next_offset, match_off;
64          int match_len;          int match_len;
65          int old_offset, match_bits;          int old_offset, match_bits;
66            RD_BOOL big = ctype & RDP_MPPC_BIG ? True : False;
67    
68          signed char *dict = &(g_mppc_dict.hist);          uint8 *dict = g_mppc_dict.hist;
69    
70          if ((ctype & RDP_MPPC_COMPRESSED) == 0)          if ((ctype & RDP_MPPC_COMPRESSED) == 0)
71          {          {
# Line 155  mppc_expand(uint8 * data, uint32 clen, u Line 156  mppc_expand(uint8 * data, uint32 clen, u
156                  /* decode offset  */                  /* decode offset  */
157                  /* length pair    */                  /* length pair    */
158                  walker <<= 1;                  walker <<= 1;
159                  if (--walker_len < 2)                  if (--walker_len < (big ? 3 : 2))
160                  {                  {
161                          if (i >= clen)                          if (i >= clen)
162                                  return -1;                                  return -1;
163                          walker |= (data[i++] & 0xff) << (24 - walker_len);                          walker |= (data[i++] & 0xff) << (24 - walker_len);
164                          walker_len += 8;                          walker_len += 8;
165                  }                  }
166                  /* offset decoding where offset len is:  
167                     -63: 1111 followed by the lower 6 bits of the value                  if (big)
                    64-319: 1110 followed by the lower 8 bits of the value ( value - 64 )  
                    320-8191: 110 followed by the lower 13 bits of the value ( value - 320 )  
                  */  
                 switch (((uint32) walker) >> ((uint32) 30))  
168                  {                  {
169                          case 3: /* - 63 */                          /* offset decoding where offset len is:
170                                  if (walker_len < 8)                             -63: 11111 followed by the lower 6 bits of the value
171                                  {                             64-319: 11110 followed by the lower 8 bits of the value ( value - 64 )
172                                          if (i >= clen)                             320-2367: 1110 followed by lower 11 bits of the value ( value - 320 )
173                                                  return -1;                             2368-65535: 110 followed by lower 16 bits of the value ( value - 2368 )
174                                          walker |= (data[i++] & 0xff) << (24 - walker_len);                           */
175                                          walker_len += 8;                          switch (((uint32) walker) >> ((uint32) 29))
176                                  }                          {
177                                  walker <<= 2;                                  case 7: /* - 63 */
178                                  match_off = ((uint32) walker) >> ((uint32) 26);                                          for (; walker_len < 9; walker_len += 8)
179                                  walker <<= 6;                                          {
180                                  walker_len -= 8;                                                  if (i >= clen)
181                                  break;                                                          return -1;
182                                                    walker |= (data[i++] & 0xff) << (24 - walker_len);
183                                            }
184                                            walker <<= 3;
185                                            match_off = ((uint32) walker) >> ((uint32) 26);
186                                            walker <<= 6;
187                                            walker_len -= 9;
188                                            break;
189    
190                          case 2: /* 64 - 319 */                                  case 6: /* 64 - 319 */
191                                  for (; walker_len < 10; walker_len += 8)                                          for (; walker_len < 11; walker_len += 8)
192                                  {                                          {
193                                          if (i >= clen)                                                  if (i >= clen)
194                                                  return -1;                                                          return -1;
195                                          walker |= (data[i++] & 0xff) << (24 - walker_len);                                                  walker |= (data[i++] & 0xff) << (24 - walker_len);
196                                  }                                          }
197    
198                                  walker <<= 2;                                          walker <<= 3;
199                                  match_off = (((uint32) walker) >> ((uint32) 24)) + 64;                                          match_off = (((uint32) walker) >> ((uint32) 24)) + 64;
200                                  walker <<= 8;                                          walker <<= 8;
201                                  walker_len -= 10;                                          walker_len -= 11;
202                                  break;                                          break;
203    
204                          default:        /* 320 - 8191 */                                  case 5:
205                                  for (; walker_len < 14; walker_len += 8)                                  case 4: /* 320 - 2367 */
206                                  {                                          for (; walker_len < 13; walker_len += 8)
207                                          if (i >= clen)                                          {
208                                                  return -1;                                                  if (i >= clen)
209                                          walker |= (data[i++] & 0xff) << (24 - walker_len);                                                          return -1;
210                                  }                                                  walker |= (data[i++] & 0xff) << (24 - walker_len);
211                                            }
212    
213                                  match_off = (walker >> 18) + 320;                                          walker <<= 2;
214                                  walker <<= 14;                                          match_off = (((uint32) walker) >> ((uint32) 21)) + 320;
215                                  walker_len -= 14;                                          walker <<= 11;
216                                  break;                                          walker_len -= 13;
217                                            break;
218    
219                                    default:        /* 2368 - 65535 */
220                                            for (; walker_len < 17; walker_len += 8)
221                                            {
222                                                    if (i >= clen)
223                                                            return -1;
224                                                    walker |= (data[i++] & 0xff) << (24 - walker_len);
225                                            }
226    
227                                            walker <<= 1;
228                                            match_off = (((uint32) walker) >> ((uint32) 16)) + 2368;
229                                            walker <<= 16;
230                                            walker_len -= 17;
231                                            break;
232                            }
233                    }
234                    else
235                    {
236                            /* offset decoding where offset len is:
237                               -63: 1111 followed by the lower 6 bits of the value
238                               64-319: 1110 followed by the lower 8 bits of the value ( value - 64 )
239                               320-8191: 110 followed by the lower 13 bits of the value ( value - 320 )
240                             */
241                            switch (((uint32) walker) >> ((uint32) 30))
242                            {
243                                    case 3: /* - 63 */
244                                            if (walker_len < 8)
245                                            {
246                                                    if (i >= clen)
247                                                            return -1;
248                                                    walker |= (data[i++] & 0xff) << (24 - walker_len);
249                                                    walker_len += 8;
250                                            }
251                                            walker <<= 2;
252                                            match_off = ((uint32) walker) >> ((uint32) 26);
253                                            walker <<= 6;
254                                            walker_len -= 8;
255                                            break;
256    
257                                    case 2: /* 64 - 319 */
258                                            for (; walker_len < 10; walker_len += 8)
259                                            {
260                                                    if (i >= clen)
261                                                            return -1;
262                                                    walker |= (data[i++] & 0xff) << (24 - walker_len);
263                                            }
264    
265                                            walker <<= 2;
266                                            match_off = (((uint32) walker) >> ((uint32) 24)) + 64;
267                                            walker <<= 8;
268                                            walker_len -= 10;
269                                            break;
270    
271                                    default:        /* 320 - 8191 */
272                                            for (; walker_len < 14; walker_len += 8)
273                                            {
274                                                    if (i >= clen)
275                                                            return -1;
276                                                    walker |= (data[i++] & 0xff) << (24 - walker_len);
277                                            }
278    
279                                            match_off = (walker >> 18) + 320;
280                                            walker <<= 14;
281                                            walker_len -= 14;
282                                            break;
283                            }
284                  }                  }
285                  if (walker_len == 0)                  if (walker_len == 0)
286                  {                  {
# Line 244  mppc_expand(uint8 * data, uint32 clen, u Line 316  mppc_expand(uint8 * data, uint32 clen, u
316                             i.e. 4097 is encoded as: 111111111110 000000000001                             i.e. 4097 is encoded as: 111111111110 000000000001
317                             meaning 4096 + 1...                             meaning 4096 + 1...
318                           */                           */
319                          match_bits = 11;        /* 11 bits of value at most */                          match_bits = big ? 14 : 11;     /* 11 or 14 bits of value at most */
320                          do                          do
321                          {                          {
322                                  walker <<= 1;                                  walker <<= 1;
# Line 263  mppc_expand(uint8 * data, uint32 clen, u Line 335  mppc_expand(uint8 * data, uint32 clen, u
335                                  }                                  }
336                          }                          }
337                          while (1);                          while (1);
338                          match_len = 13 - match_bits;                          match_len = (big ? 16 : 13) - match_bits;
339                          walker <<= 1;                          walker <<= 1;
340                          if (--walker_len < match_len)                          if (--walker_len < match_len)
341                          {                          {
# Line 279  mppc_expand(uint8 * data, uint32 clen, u Line 351  mppc_expand(uint8 * data, uint32 clen, u
351    
352                          match_bits = match_len;                          match_bits = match_len;
353                          match_len =                          match_len =
354                                  walker >> 32 - match_bits & ~(-1 << match_bits) | 1 << match_bits;                                  ((walker >> (32 - match_bits)) & (~(-1 << match_bits))) | (1 <<
355                                                                                               match_bits);
356                          walker <<= match_bits;                          walker <<= match_bits;
357                          walker_len -= match_bits;                          walker_len -= match_bits;
358                  }                  }
# Line 288  mppc_expand(uint8 * data, uint32 clen, u Line 361  mppc_expand(uint8 * data, uint32 clen, u
361                          return -1;                          return -1;
362                  }                  }
363                  /* memory areas can overlap - meaning we can't use memXXX functions */                  /* memory areas can overlap - meaning we can't use memXXX functions */
364                  k = next_offset - match_off & (RDP_MPPC_DICT_SIZE - 1);                  k = (next_offset - match_off) & (big ? 65535 : 8191);
365                  do                  do
366                  {                  {
367                          dict[next_offset++] = dict[k++];                          dict[next_offset++] = dict[k++];

Legend:
Removed from v.689  
changed lines
  Added in v.1507

  ViewVC Help
Powered by ViewVC 1.1.26