Skip to content

Commit

Permalink
upgraded to use large file API and GUInt32 for block offsets
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.osgeo.org/gdal/trunk@8750 f0d54148-0727-0410-94bb-9a71ac55c965
  • Loading branch information
warmerdam committed Oct 31, 2005
1 parent 17a0bfc commit 5174fd6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
15 changes: 9 additions & 6 deletions frmts/aigrid/aigopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
******************************************************************************
*
* $Log$
* Revision 1.18 2005/10/31 04:51:55 fwarmerdam
* upgraded to use large file API and GUInt32 for block offsets
*
* Revision 1.17 2004/01/29 20:48:10 warmerda
* Make sure that if a bare "w001001.adf" is given to AIGOpen() it will
* work. The name is changed to ".".
Expand Down Expand Up @@ -166,7 +169,7 @@ AIGInfo_t *AIGOpen( const char * pszInputName, const char * pszAccess )
/* -------------------------------------------------------------------- */
if( AIGReadBlockIndex( pszCoverName, psInfo ) != CE_None )
{
VSIFClose( psInfo->fpGrid );
VSIFCloseL( psInfo->fpGrid );

CPLFree( psInfo );
return NULL;
Expand All @@ -177,7 +180,7 @@ AIGInfo_t *AIGOpen( const char * pszInputName, const char * pszAccess )
/* -------------------------------------------------------------------- */
if( AIGReadBounds( pszCoverName, psInfo ) != CE_None )
{
VSIFClose( psInfo->fpGrid );
VSIFCloseL( psInfo->fpGrid );

CPLFree( psInfo );
return NULL;
Expand All @@ -188,7 +191,7 @@ AIGInfo_t *AIGOpen( const char * pszInputName, const char * pszAccess )
/* -------------------------------------------------------------------- */
if( AIGReadStatistics( pszCoverName, psInfo ) != CE_None )
{
VSIFClose( psInfo->fpGrid );
VSIFCloseL( psInfo->fpGrid );

CPLFree( psInfo );
return NULL;
Expand Down Expand Up @@ -290,7 +293,7 @@ CPLErr AIGReadFloatTile( AIGInfo_t * psInfo, int nBlockXOff, int nBlockYOff,
void AIGClose( AIGInfo_t * psInfo )

{
VSIFClose( psInfo->fpGrid );
VSIFCloseL( psInfo->fpGrid );

CPLFree( psInfo->panBlockOffset );
CPLFree( psInfo->panBlockSize );
Expand All @@ -310,7 +313,7 @@ FILE *AIGLLOpen( const char *pszFilename, const char *pszAccess )
{
FILE *fp;

fp = VSIFOpen( pszFilename, pszAccess );
fp = VSIFOpenL( pszFilename, pszAccess );
if( fp == NULL )
{
char *pszUCFilename = CPLStrdup(pszFilename);
Expand All @@ -323,7 +326,7 @@ FILE *AIGLLOpen( const char *pszFilename, const char *pszAccess )
pszUCFilename[i] = (char) toupper(pszUCFilename[i]);
}

fp = VSIFOpen( pszUCFilename, pszAccess );
fp = VSIFOpenL( pszUCFilename, pszAccess );

CPLFree( pszUCFilename );
}
Expand Down
7 changes: 5 additions & 2 deletions frmts/aigrid/aigrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
******************************************************************************
*
* $Log$
* Revision 1.13 2005/10/31 04:51:55 fwarmerdam
* upgraded to use large file API and GUInt32 for block offsets
*
* Revision 1.12 2002/11/11 18:29:03 warmerda
* added AIGLLOpen() to support upper case names too
*
Expand Down Expand Up @@ -84,7 +87,7 @@ typedef struct {
/* Private information */

int nBlocks;
int *panBlockOffset;
GUInt32 *panBlockOffset;
int *panBlockSize;

FILE *fpGrid; /* the w001001.adf file */
Expand Down Expand Up @@ -128,7 +131,7 @@ typedef struct {
/* Private APIs */
/* ==================================================================== */

CPLErr AIGReadBlock( FILE * fp, int nBlockOffset, int nBlockSize,
CPLErr AIGReadBlock( FILE * fp, GUInt32 nBlockOffset, int nBlockSize,
int nBlockXSize, int nBlockYSize, GInt32 * panData,
int nCellType );

Expand Down
33 changes: 18 additions & 15 deletions frmts/aigrid/gridlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
******************************************************************************
*
* $Log$
* Revision 1.24 2005/10/31 04:51:55 fwarmerdam
* upgraded to use large file API and GUInt32 for block offsets
*
* Revision 1.23 2004/04/05 19:59:05 warmerda
* Fixed 0x01 support, wasn't including nMin.
*
Expand Down Expand Up @@ -582,7 +585,7 @@ CPLErr AIGProcessBlock( GByte *pabyCur, int nDataSize, int nMin, int nMagic,
/* Read a single block of integer grid data. */
/************************************************************************/

CPLErr AIGReadBlock( FILE * fp, int nBlockOffset, int nBlockSize,
CPLErr AIGReadBlock( FILE * fp, GUInt32 nBlockOffset, int nBlockSize,
int nBlockXSize, int nBlockYSize,
GInt32 *panData, int nCellType )

Expand All @@ -607,8 +610,8 @@ CPLErr AIGReadBlock( FILE * fp, int nBlockOffset, int nBlockSize,
/* Read the block into memory. */
/* -------------------------------------------------------------------- */
pabyRaw = (GByte *) CPLMalloc(nBlockSize+2);
if( VSIFSeek( fp, nBlockOffset, SEEK_SET ) != 0
|| VSIFRead( pabyRaw, nBlockSize+2, 1, fp ) != 1 )
if( VSIFSeekL( fp, nBlockOffset, SEEK_SET ) != 0
|| VSIFReadL( pabyRaw, nBlockSize+2, 1, fp ) != 1 )
{
memset( panData, 0, nBlockXSize*nBlockYSize*4 );
CPLError( CE_Failure, CPLE_AppDefined,
Expand Down Expand Up @@ -805,9 +808,9 @@ CPLErr AIGReadHeader( const char * pszCoverName, AIGInfo_t * psInfo )
/* long. */
/* -------------------------------------------------------------------- */

VSIFRead( abyData, 1, 308, fp );
VSIFReadL( abyData, 1, 308, fp );

VSIFClose( fp );
VSIFCloseL( fp );

/* -------------------------------------------------------------------- */
/* Read the block size information. */
Expand Down Expand Up @@ -872,8 +875,8 @@ CPLErr AIGReadBlockIndex( const char * pszCoverName, AIGInfo_t * psInfo )
/* -------------------------------------------------------------------- */
/* Get the file length (in 2 byte shorts) */
/* -------------------------------------------------------------------- */
VSIFSeek( fp, 24, SEEK_SET );
VSIFRead( &nValue, 1, 4, fp );
VSIFSeekL( fp, 24, SEEK_SET );
VSIFReadL( &nValue, 1, 4, fp );

nLength = CPL_MSBWORD32(nValue) * 2;

Expand All @@ -883,15 +886,15 @@ CPLErr AIGReadBlockIndex( const char * pszCoverName, AIGInfo_t * psInfo )
/* -------------------------------------------------------------------- */
psInfo->nBlocks = (nLength-100) / 8;
panIndex = (GUInt32 *) CPLMalloc(psInfo->nBlocks * 8);
VSIFSeek( fp, 100, SEEK_SET );
VSIFRead( panIndex, 8, psInfo->nBlocks, fp );
VSIFSeekL( fp, 100, SEEK_SET );
VSIFReadL( panIndex, 8, psInfo->nBlocks, fp );

VSIFClose( fp );
VSIFCloseL( fp );

/* -------------------------------------------------------------------- */
/* Allocate AIGInfo block info arrays. */
/* -------------------------------------------------------------------- */
psInfo->panBlockOffset = (int *) CPLMalloc(4 * psInfo->nBlocks);
psInfo->panBlockOffset = (GUInt32 *) CPLMalloc(4 * psInfo->nBlocks);
psInfo->panBlockSize = (int *) CPLMalloc(4 * psInfo->nBlocks);

/* -------------------------------------------------------------------- */
Expand Down Expand Up @@ -944,9 +947,9 @@ CPLErr AIGReadBounds( const char * pszCoverName, AIGInfo_t * psInfo )
/* -------------------------------------------------------------------- */
/* Get the contents - four doubles. */
/* -------------------------------------------------------------------- */
VSIFRead( adfBound, 1, 32, fp );
VSIFReadL( adfBound, 1, 32, fp );

VSIFClose( fp );
VSIFCloseL( fp );

#ifdef CPL_LSB
CPL_SWAPDOUBLE(adfBound+0);
Expand Down Expand Up @@ -1004,9 +1007,9 @@ CPLErr AIGReadStatistics( const char * pszCoverName, AIGInfo_t * psInfo )
/* -------------------------------------------------------------------- */
/* Get the contents - four doubles. */
/* -------------------------------------------------------------------- */
VSIFRead( adfStats, 1, 32, fp );
VSIFReadL( adfStats, 1, 32, fp );

VSIFClose( fp );
VSIFCloseL( fp );

#ifdef CPL_LSB
CPL_SWAPDOUBLE(adfStats+0);
Expand Down

0 comments on commit 5174fd6

Please sign in to comment.