aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2016-01-24 17:27:40 +0100
committerEven Rouault <even.rouault@spatialys.com>2016-01-24 17:27:40 +0100
commit0f500a5950b6bbd2c05f61c12158f934f56b8d6e (patch)
tree6dd6ed5fe2dc4016b77cda6f1fbaa6ba21541fdf /src
parent832329a9aadbfcb7f46919c903f7672e719d2a82 (diff)
downloadPROJ-0f500a5950b6bbd2c05f61c12158f934f56b8d6e.tar.gz
PROJ-0f500a5950b6bbd2c05f61c12158f934f56b8d6e.zip
Add support for big-endian NTv2 grids (#345)
Diffstat (limited to 'src')
-rw-r--r--src/pj_gridinfo.c15
-rw-r--r--src/projects.h1
2 files changed, 12 insertions, 4 deletions
diff --git a/src/pj_gridinfo.c b/src/pj_gridinfo.c
index 958396ae..08eb80f3 100644
--- a/src/pj_gridinfo.c
+++ b/src/pj_gridinfo.c
@@ -312,7 +312,7 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
return 0;
}
- if( !IS_LSB )
+ if( gi->must_swap )
swap_words( (unsigned char *) row_buf, 4,
gi->ct->lim.lam*4 );
@@ -392,7 +392,7 @@ int pj_gridinfo_load( projCtx ctx, PJ_GRIDINFO *gi )
}
/************************************************************************/
-/* pj_gridinfo_init_ntv2() */
+/* pj_gridinfo_parent() */
/* */
/* Seek a parent grid file by name from a grid list */
/************************************************************************/
@@ -423,6 +423,7 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
{
unsigned char header[11*16];
int num_subfiles, subfile;
+ int must_swap;
assert( sizeof(int) == 4 );
assert( sizeof(double) == 8 );
@@ -442,11 +443,16 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
pj_ctx_set_errno( ctx, -38 );
return 0;
}
+
+ if( header[8] == 11 )
+ must_swap = !IS_LSB;
+ else
+ must_swap = IS_LSB;
/* -------------------------------------------------------------------- */
/* Byte swap interesting fields if needed. */
/* -------------------------------------------------------------------- */
- if( !IS_LSB )
+ if( must_swap )
{
swap_words( header+8, 4, 1 );
swap_words( header+8+16, 4, 1 );
@@ -490,7 +496,7 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
/* -------------------------------------------------------------------- */
/* Byte swap interesting fields if needed. */
/* -------------------------------------------------------------------- */
- if( !IS_LSB )
+ if( must_swap )
{
swap_words( header+8+16*4, 8, 1 );
swap_words( header+8+16*5, 8, 1 );
@@ -561,6 +567,7 @@ static int pj_gridinfo_init_ntv2( projCtx ctx, PAFile fid, PJ_GRIDINFO *gilist )
gi->next = NULL;
}
+ gi->must_swap = must_swap;
gi->ct = ct;
gi->format = "ntv2";
gi->grid_offset = pj_ctx_ftell( ctx, fid );
diff --git a/src/projects.h b/src/projects.h
index 0b1d5b3e..411a3403 100644
--- a/src/projects.h
+++ b/src/projects.h
@@ -371,6 +371,7 @@ typedef struct _pj_gi {
"ntv2" or "missing". */
int grid_offset; /* offset in file, for delayed loading */
+ int must_swap; /* only for NTv2 */
struct CTABLE *ct;