Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: GDAL Core
4 : * Purpose: GDAL Core C++/Private declarations
5 : * Author: Even Rouault <even dot rouault at spatialys.com>
6 : *
7 : ******************************************************************************
8 : * Copyright (c) 2008-2014, Even Rouault <even dot rouault at spatialys.com>
9 : *
10 : * SPDX-License-Identifier: MIT
11 : ****************************************************************************/
12 :
13 : #ifndef GDAL_PROXY_H_INCLUDED
14 : #define GDAL_PROXY_H_INCLUDED
15 :
16 : #ifndef DOXYGEN_SKIP
17 :
18 : #include "gdal.h"
19 :
20 : #ifdef __cplusplus
21 :
22 : #include "gdal_priv.h"
23 : #include "cpl_hash_set.h"
24 :
25 : /* ******************************************************************** */
26 : /* GDALProxyDataset */
27 : /* ******************************************************************** */
28 :
29 : class CPL_DLL GDALProxyDataset : public GDALDataset
30 : {
31 : protected:
32 6252 : GDALProxyDataset()
33 6252 : {
34 6252 : }
35 :
36 : virtual GDALDataset *RefUnderlyingDataset() const = 0;
37 : virtual void UnrefUnderlyingDataset(GDALDataset *poUnderlyingDataset) const;
38 :
39 : CPLErr IBuildOverviews(const char *, int, const int *, int, const int *,
40 : GDALProgressFunc, void *,
41 : CSLConstList papszOptions) override;
42 : CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
43 : GDALDataType, int, BANDMAP_TYPE, GSpacing, GSpacing,
44 : GSpacing, GDALRasterIOExtraArg *psExtraArg) override;
45 : CPLErr BlockBasedRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff,
46 : int nXSize, int nYSize, void *pData,
47 : int nBufXSize, int nBufYSize,
48 : GDALDataType eBufType, int nBandCount,
49 : const int *panBandMap, GSpacing nPixelSpace,
50 : GSpacing nLineSpace, GSpacing nBandSpace,
51 : GDALRasterIOExtraArg *psExtraArg) override;
52 :
53 : public:
54 : CPLErr Close(GDALProgressFunc, void *) override;
55 : bool GetCloseReportsProgress() const override;
56 :
57 : char **GetMetadataDomainList() override;
58 : CSLConstList GetMetadata(const char *pszDomain) override;
59 : CPLErr SetMetadata(CSLConstList papszMetadata,
60 : const char *pszDomain) override;
61 : const char *GetMetadataItem(const char *pszName,
62 : const char *pszDomain) override;
63 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
64 : const char *pszDomain) override;
65 :
66 : CPLErr FlushCache(bool bAtClosing) override;
67 :
68 : const OGRSpatialReference *GetSpatialRef() const override;
69 : CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
70 :
71 : CPLErr GetGeoTransform(GDALGeoTransform &) const override;
72 : CPLErr SetGeoTransform(const GDALGeoTransform &) override;
73 :
74 : void *GetInternalHandle(const char *) override;
75 : GDALDriver *GetDriver() const override;
76 : char **GetFileList() override;
77 :
78 : int GetGCPCount() override;
79 : const OGRSpatialReference *GetGCPSpatialRef() const override;
80 : const GDAL_GCP *GetGCPs() override;
81 : CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
82 : const OGRSpatialReference *poGCP_SRS) override;
83 :
84 : CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
85 : int nBufXSize, int nBufYSize, GDALDataType eDT,
86 : int nBandCount, int *panBandList,
87 : CSLConstList papszOptions) override;
88 :
89 : CPLErr CreateMaskBand(int nFlags) override;
90 :
91 : virtual CPLStringList
92 : GetCompressionFormats(int nXOff, int nYOff, int nXSize, int nYSize,
93 : int nBandCount, const int *panBandList) override;
94 : virtual CPLErr ReadCompressedData(const char *pszFormat, int nXOff,
95 : int nYOff, int nXSize, int nYSize,
96 : int nBandCount, const int *panBandList,
97 : void **ppBuffer, size_t *pnBufferSize,
98 : char **ppszDetailedFormat) override;
99 :
100 : private:
101 : CPL_DISALLOW_COPY_ASSIGN(GDALProxyDataset)
102 : };
103 :
104 : /* ******************************************************************** */
105 : /* GDALProxyRasterBand */
106 : /* ******************************************************************** */
107 :
108 : class CPL_DLL GDALProxyRasterBand : public GDALRasterBand
109 : {
110 : protected:
111 108420 : GDALProxyRasterBand()
112 108420 : {
113 108420 : }
114 :
115 : virtual GDALRasterBand *
116 : RefUnderlyingRasterBand(bool bForceOpen = true) const = 0;
117 : virtual void
118 : UnrefUnderlyingRasterBand(GDALRasterBand *poUnderlyingRasterBand) const;
119 :
120 : CPLErr IReadBlock(int, int, void *) override;
121 : CPLErr IWriteBlock(int, int, void *) override;
122 : CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
123 : GDALDataType, GSpacing, GSpacing,
124 : GDALRasterIOExtraArg *psExtraArg) override;
125 :
126 : int IGetDataCoverageStatus(int nXOff, int nYOff, int nXSize, int nYSize,
127 : int nMaskFlagStop, double *pdfDataPct) override;
128 :
129 : public:
130 : char **GetMetadataDomainList() override;
131 : CSLConstList GetMetadata(const char *pszDomain) override;
132 : CPLErr SetMetadata(CSLConstList papszMetadata,
133 : const char *pszDomain) override;
134 : const char *GetMetadataItem(const char *pszName,
135 : const char *pszDomain) override;
136 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
137 : const char *pszDomain) override;
138 :
139 : GDALRasterBlock *GetLockedBlockRef(int nXBlockOff, int nYBlockOff,
140 : int bJustInitialize) override;
141 :
142 : GDALRasterBlock *TryGetLockedBlockRef(int nXBlockOff,
143 : int nYBlockYOff) override;
144 :
145 : CPLErr FlushBlock(int nXBlockOff, int nYBlockOff,
146 : int bWriteDirtyBlock) override;
147 :
148 : CPLErr FlushCache(bool bAtClosing) override;
149 : char **GetCategoryNames() override;
150 : double GetNoDataValue(int *pbSuccess = nullptr) override;
151 : double GetMinimum(int *pbSuccess = nullptr) override;
152 : double GetMaximum(int *pbSuccess = nullptr) override;
153 : double GetOffset(int *pbSuccess = nullptr) override;
154 : double GetScale(int *pbSuccess = nullptr) override;
155 : const char *GetUnitType() override;
156 : GDALColorInterp GetColorInterpretation() override;
157 : GDALColorTable *GetColorTable() override;
158 : CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0) override;
159 :
160 : CPLErr SetCategoryNames(char **) override;
161 : CPLErr SetNoDataValue(double) override;
162 : CPLErr DeleteNoDataValue() override;
163 : CPLErr SetColorTable(GDALColorTable *) override;
164 : CPLErr SetColorInterpretation(GDALColorInterp) override;
165 : CPLErr SetOffset(double) override;
166 : CPLErr SetScale(double) override;
167 : CPLErr SetUnitType(const char *) override;
168 :
169 : CPLErr GetStatistics(int bApproxOK, int bForce, double *pdfMin,
170 : double *pdfMax, double *pdfMean,
171 : double *padfStdDev) override;
172 : CPLErr ComputeStatistics(int bApproxOK, double *pdfMin, double *pdfMax,
173 : double *pdfMean, double *pdfStdDev,
174 : GDALProgressFunc, void *pProgressData) override;
175 : CPLErr SetStatistics(double dfMin, double dfMax, double dfMean,
176 : double dfStdDev) override;
177 : CPLErr ComputeRasterMinMax(int, double *) override;
178 :
179 : int HasArbitraryOverviews() override;
180 : int GetOverviewCount() override;
181 : GDALRasterBand *GetOverview(int) override;
182 : GDALRasterBand *GetRasterSampleOverview(GUIntBig) override;
183 : CPLErr BuildOverviews(const char *, int, const int *, GDALProgressFunc,
184 : void *, CSLConstList papszOptions) override;
185 :
186 : CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
187 : int nBufXSize, int nBufYSize, GDALDataType eDT,
188 : CSLConstList papszOptions) override;
189 :
190 : CPLErr GetHistogram(double dfMin, double dfMax, int nBuckets,
191 : GUIntBig *panHistogram, int bIncludeOutOfRange,
192 : int bApproxOK, GDALProgressFunc,
193 : void *pProgressData) override;
194 :
195 : CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax, int *pnBuckets,
196 : GUIntBig **ppanHistogram, int bForce,
197 : GDALProgressFunc, void *pProgressData) override;
198 : CPLErr SetDefaultHistogram(double dfMin, double dfMax, int nBuckets,
199 : GUIntBig *panHistogram) override;
200 :
201 : GDALRasterAttributeTable *GetDefaultRAT() override;
202 : CPLErr SetDefaultRAT(const GDALRasterAttributeTable *) override;
203 :
204 : GDALRasterBand *GetMaskBand() override;
205 : int GetMaskFlags() override;
206 : CPLErr CreateMaskBand(int nFlags) override;
207 : bool IsMaskBand() const override;
208 : GDALMaskValueRange GetMaskValueRange() const override;
209 :
210 : CPLVirtualMem *GetVirtualMemAuto(GDALRWFlag eRWFlag, int *pnPixelSpace,
211 : GIntBig *pnLineSpace,
212 : CSLConstList papszOptions) override;
213 :
214 : CPLErr InterpolateAtPoint(double dfPixel, double dfLine,
215 : GDALRIOResampleAlg eInterpolation,
216 : double *pdfRealValue,
217 : double *pdfImagValue) const override;
218 :
219 : void EnablePixelTypeSignedByteWarning(bool b) override;
220 :
221 : private:
222 : CPL_DISALLOW_COPY_ASSIGN(GDALProxyRasterBand)
223 : };
224 :
225 : /* ******************************************************************** */
226 : /* GDALProxyPoolDataset */
227 : /* ******************************************************************** */
228 :
229 : typedef struct _GDALProxyPoolCacheEntry GDALProxyPoolCacheEntry;
230 : class GDALProxyPoolRasterBand;
231 :
232 : class CPL_DLL GDALProxyPoolDataset /* non final */ : public GDALProxyDataset
233 : {
234 : private:
235 : GIntBig responsiblePID = -1;
236 : mutable char *pszProjectionRef = nullptr;
237 : const CPLStringList m_aosAllowedDrivers;
238 : mutable OGRSpatialReference *m_poSRS = nullptr;
239 : mutable OGRSpatialReference *m_poGCPSRS = nullptr;
240 : GDALGeoTransform m_gt{};
241 : bool m_bHasSrcSRS = false;
242 : bool m_bHasSrcGeoTransform = false;
243 : char *pszGCPProjection = nullptr;
244 : int nGCPCount = 0;
245 : GDAL_GCP *pasGCPList = nullptr;
246 : CPLHashSet *metadataSet = nullptr;
247 : CPLHashSet *metadataItemSet = nullptr;
248 :
249 : mutable GDALProxyPoolCacheEntry *cacheEntry = nullptr;
250 : char *m_pszOwner = nullptr;
251 :
252 : GDALDataset *RefUnderlyingDataset(bool bForceOpen) const;
253 :
254 : GDALProxyPoolDataset(const char *pszSourceDatasetDescription,
255 : GDALAccess eAccess, int bShared, const char *pszOwner,
256 : CSLConstList papszAllowedDrivers);
257 :
258 : protected:
259 : GDALDataset *RefUnderlyingDataset() const override;
260 : void
261 : UnrefUnderlyingDataset(GDALDataset *poUnderlyingDataset) const override;
262 :
263 : friend class GDALProxyPoolRasterBand;
264 :
265 : public:
266 : GDALProxyPoolDataset(const char *pszSourceDatasetDescription,
267 : int nRasterXSize, int nRasterYSize,
268 : GDALAccess eAccess = GA_ReadOnly, int bShared = FALSE,
269 : const char *pszProjectionRef = nullptr,
270 : const GDALGeoTransform *pGT = nullptr,
271 : const char *pszOwner = nullptr,
272 : CSLConstList papszAllowedDrivers = nullptr);
273 :
274 : static GDALProxyPoolDataset *
275 : Create(const char *pszSourceDatasetDescription,
276 : CSLConstList papszOpenOptions = nullptr,
277 : GDALAccess eAccess = GA_ReadOnly, int bShared = FALSE,
278 : const char *pszOwner = nullptr,
279 : CSLConstList papszAllowedDrivers = nullptr);
280 :
281 : ~GDALProxyPoolDataset() override;
282 :
283 : void SetOpenOptions(CSLConstList papszOpenOptions);
284 :
285 : // If size (nBlockXSize&nBlockYSize) parameters is zero
286 : // they will be loaded when RefUnderlyingRasterBand function is called.
287 : // But in this case we cannot use them in other non-virtual methods before
288 : // RefUnderlyingRasterBand fist call.
289 : void AddSrcBandDescription(GDALDataType eDataType, int nBlockXSize,
290 : int nBlockYSize);
291 :
292 : // Used by VRT SimpleSource to add a single GDALProxyPoolRasterBand while
293 : // keeping all other bands initialized to a nullptr. This is under the
294 : // assumption, VRT SimpleSource will not have to access any other bands than
295 : // the one added.
296 : void AddSrcBand(int nBand, GDALDataType eDataType, int nBlockXSize,
297 : int nBlockYSize);
298 : CPLErr FlushCache(bool bAtClosing) override;
299 :
300 : const OGRSpatialReference *GetSpatialRef() const override;
301 : CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
302 :
303 : CPLErr GetGeoTransform(GDALGeoTransform &) const override;
304 : CPLErr SetGeoTransform(const GDALGeoTransform &) override;
305 :
306 : // Special behavior for the following methods : they return a pointer
307 : // data type, that must be cached by the proxy, so it doesn't become invalid
308 : // when the underlying object get closed.
309 : CSLConstList GetMetadata(const char *pszDomain) override;
310 : const char *GetMetadataItem(const char *pszName,
311 : const char *pszDomain) override;
312 :
313 : void *GetInternalHandle(const char *pszRequest) override;
314 :
315 : const OGRSpatialReference *GetGCPSpatialRef() const override;
316 : const GDAL_GCP *GetGCPs() override;
317 :
318 : private:
319 : CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolDataset)
320 : };
321 :
322 : /* ******************************************************************** */
323 : /* GDALProxyPoolRasterBand */
324 : /* ******************************************************************** */
325 :
326 : class GDALProxyPoolOverviewRasterBand;
327 : class GDALProxyPoolMaskBand;
328 :
329 : class CPL_DLL
330 : GDALProxyPoolRasterBand /* non final */ : public GDALProxyRasterBand
331 : {
332 : private:
333 : CPLHashSet *metadataSet = nullptr;
334 : CPLHashSet *metadataItemSet = nullptr;
335 : char *pszUnitType = nullptr;
336 : char **papszCategoryNames = nullptr;
337 : GDALColorTable *poColorTable = nullptr;
338 :
339 : int nSizeProxyOverviewRasterBand = 0;
340 : GDALProxyPoolOverviewRasterBand **papoProxyOverviewRasterBand = nullptr;
341 : GDALProxyPoolMaskBand *poProxyMaskBand = nullptr;
342 :
343 : protected:
344 : GDALRasterBand *
345 : RefUnderlyingRasterBand(bool bForceOpen = true) const override;
346 : void UnrefUnderlyingRasterBand(
347 : GDALRasterBand *poUnderlyingRasterBand) const override;
348 :
349 : friend class GDALProxyPoolOverviewRasterBand;
350 : friend class GDALProxyPoolMaskBand;
351 :
352 : public:
353 : GDALProxyPoolRasterBand(GDALProxyPoolDataset *poDS, int nBand,
354 : GDALDataType eDataType, int nBlockXSize,
355 : int nBlockYSize);
356 : GDALProxyPoolRasterBand(GDALProxyPoolDataset *poDS,
357 : GDALRasterBand *poUnderlyingRasterBand);
358 : ~GDALProxyPoolRasterBand() override;
359 :
360 : void AddSrcMaskBandDescription(GDALDataType eDataType, int nBlockXSize,
361 : int nBlockYSize);
362 :
363 : void AddSrcMaskBandDescriptionFromUnderlying();
364 :
365 : // Special behavior for the following methods : they return a pointer
366 : // data type, that must be cached by the proxy, so it doesn't become invalid
367 : // when the underlying object get closed.
368 : CSLConstList GetMetadata(const char *pszDomain) override;
369 : const char *GetMetadataItem(const char *pszName,
370 : const char *pszDomain) override;
371 : char **GetCategoryNames() override;
372 : const char *GetUnitType() override;
373 : GDALColorTable *GetColorTable() override;
374 : GDALRasterBand *GetOverview(int) override;
375 : GDALRasterBand *
376 : GetRasterSampleOverview(GUIntBig nDesiredSamples) override; // TODO
377 : GDALRasterBand *GetMaskBand() override;
378 :
379 : CPLErr FlushCache(bool bAtClosing) override;
380 :
381 : private:
382 : CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolRasterBand)
383 : };
384 :
385 : /* ******************************************************************** */
386 : /* GDALProxyPoolOverviewRasterBand */
387 : /* ******************************************************************** */
388 :
389 : class GDALProxyPoolOverviewRasterBand final : public GDALProxyPoolRasterBand
390 : {
391 : private:
392 : GDALProxyPoolRasterBand *poMainBand = nullptr;
393 : int nOverviewBand = 0;
394 :
395 : mutable GDALRasterBand *poUnderlyingMainRasterBand = nullptr;
396 : mutable int nRefCountUnderlyingMainRasterBand = 0;
397 :
398 : CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolOverviewRasterBand)
399 :
400 : protected:
401 : GDALRasterBand *
402 : RefUnderlyingRasterBand(bool bForceOpen = true) const override;
403 : void UnrefUnderlyingRasterBand(
404 : GDALRasterBand *poUnderlyingRasterBand) const override;
405 :
406 : public:
407 : GDALProxyPoolOverviewRasterBand(GDALProxyPoolDataset *poDS,
408 : GDALRasterBand *poUnderlyingOverviewBand,
409 : GDALProxyPoolRasterBand *poMainBand,
410 : int nOverviewBand);
411 : ~GDALProxyPoolOverviewRasterBand() override;
412 : };
413 :
414 : /* ******************************************************************** */
415 : /* GDALProxyPoolMaskBand */
416 : /* ******************************************************************** */
417 :
418 : class GDALProxyPoolMaskBand final : public GDALProxyPoolRasterBand
419 : {
420 : private:
421 : GDALProxyPoolRasterBand *poMainBand = nullptr;
422 :
423 : mutable GDALRasterBand *poUnderlyingMainRasterBand = nullptr;
424 : mutable int nRefCountUnderlyingMainRasterBand = 0;
425 :
426 : CPL_DISALLOW_COPY_ASSIGN(GDALProxyPoolMaskBand)
427 :
428 : protected:
429 : GDALRasterBand *
430 : RefUnderlyingRasterBand(bool bForceOpen = true) const override;
431 : void UnrefUnderlyingRasterBand(
432 : GDALRasterBand *poUnderlyingRasterBand) const override;
433 :
434 : public:
435 : GDALProxyPoolMaskBand(GDALProxyPoolDataset *poDS,
436 : GDALRasterBand *poUnderlyingMaskBand,
437 : GDALProxyPoolRasterBand *poMainBand);
438 : GDALProxyPoolMaskBand(GDALProxyPoolDataset *poDS,
439 : GDALProxyPoolRasterBand *poMainBand,
440 : GDALDataType eDataType, int nBlockXSize,
441 : int nBlockYSize);
442 : ~GDALProxyPoolMaskBand() override;
443 :
444 0 : bool IsMaskBand() const override
445 : {
446 0 : return true;
447 : }
448 : };
449 :
450 : #endif
451 :
452 : /* ******************************************************************** */
453 : /* C types and methods declarations */
454 : /* ******************************************************************** */
455 :
456 : CPL_C_START
457 :
458 : typedef struct GDALProxyPoolDatasetHS *GDALProxyPoolDatasetH;
459 :
460 : GDALProxyPoolDatasetH CPL_DLL GDALProxyPoolDatasetCreate(
461 : const char *pszSourceDatasetDescription, int nRasterXSize, int nRasterYSize,
462 : GDALAccess eAccess, int bShared, const char *pszProjectionRef,
463 : const double *padfGeoTransform);
464 :
465 : void CPL_DLL
466 : GDALProxyPoolDatasetDelete(GDALProxyPoolDatasetH hProxyPoolDataset);
467 :
468 : void CPL_DLL GDALProxyPoolDatasetAddSrcBandDescription(
469 : GDALProxyPoolDatasetH hProxyPoolDataset, GDALDataType eDataType,
470 : int nBlockXSize, int nBlockYSize);
471 :
472 : int CPL_DLL GDALGetMaxDatasetPoolSize(void);
473 :
474 : CPL_C_END
475 :
476 : #endif /* #ifndef DOXYGEN_SKIP */
477 :
478 : #endif /* GDAL_PROXY_H_INCLUDED */
|