/src/gdal/frmts/gtiff/gtiffdataset.h
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Project: GeoTIFF Driver |
4 | | * Purpose: GDAL GeoTIFF support. |
5 | | * Author: Frank Warmerdam, warmerdam@pobox.com |
6 | | * |
7 | | ****************************************************************************** |
8 | | * Copyright (c) 1998, 2002, Frank Warmerdam <warmerdam@pobox.com> |
9 | | * Copyright (c) 2007-2015, Even Rouault <even dot rouault at spatialys dot com> |
10 | | * |
11 | | * SPDX-License-Identifier: MIT |
12 | | ****************************************************************************/ |
13 | | |
14 | | #ifndef GTIFFDATASET_H_INCLUDED |
15 | | #define GTIFFDATASET_H_INCLUDED |
16 | | |
17 | | #include "gdal_pam.h" |
18 | | |
19 | | #include <mutex> |
20 | | #include <queue> |
21 | | |
22 | | #include "cpl_json.h" |
23 | | #include "cpl_mem_cache.h" |
24 | | #include "cpl_worker_thread_pool.h" // CPLJobQueue, CPLWorkerThreadPool |
25 | | #include "fetchbufferdirectio.h" |
26 | | #include "gtiff.h" |
27 | | #include "gt_wkt_srs.h" // GTIFFKeysFlavorEnum |
28 | | #include "tiffio.h" // TIFF* |
29 | | |
30 | | enum class GTiffProfile : GByte |
31 | | { |
32 | | BASELINE, |
33 | | GEOTIFF, |
34 | | GDALGEOTIFF |
35 | | }; |
36 | | |
37 | | // This must be a #define, since it is used in a XSTRINGIFY() macro |
38 | 0 | #define DEFAULT_WEBP_LEVEL 75 |
39 | | |
40 | | class GTiffBitmapBand; |
41 | | class GTiffDataset; |
42 | | class GTiffJPEGOverviewBand; |
43 | | class GTiffJPEGOverviewDS; |
44 | | class GTiffRasterBand; |
45 | | class GTiffRGBABand; |
46 | | |
47 | | typedef struct |
48 | | { |
49 | | GTiffDataset *poDS; |
50 | | char *pszTmpFilename; |
51 | | GByte *pabyBuffer; |
52 | | GByte *pabyCompressedBuffer; // Owned by pszTmpFilename. |
53 | | GPtrDiff_t nBufferSize; |
54 | | GPtrDiff_t nCompressedBufferSize; |
55 | | int nHeight; |
56 | | int nStripOrTile; |
57 | | uint16_t nPredictor; |
58 | | bool bTIFFIsBigEndian; |
59 | | bool bReady; |
60 | | uint16_t *pExtraSamples; |
61 | | uint16_t nExtraSampleCount; |
62 | | } GTiffCompressionJob; |
63 | | |
64 | | typedef enum |
65 | | { |
66 | | GTIFFTAGTYPE_STRING, |
67 | | GTIFFTAGTYPE_SHORT, |
68 | | GTIFFTAGTYPE_FLOAT, |
69 | | GTIFFTAGTYPE_BYTE_STRING |
70 | | } GTIFFTagTypes; |
71 | | |
72 | | struct GTIFFTag |
73 | | { |
74 | | const char *pszTagName; |
75 | | int nTagVal; |
76 | | GTIFFTagTypes eType; |
77 | | }; |
78 | | |
79 | | /************************************************************************/ |
80 | | /* ==================================================================== */ |
81 | | /* GTiffDataset */ |
82 | | /* ==================================================================== */ |
83 | | /************************************************************************/ |
84 | | |
85 | | class GTiffDataset final : public GDALPamDataset |
86 | | { |
87 | | public: |
88 | | struct MaskOffset |
89 | | { |
90 | | uint64_t nMask; |
91 | | uint64_t nRoundUpBitTest; |
92 | | }; |
93 | | |
94 | | private: |
95 | | CPL_DISALLOW_COPY_ASSIGN(GTiffDataset) |
96 | | |
97 | | friend class GTiffBitmapBand; |
98 | | friend class GTiffJPEGOverviewDS; |
99 | | friend class GTiffJPEGOverviewBand; |
100 | | friend class GTiffOddBitsBand; |
101 | | friend class GTiffRasterBand; |
102 | | friend class GTiffRGBABand; |
103 | | friend class GTiffSplitBand; |
104 | | friend class GTiffSplitBitmapBand; |
105 | | |
106 | | friend void GTIFFSetJpegQuality(GDALDatasetH hGTIFFDS, int nJpegQuality); |
107 | | friend void GTIFFSetJpegTablesMode(GDALDatasetH hGTIFFDS, |
108 | | int nJpegTablesMode); |
109 | | friend void GTIFFSetWebPLevel(GDALDatasetH hGTIFFDS, int nWebPLevel); |
110 | | friend void GTIFFSetWebPLossless(GDALDatasetH hGTIFFDS, bool bWebPLossless); |
111 | | friend void GTIFFSetZLevel(GDALDatasetH hGTIFFDS, int nZLevel); |
112 | | friend void GTIFFSetZSTDLevel(GDALDatasetH hGTIFFDS, int nZSTDLevel); |
113 | | friend void GTIFFSetMaxZError(GDALDatasetH hGTIFFDS, double dfMaxZError); |
114 | | #if HAVE_JXL |
115 | | friend void GTIFFSetJXLLossless(GDALDatasetH hGTIFFDS, bool bIsLossless); |
116 | | friend void GTIFFSetJXLEffort(GDALDatasetH hGTIFFDS, int nEffort); |
117 | | friend void GTIFFSetJXLDistance(GDALDatasetH hGTIFFDS, float fDistance); |
118 | | friend void GTIFFSetJXLAlphaDistance(GDALDatasetH hGTIFFDS, |
119 | | float fAlphaDistance); |
120 | | #endif |
121 | | |
122 | | TIFF *m_hTIFF = nullptr; |
123 | | VSILFILE *m_fpL = nullptr; |
124 | | VSILFILE *m_fpToWrite = nullptr; |
125 | | std::vector<std::shared_ptr<GTiffDataset>> m_apoOverviewDS{}; |
126 | | // For a non-mask dataset, points to the corresponding (internal) mask |
127 | | std::shared_ptr<GTiffDataset> m_poMaskDS{}; |
128 | | // Points to a dataset within m_poMaskExtOvrDS |
129 | | GDALDataset *m_poExternalMaskDS = nullptr; |
130 | | // For a mask dataset, points to the corresponding imagery dataset |
131 | | GTiffDataset *m_poImageryDS = nullptr; |
132 | | // For an overview or mask dataset, points to the root dataset |
133 | | GTiffDataset *m_poBaseDS = nullptr; |
134 | | // Used with MASK_OVERVIEW_DATASET open option |
135 | | std::unique_ptr<GDALDataset> m_poMaskExtOvrDS{}; |
136 | | std::vector<std::unique_ptr<GTiffJPEGOverviewDS>> m_apoJPEGOverviewDS{}; |
137 | | std::vector<std::unique_ptr<GTiffJPEGOverviewDS>> m_apoJPEGOverviewDSOld{}; |
138 | | std::vector<gdal::GCP> m_aoGCPs{}; |
139 | | std::unique_ptr<GDALColorTable> m_poColorTable{}; |
140 | | char **m_papszMetadataFiles = nullptr; |
141 | | GByte *m_pabyBlockBuf = nullptr; |
142 | | char **m_papszCreationOptions = nullptr; |
143 | | void *m_pabyTempWriteBuffer = nullptr; |
144 | | CPLVirtualMem *m_pBaseMapping = nullptr; |
145 | | GByte *m_pTempBufferForCommonDirectIO = nullptr; |
146 | | CPLVirtualMem *m_psVirtualMemIOMapping = nullptr; |
147 | | CPLWorkerThreadPool *m_poThreadPool = nullptr; |
148 | | std::unique_ptr<CPLJobQueue> m_poCompressQueue{}; |
149 | | std::mutex m_oCompressThreadPoolMutex{}; |
150 | | |
151 | | lru11::Cache<int, std::pair<vsi_l_offset, vsi_l_offset>> |
152 | | m_oCacheStrileToOffsetByteCount{1024}; |
153 | | |
154 | | MaskOffset *m_panMaskOffsetLsb = nullptr; |
155 | | char *m_pszVertUnit = nullptr; |
156 | | std::string m_osFilename{}; |
157 | | char *m_pszTmpFilename = nullptr; |
158 | | char *m_pszGeorefFilename = nullptr; |
159 | | char *m_pszXMLFilename = nullptr; |
160 | | |
161 | | CPLJSONObject m_oISIS3Metadata{}; |
162 | | std::map<std::string, std::string> m_oMapISIS3MetadataItems{}; |
163 | | |
164 | | GDALGeoTransform m_gt{}; |
165 | | double m_dfMaxZError = 0.0; |
166 | | double m_dfMaxZErrorOverview = 0.0; |
167 | | uint32_t m_anLercAddCompressionAndVersion[2]{0, 0}; |
168 | | #if HAVE_JXL |
169 | | bool m_bJXLLossless = true; |
170 | | float m_fJXLDistance = 1.0f; |
171 | | float m_fJXLAlphaDistance = -1.0f; // -1 = same as non-alpha channel |
172 | | uint32_t m_nJXLEffort = 5; |
173 | | #endif |
174 | | double m_dfNoDataValue = DEFAULT_NODATA_VALUE; |
175 | | int64_t m_nNoDataValueInt64 = GDAL_PAM_DEFAULT_NODATA_VALUE_INT64; |
176 | | uint64_t m_nNoDataValueUInt64 = GDAL_PAM_DEFAULT_NODATA_VALUE_UINT64; |
177 | | |
178 | | toff_t m_nDirOffset = 0; |
179 | | |
180 | | int m_nBlocksPerRow = 0; |
181 | | int m_nBlocksPerColumn = 0; |
182 | | int m_nBlocksPerBand = 0; |
183 | | int m_nBlockXSize = 0; |
184 | | int m_nBlockYSize = 0; |
185 | | int m_nLoadedBlock = -1; // Or tile, or scanline |
186 | | uint32_t m_nRowsPerStrip = 0; |
187 | | int m_nLastBandRead = -1; // Used for the all-in-on-strip case. |
188 | | int m_nLastWrittenBlockId = -1; // used for m_bStreamingOut |
189 | | int m_nRefBaseMapping = 0; |
190 | | int m_nDisableMultiThreadedRead = 0; |
191 | | |
192 | | struct JPEGOverviewVisibilitySetter |
193 | | { |
194 | | signed char &nCounter_; |
195 | | |
196 | | explicit JPEGOverviewVisibilitySetter(signed char &nCounter) |
197 | 0 | : nCounter_(nCounter) |
198 | 0 | { |
199 | 0 | ++nCounter_; |
200 | 0 | } |
201 | | |
202 | | ~JPEGOverviewVisibilitySetter() |
203 | 0 | { |
204 | 0 | --nCounter_; |
205 | 0 | } |
206 | | }; |
207 | | |
208 | | std::unique_ptr<JPEGOverviewVisibilitySetter> |
209 | | MakeJPEGOverviewVisible() CPL_WARN_UNUSED_RESULT |
210 | 0 | { |
211 | 0 | return std::make_unique<JPEGOverviewVisibilitySetter>( |
212 | 0 | m_nJPEGOverviewVisibilityCounter); |
213 | 0 | } |
214 | | |
215 | | public: |
216 | | static constexpr int DEFAULT_COLOR_TABLE_MULTIPLIER_257 = 257; |
217 | | |
218 | | private: |
219 | | //! Multiplication factor to go from GDAL [0,255] color table range to |
220 | | // TIFF [0,65535] color map one. |
221 | | // 0 is not a valid value, and means not specified by user through the |
222 | | // COLOR_TABLE_MULTIPLIER open / creation option. |
223 | | int m_nColorTableMultiplier = 0; |
224 | | |
225 | | GTIFFKeysFlavorEnum m_eGeoTIFFKeysFlavor = GEOTIFF_KEYS_STANDARD; |
226 | | GeoTIFFVersionEnum m_eGeoTIFFVersion = GEOTIFF_VERSION_AUTO; |
227 | | |
228 | | uint16_t m_nPlanarConfig = 0; |
229 | | uint16_t m_nSamplesPerPixel = 0; |
230 | | uint16_t m_nBitsPerSample = 0; |
231 | | uint16_t m_nPhotometric = 0; |
232 | | uint16_t m_nSampleFormat = 0; |
233 | | uint16_t m_nCompression = 0; |
234 | | |
235 | | // If > 0, the implicit JPEG overviews are visible through |
236 | | // GetOverviewCount(). |
237 | | signed char m_nJPEGOverviewVisibilityCounter = 0; |
238 | | signed char m_nPAMGeorefSrcIndex = -1; |
239 | | signed char m_nINTERNALGeorefSrcIndex = -1; |
240 | | signed char m_nTABFILEGeorefSrcIndex = -1; |
241 | | signed char m_nWORLDFILEGeorefSrcIndex = -1; |
242 | | signed char m_nXMLGeorefSrcIndex = -1; |
243 | | signed char m_nGeoTransformGeorefSrcIndex = -1; |
244 | | |
245 | | signed char m_nHasOptimizedReadMultiRange = -1; |
246 | | |
247 | | signed char m_nZLevel = -1; |
248 | | signed char m_nLZMAPreset = -1; |
249 | | signed char m_nZSTDLevel = -1; |
250 | | signed char m_nWebPLevel = DEFAULT_WEBP_LEVEL; |
251 | | signed char m_nJpegQuality = -1; |
252 | | signed char m_nJpegTablesMode = -1; |
253 | | |
254 | | enum class VirtualMemIOEnum : GByte |
255 | | { |
256 | | NO, |
257 | | YES, |
258 | | IF_ENOUGH_RAM |
259 | | }; |
260 | | |
261 | | VirtualMemIOEnum m_eVirtualMemIOUsage = VirtualMemIOEnum::NO; |
262 | | |
263 | | GTiffProfile m_eProfile = GTiffProfile::GDALGEOTIFF; |
264 | | |
265 | | OGRSpatialReference m_oSRS{}; |
266 | | |
267 | | GDALMultiDomainMetadata m_oGTiffMDMD{}; |
268 | | |
269 | | std::vector<GTiffCompressionJob> m_asCompressionJobs{}; |
270 | | std::queue<int> m_asQueueJobIdx{}; // queue of index of m_asCompressionJobs |
271 | | // being compressed in worker threads |
272 | | |
273 | | bool m_bStreamingIn : 1; |
274 | | bool m_bStreamingOut : 1; |
275 | | bool m_bScanDeferred : 1; |
276 | | bool m_bSingleIFDOpened = false; |
277 | | bool m_bLoadedBlockDirty : 1; |
278 | | bool m_bWriteError : 1; |
279 | | bool m_bLookedForProjection : 1; |
280 | | bool m_bLookedForMDAreaOrPoint : 1; |
281 | | bool m_bGeoTransformValid : 1; |
282 | | bool m_bCrystalized : 1; |
283 | | bool m_bGeoTIFFInfoChanged : 1; |
284 | | bool m_bForceUnsetGTOrGCPs : 1; |
285 | | bool m_bForceUnsetProjection : 1; |
286 | | bool m_bNoDataChanged : 1; |
287 | | bool m_bNoDataSet : 1; |
288 | | bool m_bNoDataSetAsInt64 : 1; |
289 | | bool m_bNoDataSetAsUInt64 : 1; |
290 | | bool m_bMetadataChanged : 1; |
291 | | bool m_bColorProfileMetadataChanged : 1; |
292 | | bool m_bForceUnsetRPC : 1; |
293 | | bool m_bNeedsRewrite : 1; |
294 | | bool m_bLoadingOtherBands : 1; |
295 | | bool m_bIsOverview : 1; |
296 | | bool m_bWriteEmptyTiles : 1; // Whether a write of a tile entirely at |
297 | | // nodata/0 should go to the disk. Default is |
298 | | // true, unless SPARSE_OK is set |
299 | | bool m_bFillEmptyTilesAtClosing : 1; // Might only be set to true on newly |
300 | | // created files, when SPARSE_OK is |
301 | | // not set |
302 | | bool m_bTreatAsSplit : 1; |
303 | | bool m_bTreatAsSplitBitmap : 1; |
304 | | bool m_bClipWarn : 1; |
305 | | bool m_bIMDRPCMetadataLoaded : 1; |
306 | | bool m_bEXIFMetadataLoaded : 1; |
307 | | bool m_bICCMetadataLoaded : 1; |
308 | | bool m_bHasWarnedDisableAggressiveBandCaching : 1; |
309 | | bool m_bDontReloadFirstBlock : 1; // Hack for libtiff 3.X and #3633. |
310 | | bool m_bWebPLossless : 1; |
311 | | bool m_bPromoteTo8Bits : 1; |
312 | | bool m_bDebugDontWriteBlocks : 1; |
313 | | bool m_bIsFinalized : 1; |
314 | | bool m_bIgnoreReadErrors : 1; |
315 | | bool m_bDirectIO : 1; |
316 | | bool m_bReadGeoTransform : 1; |
317 | | bool m_bLoadPam : 1; |
318 | | bool m_bENVIHdrTried : 1; |
319 | | bool m_bENVIHdrFound : 1; |
320 | | bool m_bHasGotSiblingFiles : 1; |
321 | | bool m_bHasIdentifiedAuthorizedGeoreferencingSources : 1; |
322 | | bool m_bLayoutIFDSBeforeData : 1; |
323 | | bool m_bBlockOrderRowMajor : 1; |
324 | | bool m_bLeaderSizeAsUInt4 : 1; |
325 | | bool m_bTrailerRepeatedLast4BytesRepeated : 1; |
326 | | bool m_bMaskInterleavedWithImagery : 1; |
327 | | bool m_bKnownIncompatibleEdition : 1; |
328 | | bool m_bWriteKnownIncompatibleEdition : 1; |
329 | | bool m_bHasUsedReadEncodedAPI : 1; // for debugging |
330 | | bool m_bWriteCOGLayout : 1; |
331 | | bool m_bTileInterleave : 1; |
332 | | bool m_bLayoutChecked : 1; |
333 | | |
334 | | void ScanDirectories(); |
335 | | bool ReadStrile(int nBlockId, void *pOutputBuffer, |
336 | | GPtrDiff_t nBlockReqSize); |
337 | | CPLErr LoadBlockBuf(int nBlockId, bool bReadFromDisk = true); |
338 | | CPLErr FlushBlockBuf(); |
339 | | |
340 | | void LoadMDAreaOrPoint(); |
341 | | void LookForProjection(); |
342 | | void LookForProjectionFromGeoTIFF(); |
343 | | void LookForProjectionFromXML(); |
344 | | |
345 | | void Crystalize(); // TODO: Spelling. |
346 | | void RestoreVolatileParameters(TIFF *hTIFF); |
347 | | |
348 | | void WriteGeoTIFFInfo(); |
349 | | bool SetDirectory(); |
350 | | void ReloadDirectory(bool bReopenHandle = false); |
351 | | |
352 | | int GetJPEGOverviewCount(); |
353 | | |
354 | | bool IsBlockAvailable(int nBlockId, vsi_l_offset *pnOffset, |
355 | | vsi_l_offset *pnSize, bool *pbErrOccurred); |
356 | | |
357 | | void ApplyPamInfo(); |
358 | | void PushMetadataToPam(); |
359 | | |
360 | | bool WriteEncodedTile(uint32_t tile, GByte *pabyData, |
361 | | int bPreserveDataBuffer); |
362 | | bool WriteEncodedStrip(uint32_t strip, GByte *pabyData, |
363 | | int bPreserveDataBuffer); |
364 | | |
365 | | template <typename T> |
366 | | void WriteDealWithLercAndNan(T *pBuffer, int nActualBlockWidth, |
367 | | int nActualBlockHeight, int nStrileHeight); |
368 | | |
369 | | bool HasOnlyNoData(const void *pBuffer, int nWidth, int nHeight, |
370 | | int nLineStride, int nComponents); |
371 | | inline bool IsFirstPixelEqualToNoData(const void *pBuffer); |
372 | | |
373 | | CPLErr FillEmptyTiles(); |
374 | | |
375 | | CPLErr FlushDirectory(); |
376 | | CPLErr CleanOverviews(); |
377 | | |
378 | | void LoadMetadata(); |
379 | | void LoadEXIFMetadata(); |
380 | | void LoadICCProfile(); |
381 | | |
382 | | CPLErr RegisterNewOverviewDataset(toff_t nOverviewOffset, |
383 | | int l_nJpegQuality, |
384 | | CSLConstList papszOptions); |
385 | | CPLErr CreateOverviewsFromSrcOverviews(GDALDataset *poSrcDS, |
386 | | GDALDataset *poOvrDS, |
387 | | int nOverviews); |
388 | | CPLErr CreateInternalMaskOverviews(int nOvrBlockXSize, int nOvrBlockYSize); |
389 | | std::tuple<CPLErr, bool> Finalize(); |
390 | | |
391 | | void DiscardLsb(GByte *pabyBuffer, GPtrDiff_t nBytes, int iBand) const; |
392 | | void GetDiscardLsbOption(CSLConstList papszOptions); |
393 | | void InitCompressionThreads(bool bUpdateMode, CSLConstList papszOptions); |
394 | | void InitCreationOrOpenOptions(bool bUpdateMode, CSLConstList papszOptions); |
395 | | static void ThreadCompressionFunc(void *pData); |
396 | | void WaitCompletionForJobIdx(int i); |
397 | | void WaitCompletionForBlock(int nBlockId); |
398 | | void WriteRawStripOrTile(int nStripOrTile, GByte *pabyCompressedBuffer, |
399 | | GPtrDiff_t nCompressedBufferSize); |
400 | | bool SubmitCompressionJob(int nStripOrTile, GByte *pabyData, GPtrDiff_t cc, |
401 | | int nHeight); |
402 | | |
403 | | int GuessJPEGQuality(bool &bOutHasQuantizationTable, |
404 | | bool &bOutHasHuffmanTable); |
405 | | |
406 | | void SetJPEGQualityAndTablesModeFromFile(int nQuality, |
407 | | bool bHasQuantizationTable, |
408 | | bool bHasHuffmanTable); |
409 | | |
410 | | int DirectIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, |
411 | | int nYSize, void *pData, int nBufXSize, int nBufYSize, |
412 | | GDALDataType eBufType, int nBandCount, const int *panBandMap, |
413 | | GSpacing nPixelSpace, GSpacing nLineSpace, GSpacing nBandSpace, |
414 | | GDALRasterIOExtraArg *psExtraArg); |
415 | | |
416 | | int VirtualMemIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, |
417 | | int nYSize, void *pData, int nBufXSize, int nBufYSize, |
418 | | GDALDataType eBufType, int nBandCount, |
419 | | const int *panBandMap, GSpacing nPixelSpace, |
420 | | GSpacing nLineSpace, GSpacing nBandSpace, |
421 | | GDALRasterIOExtraArg *psExtraArg); |
422 | | |
423 | | void SetStructuralMDFromParent(GTiffDataset *poParentDS); |
424 | | |
425 | | template <class FetchBuffer> |
426 | | CPLErr CommonDirectIO(FetchBuffer &oFetcher, int nXOff, int nYOff, |
427 | | int nXSize, int nYSize, void *pData, int nBufXSize, |
428 | | int nBufYSize, GDALDataType eBufType, int nBandCount, |
429 | | const int *panBandMap, GSpacing nPixelSpace, |
430 | | GSpacing nLineSpace, GSpacing nBandSpace); |
431 | | |
432 | | CPLErr CommonDirectIOClassic(FetchBufferDirectIO &oFetcher, int nXOff, |
433 | | int nYOff, int nXSize, int nYSize, void *pData, |
434 | | int nBufXSize, int nBufYSize, |
435 | | GDALDataType eBufType, int nBandCount, |
436 | | const int *panBandMap, GSpacing nPixelSpace, |
437 | | GSpacing nLineSpace, GSpacing nBandSpace); |
438 | | |
439 | | std::string GetSidecarFilenameWithReplacedExtension(const char *pszExt); |
440 | | |
441 | | void LoadGeoreferencingAndPamIfNeeded(); |
442 | | |
443 | | void LoadENVIHdrIfNeeded(); |
444 | | |
445 | | CSLConstList GetSiblingFiles(); |
446 | | |
447 | | void IdentifyAuthorizedGeoreferencingSources(); |
448 | | |
449 | | CPLErr FlushCacheInternal(bool bAtClosing, bool bFlushDirectory); |
450 | | bool HasOptimizedReadMultiRange(); |
451 | | |
452 | | bool AssociateExternalMask(); |
453 | | |
454 | | static bool MustCreateInternalMask(); |
455 | | |
456 | | static CPLErr CopyImageryAndMask(GTiffDataset *poDstDS, |
457 | | GDALDataset *poSrcDS, |
458 | | GDALRasterBand *poSrcMaskBand, |
459 | | GDALProgressFunc pfnProgress, |
460 | | void *pProgressData); |
461 | | |
462 | | bool GetOverviewParameters(int &nCompression, uint16_t &nPlanarConfig, |
463 | | uint16_t &nPredictor, uint16_t &nPhotometric, |
464 | | int &nOvrJpegQuality, std::string &osNoData, |
465 | | uint16_t *&panExtraSampleValues, |
466 | | uint16_t &nExtraSamples, |
467 | | CSLConstList papszOptions) const; |
468 | | |
469 | | bool IsWholeBlock(int nXOff, int nYOff, int nXSize, int nYSize) const; |
470 | | |
471 | | void *CacheMultiRange(int nXOff, int nYOff, int nXSize, int nYSize, |
472 | | int nBufXSize, int nBufYSize, const int *panBandMap, |
473 | | int nBandCount, GDALRasterIOExtraArg *psExtraArg); |
474 | | |
475 | | bool CheckCOGLayout(); |
476 | | |
477 | | static void ThreadDecompressionFunc(void *pData); |
478 | | |
479 | | static GTIF *GTIFNew(TIFF *hTIFF); |
480 | | |
481 | | static constexpr const char *DEFAULT_RASTER_ATTRIBUTE_TABLE = |
482 | | "DEFAULT_RASTER_ATTRIBUTE_TABLE"; |
483 | | static constexpr const char *RAT_ROLE = "rat"; |
484 | | |
485 | | protected: |
486 | | int CloseDependentDatasets() override; |
487 | | |
488 | | public: |
489 | | GTiffDataset(); |
490 | | ~GTiffDataset() override; |
491 | | |
492 | | CPLErr Close(GDALProgressFunc = nullptr, void * = nullptr) override; |
493 | | |
494 | | const OGRSpatialReference *GetSpatialRef() const override; |
495 | | CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override; |
496 | | |
497 | | CPLErr GetGeoTransform(GDALGeoTransform >) const override; |
498 | | CPLErr SetGeoTransform(const GDALGeoTransform >) override; |
499 | | |
500 | | int GetGCPCount() override; |
501 | | const OGRSpatialReference *GetGCPSpatialRef() const override; |
502 | | const GDAL_GCP *GetGCPs() override; |
503 | | CPLErr SetGCPs(int nGCPCountIn, const GDAL_GCP *pasGCPListIn, |
504 | | const OGRSpatialReference *poSRS) override; |
505 | | |
506 | | bool IsMultiThreadedReadCompatible() const; |
507 | | CPLErr MultiThreadedRead(int nXOff, int nYOff, int nXSize, int nYSize, |
508 | | void *pData, GDALDataType eBufType, int nBandCount, |
509 | | const int *panBandMap, GSpacing nPixelSpace, |
510 | | GSpacing nLineSpace, GSpacing nBandSpace); |
511 | | |
512 | | CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, |
513 | | int nYSize, void *pData, int nBufXSize, int nBufYSize, |
514 | | GDALDataType eBufType, int nBandCount, |
515 | | BANDMAP_TYPE panBandMap, GSpacing nPixelSpace, |
516 | | GSpacing nLineSpace, GSpacing nBandSpace, |
517 | | GDALRasterIOExtraArg *psExtraArg) override; |
518 | | |
519 | | virtual CPLStringList |
520 | | GetCompressionFormats(int nXOff, int nYOff, int nXSize, int nYSize, |
521 | | int nBandCount, const int *panBandList) override; |
522 | | virtual CPLErr ReadCompressedData(const char *pszFormat, int nXOff, |
523 | | int nYOff, int nXSize, int nYSize, |
524 | | int nBandCount, const int *panBandList, |
525 | | void **ppBuffer, size_t *pnBufferSize, |
526 | | char **ppszDetailedFormat) override; |
527 | | |
528 | | char **GetFileList() override; |
529 | | |
530 | | CPLErr IBuildOverviews(const char *, int, const int *, int, const int *, |
531 | | GDALProgressFunc, void *, |
532 | | CSLConstList papszOptions) override; |
533 | | |
534 | | virtual CPLErr AddOverviews(const std::vector<GDALDataset *> &apoSrcOvrDS, |
535 | | GDALProgressFunc pfnProgress, |
536 | | void *pProgressData, |
537 | | CSLConstList papszOptions) override; |
538 | | |
539 | | bool ComputeBlocksPerColRowAndBand(int l_nBands); |
540 | | |
541 | | CPLErr OpenOffset(TIFF *, toff_t nDirOffset, GDALAccess, |
542 | | bool bAllowRGBAInterface = true, |
543 | | bool bReadGeoTransform = false); |
544 | | |
545 | | static GDALDataset *OpenDir(GDALOpenInfo *); |
546 | | static GDALDataset *Open(GDALOpenInfo *); |
547 | | static int Identify(GDALOpenInfo *); |
548 | | static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize, |
549 | | int nBands, GDALDataType eType, |
550 | | CSLConstList papszParamList); |
551 | | static GDALDataset *CreateCopy(const char *pszFilename, |
552 | | GDALDataset *poSrcDS, int bStrict, |
553 | | CSLConstList papszOptions, |
554 | | GDALProgressFunc pfnProgress, |
555 | | void *pProgressData); |
556 | | CPLErr FlushCache(bool bAtClosing) override; |
557 | | |
558 | | char **GetMetadataDomainList() override; |
559 | | CPLErr SetMetadata(CSLConstList, const char * = "") override; |
560 | | CSLConstList GetMetadata(const char *pszDomain = "") override; |
561 | | CPLErr SetMetadataItem(const char *, const char *, |
562 | | const char * = "") override; |
563 | | virtual const char *GetMetadataItem(const char *pszName, |
564 | | const char *pszDomain = "") override; |
565 | | void *GetInternalHandle(const char *) override; |
566 | | |
567 | | CPLErr CreateMaskBand(int nFlags) override; |
568 | | |
569 | | bool GetRawBinaryLayout(GDALDataset::RawBinaryLayout &) override; |
570 | | |
571 | | // Only needed by createcopy and close code. |
572 | | static void WriteRPC(GDALDataset *, TIFF *, int, GTiffProfile, const char *, |
573 | | CSLConstList papszCreationOptions, |
574 | | bool bWriteOnlyInPAMIfNeeded = false); |
575 | | static bool WriteMetadata(GDALDataset *, TIFF *, bool, GTiffProfile, |
576 | | const char *, CSLConstList papszCreationOptions, |
577 | | bool bExcludeRPBandIMGFileWriting = false); |
578 | | static void WriteNoDataValue(TIFF *, double); |
579 | | static void WriteNoDataValue(TIFF *, int64_t); |
580 | | static void WriteNoDataValue(TIFF *, uint64_t); |
581 | | static void UnsetNoDataValue(TIFF *); |
582 | | |
583 | | static TIFF *CreateLL(const char *pszFilename, int nXSize, int nYSize, |
584 | | int nBands, GDALDataType eType, |
585 | | double dfExtraSpaceForOverviews, |
586 | | int nColorTableMultiplier, |
587 | | CSLConstList papszParamList, VSILFILE **pfpL, |
588 | | CPLString &osTmpFilename, bool bCreateCopy, |
589 | | bool &bTileInterleavingOut); |
590 | | |
591 | | CPLErr WriteEncodedTileOrStrip(uint32_t tile_or_strip, void *data, |
592 | | int bPreserveDataBuffer); |
593 | | |
594 | | static void SaveICCProfile(GTiffDataset *pDS, TIFF *hTIFF, |
595 | | CSLConstList papszParamList, |
596 | | uint32_t nBitsPerSample); |
597 | | |
598 | | static const GTIFFTag *GetTIFFTags(); |
599 | | |
600 | | static unsigned short ClampCTEntry(int iColor, int iComp, int nCTEntryVal, |
601 | | int nMultFactor); |
602 | | }; |
603 | | |
604 | | GTIFFKeysFlavorEnum GetGTIFFKeysFlavor(CSLConstList papszOptions); |
605 | | GeoTIFFVersionEnum GetGeoTIFFVersion(CSLConstList papszOptions); |
606 | | void GTiffSetDeflateSubCodec(TIFF *hTIFF); |
607 | | |
608 | | #endif // GTIFFDATASET_H_INCLUDED |