⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridlib.cpp

📁 读写ArcInfo Binary Grid的c代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** * $Id: gridlib.c,v 1.21 2002/11/11 18:29:03 warmerda Exp $ * * Project:  Arc/Info Binary Grid Translator * Purpose:  Grid file reading code. * Author:   Frank Warmerdam, warmerdam@pobox.com * ****************************************************************************** * Copyright (c) 1999, Frank Warmerdam * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************** * * $Log: gridlib.c,v $ * Revision 1.21  2002/11/11 18:29:03  warmerda * added AIGLLOpen() to support upper case names too * * Revision 1.20  2002/11/05 03:19:08  warmerda * avoid nodata remapping in gridlib, use GInt32 not GUInt for image data * * Revision 1.19  2002/10/31 03:50:21  warmerda * fixed check in AIGProcessBlock * * Revision 1.18  2002/10/31 03:09:35  warmerda * added support for FF blocks * * Revision 1.17  2002/10/28 21:34:55  warmerda * made handling of corrupt files much more bulletproof * * Revision 1.16  2001/12/14 20:36:08  warmerda * fixed interpretation of the sign of short RMin values * * Revision 1.15  2001/07/18 04:51:56  warmerda * added CPL_CVSID * * Revision 1.14  2000/07/18 13:58:58  warmerda * no RTileType for float tiles * * Revision 1.13  2000/04/20 14:05:03  warmerda * added more raw float magic codes * * Revision 1.12  2000/03/15 02:00:52  warmerda * Added type 0x01 (untested). * * Revision 1.11  2000/02/18 14:47:25  warmerda * Avoid unused variable warnings. * * Revision 1.10  2000/02/18 14:41:00  warmerda * added support for 0xcf * * Revision 1.9  2000/02/18 05:05:16  warmerda * Do one time warning for unsupported tile types - don't blow assert * * Revision 1.8  2000/02/18 04:54:40  warmerda * Added support for 0xf0 (16bit run length encoded). * Fixed up handling of min value and no data values to be more generic. * * Revision 1.7  1999/08/13 03:28:12  warmerda * treat 0x3f to 0x43 as raw 32bit data * * Revision 1.6  1999/08/12 19:11:17  warmerda * corrected negative min handling, and no data values * * Revision 1.5  1999/08/09 16:30:44  warmerda * Modified 0x00 integer blocks to be treated as a constant min valued block. * * Revision 1.4  1999/04/21 16:51:30  warmerda * fixed up floating point support * * Revision 1.3  1999/03/02 21:10:28  warmerda * added some floating point support * * Revision 1.2  1999/02/04 22:15:33  warmerda * fleshed out implementation * * Revision 1.1  1999/02/03 14:12:56  warmerda * New * */#include "stdafx.h"#include "aigrid.h"CPL_CVSID("$Id: gridlib.c,v 1.21 2002/11/11 18:29:03 warmerda Exp $");/************************************************************************//*                    AIGProcessRaw32bitFloatBlock()                    *//*                                                                      *//*      Process a block using ``00'' (32 bit) raw format.               *//************************************************************************/static CPLErr AIGProcessRaw32BitFloatBlock( GByte *pabyCur, int nDataSize, int nMin,                                     int nBlockXSize, int nBlockYSize,                                     float * pafData ){    int		i;    (void) nDataSize;    (void) nMin;    CPLAssert( nDataSize >= nBlockXSize*nBlockYSize*4 );    /* -------------------------------------------------------------------- *//*      Collect raw data.                                               *//* -------------------------------------------------------------------- */    for( i = 0; i < nBlockXSize * nBlockYSize; i++ )    {        float	fWork;#ifdef CPL_LSB        ((GByte *) &fWork)[3] = *(pabyCur++);        ((GByte *) &fWork)[2] = *(pabyCur++);        ((GByte *) &fWork)[1] = *(pabyCur++);        ((GByte *) &fWork)[0] = *(pabyCur++);#else        ((GByte *) &fWork)[0] = *(pabyCur++);        ((GByte *) &fWork)[1] = *(pabyCur++);        ((GByte *) &fWork)[2] = *(pabyCur++);        ((GByte *) &fWork)[3] = *(pabyCur++);#endif                pafData[i] = fWork;    }    return( CE_None );}/************************************************************************//*                      AIGProcessIntConstBlock()                       *//*                                                                      *//*      Process a block using ``00'' constant 32bit integer format.     *//************************************************************************/static CPLErr AIGProcessIntConstBlock( GByte *pabyCur, int nDataSize, int nMin,                                int nBlockXSize, int nBlockYSize,                                GInt32 * panData ){    int		i;    (void) pabyCur;    (void) nDataSize;    CPLAssert( nDataSize <= 8 );    /* -------------------------------------------------------------------- *//*	Apply constant min value.					*//* -------------------------------------------------------------------- */    for( i = 0; i < nBlockXSize * nBlockYSize; i++ )        panData[i] = nMin;    return( CE_None );}/************************************************************************//*                         AIGProcess16bitRawBlock()                    *//*                                                                      *//*      Process a block using ``10'' (sixteen bit) raw format.          *//************************************************************************/static CPLErr AIGProcessRaw16BitBlock( GByte *pabyCur, int nDataSize, int nMin,                                int nBlockXSize, int nBlockYSize,                                GInt32 * panData ){    int		i;    (void) nDataSize;        CPLAssert( nDataSize >= nBlockXSize*nBlockYSize*2 );    /* -------------------------------------------------------------------- *//*      Collect raw data.                                               *//* -------------------------------------------------------------------- */    for( i = 0; i < nBlockXSize * nBlockYSize; i++ )    {        panData[i] = pabyCur[0] * 256 + pabyCur[1] + nMin;        pabyCur += 2;    }    return( CE_None );}/************************************************************************//*                         AIGProcess4BitRawBlock()                     *//*                                                                      *//*      Process a block using ``08'' raw format.                        *//************************************************************************/static CPLErr AIGProcessRaw4BitBlock( GByte *pabyCur, int nDataSize, int nMin,                               int nBlockXSize, int nBlockYSize,                               GInt32 * panData ){    int		i;    (void) nDataSize;    CPLAssert( nDataSize >= (nBlockXSize*nBlockYSize+1)/2 );    /* -------------------------------------------------------------------- *//*      Collect raw data.                                               *//* -------------------------------------------------------------------- */    for( i = 0; i < nBlockXSize * nBlockYSize; i++ )    {        if( i % 2 == 0 )            panData[i] = ((*(pabyCur) & 0xf0) >> 4) + nMin;        else            panData[i] = (*(pabyCur++) & 0xf) + nMin;    }    return( CE_None );}/************************************************************************//*                       AIGProcess1BitRawBlock()                       *//*                                                                      *//*      Process a block using ``0x01'' raw format.                      *//************************************************************************/static CPLErr AIGProcessRaw1BitBlock( GByte *pabyCur, int nDataSize, int nMin,                               int nBlockXSize, int nBlockYSize,                               GInt32 * panData ){    int		i;    (void) nDataSize;    CPLAssert( nDataSize >= (nBlockXSize*nBlockYSize+7)/8 );    /* -------------------------------------------------------------------- *//*      Collect raw data.                                               *//* -------------------------------------------------------------------- */    for( i = 0; i < nBlockXSize * nBlockYSize; i++ )    {        if( pabyCur[i>>3] & (0x80 >> (i&0x7)) )            panData[i] = 1;        else            panData[i] = 0;    }    return( CE_None );}/************************************************************************//*                         AIGProcessRawBlock()                         *//*                                                                      *//*      Process a block using ``08'' raw format.                        *//************************************************************************/static CPLErr AIGProcessRawBlock( GByte *pabyCur, int nDataSize, int nMin,                        int nBlockXSize, int nBlockYSize, GInt32 * panData ){    int		i;    (void) nDataSize;    CPLAssert( nDataSize >= nBlockXSize*nBlockYSize );    /* -------------------------------------------------------------------- *//*      Collect raw data.                                               *//* -------------------------------------------------------------------- */    for( i = 0; i < nBlockXSize * nBlockYSize; i++ )    {        panData[i] = *(pabyCur++) + nMin;    }    return( CE_None );}/************************************************************************//*                         AIGProcessFFBlock()                          *//*                                                                      *//*      Process a type 0xFF (CCITT RLE) compressed block.               *//************************************************************************/static CPLErr AIGProcessFFBlock( GByte *pabyCur, int nDataSize, int nMin,                          int nBlockXSize, int nBlockYSize,                          GInt32 * panData ){/* -------------------------------------------------------------------- *//*      Convert CCITT compress bitstream into 1bit raw data.            *//* -------------------------------------------------------------------- */    CPLErr eErr;    int i, nDstBytes = (nBlockXSize * nBlockYSize + 7) / 8;    unsigned char *pabyIntermediate;    pabyIntermediate = (unsigned char *) CPLMalloc(nDstBytes);        eErr = DecompressCCITTRLETile( pabyCur, nDataSize,                                    pabyIntermediate, nDstBytes,                                   nBlockXSize, nBlockYSize );    if( eErr != CE_None )        return eErr;/* -------------------------------------------------------------------- *//*      Convert the bit buffer into 32bit integers and account for      *//*      nMin.                                                           *//* -------------------------------------------------------------------- */    for( i = 0; i < nBlockXSize * nBlockYSize; i++ )    {        if( pabyIntermediate[i>>3] & (0x80 >> (i&0x7)) )            panData[i] = nMin+1;        else            panData[i] = nMin;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -