Debian Codegraph @

src/LercLib/Lerc.h

raw symbols SCIP
1 /*
2 Copyright 2015 - 2026 Esri
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 A local copy of the license and additional notices are located with the
17 source distribution at:
18
19 http://github.com/Esri/lerc/
20
21 Contributors: Thomas Maurer
22 */
23
24 #pragma once
25
26 #include <cstring>
27 #include <vector>
28 #include "include/Lerc_types.h"cxx . . $ `<file>/src/LercLib/include/Lerc_types.h`/
29 #include "BitMask.h"cxx . . $ `<file>/src/LercLib/BitMask.h`/
30 #include "Lerc2.h"cxx . . $ `<file>/src/LercLib/Lerc2.h`/
31
32 NAMESPACE_LERC_STARTcxx . . $ `src/LercLib/Defines.h:35:9`!
33
34 #ifdef HAVE_LERC1_DECODEcxx . . $ `src/LercLib/Defines.h:39:9`!
35 class CntZImagecxx . . $ LercNS/CntZImage#;
36 #endif
37
38 class Lerccxx . . $ LercNS/Lerc#
39 {
40 public:
41 Lerccxx . . $ LercNS/Lerc#Lerc(49f6e7a06ebc5aa8).() {}
42 ~cxx . . $ LercNS/Lerc#`~Lerc`(ced63f7c635d850d).Lerccxx . . $ LercNS/Lerc#() {}
43
44 // data types supported by Lerc
45 enum DataTypecxx . . $ LercNS/Lerc#DataType# { DT_Charcxx . . $ LercNS/Lerc#DT_Char., DT_Bytecxx . . $ LercNS/Lerc#DT_Byte., DT_Shortcxx . . $ LercNS/Lerc#DT_Short., DT_UShortcxx . . $ LercNS/Lerc#DT_UShort., DT_Intcxx . . $ LercNS/Lerc#DT_Int., DT_UIntcxx . . $ LercNS/Lerc#DT_UInt., DT_Floatcxx . . $ LercNS/Lerc#DT_Float., DT_Doublecxx . . $ LercNS/Lerc#DT_Double., DT_Undefinedcxx . . $ LercNS/Lerc#DT_Undefined. };
46
47 // all functions are provided in 2 flavors
48 // - using void pointers to the image data, can be called on a Lerc lib or dll
49 // - data templated, can be called if compiled together
50
51
52 // Encode
53
54 // if more than 1 band, the outgoing Lerc blob has the single band Lerc blobs concatenated;
55 // or, if you have multiple values per pixel and stored as [RGB, RGB, ... ], then set nDepth accordingly (e.g., 3)
56
57 // computes the number of bytes needed to allocate the buffer, accurate to the byte;
58 // does not encode the image data, but uses statistics and formulas to compute the buffer size needed;
59 // this function is optional, you can also use a buffer large enough to call Encode() directly,
60 // or, if encoding a batch of same width / height tiles, call this function once, double the buffer size, and
61 // then just call Encode() on all tiles;
62
63 static ErrCodecxx . . $ LercNS/ErrCode# ComputeCompressedSizecxx . . $ LercNS/Lerc#ComputeCompressedSize(907a79ad428f5081).(
64 const void* pData, // raw image data, row by row, band by band
65 int version, // 2 = v2.2, 3 = v2.3, 4 = v2.4, 5 = v2.5
66 DataTypecxx . . $ LercNS/Lerc#DataType# dt, // data type, char to double
67 int nDepth, // number of values per pixel
68 int nCols, // number of cols
69 int nRows, // number of rows
70 int nBands, // number of bands
71 int nMasks, // number of masks (0, 1, or nBands)
72 const Bytecxx . . $ LercNS/Byte#* pValidBytes, // masks (size = nMasks * nRows * nCols)
73 double maxZErr, // max coding error per pixel, defines the precision
74 unsigned int& numBytesNeeded, // size of outgoing Lerc blob
75 const unsigned char* pUsesNoData,// if there are invalid values not marked by the mask, pass an array of size nBands, 1 - uses noData, 0 - not
76 const double* noDataValues); // same, pass an array of size nBands with noData value per band, or pass nullptr
77
78 // encodes or compresses the image data into the buffer
79
80 static ErrCodecxx . . $ LercNS/ErrCode# Encodecxx . . $ LercNS/Lerc#Encode(5806e23373902463).(
81 const void* pData, // raw image data, row by row, band by band
82 int version, // 2 = v2.2, 3 = v2.3, 4 = v2.4, 5 = v2.5
83 DataTypecxx . . $ LercNS/Lerc#DataType# dt, // data type, char to double
84 int nDepth, // number of values per pixel
85 int nCols, // number of cols
86 int nRows, // number of rows
87 int nBands, // number of bands
88 int nMasks, // number of masks (0, 1, or nBands)
89 const Bytecxx . . $ LercNS/Byte#* pValidBytes, // masks (size = nMasks * nRows * nCols)
90 double maxZErr, // max coding error per pixel, defines the precision
91 Bytecxx . . $ LercNS/Byte#* pBuffer, // buffer to write to, function fails if buffer too small
92 unsigned int numBytesBuffer, // buffer size
93 unsigned int& numBytesWritten, // num bytes written to buffer
94 const unsigned char* pUsesNoData,// if there are invalid values not marked by the mask, pass an array of size nBands, 1 - uses noData, 0 - not
95 const double* noDataValues); // same, pass an array of size nBands with noData value per band, or pass nullptr
96
97 // Decode
98
99 struct LercInfocxx . . $ LercNS/Lerc#LercInfo#
100 {
101 int versioncxx . . $ LercNS/Lerc#LercInfo#version., // Lerc version number (0 for old Lerc1, 1 to 5 for Lerc 2.1 to 2.5)
102 nDepthcxx . . $ LercNS/Lerc#LercInfo#nDepth., // number of values per pixel
103 nColscxx . . $ LercNS/Lerc#LercInfo#nCols., // number of columns
104 nRowscxx . . $ LercNS/Lerc#LercInfo#nRows., // number of rows
105 numValidPixelcxx . . $ LercNS/Lerc#LercInfo#numValidPixel., // number of valid pixels
106 nBandscxx . . $ LercNS/Lerc#LercInfo#nBands.; // number of bands
107 unsigned int blobSizecxx . . $ LercNS/Lerc#LercInfo#blobSize.; // total blob size in bytes, <= 4 GB
108 int nMaskscxx . . $ LercNS/Lerc#LercInfo#nMasks., // number of masks (0, 1, or nBands)
109 nUsesNoDataValuecxx . . $ LercNS/Lerc#LercInfo#nUsesNoDataValue.; // 0 - no noData value used, nBands - noData value used in 1 or more bands (only possible for nDepth > 1)
110 DataTypecxx . . $ LercNS/Lerc#DataType# dtcxx . . $ LercNS/Lerc#LercInfo#dt.; // data type (float only for old Lerc1)
111 double zMincxx . . $ LercNS/Lerc#LercInfo#zMin., // min pixel value, over all data values
112 zMaxcxx . . $ LercNS/Lerc#LercInfo#zMax., // max pixel value, over all data values
113 maxZErrorcxx . . $ LercNS/Lerc#LercInfo#maxZError.; // maxZError used for encoding
114
115 void RawInitcxx . . $ LercNS/Lerc#LercInfo#RawInit(49f6e7a06ebc5aa8).() { memset(this, 0, sizeof(struct LercInfocxx . . $ LercNS/Lerc#LercInfo#)); }
116 };
117
118 // again, this function is optional;
119 // call it on a Lerc blob to get the above struct returned, from this the data arrays
120 // can be constructed before calling Decode();
121 // same as above, for a batch of Lerc blobs of the same kind, you can call this function on
122 // the first blob, get the info, and on the other Lerc blobs just call Decode();
123 // this function is very fast on (newer) Lerc2 blobs as it only reads the blob headers;
124
125 // Remark on param numBytesBlob. Usually it is known, either the file size of the blob written to disk,
126 // or the size of the blob transmitted. It should be accurate for 2 reasons:
127 // _ function finds out how many single band Lerc blobs are concatenated
128 // _ function checks for truncated file or blob
129 // It is OK to pass numBytesBlob too large as long as there is no other (valid) Lerc blob following next.
130 // If in doubt, check the code in Lerc::GetLercInfo(...) for the exact logic.
131
132 static ErrCodecxx . . $ LercNS/ErrCode# GetLercInfocxx . . $ LercNS/Lerc#GetLercInfo(db35de8f40228c29).(const Bytecxx . . $ LercNS/Byte#* pLercBlob, // Lerc blob to decode
133 unsigned int numBytesBlob, // size of Lerc blob in bytes
134 struct LercInfocxx . . $ LercNS/Lerc#LercInfo#& lercInfo,
135 double* pMins = nullptr, // pass array of size (nDepth * nBands) to get the min values per dimension and band
136 double* pMaxs = nullptr, // same as pMins, to get the max values
137 size_t nElem = 0); // (nDepth * nBands), if passed
138
139 // setup outgoing arrays accordingly, then call Decode()
140
141 static ErrCodecxx . . $ LercNS/ErrCode# Decodecxx . . $ LercNS/Lerc#Decode(107064e3f405a899).(
142 const Bytecxx . . $ LercNS/Byte#* pLercBlob, // Lerc blob to decode
143 unsigned int numBytesBlob, // size of Lerc blob in bytes
144 int nMasks, // number of masks (0, 1, or nBands)
145 Bytecxx . . $ LercNS/Byte#* pValidBytes, // masks (fails if not big enough to take the masks decoded, fills with 1 if all valid)
146 int nDepth, // number of values per pixel
147 int nCols, // number of cols
148 int nRows, // number of rows
149 int nBands, // number of bands
150 DataTypecxx . . $ LercNS/Lerc#DataType# dt, // data type of outgoing array
151 void* pData, // outgoing data bands
152 unsigned char* pUsesNoData, // pass an array of size nBands, 1 - band uses noData, 0 - not
153 double* noDataValues); // same, pass an array of size nBands to get the noData value per band, if any
154
155 static ErrCodecxx . . $ LercNS/ErrCode# ConvertToDoublecxx . . $ LercNS/Lerc#ConvertToDouble(82cb9f5f9c82c481).(
156 const void* pDataIn, // pixel data of image tile of data type dt (< double)
157 DataTypecxx . . $ LercNS/Lerc#DataType# dt, // data type of input data
158 size_t nDataValues, // total number of data values (nDepth * nCols * nRows * nBands)
159 double* pDataOut); // pixel data converted to double
160
161
162 // same as functions above, but data templated instead of using void pointers
163
164 template<class T> static ErrCodecxx . . $ LercNS/ErrCode# ComputeCompressedSizeTemplcxx . . $ LercNS/Lerc#ComputeCompressedSizeTempl(40cc20dd7dade3bf).(
165 const T* pData, // raw image data, row by row, band by
166 int version, // 2 = v2.2, 3 = v2.3, 4 = v2.4, 5 = v2.5
167 int nDepth, // number of values per pixel
168 int nCols, // number of cols
169 int nRows, // number of rows
170 int nBands, // number of bands
171 int nMasks, // number of masks (0, 1, or nBands)
172 const Bytecxx . . $ LercNS/Byte#* pValidBytes, // masks (size = nMasks * nRows * nCols)
173 double maxZErr, // max coding error per pixel, defines the precision
174 unsigned int& numBytes, // size of outgoing Lerc blob
175 const unsigned char* pUsesNoData,// if there are invalid values not marked by the mask, pass an array of size nBands, 1 - uses noData, 0 - not
176 const double* noDataValues); // same, pass an array of size nBands with noData value per band, or pass nullptr
177
178 template<class T> static ErrCodecxx . . $ LercNS/ErrCode# EncodeTemplcxx . . $ LercNS/Lerc#EncodeTempl(402103a7adc54e8c).(
179 const T* pData, // raw image data, row by row, band by band
180 int version, // 2 = v2.2, 3 = v2.3, 4 = v2.4 5 = v2.5
181 int nDepth, // number of values per pixel
182 int nCols, // number of cols
183 int nRows, // number of rows
184 int nBands, // number of bands
185 int nMasks, // number of masks (0, 1, or nBands)
186 const Bytecxx . . $ LercNS/Byte#* pValidBytes, // masks (size = nMasks * nRows * nCols)
187 double maxZErr, // max coding error per pixel, defines the precision
188 Bytecxx . . $ LercNS/Byte#* pBuffer, // buffer to write to, function will fail if buffer too small
189 unsigned int numBytesBuffer, // buffer size
190 unsigned int& numBytesWritten, // num bytes written to buffer
191 const unsigned char* pUsesNoData,// if there are invalid values not marked by the mask, pass an array of size nBands, 1 - uses noData, 0 - not
192 const double* noDataValues); // same, pass an array of size nBands with noData value per band, or pass nullptr
193
194 template<class T> static ErrCodecxx . . $ LercNS/ErrCode# DecodeTemplcxx . . $ LercNS/Lerc#DecodeTempl(a7acf4c1e550641d).(
195 T* pData, // outgoing data bands
196 const Bytecxx . . $ LercNS/Byte#* pLercBlob, // Lerc blob to decode
197 unsigned int numBytesBlob, // size of Lerc blob in bytes
198 int nDepth, // number of values per pixel
199 int nCols, // number of cols
200 int nRows, // number of rows
201 int nBands, // number of bands
202 int nMasks, // number of masks (0, 1, or nBands)
203 Bytecxx . . $ LercNS/Byte#* pValidBytes, // masks (fails if not big enough to take the masks decoded, fills with 1 if all valid)
204 unsigned char* pUsesNoData, // pass an array of size nBands, 1 - band uses noData, 0 - not
205 double* noDataValues); // same, pass an array of size nBands to get the noData value per band, if any
206
207 private:
208
209 template<class T> static ErrCodecxx . . $ LercNS/ErrCode# EncodeInternal_v5cxx . . $ LercNS/Lerc#EncodeInternal_v5(f53d28dc65a36817).(
210 const T* pData, // raw image data, row by row, band by band
211 int version, // 2 = v2.2, 3 = v2.3, 4 = v2.4, 5 = v2.5
212 int nDepth, // number of values per pixel
213 int nCols, // number of cols
214 int nRows, // number of rows
215 int nBands, // number of bands
216 int nMasks, // number of masks (0, 1, or nBands)
217 const Bytecxx . . $ LercNS/Byte#* pValidBytes, // masks (size = nMasks * nRows * nCols)
218 double maxZErr, // max coding error per pixel, defines the precision
219 unsigned int& numBytes, // size of outgoing Lerc blob
220 Bytecxx . . $ LercNS/Byte#* pBuffer, // buffer to write to, function will fail if buffer too small
221 unsigned int numBytesBuffer, // buffer size
222 unsigned int& numBytesWritten); // num bytes written to buffer
223
224 template<class T> static ErrCodecxx . . $ LercNS/ErrCode# EncodeInternalcxx . . $ LercNS/Lerc#EncodeInternal(810fae6e2d3e41ce).(
225 const T* pData, // raw image data, row by row, band by band
226 int version, // 6 = v2.6 (or -1 for current)
227 int nDepth, // number of values per pixel
228 int nCols, // number of cols
229 int nRows, // number of rows
230 int nBands, // number of bands
231 int nMasks, // number of masks (0, 1, or nBands)
232 const Bytecxx . . $ LercNS/Byte#* pValidBytes, // masks (size = nMasks * nRows * nCols)
233 double maxZErr, // max coding error per pixel, defines the precision
234 unsigned int& numBytes, // size of outgoing Lerc blob
235 Bytecxx . . $ LercNS/Byte#* pBuffer, // buffer to write to, function will fail if buffer too small
236 unsigned int numBytesBuffer, // buffer size
237 unsigned int& numBytesWritten, // num bytes written to buffer
238 const unsigned char* pUsesNoData,// if there are invalid values not marked by the mask, pass an array of size nBands, 1 - uses noData, 0 - not
239 const double* noDataValues); // same, pass an array of size nBands with noData value per band, or pass nullptr
240
241 #ifdef HAVE_LERC1_DECODEcxx . . $ `src/LercLib/Defines.h:39:9`!
242 template<class T> static bool Convertcxx . . $ LercNS/Lerc#Convert(d91d2f7413d17fb0).(const CntZImagecxx . . $ LercNS/CntZImage#& zImg, T* arr, Bytecxx . . $ LercNS/Byte#* pByteMask, bool bMustFillMask);
243 #endif
244 template<class T> static ErrCodecxx . . $ LercNS/ErrCode# ConvertToDoubleTemplcxx . . $ LercNS/Lerc#ConvertToDoubleTempl(3116af53592bc7bf).(const T* pDataIn, size_t nDataValues, double* pDataOut);
245
246 template<class T> static ErrCodecxx . . $ LercNS/ErrCode# CheckForNaNcxx . . $ LercNS/Lerc#CheckForNaN(db39ed3c12335d1).(const T* arr, int nDepth, int nCols, int nRows, const Bytecxx . . $ LercNS/Byte#* pByteMask);
247
248 template<class T> static bool ReplaceNaNValuescxx . . $ LercNS/Lerc#ReplaceNaNValues(ad56b70f5ef9fcb2).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<T>& dataBuffer, stdcxx . . $ std/::vectorcxx . . $ std/vector#<Bytecxx . . $ LercNS/Byte#>& maskBuffer, int nDepth, int nCols, int nRows);
249
250 template<class T> static bool Resizecxx . . $ LercNS/Lerc#Resize(e6f179a37c0c9e9e).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<T>& buffer, size_t nElem);
251
252 static bool Convertcxx . . $ LercNS/Lerc#Convert(1633025d0e7a0295).(const Bytecxx . . $ LercNS/Byte#* pByteMask, int nCols, int nRows, BitMaskcxx . . $ LercNS/BitMask#& bitMask);
253 static bool Convertcxx . . $ LercNS/Lerc#Convert(54c99c5ab6149a98).(const BitMaskcxx . . $ LercNS/BitMask#& bitMask, Bytecxx . . $ LercNS/Byte#* pByteMask);
254 static bool MasksDiffercxx . . $ LercNS/Lerc#MasksDiffer(176f309453ec74c9).(const Bytecxx . . $ LercNS/Byte#* p0, const Bytecxx . . $ LercNS/Byte#* p1, size_t n);
255
256 static ErrCodecxx . . $ LercNS/ErrCode# GetRangescxx . . $ LercNS/Lerc#GetRanges(771fda4212732f67).(const Bytecxx . . $ LercNS/Byte#* pLercBlob, unsigned int numBytesBlob, int iBand,
257 const struct Lerc2cxx . . $ LercNS/Lerc2#::HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& lerc2Info, double* pMins, double* pMaxs, size_t nElem);
258
259 template<class T>
260 static bool RemapNoDatacxx . . $ LercNS/Lerc#RemapNoData(f51e42f49da7dd89).(T* data, const BitMaskcxx . . $ LercNS/BitMask#& bitMask, const struct Lerc2cxx . . $ LercNS/Lerc2#::HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& lerc2Info);
261
262 template<class T>
263 static bool DecodeAndCompareToInputcxx . . $ LercNS/Lerc#DecodeAndCompareToInput(d81b550f31abee77).(const Bytecxx . . $ LercNS/Byte#* pLercBlob, size_t blobSize, double maxZErr, Lerc2cxx . . $ LercNS/Lerc2#& lerc2Verify,
264 const T* pData, const Bytecxx . . $ LercNS/Byte#* pByteMask, const T* pDataOrig, const Bytecxx . . $ LercNS/Byte#* pByteMaskOrig,
265 bool bInputHasNoData, double origNoDataA, bool bModifiedMask);
266
267 template<class T>
268 static bool GetTypeRangecxx . . $ LercNS/Lerc#GetTypeRange(7b655ca3a0607607).(const T, stdcxx . . $ std/::paircxx . . $ std/pair#<double, double>& range);
269
270 template<class T>
271 inline static bool IsIntcxx . . $ LercNS/Lerc#IsInt(ee44d93984fb03e9).(T z) { return(z == (T)floor((double)z + 0.5)); };
272
273 template<class T>
274 static ErrCodecxx . . $ LercNS/ErrCode# FilterNoDatacxx . . $ LercNS/Lerc#FilterNoData(f77eaabeedbde36b).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<T>& dataBuffer, stdcxx . . $ std/::vectorcxx . . $ std/vector#<Bytecxx . . $ LercNS/Byte#>& maskBuffer, int nDepth, int nCols, int nRows,
275 double& maxZError, bool bPassNoDataValue, double& noDataValue, bool& bModifiedMask, bool& bNeedNoData,
276 double& minVal, double& maxVal);
277
278 template<class T>
279 static ErrCodecxx . . $ LercNS/ErrCode# FilterNoDataAndNaNcxx . . $ LercNS/Lerc#FilterNoDataAndNaN(52e685621fa17e88).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<T>& dataBuffer, stdcxx . . $ std/::vectorcxx . . $ std/vector#<Bytecxx . . $ LercNS/Byte#>& maskBuffer, int nDepth, int nCols, int nRows,
280 double& maxZError, bool bPassNoDataValue, double& noDataValue, bool& bModifiedMask, bool& bNeedNoData, bool& bIsFltDblAllInt,
281 double& minVal, double& maxVal);
282
283 template<class T>
284 static bool FindNewNoDataBelowValidMincxx . . $ LercNS/Lerc#FindNewNoDataBelowValidMin(98c0c5cb235ea887).(double minVal, double maxZErr, bool bAllInt, double lowIntLimit, T& newNoDataVal);
285
286 static bool CheckDimensionscxx . . $ LercNS/Lerc#CheckDimensions(67519ccc50caacfb).(int nDepth, int nCols, int nRows, size_t sizeOfDataElement);
287 };
288 NAMESPACE_LERC_ENDcxx . . $ `src/LercLib/Defines.h:36:9`!