LCOV - code coverage report
Current view: directory - frmts/hfa - hfa_overviews.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 25 19 76.0 %
Date: 2011-12-18 Functions: 1 1 100.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: hfa_overviews.cpp 18859 2010-02-19 19:41:06Z warmerdam $
       3                 :  *
       4                 :  * Project:  Erdas Imagine Driver
       5                 :  * Purpose:  Entry point for building overviews, used by non-imagine formats.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2005, 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 "gdal_pam.h"
      31                 : #include "hfa_p.h"
      32                 : #include "cpl_string.h"
      33                 : 
      34                 : CPL_CVSID("$Id: hfa_overviews.cpp 18859 2010-02-19 19:41:06Z warmerdam $");
      35                 : 
      36               2 : CPLErr HFAAuxBuildOverviews( const char *pszOvrFilename, 
      37                 :                              GDALDataset *poParentDS,
      38                 :                              GDALDataset **ppoODS,
      39                 :                              int nBands, int *panBandList,
      40                 :                              int nNewOverviews, int *panNewOverviewList, 
      41                 :                              const char *pszResampling, 
      42                 :                              GDALProgressFunc pfnProgress, 
      43                 :                              void *pProgressData )
      44                 : 
      45                 : {
      46                 : /* ==================================================================== */
      47                 : /*      If the .aux file doesn't exist yet then create it now.          */
      48                 : /* ==================================================================== */
      49               2 :     if( *ppoODS == NULL )
      50                 :     {
      51               2 :         GDALDataType eDT = GDT_Unknown;
      52                 : /* -------------------------------------------------------------------- */
      53                 : /*      Determine the band datatype, and verify that all bands are      */
      54                 : /*      the same.                                                       */
      55                 : /* -------------------------------------------------------------------- */
      56                 :         int iBand;
      57                 : 
      58               4 :         for( iBand = 0; iBand < nBands; iBand++ )
      59                 :         {
      60                 :             GDALRasterBand *poBand = 
      61               2 :                 poParentDS->GetRasterBand( panBandList[iBand] );
      62                 : 
      63               2 :             if( iBand == 0 )
      64               2 :                 eDT = poBand->GetRasterDataType();
      65                 :             else
      66                 :             {
      67               0 :                 if( eDT != poBand->GetRasterDataType() )
      68                 :                 {
      69                 :                     CPLError( CE_Failure, CPLE_NotSupported, 
      70                 :                               "HFAAuxBuildOverviews() doesn't support a mixture of band"
      71               0 :                               " data types." );
      72               0 :                     return CE_Failure;
      73                 :                 }
      74                 :             }
      75                 :         }
      76                 : 
      77                 : /* -------------------------------------------------------------------- */
      78                 : /*      Create the HFA (.aux) file.  We create it with                  */
      79                 : /*      COMPRESSED=YES so that no space will be allocated for the       */
      80                 : /*      base band.                                                      */
      81                 : /* -------------------------------------------------------------------- */
      82               2 :         GDALDriver *poHFADriver = (GDALDriver *) GDALGetDriverByName("HFA");
      83               2 :         if (poHFADriver == NULL)
      84                 :         {
      85                 :             CPLError( CE_Failure, CPLE_AppDefined, 
      86               0 :                       "HFA driver is unavailable." );
      87               0 :             return CE_Failure;
      88                 :         }
      89                 :         
      90                 :         const char *apszOptions[4] = { "COMPRESSED=YES", "AUX=YES", 
      91               2 :                                        NULL, NULL };
      92                 :         
      93               2 :         CPLString osDepFileOpt = "DEPENDENT_FILE=";
      94               2 :         osDepFileOpt += CPLGetFilename(poParentDS->GetDescription());
      95               2 :         apszOptions[2] = osDepFileOpt.c_str();
      96                 : 
      97                 :         *ppoODS = 
      98                 :             poHFADriver->Create( pszOvrFilename, 
      99                 :                                  poParentDS->GetRasterXSize(), 
     100                 :                                  poParentDS->GetRasterYSize(), 
     101               2 :                                  nBands, eDT, (char **)apszOptions );
     102                 : 
     103               2 :         if( *ppoODS == NULL )
     104               0 :             return CE_Failure;
     105                 :     }
     106                 : 
     107                 : /* ==================================================================== */
     108                 : /*      Create the layers.  We depend on the normal buildoverviews      */
     109                 : /*      support for HFA to do this.  But we disable the internal        */
     110                 : /*      computation of the imagery for these layers.                    */
     111                 : /*                                                                      */
     112                 : /*      We avoid regenerating the new layers here, because if we did    */
     113                 : /*      it would use the base layer from the .aux file as the source    */
     114                 : /*      data, and that is fake (all invalid tiles).                     */
     115                 : /* ==================================================================== */
     116               2 :     CPLString oAdjustedResampling = "NO_REGEN:";
     117               2 :     oAdjustedResampling += pszResampling;
     118                 : 
     119                 :     CPLErr eErr = 
     120                 :         (*ppoODS)->BuildOverviews( oAdjustedResampling,
     121                 :                                    nNewOverviews, panNewOverviewList,
     122                 :                                    nBands, panBandList,
     123               2 :                                    pfnProgress, pProgressData );
     124                 : 
     125               2 :     return eErr;
     126                 : }
     127                 : 

Generated by: LCOV version 1.7