Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: Erdas Imagine Driver 4 : * Purpose: Entry point for building overviews, used by non-imagine formats. 5 : * Author: Frank Warmerdam, warmerdam@pobox.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2005, Frank Warmerdam 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "cpl_port.h" 14 : #include "hfa_p.h" 15 : 16 : #include <cstddef> 17 : #include <string> 18 : 19 : #include "cpl_conv.h" 20 : #include "cpl_error.h" 21 : #include "cpl_progress.h" 22 : #include "cpl_string.h" 23 : #include "gdal.h" 24 : #include "gdal_pam.h" 25 : #include "gdal_priv.h" 26 : 27 5 : CPLErr HFAAuxBuildOverviews(const char *pszOvrFilename, GDALDataset *poParentDS, 28 : GDALDataset **ppoODS, int nBands, 29 : const int *panBandList, int nNewOverviews, 30 : const int *panNewOverviewList, 31 : const char *pszResampling, 32 : GDALProgressFunc pfnProgress, void *pProgressData, 33 : CSLConstList papszOptions) 34 : 35 : { 36 : // If the .aux file doesn't exist yet then create it now. 37 5 : if (*ppoODS == nullptr) 38 : { 39 4 : GDALDataType eDT = GDT_Unknown; 40 : // Determine the band datatype, and verify that all bands are the same. 41 8 : for (int iBand = 0; iBand < nBands; iBand++) 42 : { 43 : GDALRasterBand *poBand = 44 4 : poParentDS->GetRasterBand(panBandList[iBand]); 45 : 46 4 : if (iBand == 0) 47 : { 48 4 : eDT = poBand->GetRasterDataType(); 49 : } 50 : else 51 : { 52 0 : if (eDT != poBand->GetRasterDataType()) 53 : { 54 0 : CPLError(CE_Failure, CPLE_NotSupported, 55 : "HFAAuxBuildOverviews() doesn't support a " 56 : "mixture of band data types."); 57 0 : return CE_Failure; 58 : } 59 : } 60 : } 61 : 62 : // Create the HFA (.aux) file. We create it with 63 : // COMPRESSED=YES so that no space will be allocated for the 64 : // base band. 65 : GDALDriver *poHFADriver = 66 4 : static_cast<GDALDriver *>(GDALGetDriverByName("HFA")); 67 4 : if (poHFADriver == nullptr) 68 : { 69 0 : CPLError(CE_Failure, CPLE_AppDefined, "HFA driver is unavailable."); 70 0 : return CE_Failure; 71 : } 72 : 73 4 : CPLString osDepFileOpt = "DEPENDENT_FILE="; 74 4 : osDepFileOpt += CPLGetFilename(poParentDS->GetDescription()); 75 : 76 4 : const char *const apszOptions[4] = {"COMPRESSED=YES", "AUX=YES", 77 4 : osDepFileOpt.c_str(), nullptr}; 78 : 79 4 : *ppoODS = 80 4 : poHFADriver->Create(pszOvrFilename, poParentDS->GetRasterXSize(), 81 : poParentDS->GetRasterYSize(), 82 : poParentDS->GetRasterCount(), eDT, apszOptions); 83 : 84 4 : if (*ppoODS == nullptr) 85 0 : return CE_Failure; 86 : } 87 : 88 : // Create the layers. We depend on the normal buildoverviews 89 : // support for HFA to do this. But we disable the internal 90 : // computation of the imagery for these layers. 91 : // 92 : // We avoid regenerating the new layers here, because if we did 93 : // it would use the base layer from the .aux file as the source 94 : // data, and that is fake (all invalid tiles). 95 5 : CPLStringList aosOptions(papszOptions); 96 5 : aosOptions.SetNameValue("REGENERATE", "NO"); 97 : 98 5 : CPLErr eErr = (*ppoODS)->BuildOverviews( 99 : pszResampling, nNewOverviews, panNewOverviewList, nBands, panBandList, 100 5 : pfnProgress, pProgressData, aosOptions.List()); 101 : 102 5 : return eErr; 103 : }