Debian Codegraph @

frmts/mrf/LERCV1/Lerc1Image.h

raw symbols SCIP
1 /*
2 Copyright 2015 - 2024 Esri
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software
8 distributed under the License is distributed on an "AS IS" BASIS,
9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 See the License for the specific language governing permissions and
11 limitations under the License.
12 A local copy of the license and additional notices are located with the
13 source distribution at:
14 http://github.com/Esri/lerc/
15 Contributors: Thomas Maurer
16 Lucian Plesea
17 */
18
19 #ifndef LERC1IMAGE_H
20 #define LERC1IMAGE_Hcxx . . $ `frmts/mrf/LERCV1/Lerc1Image.h:20:9`!
21
22 #include <cstring>
23 #include <vector>
24
25 #ifndef NAMESPACE_LERC1_START
26 #define NAMESPACE_LERC1_STARTcxx . . $ `frmts/mrf/LERCV1/Lerc1Image.h:26:9`! \
27 namespace Lerc1NS \
28 {
29 #define NAMESPACE_LERC1_ENDcxx . . $ `frmts/mrf/LERCV1/Lerc1Image.h:29:9`! }
30 #define USING_NAMESPACE_LERC1cxx . . $ `frmts/mrf/LERCV1/Lerc1Image.h:30:9`! using namespace Lerc1NS;
31 #endif
32
33 NAMESPACE_LERC1_STARTcxx . . $ Lerc1NS/
34 static_assert(sizeof(float) == 4, "lerc requires float to be exactly 4 bytes");
35
36 typedef unsigned char Bytecxx . . $ Lerc1NS/Byte#;
37
38 /** BitMaskV1 - Convenient and fast access to binary mask bits
39 * includes RLE compression and decompression
40 *
41 */
42
43 class BitMaskV1cxx . . $ Lerc1NS/BitMaskV1#
44 {
45 public:
46 BitMaskV1cxx . . $ Lerc1NS/BitMaskV1#BitMaskV1(49f6e7a06ebc5aa8).() : m_nRowscxx . . $ Lerc1NS/BitMaskV1#m_nRows.(0), m_nColscxx . . $ Lerc1NS/BitMaskV1#m_nCols.(0)
47 {
48 }
49
50 int sizecxx . . $ Lerc1NS/BitMaskV1#size(455f465bc33b4cdf).() const
51 {
52 return 1 + (m_nColscxx . . $ Lerc1NS/BitMaskV1#m_nCols. * m_nRowscxx . . $ Lerc1NS/BitMaskV1#m_nRows. - 1) / 8;
53 }
54
55 void Setcxx . . $ Lerc1NS/BitMaskV1#Set(918ebd27a9ddbad3).(int k, bool v)
56 {
57 if (v)
58 SetValidcxx . . $ Lerc1NS/BitMaskV1#SetValid(d4f767463ce0a6b3).(k);
59 else
60 SetInvalidcxx . . $ Lerc1NS/BitMaskV1#SetInvalid(d4f767463ce0a6b3).(k);
61 }
62
63 Bytecxx . . $ Lerc1NS/Byte# IsValidcxx . . $ Lerc1NS/BitMaskV1#IsValid(8e2d02308e688b6b).(int k) const
64 {
65 return (bitscxx . . $ Lerc1NS/BitMaskV1#bits.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).k >> 3] & Bitcxx . . $ Lerc1NS/BitMaskV1#Bit(bc0fba5608a0bfe7).(k)) != 0;
66 }
67
68 void resizecxx . . $ Lerc1NS/BitMaskV1#resize(3e454b8ccf442868).(int nCols, int nRows)
69 {
70 m_nRowscxx . . $ Lerc1NS/BitMaskV1#m_nRows. = nRows;
71 m_nColscxx . . $ Lerc1NS/BitMaskV1#m_nCols. = nCols;
72 bitscxx . . $ Lerc1NS/BitMaskV1#bits..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(sizecxx . . $ Lerc1NS/BitMaskV1#size(455f465bc33b4cdf).());
73 }
74
75 // max RLE compressed size is n + 4 + 2 * (n - 1) / 32767
76 // Returns encoded size
77 int RLEcompresscxx . . $ Lerc1NS/BitMaskV1#RLEcompress(a73b67534c650005).(Bytecxx . . $ Lerc1NS/Byte# *aRLE) const;
78 // Encoded size, without doing the work
79 int RLEsizecxx . . $ Lerc1NS/BitMaskV1#RLEsize(455f465bc33b4cdf).() const;
80 // Decompress a RLE bitmask, bitmask size should be already set
81 // Returns false if input seems wrong
82 bool RLEdecompresscxx . . $ Lerc1NS/BitMaskV1#RLEdecompress(3a706fe4966174d9).(const Bytecxx . . $ Lerc1NS/Byte# *src, size_t sz);
83
84 private:
85 int m_nRowscxx . . $ Lerc1NS/BitMaskV1#m_nRows., m_nColscxx . . $ Lerc1NS/BitMaskV1#m_nCols.;
86 stdcxx . . $ std/::vectorcxx . . $ std/vector#<Bytecxx . . $ Lerc1NS/Byte#> bitscxx . . $ Lerc1NS/BitMaskV1#bits.;
87
88 static Bytecxx . . $ Lerc1NS/Byte# Bitcxx . . $ Lerc1NS/BitMaskV1#Bit(bc0fba5608a0bfe7).(int k)
89 {
90 return static_cast<Bytecxx . . $ Lerc1NS/Byte#>(0x80 >> (k & 7));
91 }
92
93 void SetValidcxx . . $ Lerc1NS/BitMaskV1#SetValid(d4f767463ce0a6b3).(int k)
94 {
95 bitscxx . . $ Lerc1NS/BitMaskV1#bits.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).k >> 3] |= Bitcxx . . $ Lerc1NS/BitMaskV1#Bit(bc0fba5608a0bfe7).(k);
96 }
97
98 void SetInvalidcxx . . $ Lerc1NS/BitMaskV1#SetInvalid(d4f767463ce0a6b3).(int k)
99 {
100 bitscxx . . $ Lerc1NS/BitMaskV1#bits.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).k >> 3] &= ~Bitcxx . . $ Lerc1NS/BitMaskV1#Bit(bc0fba5608a0bfe7).(k);
101 }
102 };
103
104 template <typename T> class TImagecxx . . $ Lerc1NS/TImage#
105 {
106 public:
107 TImagecxx . . $ Lerc1NS/TImage#`TImage<T>`(49f6e7a06ebc5aa8).() : width_cxx . . $ Lerc1NS/TImage#width_.(0), height_cxx . . $ Lerc1NS/TImage#height_.(0)
108 {
109 }
110
111 ~cxx . . $ Lerc1NS/TImage#`~TImage<T>`(49f6e7a06ebc5aa8).TImage()
112 {
113 }
114
115 bool setsizecxx . . $ Lerc1NS/TImage#setsize(cf9ef193275fa6d8).(int width, int height)
116 {
117 width_cxx . . $ Lerc1NS/TImage#width_. = width;
118 height_cxx . . $ Lerc1NS/TImage#height_. = height;
119 valuescxx . . $ Lerc1NS/TImage#values..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(getSizecxx . . $ Lerc1NS/TImage#getSize(455f465bc33b4cdf).());
120 return true;
121 }
122
123 int getWidthcxx . . $ Lerc1NS/TImage#getWidth(455f465bc33b4cdf).() const
124 {
125 return width_cxx . . $ Lerc1NS/TImage#width_.;
126 }
127
128 int getHeightcxx . . $ Lerc1NS/TImage#getHeight(455f465bc33b4cdf).() const
129 {
130 return height_cxx . . $ Lerc1NS/TImage#height_.;
131 }
132
133 int getSizecxx . . $ Lerc1NS/TImage#getSize(455f465bc33b4cdf).() const
134 {
135 return width_cxx . . $ Lerc1NS/TImage#width_. * height_cxx . . $ Lerc1NS/TImage#height_.;
136 }
137
138 const T &operatorcxx . . $ Lerc1NS/TImage#`operator()`(17c8b25841cc6a04).()(int row, int col) const
139 {
140 return valuescxx . . $ Lerc1NS/TImage#values.[row * width_cxx . . $ Lerc1NS/TImage#width_. + col];
141 }
142
143 T &operatorcxx . . $ Lerc1NS/TImage#`operator()`(81532356f20a340f).()(int row, int col)
144 {
145 return valuescxx . . $ Lerc1NS/TImage#values.[row * width_cxx . . $ Lerc1NS/TImage#width_. + col];
146 }
147
148 const T *datacxx . . $ Lerc1NS/TImage#data(1016ee5406d91ab9).() const
149 {
150 return valuescxx . . $ Lerc1NS/TImage#values..datacxx . . $ std/vector#data(8e614c7de0b1573e).();
151 }
152
153 private:
154 int width_cxx . . $ Lerc1NS/TImage#width_., height_cxx . . $ Lerc1NS/TImage#height_.;
155 stdcxx . . $ std/::vectorcxx . . $ std/vector#<T> valuescxx . . $ Lerc1NS/TImage#values.;
156 };
157
158 class Lerc1Imagecxx . . $ Lerc1NS/Lerc1Image# final : public TImagecxx . . $ Lerc1NS/TImage#<float>
159 {
160 protected:
161 struct InfoFromComputeNumBytescxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes#
162 {
163 double maxZErrorcxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes#maxZError.;
164 int numTilesVertCntcxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes#numTilesVertCnt.;
165 int numTilesHoriCntcxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes#numTilesHoriCnt.;
166 int numBytesCntcxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes#numBytesCnt.;
167 float maxCntInImgcxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes#maxCntInImg.;
168 int numTilesVertZcxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes#numTilesVertZ.;
169 int numTilesHoriZcxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes#numTilesHoriZ.;
170 int numBytesZcxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes#numBytesZ.;
171 float maxZInImgcxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes#maxZInImg.;
172
173 InfoFromComputeNumBytescxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes#InfoFromComputeNumBytes(49f6e7a06ebc5aa8).()
174 {
175 stdcxx . . $ std/::memset(this, 0, sizeof(*this));
176 }
177 };
178
179 bool findTilingcxx . . $ Lerc1NS/Lerc1Image#findTiling(53a22b785be7aacd).(double maxZError, int &numTilesVert, int &numTilesHori,
180 int &numBytesOpt, float &maxValInImg) const;
181
182 bool writeTilescxx . . $ Lerc1NS/Lerc1Image#writeTiles(631aa45a0d632d3a).(double maxZError, int numTilesVert, int numTilesHori,
183 Bytecxx . . $ Lerc1NS/Byte# *bArr, int &numBytes, float &maxValInImg) const;
184
185 bool readTilescxx . . $ Lerc1NS/Lerc1Image#readTiles(359103977d2cc5b4).(double maxZErrorInFile, int numTilesVert, int numTilesHori,
186 float maxValInImg, Bytecxx . . $ Lerc1NS/Byte# *bArr, size_t nRemainingBytes);
187
188 bool computeZStatscxx . . $ Lerc1NS/Lerc1Image#computeZStats(b0d7a86b4471159a).(int r0, int r1, int c0, int c1, float &zMin, float &zMax,
189 int &numValidPixel, int &numFinite) const;
190
191 // returns true if all floating point values in the region have the same
192 // binary representation
193 bool isallsamevalcxx . . $ Lerc1NS/Lerc1Image#isallsameval(b98a7ec14dc3fd19).(int r0, int r1, int c0, int c1) const;
194
195 bool writeZTilecxx . . $ Lerc1NS/Lerc1Image#writeZTile(e6b50bf01f299fa1).(Bytecxx . . $ Lerc1NS/Byte# **ppByte, int &numBytes, int r0, int r1, int c0,
196 int c1, int numValidPixel, float zMin, float zMax,
197 double maxZError) const;
198
199 bool readZTilecxx . . $ Lerc1NS/Lerc1Image#readZTile(cf7a4153af542bd2).(Bytecxx . . $ Lerc1NS/Byte# **ppByte, size_t &nRemainingBytes, int r0, int r1,
200 int c0, int c1, double maxZErrorInFile, float maxZInImg);
201
202 unsigned int
203 computeNumBytesNeededToWritecxx . . $ Lerc1NS/Lerc1Image#computeNumBytesNeededToWrite(571850009b068a10).(double maxZError, bool onlyZPart,
204 InfoFromComputeNumBytescxx . . $ Lerc1NS/Lerc1Image#InfoFromComputeNumBytes# *info) const;
205
206 stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int> idataVeccxx . . $ Lerc1NS/Lerc1Image#idataVec.; // temporary buffer
207 BitMaskV1cxx . . $ Lerc1NS/BitMaskV1# maskcxx . . $ Lerc1NS/Lerc1Image#mask.;
208
209 public:
210 /// binary file IO with optional compression
211 /// (maxZError = 0 means no lossy compression for Z; the mask part is
212 /// compressed lossless or not at all) read succeeds only if maxZError on
213 /// file <= maxZError requested (!)
214
215 Lerc1Imagecxx . . $ Lerc1NS/Lerc1Image#Lerc1Image(49f6e7a06ebc5aa8).()
216 {
217 }
218
219 ~cxx . . $ Lerc1NS/Lerc1Image#`~Lerc1Image`(ced63f7c635d850d).Lerc1Imagecxx . . $ Lerc1NS/Lerc1Image#()
220 {
221 }
222
223 static unsigned int computeNumBytesNeededToWriteVoidImagecxx . . $ Lerc1NS/Lerc1Image#computeNumBytesNeededToWriteVoidImage(db52760e79bf9054).();
224
225 // Only initialize the size from the header, if LERC1
226 static bool getwhcxx . . $ Lerc1NS/Lerc1Image#getwh(37c2e7a019a64086).(const Bytecxx . . $ Lerc1NS/Byte# *ppByte, size_t nBytes, int &w, int &h);
227
228 void resizecxx . . $ Lerc1NS/Lerc1Image#resize(3e454b8ccf442868).(int width, int height)
229 {
230 setsizecxx . . $ Lerc1NS/TImage#setsize(cf9ef193275fa6d8).(width, height);
231 maskcxx . . $ Lerc1NS/Lerc1Image#mask..resizecxx . . $ Lerc1NS/BitMaskV1#resize(3e454b8ccf442868).(getWidthcxx . . $ Lerc1NS/TImage#getWidth(455f465bc33b4cdf).(), getHeightcxx . . $ Lerc1NS/TImage#getHeight(455f465bc33b4cdf).());
232 }
233
234 bool IsValidcxx . . $ Lerc1NS/Lerc1Image#IsValid(88e30549ca55c866).(int row, int col) const
235 {
236 return maskcxx . . $ Lerc1NS/Lerc1Image#mask..IsValidcxx . . $ Lerc1NS/BitMaskV1#IsValid(8e2d02308e688b6b).(row * getWidthcxx . . $ Lerc1NS/TImage#getWidth(455f465bc33b4cdf).() + col) != 0;
237 }
238
239 void SetMaskcxx . . $ Lerc1NS/Lerc1Image#SetMask(6908015b96d379c0).(int row, int col, bool v)
240 {
241 maskcxx . . $ Lerc1NS/Lerc1Image#mask..Setcxx . . $ Lerc1NS/BitMaskV1#Set(918ebd27a9ddbad3).(row * getWidthcxx . . $ Lerc1NS/TImage#getWidth(455f465bc33b4cdf).() + col, v);
242 }
243
244 // Read and write into a memory buffer
245 bool writecxx . . $ Lerc1NS/Lerc1Image#write(f2ef986e1ca837d).(Bytecxx . . $ Lerc1NS/Byte# **ppByte, double maxZError = 0,
246 bool onlyZPart = false) const;
247 bool readcxx . . $ Lerc1NS/Lerc1Image#read(6ab0b3f2bde2cd91).(Bytecxx . . $ Lerc1NS/Byte# **ppByte, size_t &nRemainingBytes, double maxZError,
248 bool onlyZPart = false);
249 };
250
251 NAMESPACE_LERC1_ENDcxx . . $ `frmts/mrf/LERCV1/Lerc1Image.h:29:9`!
252 #endif