Skip to content

Commit

Permalink
Add support for big-endian NTv2 grids (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 24, 2016
1 parent 832329a commit 0f500a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/pj_gridinfo.c
Expand Up @@ -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 );

Expand Down Expand Up @@ -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 */
/************************************************************************/
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/projects.h
Expand Up @@ -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;

Expand Down

0 comments on commit 0f500a5

Please sign in to comment.