LCOV - code coverage report
Current view: directory - frmts/ceos - ceosdataset.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 63 54 85.7 %
Date: 2012-04-28 Functions: 12 7 58.3 %

       1                 : /******************************************************************************
       2                 :  * $Id: ceosdataset.cpp 20504 2010-09-02 02:40:49Z warmerdam $
       3                 :  *
       4                 :  * Project:  CEOS Translator
       5                 :  * Purpose:  GDALDataset driver for CEOS translator.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 1999, Frank Warmerdam
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #include "ceosopen.h"
      31                 : #include "gdal_pam.h"
      32                 : 
      33                 : CPL_CVSID("$Id: ceosdataset.cpp 20504 2010-09-02 02:40:49Z warmerdam $");
      34                 : 
      35                 : CPL_C_START
      36                 : void  GDALRegister_CEOS(void);
      37                 : CPL_C_END
      38                 : 
      39                 : /************************************************************************/
      40                 : /* ==================================================================== */
      41                 : /*        CEOSDataset       */
      42                 : /* ==================================================================== */
      43                 : /************************************************************************/
      44                 : 
      45                 : class CEOSRasterBand;
      46                 : 
      47                 : class CEOSDataset : public GDALPamDataset
      48                 : {
      49                 :     friend class CEOSRasterBand;
      50                 :     
      51                 :     CEOSImage *psCEOS;
      52                 : 
      53                 :   public:
      54                 :                  CEOSDataset();
      55                 :                 ~CEOSDataset();
      56                 :     static GDALDataset *Open( GDALOpenInfo * );
      57                 : };
      58                 : 
      59                 : /************************************************************************/
      60                 : /* ==================================================================== */
      61                 : /*                            CEOSRasterBand                             */
      62                 : /* ==================================================================== */
      63                 : /************************************************************************/
      64                 : 
      65                 : class CEOSRasterBand : public GDALPamRasterBand
      66               8 : {
      67                 :     friend class CEOSDataset;
      68                 :     
      69                 :   public:
      70                 : 
      71                 :         CEOSRasterBand( CEOSDataset *, int );
      72                 :     
      73                 :     virtual CPLErr IReadBlock( int, int, void * );
      74                 : };
      75                 : 
      76                 : 
      77                 : /************************************************************************/
      78                 : /*                           CEOSRasterBand()                            */
      79                 : /************************************************************************/
      80                 : 
      81               8 : CEOSRasterBand::CEOSRasterBand( CEOSDataset *poDS, int nBand )
      82                 : 
      83                 : {
      84               8 :     this->poDS = poDS;
      85               8 :     this->nBand = nBand;
      86                 :     
      87               8 :     eDataType = GDT_Byte;
      88                 : 
      89               8 :     nBlockXSize = poDS->GetRasterXSize();
      90               8 :     nBlockYSize = 1;
      91               8 : }
      92                 : 
      93                 : /************************************************************************/
      94                 : /*                             IReadBlock()                             */
      95                 : /************************************************************************/
      96                 : 
      97               6 : CPLErr CEOSRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
      98                 :                                   void * pImage )
      99                 : 
     100                 : {
     101               6 :     CEOSDataset *poCEOS_DS = (CEOSDataset *) poDS;
     102                 : 
     103               6 :     CPLAssert( nBlockXOff == 0 );
     104                 : 
     105               6 :     return( CEOSReadScanline(poCEOS_DS->psCEOS, nBand, nBlockYOff+1, pImage) );
     106                 : }
     107                 : 
     108                 : /************************************************************************/
     109                 : /* ==================================================================== */
     110                 : /*                             CEOSDataset                              */
     111                 : /* ==================================================================== */
     112                 : /************************************************************************/
     113                 : 
     114                 : /************************************************************************/
     115                 : /*                            CEOSDataset()                             */
     116                 : /************************************************************************/
     117                 : 
     118               2 : CEOSDataset::CEOSDataset()
     119                 : 
     120                 : {
     121               2 :     psCEOS = NULL;
     122               2 : }
     123                 : 
     124                 : /************************************************************************/
     125                 : /*                            ~CEOSDataset()                            */
     126                 : /************************************************************************/
     127                 : 
     128               2 : CEOSDataset::~CEOSDataset()
     129                 : 
     130                 : {
     131               2 :     FlushCache();
     132               2 :     if( psCEOS )
     133               2 :         CEOSClose( psCEOS );
     134               2 : }
     135                 : 
     136                 : /************************************************************************/
     137                 : /*                                Open()                                */
     138                 : /************************************************************************/
     139                 : 
     140           26878 : GDALDataset *CEOSDataset::Open( GDALOpenInfo * poOpenInfo )
     141                 : 
     142                 : {
     143                 :     CEOSImage *psCEOS;
     144                 :     int   i;
     145                 :     
     146                 : /* -------------------------------------------------------------------- */
     147                 : /*      Before trying CEOSOpen() we first verify that the first         */
     148                 : /*      record is in fact a CEOS file descriptor record.                */
     149                 : /* -------------------------------------------------------------------- */
     150           26878 :     if( poOpenInfo->nHeaderBytes < 100 )
     151           22740 :         return NULL;
     152                 : 
     153            4144 :     if( poOpenInfo->pabyHeader[4] != 0x3f
     154               2 :         || poOpenInfo->pabyHeader[5] != 0xc0
     155               2 :         || poOpenInfo->pabyHeader[6] != 0x12
     156               2 :         || poOpenInfo->pabyHeader[7] != 0x12 )
     157            4136 :         return NULL;
     158                 : 
     159                 : /* -------------------------------------------------------------------- */
     160                 : /*      Try opening the dataset.                                        */
     161                 : /* -------------------------------------------------------------------- */
     162               2 :     psCEOS = CEOSOpen( poOpenInfo->pszFilename, "rb" );
     163                 :     
     164               2 :     if( psCEOS == NULL )
     165               0 :         return( NULL );
     166                 : 
     167               2 :     if( psCEOS->nBitsPerPixel != 8 )
     168                 :     {
     169                 :         CPLError( CE_Failure, CPLE_NotSupported, 
     170                 :                   "The CEOS driver cannot handle nBitsPerPixel = %d",
     171               0 :                   psCEOS->nBitsPerPixel );
     172               0 :         CEOSClose(psCEOS);
     173               0 :         return NULL;
     174                 :     }
     175                 : 
     176               2 :     if( !GDALCheckDatasetDimensions(psCEOS->nPixels, psCEOS->nBands) ||
     177                 :         !GDALCheckBandCount(psCEOS->nBands, FALSE) )
     178                 :     {
     179               0 :         CEOSClose( psCEOS );
     180               0 :         return NULL;
     181                 :     }
     182                 : 
     183                 : /* -------------------------------------------------------------------- */
     184                 : /*      Confirm the requested access is supported.                      */
     185                 : /* -------------------------------------------------------------------- */
     186               2 :     if( poOpenInfo->eAccess == GA_Update )
     187                 :     {
     188               0 :         CEOSClose(psCEOS);
     189                 :         CPLError( CE_Failure, CPLE_NotSupported, 
     190                 :                   "The CEOS driver does not support update access to existing"
     191               0 :                   " datasets.\n" );
     192               0 :         return NULL;
     193                 :     }
     194                 : /* -------------------------------------------------------------------- */
     195                 : /*      Create a corresponding GDALDataset.                             */
     196                 : /* -------------------------------------------------------------------- */
     197                 :     CEOSDataset   *poDS;
     198                 : 
     199               2 :     poDS = new CEOSDataset();
     200                 : 
     201               2 :     poDS->psCEOS = psCEOS;
     202                 :     
     203                 : /* -------------------------------------------------------------------- */
     204                 : /*      Capture some information from the file that is of interest.     */
     205                 : /* -------------------------------------------------------------------- */
     206               2 :     poDS->nRasterXSize = psCEOS->nPixels;
     207               2 :     poDS->nRasterYSize = psCEOS->nLines;
     208                 :     
     209                 : /* -------------------------------------------------------------------- */
     210                 : /*      Create band information objects.                                */
     211                 : /* -------------------------------------------------------------------- */
     212               2 :     poDS->nBands = psCEOS->nBands;;
     213                 : 
     214              20 :     for( i = 0; i < poDS->nBands; i++ )
     215               8 :         poDS->SetBand( i+1, new CEOSRasterBand( poDS, i+1 ) );
     216                 : 
     217                 : /* -------------------------------------------------------------------- */
     218                 : /*      Initialize any PAM information.                                 */
     219                 : /* -------------------------------------------------------------------- */
     220               2 :     poDS->SetDescription( poOpenInfo->pszFilename );
     221               2 :     poDS->TryLoadXML();
     222                 : 
     223                 : /* -------------------------------------------------------------------- */
     224                 : /*      Check for overviews.                                            */
     225                 : /* -------------------------------------------------------------------- */
     226               2 :     poDS->oOvManager.Initialize( poDS, poOpenInfo->pszFilename );
     227                 : 
     228               2 :     return( poDS );
     229                 : }
     230                 : 
     231                 : /************************************************************************/
     232                 : /*                          GDALRegister_GTiff()                        */
     233                 : /************************************************************************/
     234                 : 
     235            1135 : void GDALRegister_CEOS()
     236                 : 
     237                 : {
     238                 :     GDALDriver  *poDriver;
     239                 : 
     240            1135 :     if( GDALGetDriverByName( "CEOS" ) == NULL )
     241                 :     {
     242            1093 :         poDriver = new GDALDriver();
     243                 :         
     244            1093 :         poDriver->SetDescription( "CEOS" );
     245                 :         poDriver->SetMetadataItem( GDAL_DMD_LONGNAME, 
     246            1093 :                                    "CEOS Image" );
     247                 :         poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC, 
     248            1093 :                                    "frmt_various.html#CEOS" );
     249            1093 :         poDriver->SetMetadataItem( GDAL_DCAP_VIRTUALIO, "YES" );
     250                 :         
     251            1093 :         poDriver->pfnOpen = CEOSDataset::Open;
     252                 : 
     253            1093 :         GetGDALDriverManager()->RegisterDriver( poDriver );
     254                 :     }
     255            1135 : }

Generated by: LCOV version 1.7