28static int compute_window_row(
int fd,
int row,
int *
cellRow)
36 G_fatal_error(
_(
"Reading raster map <%s@%s> request for row %d is "
42 f = row *
fcb->C1 +
fcb->C2;
55static void do_reclass_int(
int fd,
void *cell,
int null_is_zero)
71 if (c[i] <
min || c[i] >
max) {
86static void read_data_fp_compressed(
int fd,
int row,
unsigned char *
data_buf,
93 size_t bufsize =
fcb->cellhd.cols *
fcb->nbytes;
98 _(
"Error seeking fp raster data file for row %d of <%s>: %s"), row,
104 fcb->cellhd.compressed);
106 G_fatal_error(
_(
"Error uncompressing fp raster data for row %d of "
107 "<%s>: error code %d"),
111static void rle_decompress(
unsigned char *dst,
const unsigned char *src,
117 for (i = 0; i <
pairs; i++) {
130static void read_data_compressed(
int fd,
int row,
unsigned char *
data_buf,
138 unsigned char *cmp, *
cmp2;
143 _(
"Error seeking raster data file for row %d of <%s>: %s"), row,
150 G_fatal_error(
_(
"Error reading raster data for row %d of <%s>: %s"),
158 if (
fcb->cellhd.compressed > 0) {
168 if (
fcb->cellhd.compressed < 0 || (
size_t)
readamount < bufsize) {
169 if (
fcb->cellhd.compressed == 1)
173 fcb->cellhd.compressed)) < 0 ||
174 (
unsigned int)n != bufsize) {
176 _(
"Error uncompressing raster data for row %d of <%s>"),
187static void read_data_uncompressed(
int fd,
int row,
unsigned char *
data_buf,
196 G_fatal_error(
_(
"Error reading raster data for row %d of <%s>"), row,
200 G_fatal_error(
_(
"Error reading raster data for row %d of <%s>"), row,
204static void read_data_gdal(
int fd,
int row,
unsigned char *
data_buf,
213 if (
fcb->gdal->vflip)
214 row =
fcb->cellhd.rows - 1 - row;
221 1, buf,
fcb->cellhd.cols, 1,
fcb->gdal->type, 0, 0);
223 if (
fcb->gdal->hflip) {
226 for (i = 0; i <
fcb->cellhd.cols; i++)
228 buf + (
fcb->cellhd.cols - 1 - i) *
fcb->cur_nbytes,
235 _(
"Error reading raster data via GDAL for row %d of <%s>"), row,
239static void read_data(
int fd,
int row,
unsigned char *
data_buf,
int *
nbytes)
248 if (!
fcb->cellhd.compressed)
266 for (i = 0; i < n; i++) {
267 const unsigned char *d;
284 if (
big && (*d & 0x80)) {
302static void cell_values_float(
int fd,
const unsigned char *
data UNUSED,
311 for (i = 0; i < n; i++) {
321static void cell_values_double(
int fd,
const unsigned char *
data UNUSED,
326 const double *
work_buf = (
const double *)
fcb->data;
330 for (i = 0; i < n; i++) {
340static void gdal_values_int(
int fd,
const unsigned char *
data,
346 const unsigned char *d;
350 for (i = 0; i < n; i++) {
363 switch (
fcb->gdal->type) {
392static void gdal_values_float(
int fd
UNUSED,
const unsigned char *
data,
397 const float *d = (
const float *)
data;
401 for (i = 0; i < n; i++) {
412 c[i] = d[
cmap[i] - 1];
418static void gdal_values_double(
int fd
UNUSED,
const unsigned char *
data,
423 const double *d = (
const double *)
data;
427 for (i = 0; i < n; i++) {
438 c[i] = d[
cmap[i] - 1];
453static void transfer_to_cell_XX(
int fd,
void *cell)
457 int) = {cell_values_int, cell_values_float, cell_values_double};
460 int) = {gdal_values_int, gdal_values_float, gdal_values_double};
465 fcb->cur_nbytes, cell,
469 fcb->cur_nbytes, cell,
473static void transfer_to_cell_fi(
int fd,
void *cell)
483 (
fcb->col_map[i] == 0)
490static void transfer_to_cell_di(
int fd,
void *cell)
500 (
fcb->col_map[i] == 0)
507static void transfer_to_cell_if(
int fd,
void *cell)
520static void transfer_to_cell_df(
int fd,
void *cell)
533static void transfer_to_cell_id(
int fd,
void *cell)
546static void transfer_to_cell_fd(
int fd,
void *cell)
563static int get_map_row_nomask(
int fd,
void *
rast,
int row,
567 {transfer_to_cell_XX, transfer_to_cell_if, transfer_to_cell_id},
568 {transfer_to_cell_fi, transfer_to_cell_XX, transfer_to_cell_fd},
569 {transfer_to_cell_di, transfer_to_cell_df, transfer_to_cell_XX}};
588 if (
r !=
fcb->cur_row) {
590 read_data(fd,
fcb->cur_row,
fcb->data, &
fcb->cur_nbytes);
598static void get_map_row_no_reclass(
int fd,
void *
rast,
int row,
602 get_map_row_nomask(fd,
rast, row, data_type);
628 if (!
fcb->reclass_flag)
678 get_map_row(fd, buf, row, data_type, 0, 0);
770 get_map_row(fd, buf, row, data_type, 0, 1);
834static int read_null_bits_compressed(
int null_fd,
unsigned char *flags,
int row,
839 off_t t2 =
fcb->null_row_ptr[row + 1];
846 _(
"Error seeking compressed null data for row %d of <%s>"), row,
851 (
unsigned int)res != size) {
853 _(
"Error reading compressed null data for row %d of <%s>"), row,
865 _(
"Error reading compressed null data for row %d of <%s>"), row,
871 G_fatal_error(
_(
"Error uncompressing null data for row %d of <%s>"),
884 int cols =
fcb->cellhd.cols;
889 if (compute_window_row(fd, row, &R) <= 0) {
899 if (
fcb->null_row_ptr)
900 return read_null_bits_compressed(
null_fd, flags, R, size, fd);
902 offset = (
off_t)size * R;
913#define check_null_bit(flags, bit_num) \
914 ((flags)[(bit_num) >> 3] & ((unsigned char)0x80 >> ((bit_num) & 7)) ? 1 : 0)
916static void get_null_value_row_nomask(
int fd,
char *flags,
int row)
922 G_warning(
_(
"Reading raster map <%s@%s> request for row %d is outside "
936 if (row !=
fcb->null_cur_row) {
938 fcb->null_cur_row = -1;
958 fcb->null_cur_row = row;
963 if (!
fcb->col_map[
j])
972static void get_null_value_row_gdal(
int fd,
char *flags,
int row)
986 flags[i] = !
fcb->col_map[i] ||
tmp_buf[i] ==
fcb->gdal->null_val ||
996static void embed_mask(
char *flags,
int row)
1023static void get_null_value_row(
int fd,
char *flags,
int row,
int with_mask)
1028 get_null_value_row_gdal(fd, flags, row);
1030 get_null_value_row_nomask(fd, flags, row);
1033 embed_mask(flags, row);
1089 if (!
fcb->reclass_flag)
1090 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 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)