[GRASS-SVN] r52015 - in grass/trunk: include/Make include/defs lib/raster
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jun 8 14:07:02 PDT 2012
Author: glynn
Date: 2012-06-08 14:07:01 -0700 (Fri, 08 Jun 2012)
New Revision: 52015
Added:
grass/trunk/lib/raster/xdr.c
Modified:
grass/trunk/include/Make/Grass.make
grass/trunk/include/defs/raster.h
grass/trunk/lib/raster/R.h
grass/trunk/lib/raster/close.c
grass/trunk/lib/raster/get_row.c
grass/trunk/lib/raster/init.c
grass/trunk/lib/raster/open.c
grass/trunk/lib/raster/put_row.c
grass/trunk/lib/raster/range.c
Log:
Eliminate RPC/XDR dependency from raster library
Modified: grass/trunk/include/Make/Grass.make
===================================================================
--- grass/trunk/include/Make/Grass.make 2012-06-08 19:09:43 UTC (rev 52014)
+++ grass/trunk/include/Make/Grass.make 2012-06-08 21:07:01 UTC (rev 52015)
@@ -211,7 +211,7 @@
OGSFDEPS = $(BITMAPLIB) $(RASTER3DLIB) $(VECTORLIB) $(DBMILIB) $(RASTERLIB) $(GISLIB) $(FFMPEGLIBPATH) $(FFMPEGLIB) $(TIFFLIBPATH) $(TIFFLIB) $(OPENGLLIB) $(OPENGLULIB) $(MATHLIB)
PNGDRIVERDEPS = $(DRIVERLIB) $(GISLIB) $(PNGLIB) $(MATHLIB)
PSDRIVERDEPS = $(DRIVERLIB) $(GISLIB) $(MATHLIB)
-RASTERDEPS = $(GISLIB) $(XDRLIB) $(SOCKLIB) $(MATHLIB)
+RASTERDEPS = $(GISLIB) $(MATHLIB)
RLIDEPS = $(RASTERLIB) $(GISLIB) $(MATHLIB)
ROWIODEPS = $(GISLIB)
RTREEDEPS = $(GISLIB) $(MATHLIB)
Modified: grass/trunk/include/defs/raster.h
===================================================================
--- grass/trunk/include/defs/raster.h 2012-06-08 19:09:43 UTC (rev 52014)
+++ grass/trunk/include/defs/raster.h 2012-06-08 21:07:01 UTC (rev 52015)
@@ -578,6 +578,12 @@
void Rast__create_window_mapping(int);
int Rast_row_repeat_nomask(int, int);
+/* xdr.c */
+void Rast_xdr_get_float(float *, const void *);
+void Rast_xdr_put_float(void *, const float *);
+void Rast_xdr_get_double(double *, const void *);
+void Rast_xdr_put_double(void *, const double *);
+
/* zero_cell.c */
void Rast_zero_buf(void *, RASTER_MAP_TYPE);
void Rast_zero_input_buf(void *, RASTER_MAP_TYPE);
Modified: grass/trunk/lib/raster/R.h
===================================================================
--- grass/trunk/lib/raster/R.h 2012-06-08 19:09:43 UTC (rev 52014)
+++ grass/trunk/lib/raster/R.h 2012-06-08 21:07:01 UTC (rev 52015)
@@ -1,7 +1,6 @@
#include <grass/config.h>
#include <grass/gis.h>
#include <rpc/types.h>
-#include <rpc/xdr.h>
#ifdef HAVE_GDAL
#include <gdal.h>
#endif
@@ -65,7 +64,6 @@
char *name; /* Name of open file */
char *mapset; /* Mapset of open file */
int io_error; /* io error warning given */
- XDR xdrstream; /* xdr stream for reading fp */
struct Quant quant;
struct GDAL_link *gdal;
int data_fd; /* Raster data fd */
@@ -73,6 +71,7 @@
struct R__ /* Structure of library globals */
{
+ int little_endian; /* Flag denoting little-endian architecture */
RASTER_MAP_TYPE fp_type; /* type for writing floating maps */
int mask_fd; /* File descriptor for automatic mask */
int auto_mask; /* Flag denoting automatic masking */
Modified: grass/trunk/lib/raster/close.c
===================================================================
--- grass/trunk/lib/raster/close.c 2012-06-08 19:09:43 UTC (rev 52014)
+++ grass/trunk/lib/raster/close.c 2012-06-08 21:07:01 UTC (rev 52015)
@@ -168,7 +168,6 @@
if (fcb->map_type != CELL_TYPE) {
Rast_quant_free(&fcb->quant);
- xdr_destroy(&fcb->xdrstream);
}
close(fcb->data_fd);
Modified: grass/trunk/lib/raster/get_row.c
===================================================================
--- grass/trunk/lib/raster/get_row.c 2012-06-08 19:09:43 UTC (rev 52014)
+++ grass/trunk/lib/raster/get_row.c 2012-06-08 21:07:01 UTC (rev 52015)
@@ -16,7 +16,6 @@
#include <sys/types.h>
#include <rpc/types.h> /* need this for sgi */
-#include <rpc/xdr.h>
#include <grass/config.h>
#include <grass/raster.h>
@@ -283,37 +282,17 @@
void *cell, int n)
{
struct fileinfo *fcb = &R__.fileinfo[fd];
+ const float *work_buf = (const float *) fcb->data;
FCELL *c = cell;
- COLUMN_MAPPING cmapold = 0;
- XDR *xdrs = &fcb->xdrstream;
int i;
- /* xdr stream is initialized to read from */
- /* fcb->data in 'opencell.c' */
- xdr_setpos(xdrs, 0);
-
for (i = 0; i < n; i++) {
if (!cmap[i]) {
c[i] = 0;
continue;
}
- if (cmap[i] == cmapold) {
- c[i] = c[i - 1];
- continue;
- }
-
- if (cmap[i] < cmapold) {
- xdr_setpos(xdrs, 0);
- cmapold = 0;
- }
-
- while (cmapold++ != cmap[i]) /* skip */
- if (!xdr_float(xdrs, &c[i]))
- G_fatal_error(_("cell_values_float: xdr_float failed for index %d"),
- i);
-
- cmapold--;
+ Rast_xdr_get_float(&c[i], &work_buf[cmap[i]-1]);
}
}
@@ -322,37 +301,17 @@
void *cell, int n)
{
struct fileinfo *fcb = &R__.fileinfo[fd];
+ const double *work_buf = (const double *) fcb->data;
DCELL *c = cell;
- COLUMN_MAPPING cmapold = 0;
- XDR *xdrs = &fcb->xdrstream;
int i;
- /* xdr stream is initialized to read from */
- /* fcb->data in 'opencell.c' */
- xdr_setpos(xdrs, 0);
-
for (i = 0; i < n; i++) {
if (!cmap[i]) {
c[i] = 0;
continue;
}
- if (cmap[i] == cmapold) {
- c[i] = c[i - 1];
- continue;
- }
-
- if (cmap[i] < cmapold) {
- xdr_setpos(xdrs, 0);
- cmapold = 0;
- }
-
- while (cmapold++ != cmap[i]) /* skip */
- if (!xdr_double(xdrs, &c[i]))
- G_fatal_error(_("cell_values_double: xdr_double failed for index %d"),
- i);
-
- cmapold--;
+ Rast_xdr_get_double(&c[i], &work_buf[cmap[i]-1]);
}
}
Modified: grass/trunk/lib/raster/init.c
===================================================================
--- grass/trunk/lib/raster/init.c 2012-06-08 19:09:43 UTC (rev 52014)
+++ grass/trunk/lib/raster/init.c 2012-06-08 21:07:01 UTC (rev 52015)
@@ -80,6 +80,9 @@
{
Rast__init_window();
+ /* byte order */
+ R__.little_endian = G_is_little_endian();
+
/* no histograms */
R__.want_histogram = 0;
Modified: grass/trunk/lib/raster/open.c
===================================================================
--- grass/trunk/lib/raster/open.c 2012-06-08 19:09:43 UTC (rev 52014)
+++ grass/trunk/lib/raster/open.c 2012-06-08 21:07:01 UTC (rev 52015)
@@ -340,10 +340,6 @@
}
}
- if (fcb->map_type != CELL_TYPE)
- xdrmem_create(&fcb->xdrstream, (caddr_t) fcb->data,
- (u_int) (fcb->nbytes * fcb->cellhd.cols), XDR_DECODE);
-
return fd;
}
Modified: grass/trunk/lib/raster/put_row.c
===================================================================
--- grass/trunk/lib/raster/put_row.c 2012-06-08 19:09:43 UTC (rev 52014)
+++ grass/trunk/lib/raster/put_row.c 2012-06-08 21:07:01 UTC (rev 52015)
@@ -138,8 +138,8 @@
fcb->row_ptr[row] = lseek(fcb->data_fd, 0L, SEEK_CUR);
}
-static void convert_float(XDR * xdrs, char *null_buf, const FCELL * rast,
- int row, int n)
+static void convert_float(float *work_buf, int size, char *null_buf,
+ const FCELL *rast, int row, int n)
{
int i;
@@ -154,13 +154,12 @@
else
f = rast[i];
- if (!xdr_float(xdrs, &f))
- G_fatal_error(_("xdr_float failed for index %d of row %d"), i, row);
+ Rast_xdr_put_float(&work_buf[i], &f);
}
}
-static void convert_double(XDR * xdrs, char *null_buf, const DCELL * rast,
- int row, int n)
+static void convert_double(double *work_buf, int size, char *null_buf,
+ const DCELL *rast, int row, int n)
{
int i;
@@ -175,8 +174,7 @@
else
d = rast[i];
- if (!xdr_double(xdrs, &d))
- G_fatal_error(_("xdr_double failed for index %d of row %d"), i, row);
+ Rast_xdr_put_double(&work_buf[i], &d);
}
}
@@ -186,7 +184,7 @@
{
struct fileinfo *fcb = &R__.fileinfo[fd];
int compressed = (fcb->open_mode == OPEN_NEW_COMPRESSED);
- XDR *xdrs = &fcb->xdrstream;
+ int size = fcb->nbytes * fcb->cellhd.cols;
void *work_buf;
if (row < 0 || row >= fcb->cellhd.rows)
@@ -195,22 +193,16 @@
if (n <= 0)
return;
- work_buf = G__alloca(fcb->cellhd.cols * fcb->nbytes + 1);
+ work_buf = G__alloca(size + 1);
if (compressed)
set_file_pointer(fd, row);
- xdrmem_create(xdrs, work_buf,
- (unsigned int)fcb->nbytes * fcb->cellhd.cols, XDR_ENCODE);
- xdr_setpos(xdrs, 0);
-
if (data_type == FCELL_TYPE)
- convert_float(xdrs, null_buf, rast, row, n);
+ convert_float(work_buf, size, null_buf, rast, row, n);
else
- convert_double(xdrs, null_buf, rast, row, n);
+ convert_double(work_buf, size, null_buf, rast, row, n);
- xdr_destroy(&fcb->xdrstream);
-
if (compressed)
write_data_compressed(fd, row, work_buf, n);
else
Modified: grass/trunk/lib/raster/range.c
===================================================================
--- grass/trunk/lib/raster/range.c 2012-06-08 19:09:43 UTC (rev 52014)
+++ grass/trunk/lib/raster/range.c 2012-06-08 21:07:01 UTC (rev 52015)
@@ -13,7 +13,6 @@
#include <unistd.h>
#include <rpc/types.h> /* need this for sgi */
-#include <rpc/xdr.h>
#include <grass/raster.h>
#include <grass/glocale.h>
@@ -73,10 +72,10 @@
{
struct Range range;
int fd;
- char xdr_buf[100];
+ char xdr_buf[2][XDR_DOUBLE_NBYTES];
DCELL dcell1, dcell2;
- XDR xdr_str;
+ Rast_init();
Rast_init_fp_range(drange);
if (Rast_map_type(name, mapset) == CELL_TYPE) {
@@ -105,21 +104,17 @@
return -1;
}
- if (read(fd, xdr_buf, 2 * XDR_DOUBLE_NBYTES) != 2 * XDR_DOUBLE_NBYTES)
- return 2;
-
- xdrmem_create(&xdr_str, xdr_buf, (u_int) XDR_DOUBLE_NBYTES * 2,
- XDR_DECODE);
-
- /* if the f_range file exists, but empty */
- if (!xdr_double(&xdr_str, &dcell1) || !xdr_double(&xdr_str, &dcell2)) {
- if (fd)
- close(fd);
+ if (read(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) {
+ /* if the f_range file exists, but empty */
+ close(fd);
G_warning(_("Unable to read fp range file for <%s>"),
G_fully_qualified_name(name, mapset));
- return -1;
+ return 2;
}
+ Rast_xdr_get_double(&dcell1, xdr_buf[0]);
+ Rast_xdr_get_double(&dcell2, xdr_buf[1]);
+
Rast_update_fp_range(dcell1, drange);
Rast_update_fp_range(dcell2, drange);
close(fd);
@@ -292,9 +287,10 @@
void Rast_write_fp_range(const char *name, const struct FPRange *range)
{
int fd;
- char xdr_buf[100];
- XDR xdr_str;
+ char xdr_buf[2][XDR_DOUBLE_NBYTES];
+ Rast_init();
+
fd = G_open_new_misc("cell_misc", "f_range", name);
if (fd < 0) {
G_remove_misc("cell_misc", "f_range", name);
@@ -307,20 +303,14 @@
return;
}
- xdrmem_create(&xdr_str, xdr_buf, (u_int) XDR_DOUBLE_NBYTES * 2,
- XDR_ENCODE);
+ Rast_xdr_put_double(xdr_buf[0], &range->min);
+ Rast_xdr_put_double(xdr_buf[1], &range->max);
- if (!xdr_double(&xdr_str, (double *)&(range->min))) {
+ if (write(fd, xdr_buf, sizeof(xdr_buf)) != sizeof(xdr_buf)) {
G_remove_misc("cell_misc", "f_range", name);
G_fatal_error(_("Unable to write range file for <%s>"), name);
}
- if (!xdr_double(&xdr_str, (double *)&(range->max))) {
- G_remove_misc("cell_misc", "f_range", name);
- G_fatal_error(_("Unable to write range file for <%s>"), name);
- }
-
- write(fd, xdr_buf, XDR_DOUBLE_NBYTES * 2);
close(fd);
}
Added: grass/trunk/lib/raster/xdr.c
===================================================================
--- grass/trunk/lib/raster/xdr.c (rev 0)
+++ grass/trunk/lib/raster/xdr.c 2012-06-08 21:07:01 UTC (rev 52015)
@@ -0,0 +1,55 @@
+
+#include <grass/raster.h>
+
+#include "R.h"
+
+static void swap_float(void *dstp, const void *srcp) {
+ unsigned char *dst = (unsigned char *) dstp;
+ const unsigned char *src = (const unsigned char *) srcp;
+ if (R__.little_endian) {
+ dst[0] = src[3];
+ dst[1] = src[2];
+ dst[2] = src[1];
+ dst[3] = src[0];
+ }
+ else
+ *dst = *src;
+}
+
+static void swap_double(void *dstp, const void *srcp) {
+ unsigned char *dst = (unsigned char *) dstp;
+ const unsigned char *src = (const unsigned char *) srcp;
+ if (R__.little_endian) {
+ dst[0] = src[7];
+ dst[1] = src[6];
+ dst[2] = src[5];
+ dst[3] = src[4];
+ dst[4] = src[3];
+ dst[5] = src[2];
+ dst[6] = src[1];
+ dst[7] = src[0];
+ }
+ else
+ *dst = *src;
+}
+
+void Rast_xdr_get_float(float *dst, const void *src)
+{
+ swap_float(dst, src);
+}
+
+void Rast_xdr_put_float(void *dst, const float *src)
+{
+ swap_float(dst, src);
+}
+
+void Rast_xdr_get_double(double *dst, const void *src)
+{
+ swap_double(dst, src);
+}
+
+void Rast_xdr_put_double(void *dst, const double *src)
+{
+ swap_double(dst, src);
+}
+
Property changes on: grass/trunk/lib/raster/xdr.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list