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) {
44 if (indexLength < map->indexLongNbytes * map->
nTiles) {
46 if (indexLength >
sizeof(
long) * map->
nTiles) {
50 Rast3d_error(
"Rast3d_readIndex: error in Rast3d_malloc");
55 tmp2 = (
unsigned char *)map->
index;
57 if (read(map->
data_fd, tmp2, indexLength) != indexLength) {
65 if (indexLength >
sizeof(
long) * map->
nTiles)
71 for (tileIndex = 0; tileIndex < map->
nTiles; tileIndex++)
72 if (map->
index[tileIndex] == 0)
73 map->
index[tileIndex] = -1;
84 int indexLength, tileIndex;
98 (
unsigned char *)&ldummy, 1);
102 Rast3d_error(
"Rast3d_flush_index: error in Rast3d_malloc");
106 for (tileIndex = 0; tileIndex < map->
nTiles; tileIndex++)
107 if (map->
index[tileIndex] == -1)
108 map->
index[tileIndex] = 0;
112 indexLength = map->
nTiles *
sizeof(long);
113 if (write(map->
data_fd, tmp, indexLength) != indexLength) {
119 if (!Rast3d_readIndex(map)) {
120 Rast3d_error(
"Rast3d_flush_index: error in Rast3d_readIndex");
129 static long *cmpIndex;
131 static int indexSortCompare(
const void *a,
const void *
b)
133 long offset1, offset2;
135 offset1 = cmpIndex[*((
const long *)a)];
136 offset2 = cmpIndex[*((
const long *)b)];
138 if (offset1 > offset2)
140 if (offset1 < offset2)
150 int i0, i1, i2, i3, i4, i5, nofElts;
159 Rast3d_error(
"Rast3d_init_index: error in Rast3d_malloc");
164 for (tile = 0; tile < map->
nTiles; tile++)
165 map->
index[tile] = -1;
171 for (tile = 0; tile < map->
nTiles; tile++) {
174 (map, tile, &i0, &i1, &i2, &i3, &i4, &i5);
181 if (!Rast3d_readIndex(map)) {
182 Rast3d_error(
"Rast3d_init_index: error in Rast3d_readIndex");
187 if (offsetP ==
NULL) {
188 Rast3d_error(
"Rast3d_init_index: error in Rast3d_malloc");
192 for (tile = 0; tile < map->
nTiles; tile++)
193 offsetP[tile] = tile;
194 cmpIndex = map->
index;
195 qsort(offsetP, map->
nTiles,
sizeof(
long), indexSortCompare);
197 for (tile = 0; tile < map->
nTiles - 1; tile++) {
198 if (map->
index[offsetP[tile]] == -1) {
204 map->
index[offsetP[tile]];
void Rast3d_rle_decode(char *, char *, int, int, int *, int *)
#define RASTER3D_WRITE_DATA
void * Rast3d_malloc(int)
Same as malloc (nBytes), except that in case of error Rast3d_error() is invoked.
int Rast3d_long_encode(long *, unsigned char *, int)
void Rast3d_long_decode(unsigned char *, long *, int, int)
int Rast3d_init_index(RASTER3D_Map *map, int hasIndex)
void Rast3d_error(const char *,...) __attribute__((format(printf
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...
int Rast3d_flush_index(RASTER3D_Map *map)
void Rast3d_free(void *)
Same as free (ptr).