home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************
-
- COPYRIGHT (C) 1992 UNIVERSITY OF CALIFORNIA
-
- ***************************************************************/
-
- #define N 4
- #define NMAX 32
- rle_encode(indices, nindex, ncv)
- int **indices, *nindex, ncv;
- {
- int *indices2, *ptr1, *ptr2, *max, cnt, nn[N], ii;
-
- nn[0] = NMAX;
- nn[1] = 2*NMAX;
- nn[2] = 4*NMAX;
- nn[3] = 8*NMAX;
-
- ptr1 = *indices;
- ptr2 = indices2 = (int*)malloc(*nindex*sizeof(int));
- max = ptr1 + *nindex;
-
- while(ptr1 < max) {
-
- if(*ptr1 != 0)
- *ptr2++ = *ptr1++;
-
- else {
-
- cnt = 1;
- while(*++ptr1 == 0) {
- cnt++;
- if(ptr1 == max - 1) {
- ptr1 = max;
- break;
- }
- }
-
- if(cnt == 1)
- *ptr2++ = 0;
-
- else {
- for(ii = N - 1; ii >= 0; ii--) {
- if( cnt >= nn[ii] ) {
- while(cnt >= nn[ii]) {
- *ptr2++ = ncv - 2 + NMAX + ii;
- cnt -= nn[ii];
- }
- }
- }
-
- if(cnt == 1)
- *ptr2++ = 0;
- else if(cnt != 0)
- *ptr2++ = ncv - 2 + cnt;
- }
- }
- }
-
- *nindex = ptr2 - indices2;
- indices2 = (int*)realloc(indices2, *nindex*sizeof(int));
- free(*indices);
- *indices = indices2;
- }
-