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)
76 while ((lPrime = lPrime / 254) != 0)
92 static char *rle_code2length(
char *
src,
int *length)
113 *length += 254 * code;
129 *length += 254 * code;
143 int length, nofEqual;
144 char *head, *tail, *headStop, *headStop2;
151 head =
src + eltLength;
154 headStop =
src + nofElts * eltLength;
156 while (head != headStop) {
157 headStop2 = head + eltLength;
159 while (head != headStop2) {
160 if (*head != *tail) {
161 length += G_rle_codeLength(nofEqual) + eltLength;
163 tail = headStop2 - eltLength;
170 if (head == headStop2) {
177 length += G_rle_codeLength(nofEqual) + eltLength;
179 return length + G_rle_codeLength(-1);
187 char *head, *tail, *headStop, *headStop2;
193 head =
src + eltLength;
196 headStop =
src + nofElts * eltLength;
198 while (head != headStop) {
199 headStop2 = head + eltLength;
201 while (head != headStop2) {
202 if (*head != *tail) {
203 dst = rle_length2code(nofEqual,
dst);
204 tail = headStop2 - eltLength * (nofEqual + 1);
205 head = tail + eltLength;
210 tail = headStop2 - eltLength;
217 if (head == headStop2) {
225 dst = rle_length2code(nofEqual,
dst);
226 tail = headStop - eltLength * nofEqual;
227 head = tail + eltLength;
230 dst = rle_length2code(-1,
dst);
231 rle_code2length(
dst - 2, &nofEqual);
237 int *lengthEncode,
int *lengthDecode)
240 char *src2, *srcStop, *src2Stop, *dstFirst;
242 srcStop =
src + nofElts * eltLength;
245 while (
src != srcStop) {
246 src = rle_code2length(
src, &nofEqual);
248 if (nofEqual == -1) {
249 *lengthEncode =
src - (srcStop - nofElts * eltLength);
250 *lengthDecode =
dst - dstFirst;
256 src2Stop = src2 + eltLength;
257 while (src2 != src2Stop)
279 if (scanf(
"%d", &length) != 1)
281 printf(
"length = %d\n", length);
282 printf(
"codeLength %d ", G_rle_codeLength(length));
283 (void)rle_length2code(length, c);
285 (void)rle_code2length(c, &length);
286 printf(
"output length %d\n\n", length);
void Rast3d_fatal_error(const char *,...) __attribute__((format(printf
void Rast3d_rle_decode(char *src, char *dst, int nofElts, int eltLength, int *lengthEncode, int *lengthDecode)
#define G_RLE_INPUT_CODE(codeP)
void Rast3d_rle_encode(char *src, char *dst, int nofElts, int eltLength)
int Rast3d_rle_count_only(char *src, int nofElts, int eltLength)
#define G_RLE_OUTPUT_CODE(code)