GRASS 8 Programmer's Manual 8.6.0dev(2026)-ddeab64dbf
Loading...
Searching...
No Matches
long.c
Go to the documentation of this file.
1#include "raster3d_intern.h"
2
3/*---------------------------------------------------------------------------*/
4
5int Rast3d_long_encode(long *source, unsigned char *dst, int nofNums)
6{
7 long *src, d;
8 int eltLength, nBytes;
9 unsigned char *dstStop, tmp;
10
11 eltLength = RASTER3D_LONG_LENGTH;
12 nBytes = 8;
13
14 d = 1;
15
16 while (eltLength--) {
17 dstStop = dst + nofNums;
18 src = source;
19
20 while (dst != dstStop) {
21 tmp = ((*src++ / d) % 256);
22 if (tmp != 0)
23 nBytes = RASTER3D_MIN(nBytes, eltLength);
24 *dst++ = tmp;
25 }
26
27 d *= 256;
28 }
29
31}
32
33/*---------------------------------------------------------------------------*/
34
35void Rast3d_long_decode(unsigned char *source, long *dst, int nofNums,
36 int longNbytes)
37{
38 long *dest;
39 int eltLength;
40 unsigned char *srcStop;
41
42 eltLength = longNbytes;
43
44 source += nofNums * eltLength - 1;
45
46 eltLength--;
48 dest = dst;
49 dest += nofNums - 1;
50 while (source != srcStop) {
51 *dest = *source--;
52 if ((eltLength >= (int)RASTER3D_LONG_LENGTH) && (*dest != 0))
53 Rast3d_fatal_error("Rast3d_long_decode: decoded long too long");
54 dest--;
55 }
56
57 while (eltLength--) {
59 dest = dst;
60 dest += nofNums - 1;
61 while (source != srcStop) {
62 *dest *= 256;
63 *dest += *source--;
64 if ((eltLength >= (int)RASTER3D_LONG_LENGTH) && (*dest != 0))
65 Rast3d_fatal_error("Rast3d_long_decode: decoded long too long");
66 dest--;
67 }
68 }
69}
void Rast3d_fatal_error(const char *,...) __attribute__((format(printf
void Rast3d_long_decode(unsigned char *source, long *dst, int nofNums, int longNbytes)
Definition long.c:35
int Rast3d_long_encode(long *source, unsigned char *dst, int nofNums)
Definition long.c:5
#define RASTER3D_LONG_LENGTH
#define RASTER3D_MIN(a, b)