/src/gdal/frmts/hfa/hfa_overviews.cpp
Line  | Count  | Source (jump to first uncovered line)  | 
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  |  | 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  | 0  | { | 
36  |  |     // If the .aux file doesn't exist yet then create it now.  | 
37  | 0  |     if (*ppoODS == nullptr)  | 
38  | 0  |     { | 
39  | 0  |         GDALDataType eDT = GDT_Unknown;  | 
40  |  |         // Determine the band datatype, and verify that all bands are the same.  | 
41  | 0  |         for (int iBand = 0; iBand < nBands; iBand++)  | 
42  | 0  |         { | 
43  | 0  |             GDALRasterBand *poBand =  | 
44  | 0  |                 poParentDS->GetRasterBand(panBandList[iBand]);  | 
45  |  | 
  | 
46  | 0  |             if (iBand == 0)  | 
47  | 0  |             { | 
48  | 0  |                 eDT = poBand->GetRasterDataType();  | 
49  | 0  |             }  | 
50  | 0  |             else  | 
51  | 0  |             { | 
52  | 0  |                 if (eDT != poBand->GetRasterDataType())  | 
53  | 0  |                 { | 
54  | 0  |                     CPLError(CE_Failure, CPLE_NotSupported,  | 
55  | 0  |                              "HFAAuxBuildOverviews() doesn't support a "  | 
56  | 0  |                              "mixture of band data types.");  | 
57  | 0  |                     return CE_Failure;  | 
58  | 0  |                 }  | 
59  | 0  |             }  | 
60  | 0  |         }  | 
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  | 0  |         GDALDriver *poHFADriver =  | 
66  | 0  |             static_cast<GDALDriver *>(GDALGetDriverByName("HFA")); | 
67  | 0  |         if (poHFADriver == nullptr)  | 
68  | 0  |         { | 
69  | 0  |             CPLError(CE_Failure, CPLE_AppDefined, "HFA driver is unavailable.");  | 
70  | 0  |             return CE_Failure;  | 
71  | 0  |         }  | 
72  |  |  | 
73  | 0  |         CPLString osDepFileOpt = "DEPENDENT_FILE=";  | 
74  | 0  |         osDepFileOpt += CPLGetFilename(poParentDS->GetDescription());  | 
75  |  | 
  | 
76  | 0  |         const char *const apszOptions[4] = {"COMPRESSED=YES", "AUX=YES", | 
77  | 0  |                                             osDepFileOpt.c_str(), nullptr};  | 
78  |  | 
  | 
79  | 0  |         *ppoODS =  | 
80  | 0  |             poHFADriver->Create(pszOvrFilename, poParentDS->GetRasterXSize(),  | 
81  | 0  |                                 poParentDS->GetRasterYSize(),  | 
82  | 0  |                                 poParentDS->GetRasterCount(), eDT, apszOptions);  | 
83  |  | 
  | 
84  | 0  |         if (*ppoODS == nullptr)  | 
85  | 0  |             return CE_Failure;  | 
86  | 0  |     }  | 
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  | 0  |     CPLStringList aosOptions(papszOptions);  | 
96  | 0  |     aosOptions.SetNameValue("REGENERATE", "NO"); | 
97  |  | 
  | 
98  | 0  |     CPLErr eErr = (*ppoODS)->BuildOverviews(  | 
99  | 0  |         pszResampling, nNewOverviews, panNewOverviewList, nBands, panBandList,  | 
100  | 0  |         pfnProgress, pProgressData, aosOptions.List());  | 
101  |  | 
  | 
102  | 0  |     return eErr;  | 
103  | 0  | }  |