4 #define G_254_SQUARE 64516 5 #define G_254_TIMES_2 508 7 #define G_RLE_OUTPUT_CODE(code) (*((unsigned char *) dst++) = (code)) 8 #define G_RLE_INPUT_CODE(codeP) (*(codeP) = *((unsigned char *) src++)) 12 static int G_rle_codeLength(
int length)
28 while ((lPrime = lPrime / 254) != 0)
30 return codeLength + 2;
35 static char *rle_length2code(
int length,
char *
dst)
74 while ((lPrime = lPrime / 254) != 0)
89 static char *rle_code2length(
char *src,
int *length)
109 *length += 254 * code;
124 *length += 254 * code;
137 int length, nofEqual;
138 char *head, *tail, *headStop, *headStop2;
145 head = src + eltLength;
148 headStop = src + nofElts * eltLength;
150 while (head != headStop) {
151 headStop2 = head + eltLength;
153 while (head != headStop2) {
154 if (*head != *tail) {
155 length += G_rle_codeLength(nofEqual) + eltLength;
157 tail = headStop2 - eltLength;
164 if (head == headStop2) {
171 length += G_rle_codeLength(nofEqual) + eltLength;
173 return length + G_rle_codeLength(-1);
180 int length, nofEqual;
181 char *head, *tail, *headStop, *headStop2;
188 head = src + eltLength;
191 headStop = src + nofElts * eltLength;
193 while (head != headStop) {
194 headStop2 = head + eltLength;
196 while (head != headStop2) {
197 if (*head != *tail) {
198 dst = rle_length2code(nofEqual, dst);
199 tail = headStop2 - eltLength * (nofEqual + 1);
200 head = tail + eltLength;
204 length += G_rle_codeLength(nofEqual) + eltLength;
206 tail = headStop2 - eltLength;
213 if (head == headStop2) {
221 dst = rle_length2code(nofEqual, dst);
222 tail = headStop - eltLength * nofEqual;
223 head = tail + eltLength;
226 length += G_rle_codeLength(nofEqual) + eltLength;
227 dst = rle_length2code(-1, dst);
228 length += G_rle_codeLength(-1);
229 rle_code2length(dst - 2, &nofEqual);
236 int *lengthEncode,
int *lengthDecode)
239 char *src2, *srcStop, *src2Stop, *dstFirst;
241 srcStop = src + nofElts * eltLength;
244 while (src != srcStop) {
245 src = rle_code2length(src, &nofEqual);
247 if (nofEqual == -1) {
248 *lengthEncode = src - (srcStop - nofElts * eltLength);
249 *lengthDecode = dst - dstFirst;
255 src2Stop = src2 + eltLength;
256 while (src2 != src2Stop)
278 if (scanf(
"%d", &length) != 1)
280 printf(
"length = %d\n", length);
281 printf(
"codeLength %d ", G_rle_codeLength(length));
282 (void)rle_length2code(length, c);
284 (void)rle_code2length(c, &length);
285 printf(
"output length %d\n\n", length);
void Rast3d_fatal_error(const char *,...) __attribute__((format(printf
#define G_RLE_INPUT_CODE(codeP)
int Rast3d_rle_count_only(char *src, int nofElts, int eltLength)
void Rast3d_rle_encode(char *src, char *dst, int nofElts, int eltLength)
#define G_RLE_OUTPUT_CODE(code)
void Rast3d_rle_decode(char *src, char *dst, int nofElts, int eltLength, int *lengthEncode, int *lengthDecode)