static void read_data_gdal(int fd, int row, unsigned char *data_buf, int *nbytes) { struct fileinfo *fcb = &R__.fileinfo[fd]; unsigned char *buf; CPLErr err; *nbytes = fcb->nbytes; if (fcb->gdal->vflip) row = fcb->cellhd.rows - 1 - row; buf = fcb->gdal->hflip ? G_alloca(fcb->cellhd.cols * fcb->cur_nbytes) : data_buf; err = Rast_gdal_raster_IO(fcb->gdal->band, GF_Read, 0, row, fcb->cellhd.cols, 1, buf, fcb->cellhd.cols, 1, fcb->gdal->type, 0, 0); if (fcb->gdal->hflip) { int i; for (i = 0; i < fcb->cellhd.cols; i++) memcpy(data_buf + i * fcb->cur_nbytes, buf + (fcb->cellhd.cols - 1 - i) * fcb->cur_nbytes, fcb->cur_nbytes); G_freea(buf); } if (err != CE_None) G_fatal_error(_("Error reading raster data via GDAL for row %d of <%s>"), row, fcb->name); }
static void put_data_gdal(int fd, const void *rast, int row, int n, int zeros_r_nulls, RASTER_MAP_TYPE map_type) { #ifdef HAVE_GDAL struct fileinfo *fcb = &R__.fileinfo[fd]; int size = Rast_cell_size(map_type); DCELL null_val = fcb->gdal->null_val; const void *src; void *work_buf, *dst; GDALDataType datatype; CPLErr err; int i; if (row < 0 || row >= fcb->cellhd.rows) return; if (n <= 0) return; work_buf = G__alloca(n * size); switch (map_type) { case CELL_TYPE: datatype = GDT_Int32; break; case FCELL_TYPE: datatype = GDT_Float32; break; case DCELL_TYPE: datatype = GDT_Float64; break; } src = rast; dst = work_buf; for (i = 0; i < n; i++) { if (Rast_is_null_value(src, map_type) || (zeros_r_nulls && !*(CELL *) src)) Rast_set_d_value(dst, null_val, map_type); else memcpy(dst, src, size); src = G_incr_void_ptr(src, size); dst = G_incr_void_ptr(dst, size); } err = Rast_gdal_raster_IO(fcb->gdal->band, GF_Write, 0, row, n, 1, work_buf, n, 1, datatype, 0, 0); G__freea(work_buf); if (err != CE_None) G_fatal_error(_("Error writing data via GDAL for row %d of <%s>"), row, fcb->name); #endif }