/* File : PACK.C Description: Author : Peter H. Michalicka Environment: HP-UX 8.05 */ #include #include "tiff.h" #ifdef ANSI void getbuf(int count, BYTE *ptr); #endif /* Unpack a line of data compressed with the PackBits scheme. */ void unpackbits(des_byts, des) int des_byts; BYTE *des; { int i, count, ch; BYTE src[128]; while(des_byts > 0) { getbuf(1, src); ch = *src; if(ch & 0x80) { /* ch = 128 -> 255: write the following byte 257-ch times */ count = 257 - ch; getbuf(1, src); ch = *src; for (i = 0; i < count; i++) *des++ = (BYTE)ch; } else { /* ch = 0 -> 127: copy the following ch+1 bytes literally */ count = ch + 1; getbuf(count, des); des += count; /* and where to write them */ } des_byts -= count; /* Update bytes left to write */ } }