| 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 | Lucian Plesea (provided checksum code) |
| 23 | */ |
| 24 | |
| 25 | #include <climits> |
| 26 | #include <typeinfo> |
| 27 | #include "Defines.h"cxx . . $ `<file>/src/LercLib/Defines.h`/ |
| 28 | #include "Lerc2.h"cxx . . $ `<file>/src/LercLib/Lerc2.h`/ |
| 29 | #include "Huffman.h"cxx . . $ `<file>/src/LercLib/Huffman.h`/ |
| 30 | #include "RLE.h"cxx . . $ `<file>/src/LercLib/RLE.h`/ |
| 31 | |
| 32 | USING_NAMESPACE_LERCcxx . . $ `src/LercLib/Defines.h:37:9`! |
| 33 | using namespace std; |
| 34 | |
| 35 | // -------------------------------------------------------------------------- ; |
| 36 | |
| 37 | Lerc2cxx . . $ LercNS/Lerc2#::Lerc2cxx . . $ LercNS/Lerc2#Lerc2(49f6e7a06ebc5aa8).() |
| 38 | { |
| 39 | Initcxx . . $ LercNS/Lerc2#Init(49f6e7a06ebc5aa8).(); |
| 40 | } |
| 41 | |
| 42 | // -------------------------------------------------------------------------- ; |
| 43 | |
| 44 | Lerc2cxx . . $ LercNS/Lerc2#::Lerc2cxx . . $ LercNS/Lerc2#Lerc2(fe02dd8c5b4270ed).(int nDepth, int nCols, int nRows, const Bytecxx . . $ LercNS/Byte#* pMaskBits) |
| 45 | { |
| 46 | Initcxx . . $ LercNS/Lerc2#Init(49f6e7a06ebc5aa8).(); |
| 47 | Setcxx . . $ LercNS/Lerc2#Set(2c716c8d5f4e4280).(nDepth, nCols, nRows, pMaskBits); |
| 48 | } |
| 49 | |
| 50 | // -------------------------------------------------------------------------- ; |
| 51 | |
| 52 | bool Lerc2cxx . . $ LercNS/Lerc2#::SetEncoderToOldVersioncxx . . $ LercNS/Lerc2#SetEncoderToOldVersion(83c267b20bac841a).(int version) |
| 53 | { |
| 54 | if (version < 2 || version > CurrentVersioncxx . . $ LercNS/Lerc2#CurrentVersion(b126dc7c1de90089).()) |
| 55 | return false; |
| 56 | |
| 57 | if (version < 4 && m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth. > 1) |
| 58 | return false; |
| 59 | |
| 60 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. = version; |
| 61 | |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | // -------------------------------------------------------------------------- ; |
| 66 | |
| 67 | void Lerc2cxx . . $ LercNS/Lerc2#::Initcxx . . $ LercNS/Lerc2#Init(49f6e7a06ebc5aa8).() |
| 68 | { |
| 69 | m_microBlockSizecxx . . $ LercNS/Lerc2#m_microBlockSize. = 8; |
| 70 | m_maxValToQuantizecxx . . $ LercNS/Lerc2#m_maxValToQuantize. = 0; |
| 71 | m_encodeMaskcxx . . $ LercNS/Lerc2#m_encodeMask. = true; |
| 72 | m_writeDataOneSweepcxx . . $ LercNS/Lerc2#m_writeDataOneSweep. = false; |
| 73 | m_minMaxSetcxx . . $ LercNS/Lerc2#m_minMaxSet. = false; |
| 74 | m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. = IEM_Tilingcxx . . $ LercNS/Lerc2#IEM_Tiling.; |
| 75 | |
| 76 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..RawInitcxx . . $ LercNS/Lerc2#HeaderInfo#RawInit(49f6e7a06ebc5aa8).(); |
| 77 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. = CurrentVersioncxx . . $ LercNS/Lerc2#CurrentVersion(b126dc7c1de90089).(); |
| 78 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..microBlockSizecxx . . $ LercNS/Lerc2#HeaderInfo#microBlockSize. = m_microBlockSizecxx . . $ LercNS/Lerc2#m_microBlockSize.; |
| 79 | } |
| 80 | |
| 81 | // -------------------------------------------------------------------------- ; |
| 82 | |
| 83 | bool Lerc2cxx . . $ LercNS/Lerc2#::Setcxx . . $ LercNS/Lerc2#Set(2c716c8d5f4e4280).(int nDepth, int nCols, int nRows, const Bytecxx . . $ LercNS/Byte#* pMaskBits) |
| 84 | { |
| 85 | if (nDepth > 1 && m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. < 4) |
| 86 | return false; |
| 87 | |
| 88 | if (!m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..SetSizecxx . . $ LercNS/BitMask#SetSize(cf9ef193275fa6d8).(nCols, nRows)) |
| 89 | return false; |
| 90 | |
| 91 | if (pMaskBits) |
| 92 | { |
| 93 | memcpy(m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..Bitscxx . . $ LercNS/BitMask#Bits(37d8967d10cb1e7b).(), pMaskBits, m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..Sizecxx . . $ LercNS/BitMask#Size(fe4d2d262d4164a8).()); |
| 94 | |
| 95 | int64_t numValid = m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..CountValidBitscxx . . $ LercNS/BitMask#CountValidBits(57a65ae535d7db84).(); |
| 96 | if (numValid < 0 || numValid > (int64_t)INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!) |
| 97 | return false; |
| 98 | |
| 99 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. = (int)numValid; |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. = nCols * nRows; |
| 104 | m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..SetAllValidcxx . . $ LercNS/BitMask#SetAllValid(83f5f38750778ac8).(); |
| 105 | } |
| 106 | |
| 107 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth. = nDepth; |
| 108 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. = nCols; |
| 109 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. = nRows; |
| 110 | |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | // -------------------------------------------------------------------------- ; |
| 115 | |
| 116 | bool Lerc2cxx . . $ LercNS/Lerc2#::SetNoDataValuescxx . . $ LercNS/Lerc2#SetNoDataValues(33f2d77f1c62171e).(bool bNeedsNoDataVal, double noDataVal, double noDataValOrig) |
| 117 | { |
| 118 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. < 6) |
| 119 | return false; |
| 120 | |
| 121 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..bPassNoDataValuescxx . . $ LercNS/Lerc2#HeaderInfo#bPassNoDataValues. = bNeedsNoDataVal; |
| 122 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..noDataValcxx . . $ LercNS/Lerc2#HeaderInfo#noDataVal. = bNeedsNoDataVal ? noDataVal : 0; |
| 123 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..noDataValOrigcxx . . $ LercNS/Lerc2#HeaderInfo#noDataValOrig. = bNeedsNoDataVal ? noDataValOrig : 0; |
| 124 | |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | // -------------------------------------------------------------------------- ; |
| 129 | |
| 130 | bool Lerc2cxx . . $ LercNS/Lerc2#::SetNumBlobsMoreToComecxx . . $ LercNS/Lerc2#SetNumBlobsMoreToCome(83c267b20bac841a).(int nBlobsMore) |
| 131 | { |
| 132 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. < 6) |
| 133 | return false; |
| 134 | |
| 135 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nBlobsMorecxx . . $ LercNS/Lerc2#HeaderInfo#nBlobsMore. = nBlobsMore; |
| 136 | |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | // -------------------------------------------------------------------------- ; |
| 141 | |
| 142 | bool Lerc2cxx . . $ LercNS/Lerc2#::SetIsAllIntcxx . . $ LercNS/Lerc2#SetIsAllInt(efaadfb7dc14930a).(bool bIsAllInt) |
| 143 | { |
| 144 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. < 6) |
| 145 | return false; |
| 146 | |
| 147 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..bIsIntcxx . . $ LercNS/Lerc2#HeaderInfo#bIsInt. = bIsAllInt ? 1 : 0; |
| 148 | |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | // -------------------------------------------------------------------------- ; |
| 153 | |
| 154 | bool Lerc2cxx . . $ LercNS/Lerc2#::SetMinMaxcxx . . $ LercNS/Lerc2#SetMinMax(9f72e67440d8b329).(int nDepth, double minVal, double maxVal) |
| 155 | { |
| 156 | ClearMinMaxcxx . . $ LercNS/Lerc2#ClearMinMax(49f6e7a06ebc5aa8).(); |
| 157 | |
| 158 | if (nDepth != 1 || minVal > maxVal) |
| 159 | return false; |
| 160 | |
| 161 | m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec..assigncxx . . $ std/vector#assign(3804226c8c0acbc3).(1, minVal); |
| 162 | m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec..assigncxx . . $ std/vector#assign(3804226c8c0acbc3).(1, maxVal); |
| 163 | m_minMaxSetcxx . . $ LercNS/Lerc2#m_minMaxSet. = true; |
| 164 | |
| 165 | return true; |
| 166 | } |
| 167 | |
| 168 | // -------------------------------------------------------------------------- ; |
| 169 | |
| 170 | void Lerc2cxx . . $ LercNS/Lerc2#::ClearMinMaxcxx . . $ LercNS/Lerc2#ClearMinMax(49f6e7a06ebc5aa8).() |
| 171 | { |
| 172 | m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec..clearcxx . . $ std/vector#clear(ced63f7c635d850d).(); |
| 173 | m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec..clearcxx . . $ std/vector#clear(ced63f7c635d850d).(); |
| 174 | m_minMaxSetcxx . . $ LercNS/Lerc2#m_minMaxSet. = false; |
| 175 | } |
| 176 | |
| 177 | // -------------------------------------------------------------------------- ; |
| 178 | |
| 179 | template<class T> |
| 180 | unsigned int Lerc2cxx . . $ LercNS/Lerc2#::ComputeNumBytesNeededToWritecxx . . $ LercNS/Lerc2#ComputeNumBytesNeededToWrite(30bb643c04a8fd76).(const T* arr, double maxZError, bool encodeMask) |
| 181 | { |
| 182 | if (!arr || !IsLittleEndianSystemcxx . . $ LercNS/Lerc2#IsLittleEndianSystem(c9857a73d68e59ba).()) |
| 183 | return 0; |
| 184 | |
| 185 | // header |
| 186 | unsigned int nBytesHeaderMask = ComputeNumBytesHeaderToWritecxx . . $ LercNS/Lerc2#ComputeNumBytesHeaderToWrite(c71a4331653d1346).(m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.); |
| 187 | |
| 188 | // valid / invalid mask |
| 189 | int numValid = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel.; |
| 190 | int numTotal = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. * m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; |
| 191 | |
| 192 | bool needMask = numValid > 0 && numValid < numTotal; |
| 193 | |
| 194 | m_encodeMaskcxx . . $ LercNS/Lerc2#m_encodeMask. = encodeMask; |
| 195 | |
| 196 | nBytesHeaderMask += 1 * sizeof(int); // the mask encode numBytes |
| 197 | |
| 198 | if (needMask && encodeMask) |
| 199 | { |
| 200 | RLEcxx . . $ LercNS/RLE# rlecxx . . $ LercNS/RLE#RLE(49f6e7a06ebc5aa8).; |
| 201 | size_t n = rle.computeNumBytesRLEcxx . . $ LercNS/RLE#computeNumBytesRLE(c94820f36e75556c).((const Bytecxx . . $ LercNS/Byte#*)m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..Bitscxx . . $ LercNS/BitMask#Bits(37d8967d10cb1e7b).(), m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..Sizecxx . . $ LercNS/BitMask#Size(fe4d2d262d4164a8).()); |
| 202 | nBytesHeaderMask += (unsigned int)n; |
| 203 | } |
| 204 | |
| 205 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. = GetDataTypecxx . . $ LercNS/Lerc2#GetDataType(36b83e793b7541af).(arr[0]); |
| 206 | |
| 207 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Undefinedcxx . . $ LercNS/Lerc2#DT_Undefined.) |
| 208 | return 0; |
| 209 | |
| 210 | if (maxZError == 777) // cheat code |
| 211 | maxZError = -0.01; |
| 212 | |
| 213 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. < DT_Floatcxx . . $ LercNS/Lerc2#DT_Float.) // integer types |
| 214 | { |
| 215 | // interpret a negative maxZError as bit plane epsilon; dflt = 0.01; |
| 216 | if (maxZError < 0 && (!TryBitPlaneCompressioncxx . . $ LercNS/Lerc2#TryBitPlaneCompression(fcbe6167061550ea).(arr, -maxZError, maxZError))) |
| 217 | maxZError = 0; |
| 218 | |
| 219 | maxZError = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(0.5, floor(maxZError)); |
| 220 | } |
| 221 | else // float types |
| 222 | { |
| 223 | if (maxZError < 0) // don't allow bit plane compression for float or double |
| 224 | return 0; |
| 225 | |
| 226 | double maxZErrorNew = maxZError; |
| 227 | if (maxZError > 0 && TryRaiseMaxZErrorcxx . . $ LercNS/Lerc2#TryRaiseMaxZError(b6fd15fa3aacb116).(arr, maxZErrorNew)) |
| 228 | { |
| 229 | //printf("%f --> %f\n", maxZError, maxZErrorNew); |
| 230 | maxZError = maxZErrorNew; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. = maxZError; |
| 235 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin. = 0; |
| 236 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax. = 0; |
| 237 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..microBlockSizecxx . . $ LercNS/Lerc2#HeaderInfo#microBlockSize. = m_microBlockSizecxx . . $ LercNS/Lerc2#m_microBlockSize.; |
| 238 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize. = nBytesHeaderMask; |
| 239 | |
| 240 | if (numValid == 0) |
| 241 | return nBytesHeaderMask; |
| 242 | |
| 243 | m_maxValToQuantizecxx . . $ LercNS/Lerc2#m_maxValToQuantize. = GetMaxValToQuantizecxx . . $ LercNS/Lerc2#GetMaxValToQuantize(3707fc1f19bbe2a2).(m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt.); |
| 244 | |
| 245 | Bytecxx . . $ LercNS/Byte#* ptr = nullptr; // only emulate the writing and just count the bytes needed |
| 246 | int nBytesTiling = 0; |
| 247 | |
| 248 | if ((!m_minMaxSetcxx . . $ LercNS/Lerc2#m_minMaxSet. || m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth. > 1) |
| 249 | && !ComputeMinMaxRangescxx . . $ LercNS/Lerc2#ComputeMinMaxRanges(ac2d38011843179f).(arr, m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec., m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec.)) // need this for diff encoding before WriteTiles() |
| 250 | return 0; |
| 251 | |
| 252 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin. = *stdcxx . . $ std/::min_elementcxx . . $ std/min_element(f80f7d6260b3ee3a).(m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec..begincxx . . $ std/vector#begin(55a6de06420d4903).(), m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec..endcxx . . $ std/vector#end(55a6de06420d4903).()); |
| 253 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax. = *stdcxx . . $ std/::max_elementcxx . . $ std/max_element(f80f7d6260b3ee3a).(m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec..begincxx . . $ std/vector#begin(55a6de06420d4903).(), m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec..endcxx . . $ std/vector#end(55a6de06420d4903).()); |
| 254 | |
| 255 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin. == m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax.) // image is const |
| 256 | return nBytesHeaderMask; |
| 257 | |
| 258 | int nDepth = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 259 | |
| 260 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 4) |
| 261 | { |
| 262 | // add the min max ranges behind the mask and before the main data; |
| 263 | // so we do not write it if no valid pixel or all same value const |
| 264 | |
| 265 | size_t currBlobSize = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize.; |
| 266 | currBlobSize += sizeof(T) * nDepth * 2; |
| 267 | |
| 268 | if (currBlobSize > (size_t)INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!) // limit Lerc blob size per band to 2 GB |
| 269 | return 0; |
| 270 | |
| 271 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize. = (int)currBlobSize; |
| 272 | |
| 273 | bool minMaxEqual = false; |
| 274 | if (!CheckMinMaxRangescxx . . $ LercNS/Lerc2#CheckMinMaxRanges(dadd4ad61e27fbc).(minMaxEqual)) |
| 275 | return 0; |
| 276 | |
| 277 | if (minMaxEqual) |
| 278 | return m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize.; // all nDepth bands are const |
| 279 | } |
| 280 | |
| 281 | // data |
| 282 | if (!WriteTilescxx . . $ LercNS/Lerc2#WriteTiles(b7537629c01bf85b).(arr, &ptr, nBytesTiling) || nBytesTiling < 0) |
| 283 | return 0; |
| 284 | |
| 285 | m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. = IEM_Tilingcxx . . $ LercNS/Lerc2#IEM_Tiling.; |
| 286 | int nBytesData = nBytesTiling; |
| 287 | int nBytesHuffman = 0; |
| 288 | |
| 289 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanIntcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanInt(50ce9a9e25b4a850).()) |
| 290 | { |
| 291 | ImageEncodeModecxx . . $ LercNS/Lerc2#ImageEncodeMode# huffmanEncMode; |
| 292 | ComputeHuffmanCodescxx . . $ LercNS/Lerc2#ComputeHuffmanCodes(262ecf6b652a9a81).(arr, nBytesHuffman, huffmanEncMode, m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes.); // save Huffman codes for later use |
| 293 | |
| 294 | if (nBytesHuffman < 0) |
| 295 | nBytesHuffman = INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!; |
| 296 | |
| 297 | if (!m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes..emptycxx . . $ std/vector#empty(3482b152b9333168).() && nBytesHuffman < nBytesTiling) |
| 298 | { |
| 299 | m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. = huffmanEncMode; |
| 300 | nBytesData = nBytesHuffman; |
| 301 | } |
| 302 | else |
| 303 | m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(0); |
| 304 | } |
| 305 | else if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanFltcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanFlt(50ce9a9e25b4a850).()) |
| 306 | { |
| 307 | m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(0); |
| 308 | |
| 309 | bool rv = m_lfpccxx . . $ LercNS/Lerc2#m_lfpc..ComputeHuffmanCodesFltcxx . . $ LercNS/LosslessFPCompression#ComputeHuffmanCodesFlt(dbf79bfbd080cdb0).(arr, (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.), |
| 310 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols., m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows., m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.); |
| 311 | |
| 312 | if (!rv) |
| 313 | return 0; |
| 314 | |
| 315 | if (rv) |
| 316 | { |
| 317 | nBytesHuffman = m_lfpccxx . . $ LercNS/Lerc2#m_lfpc..compressedLengthcxx . . $ LercNS/LosslessFPCompression#compressedLength(455f465bc33b4cdf).(); |
| 318 | |
| 319 | if (nBytesHuffman < 0) |
| 320 | nBytesHuffman = INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!; |
| 321 | |
| 322 | if (nBytesHuffman < nBytesTiling * 0.9) // demand at least 10% better than not Huffman |
| 323 | { |
| 324 | nBytesData = nBytesHuffman; |
| 325 | m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. = IEM_DeltaDeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaDeltaHuffman.; |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | m_writeDataOneSweepcxx . . $ LercNS/Lerc2#m_writeDataOneSweep. = false; |
| 331 | size_t nBytesDataOneSweep = sizeof(T) * nDepth * numValid; |
| 332 | |
| 333 | { |
| 334 | // try with double block size to reduce block header overhead, if |
| 335 | if (((size_t)nBytesTiling * 8 < (size_t)numTotal * nDepth * 1.5) // resulting bit rate < x (2 bpp) |
| 336 | && ((size_t)nBytesTiling < 4 * nBytesDataOneSweep) // bit stuffing is effective |
| 337 | && (nBytesHuffman == 0 || (size_t)nBytesTiling < (size_t)2 * nBytesHuffman) // not much worse than huffman (otherwise huffman wins anyway) |
| 338 | && (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. > m_microBlockSizecxx . . $ LercNS/Lerc2#m_microBlockSize. || m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. > m_microBlockSizecxx . . $ LercNS/Lerc2#m_microBlockSize.)) |
| 339 | { |
| 340 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..microBlockSizecxx . . $ LercNS/Lerc2#HeaderInfo#microBlockSize. = m_microBlockSizecxx . . $ LercNS/Lerc2#m_microBlockSize. * 2; |
| 341 | |
| 342 | int nBytes2 = 0; |
| 343 | if (!WriteTilescxx . . $ LercNS/Lerc2#WriteTiles(b7537629c01bf85b).(arr, &ptr, nBytes2) || nBytes2 < 0) // no huffman in here anymore |
| 344 | return 0; |
| 345 | |
| 346 | if (nBytes2 <= nBytesData) |
| 347 | { |
| 348 | nBytesData = nBytes2; |
| 349 | m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. = IEM_Tilingcxx . . $ LercNS/Lerc2#IEM_Tiling.; |
| 350 | m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(0); |
| 351 | } |
| 352 | else |
| 353 | { |
| 354 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..microBlockSizecxx . . $ LercNS/Lerc2#HeaderInfo#microBlockSize. = m_microBlockSizecxx . . $ LercNS/Lerc2#m_microBlockSize.; // reset to orig |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanIntcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanInt(50ce9a9e25b4a850).() || m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanFltcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanFlt(50ce9a9e25b4a850).()) |
| 360 | nBytesData += 1; // flag for image encode mode |
| 361 | |
| 362 | size_t totalBlobSize = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize.; |
| 363 | |
| 364 | if (nBytesDataOneSweep <= (size_t)nBytesData) |
| 365 | { |
| 366 | m_writeDataOneSweepcxx . . $ LercNS/Lerc2#m_writeDataOneSweep. = true; // fallback: write data binary uncompressed in one sweep |
| 367 | totalBlobSize += 1 + nBytesDataOneSweep; // header, mask, min max ranges, flag, data one sweep |
| 368 | } |
| 369 | else |
| 370 | { |
| 371 | m_writeDataOneSweepcxx . . $ LercNS/Lerc2#m_writeDataOneSweep. = false; |
| 372 | totalBlobSize += 1 + nBytesData; // header, mask, min max ranges, flag(s), data |
| 373 | } |
| 374 | |
| 375 | if (totalBlobSize > (size_t)INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!) // limit Lerc blob size per band to 2 GB |
| 376 | return 0; |
| 377 | |
| 378 | m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize. = (int)totalBlobSize; |
| 379 | |
| 380 | return m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize.; |
| 381 | } |
| 382 | |
| 383 | // -------------------------------------------------------------------------- ; |
| 384 | |
| 385 | template unsigned int Lerc2::ComputeNumBytesNeededToWrite<signed char>(const signed char* arr, double maxZError, bool encodeMask); |
| 386 | template unsigned int Lerc2::ComputeNumBytesNeededToWrite<Byte>(const Byte* arr, double maxZError, bool encodeMask); |
| 387 | template unsigned int Lerc2::ComputeNumBytesNeededToWrite<short>(const short* arr, double maxZError, bool encodeMask); |
| 388 | template unsigned int Lerc2::ComputeNumBytesNeededToWrite<unsigned short>(const unsigned short* arr, double maxZError, bool encodeMask); |
| 389 | template unsigned int Lerc2::ComputeNumBytesNeededToWrite<int>(const int* arr, double maxZError, bool encodeMask); |
| 390 | template unsigned int Lerc2::ComputeNumBytesNeededToWrite<unsigned int>(const unsigned int* arr, double maxZError, bool encodeMask); |
| 391 | template unsigned int Lerc2::ComputeNumBytesNeededToWrite<float>(const float* arr, double maxZError, bool encodeMask); |
| 392 | template unsigned int Lerc2::ComputeNumBytesNeededToWrite<double>(const double* arr, double maxZError, bool encodeMask); |
| 393 | |
| 394 | // -------------------------------------------------------------------------- ; |
| 395 | |
| 396 | template<class T> |
| 397 | bool Lerc2cxx . . $ LercNS/Lerc2#::Encodecxx . . $ LercNS/Lerc2#Encode(9add4431f33ebb71).(const T* arr, Bytecxx . . $ LercNS/Byte#** ppByte) |
| 398 | { |
| 399 | if (!arr || !ppByte || !IsLittleEndianSystemcxx . . $ LercNS/Lerc2#IsLittleEndianSystem(c9857a73d68e59ba).()) |
| 400 | return false; |
| 401 | |
| 402 | Bytecxx . . $ LercNS/Byte#* ptrBlob = *ppByte; // keep a ptr to the start of the blob |
| 403 | |
| 404 | if (!WriteHeadercxx . . $ LercNS/Lerc2#WriteHeader(a9c1fa508da30057).(ppByte, m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.)) |
| 405 | return false; |
| 406 | |
| 407 | if (!WriteMaskcxx . . $ LercNS/Lerc2#WriteMask(2c1b2a8bb0754e17).(ppByte)) |
| 408 | return false; |
| 409 | |
| 410 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. == 0 || m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin. == m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax.) |
| 411 | { |
| 412 | return DoChecksOnEncodecxx . . $ LercNS/Lerc2#DoChecksOnEncode(8a03234bfcce5350).(ptrBlob, *ppByte); |
| 413 | } |
| 414 | |
| 415 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 4) |
| 416 | { |
| 417 | if (!WriteMinMaxRangescxx . . $ LercNS/Lerc2#WriteMinMaxRanges(cc83d641fe8bfa9b).(arr, ppByte)) |
| 418 | return false; |
| 419 | |
| 420 | bool minMaxEqual = false; |
| 421 | if (!CheckMinMaxRangescxx . . $ LercNS/Lerc2#CheckMinMaxRanges(dadd4ad61e27fbc).(minMaxEqual)) |
| 422 | return false; |
| 423 | |
| 424 | if (minMaxEqual) |
| 425 | return DoChecksOnEncodecxx . . $ LercNS/Lerc2#DoChecksOnEncode(8a03234bfcce5350).(ptrBlob, *ppByte); |
| 426 | } |
| 427 | |
| 428 | **ppByte = m_writeDataOneSweepcxx . . $ LercNS/Lerc2#m_writeDataOneSweep. ? 1 : 0; // write flag |
| 429 | (*ppByte)++; |
| 430 | |
| 431 | if (!m_writeDataOneSweepcxx . . $ LercNS/Lerc2#m_writeDataOneSweep.) |
| 432 | { |
| 433 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanIntcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanInt(50ce9a9e25b4a850).() || m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanFltcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanFlt(50ce9a9e25b4a850).()) |
| 434 | { |
| 435 | **ppByte = (Bytecxx . . $ LercNS/Byte#)m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode.; // Huffman or tiling encode mode |
| 436 | (*ppByte)++; |
| 437 | |
| 438 | if (m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. != IEM_Tilingcxx . . $ LercNS/Lerc2#IEM_Tiling.) |
| 439 | { |
| 440 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanFltcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanFlt(50ce9a9e25b4a850).()) |
| 441 | { |
| 442 | if (!(m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_DeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaHuffman. || m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_Huffmancxx . . $ LercNS/Lerc2#IEM_Huffman. || m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_DeltaDeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaDeltaHuffman.)) |
| 443 | return false; |
| 444 | |
| 445 | if (!m_lfpccxx . . $ LercNS/Lerc2#m_lfpc..EncodeHuffmanFltcxx . . $ LercNS/LosslessFPCompression#EncodeHuffmanFlt(3a3fc37189ba3738).(ppByte)) |
| 446 | return false; |
| 447 | |
| 448 | return DoChecksOnEncodecxx . . $ LercNS/Lerc2#DoChecksOnEncode(8a03234bfcce5350).(ptrBlob, *ppByte); |
| 449 | } |
| 450 | |
| 451 | if (!m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes..emptycxx . . $ std/vector#empty(3482b152b9333168).()) // Huffman, no tiling |
| 452 | { |
| 453 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanIntcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanInt(50ce9a9e25b4a850).()) |
| 454 | { |
| 455 | if (!(m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_DeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaHuffman. || m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_Huffmancxx . . $ LercNS/Lerc2#IEM_Huffman.)) |
| 456 | return false; |
| 457 | |
| 458 | if (!EncodeHuffmancxx . . $ LercNS/Lerc2#EncodeHuffman(cc83d641fe8bfa9b).(arr, ppByte)) // data bit stuffed |
| 459 | return false; |
| 460 | } |
| 461 | else |
| 462 | return false; |
| 463 | |
| 464 | return DoChecksOnEncodecxx . . $ LercNS/Lerc2#DoChecksOnEncode(8a03234bfcce5350).(ptrBlob, *ppByte); |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | int numBytes = 0; |
| 470 | if (!WriteTilescxx . . $ LercNS/Lerc2#WriteTiles(b7537629c01bf85b).(arr, ppByte, numBytes) || numBytes < 0) |
| 471 | return false; |
| 472 | } |
| 473 | else |
| 474 | { |
| 475 | if (!WriteDataOneSweepcxx . . $ LercNS/Lerc2#WriteDataOneSweep(cc83d641fe8bfa9b).(arr, ppByte)) |
| 476 | return false; |
| 477 | } |
| 478 | |
| 479 | return DoChecksOnEncodecxx . . $ LercNS/Lerc2#DoChecksOnEncode(8a03234bfcce5350).(ptrBlob, *ppByte); |
| 480 | } |
| 481 | |
| 482 | // -------------------------------------------------------------------------- ; |
| 483 | |
| 484 | template bool Lerc2::Encode<signed char>(const signed char* arr, Byte** ppByte); |
| 485 | template bool Lerc2::Encode<Byte>(const Byte* arr, Byte** ppByte); |
| 486 | template bool Lerc2::Encode<short>(const short* arr, Byte** ppByte); |
| 487 | template bool Lerc2::Encode<unsigned short>(const unsigned short* arr, Byte** ppByte); |
| 488 | template bool Lerc2::Encode<int>(const int* arr, Byte** ppByte); |
| 489 | template bool Lerc2::Encode<unsigned int>(const unsigned int* arr, Byte** ppByte); |
| 490 | template bool Lerc2::Encode<float>(const float* arr, Byte** ppByte); |
| 491 | template bool Lerc2::Encode<double>(const double* arr, Byte** ppByte); |
| 492 | |
| 493 | // -------------------------------------------------------------------------- ; |
| 494 | |
| 495 | bool Lerc2cxx . . $ LercNS/Lerc2#::GetHeaderInfocxx . . $ LercNS/Lerc2#GetHeaderInfo(5bafa162245ba3da).(const Bytecxx . . $ LercNS/Byte#* pByte, size_t nBytesRemaining, struct HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd, bool& bHasMask) |
| 496 | { |
| 497 | if (!pByte || !IsLittleEndianSystemcxx . . $ LercNS/Lerc2#IsLittleEndianSystem(c9857a73d68e59ba).()) |
| 498 | return false; |
| 499 | |
| 500 | if (!ReadHeadercxx . . $ LercNS/Lerc2#ReadHeader(33258b37336fa9a0).(&pByte, nBytesRemaining, hd)) |
| 501 | return false; |
| 502 | |
| 503 | int numBytesMask(0); |
| 504 | if (nBytesRemaining < sizeof(int) || !memcpy(&numBytesMask, pByte, sizeof(int)) || numBytesMask < 0) |
| 505 | return false; |
| 506 | |
| 507 | bHasMask = numBytesMask > 0; |
| 508 | |
| 509 | return true; |
| 510 | } |
| 511 | |
| 512 | // -------------------------------------------------------------------------- ; |
| 513 | |
| 514 | bool Lerc2cxx . . $ LercNS/Lerc2#::GetRangescxx . . $ LercNS/Lerc2#GetRanges(bfe330d8d1b8c5bf).(const Bytecxx . . $ LercNS/Byte#* pByte, size_t nBytesRemaining, double* pMins, double* pMaxs) |
| 515 | { |
| 516 | if (!pByte || !IsLittleEndianSystemcxx . . $ LercNS/Lerc2#IsLittleEndianSystem(c9857a73d68e59ba).() || m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. < 4 || !pMins || !pMaxs) |
| 517 | return false; |
| 518 | |
| 519 | if (!ReadHeadercxx . . $ LercNS/Lerc2#ReadHeader(33258b37336fa9a0).(&pByte, nBytesRemaining, m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.)) |
| 520 | return false; |
| 521 | |
| 522 | if (!ReadMaskcxx . . $ LercNS/Lerc2#ReadMask(79d815e0e9c169c7).(&pByte, nBytesRemaining)) |
| 523 | return false; |
| 524 | |
| 525 | const int nDepth = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 526 | |
| 527 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. == 0) // image is empty |
| 528 | { |
| 529 | memset(pMins, 0, nDepth * sizeof(double)); // fill with 0 |
| 530 | memset(pMaxs, 0, nDepth * sizeof(double)); |
| 531 | |
| 532 | return true; |
| 533 | } |
| 534 | |
| 535 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin. == m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax.) // image is const |
| 536 | { |
| 537 | double val = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin.; |
| 538 | |
| 539 | for (int i = 0; i < nDepth; i++) // fill with const |
| 540 | pMins[i] = pMaxs[i] = val; |
| 541 | |
| 542 | return true; |
| 543 | } |
| 544 | |
| 545 | bool rv = false; |
| 546 | void* ptr = nullptr; |
| 547 | |
| 548 | switch (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt.) |
| 549 | { |
| 550 | case DT_Charcxx . . $ LercNS/Lerc2#DT_Char.: rv = ReadMinMaxRangescxx . . $ LercNS/Lerc2#ReadMinMaxRanges(823b49aaa8f6c8db).(&pByte, nBytesRemaining, (signed char*) ptr); break; |
| 551 | case DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte.: rv = ReadMinMaxRangescxx . . $ LercNS/Lerc2#ReadMinMaxRanges(823b49aaa8f6c8db).(&pByte, nBytesRemaining, (Bytecxx . . $ LercNS/Byte#*) ptr); break; |
| 552 | case DT_Shortcxx . . $ LercNS/Lerc2#DT_Short.: rv = ReadMinMaxRangescxx . . $ LercNS/Lerc2#ReadMinMaxRanges(823b49aaa8f6c8db).(&pByte, nBytesRemaining, (short*) ptr); break; |
| 553 | case DT_UShortcxx . . $ LercNS/Lerc2#DT_UShort.: rv = ReadMinMaxRangescxx . . $ LercNS/Lerc2#ReadMinMaxRanges(823b49aaa8f6c8db).(&pByte, nBytesRemaining, (unsigned short*)ptr); break; |
| 554 | case DT_Intcxx . . $ LercNS/Lerc2#DT_Int.: rv = ReadMinMaxRangescxx . . $ LercNS/Lerc2#ReadMinMaxRanges(823b49aaa8f6c8db).(&pByte, nBytesRemaining, (int*) ptr); break; |
| 555 | case DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.: rv = ReadMinMaxRangescxx . . $ LercNS/Lerc2#ReadMinMaxRanges(823b49aaa8f6c8db).(&pByte, nBytesRemaining, (unsigned int*) ptr); break; |
| 556 | case DT_Floatcxx . . $ LercNS/Lerc2#DT_Float. : rv = ReadMinMaxRangescxx . . $ LercNS/Lerc2#ReadMinMaxRanges(823b49aaa8f6c8db).(&pByte, nBytesRemaining, (float*) ptr); break; |
| 557 | case DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.: rv = ReadMinMaxRangescxx . . $ LercNS/Lerc2#ReadMinMaxRanges(823b49aaa8f6c8db).(&pByte, nBytesRemaining, (double*) ptr); break; |
| 558 | |
| 559 | default: |
| 560 | return false; |
| 561 | } |
| 562 | |
| 563 | if (!rv) |
| 564 | return false; |
| 565 | |
| 566 | for (int i = 0; i < nDepth; i++) |
| 567 | { |
| 568 | pMins[i] = m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]; |
| 569 | pMaxs[i] = m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]; |
| 570 | } |
| 571 | |
| 572 | return true; |
| 573 | } |
| 574 | |
| 575 | // -------------------------------------------------------------------------- ; |
| 576 | |
| 577 | template<class T> |
| 578 | bool Lerc2cxx . . $ LercNS/Lerc2#::Decodecxx . . $ LercNS/Lerc2#Decode(1e98a814b12037d0).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining, T* arr, Bytecxx . . $ LercNS/Byte#* pMaskBits) |
| 579 | { |
| 580 | if (!arr || !ppByte || !IsLittleEndianSystemcxx . . $ LercNS/Lerc2#IsLittleEndianSystem(c9857a73d68e59ba).()) |
| 581 | return false; |
| 582 | |
| 583 | const Bytecxx . . $ LercNS/Byte#* ptrBlob = *ppByte; // keep a ptr to the start of the blob |
| 584 | size_t nBytesRemaining00 = nBytesRemaining; |
| 585 | |
| 586 | if (!ReadHeadercxx . . $ LercNS/Lerc2#ReadHeader(33258b37336fa9a0).(ppByte, nBytesRemaining, m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.)) |
| 587 | return false; |
| 588 | |
| 589 | if (nBytesRemaining00 < (size_t)m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize.) |
| 590 | return false; |
| 591 | |
| 592 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 3) |
| 593 | { |
| 594 | int nBytes = (int)(FileKeycxx . . $ LercNS/Lerc2#FileKey(efd28698952f529a).().lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).() + sizeof(int) + sizeof(unsigned int)); // start right after the checksum entry |
| 595 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize. < nBytes) |
| 596 | return false; |
| 597 | unsigned int checksum = ComputeChecksumFletcher32cxx . . $ LercNS/Lerc2#ComputeChecksumFletcher32(f38ae389a4b85ca).(ptrBlob + nBytes, m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize. - nBytes); |
| 598 | |
| 599 | if (checksum != m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..checksumcxx . . $ LercNS/Lerc2#HeaderInfo#checksum.) |
| 600 | return false; |
| 601 | } |
| 602 | |
| 603 | if (!ReadMaskcxx . . $ LercNS/Lerc2#ReadMask(79d815e0e9c169c7).(ppByte, nBytesRemaining)) |
| 604 | return false; |
| 605 | |
| 606 | if (pMaskBits) // return proper mask bits even if they were not stored |
| 607 | memcpy(pMaskBits, m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..Bitscxx . . $ LercNS/BitMask#Bits(37d8967d10cb1e7b).(), m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..Sizecxx . . $ LercNS/BitMask#Size(fe4d2d262d4164a8).()); |
| 608 | |
| 609 | memset(arr, 0, (size_t)m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. * m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. * m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth. * sizeof(T)); |
| 610 | |
| 611 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. == 0) |
| 612 | return true; |
| 613 | |
| 614 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin. == m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax.) // image is const |
| 615 | { |
| 616 | if (!FillConstImagecxx . . $ LercNS/Lerc2#FillConstImage(688a48c7bc3386d6).(arr)) |
| 617 | return false; |
| 618 | |
| 619 | return true; |
| 620 | } |
| 621 | |
| 622 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 4) |
| 623 | { |
| 624 | if (!ReadMinMaxRangescxx . . $ LercNS/Lerc2#ReadMinMaxRanges(823b49aaa8f6c8db).(ppByte, nBytesRemaining, arr)) |
| 625 | return false; |
| 626 | |
| 627 | bool minMaxEqual = false; |
| 628 | if (!CheckMinMaxRangescxx . . $ LercNS/Lerc2#CheckMinMaxRanges(dadd4ad61e27fbc).(minMaxEqual)) |
| 629 | return false; |
| 630 | |
| 631 | if (minMaxEqual) // if all bands are const, fill outgoing and done |
| 632 | { |
| 633 | if (!FillConstImagecxx . . $ LercNS/Lerc2#FillConstImage(688a48c7bc3386d6).(arr)) |
| 634 | return false; |
| 635 | |
| 636 | return true; // done |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | if (nBytesRemaining < 1) |
| 641 | return false; |
| 642 | |
| 643 | Bytecxx . . $ LercNS/Byte# readDataOneSweep = **ppByte; // read flag |
| 644 | (*ppByte)++; |
| 645 | nBytesRemaining--; |
| 646 | |
| 647 | if (!readDataOneSweep) |
| 648 | { |
| 649 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanIntcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanInt(50ce9a9e25b4a850).() || m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanFltcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanFlt(50ce9a9e25b4a850).()) |
| 650 | { |
| 651 | if (nBytesRemaining < 1) |
| 652 | return false; |
| 653 | |
| 654 | Bytecxx . . $ LercNS/Byte# flag = **ppByte; // read flag Huffman / Lerc2 |
| 655 | (*ppByte)++; |
| 656 | nBytesRemaining--; |
| 657 | |
| 658 | if (flag > 3 |
| 659 | || (flag > 2 && m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. < 6) |
| 660 | || (flag > 1 && m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. < 4)) |
| 661 | return false; |
| 662 | |
| 663 | m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. = (ImageEncodeModecxx . . $ LercNS/Lerc2#ImageEncodeMode#)flag; |
| 664 | |
| 665 | if (m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. != IEM_Tilingcxx . . $ LercNS/Lerc2#IEM_Tiling.) |
| 666 | { |
| 667 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanIntcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanInt(50ce9a9e25b4a850).()) |
| 668 | { |
| 669 | if (m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_DeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaHuffman. || (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 4 && m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_Huffmancxx . . $ LercNS/Lerc2#IEM_Huffman.)) |
| 670 | return DecodeHuffmancxx . . $ LercNS/Lerc2#DecodeHuffman(d8761aea236c93e).(ppByte, nBytesRemaining, arr); // done. |
| 671 | else |
| 672 | return false; |
| 673 | } |
| 674 | else if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..TryHuffmanFltcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanFlt(50ce9a9e25b4a850).() && m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_DeltaDeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaDeltaHuffman.) |
| 675 | { |
| 676 | return LosslessFPCompressioncxx . . $ LercNS/LosslessFPCompression#::DecodeHuffmanFltcxx . . $ LercNS/LosslessFPCompression#DecodeHuffmanFlt(cd74ab201788fe3a).(ppByte, nBytesRemaining, arr, |
| 677 | (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.), m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols., m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows., m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.); |
| 678 | } |
| 679 | else |
| 680 | return false; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | if (!ReadTilescxx . . $ LercNS/Lerc2#ReadTiles(d8761aea236c93e).(ppByte, nBytesRemaining, arr)) |
| 685 | return false; |
| 686 | } |
| 687 | else |
| 688 | { |
| 689 | if (!ReadDataOneSweepcxx . . $ LercNS/Lerc2#ReadDataOneSweep(d8761aea236c93e).(ppByte, nBytesRemaining, arr)) |
| 690 | return false; |
| 691 | } |
| 692 | |
| 693 | return true; |
| 694 | } |
| 695 | |
| 696 | // -------------------------------------------------------------------------- ; |
| 697 | |
| 698 | template bool Lerc2::Decode<signed char>(const Byte** ppByte, size_t& nBytesRemaining, signed char* arr, Byte* pMaskBits); |
| 699 | template bool Lerc2::Decode<Byte>(const Byte** ppByte, size_t& nBytesRemaining, Byte* arr, Byte* pMaskBits); |
| 700 | template bool Lerc2::Decode<short>(const Byte** ppByte, size_t& nBytesRemaining, short* arr, Byte* pMaskBits); |
| 701 | template bool Lerc2::Decode<unsigned short>(const Byte** ppByte, size_t& nBytesRemaining, unsigned short* arr, Byte* pMaskBits); |
| 702 | template bool Lerc2::Decode<int>(const Byte** ppByte, size_t& nBytesRemaining, int* arr, Byte* pMaskBits); |
| 703 | template bool Lerc2::Decode<unsigned int>(const Byte** ppByte, size_t& nBytesRemaining, unsigned int* arr, Byte* pMaskBits); |
| 704 | template bool Lerc2::Decode<float>(const Byte** ppByte, size_t& nBytesRemaining, float* arr, Byte* pMaskBits); |
| 705 | template bool Lerc2::Decode<double>(const Byte** ppByte, size_t& nBytesRemaining, double* arr, Byte* pMaskBits); |
| 706 | |
| 707 | // -------------------------------------------------------------------------- ; |
| 708 | // -------------------------------------------------------------------------- ; |
| 709 | |
| 710 | unsigned int Lerc2cxx . . $ LercNS/Lerc2#::ComputeNumBytesHeaderToWritecxx . . $ LercNS/Lerc2#ComputeNumBytesHeaderToWrite(c71a4331653d1346).(const struct HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd) |
| 711 | { |
| 712 | unsigned int numBytes = (unsigned int)FileKeycxx . . $ LercNS/Lerc2#FileKey(efd28698952f529a).().lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).(); |
| 713 | numBytes += 1 * sizeof(int); |
| 714 | numBytes += (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 3 ? 1 : 0) * sizeof(unsigned int); |
| 715 | numBytes += (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 4 ? 7 : 6) * sizeof(int); |
| 716 | numBytes += (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6 ? 1 : 0) * sizeof(int); |
| 717 | numBytes += (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6 ? 4 : 0) * sizeof(Bytecxx . . $ LercNS/Byte#); |
| 718 | numBytes += (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6 ? 5 : 3) * sizeof(double); |
| 719 | return numBytes; |
| 720 | } |
| 721 | |
| 722 | // -------------------------------------------------------------------------- ; |
| 723 | |
| 724 | bool Lerc2cxx . . $ LercNS/Lerc2#::WriteHeadercxx . . $ LercNS/Lerc2#WriteHeader(a9c1fa508da30057).(Bytecxx . . $ LercNS/Byte#** ppByte, const struct HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd) |
| 725 | { |
| 726 | if (!ppByte) |
| 727 | return false; |
| 728 | |
| 729 | Bytecxx . . $ LercNS/Byte#* ptr = *ppByte; |
| 730 | |
| 731 | stringcxx . . $ std/string# fileKey = FileKeycxx . . $ LercNS/Lerc2#FileKey(efd28698952f529a).(); |
| 732 | size_t len = fileKey.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).(); |
| 733 | memcpy(ptr, fileKey.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), len); |
| 734 | ptr += len; |
| 735 | |
| 736 | memcpy(ptr, &hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version., sizeof(int)); |
| 737 | ptr += sizeof(int); |
| 738 | |
| 739 | if (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 3) |
| 740 | { |
| 741 | unsigned int checksum = 0; |
| 742 | memcpy(ptr, &checksum, sizeof(unsigned int)); // place holder to be filled by the real check sum later |
| 743 | ptr += sizeof(unsigned int); |
| 744 | } |
| 745 | |
| 746 | vectorcxx . . $ std/vector#<int> intVeccxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 747 | intVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.); |
| 748 | intVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.); |
| 749 | if (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 4) intVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.); |
| 750 | intVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel.); |
| 751 | intVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.microBlockSizecxx . . $ LercNS/Lerc2#HeaderInfo#microBlockSize.); |
| 752 | intVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize.); |
| 753 | intVec.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).((int)hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt.); |
| 754 | if (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) intVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.nBlobsMorecxx . . $ LercNS/Lerc2#HeaderInfo#nBlobsMore.); |
| 755 | |
| 756 | len = intVec.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() * sizeof(int); |
| 757 | memcpy(ptr, &intVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], len); |
| 758 | ptr += len; |
| 759 | |
| 760 | if (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) |
| 761 | { |
| 762 | vectorcxx . . $ std/vector#<Bytecxx . . $ LercNS/Byte#> byteVeccxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 763 | byteVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.bPassNoDataValuescxx . . $ LercNS/Lerc2#HeaderInfo#bPassNoDataValues.); |
| 764 | byteVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.bIsIntcxx . . $ LercNS/Lerc2#HeaderInfo#bIsInt.); |
| 765 | byteVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.bReserved3cxx . . $ LercNS/Lerc2#HeaderInfo#bReserved3.); |
| 766 | byteVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.bReserved4cxx . . $ LercNS/Lerc2#HeaderInfo#bReserved4.); |
| 767 | |
| 768 | len = byteVec.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 769 | memcpy(ptr, &byteVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], len); |
| 770 | ptr += len; |
| 771 | } |
| 772 | |
| 773 | vectorcxx . . $ std/vector#<double> dblVeccxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 774 | dblVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError.); |
| 775 | dblVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin.); |
| 776 | dblVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax.); |
| 777 | if (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) dblVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.noDataValcxx . . $ LercNS/Lerc2#HeaderInfo#noDataVal.); |
| 778 | if (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) dblVec.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(hd.noDataValOrigcxx . . $ LercNS/Lerc2#HeaderInfo#noDataValOrig.); |
| 779 | |
| 780 | len = dblVec.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() * sizeof(double); |
| 781 | memcpy(ptr, &dblVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], len); |
| 782 | ptr += len; |
| 783 | |
| 784 | *ppByte = ptr; |
| 785 | return true; |
| 786 | } |
| 787 | |
| 788 | // -------------------------------------------------------------------------- ; |
| 789 | |
| 790 | bool Lerc2cxx . . $ LercNS/Lerc2#::ReadHeadercxx . . $ LercNS/Lerc2#ReadHeader(33258b37336fa9a0).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemainingInOut, struct HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd) |
| 791 | { |
| 792 | if (!ppByte || !*ppByte) |
| 793 | return false; |
| 794 | |
| 795 | const Bytecxx . . $ LercNS/Byte#* ptr = *ppByte; |
| 796 | size_t nBytesRemaining = nBytesRemainingInOut; |
| 797 | |
| 798 | stringcxx . . $ std/string# fileKey = FileKeycxx . . $ LercNS/Lerc2#FileKey(efd28698952f529a).(); |
| 799 | size_t keyLen = fileKey.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).(); |
| 800 | |
| 801 | hd.RawInitcxx . . $ LercNS/Lerc2#HeaderInfo#RawInit(49f6e7a06ebc5aa8).(); |
| 802 | |
| 803 | if (nBytesRemaining < keyLen || memcmp(ptr, fileKey.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), keyLen)) |
| 804 | return false; |
| 805 | |
| 806 | ptr += keyLen; |
| 807 | nBytesRemaining -= keyLen; |
| 808 | |
| 809 | if (nBytesRemaining < sizeof(int) || !memcpy(&(hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version.), ptr, sizeof(int))) |
| 810 | return false; |
| 811 | |
| 812 | ptr += sizeof(int); |
| 813 | nBytesRemaining -= sizeof(int); |
| 814 | |
| 815 | if (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. < 0 || hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. > CurrentVersioncxx . . $ LercNS/Lerc2#CurrentVersion(b126dc7c1de90089).()) // this reader is outdated |
| 816 | return false; |
| 817 | |
| 818 | if (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 3) |
| 819 | { |
| 820 | if (nBytesRemaining < sizeof(unsigned int) || !memcpy(&(hd.checksumcxx . . $ LercNS/Lerc2#HeaderInfo#checksum.), ptr, sizeof(unsigned int))) |
| 821 | return false; |
| 822 | |
| 823 | ptr += sizeof(unsigned int); |
| 824 | nBytesRemaining -= sizeof(unsigned int); |
| 825 | } |
| 826 | |
| 827 | int nInts = 6; |
| 828 | nInts += (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 4) ? 1 : 0; |
| 829 | nInts += (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) ? 1 : 0; |
| 830 | |
| 831 | int nBytes = 0; |
| 832 | nBytes += (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) ? 4 : 0; |
| 833 | |
| 834 | int nDbls = 3; |
| 835 | nDbls += (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) ? 2 : 0; |
| 836 | |
| 837 | vectorcxx . . $ std/vector#<int> intVeccxx . . $ std/vector#vector(229e4d6bd205de31).(nInts, 0); |
| 838 | vectorcxx . . $ std/vector#<Bytecxx . . $ LercNS/Byte#> byteVeccxx . . $ std/vector#vector(229e4d6bd205de31).(nBytes, 0); |
| 839 | vectorcxx . . $ std/vector#<double> dblVeccxx . . $ std/vector#vector(229e4d6bd205de31).(nDbls, 0); |
| 840 | |
| 841 | size_t len = sizeof(int) * intVec.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 842 | |
| 843 | if (nBytesRemaining < len || !memcpy(&intVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], ptr, len)) |
| 844 | return false; |
| 845 | |
| 846 | ptr += len; |
| 847 | nBytesRemaining -= len; |
| 848 | |
| 849 | if (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) |
| 850 | { |
| 851 | len = byteVec.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 852 | |
| 853 | if (nBytesRemaining < len || !memcpy(&byteVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], ptr, len)) |
| 854 | return false; |
| 855 | |
| 856 | ptr += len; |
| 857 | nBytesRemaining -= len; |
| 858 | } |
| 859 | |
| 860 | len = sizeof(double) * dblVec.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 861 | |
| 862 | if (nBytesRemaining < len || !memcpy(&dblVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], ptr, len)) |
| 863 | return false; |
| 864 | |
| 865 | ptr += len; |
| 866 | nBytesRemaining -= len; |
| 867 | |
| 868 | int i = 0; |
| 869 | hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. = intVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++]; |
| 870 | hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. = intVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++]; |
| 871 | hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth. = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 4) ? intVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++] : 1; |
| 872 | hd.numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. = intVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++]; |
| 873 | hd.microBlockSizecxx . . $ LercNS/Lerc2#HeaderInfo#microBlockSize. = intVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++]; |
| 874 | hd.blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize. = intVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++]; |
| 875 | const int dt = intVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++]; |
| 876 | |
| 877 | if (hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. <= 0 || hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. <= 0 || hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth. <= 0 || hd.numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. < 0 |
| 878 | || hd.microBlockSizecxx . . $ LercNS/Lerc2#HeaderInfo#microBlockSize. <= 0 || hd.blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize. <= 0 || dt < DT_Charcxx . . $ LercNS/Lerc2#DT_Char. || dt > DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.) |
| 879 | return false; |
| 880 | |
| 881 | hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. = static_cast<DataTypecxx . . $ LercNS/Lerc2#DataType#>(dt); |
| 882 | hd.nBlobsMorecxx . . $ LercNS/Lerc2#HeaderInfo#nBlobsMore. = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) ? intVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++] : 0; |
| 883 | |
| 884 | i = 0; |
| 885 | hd.bPassNoDataValuescxx . . $ LercNS/Lerc2#HeaderInfo#bPassNoDataValues. = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) ? byteVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++] : 0; |
| 886 | hd.bIsIntcxx . . $ LercNS/Lerc2#HeaderInfo#bIsInt. = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) ? byteVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++] : 0; |
| 887 | hd.bReserved3cxx . . $ LercNS/Lerc2#HeaderInfo#bReserved3. = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) ? byteVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++] : 0; |
| 888 | hd.bReserved4cxx . . $ LercNS/Lerc2#HeaderInfo#bReserved4. = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) ? byteVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++] : 0; |
| 889 | |
| 890 | i = 0; |
| 891 | hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. = dblVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++]; |
| 892 | hd.zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin. = dblVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++]; |
| 893 | hd.zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax. = dblVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++]; |
| 894 | hd.noDataValcxx . . $ LercNS/Lerc2#HeaderInfo#noDataVal. = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) ? dblVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++] : 0; |
| 895 | hd.noDataValOrigcxx . . $ LercNS/Lerc2#HeaderInfo#noDataValOrig. = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) ? dblVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i++] : 0; |
| 896 | |
| 897 | // here we guard against bogus input parameters and dimensions: |
| 898 | // we limit the size of input data per band to 2 GB, so any product [height * width * depth * sizeof(data element)] <= INT_MAX; |
| 899 | // the size of a compressed binary Lerc blob per band is <= 2 GB; |
| 900 | // the total size of a compressed binary Lerc blob over all bands is <= 4 GB (current Lerc API limitation); |
| 901 | // (see the corresponding size and dimension checks in Lerc::CheckDimensions(...)); |
| 902 | |
| 903 | const uint64_tcxx . . $ uint64_t# numPixel = (uint64_tcxx . . $ uint64_t#)hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. * hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; |
| 904 | const uint64_tcxx . . $ uint64_t# maxint32 = (uint64_tcxx . . $ uint64_t#)INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!; |
| 905 | const uint64_tcxx . . $ uint64_t# nbpp = GetDataTypeSizecxx . . $ LercNS/Lerc2#GetDataTypeSize(3707fc1f19bbe2a2).(hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt.); |
| 906 | |
| 907 | if (numPixel > maxint32 || (uint64_tcxx . . $ uint64_t#)hd.numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. > numPixel) |
| 908 | return false; |
| 909 | |
| 910 | if (hd.microBlockSizecxx . . $ LercNS/Lerc2#HeaderInfo#microBlockSize. > 32 || nbpp * hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth. > maxint32 || nbpp * hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth. * numPixel > maxint32) |
| 911 | return false; |
| 912 | |
| 913 | *ppByte = ptr; |
| 914 | nBytesRemainingInOut = nBytesRemaining; |
| 915 | |
| 916 | return true; |
| 917 | } |
| 918 | |
| 919 | // -------------------------------------------------------------------------- ; |
| 920 | |
| 921 | bool Lerc2cxx . . $ LercNS/Lerc2#::WriteMaskcxx . . $ LercNS/Lerc2#WriteMask(2c1b2a8bb0754e17).(Bytecxx . . $ LercNS/Byte#** ppByte) const |
| 922 | { |
| 923 | if (!ppByte) |
| 924 | return false; |
| 925 | |
| 926 | int numValid = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel.; |
| 927 | int numTotal = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. * m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; |
| 928 | |
| 929 | bool needMask = numValid > 0 && numValid < numTotal; |
| 930 | |
| 931 | Bytecxx . . $ LercNS/Byte#* ptr = *ppByte; |
| 932 | |
| 933 | if (needMask && m_encodeMaskcxx . . $ LercNS/Lerc2#m_encodeMask.) |
| 934 | { |
| 935 | Bytecxx . . $ LercNS/Byte#* pArrRLE; |
| 936 | size_t numBytesRLE; |
| 937 | RLEcxx . . $ LercNS/RLE# rlecxx . . $ LercNS/RLE#RLE(49f6e7a06ebc5aa8).; |
| 938 | if (!rle.compresscxx . . $ LercNS/RLE#compress(34df028bea51163d).((const Bytecxx . . $ LercNS/Byte#*)m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..Bitscxx . . $ LercNS/BitMask#Bits(7eb257f306f79f97).(), m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..Sizecxx . . $ LercNS/BitMask#Size(fe4d2d262d4164a8).(), &pArrRLE, numBytesRLE, false)) |
| 939 | return false; |
| 940 | |
| 941 | int numBytesMask = (int)numBytesRLE; |
| 942 | memcpy(ptr, &numBytesMask, sizeof(int)); // num bytes for compressed mask |
| 943 | ptr += sizeof(int); |
| 944 | memcpy(ptr, pArrRLE, numBytesRLE); |
| 945 | ptr += numBytesRLE; |
| 946 | |
| 947 | delete[] pArrRLE; |
| 948 | } |
| 949 | else |
| 950 | { |
| 951 | memset(ptr, 0, sizeof(int)); // indicates no mask stored |
| 952 | ptr += sizeof(int); |
| 953 | } |
| 954 | |
| 955 | *ppByte = ptr; |
| 956 | return true; |
| 957 | } |
| 958 | |
| 959 | // -------------------------------------------------------------------------- ; |
| 960 | |
| 961 | bool Lerc2cxx . . $ LercNS/Lerc2#::ReadMaskcxx . . $ LercNS/Lerc2#ReadMask(79d815e0e9c169c7).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemainingInOut) |
| 962 | { |
| 963 | if (!ppByte) |
| 964 | return false; |
| 965 | |
| 966 | int numValid = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel.; |
| 967 | int w = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; |
| 968 | int h = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; |
| 969 | |
| 970 | const Bytecxx . . $ LercNS/Byte#* ptr = *ppByte; |
| 971 | size_t nBytesRemaining = nBytesRemainingInOut; |
| 972 | |
| 973 | int numBytesMask; |
| 974 | if (nBytesRemaining < sizeof(int) || !memcpy(&numBytesMask, ptr, sizeof(int)) || numBytesMask < 0) |
| 975 | return false; |
| 976 | |
| 977 | ptr += sizeof(int); |
| 978 | nBytesRemaining -= sizeof(int); |
| 979 | |
| 980 | if ((numValid == 0 || numValid == w * h) && (numBytesMask != 0)) |
| 981 | return false; |
| 982 | |
| 983 | if (!m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..SetSizecxx . . $ LercNS/BitMask#SetSize(cf9ef193275fa6d8).(w, h)) |
| 984 | return false; |
| 985 | |
| 986 | if (numValid == 0) |
| 987 | m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..SetAllInvalidcxx . . $ LercNS/BitMask#SetAllInvalid(83f5f38750778ac8).(); |
| 988 | else if (numValid == w * h) |
| 989 | m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..SetAllValidcxx . . $ LercNS/BitMask#SetAllValid(83f5f38750778ac8).(); |
| 990 | else if (numBytesMask > 0) // read it in |
| 991 | { |
| 992 | if (nBytesRemaining < static_cast<size_t>(numBytesMask)) |
| 993 | return false; |
| 994 | |
| 995 | RLEcxx . . $ LercNS/RLE# rlecxx . . $ LercNS/RLE#RLE(49f6e7a06ebc5aa8).; |
| 996 | if (!rle.decompresscxx . . $ LercNS/RLE#decompress(b7ce43e8339adf29).(ptr, nBytesRemaining, m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..Bitscxx . . $ LercNS/BitMask#Bits(37d8967d10cb1e7b).(), m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..Sizecxx . . $ LercNS/BitMask#Size(fe4d2d262d4164a8).())) |
| 997 | return false; |
| 998 | |
| 999 | ptr += numBytesMask; |
| 1000 | nBytesRemaining -= numBytesMask; |
| 1001 | } |
| 1002 | // else use previous mask |
| 1003 | |
| 1004 | *ppByte = ptr; |
| 1005 | nBytesRemainingInOut = nBytesRemaining; |
| 1006 | |
| 1007 | return true; |
| 1008 | } |
| 1009 | |
| 1010 | // -------------------------------------------------------------------------- ; |
| 1011 | |
| 1012 | bool Lerc2cxx . . $ LercNS/Lerc2#::DoChecksOnEncodecxx . . $ LercNS/Lerc2#DoChecksOnEncode(8a03234bfcce5350).(Bytecxx . . $ LercNS/Byte#* pBlobBegin, Bytecxx . . $ LercNS/Byte#* pBlobEnd) const |
| 1013 | { |
| 1014 | if ((size_t)(pBlobEnd - pBlobBegin) != (size_t)m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize.) |
| 1015 | return false; |
| 1016 | |
| 1017 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 3) |
| 1018 | { |
| 1019 | int blobSize = (int)(pBlobEnd - pBlobBegin); |
| 1020 | int nBytes = (int)(FileKeycxx . . $ LercNS/Lerc2#FileKey(efd28698952f529a).().lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).() + sizeof(int) + sizeof(unsigned int)); // start right after the checksum entry |
| 1021 | if (blobSize < nBytes) |
| 1022 | return false; |
| 1023 | unsigned int checksum = ComputeChecksumFletcher32cxx . . $ LercNS/Lerc2#ComputeChecksumFletcher32(f38ae389a4b85ca).(pBlobBegin + nBytes, blobSize - nBytes); |
| 1024 | |
| 1025 | nBytes -= sizeof(unsigned int); |
| 1026 | memcpy(pBlobBegin + nBytes, &checksum, sizeof(unsigned int)); |
| 1027 | } |
| 1028 | |
| 1029 | return true; |
| 1030 | } |
| 1031 | |
| 1032 | // -------------------------------------------------------------------------- ; |
| 1033 | |
| 1034 | // from https://en.wikipedia.org/wiki/Fletcher's_checksum |
| 1035 | // modified from ushorts to bytes (by Lucian Plesea) |
| 1036 | |
| 1037 | unsigned int Lerc2cxx . . $ LercNS/Lerc2#::ComputeChecksumFletcher32cxx . . $ LercNS/Lerc2#ComputeChecksumFletcher32(f38ae389a4b85ca).(const Bytecxx . . $ LercNS/Byte#* pByte, int len) |
| 1038 | { |
| 1039 | unsigned int sum1 = 0xffff, sum2 = 0xffff; |
| 1040 | unsigned int words = len / 2; |
| 1041 | |
| 1042 | while (words) |
| 1043 | { |
| 1044 | unsigned int tlen = (words >= 359) ? 359 : words; |
| 1045 | words -= tlen; |
| 1046 | do { |
| 1047 | sum1 += (*pByte++ << 8); |
| 1048 | sum2 += sum1 += *pByte++; |
| 1049 | } while (--tlen); |
| 1050 | |
| 1051 | sum1 = (sum1 & 0xffff) + (sum1 >> 16); |
| 1052 | sum2 = (sum2 & 0xffff) + (sum2 >> 16); |
| 1053 | } |
| 1054 | |
| 1055 | // add the straggler byte if it exists |
| 1056 | if (len & 1) |
| 1057 | sum2 += sum1 += (*pByte << 8); |
| 1058 | |
| 1059 | // second reduction step to reduce sums to 16 bits |
| 1060 | sum1 = (sum1 & 0xffff) + (sum1 >> 16); |
| 1061 | sum2 = (sum2 & 0xffff) + (sum2 >> 16); |
| 1062 | |
| 1063 | return sum2 << 16 | sum1; |
| 1064 | } |
| 1065 | |
| 1066 | // -------------------------------------------------------------------------- ; |
| 1067 | |
| 1068 | // for the theory and math, see |
| 1069 | // https://pdfs.semanticscholar.org/d064/2e2ad1a4c3b445b0d795770f604a5d9e269c.pdf |
| 1070 | |
| 1071 | template<class T> |
| 1072 | bool Lerc2cxx . . $ LercNS/Lerc2#::TryBitPlaneCompressioncxx . . $ LercNS/Lerc2#TryBitPlaneCompression(fcbe6167061550ea).(const T* data, double eps, double& newMaxZError) const |
| 1073 | { |
| 1074 | newMaxZError = 0; // lossless is the obvious fallback |
| 1075 | |
| 1076 | if (!data || eps <= 0) |
| 1077 | return false; |
| 1078 | |
| 1079 | const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.; |
| 1080 | const int nDepth = hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 1081 | const int maxShift = 8 * GetDataTypeSizecxx . . $ LercNS/Lerc2#GetDataTypeSize(3707fc1f19bbe2a2).(hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt.); |
| 1082 | const int minCnt = 5000; |
| 1083 | |
| 1084 | if (hd.numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. < minCnt) // not enough data for good stats |
| 1085 | return false; |
| 1086 | |
| 1087 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<int> cntDiffVeccxx . . $ std/vector#vector(229e4d6bd205de31).((size_t)nDepth * maxShift, 0); |
| 1088 | int cnt = 0; |
| 1089 | |
| 1090 | if (nDepth == 1 && hd.numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. == hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. * hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.) // special but common case |
| 1091 | { |
| 1092 | if (hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte. || hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_UShortcxx . . $ LercNS/Lerc2#DT_UShort. || hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.) // unsigned int |
| 1093 | { |
| 1094 | for (int i = 0; i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. - 1; i++) |
| 1095 | for (int k = i * hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols., j = 0; j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. - 1; j++, k++) |
| 1096 | { |
| 1097 | unsigned int c = ((unsigned int)data[k]) ^ ((unsigned int)data[k + 1]); |
| 1098 | AddUIntToCountscxx . . $ LercNS/Lerc2#AddUIntToCounts(a4fdc77d1ddcd2d8).(&cntDiffVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], c, maxShift); |
| 1099 | cnt++; |
| 1100 | c = ((unsigned int)data[k]) ^ ((unsigned int)data[k + hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.]); |
| 1101 | AddUIntToCountscxx . . $ LercNS/Lerc2#AddUIntToCounts(a4fdc77d1ddcd2d8).(&cntDiffVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], c, maxShift); |
| 1102 | cnt++; |
| 1103 | } |
| 1104 | } |
| 1105 | else if (hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Charcxx . . $ LercNS/Lerc2#DT_Char. || hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Shortcxx . . $ LercNS/Lerc2#DT_Short. || hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Intcxx . . $ LercNS/Lerc2#DT_Int.) // signed int |
| 1106 | { |
| 1107 | for (int i = 0; i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. - 1; i++) |
| 1108 | for (int k = i * hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols., j = 0; j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. - 1; j++, k++) |
| 1109 | { |
| 1110 | int c = ((int)data[k]) ^ ((int)data[k + 1]); |
| 1111 | AddIntToCountscxx . . $ LercNS/Lerc2#AddIntToCounts(5f3888e91f92d472).(&cntDiffVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], c, maxShift); |
| 1112 | cnt++; |
| 1113 | c = ((int)data[k]) ^ ((int)data[k + hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.]); |
| 1114 | AddIntToCountscxx . . $ LercNS/Lerc2#AddIntToCounts(5f3888e91f92d472).(&cntDiffVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], c, maxShift); |
| 1115 | cnt++; |
| 1116 | } |
| 1117 | } |
| 1118 | else |
| 1119 | return false; // unsupported data type |
| 1120 | } |
| 1121 | |
| 1122 | else // general case: nDepth > 1 or not all pixel valid |
| 1123 | { |
| 1124 | if (hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte. || hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_UShortcxx . . $ LercNS/Lerc2#DT_UShort. || hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.) // unsigned int |
| 1125 | { |
| 1126 | for (int k = 0, m0 = 0, i = 0; i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; i++) |
| 1127 | for (int j = 0; j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; j++, k++, m0 += nDepth) |
| 1128 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 1129 | { |
| 1130 | if (j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. - 1 && m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k + 1)) // hori |
| 1131 | { |
| 1132 | for (int s0 = 0, m = 0; m < nDepth; m++, s0 += maxShift) |
| 1133 | { |
| 1134 | unsigned int c = ((unsigned int)data[m0 + m]) ^ ((unsigned int)data[m0 + m + nDepth]); |
| 1135 | AddUIntToCountscxx . . $ LercNS/Lerc2#AddUIntToCounts(a4fdc77d1ddcd2d8).(&cntDiffVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).s0], c, maxShift); |
| 1136 | } |
| 1137 | cnt++; |
| 1138 | } |
| 1139 | if (i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. - 1 && m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k + hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.)) // vert |
| 1140 | { |
| 1141 | for (int s0 = 0, m = 0; m < nDepth; m++, s0 += maxShift) |
| 1142 | { |
| 1143 | unsigned int c = ((unsigned int)data[m0 + m]) ^ ((unsigned int)data[m0 + m + nDepth * hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.]); |
| 1144 | AddUIntToCountscxx . . $ LercNS/Lerc2#AddUIntToCounts(a4fdc77d1ddcd2d8).(&cntDiffVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).s0], c, maxShift); |
| 1145 | } |
| 1146 | cnt++; |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | else if (hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Charcxx . . $ LercNS/Lerc2#DT_Char. || hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Shortcxx . . $ LercNS/Lerc2#DT_Short. || hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Intcxx . . $ LercNS/Lerc2#DT_Int.) // signed int |
| 1151 | { |
| 1152 | for (int k = 0, m0 = 0, i = 0; i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; i++) |
| 1153 | for (int j = 0; j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; j++, k++, m0 += nDepth) |
| 1154 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 1155 | { |
| 1156 | if (j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. - 1 && m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k + 1)) // hori |
| 1157 | { |
| 1158 | for (int s0 = 0, m = 0; m < nDepth; m++, s0 += maxShift) |
| 1159 | { |
| 1160 | int c = ((int)data[m0 + m]) ^ ((int)data[m0 + m + nDepth]); |
| 1161 | AddIntToCountscxx . . $ LercNS/Lerc2#AddIntToCounts(5f3888e91f92d472).(&cntDiffVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).s0], c, maxShift); |
| 1162 | } |
| 1163 | cnt++; |
| 1164 | } |
| 1165 | if (i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. - 1 && m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k + hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.)) // vert |
| 1166 | { |
| 1167 | for (int s0 = 0, m = 0; m < nDepth; m++, s0 += maxShift) |
| 1168 | { |
| 1169 | int c = ((int)data[m0 + m]) ^ ((int)data[m0 + m + nDepth * hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.]); |
| 1170 | AddIntToCountscxx . . $ LercNS/Lerc2#AddIntToCounts(5f3888e91f92d472).(&cntDiffVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).s0], c, maxShift); |
| 1171 | } |
| 1172 | cnt++; |
| 1173 | } |
| 1174 | } |
| 1175 | } |
| 1176 | else |
| 1177 | return false; // unsupported data type |
| 1178 | } |
| 1179 | |
| 1180 | if (cnt < minCnt) // not enough data for good stats |
| 1181 | return false; |
| 1182 | |
| 1183 | int nCutFound = 0, lastPlaneKept = 0; |
| 1184 | //const bool printAll = false; |
| 1185 | |
| 1186 | for (int s = maxShift - 1; s >= 0; s--) |
| 1187 | { |
| 1188 | //if (printAll) printf("bit plane %2d: ", s); |
| 1189 | bool bCrit = true; |
| 1190 | |
| 1191 | for (int iDepth = 0; iDepth < nDepth; iDepth++) |
| 1192 | { |
| 1193 | double x = cntDiffVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).iDepth * maxShift + s]; |
| 1194 | double n = cnt; |
| 1195 | double m = x / n; |
| 1196 | //double stdDev = sqrt(x * x / n - m * m) / n; |
| 1197 | |
| 1198 | //printf(" %.4f +- %.4f ", (float)(2 * m), (float)(2 * stdDev)); |
| 1199 | //if (printAll) printf(" %.4f ", (float)(2 * m)); |
| 1200 | |
| 1201 | if (fabs(1 - 2 * m) >= eps) |
| 1202 | bCrit = false; |
| 1203 | } |
| 1204 | //if (printAll) printf("\n"); |
| 1205 | |
| 1206 | if (bCrit && nCutFound < 2) |
| 1207 | { |
| 1208 | if (nCutFound == 0) |
| 1209 | lastPlaneKept = s; |
| 1210 | |
| 1211 | if (nCutFound == 1 && s < lastPlaneKept - 1) |
| 1212 | { |
| 1213 | lastPlaneKept = s; |
| 1214 | nCutFound = 0; |
| 1215 | //if (printAll) printf(" reset "); |
| 1216 | } |
| 1217 | |
| 1218 | nCutFound++; |
| 1219 | //if (printAll && nCutFound == 1) printf("\n"); |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | lastPlaneKept = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(0, lastPlaneKept); |
| 1224 | //if (printAll) printf("%d \n", lastPlaneKept); |
| 1225 | |
| 1226 | newMaxZError = (1 << lastPlaneKept) >> 1; // turn lastPlaneKept into new maxZError |
| 1227 | |
| 1228 | return true; |
| 1229 | } |
| 1230 | |
| 1231 | // -------------------------------------------------------------------------- ; |
| 1232 | |
| 1233 | template<class T> |
| 1234 | bool Lerc2cxx . . $ LercNS/Lerc2#::TryRaiseMaxZErrorcxx . . $ LercNS/Lerc2#TryRaiseMaxZError(b6fd15fa3aacb116).(const T* data, double& maxZError) const |
| 1235 | { |
| 1236 | if (!data || m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. < DT_Floatcxx . . $ LercNS/Lerc2#DT_Float. || m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. == 0) |
| 1237 | return false; |
| 1238 | |
| 1239 | const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.; |
| 1240 | const int nDepth = hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 1241 | |
| 1242 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<double> roundErrcxx . . $ std/vector#vector(49f6e7a06ebc5aa8)., zErrcxx . . $ std/vector#vector(49f6e7a06ebc5aa8)., zErrCand = {cxx . . $ std/vector#vector(9619226211e5a241). 1, 0.5, 0.1, 0.05, 0.01, 0.005, 0.001, 0.0005, 0.0001 }; |
| 1243 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<int> zFaccxx . . $ std/vector#vector(49f6e7a06ebc5aa8)., zFacCand = {cxx . . $ std/vector#vector(9619226211e5a241). 1, 2, 10, 20, 100, 200, 1000, 2000, 10000 }; |
| 1244 | |
| 1245 | for (size_t i = 0; i < zErrCand.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); i++) |
| 1246 | if (zErrCand[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] / 2 > maxZError) |
| 1247 | { |
| 1248 | zErr.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(zErrCand[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] / 2); |
| 1249 | zFac.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(zFacCand[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i]); |
| 1250 | roundErr.push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).(0); |
| 1251 | } |
| 1252 | |
| 1253 | if (zErr.emptycxx . . $ std/vector#empty(3482b152b9333168).()) |
| 1254 | return false; |
| 1255 | |
| 1256 | if (nDepth == 1 && hd.numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. == hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. * hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.) // special but common case |
| 1257 | { |
| 1258 | for (int i = 0; i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; i++) |
| 1259 | { |
| 1260 | size_t nCand = zErr.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 1261 | |
| 1262 | for (int k = i * hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols., j = 0; j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; j++, k++) |
| 1263 | { |
| 1264 | double x = data[k]; |
| 1265 | |
| 1266 | for (size_t n = 0; n < nCand; n++) |
| 1267 | { |
| 1268 | double z = x * zFac[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).n]; |
| 1269 | if (z == (int)z) |
| 1270 | break; |
| 1271 | |
| 1272 | double delta = fabs(floor(z + 0.5) - z); |
| 1273 | roundErr[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).n] = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(roundErr[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).n], delta); |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | if (!PruneCandidatescxx . . $ LercNS/Lerc2#PruneCandidates(5c611f0afd62edd0).(roundErr, zErr, zFac, maxZError)) |
| 1278 | return false; |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | else // general case: nDepth > 1 or not all pixel valid |
| 1283 | { |
| 1284 | for (int k = 0, m0 = 0, i = 0; i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; i++) |
| 1285 | { |
| 1286 | size_t nCand = zErr.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 1287 | |
| 1288 | for (int j = 0; j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; j++, k++, m0 += nDepth) |
| 1289 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 1290 | for (int m = 0; m < nDepth; m++) |
| 1291 | { |
| 1292 | double x = data[m0 + m]; |
| 1293 | |
| 1294 | for (size_t n = 0; n < nCand; n++) |
| 1295 | { |
| 1296 | double z = x * zFac[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).n]; |
| 1297 | if (z == (int)z) |
| 1298 | break; |
| 1299 | |
| 1300 | double delta = fabs(floor(z + 0.5) - z); |
| 1301 | roundErr[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).n] = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(roundErr[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).n], delta); |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | if (!PruneCandidatescxx . . $ LercNS/Lerc2#PruneCandidates(5c611f0afd62edd0).(roundErr, zErr, zFac, maxZError)) |
| 1306 | return false; |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | for (size_t n = 0; n < zErr.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); n++) |
| 1311 | if (roundErr[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).n] / zFac[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).n] <= maxZError / 2) |
| 1312 | { |
| 1313 | maxZError = zErr[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).n]; |
| 1314 | return true; |
| 1315 | } |
| 1316 | |
| 1317 | return false; |
| 1318 | } |
| 1319 | |
| 1320 | // -------------------------------------------------------------------------- ; |
| 1321 | |
| 1322 | bool Lerc2cxx . . $ LercNS/Lerc2#::PruneCandidatescxx . . $ LercNS/Lerc2#PruneCandidates(5c611f0afd62edd0).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<double>& roundErr, stdcxx . . $ std/::vectorcxx . . $ std/vector#<double>& zErr, |
| 1323 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& zFac, double maxZError) |
| 1324 | { |
| 1325 | size_t nCand = zErr.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 1326 | |
| 1327 | if (nCand == 0 || roundErr.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() != nCand || zFac.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() != nCand || maxZError <= 0) |
| 1328 | return false; |
| 1329 | |
| 1330 | for (int n = (int)(nCand - 1); n >= 0; n--) |
| 1331 | if (roundErr[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).n] / zFac[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).n] > maxZError / 2) |
| 1332 | { |
| 1333 | roundErr.erasecxx . . $ std/vector#erase(351407f384f345bc).(roundErr.begincxx . . $ std/vector#begin(55a6de06420d4903).() + n); |
| 1334 | zErr.erasecxx . . $ std/vector#erase(351407f384f345bc).(zErr.begincxx . . $ std/vector#begin(55a6de06420d4903).() + n); |
| 1335 | zFac.erasecxx . . $ std/vector#erase(351407f384f345bc).(zFac.begincxx . . $ std/vector#begin(55a6de06420d4903).() + n); |
| 1336 | } |
| 1337 | |
| 1338 | return (!zErr.emptycxx . . $ std/vector#empty(3482b152b9333168).()); |
| 1339 | } |
| 1340 | |
| 1341 | // -------------------------------------------------------------------------- ; |
| 1342 | |
| 1343 | template<class T> |
| 1344 | bool Lerc2cxx . . $ LercNS/Lerc2#::WriteDataOneSweepcxx . . $ LercNS/Lerc2#WriteDataOneSweep(cc83d641fe8bfa9b).(const T* data, Bytecxx . . $ LercNS/Byte#** ppByte) const |
| 1345 | { |
| 1346 | if (!data || !ppByte) |
| 1347 | return false; |
| 1348 | |
| 1349 | Bytecxx . . $ LercNS/Byte#* ptr = (*ppByte); |
| 1350 | const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.; |
| 1351 | int nDepth = hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 1352 | int len = nDepth * sizeof(T); |
| 1353 | |
| 1354 | for (int k = 0, m0 = 0, i = 0; i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; i++) |
| 1355 | for (int j = 0; j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; j++, k++, m0 += nDepth) |
| 1356 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 1357 | { |
| 1358 | memcpy(ptr, &data[m0], len); |
| 1359 | ptr += len; |
| 1360 | } |
| 1361 | |
| 1362 | (*ppByte) = ptr; |
| 1363 | return true; |
| 1364 | } |
| 1365 | |
| 1366 | // -------------------------------------------------------------------------- ; |
| 1367 | |
| 1368 | template<class T> |
| 1369 | bool Lerc2cxx . . $ LercNS/Lerc2#::ReadDataOneSweepcxx . . $ LercNS/Lerc2#ReadDataOneSweep(d8761aea236c93e).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining, T* data) const |
| 1370 | { |
| 1371 | if (!data || !ppByte || !(*ppByte)) |
| 1372 | return false; |
| 1373 | |
| 1374 | const Bytecxx . . $ LercNS/Byte#* ptr = (*ppByte); |
| 1375 | const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.; |
| 1376 | int nDepth = hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 1377 | size_t len = sizeof(T) * nDepth; |
| 1378 | |
| 1379 | int64_t numValid = m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..CountValidBitscxx . . $ LercNS/BitMask#CountValidBits(57a65ae535d7db84).(); |
| 1380 | if (numValid < 0 || numValid >(int64_t)INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!) |
| 1381 | return false; |
| 1382 | |
| 1383 | size_t nValidPix = (size_t)numValid; |
| 1384 | |
| 1385 | if (nBytesRemaining < nValidPix * len) |
| 1386 | return false; |
| 1387 | |
| 1388 | for (int k = 0, m0 = 0, i = 0; i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; i++) |
| 1389 | for (int j = 0; j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; j++, k++, m0 += nDepth) |
| 1390 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 1391 | { |
| 1392 | memcpy(&data[m0], ptr, len); |
| 1393 | ptr += len; |
| 1394 | } |
| 1395 | |
| 1396 | (*ppByte) = ptr; |
| 1397 | nBytesRemaining -= nValidPix * len; |
| 1398 | |
| 1399 | return true; |
| 1400 | } |
| 1401 | |
| 1402 | // -------------------------------------------------------------------------- ; |
| 1403 | |
| 1404 | template<class T> |
| 1405 | bool Lerc2cxx . . $ LercNS/Lerc2#::ComputeMinMaxRangescxx . . $ LercNS/Lerc2#ComputeMinMaxRanges(ac2d38011843179f).(const T* data, stdcxx . . $ std/::vectorcxx . . $ std/vector#<double>& zMinVecA, stdcxx . . $ std/::vectorcxx . . $ std/vector#<double>& zMaxVecA) const |
| 1406 | { |
| 1407 | if (!data || m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. == 0) |
| 1408 | return false; |
| 1409 | |
| 1410 | const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.; |
| 1411 | const int nDepth = hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 1412 | bool bInit = false; |
| 1413 | |
| 1414 | zMinVecA.resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(nDepth); |
| 1415 | zMaxVecA.resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(nDepth); |
| 1416 | |
| 1417 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<T> zMinVec(nDepth, 0), zMaxVec(nDepth, 0); |
| 1418 | |
| 1419 | if (hd.numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. == hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. * hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.) // all valid, no mask |
| 1420 | { |
| 1421 | bInit = true; |
| 1422 | for (int m = 0; m < nDepth; m++) |
| 1423 | zMinVec[m] = zMaxVec[m] = data[m]; |
| 1424 | |
| 1425 | for (int m0 = 0, i = 0; i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; i++) |
| 1426 | for (int j = 0; j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; j++, m0 += nDepth) |
| 1427 | for (int m = 0; m < nDepth; m++) |
| 1428 | { |
| 1429 | T val = data[m0 + m]; |
| 1430 | |
| 1431 | if (val <cxx . . $ std/`operator<`(9c5f1f2306f1a4b2). zMinVec[m]) |
| 1432 | zMinVec[m] = val; |
| 1433 | else if (val >cxx . . $ std/`operator>`(9c5f1f2306f1a4b2). zMaxVec[m]) |
| 1434 | zMaxVec[m] = val; |
| 1435 | } |
| 1436 | } |
| 1437 | else |
| 1438 | { |
| 1439 | for (int k = 0, m0 = 0, i = 0; i < hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; i++) |
| 1440 | for (int j = 0; j < hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; j++, k++, m0 += nDepth) |
| 1441 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 1442 | { |
| 1443 | if (bInit) |
| 1444 | for (int m = 0; m < nDepth; m++) |
| 1445 | { |
| 1446 | T val = data[m0 + m]; |
| 1447 | |
| 1448 | if (val <cxx . . $ std/`operator<`(9c5f1f2306f1a4b2). zMinVec[m]) |
| 1449 | zMinVec[m] = val; |
| 1450 | else if (val >cxx . . $ std/`operator>`(9c5f1f2306f1a4b2). zMaxVec[m]) |
| 1451 | zMaxVec[m] = val; |
| 1452 | } |
| 1453 | else |
| 1454 | { |
| 1455 | bInit = true; |
| 1456 | for (int m = 0; m < nDepth; m++) |
| 1457 | zMinVec[m] = zMaxVec[m] = data[m0 + m]; |
| 1458 | } |
| 1459 | } |
| 1460 | } |
| 1461 | |
| 1462 | if (bInit) |
| 1463 | for (int m = 0; m < nDepth; m++) |
| 1464 | { |
| 1465 | zMinVecA[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).m] = zMinVec[m]; |
| 1466 | zMaxVecA[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).m] = zMaxVec[m]; |
| 1467 | } |
| 1468 | |
| 1469 | return bInit; |
| 1470 | } |
| 1471 | |
| 1472 | // -------------------------------------------------------------------------- ; |
| 1473 | |
| 1474 | template<class T> |
| 1475 | bool Lerc2cxx . . $ LercNS/Lerc2#::WriteTilescxx . . $ LercNS/Lerc2#WriteTiles(b7537629c01bf85b).(const T* data, Bytecxx . . $ LercNS/Byte#** ppByte, int& numBytes) const |
| 1476 | { |
| 1477 | if (!data || !ppByte) |
| 1478 | return false; |
| 1479 | |
| 1480 | numBytes = 0; |
| 1481 | int numBytesLerc = 0; |
| 1482 | |
| 1483 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int> quantVeccxx . . $ std/vector#vector(49f6e7a06ebc5aa8)., quantVecDiffcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 1484 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::pair<unsigned int, unsigned int> > sortedQuantVeccxx . . $ std/vector#vector(49f6e7a06ebc5aa8)., sortedQuantVecDiffcxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 1485 | |
| 1486 | const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.; |
| 1487 | int mbSize = hd.microBlockSizecxx . . $ LercNS/Lerc2#HeaderInfo#microBlockSize.; |
| 1488 | int nDepth = hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 1489 | |
| 1490 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<T> dataVec((size_t)mbSize * mbSize, 0); |
| 1491 | T* dataBuf = &dataVec[0]; |
| 1492 | |
| 1493 | const bool bDtInt = (hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. < DT_Floatcxx . . $ LercNS/Lerc2#DT_Float.); |
| 1494 | const bool bIntLossless = bDtInt && (hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. == 0.5); |
| 1495 | const bool bTryDiffEnc = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 5) && (nDepth > 1) && bIntLossless; // only for int lossless to avoid error propagation |
| 1496 | |
| 1497 | const bool bCheckForIntOverflow = NeedToCheckForIntOverflowcxx . . $ LercNS/Lerc2#NeedToCheckForIntOverflow(bf20af955ee05b5d).(hd); |
| 1498 | const bool bCheckForFltRndErr = NeedToCheckForFltRndErrcxx . . $ LercNS/Lerc2#NeedToCheckForFltRndErr(bf20af955ee05b5d).(hd); |
| 1499 | |
| 1500 | int mbDiff2 = bTryDiffEnc ? mbSize * mbSize : 0; |
| 1501 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<int> diffDataVecIntcxx . . $ std/vector#vector(229e4d6bd205de31).(mbDiff2, 0); // use fixed type (int) for difference of all int types |
| 1502 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<T> diffDataVecFlt(mbDiff2, 0), prevDataVec(mbDiff2, 0); |
| 1503 | |
| 1504 | int numTilesVert = (hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. + mbSize - 1) / mbSize; |
| 1505 | int numTilesHori = (hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. + mbSize - 1) / mbSize; |
| 1506 | |
| 1507 | for (int iTile = 0; iTile < numTilesVert; iTile++) |
| 1508 | { |
| 1509 | int tileH = mbSize; |
| 1510 | int i0 = iTile * tileH; |
| 1511 | if (iTile == numTilesVert - 1) |
| 1512 | tileH = hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. - i0; |
| 1513 | |
| 1514 | for (int jTile = 0; jTile < numTilesHori; jTile++) |
| 1515 | { |
| 1516 | int tileW = mbSize; |
| 1517 | int j0 = jTile * tileW; |
| 1518 | if (jTile == numTilesHori - 1) |
| 1519 | tileW = hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. - j0; |
| 1520 | |
| 1521 | for (int iDepth = 0; iDepth < nDepth; iDepth++) |
| 1522 | { |
| 1523 | T zMin = 0, zMax = 0; |
| 1524 | int numValidPixel = 0; |
| 1525 | bool bQuantizeDone = false; |
| 1526 | bool tryLut = false; |
| 1527 | |
| 1528 | if (!GetValidDataAndStatscxx . . $ LercNS/Lerc2#GetValidDataAndStats(8703c438c2986eac).(data, i0, i0 + tileH, j0, j0 + tileW, iDepth, dataBuf, zMin, zMax, numValidPixel, tryLut)) |
| 1529 | return false; |
| 1530 | |
| 1531 | if (numValidPixel == 0 && !(*ppByte)) |
| 1532 | { |
| 1533 | numBytesLerc += nDepth; // 1 byte per empty block |
| 1534 | break; // iDepth loop |
| 1535 | } |
| 1536 | |
| 1537 | //tryLut = false; // always OFF |
| 1538 | //tryLut = NeedToQuantize(numValidPixel, zMin, zMax); // always ON |
| 1539 | |
| 1540 | // if needed, quantize the data here once |
| 1541 | if (((*ppByte && iDepth == 0) || tryLut) && NeedToQuantizecxx . . $ LercNS/Lerc2#NeedToQuantize(2999a0978c8d2873).(numValidPixel, zMin, zMax)) |
| 1542 | { |
| 1543 | Quantizecxx . . $ LercNS/Lerc2#Quantize(e1565945717ed8ab).(dataBuf, numValidPixel, zMin, quantVec); |
| 1544 | bQuantizeDone = true; |
| 1545 | if (tryLut) |
| 1546 | SortQuantArraycxx . . $ LercNS/Lerc2#SortQuantArray(3b8c1c1ca38f2c23).(quantVec, sortedQuantVec); |
| 1547 | } |
| 1548 | |
| 1549 | BlockEncodeModecxx . . $ LercNS/Lerc2#BlockEncodeMode# blockEncodeMode(BEM_RawBinarycxx . . $ LercNS/Lerc2#BEM_RawBinary.), blockEncodeModeDiff(BEM_RawBinarycxx . . $ LercNS/Lerc2#BEM_RawBinary.); |
| 1550 | int numBytesNeeded = NumBytesTilecxx . . $ LercNS/Lerc2#NumBytesTile(2ecbd70ef45e66ca).(numValidPixel, zMin, zMax, hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt., tryLut, blockEncodeMode, sortedQuantVec); |
| 1551 | |
| 1552 | int numBytesNeededDiff = numBytesNeeded + 1; |
| 1553 | int zMinDiffInt(0), zMaxDiffInt(0); |
| 1554 | T zMinDiffFlt(0), zMaxDiffFlt(0); |
| 1555 | double zMinDiff(0), zMaxDiff(0); |
| 1556 | bool bQuantizeDoneDiff = false, tryLutDiff = false; |
| 1557 | |
| 1558 | if (bTryDiffEnc && iDepth > 0 && numValidPixel > 0) |
| 1559 | { |
| 1560 | bool rv = bDtInt ? ComputeDiffSliceIntcxx . . $ LercNS/Lerc2#ComputeDiffSliceInt(eab4b4994b480060).(&dataVec[0], &prevDataVec[0], numValidPixel, bCheckForIntOverflow, hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError., diffDataVecInt, zMinDiffInt, zMaxDiffInt, tryLutDiff) |
| 1561 | : ComputeDiffSliceFltcxx . . $ LercNS/Lerc2#ComputeDiffSliceFlt(97f9455deea0d2f9).(&dataVec[0], &prevDataVec[0], numValidPixel, bCheckForFltRndErr, hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError., diffDataVecFlt, zMinDiffFlt, zMaxDiffFlt, tryLutDiff); |
| 1562 | |
| 1563 | zMinDiff = bDtInt ? zMinDiffInt : zMinDiffFlt; |
| 1564 | zMaxDiff = bDtInt ? zMaxDiffInt : zMaxDiffFlt; |
| 1565 | |
| 1566 | if (rv) // can be false due to int overflow, then fall back to abs / regular encode |
| 1567 | { |
| 1568 | // tryLutDiff = false; // for faster encode? |
| 1569 | |
| 1570 | if (tryLutDiff && NeedToQuantizecxx . . $ LercNS/Lerc2#NeedToQuantize(2999a0978c8d2873).(numValidPixel, zMinDiff, zMaxDiff)) |
| 1571 | { |
| 1572 | bDtInt ? Quantizecxx . . $ LercNS/Lerc2#Quantize(e1565945717ed8ab).(&diffDataVecInt[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], numValidPixel, zMinDiffInt, quantVecDiff) |
| 1573 | : Quantizecxx . . $ LercNS/Lerc2#Quantize(e1565945717ed8ab).(&diffDataVecFlt[0], numValidPixel, zMinDiffFlt, quantVecDiff); |
| 1574 | bQuantizeDoneDiff = true; |
| 1575 | SortQuantArraycxx . . $ LercNS/Lerc2#SortQuantArray(3b8c1c1ca38f2c23).(quantVecDiff, sortedQuantVecDiff); |
| 1576 | } |
| 1577 | |
| 1578 | int nb = bDtInt ? NumBytesTilecxx . . $ LercNS/Lerc2#NumBytesTile(2ecbd70ef45e66ca).(numValidPixel, zMinDiffInt, zMaxDiffInt, DT_Intcxx . . $ LercNS/Lerc2#DT_Int., tryLutDiff, blockEncodeModeDiff, sortedQuantVecDiff) |
| 1579 | : NumBytesTilecxx . . $ LercNS/Lerc2#NumBytesTile(2ecbd70ef45e66ca).(numValidPixel, zMinDiffFlt, zMaxDiffFlt, hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt., tryLutDiff, blockEncodeModeDiff, sortedQuantVecDiff); |
| 1580 | if (nb > 0) |
| 1581 | numBytesNeededDiff = nb; |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | numBytesLerc += stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(numBytesNeeded, numBytesNeededDiff); |
| 1586 | |
| 1587 | if (bTryDiffEnc && iDepth < (nDepth - 1) && numValidPixel > 0) |
| 1588 | { |
| 1589 | if (iDepth == 0) |
| 1590 | prevDataVec.resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(numValidPixel); |
| 1591 | |
| 1592 | if (!bIntLossless) // if not int lossless: do lossy quantize back and forth, then copy to buffer |
| 1593 | { |
| 1594 | double zMaxClamp = m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).iDepth]; |
| 1595 | bool bClampScaleBack = (zMax +cxx . . $ std/operator+(2764d1739bf7913d). 2 * hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. >cxx . . $ std/`operator>`(9c5f1f2306f1a4b2). zMaxClamp); |
| 1596 | |
| 1597 | if (iDepth == 0 || numBytesNeeded <= numBytesNeededDiff) // for regular or abs encode |
| 1598 | { |
| 1599 | if (bQuantizeDone || NeedToQuantizecxx . . $ LercNS/Lerc2#NeedToQuantize(2999a0978c8d2873).(numValidPixel, zMin, zMax)) |
| 1600 | { |
| 1601 | if (!bQuantizeDone) |
| 1602 | Quantizecxx . . $ LercNS/Lerc2#Quantize(e1565945717ed8ab).(dataBuf, numValidPixel, zMin, quantVec); |
| 1603 | |
| 1604 | bQuantizeDone = true; |
| 1605 | ScaleBackcxx . . $ LercNS/Lerc2#ScaleBack(89d102402d680757).(&prevDataVec[0], quantVec, zMin, false, bClampScaleBack, zMaxClamp, hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError.); |
| 1606 | } |
| 1607 | else if (zMin ==cxx . . $ std/`operator==`(bf4c77cd91c4b201). zMax || ((hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. > 0) && (0 == (unsigned int)(ComputeMaxValcxx . . $ LercNS/Lerc2#ComputeMaxVal(7678bba071383ab).(zMin, zMax, hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError.) +cxx . . $ std/operator+(2764d1739bf7913d). 0.5)))) // const block case |
| 1608 | prevDataVec.assigncxx . . $ std/vector#assign(3804226c8c0acbc3).(numValidPixel, zMin); |
| 1609 | else |
| 1610 | copycxx . . $ std/copy(88304b602929f6f4).(dataVec.begincxx . . $ std/vector#begin(55a6de06420d4903).(), dataVec.begincxx . . $ std/vector#begin(55a6de06420d4903).() +cxx . . $ std/operator+(2764d1739bf7913d). numValidPixel, prevDataVec.begincxx . . $ std/vector#begin(55a6de06420d4903).()); |
| 1611 | } |
| 1612 | else // for diff or relative encode |
| 1613 | { |
| 1614 | if (bQuantizeDoneDiff || NeedToQuantizecxx . . $ LercNS/Lerc2#NeedToQuantize(2999a0978c8d2873).(numValidPixel, zMinDiff, zMaxDiff)) |
| 1615 | { |
| 1616 | if (!bQuantizeDoneDiff) |
| 1617 | bDtInt ? Quantizecxx . . $ LercNS/Lerc2#Quantize(e1565945717ed8ab).(&diffDataVecInt[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], numValidPixel, zMinDiffInt, quantVecDiff) |
| 1618 | : Quantizecxx . . $ LercNS/Lerc2#Quantize(e1565945717ed8ab).(&diffDataVecFlt[0], numValidPixel, zMinDiffFlt, quantVecDiff); |
| 1619 | |
| 1620 | bQuantizeDoneDiff = true; |
| 1621 | ScaleBackcxx . . $ LercNS/Lerc2#ScaleBack(89d102402d680757).(&prevDataVec[0], quantVecDiff, zMinDiff, true, bClampScaleBack, zMaxClamp, hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError.); |
| 1622 | } |
| 1623 | else if (zMinDiff == zMaxDiff || ((hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. > 0) && (0 == (unsigned int)(ComputeMaxValcxx . . $ LercNS/Lerc2#ComputeMaxVal(7678bba071383ab).(zMinDiff, zMaxDiff, hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError.) + 0.5)))) // const block case |
| 1624 | { |
| 1625 | ScaleBackConstBlockcxx . . $ LercNS/Lerc2#ScaleBackConstBlock(774e296019d19ac7).(&prevDataVec[0], numValidPixel, zMinDiff, bClampScaleBack, zMaxClamp); |
| 1626 | } |
| 1627 | else |
| 1628 | copycxx . . $ std/copy(88304b602929f6f4).(dataVec.begincxx . . $ std/vector#begin(55a6de06420d4903).(), dataVec.begincxx . . $ std/vector#begin(55a6de06420d4903).() +cxx . . $ std/operator+(2764d1739bf7913d). numValidPixel, prevDataVec.begincxx . . $ std/vector#begin(55a6de06420d4903).()); |
| 1629 | } |
| 1630 | } |
| 1631 | else |
| 1632 | copycxx . . $ std/copy(88304b602929f6f4).(dataVec.begincxx . . $ std/vector#begin(55a6de06420d4903).(), dataVec.begincxx . . $ std/vector#begin(55a6de06420d4903).() +cxx . . $ std/operator+(2764d1739bf7913d). numValidPixel, prevDataVec.begincxx . . $ std/vector#begin(55a6de06420d4903).()); |
| 1633 | } |
| 1634 | |
| 1635 | if (*ppByte) |
| 1636 | { |
| 1637 | int numBytesWritten = 0; |
| 1638 | bool rv = false; |
| 1639 | |
| 1640 | if (iDepth == 0 || numBytesNeeded <= numBytesNeededDiff) |
| 1641 | { |
| 1642 | if (!bQuantizeDone && NeedToQuantizecxx . . $ LercNS/Lerc2#NeedToQuantize(2999a0978c8d2873).(numValidPixel, zMin, zMax)) |
| 1643 | Quantizecxx . . $ LercNS/Lerc2#Quantize(e1565945717ed8ab).(dataBuf, numValidPixel, zMin, quantVec); |
| 1644 | |
| 1645 | rv = WriteTilecxx . . $ LercNS/Lerc2#WriteTile(a3208ab338cab164).(dataBuf, numValidPixel, ppByte, numBytesWritten, j0, zMin, zMax, hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt., false, quantVec, blockEncodeMode, sortedQuantVec); |
| 1646 | } |
| 1647 | else |
| 1648 | { |
| 1649 | if (!bQuantizeDoneDiff && NeedToQuantizecxx . . $ LercNS/Lerc2#NeedToQuantize(2999a0978c8d2873).(numValidPixel, zMinDiff, zMaxDiff)) |
| 1650 | { |
| 1651 | bDtInt ? Quantizecxx . . $ LercNS/Lerc2#Quantize(e1565945717ed8ab).(&diffDataVecInt[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], numValidPixel, zMinDiffInt, quantVecDiff) |
| 1652 | : Quantizecxx . . $ LercNS/Lerc2#Quantize(e1565945717ed8ab).(&diffDataVecFlt[0], numValidPixel, zMinDiffFlt, quantVecDiff); |
| 1653 | } |
| 1654 | rv = bDtInt |
| 1655 | ? WriteTilecxx . . $ LercNS/Lerc2#WriteTile(a3208ab338cab164).(&diffDataVecInt[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], numValidPixel, ppByte, numBytesWritten, j0, zMinDiffInt, zMaxDiffInt, DT_Intcxx . . $ LercNS/Lerc2#DT_Int., true, quantVecDiff, blockEncodeModeDiff, sortedQuantVecDiff) |
| 1656 | : WriteTilecxx . . $ LercNS/Lerc2#WriteTile(a3208ab338cab164).(&diffDataVecFlt[0], numValidPixel, ppByte, numBytesWritten, j0, zMinDiffFlt, zMaxDiffFlt, hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt., true, quantVecDiff, blockEncodeModeDiff, sortedQuantVecDiff); |
| 1657 | } |
| 1658 | |
| 1659 | if (!rv || numBytesWritten != stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(numBytesNeeded, numBytesNeededDiff)) |
| 1660 | return false; |
| 1661 | } |
| 1662 | } |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | numBytes += numBytesLerc; |
| 1667 | return true; |
| 1668 | } |
| 1669 | |
| 1670 | // -------------------------------------------------------------------------- ; |
| 1671 | |
| 1672 | template<class T> |
| 1673 | bool Lerc2cxx . . $ LercNS/Lerc2#::ReadTilescxx . . $ LercNS/Lerc2#ReadTiles(d8761aea236c93e).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining, T* data) const |
| 1674 | { |
| 1675 | if (!data || !ppByte || !(*ppByte)) |
| 1676 | return false; |
| 1677 | |
| 1678 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int> bufferVeccxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 1679 | |
| 1680 | const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.; |
| 1681 | int mbSize = hd.microBlockSizecxx . . $ LercNS/Lerc2#HeaderInfo#microBlockSize.; |
| 1682 | int nDepth = hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 1683 | |
| 1684 | if (mbSize > 32) |
| 1685 | return false; |
| 1686 | |
| 1687 | int numTilesVert = (hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. + mbSize - 1) / mbSize; |
| 1688 | int numTilesHori = (hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. + mbSize - 1) / mbSize; |
| 1689 | |
| 1690 | for (int iTile = 0; iTile < numTilesVert; iTile++) |
| 1691 | { |
| 1692 | int tileH = mbSize; |
| 1693 | int i0 = iTile * tileH; |
| 1694 | if (iTile == numTilesVert - 1) |
| 1695 | tileH = hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. - i0; |
| 1696 | |
| 1697 | for (int jTile = 0; jTile < numTilesHori; jTile++) |
| 1698 | { |
| 1699 | int tileW = mbSize; |
| 1700 | int j0 = jTile * tileW; |
| 1701 | if (jTile == numTilesHori - 1) |
| 1702 | tileW = hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. - j0; |
| 1703 | |
| 1704 | for (int iDepth = 0; iDepth < nDepth; iDepth++) |
| 1705 | { |
| 1706 | if (!ReadTilecxx . . $ LercNS/Lerc2#ReadTile(e46b292ef6d163a3).(ppByte, nBytesRemaining, data, i0, i0 + tileH, j0, j0 + tileW, iDepth, bufferVec)) |
| 1707 | return false; |
| 1708 | } |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | return true; |
| 1713 | } |
| 1714 | |
| 1715 | // -------------------------------------------------------------------------- ; |
| 1716 | |
| 1717 | template<class T> |
| 1718 | bool Lerc2cxx . . $ LercNS/Lerc2#::GetValidDataAndStatscxx . . $ LercNS/Lerc2#GetValidDataAndStats(8703c438c2986eac).(const T* data, int i0, int i1, int j0, int j1, int iDepth, |
| 1719 | T* dataBuf, T& zMin, T& zMax, int& numValidPixel, bool& tryLut) const |
| 1720 | { |
| 1721 | const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.; |
| 1722 | |
| 1723 | if (!data || i0 < 0 || j0 < 0 || i1 > hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows. || j1 > hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. || i0 >= i1 || j0 >= j1 || iDepth < 0 || iDepth > hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth. || !dataBuf) |
| 1724 | return false; |
| 1725 | |
| 1726 | zMin = zMax = 0; |
| 1727 | tryLut = false; |
| 1728 | |
| 1729 | T prevVal = 0; |
| 1730 | int cnt = 0, cntSameVal = 0; |
| 1731 | int nDepth = hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 1732 | |
| 1733 | if (hd.numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. == hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. * hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.) // all valid, no mask |
| 1734 | { |
| 1735 | int k0 = i0 * hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. + j0; |
| 1736 | int m0 = k0 * nDepth + iDepth; |
| 1737 | zMin = zMax = data[m0]; // init |
| 1738 | |
| 1739 | for (int i = i0; i < i1; i++) |
| 1740 | { |
| 1741 | int k = i * hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. + j0; |
| 1742 | int m = k * nDepth + iDepth; |
| 1743 | |
| 1744 | for (int j = j0; j < j1; j++, m += nDepth) |
| 1745 | { |
| 1746 | T val = data[m]; |
| 1747 | dataBuf[cnt] = val; |
| 1748 | |
| 1749 | if (val <cxx . . $ std/`operator<`(9c5f1f2306f1a4b2). zMin) |
| 1750 | zMin = val; |
| 1751 | else if (val >cxx . . $ std/`operator>`(9c5f1f2306f1a4b2). zMax) |
| 1752 | zMax = val; |
| 1753 | |
| 1754 | if (val ==cxx . . $ std/`operator==`(bf4c77cd91c4b201). prevVal) |
| 1755 | cntSameVal++; |
| 1756 | |
| 1757 | prevVal = val; |
| 1758 | cnt++; |
| 1759 | } |
| 1760 | } |
| 1761 | } |
| 1762 | else // not all valid, use mask |
| 1763 | { |
| 1764 | for (int i = i0; i < i1; i++) |
| 1765 | { |
| 1766 | int k = i * hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols. + j0; |
| 1767 | int m = k * nDepth + iDepth; |
| 1768 | |
| 1769 | for (int j = j0; j < j1; j++, k++, m += nDepth) |
| 1770 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 1771 | { |
| 1772 | T val = data[m]; |
| 1773 | dataBuf[cnt] = val; |
| 1774 | |
| 1775 | if (cnt > 0) |
| 1776 | { |
| 1777 | if (val <cxx . . $ std/`operator<`(9c5f1f2306f1a4b2). zMin) |
| 1778 | zMin = val; |
| 1779 | else if (val >cxx . . $ std/`operator>`(9c5f1f2306f1a4b2). zMax) |
| 1780 | zMax = val; |
| 1781 | |
| 1782 | if (val ==cxx . . $ std/`operator==`(bf4c77cd91c4b201). prevVal) |
| 1783 | cntSameVal++; |
| 1784 | } |
| 1785 | else |
| 1786 | zMin = zMax = val; // init |
| 1787 | |
| 1788 | prevVal = val; |
| 1789 | cnt++; |
| 1790 | } |
| 1791 | } |
| 1792 | } |
| 1793 | |
| 1794 | if (cnt > 4) |
| 1795 | tryLut = (zMax >cxx . . $ std/`operator>`(9c5f1f2306f1a4b2). zMin +cxx . . $ std/operator+(2764d1739bf7913d). 3 * hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError.) && (2 * cntSameVal > cnt); |
| 1796 | |
| 1797 | numValidPixel = cnt; |
| 1798 | return true; |
| 1799 | } |
| 1800 | |
| 1801 | // -------------------------------------------------------------------------- ; |
| 1802 | |
| 1803 | template<class T> |
| 1804 | bool Lerc2cxx . . $ LercNS/Lerc2#::ComputeDiffSliceIntcxx . . $ LercNS/Lerc2#ComputeDiffSliceInt(eab4b4994b480060).(const T* data, const T* prevData, int numValidPixel, |
| 1805 | bool bCheckForIntOverflow, double maxZError, |
| 1806 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& diffDataVec, int& zMin, int& zMax, bool& tryLut) |
| 1807 | { |
| 1808 | if (numValidPixel <= 0) |
| 1809 | return false; |
| 1810 | |
| 1811 | diffDataVec.resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(numValidPixel); |
| 1812 | |
| 1813 | int prevVal(0), cnt(0), cntSameVal(0); |
| 1814 | |
| 1815 | if (!bCheckForIntOverflow) |
| 1816 | { |
| 1817 | zMin = zMax = (int)data[0] - (int)prevData[0]; // init |
| 1818 | |
| 1819 | for (int i = 0; i < numValidPixel; i++) |
| 1820 | { |
| 1821 | int val = (int)data[i] - (int)prevData[i]; |
| 1822 | |
| 1823 | diffDataVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] = val; |
| 1824 | |
| 1825 | if (val < zMin) |
| 1826 | zMin = val; |
| 1827 | else if (val > zMax) |
| 1828 | zMax = val; |
| 1829 | |
| 1830 | if (val == prevVal) |
| 1831 | cntSameVal++; |
| 1832 | |
| 1833 | prevVal = val; |
| 1834 | cnt++; |
| 1835 | } |
| 1836 | } |
| 1837 | else |
| 1838 | { |
| 1839 | zMin = zMax = (int)((double)data[0] - (double)prevData[0]); // init |
| 1840 | const double zIntMax = 0x7FFFFFFF; |
| 1841 | const double zIntMin = -zIntMax - 1; |
| 1842 | bool bOverflow = false; |
| 1843 | |
| 1844 | for (int i = 0; i < numValidPixel; i++) |
| 1845 | { |
| 1846 | double z = (double)data[i] - (double)prevData[i]; |
| 1847 | int val = (int)z; |
| 1848 | |
| 1849 | if (z < zIntMin || z > zIntMax) // check for int32 overflow |
| 1850 | bOverflow = true; |
| 1851 | |
| 1852 | diffDataVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] = val; |
| 1853 | |
| 1854 | if (val < zMin) |
| 1855 | zMin = val; |
| 1856 | else if (val > zMax) |
| 1857 | zMax = val; |
| 1858 | |
| 1859 | if (val == prevVal) |
| 1860 | cntSameVal++; |
| 1861 | |
| 1862 | prevVal = val; |
| 1863 | cnt++; |
| 1864 | } |
| 1865 | |
| 1866 | if (bOverflow) |
| 1867 | return false; |
| 1868 | } |
| 1869 | |
| 1870 | if (cnt > 4) |
| 1871 | tryLut = (zMax > zMin + 3 * maxZError) && (2 * cntSameVal > cnt); |
| 1872 | |
| 1873 | return true; |
| 1874 | } |
| 1875 | |
| 1876 | // -------------------------------------------------------------------------- ; |
| 1877 | |
| 1878 | template<class T> |
| 1879 | bool Lerc2cxx . . $ LercNS/Lerc2#::ComputeDiffSliceFltcxx . . $ LercNS/Lerc2#ComputeDiffSliceFlt(97f9455deea0d2f9).(const T* data, const T* prevData, int numValidPixel, |
| 1880 | bool bCheckForFltRndErr, double maxZError, |
| 1881 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<T>& diffDataVec, T& zMin, T& zMax, bool& tryLut) |
| 1882 | { |
| 1883 | if (numValidPixel <= 0) |
| 1884 | return false; |
| 1885 | |
| 1886 | diffDataVec.resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(numValidPixel); |
| 1887 | |
| 1888 | zMin = zMax = (T)((double)data[0] - (double)prevData[0]); // init |
| 1889 | T prevVal(0); |
| 1890 | int cnt(0), cntSameVal(0); |
| 1891 | |
| 1892 | if (!bCheckForFltRndErr) |
| 1893 | { |
| 1894 | for (int i = 0; i < numValidPixel; i++) |
| 1895 | { |
| 1896 | T val = (T)((double)data[i] - (double)prevData[i]); |
| 1897 | |
| 1898 | diffDataVec[i] = val; |
| 1899 | |
| 1900 | if (val <cxx . . $ std/`operator<`(9c5f1f2306f1a4b2). zMin) |
| 1901 | zMin = val; |
| 1902 | else if (val >cxx . . $ std/`operator>`(9c5f1f2306f1a4b2). zMax) |
| 1903 | zMax = val; |
| 1904 | |
| 1905 | if (val ==cxx . . $ std/`operator==`(bf4c77cd91c4b201). prevVal) |
| 1906 | cntSameVal++; |
| 1907 | |
| 1908 | prevVal = val; |
| 1909 | cnt++; |
| 1910 | } |
| 1911 | } |
| 1912 | else |
| 1913 | { |
| 1914 | double maxRoundErr = 0; |
| 1915 | |
| 1916 | for (int i = 0; i < numValidPixel; i++) |
| 1917 | { |
| 1918 | T val = (T)((double)data[i] - (double)prevData[i]); |
| 1919 | |
| 1920 | double testVal = (double)val + (double)prevData[i]; // compute flt pnt rounding error |
| 1921 | maxRoundErr = (stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).)(fabs(testVal - (double)data[i]), maxRoundErr); |
| 1922 | |
| 1923 | diffDataVec[i] = val; |
| 1924 | |
| 1925 | if (val <cxx . . $ std/`operator<`(9c5f1f2306f1a4b2). zMin) |
| 1926 | zMin = val; |
| 1927 | else if (val >cxx . . $ std/`operator>`(9c5f1f2306f1a4b2). zMax) |
| 1928 | zMax = val; |
| 1929 | |
| 1930 | if (val ==cxx . . $ std/`operator==`(bf4c77cd91c4b201). prevVal) |
| 1931 | cntSameVal++; |
| 1932 | |
| 1933 | prevVal = val; |
| 1934 | cnt++; |
| 1935 | } |
| 1936 | |
| 1937 | if (maxRoundErr > maxZError / 8) |
| 1938 | return false; |
| 1939 | } |
| 1940 | |
| 1941 | if (cnt > 4) |
| 1942 | tryLut = (zMax >cxx . . $ std/`operator>`(9c5f1f2306f1a4b2). zMin +cxx . . $ std/operator+(2764d1739bf7913d). 3 * maxZError) && (2 * cntSameVal > cnt); |
| 1943 | |
| 1944 | return true; |
| 1945 | } |
| 1946 | |
| 1947 | // -------------------------------------------------------------------------- ; |
| 1948 | |
| 1949 | template<class T> |
| 1950 | bool Lerc2cxx . . $ LercNS/Lerc2#::WriteTilecxx . . $ LercNS/Lerc2#WriteTile(a3208ab338cab164).(const T* dataBuf, int num, Bytecxx . . $ LercNS/Byte#** ppByte, int& numBytesWritten, int j0, T zMin, T zMax, |
| 1951 | DataTypecxx . . $ LercNS/Lerc2#DataType# dtZ, bool bDiffEnc, const stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int>& quantVec, BlockEncodeModecxx . . $ LercNS/Lerc2#BlockEncodeMode# blockEncodeMode, |
| 1952 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::pair<unsigned int, unsigned int>>& sortedQuantVec) const |
| 1953 | { |
| 1954 | Bytecxx . . $ LercNS/Byte#* ptr = *ppByte; |
| 1955 | Bytecxx . . $ LercNS/Byte# comprFlag = ((j0 >> 3) & 15) << 2; // use bits 2345 for integrity check |
| 1956 | |
| 1957 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 5) |
| 1958 | comprFlag = bDiffEnc ? (comprFlag | 4) : (comprFlag & (7 << 3)); // bit 2 now encodes diff encoding |
| 1959 | |
| 1960 | if (num == 0 || (zMin ==cxx . . $ std/`operator==`(bf4c77cd91c4b201). 0 && zMax ==cxx . . $ std/`operator==`(bf4c77cd91c4b201). 0)) // special cases |
| 1961 | { |
| 1962 | *ptr++ = comprFlag | 2; // set compression flag to 2 to mark tile as constant 0 |
| 1963 | numBytesWritten = 1; |
| 1964 | *ppByte = ptr; |
| 1965 | return true; |
| 1966 | } |
| 1967 | |
| 1968 | if (blockEncodeMode == BEM_RawBinarycxx . . $ LercNS/Lerc2#BEM_RawBinary.) |
| 1969 | { |
| 1970 | if (bDiffEnc) |
| 1971 | return false; // doesn't make sense, should not happen |
| 1972 | |
| 1973 | *ptr++ = comprFlag | 0; // write z's binary uncompressed |
| 1974 | |
| 1975 | memcpy(ptr, dataBuf, num * sizeof(T)); |
| 1976 | ptr += num * sizeof(T); |
| 1977 | } |
| 1978 | else |
| 1979 | { |
| 1980 | double maxVal = (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. > 0) ? ComputeMaxValcxx . . $ LercNS/Lerc2#ComputeMaxVal(7678bba071383ab).(zMin, zMax, m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError.) : 0; |
| 1981 | |
| 1982 | // write z's as int arr bit stuffed |
| 1983 | unsigned int maxElem = (unsigned int)(maxVal + 0.5); |
| 1984 | if (maxElem == 0) |
| 1985 | comprFlag |= 3; // set compression flag to 3 to mark tile as constant zMin |
| 1986 | else |
| 1987 | comprFlag |= 1; // use bit stuffing |
| 1988 | |
| 1989 | DataTypecxx . . $ LercNS/Lerc2#DataType# dtReduced; |
| 1990 | int bits67 = ReduceDataTypecxx . . $ LercNS/Lerc2#ReduceDataType(119daec24cbf5a2e).(zMin, dtZ, dtReduced); |
| 1991 | comprFlag |= bits67 << 6; |
| 1992 | |
| 1993 | *ptr++ = comprFlag; |
| 1994 | |
| 1995 | if (!WriteVariableDataTypecxx . . $ LercNS/Lerc2#WriteVariableDataType(f74bd397b7d7cc62).(&ptr, (double)zMin, dtReduced)) |
| 1996 | return false; |
| 1997 | |
| 1998 | if (maxElem > 0) |
| 1999 | { |
| 2000 | if ((int)quantVec.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() != num) |
| 2001 | return false; |
| 2002 | |
| 2003 | if (blockEncodeMode == BEM_BitStuffSimplecxx . . $ LercNS/Lerc2#BEM_BitStuffSimple.) |
| 2004 | { |
| 2005 | if (!m_bitStuffer2cxx . . $ LercNS/Lerc2#m_bitStuffer2..EncodeSimplecxx . . $ LercNS/BitStuffer2#EncodeSimple(cf58339148bdbf5).(&ptr, quantVec, m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version.)) |
| 2006 | return false; |
| 2007 | } |
| 2008 | else if (blockEncodeMode == BEM_BitStuffLUTcxx . . $ LercNS/Lerc2#BEM_BitStuffLUT.) |
| 2009 | { |
| 2010 | if (!m_bitStuffer2cxx . . $ LercNS/Lerc2#m_bitStuffer2..EncodeLutcxx . . $ LercNS/BitStuffer2#EncodeLut(78d956e6119bfa94).(&ptr, sortedQuantVec, m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version.)) |
| 2011 | return false; |
| 2012 | } |
| 2013 | else |
| 2014 | return false; |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | numBytesWritten = (int)(ptr - *ppByte); |
| 2019 | *ppByte = ptr; |
| 2020 | return true; |
| 2021 | } |
| 2022 | |
| 2023 | // -------------------------------------------------------------------------- ; |
| 2024 | |
| 2025 | template<class T> |
| 2026 | bool Lerc2cxx . . $ LercNS/Lerc2#::ReadTilecxx . . $ LercNS/Lerc2#ReadTile(e46b292ef6d163a3).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemainingInOut, T* data, int i0, int i1, int j0, int j1, int iDepth, |
| 2027 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int>& bufferVec) const |
| 2028 | { |
| 2029 | const Bytecxx . . $ LercNS/Byte#* ptr = *ppByte; |
| 2030 | size_t nBytesRemaining = nBytesRemainingInOut; |
| 2031 | |
| 2032 | if (nBytesRemaining < 1) |
| 2033 | return false; |
| 2034 | |
| 2035 | const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.; |
| 2036 | int nCols = hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; |
| 2037 | int nDepth = hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 2038 | |
| 2039 | Bytecxx . . $ LercNS/Byte# comprFlag = *ptr++; |
| 2040 | nBytesRemaining--; |
| 2041 | |
| 2042 | const bool bDiffEnc = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 5) ? (comprFlag & 4) : false; // bit 2 now encodes diff or delta encoding |
| 2043 | const int pattern = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 5) ? 14 : 15; |
| 2044 | |
| 2045 | if (((comprFlag >> 2) & pattern) != ((j0 >> 3) & pattern)) // use bits 2345 for integrity check |
| 2046 | return false; |
| 2047 | |
| 2048 | if (bDiffEnc && iDepth == 0) |
| 2049 | return false; |
| 2050 | |
| 2051 | int bits67 = comprFlag >> 6; |
| 2052 | comprFlag &= 3; |
| 2053 | |
| 2054 | if (comprFlag == 2) // entire tile is constant 0 (all the valid pixels) |
| 2055 | { |
| 2056 | for (int i = i0; i < i1; i++) |
| 2057 | { |
| 2058 | int k = i * nCols + j0; |
| 2059 | int m = k * nDepth + iDepth; |
| 2060 | |
| 2061 | for (int j = j0; j < j1; j++, k++, m += nDepth) |
| 2062 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2063 | data[m] = bDiffEnc ? data[m - 1] : 0; |
| 2064 | } |
| 2065 | |
| 2066 | *ppByte = ptr; |
| 2067 | nBytesRemainingInOut = nBytesRemaining; |
| 2068 | return true; |
| 2069 | } |
| 2070 | |
| 2071 | else if (comprFlag == 0) // read z's binary uncompressed |
| 2072 | { |
| 2073 | if (bDiffEnc) |
| 2074 | return false; // doesn't make sense, should not happen |
| 2075 | |
| 2076 | const T* srcPtr = (const T*)ptr; |
| 2077 | int cnt = 0; |
| 2078 | |
| 2079 | for (int i = i0; i < i1; i++) |
| 2080 | { |
| 2081 | int k = i * nCols + j0; |
| 2082 | int m = k * nDepth + iDepth; |
| 2083 | |
| 2084 | for (int j = j0; j < j1; j++, k++, m += nDepth) |
| 2085 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2086 | { |
| 2087 | if (nBytesRemaining < sizeof(T)) |
| 2088 | return false; |
| 2089 | |
| 2090 | data[m] = *srcPtr++; |
| 2091 | nBytesRemaining -= sizeof(T); |
| 2092 | |
| 2093 | cnt++; |
| 2094 | } |
| 2095 | } |
| 2096 | |
| 2097 | ptr += cnt * sizeof(T); |
| 2098 | } |
| 2099 | else |
| 2100 | { |
| 2101 | // read z's as int arr bit stuffed |
| 2102 | DataTypecxx . . $ LercNS/Lerc2#DataType# dtUsed = GetDataTypeUsedcxx . . $ LercNS/Lerc2#GetDataTypeUsed(8734f81ae2289f0e).((bDiffEnc && hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. < DT_Floatcxx . . $ LercNS/Lerc2#DT_Float.) ? DT_Intcxx . . $ LercNS/Lerc2#DT_Int. : hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt., bits67); |
| 2103 | if (dtUsed == DT_Undefinedcxx . . $ LercNS/Lerc2#DT_Undefined.) |
| 2104 | return false; |
| 2105 | size_t n = GetDataTypeSizecxx . . $ LercNS/Lerc2#GetDataTypeSize(3707fc1f19bbe2a2).(dtUsed); |
| 2106 | if (nBytesRemaining < n) |
| 2107 | return false; |
| 2108 | |
| 2109 | double offset = ReadVariableDataTypecxx . . $ LercNS/Lerc2#ReadVariableDataType(efb34eb88c208493).(&ptr, dtUsed); |
| 2110 | nBytesRemaining -= n; |
| 2111 | |
| 2112 | double zMax = (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 4 && nDepth > 1) ? m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).iDepth] : hd.zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax.; |
| 2113 | |
| 2114 | if (comprFlag == 3) // entire tile is constant zMin (all the valid pixels) |
| 2115 | { |
| 2116 | for (int i = i0; i < i1; i++) |
| 2117 | { |
| 2118 | int k = i * nCols + j0; |
| 2119 | int m = k * nDepth + iDepth; |
| 2120 | |
| 2121 | if (!bDiffEnc) |
| 2122 | { |
| 2123 | T val = (T)offset; |
| 2124 | for (int j = j0; j < j1; j++, k++, m += nDepth) |
| 2125 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2126 | data[m] = val; |
| 2127 | } |
| 2128 | else |
| 2129 | { |
| 2130 | for (int j = j0; j < j1; j++, k++, m += nDepth) |
| 2131 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2132 | { |
| 2133 | double z = offset +cxx . . $ std/operator+(2764d1739bf7913d). data[m - 1]; |
| 2134 | data[m] = (T)stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(z, zMax); |
| 2135 | } |
| 2136 | } |
| 2137 | } |
| 2138 | } |
| 2139 | else |
| 2140 | { |
| 2141 | size_t maxElementCount = size_t(i1 - i0) * (j1 - j0); |
| 2142 | if (!m_bitStuffer2cxx . . $ LercNS/Lerc2#m_bitStuffer2..Decodecxx . . $ LercNS/BitStuffer2#Decode(e9dc1ca41d64813e).(&ptr, nBytesRemaining, bufferVec, maxElementCount, hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version.)) |
| 2143 | return false; |
| 2144 | |
| 2145 | double invScale = 2 * hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError.; // for int types this is int |
| 2146 | const unsigned int* srcPtr = bufferVec.datacxx . . $ std/vector#data(258ee1c9e0a18a5c).(); |
| 2147 | |
| 2148 | if (bufferVec.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() == maxElementCount) // all valid |
| 2149 | { |
| 2150 | for (int i = i0; i < i1; i++) |
| 2151 | { |
| 2152 | int k = i * nCols + j0; |
| 2153 | int m = k * nDepth + iDepth; |
| 2154 | |
| 2155 | if (!bDiffEnc) |
| 2156 | { |
| 2157 | for (int j = j0; j < j1; j++, k++, m += nDepth) |
| 2158 | { |
| 2159 | double z = offset + *srcPtr++ * invScale; |
| 2160 | data[m] = (T)stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(z, zMax); // make sure we stay in the orig range |
| 2161 | } |
| 2162 | } |
| 2163 | else |
| 2164 | { |
| 2165 | for (int j = j0; j < j1; j++, k++, m += nDepth) |
| 2166 | { |
| 2167 | double z = offset + *srcPtr++ * invScale +cxx . . $ std/operator+(2764d1739bf7913d). data[m - 1]; |
| 2168 | data[m] = (T)stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(z, zMax); |
| 2169 | } |
| 2170 | } |
| 2171 | } |
| 2172 | } |
| 2173 | else // not all valid |
| 2174 | { |
| 2175 | if (hd.versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. > 2) |
| 2176 | { |
| 2177 | for (int i = i0; i < i1; i++) |
| 2178 | { |
| 2179 | int k = i * nCols + j0; |
| 2180 | int m = k * nDepth + iDepth; |
| 2181 | |
| 2182 | if (!bDiffEnc) |
| 2183 | { |
| 2184 | for (int j = j0; j < j1; j++, k++, m += nDepth) |
| 2185 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2186 | { |
| 2187 | double z = offset + *srcPtr++ * invScale; |
| 2188 | data[m] = (T)stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(z, zMax); // make sure we stay in the orig range |
| 2189 | } |
| 2190 | } |
| 2191 | else |
| 2192 | { |
| 2193 | for (int j = j0; j < j1; j++, k++, m += nDepth) |
| 2194 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2195 | { |
| 2196 | double z = offset + *srcPtr++ * invScale +cxx . . $ std/operator+(2764d1739bf7913d). data[m - 1]; |
| 2197 | data[m] = (T)stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(z, zMax); |
| 2198 | } |
| 2199 | } |
| 2200 | } |
| 2201 | } |
| 2202 | else // fail gracefully in case of corrupted blob for old version <= 2 which had no checksum |
| 2203 | { |
| 2204 | size_t bufferVecIdx = 0; |
| 2205 | |
| 2206 | for (int i = i0; i < i1; i++) |
| 2207 | { |
| 2208 | int k = i * nCols + j0; |
| 2209 | int m = k * nDepth + iDepth; |
| 2210 | |
| 2211 | for (int j = j0; j < j1; j++, k++, m += nDepth) |
| 2212 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2213 | { |
| 2214 | if (bufferVecIdx == bufferVec.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()) // fail gracefully in case of corrupted blob for old version <= 2 which had no checksum |
| 2215 | return false; |
| 2216 | |
| 2217 | double z = offset + bufferVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).bufferVecIdx] * invScale; |
| 2218 | bufferVecIdx++; |
| 2219 | data[m] = (T)stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(z, zMax); // make sure we stay in the orig range |
| 2220 | } |
| 2221 | } |
| 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | *ppByte = ptr; |
| 2228 | nBytesRemainingInOut = nBytesRemaining; |
| 2229 | return true; |
| 2230 | } |
| 2231 | |
| 2232 | // -------------------------------------------------------------------------- ; |
| 2233 | |
| 2234 | template<class T> |
| 2235 | Lerc2cxx . . $ LercNS/Lerc2#::DataTypecxx . . $ LercNS/Lerc2#DataType# Lerc2cxx . . $ LercNS/Lerc2#::GetDataTypecxx . . $ LercNS/Lerc2#GetDataType(36b83e793b7541af).(T z) |
| 2236 | { |
| 2237 | const stdcxx . . $ std/::type_info& ti = typeid(z); |
| 2238 | |
| 2239 | if (ti == typeid(signed char)) return DT_Charcxx . . $ LercNS/Lerc2#DT_Char.; |
| 2240 | else if (ti == typeid(Bytecxx . . $ LercNS/Byte#)) return DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte.; |
| 2241 | else if (ti == typeid(short)) return DT_Shortcxx . . $ LercNS/Lerc2#DT_Short.; |
| 2242 | else if (ti == typeid(unsigned short)) return DT_UShortcxx . . $ LercNS/Lerc2#DT_UShort.; |
| 2243 | else if (ti == typeid(int) && sizeof(int) == 4) return DT_Intcxx . . $ LercNS/Lerc2#DT_Int.; |
| 2244 | else if (ti == typeid(long) && sizeof(long) == 4) return DT_Intcxx . . $ LercNS/Lerc2#DT_Int.; |
| 2245 | else if (ti == typeid(unsigned int) && sizeof(unsigned int) == 4) return DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.; |
| 2246 | else if (ti == typeid(unsigned long) && sizeof(unsigned long) == 4) return DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.; |
| 2247 | else if (ti == typeid(float)) return DT_Floatcxx . . $ LercNS/Lerc2#DT_Float.; |
| 2248 | else if (ti == typeid(double)) return DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.; |
| 2249 | else |
| 2250 | return DT_Undefinedcxx . . $ LercNS/Lerc2#DT_Undefined.; |
| 2251 | } |
| 2252 | |
| 2253 | // -------------------------------------------------------------------------- ; |
| 2254 | |
| 2255 | void Lerc2cxx . . $ LercNS/Lerc2#::SortQuantArraycxx . . $ LercNS/Lerc2#SortQuantArray(3b8c1c1ca38f2c23).(const vectorcxx . . $ std/vector#<unsigned int>& quantVec, vectorcxx . . $ std/vector#<pair<unsigned int, unsigned int> >& sortedQuantVec) |
| 2256 | { |
| 2257 | int numElem = (int)quantVec.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 2258 | sortedQuantVec.resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(numElem); |
| 2259 | |
| 2260 | for (int i = 0; i < numElem; i++) |
| 2261 | sortedQuantVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] = pair<unsigned int, unsigned int>(quantVec[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i], i); |
| 2262 | |
| 2263 | stdcxx . . $ std/::sortcxx . . $ std/sort(4d3091562df4e52e).(sortedQuantVec.begincxx . . $ std/vector#begin(55a6de06420d4903).(), sortedQuantVec.endcxx . . $ std/vector#end(55a6de06420d4903).(), |
| 2264 | [](const pair<unsigned int, unsigned int>& p0, |
| 2265 | const pair<unsigned int, unsigned int>& p1) { return p0.first < p1.first; }); |
| 2266 | } |
| 2267 | |
| 2268 | // -------------------------------------------------------------------------- ; |
| 2269 | |
| 2270 | template<class T> |
| 2271 | void Lerc2cxx . . $ LercNS/Lerc2#::ComputeHuffmanCodescxx . . $ LercNS/Lerc2#ComputeHuffmanCodes(262ecf6b652a9a81).(const T* data, int& numBytes, ImageEncodeModecxx . . $ LercNS/Lerc2#ImageEncodeMode#& imageEncodeMode, stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::pair<unsigned short, unsigned int> >& codes) const |
| 2272 | { |
| 2273 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<int> histocxx . . $ std/vector#vector(49f6e7a06ebc5aa8)., deltaHistocxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 2274 | ComputeHistoForHuffmancxx . . $ LercNS/Lerc2#ComputeHistoForHuffman(1286356d30332779).(data, histo, deltaHisto); |
| 2275 | |
| 2276 | int nBytes0 = 0, nBytes1 = 0; |
| 2277 | double avgBpp0 = 0, avgBpp1 = 0; |
| 2278 | Huffmancxx . . $ LercNS/Huffman# huffman0cxx . . $ LercNS/Huffman#Huffman(49f6e7a06ebc5aa8)., huffman1cxx . . $ LercNS/Huffman#Huffman(49f6e7a06ebc5aa8).; |
| 2279 | |
| 2280 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 4) |
| 2281 | { |
| 2282 | if (!huffman0.ComputeCodescxx . . $ LercNS/Huffman#ComputeCodes(13834f6f38354517).(histo) || !huffman0.ComputeCompressedSizecxx . . $ LercNS/Huffman#ComputeCompressedSize(aaf3cc3253c7f648).(histo, nBytes0, avgBpp0)) |
| 2283 | nBytes0 = 0; |
| 2284 | } |
| 2285 | |
| 2286 | if (!huffman1.ComputeCodescxx . . $ LercNS/Huffman#ComputeCodes(13834f6f38354517).(deltaHisto) || !huffman1.ComputeCompressedSizecxx . . $ LercNS/Huffman#ComputeCompressedSize(aaf3cc3253c7f648).(deltaHisto, nBytes1, avgBpp1)) |
| 2287 | nBytes1 = 0; |
| 2288 | |
| 2289 | if (nBytes0 > 0 && nBytes1 > 0) // regular case, pick the better of the two |
| 2290 | { |
| 2291 | imageEncodeMode = (nBytes0 <= nBytes1) ? IEM_Huffmancxx . . $ LercNS/Lerc2#IEM_Huffman. : IEM_DeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaHuffman.; |
| 2292 | codes =cxx . . $ std/vector#`operator=`(e6b68e61becad66f). (nBytes0 <= nBytes1) ? huffman0.GetCodescxx . . $ LercNS/Huffman#GetCodes(b040d847b6c149f9).() : huffman1.GetCodescxx . . $ LercNS/Huffman#GetCodes(b040d847b6c149f9).(); |
| 2293 | numBytes = (stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).)(nBytes0, nBytes1); |
| 2294 | } |
| 2295 | else if (nBytes0 == 0 && nBytes1 == 0) // rare case huffman cannot handle, fall back to tiling |
| 2296 | { |
| 2297 | imageEncodeMode = IEM_Tilingcxx . . $ LercNS/Lerc2#IEM_Tiling.; |
| 2298 | codes.resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(0); |
| 2299 | numBytes = 0; |
| 2300 | } |
| 2301 | else // rare also, pick the valid one, the other is 0 |
| 2302 | { |
| 2303 | imageEncodeMode = (nBytes0 > nBytes1) ? IEM_Huffmancxx . . $ LercNS/Lerc2#IEM_Huffman. : IEM_DeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaHuffman.; |
| 2304 | codes =cxx . . $ std/vector#`operator=`(e6b68e61becad66f). (nBytes0 > nBytes1) ? huffman0.GetCodescxx . . $ LercNS/Huffman#GetCodes(b040d847b6c149f9).() : huffman1.GetCodescxx . . $ LercNS/Huffman#GetCodes(b040d847b6c149f9).(); |
| 2305 | numBytes = (stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).)(nBytes0, nBytes1); |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | // -------------------------------------------------------------------------- ; |
| 2310 | |
| 2311 | template<class T> |
| 2312 | void Lerc2cxx . . $ LercNS/Lerc2#::ComputeHistoForHuffmancxx . . $ LercNS/Lerc2#ComputeHistoForHuffman(1286356d30332779).(const T* data, stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& histo, stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& deltaHisto) const |
| 2313 | { |
| 2314 | histo.resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(256); |
| 2315 | deltaHisto.resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(256); |
| 2316 | |
| 2317 | memset(&histo[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], 0, histo.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() * sizeof(int)); |
| 2318 | memset(&deltaHisto[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).0], 0, deltaHisto.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() * sizeof(int)); |
| 2319 | |
| 2320 | int offset = (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Charcxx . . $ LercNS/Lerc2#DT_Char.) ? 128 : 0; |
| 2321 | int height = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; |
| 2322 | int width = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; |
| 2323 | int nDepth = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 2324 | |
| 2325 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. == width * height) // all valid |
| 2326 | { |
| 2327 | for (int iDepth = 0; iDepth < nDepth; iDepth++) |
| 2328 | { |
| 2329 | T prevVal = 0; |
| 2330 | for (int m = iDepth, i = 0; i < height; i++) |
| 2331 | for (int j = 0; j < width; j++, m += nDepth) |
| 2332 | { |
| 2333 | T val = data[m]; |
| 2334 | T delta = val; |
| 2335 | |
| 2336 | if (j > 0) |
| 2337 | delta -= prevVal; // use overflow |
| 2338 | else if (i > 0) |
| 2339 | delta -= data[m - width * nDepth]; |
| 2340 | else |
| 2341 | delta -= prevVal; |
| 2342 | |
| 2343 | prevVal = val; |
| 2344 | |
| 2345 | histo[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).offset + (int)val]++; |
| 2346 | deltaHisto[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).offset + (int)delta]++; |
| 2347 | } |
| 2348 | } |
| 2349 | } |
| 2350 | else // not all valid |
| 2351 | { |
| 2352 | for (int iDepth = 0; iDepth < nDepth; iDepth++) |
| 2353 | { |
| 2354 | T prevVal = 0; |
| 2355 | for (int k = 0, m = iDepth, i = 0; i < height; i++) |
| 2356 | for (int j = 0; j < width; j++, k++, m += nDepth) |
| 2357 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2358 | { |
| 2359 | T val = data[m]; |
| 2360 | T delta = val; |
| 2361 | |
| 2362 | if (j > 0 && m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k - 1)) |
| 2363 | { |
| 2364 | delta -= prevVal; // use overflow |
| 2365 | } |
| 2366 | else if (i > 0 && m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k - width)) |
| 2367 | { |
| 2368 | delta -= data[m - width * nDepth]; |
| 2369 | } |
| 2370 | else |
| 2371 | delta -= prevVal; |
| 2372 | |
| 2373 | prevVal = val; |
| 2374 | |
| 2375 | histo[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).offset + (int)val]++; |
| 2376 | deltaHisto[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).offset + (int)delta]++; |
| 2377 | } |
| 2378 | } |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | // -------------------------------------------------------------------------- ; |
| 2383 | |
| 2384 | template<class T> |
| 2385 | bool Lerc2cxx . . $ LercNS/Lerc2#::EncodeHuffmancxx . . $ LercNS/Lerc2#EncodeHuffman(cc83d641fe8bfa9b).(const T* data, Bytecxx . . $ LercNS/Byte#** ppByte) const |
| 2386 | { |
| 2387 | if (!data || !ppByte) |
| 2388 | return false; |
| 2389 | |
| 2390 | Huffmancxx . . $ LercNS/Huffman# huffmancxx . . $ LercNS/Huffman#Huffman(49f6e7a06ebc5aa8).; |
| 2391 | if (!huffman.SetCodescxx . . $ LercNS/Huffman#SetCodes(8994584b4c5a0cd).(m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes.) || !huffman.WriteCodeTablecxx . . $ LercNS/Huffman#WriteCodeTable(18073134a042c744).(ppByte, m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version.)) // header and code table |
| 2392 | return false; |
| 2393 | |
| 2394 | int offset = (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Charcxx . . $ LercNS/Lerc2#DT_Char.) ? 128 : 0; |
| 2395 | int height = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; |
| 2396 | int width = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; |
| 2397 | int nDepth = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 2398 | int bitPos = 0; |
| 2399 | |
| 2400 | if (m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_DeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaHuffman.) |
| 2401 | { |
| 2402 | for (int iDepth = 0; iDepth < nDepth; iDepth++) |
| 2403 | { |
| 2404 | T prevVal = 0; |
| 2405 | for (int k = 0, m = iDepth, i = 0; i < height; i++) |
| 2406 | for (int j = 0; j < width; j++, k++, m += nDepth) |
| 2407 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2408 | { |
| 2409 | T val = data[m]; |
| 2410 | T delta = val; |
| 2411 | |
| 2412 | if (j > 0 && m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k - 1)) |
| 2413 | { |
| 2414 | delta -= prevVal; // use overflow |
| 2415 | } |
| 2416 | else if (i > 0 && m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k - width)) |
| 2417 | { |
| 2418 | delta -= data[m - width * nDepth]; |
| 2419 | } |
| 2420 | else |
| 2421 | delta -= prevVal; |
| 2422 | |
| 2423 | prevVal = val; |
| 2424 | |
| 2425 | // bit stuff the huffman code for this delta |
| 2426 | int kBin = offset + (int)delta; |
| 2427 | int len = m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).kBin].first; |
| 2428 | if (len <= 0) |
| 2429 | return false; |
| 2430 | |
| 2431 | unsigned int code = m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).kBin].second; |
| 2432 | |
| 2433 | if (!Huffmancxx . . $ LercNS/Huffman#::PushValuecxx . . $ LercNS/Huffman#PushValue(a42e7bfdfc4e36d8).(ppByte, bitPos, code, len)) |
| 2434 | return false; |
| 2435 | } |
| 2436 | } |
| 2437 | } |
| 2438 | |
| 2439 | else if (m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_Huffmancxx . . $ LercNS/Lerc2#IEM_Huffman.) |
| 2440 | { |
| 2441 | for (int k = 0, m0 = 0, i = 0; i < height; i++) |
| 2442 | for (int j = 0; j < width; j++, k++, m0 += nDepth) |
| 2443 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2444 | for (int m = 0; m < nDepth; m++) |
| 2445 | { |
| 2446 | T val = data[m0 + m]; |
| 2447 | |
| 2448 | // bit stuff the huffman code for this val |
| 2449 | int kBin = offset + (int)val; |
| 2450 | int len = m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).kBin].first; |
| 2451 | if (len <= 0) |
| 2452 | return false; |
| 2453 | |
| 2454 | unsigned int code = m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).kBin].second; |
| 2455 | |
| 2456 | if (!Huffmancxx . . $ LercNS/Huffman#::PushValuecxx . . $ LercNS/Huffman#PushValue(a42e7bfdfc4e36d8).(ppByte, bitPos, code, len)) |
| 2457 | return false; |
| 2458 | } |
| 2459 | } |
| 2460 | |
| 2461 | else |
| 2462 | return false; |
| 2463 | |
| 2464 | size_t numUInts = (bitPos > 0 ? 1 : 0) + 1; // add one more as the decode LUT can read ahead |
| 2465 | *ppByte += numUInts * sizeof(unsigned int); |
| 2466 | |
| 2467 | return true; |
| 2468 | } |
| 2469 | |
| 2470 | // -------------------------------------------------------------------------- ; |
| 2471 | |
| 2472 | template<class T> |
| 2473 | bool Lerc2cxx . . $ LercNS/Lerc2#::DecodeHuffmancxx . . $ LercNS/Lerc2#DecodeHuffman(d8761aea236c93e).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemainingInOut, T* data) const |
| 2474 | { |
| 2475 | if (!data || !ppByte || !(*ppByte)) |
| 2476 | return false; |
| 2477 | |
| 2478 | Huffmancxx . . $ LercNS/Huffman# huffmancxx . . $ LercNS/Huffman#Huffman(49f6e7a06ebc5aa8).; |
| 2479 | if (!huffman.ReadCodeTablecxx . . $ LercNS/Huffman#ReadCodeTable(93c08913fdc74d09).(ppByte, nBytesRemainingInOut, m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..versioncxx . . $ LercNS/Lerc2#HeaderInfo#version.)) // header and code table |
| 2480 | return false; |
| 2481 | |
| 2482 | int numBitsLUT = 0; |
| 2483 | if (!huffman.BuildTreeFromCodescxx . . $ LercNS/Huffman#BuildTreeFromCodes(30ce46cb091eb21e).(numBitsLUT)) |
| 2484 | return false; |
| 2485 | |
| 2486 | int offset = (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Charcxx . . $ LercNS/Lerc2#DT_Char.) ? 128 : 0; |
| 2487 | int height = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; |
| 2488 | int width = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; |
| 2489 | int nDepth = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 2490 | |
| 2491 | const Bytecxx . . $ LercNS/Byte#* ptr0 = *ppByte; |
| 2492 | const Bytecxx . . $ LercNS/Byte#* ptr = ptr0; |
| 2493 | |
| 2494 | int bitPos = 0; |
| 2495 | size_t nBytesRemaining = nBytesRemainingInOut; |
| 2496 | |
| 2497 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel. == width * height) // all valid |
| 2498 | { |
| 2499 | if (m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_DeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaHuffman.) |
| 2500 | { |
| 2501 | for (int iDepth = 0; iDepth < nDepth; iDepth++) |
| 2502 | { |
| 2503 | T prevVal = 0; |
| 2504 | for (int m = iDepth, i = 0; i < height; i++) |
| 2505 | for (int j = 0; j < width; j++, m += nDepth) |
| 2506 | { |
| 2507 | int val = 0; |
| 2508 | if (!huffman.DecodeOneValuecxx . . $ LercNS/Huffman#DecodeOneValue(6cf2a5655d1a64b2).(&ptr, nBytesRemaining, bitPos, numBitsLUT, val)) |
| 2509 | return false; |
| 2510 | |
| 2511 | T delta = (T)(val - offset); |
| 2512 | |
| 2513 | if (j > 0) |
| 2514 | delta += prevVal; // use overflow |
| 2515 | else if (i > 0) |
| 2516 | delta += data[m - width * nDepth]; |
| 2517 | else |
| 2518 | delta += prevVal; |
| 2519 | |
| 2520 | data[m] = delta; |
| 2521 | prevVal = delta; |
| 2522 | } |
| 2523 | } |
| 2524 | } |
| 2525 | |
| 2526 | else if (m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_Huffmancxx . . $ LercNS/Lerc2#IEM_Huffman.) |
| 2527 | { |
| 2528 | for (int k = 0, m0 = 0, i = 0; i < height; i++) |
| 2529 | for (int j = 0; j < width; j++, k++, m0 += nDepth) |
| 2530 | for (int m = 0; m < nDepth; m++) |
| 2531 | { |
| 2532 | int val = 0; |
| 2533 | if (!huffman.DecodeOneValuecxx . . $ LercNS/Huffman#DecodeOneValue(6cf2a5655d1a64b2).(&ptr, nBytesRemaining, bitPos, numBitsLUT, val)) |
| 2534 | return false; |
| 2535 | |
| 2536 | data[m0 + m] = (T)(val - offset); |
| 2537 | } |
| 2538 | } |
| 2539 | |
| 2540 | else |
| 2541 | return false; |
| 2542 | } |
| 2543 | |
| 2544 | else // not all valid |
| 2545 | { |
| 2546 | if (m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_DeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaHuffman.) |
| 2547 | { |
| 2548 | for (int iDepth = 0; iDepth < nDepth; iDepth++) |
| 2549 | { |
| 2550 | T prevVal = 0; |
| 2551 | for (int k = 0, m = iDepth, i = 0; i < height; i++) |
| 2552 | for (int j = 0; j < width; j++, k++, m += nDepth) |
| 2553 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2554 | { |
| 2555 | int val = 0; |
| 2556 | if (!huffman.DecodeOneValuecxx . . $ LercNS/Huffman#DecodeOneValue(6cf2a5655d1a64b2).(&ptr, nBytesRemaining, bitPos, numBitsLUT, val)) |
| 2557 | return false; |
| 2558 | |
| 2559 | T delta = (T)(val - offset); |
| 2560 | |
| 2561 | if (j > 0 && m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k - 1)) |
| 2562 | { |
| 2563 | delta += prevVal; // use overflow |
| 2564 | } |
| 2565 | else if (i > 0 && m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k - width)) |
| 2566 | { |
| 2567 | delta += data[m - width * nDepth]; |
| 2568 | } |
| 2569 | else |
| 2570 | delta += prevVal; |
| 2571 | |
| 2572 | data[m] = delta; |
| 2573 | prevVal = delta; |
| 2574 | } |
| 2575 | } |
| 2576 | } |
| 2577 | |
| 2578 | else if (m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode. == IEM_Huffmancxx . . $ LercNS/Lerc2#IEM_Huffman.) |
| 2579 | { |
| 2580 | for (int k = 0, m0 = 0, i = 0; i < height; i++) |
| 2581 | for (int j = 0; j < width; j++, k++, m0 += nDepth) |
| 2582 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2583 | for (int m = 0; m < nDepth; m++) |
| 2584 | { |
| 2585 | int val = 0; |
| 2586 | if (!huffman.DecodeOneValuecxx . . $ LercNS/Huffman#DecodeOneValue(6cf2a5655d1a64b2).(&ptr, nBytesRemaining, bitPos, numBitsLUT, val)) |
| 2587 | return false; |
| 2588 | |
| 2589 | data[m0 + m] = (T)(val - offset); |
| 2590 | } |
| 2591 | } |
| 2592 | |
| 2593 | else |
| 2594 | return false; |
| 2595 | } |
| 2596 | |
| 2597 | size_t numUInts = (bitPos > 0 ? 1 : 0) + 1; // add one more as the decode LUT can read ahead |
| 2598 | size_t len = (ptr - ptr0) + numUInts * sizeof(unsigned int); |
| 2599 | |
| 2600 | if (nBytesRemainingInOut < len) |
| 2601 | return false; |
| 2602 | |
| 2603 | *ppByte += len; |
| 2604 | nBytesRemainingInOut -= len; |
| 2605 | return true; |
| 2606 | } |
| 2607 | |
| 2608 | // -------------------------------------------------------------------------- ; |
| 2609 | |
| 2610 | template<class T> |
| 2611 | bool Lerc2cxx . . $ LercNS/Lerc2#::WriteMinMaxRangescxx . . $ LercNS/Lerc2#WriteMinMaxRanges(cc83d641fe8bfa9b).(const T*, Bytecxx . . $ LercNS/Byte#** ppByte) const |
| 2612 | { |
| 2613 | if (!ppByte || !(*ppByte)) |
| 2614 | return false; |
| 2615 | |
| 2616 | //printf("write min / max = %f %f\n", m_zMinVec[0], m_zMaxVec[0]); |
| 2617 | |
| 2618 | int nDepth = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 2619 | if (/* nDepth < 2 || */ (int)m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() != nDepth || (int)m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() != nDepth) |
| 2620 | return false; |
| 2621 | |
| 2622 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<T> zVec(nDepth); |
| 2623 | size_t len = nDepth * sizeof(T); |
| 2624 | |
| 2625 | for (int i = 0; i < nDepth; i++) |
| 2626 | zVec[i] = (T)m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i]; |
| 2627 | |
| 2628 | memcpy(*ppByte, &zVec[0], len); |
| 2629 | (*ppByte) += len; |
| 2630 | |
| 2631 | for (int i = 0; i < nDepth; i++) |
| 2632 | zVec[i] = (T)m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i]; |
| 2633 | |
| 2634 | memcpy(*ppByte, &zVec[0], len); |
| 2635 | (*ppByte) += len; |
| 2636 | |
| 2637 | return true; |
| 2638 | } |
| 2639 | |
| 2640 | // -------------------------------------------------------------------------- ; |
| 2641 | |
| 2642 | template<class T> |
| 2643 | bool Lerc2cxx . . $ LercNS/Lerc2#::ReadMinMaxRangescxx . . $ LercNS/Lerc2#ReadMinMaxRanges(823b49aaa8f6c8db).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining, const T* /*data*/) |
| 2644 | { |
| 2645 | if (!ppByte || !(*ppByte)) |
| 2646 | return false; |
| 2647 | |
| 2648 | int nDepth = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 2649 | |
| 2650 | m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(nDepth); |
| 2651 | m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec..resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(nDepth); |
| 2652 | |
| 2653 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<T> zVec(nDepth); |
| 2654 | size_t len = nDepth * sizeof(T); |
| 2655 | |
| 2656 | if (nBytesRemaining < len || !memcpy(&zVec[0], *ppByte, len)) |
| 2657 | return false; |
| 2658 | |
| 2659 | (*ppByte) += len; |
| 2660 | nBytesRemaining -= len; |
| 2661 | |
| 2662 | for (int i = 0; i < nDepth; i++) |
| 2663 | m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] = zVec[i]; |
| 2664 | |
| 2665 | if (nBytesRemaining < len || !memcpy(&zVec[0], *ppByte, len)) |
| 2666 | return false; |
| 2667 | |
| 2668 | (*ppByte) += len; |
| 2669 | nBytesRemaining -= len; |
| 2670 | |
| 2671 | for (int i = 0; i < nDepth; i++) |
| 2672 | m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] = zVec[i]; |
| 2673 | |
| 2674 | //printf("read min / max = %f %f\n", m_zMinVec[0], m_zMaxVec[0]); |
| 2675 | |
| 2676 | return true; |
| 2677 | } |
| 2678 | |
| 2679 | // -------------------------------------------------------------------------- ; |
| 2680 | |
| 2681 | template<class T> |
| 2682 | bool Lerc2cxx . . $ LercNS/Lerc2#::FillConstImagecxx . . $ LercNS/Lerc2#FillConstImage(688a48c7bc3386d6).(T* data) const |
| 2683 | { |
| 2684 | if (!data) |
| 2685 | return false; |
| 2686 | |
| 2687 | const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.; |
| 2688 | int nCols = hd.nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols.; |
| 2689 | int nRows = hd.nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows.; |
| 2690 | int nDepth = hd.nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 2691 | T z0 = (T)hd.zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin.; |
| 2692 | |
| 2693 | if (nDepth == 1) |
| 2694 | { |
| 2695 | for (int k = 0, i = 0; i < nRows; i++) |
| 2696 | for (int j = 0; j < nCols; j++, k++) |
| 2697 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2698 | data[k] = z0; |
| 2699 | } |
| 2700 | else |
| 2701 | { |
| 2702 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<T> zBufVec(nDepth, z0); |
| 2703 | |
| 2704 | if (hd.zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin. != hd.zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax.) |
| 2705 | { |
| 2706 | if ((int)m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).() != nDepth) |
| 2707 | return false; |
| 2708 | |
| 2709 | for (int m = 0; m < nDepth; m++) |
| 2710 | zBufVec[m] = (T)m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).m]; |
| 2711 | } |
| 2712 | |
| 2713 | int len = nDepth * sizeof(T); |
| 2714 | for (int k = 0, m = 0, i = 0; i < nRows; i++) |
| 2715 | for (int j = 0; j < nCols; j++, k++, m += nDepth) |
| 2716 | if (m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask..IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 2717 | memcpy(&data[m], &zBufVec[0], len); |
| 2718 | } |
| 2719 | |
| 2720 | return true; |
| 2721 | } |
| 2722 | |
| 2723 | // -------------------------------------------------------------------------- ; |
| 2724 |