26static int compute_window_row(
int fd,
int row,
int *
cellRow)
34 G_fatal_error(
_(
"Reading raster map <%s@%s> request for row %d is "
40 f = row *
fcb->C1 +
fcb->C2;
53static void do_reclass_int(
int fd,
void *cell,
int null_is_zero)
69 if (c[i] <
min || c[i] >
max) {
84static void read_data_fp_compressed(
int fd,
int row,
unsigned char *
data_buf,
96 _(
"Error seeking fp raster data file for row %d of <%s>: %s"), row,
102 fcb->cellhd.compressed);
104 G_fatal_error(
_(
"Error uncompressing fp raster data for row %d of "
105 "<%s>: error code %d"),
109static void rle_decompress(
unsigned char *dst,
const unsigned char *src,
115 for (i = 0; i <
pairs; i++) {
128static void read_data_compressed(
int fd,
int row,
unsigned char *
data_buf,
136 unsigned char *cmp, *
cmp2;
141 _(
"Error seeking raster data file for row %d of <%s>: %s"), row,
148 G_fatal_error(
_(
"Error reading raster data for row %d of <%s>: %s"),
156 if (
fcb->cellhd.compressed > 0) {
166 if (
fcb->cellhd.compressed < 0 || (
size_t)
readamount < bufsize) {
167 if (
fcb->cellhd.compressed == 1)
171 fcb->cellhd.compressed)) < 0 ||
172 (
unsigned int)n != bufsize) {
174 _(
"Error uncompressing raster data for row %d of <%s>"),
185static void read_data_uncompressed(
int fd,
int row,
unsigned char *
data_buf,
194 G_fatal_error(
_(
"Error reading raster data for row %d of <%s>"), row,
198 G_fatal_error(
_(
"Error reading raster data for row %d of <%s>"), row,
202static void read_data_gdal(
int fd,
int row,
unsigned char *
data_buf,
210 int min_col =
fcb->gdal_min_col >= 0 ?
fcb->gdal_min_col : 0;
212 fcb->gdal_min_col >= 0 ?
fcb->gdal_max_col :
fcb->cellhd.cols - 1;
220 if (
fcb->gdal->vflip)
221 row =
fcb->cellhd.rows - 1 - row;
223 buf =
fcb->gdal->hflip ?
G_malloc((
size_t)ncols *
fcb->cur_nbytes)
227 buf, ncols, 1,
fcb->gdal->type, 0, 0);
229 if (
fcb->gdal->hflip) {
232 for (i = 0; i < ncols; i++)
234 buf + (ncols - 1 - i) *
fcb->cur_nbytes,
fcb->cur_nbytes);
240 _(
"Error reading raster data via GDAL for row %d of <%s>"), row,
244static void read_data(
int fd,
int row,
unsigned char *
data_buf,
int *
nbytes)
253 if (!
fcb->cellhd.compressed)
271 for (i = 0; i < n; i++) {
272 const unsigned char *d;
289 if (
big && (*d & 0x80)) {
307static void cell_values_float(
int fd,
const unsigned char *
data G_UNUSED,
316 for (i = 0; i < n; i++) {
326static void cell_values_double(
int fd,
const unsigned char *
data G_UNUSED,
331 const double *
work_buf = (
const double *)
fcb->data;
335 for (i = 0; i < n; i++) {
345static void gdal_values_int(
int fd,
const unsigned char *
data,
351 const unsigned char *d;
355 for (i = 0; i < n; i++) {
368 switch (
fcb->gdal->type) {
397static void gdal_values_float(
int fd
G_UNUSED,
const unsigned char *
data,
402 const float *d = (
const float *)
data;
406 for (i = 0; i < n; i++) {
417 c[i] = d[
cmap[i] - 1];
423static void gdal_values_double(
int fd
G_UNUSED,
const unsigned char *
data,
428 const double *d = (
const double *)
data;
432 for (i = 0; i < n; i++) {
443 c[i] = d[
cmap[i] - 1];
458static void transfer_to_cell_XX(
int fd,
void *cell)
462 int) = {cell_values_int, cell_values_float, cell_values_double};
465 int) = {gdal_values_int, gdal_values_float, gdal_values_double};
470 fcb->cur_nbytes, cell,
474 fcb->cur_nbytes, cell,
478static void transfer_to_cell_fi(
int fd,
void *cell)
488 (
fcb->col_map[i] == 0)
495static void transfer_to_cell_di(
int fd,
void *cell)
505 (
fcb->col_map[i] == 0)
512static void transfer_to_cell_if(
int fd,
void *cell)
525static void transfer_to_cell_df(
int fd,
void *cell)
538static void transfer_to_cell_id(
int fd,
void *cell)
551static void transfer_to_cell_fd(
int fd,
void *cell)
568static int get_map_row_nomask(
int fd,
void *
rast,
int row,
572 {transfer_to_cell_XX, transfer_to_cell_if, transfer_to_cell_id},
573 {transfer_to_cell_fi, transfer_to_cell_XX, transfer_to_cell_fd},
574 {transfer_to_cell_di, transfer_to_cell_df, transfer_to_cell_XX}};
593 if (
r !=
fcb->cur_row) {
595 read_data(fd,
fcb->cur_row,
fcb->data, &
fcb->cur_nbytes);
603static void get_map_row_no_reclass(
int fd,
void *
rast,
int row,
607 get_map_row_nomask(fd,
rast, row, data_type);
633 if (!
fcb->reclass_flag)
683 get_map_row(fd, buf, row, data_type, 0, 0);
775 get_map_row(fd, buf, row, data_type, 0, 1);
839static int read_null_bits_compressed(
int null_fd,
unsigned char *flags,
int row,
844 off_t t2 =
fcb->null_row_ptr[row + 1];
851 _(
"Error seeking compressed null data for row %d of <%s>"), row,
856 (
unsigned int)res != size) {
858 _(
"Error reading compressed null data for row %d of <%s>"), row,
870 _(
"Error reading compressed null data for row %d of <%s>"), row,
876 G_fatal_error(
_(
"Error uncompressing null data for row %d of <%s>"),
889 int cols =
fcb->cellhd.cols;
894 if (compute_window_row(fd, row, &R) <= 0) {
904 if (
fcb->null_row_ptr)
905 return read_null_bits_compressed(
null_fd, flags, R, size, fd);
907 offset = (
off_t)size * R;
918#define check_null_bit(flags, bit_num) \
919 ((flags)[(bit_num) >> 3] & ((unsigned char)0x80 >> ((bit_num) & 7)) ? 1 : 0)
921static void get_null_value_row_nomask(
int fd,
char *flags,
int row)
927 G_warning(
_(
"Reading raster map <%s@%s> request for row %d is outside "
941 if (row !=
fcb->null_cur_row) {
943 fcb->null_cur_row = -1;
963 fcb->null_cur_row = row;
968 if (!
fcb->col_map[
j])
977static void get_null_value_row_gdal(
int fd,
char *flags,
int row)
991 flags[i] = !
fcb->col_map[i] ||
tmp_buf[i] ==
fcb->gdal->null_val ||
1001static void embed_mask(
char *flags,
int row)
1028static void get_null_value_row(
int fd,
char *flags,
int row,
int with_mask)
1033 get_null_value_row_gdal(fd, flags, row);
1035 get_null_value_row_nomask(fd, flags, row);
1038 embed_mask(flags, row);
1094 if (!
fcb->reclass_flag)
1095 get_null_value_row(fd, flags, row, 1);
AMI_err name(char **stream_name)
void G_zero(void *, int)
Zero out a buffer, buf, of length i.
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int G_expand(unsigned char *, int, unsigned char *, int, int)
void G_xdr_get_float(float *, const void *)
int G_lz4_expand(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz)
int G_read_compressed(int, int, unsigned char *, int, int)
void G_xdr_get_double(double *, const void *)
#define G_incr_void_ptr(ptr, size)
int Rast_is_null_value(const void *, RASTER_MAP_TYPE)
To check if a raster value is set to NULL.
int Rast__null_bitstream_size(int)
Determines null bitstream size.
CELL Rast_quant_get_cell_value(struct Quant *, DCELL)
Returns a CELL category for the floating-point value based on the quantization rules in q....
int Rast_get_vrt_row(int, void *, int, RASTER_MAP_TYPE)
void Rast_zero_input_buf(void *, RASTER_MAP_TYPE)
void Rast_set_c_null_value(CELL *, int)
To set a number of CELL raster values to NULL.
size_t Rast_cell_size(RASTER_MAP_TYPE)
Returns size of a raster cell in bytes.
void Rast_set_c_value(void *, CELL, RASTER_MAP_TYPE)
Places a CELL raster value.
void Rast__set_null_value(void *, int, int, RASTER_MAP_TYPE)
To set one or more raster values to null.
void Rast__init_null_bits(unsigned char *, int)
?
#define Rast_is_c_null_value(cellVal)
DCELL * Rast_allocate_d_input_buf(void)
CPLErr Rast_gdal_raster_IO(GDALRasterBandH band, GDALRWFlag rw_flag, int x_off, int y_off, int x_size, int y_size, void *buffer, int buf_x_size, int buf_y_size, GDALDataType buf_type, int pixel_size, int line_size)
Input/output function for GDAL links.
#define G_UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
void Rast_get_c_row_nomask(int fd, CELL *buf, int row)
Read raster row without masking (CELL type)
#define check_null_bit(flags, bit_num)
void Rast_get_null_value_row(int fd, char *flags, int row)
Read or simulate null value row.
void Rast_get_f_row_nomask(int fd, FCELL *buf, int row)
Read raster row without masking (FCELL type)
void Rast_get_row_nomask(int fd, void *buf, int row, RASTER_MAP_TYPE data_type)
Read raster row without masking.
void Rast_get_d_row_nomask(int fd, DCELL *buf, int row)
Read raster row without masking (DCELL type)
void Rast_get_d_row(int fd, DCELL *buf, int row)
Get raster row (DCELL type)
void Rast_get_c_row(int fd, CELL *buf, int row)
Get raster row (CELL type)
void Rast_get_f_row(int fd, FCELL *buf, int row)
Get raster row (FCELL type)
void Rast_get_row(int fd, void *buf, int row, RASTER_MAP_TYPE data_type)
Get raster row.
int Rast__read_null_bits(int fd, int row, unsigned char *flags)
struct fileinfo * fileinfo
struct Cell_head rd_window
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)