27static int compute_window_row(
int fd,
int row,
int *
cellRow)
35 G_fatal_error(
_(
"Reading raster map <%s@%s> request for row %d is "
41 f = row *
fcb->C1 +
fcb->C2;
54static void do_reclass_int(
int fd,
void *cell,
int null_is_zero)
70 if (c[i] <
min || c[i] >
max) {
85static void read_data_fp_compressed(
int fd,
int row,
unsigned char *
data_buf,
97 _(
"Error seeking fp raster data file for row %d of <%s>: %s"), row,
103 G_fatal_error(
_(
"Compressed fp raster row for <%s> is too large"),
107 (
int)bufsize,
fcb->cellhd.compressed);
109 G_fatal_error(
_(
"Error uncompressing fp raster data for row %d of "
110 "<%s>: error code %d"),
114static void rle_decompress(
unsigned char *dst,
const unsigned char *src,
119 for (
size_t i = 0; i <
pairs; i++) {
132static void read_data_compressed(
int fd,
int row,
unsigned char *
data_buf,
141 unsigned char *cmp, *
cmp2;
145 G_fatal_error(
_(
"Invalid raster row offset for row %d of <%s>"), row,
157 _(
"Error seeking raster data file for row %d of <%s>: %s"), row,
165 G_fatal_error(
_(
"Error reading raster data for row %d of <%s>: %s"),
173 if (
fcb->cellhd.compressed > 0) {
189 if (
fcb->cellhd.compressed < 0 || (
size_t)
readamount < bufsize) {
190 if (
fcb->cellhd.compressed == 1)
198 fcb->cellhd.compressed)) < 0 ||
199 (
size_t)n != bufsize) {
201 _(
"Error uncompressing raster data for row %d of <%s>"),
212static void read_data_uncompressed(
int fd,
int row,
unsigned char *
data_buf,
221 G_fatal_error(
_(
"Error reading raster data for row %d of <%s>"), row,
225 G_fatal_error(
_(
"Error reading raster data for row %d of <%s>"), row,
229static void read_data_gdal(
int fd,
int row,
unsigned char *
data_buf,
237 int min_col =
fcb->gdal_min_col >= 0 ?
fcb->gdal_min_col : 0;
239 fcb->gdal_min_col >= 0 ?
fcb->gdal_max_col :
fcb->cellhd.cols - 1;
247 if (
fcb->gdal->vflip)
248 row =
fcb->cellhd.rows - 1 - row;
250 buf =
fcb->gdal->hflip ?
G_malloc((
size_t)ncols *
fcb->cur_nbytes)
254 buf, ncols, 1,
fcb->gdal->type, 0, 0);
256 if (
fcb->gdal->hflip) {
259 for (i = 0; i < ncols; i++)
261 buf + (ncols - 1 - i) *
fcb->cur_nbytes,
fcb->cur_nbytes);
267 _(
"Error reading raster data via GDAL for row %d of <%s>"), row,
271static void read_data(
int fd,
int row,
unsigned char *
data_buf,
int *
nbytes)
280 if (!
fcb->cellhd.compressed)
298 for (i = 0; i < n; i++) {
299 const unsigned char *d;
316 if (
big && (*d & 0x80)) {
334static void cell_values_float(
int fd,
const unsigned char *
data G_UNUSED,
343 for (i = 0; i < n; i++) {
353static void cell_values_double(
int fd,
const unsigned char *
data G_UNUSED,
358 const double *
work_buf = (
const double *)
fcb->data;
362 for (i = 0; i < n; i++) {
372static void gdal_values_int(
int fd,
const unsigned char *
data,
378 const unsigned char *d;
382 for (i = 0; i < n; i++) {
395 switch (
fcb->gdal->type) {
424static void gdal_values_float(
int fd
G_UNUSED,
const unsigned char *
data,
429 const float *d = (
const float *)
data;
433 for (i = 0; i < n; i++) {
444 c[i] = d[
cmap[i] - 1];
450static void gdal_values_double(
int fd
G_UNUSED,
const unsigned char *
data,
455 const double *d = (
const double *)
data;
459 for (i = 0; i < n; i++) {
470 c[i] = d[
cmap[i] - 1];
485static void transfer_to_cell_XX(
int fd,
void *cell)
489 int) = {cell_values_int, cell_values_float, cell_values_double};
492 int) = {gdal_values_int, gdal_values_float, gdal_values_double};
497 fcb->cur_nbytes, cell,
501 fcb->cur_nbytes, cell,
505static void transfer_to_cell_fi(
int fd,
void *cell)
515 (
fcb->col_map[i] == 0)
522static void transfer_to_cell_di(
int fd,
void *cell)
532 (
fcb->col_map[i] == 0)
539static void transfer_to_cell_if(
int fd,
void *cell)
552static void transfer_to_cell_df(
int fd,
void *cell)
565static void transfer_to_cell_id(
int fd,
void *cell)
578static void transfer_to_cell_fd(
int fd,
void *cell)
595static int get_map_row_nomask(
int fd,
void *
rast,
int row,
599 {transfer_to_cell_XX, transfer_to_cell_if, transfer_to_cell_id},
600 {transfer_to_cell_fi, transfer_to_cell_XX, transfer_to_cell_fd},
601 {transfer_to_cell_di, transfer_to_cell_df, transfer_to_cell_XX}};
620 if (
r !=
fcb->cur_row) {
622 read_data(fd,
fcb->cur_row,
fcb->data, &
fcb->cur_nbytes);
630static void get_map_row_no_reclass(
int fd,
void *
rast,
int row,
634 get_map_row_nomask(fd,
rast, row, data_type);
660 if (!
fcb->reclass_flag)
710 get_map_row(fd, buf, row, data_type, 0, 0);
802 get_map_row(fd, buf, row, data_type, 0, 1);
866static int read_null_bits_compressed(
int null_fd,
unsigned char *flags,
int row,
871 off_t t2 =
fcb->null_row_ptr[row + 1];
878 _(
"Error seeking compressed null data for row %d of <%s>"), row,
882 if ((res =
read(
null_fd, flags, size)) < 0 || (
size_t)res != size) {
884 _(
"Error reading compressed null data for row %d of <%s>"), row,
896 _(
"Error reading compressed null data for row %d of <%s>"), row,
902 G_fatal_error(
_(
"Compressed null data for row %d of <%s> is too large"),
906 G_fatal_error(
_(
"Error uncompressing null data for row %d of <%s>"),
919 int cols =
fcb->cellhd.cols;
924 if (compute_window_row(fd, row, &R) <= 0) {
934 if (
fcb->null_row_ptr)
935 return read_null_bits_compressed(
null_fd, flags, R, size, fd);
937 offset = (
off_t)size * R;
948#define check_null_bit(flags, bit_num) \
949 ((flags)[(bit_num) >> 3] & ((unsigned char)0x80 >> ((bit_num) & 7)) ? 1 : 0)
951static void get_null_value_row_nomask(
int fd,
char *flags,
int row)
957 G_warning(
_(
"Reading raster map <%s@%s> request for row %d is outside "
971 if (row !=
fcb->null_cur_row) {
973 fcb->null_cur_row = -1;
993 fcb->null_cur_row = row;
998 if (!
fcb->col_map[
j])
1007static void get_null_value_row_gdal(
int fd,
char *flags,
int row)
1021 flags[i] = !
fcb->col_map[i] ||
tmp_buf[i] ==
fcb->gdal->null_val ||
1031static void embed_mask(
char *flags,
int row)
1058static void get_null_value_row(
int fd,
char *flags,
int row,
int with_mask)
1063 get_null_value_row_gdal(fd, flags, row);
1065 get_null_value_row_nomask(fd, flags, row);
1068 embed_mask(flags, row);
1124 if (!
fcb->reclass_flag)
1125 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)