home *** CD-ROM | disk | FTP | other *** search
/ Los Alamos National Laboratory / LANL_CD.ISO / software / compres / src / src_rle / rle_deco.c < prev    next >
Encoding:
Text File  |  1992-01-18  |  1.1 KB  |  40 lines

  1. rle_decode(indices, nindex, ncv)
  2. int **indices, *nindex, ncv;
  3. {
  4.     int index = 0, *indices2, *max, *ptr1, val, run_length, i;
  5.  
  6.     ptr1 = *indices;
  7.     indices2 = (int*)malloc(*nindex*sizeof(int));
  8.     max = *indices + *nindex;
  9.  
  10.     while(ptr1 < max) {
  11.         val = *ptr1++;
  12.  
  13.         if(val < ncv) {
  14.             indices2[index++] = val;
  15.             if(index == *nindex)
  16.                 indices2 = (int*)realloc(indices2,(*nindex+=1024)*sizeof(int));
  17.     }
  18.  
  19.         else {
  20.             if(val <= ncv + 31)
  21.                 run_length = val - ncv + 2;
  22.             if(val == ncv+31)
  23.                 run_length = 64;
  24.             if(val == ncv+32)
  25.                 run_length = 128;
  26.             if(val == ncv+33)
  27.                 run_length = 256;
  28.             if((index + run_length) < *nindex)
  29.                 indices2 = (int*)realloc(indices2,(*nindex+=1024)*sizeof(int));
  30.             for(i = 0; i < run_length; i++)
  31.                 indices2[index++] = 0;
  32.     }
  33.     }
  34.  
  35.     *nindex = index;
  36.     indices2 = (int*)realloc(indices2, *nindex*sizeof(int));
  37.     free(*indices);
  38.     *indices = indices2;
  39. }
  40.