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