12 unsigned char *tmp, *tmp2;
13 int dummy1, dummy2, indexLength, tileIndex;
16 indexLast = lseek(map->
data_fd, (
long)0, SEEK_END);
17 if (indexLast == -1) {
32 Rast3d_error(
"Rast3d_readIndex: error in Rast3d_malloc");
38 if (read(map->
data_fd, tmp, indexLength) != indexLength) {
49 if (indexLength > (
int)
sizeof(
long) * map->
nTiles) {
54 Rast3d_error(
"Rast3d_readIndex: error in Rast3d_malloc");
59 tmp2 = (
unsigned char *)map->
index;
61 if (read(map->
data_fd, tmp2, indexLength) != indexLength) {
70 if (indexLength > (
int)
sizeof(
long) * map->
nTiles)
76 for (tileIndex = 0; tileIndex < map->
nTiles; tileIndex++)
77 if (map->
index[tileIndex] == 0)
78 map->
index[tileIndex] = -1;
89 int indexLength, tileIndex;
107 Rast3d_error(
"Rast3d_flush_index: error in Rast3d_malloc");
111 for (tileIndex = 0; tileIndex < map->
nTiles; tileIndex++)
112 if (map->
index[tileIndex] == -1)
113 map->
index[tileIndex] = 0;
117 indexLength = map->
nTiles *
sizeof(long);
118 if (write(map->
data_fd, tmp, indexLength) != indexLength) {
124 if (!Rast3d_readIndex(map)) {
125 Rast3d_error(
"Rast3d_flush_index: error in Rast3d_readIndex");
134 static long *cmpIndex;
136 static int indexSortCompare(
const void *a,
const void *
b)
138 long offset1, offset2;
140 offset1 = cmpIndex[*((
const long *)a)];
141 offset2 = cmpIndex[*((
const long *)
b)];
143 if (offset1 > offset2)
145 if (offset1 < offset2)
155 int i0, i1, i2, i3, i4, i5, nofElts;
164 Rast3d_error(
"Rast3d_init_index: error in Rast3d_malloc");
169 for (tile = 0; tile < map->
nTiles; tile++)
170 map->
index[tile] = -1;
176 for (tile = 0; tile < map->
nTiles; tile++) {
179 map, tile, &i0, &i1, &i2, &i3, &i4, &i5);
186 if (!Rast3d_readIndex(map)) {
187 Rast3d_error(
"Rast3d_init_index: error in Rast3d_readIndex");
192 if (offsetP ==
NULL) {
193 Rast3d_error(
"Rast3d_init_index: error in Rast3d_malloc");
197 for (tile = 0; tile < map->
nTiles; tile++)
198 offsetP[tile] = tile;
199 cmpIndex = map->
index;
200 qsort(offsetP, map->
nTiles,
sizeof(
long), indexSortCompare);
202 for (tile = 0; tile < map->
nTiles - 1; tile++) {
203 if (map->
index[offsetP[tile]] == -1) {
209 map->
index[offsetP[tile + 1]] - map->
index[offsetP[tile]];
void Rast3d_free(void *)
Same as free (ptr).
void Rast3d_long_decode(unsigned char *, long *, int, int)
int Rast3d_compute_clipped_tile_dimensions(RASTER3D_Map *, int, int *, int *, int *, int *, int *, int *)
Computes the dimensions of the tile when clipped to fit the region of map. The clipped dimensions are...
void Rast3d_error(const char *,...) __attribute__((format(printf
int Rast3d_long_encode(long *, unsigned char *, int)
void Rast3d_rle_decode(char *, char *, int, int, int *, int *)
void * Rast3d_malloc(int)
Same as malloc (nBytes), except that in case of error Rast3d_error() is invoked.
int Rast3d_flush_index(RASTER3D_Map *map)
int Rast3d_init_index(RASTER3D_Map *map, int hasIndex)
#define RASTER3D_WRITE_DATA