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 : * Permission is hereby granted, free of charge, to any person obtaining a
11 : * copy of this software and associated documentation files (the "Software"),
12 : * to deal in the Software without restriction, including without limitation
13 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 : * and/or sell copies of the Software, and to permit persons to whom the
15 : * Software is furnished to do so, subject to the following conditions:
16 : *
17 : * The above copyright notice and this permission notice shall be included
18 : * in all copies or substantial portions of the Software.
19 : *
20 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 : * DEALINGS IN THE SOFTWARE.
27 : ****************************************************************************/
28 :
29 : #include "cpl_port.h"
30 : #include "hfa_p.h"
31 :
32 : #include <cstddef>
33 : #include <string>
34 :
35 : #include "cpl_conv.h"
36 : #include "cpl_error.h"
37 : #include "cpl_progress.h"
38 : #include "cpl_string.h"
39 : #include "gdal.h"
40 : #include "gdal_pam.h"
41 : #include "gdal_priv.h"
42 :
43 5 : CPLErr HFAAuxBuildOverviews(const char *pszOvrFilename, GDALDataset *poParentDS,
44 : GDALDataset **ppoODS, int nBands,
45 : const int *panBandList, int nNewOverviews,
46 : const int *panNewOverviewList,
47 : const char *pszResampling,
48 : GDALProgressFunc pfnProgress, void *pProgressData,
49 : CSLConstList papszOptions)
50 :
51 : {
52 : // If the .aux file doesn't exist yet then create it now.
53 5 : if (*ppoODS == nullptr)
54 : {
55 4 : GDALDataType eDT = GDT_Unknown;
56 : // Determine the band datatype, and verify that all bands are the same.
57 8 : for (int iBand = 0; iBand < nBands; iBand++)
58 : {
59 : GDALRasterBand *poBand =
60 4 : poParentDS->GetRasterBand(panBandList[iBand]);
61 :
62 4 : if (iBand == 0)
63 : {
64 4 : eDT = poBand->GetRasterDataType();
65 : }
66 : else
67 : {
68 0 : if (eDT != poBand->GetRasterDataType())
69 : {
70 0 : CPLError(CE_Failure, CPLE_NotSupported,
71 : "HFAAuxBuildOverviews() doesn't support a "
72 : "mixture of band data types.");
73 0 : return CE_Failure;
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 : GDALDriver *poHFADriver =
82 4 : static_cast<GDALDriver *>(GDALGetDriverByName("HFA"));
83 4 : if (poHFADriver == nullptr)
84 : {
85 0 : CPLError(CE_Failure, CPLE_AppDefined, "HFA driver is unavailable.");
86 0 : return CE_Failure;
87 : }
88 :
89 4 : CPLString osDepFileOpt = "DEPENDENT_FILE=";
90 4 : osDepFileOpt += CPLGetFilename(poParentDS->GetDescription());
91 :
92 4 : const char *const apszOptions[4] = {"COMPRESSED=YES", "AUX=YES",
93 4 : osDepFileOpt.c_str(), nullptr};
94 :
95 4 : *ppoODS =
96 4 : poHFADriver->Create(pszOvrFilename, poParentDS->GetRasterXSize(),
97 : poParentDS->GetRasterYSize(),
98 : poParentDS->GetRasterCount(), eDT, apszOptions);
99 :
100 4 : if (*ppoODS == nullptr)
101 0 : return CE_Failure;
102 : }
103 :
104 : // Create the layers. We depend on the normal buildoverviews
105 : // support for HFA to do this. But we disable the internal
106 : // computation of the imagery for these layers.
107 : //
108 : // We avoid regenerating the new layers here, because if we did
109 : // it would use the base layer from the .aux file as the source
110 : // data, and that is fake (all invalid tiles).
111 5 : CPLStringList aosOptions(papszOptions);
112 5 : aosOptions.SetNameValue("REGENERATE", "NO");
113 :
114 5 : CPLErr eErr = (*ppoODS)->BuildOverviews(
115 : pszResampling, nNewOverviews, panNewOverviewList, nBands, panBandList,
116 5 : pfnProgress, pProgressData, aosOptions.List());
117 :
118 5 : return eErr;
119 : }
|