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

📄 avc_bin.c

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 C
📖 第 1 页 / 共 5 页
字号:
/*===================================================================== *                              TOL *====================================================================*//********************************************************************** *                          _AVCBinReadNextTol() * * (This function is for internal library use... external calls should * go to AVCBinReadNextTol() instead) * * Read the next TOL (tolerance) structure from the file. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinReadNextTol(AVCRawBinFile *psFile, AVCTol *psTol,                        int nPrecision){    psTol->nIndex  = AVCRawBinReadInt32(psFile);    psTol->nFlag   = AVCRawBinReadInt32(psFile);    if (AVCRawBinEOF(psFile))        return -1;    if (nPrecision == AVC_SINGLE_PREC)    {        psTol->dValue  = AVCRawBinReadFloat(psFile);    }    else    {        psTol->dValue  = AVCRawBinReadDouble(psFile);    }    return 0;}/********************************************************************** *                          AVCBinReadNextTol() * * Read the next TOL structure from the file. * * Returns a pointer to a static AVCTol structure whose contents will be * valid only until the next call or NULL if an error happened or if EOF * was reached.   **********************************************************************/AVCTol *AVCBinReadNextTol(AVCBinFile *psFile){    if (psFile->eFileType != AVCFileTOL ||        AVCRawBinEOF(psFile->psRawBinFile) ||        _AVCBinReadNextTol(psFile->psRawBinFile, psFile->cur.psTol,                           psFile->nPrecision) !=0)    {        return NULL;    }    return psFile->cur.psTol;}/*===================================================================== *                              PRJ *====================================================================*//********************************************************************** *                          _AVCBinReadOpenPrj() * * (This function is for internal library use... external calls should * go to AVCBinReadOpen() with type AVCFilePRJ instead) * * Open a PRJ file.   * * This call will actually read the whole PRJ file in memory since PRJ * files are small text files. **********************************************************************/AVCBinFile *_AVCBinReadOpenPrj(const char *pszPath, const char *pszName){    AVCBinFile   *psFile;    char         *pszFname, **papszPrj;    /*-----------------------------------------------------------------     * Load the PRJ file contents into a stringlist.     *----------------------------------------------------------------*/    pszFname = (char*)CPLMalloc((strlen(pszPath)+strlen(pszName)+1)*                                sizeof(char));    sprintf(pszFname, "%s%s", pszPath, pszName);    papszPrj = CSLLoad(pszFname);    CPLFree(pszFname);    if (papszPrj == NULL)    {        /* Failed to open file... just return NULL since an error message         * has already been issued by CSLLoad()         */        return NULL;    }    /*-----------------------------------------------------------------     * Alloc and init the AVCBinFile handle.     *----------------------------------------------------------------*/    psFile = (AVCBinFile*)CPLCalloc(1, sizeof(AVCBinFile));    psFile->eFileType = AVCFilePRJ;    psFile->psRawBinFile = NULL;    psFile->cur.papszPrj = papszPrj;    psFile->pszFilename = NULL;    return psFile;}/********************************************************************** *                          AVCBinReadPrj() * * Return the contents of the previously opened PRJ (projection) file. * * PRJ files are simple text files with variable length lines, so we * don't use the AVCRawBin*() functions for this case. * * Returns a reference to a static stringlist with the whole file  * contents, or NULL in case of error. * * The returned stringlist should NOT be freed by the caller. **********************************************************************/char **AVCBinReadNextPrj(AVCBinFile *psFile){    /*-----------------------------------------------------------------     * The file should have already been loaded by AVCBinFileOpen(),     * so there is not much to do here!     *----------------------------------------------------------------*/    return psFile->cur.papszPrj;}/*===================================================================== *                              TXT/TX6/TX7 *====================================================================*//********************************************************************** *                          _AVCBinReadNextTxt() * * (This function is for internal library use... external calls should * go to AVCBinReadNextTxt() instead) * * Read the next TXT/TX6/TX7 (Annotation) structure from the file. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinReadNextTxt(AVCRawBinFile *psFile, AVCTxt *psTxt,                               int nPrecision){    int i, numVerticesBefore, numVertices, numCharsToRead, nRecordSize;    int numBytesRead;    numVerticesBefore = ABS(psTxt->numVerticesLine) +                         ABS(psTxt->numVerticesArrow);    psTxt->nTxtId  = AVCRawBinReadInt32(psFile);    if (AVCRawBinEOF(psFile))        return -1;    nRecordSize    = 8 + 2*AVCRawBinReadInt32(psFile);    psTxt->nUserId = AVCRawBinReadInt32(psFile);    psTxt->nLevel  = AVCRawBinReadInt32(psFile);    psTxt->f_1e2    = AVCRawBinReadFloat(psFile);    psTxt->nSymbol  = AVCRawBinReadInt32(psFile);    psTxt->numVerticesLine  = AVCRawBinReadInt32(psFile);    psTxt->n28      = AVCRawBinReadInt32(psFile);    psTxt->numChars = AVCRawBinReadInt32(psFile);    psTxt->numVerticesArrow = AVCRawBinReadInt32(psFile);    for(i=0; i<20; i++)    {        psTxt->anJust1[i] = AVCRawBinReadInt16(psFile);    }    for(i=0; i<20; i++)    {        psTxt->anJust2[i] = AVCRawBinReadInt16(psFile);    }    if (nPrecision == AVC_SINGLE_PREC)    {        psTxt->dHeight = AVCRawBinReadFloat(psFile);        psTxt->dV2     = AVCRawBinReadFloat(psFile);        psTxt->dV3     = AVCRawBinReadFloat(psFile);    }    else    {        psTxt->dHeight = AVCRawBinReadDouble(psFile);        psTxt->dV2     = AVCRawBinReadDouble(psFile);        psTxt->dV3     = AVCRawBinReadDouble(psFile);    }    numCharsToRead = ((int)(psTxt->numChars + 3)/4)*4;    if (psTxt->pszText == NULL ||        ((int)(strlen(psTxt->pszText)+3)/4)*4 < numCharsToRead )    {        psTxt->pszText = (char*)CPLRealloc(psTxt->pszText,                                           (numCharsToRead+1)*sizeof(char));    }    AVCRawBinReadString(psFile, numCharsToRead, psTxt->pszText);    psTxt->pszText[psTxt->numChars] = '\0';    /* Realloc the vertices array only if it needs to grow...     * do not realloc to a smaller size.     */    numVertices = ABS(psTxt->numVerticesLine) + ABS(psTxt->numVerticesArrow);    if (psTxt->pasVertices == NULL || numVertices > numVerticesBefore)        psTxt->pasVertices = (AVCVertex*)CPLRealloc(psTxt->pasVertices,                                              numVertices*sizeof(AVCVertex));    if (nPrecision == AVC_SINGLE_PREC)    {        for(i=0; i<numVertices; i++)        {            psTxt->pasVertices[i].x = AVCRawBinReadFloat(psFile);            psTxt->pasVertices[i].y = AVCRawBinReadFloat(psFile);        }    }    else    {        for(i=0; i<numVertices; i++)        {            psTxt->pasVertices[i].x = AVCRawBinReadDouble(psFile);            psTxt->pasVertices[i].y = AVCRawBinReadDouble(psFile);        }    }    /* In V7 Coverages, we always have 8 bytes of junk at end of record.     * In Weird coverages, these 8 bytes are sometimes present, and      * sometimes not!!! (Probably another AI "random feature"! ;-)     * So we use the record size to establish if there is any junk to skip     */    if (nPrecision == AVC_SINGLE_PREC)        numBytesRead = 132 + numCharsToRead + numVertices * 2 * 4;    else        numBytesRead = 144 + numCharsToRead + numVertices * 2 * 8;    if (numBytesRead < nRecordSize)        AVCRawBinFSeek(psFile, nRecordSize - numBytesRead, SEEK_CUR);    return 0;}/********************************************************************** *                          _AVCBinReadNextPCCoverageTxt() * * (This function is for internal library use... external calls should * go to AVCBinReadNextTxt() instead) * * Read the next TXT (Annotation) structure from a PC Coverage file. * Note that it is assumed that PC Coverage files are always single  * precision. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinReadNextPCCoverageTxt(AVCRawBinFile *psFile, AVCTxt *psTxt,                                  int nPrecision){    int i, numVerticesBefore, numVertices, numCharsToRead, nRecordSize;    numVerticesBefore = ABS(psTxt->numVerticesLine) +                         ABS(psTxt->numVerticesArrow);    psTxt->nTxtId  = AVCRawBinReadInt32(psFile);    if (AVCRawBinEOF(psFile))        return -1;    nRecordSize    = 8 + 2*AVCRawBinReadInt32(psFile);    psTxt->nUserId = 0;    psTxt->nLevel  = AVCRawBinReadInt32(psFile);    psTxt->numVerticesLine  = AVCRawBinReadInt32(psFile);      /* We are not expecting more than 4 vertices */    psTxt->numVerticesLine = MIN(psTxt->numVerticesLine, 4);    psTxt->numVerticesArrow = 0;    /* Realloc the vertices array only if it needs to grow...     * do not realloc to a smaller size.     *     * Note that because of the way V7 binary TXT files work, the rest of the     * lib expects to receive duplicate coords for the first vertex, so     * we have to include an additional vertex for that.     */    psTxt->numVerticesLine += 1;    numVertices = ABS(psTxt->numVerticesLine) + ABS(psTxt->numVerticesArrow);    if (psTxt->pasVertices == NULL || numVertices > numVerticesBefore)        psTxt->pasVertices = (AVCVertex*)CPLRealloc(psTxt->pasVertices,                                              numVertices*sizeof(AVCVertex));    for(i=1; i<numVertices; i++)    {        if (nPrecision == AVC_SINGLE_PREC)        {            psTxt->pasVertices[i].x = AVCRawBinReadFloat(psFile);            psTxt->pasVertices[i].y = AVCRawBinReadFloat(psFile);        }        else        {            psTxt->pasVertices[i].x = AVCRawBinReadDouble(psFile);            psTxt->pasVertices[i].y = AVCRawBinReadDouble(psFile);        }    }    /* Duplicate the first vertex because that's the way the other binary TXT     * files work and that's what the lib expects to generate the E00.     */    psTxt->pasVertices[0].x = psTxt->pasVertices[1].x;    psTxt->pasVertices[0].y = psTxt->pasVertices[1].y;    /* Skip the other floats (vertices) that are unused */    if (nPrecision == AVC_SINGLE_PREC)        AVCRawBinFSeek(psFile, 4*(15-2*(numVertices-1)) , SEEK_CUR);    else        AVCRawBinFSeek(psFile, 8*(15-2*(numVertices-1)) , SEEK_CUR);    if (nPrecision == AVC_SINGLE_PREC)    {        psTxt->dHeight  = AVCRawBinReadFloat(psFile);    }    else    {        psTxt->dHeight  = AVCRawBinReadDouble(psFile);    }    psTxt->f_1e2    = AVCRawBinReadFloat(psFile);    psTxt->nSymbol  = AVCRawBinReadInt32(psFile);    psTxt->numChars = AVCRawBinReadInt32(psFile);    /* In some cases, we may need to skip additional spaces after the     * text string... more than should be required to simply align with     * a 4 bytes boundary... include that in numCharsToRead     */    if (nPrecision == AVC_SINGLE_PREC)    {        numCharsToRead = nRecordSize - (28 + 16*4);    }    else    {        numCharsToRead = nRecordSize - (28 + 16*8);    }    /* Do a quick check in case file is corrupt! */    psTxt->numChars = MIN(psTxt->numChars, numCharsToRead);    if (psTxt->pszText == NULL ||        ((int)(strlen(psTxt->pszText)+3)/4)*4 < numCharsToRead )    {        psTxt->pszText = (char*)CPLRealloc(psTxt->pszText,                                           (numCharsToRead+5)*sizeof(char));    }    AVCRawBinReadString(psFile, numCharsToRead, psTxt->pszText);    psTxt->pszText[psTxt->numChars] = '\0';    /* Set unused members to default values...     */    psTxt->dV2     = 0.0;    psTxt->dV3     = 0.0;    psTxt->n28      = 0;    for(i=0; i<20; i++)

⌨️ 快捷键说明

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