| 1 | /* |
| 2 | Copyright 2015 - 2026 Esri |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | |
| 16 | A local copy of the license and additional notices are located with the |
| 17 | source distribution at: |
| 18 | |
| 19 | http://github.com/Esri/lerc/ |
| 20 | |
| 21 | Contributors: Thomas Maurer |
| 22 | */ |
| 23 | |
| 24 | #ifndef LERC2_H |
| 25 | #define LERC2_Hcxx . . $ `src/LercLib/Lerc2.h:25:9`! |
| 26 | |
| 27 | #include <cfloat> |
| 28 | #include <cmath> |
| 29 | #include <climits> |
| 30 | #include <algorithm> |
| 31 | #include <string> |
| 32 | #include "BitMask.h"cxx . . $ `<file>/src/LercLib/BitMask.h`/ |
| 33 | #include "BitStuffer2.h"cxx . . $ `<file>/src/LercLib/BitStuffer2.h`/ |
| 34 | #include "fpl_Lerc2Ext.h"cxx . . $ `<file>/src/LercLib/fpl_Lerc2Ext.h`/ |
| 35 | |
| 36 | NAMESPACE_LERC_STARTcxx . . $ `src/LercLib/Defines.h:35:9`! |
| 37 | |
| 38 | /** Lerc2 v1 |
| 39 | * |
| 40 | * -- allow for lossless compression of all common data types |
| 41 | * -- avoid data type conversions and copies |
| 42 | * -- optimized compression for segmented rasters (10-15x lossless) |
| 43 | * -- micro block is 8x8 fixed, only gets doubled to 16x16 if bit rate < 1 bpp |
| 44 | * -- cnt is replaced by bit mask |
| 45 | * -- Lerc blob header has data range [min, max] |
| 46 | * -- harden consistency checks to detect if the byte blob has been tampered with |
| 47 | * -- drop support for big endian, this is legacy now |
| 48 | * |
| 49 | * Lerc2 v2 |
| 50 | * |
| 51 | * -- add Huffman coding for better lossless compression of 8 bit data types Char, Byte |
| 52 | * |
| 53 | * Lerc2 v3 |
| 54 | * |
| 55 | * -- add checksum for the entire byte blob, for more rigorous detection of compressed data corruption |
| 56 | * -- for the main bit stuffing routine, use an extra uint buffer for guaranteed memory alignment |
| 57 | * -- this also allows to drop the NumExtraBytesToAllocate functions |
| 58 | * |
| 59 | * Lerc2 v4 |
| 60 | * |
| 61 | * -- allow array per pixel, nDepth values per pixel. Such as RGB, complex number, or larger arrays per pixel |
| 62 | * -- extend Huffman coding for 8 bit data types from delta only to trying both delta and orig |
| 63 | * -- for integer data types, allow to drop bit planes containing only random noise |
| 64 | * |
| 65 | * Lerc2 v5 |
| 66 | * -- for float data (as it might be lower precision like %.2f), try raise maxZError if possible w/o extra loss |
| 67 | * -- add delta encoding of a block iDepth relative to previous block (iDepth - 1) |
| 68 | * |
| 69 | */ |
| 70 | |
| 71 | class Lerc2cxx . . $ LercNS/Lerc2# |
| 72 | { |
| 73 | public: |
| 74 | Lerc2cxx . . $ LercNS/Lerc2#Lerc2(49f6e7a06ebc5aa8).(); |
| 75 | Lerc2cxx . . $ LercNS/Lerc2#Lerc2(fe02dd8c5b4270ed).(int nDepth, int nCols, int nRows, const Bytecxx . . $ LercNS/Byte#* pMaskBits = nullptr); // valid / invalid bits as byte array |
| 76 | ~cxx . . $ LercNS/Lerc2#`~Lerc2`(ced63f7c635d850d).Lerc2cxx . . $ LercNS/Lerc2#() {} |
| 77 | |
| 78 | static int CurrentVersioncxx . . $ LercNS/Lerc2#CurrentVersion(b126dc7c1de90089).() { return 6; } |
| 79 | |
| 80 | bool SetEncoderToOldVersioncxx . . $ LercNS/Lerc2#SetEncoderToOldVersion(83c267b20bac841a).(int version); // call this to encode compatible to an old decoder |
| 81 | |
| 82 | bool Setcxx . . $ LercNS/Lerc2#Set(2c716c8d5f4e4280).(int nDepth, int nCols, int nRows, const Bytecxx . . $ LercNS/Byte#* pMaskBits = nullptr); // set mask and dimensions |
| 83 | |
| 84 | // v6 |
| 85 | bool SetNoDataValuescxx . . $ LercNS/Lerc2#SetNoDataValues(33f2d77f1c62171e).(bool bNeedsNoDataVal, double noDataVal, double noDataValOrig); |
| 86 | bool SetNumBlobsMoreToComecxx . . $ LercNS/Lerc2#SetNumBlobsMoreToCome(83c267b20bac841a).(int nBlobsMore); // for safer decode of multi-band blobs |
| 87 | bool SetIsAllIntcxx . . $ LercNS/Lerc2#SetIsAllInt(efaadfb7dc14930a).(bool bIsAllInt); |
| 88 | |
| 89 | bool SetMinMaxcxx . . $ LercNS/Lerc2#SetMinMax(9f72e67440d8b329).(int nDepth, double minVal, double maxVal); // set min / max but only for nDepth = 1 |
| 90 | void ClearMinMaxcxx . . $ LercNS/Lerc2#ClearMinMax(49f6e7a06ebc5aa8).(); |
| 91 | |
| 92 | template<class T> |
| 93 | unsigned int ComputeNumBytesNeededToWritecxx . . $ LercNS/Lerc2#ComputeNumBytesNeededToWrite(30bb643c04a8fd76).(const T* arr, double maxZError, bool encodeMask); |
| 94 | |
| 95 | /// dst buffer already allocated; byte ptr is moved like a file pointer |
| 96 | template<class T> |
| 97 | bool Encodecxx . . $ LercNS/Lerc2#Encode(9add4431f33ebb71).(const T* arr, Bytecxx . . $ LercNS/Byte#** ppByte); |
| 98 | |
| 99 | // data types supported by Lerc2 |
| 100 | enum DataTypecxx . . $ LercNS/Lerc2#DataType# {DT_Charcxx . . $ LercNS/Lerc2#DT_Char. = 0, DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte., DT_Shortcxx . . $ LercNS/Lerc2#DT_Short., DT_UShortcxx . . $ LercNS/Lerc2#DT_UShort., DT_Intcxx . . $ LercNS/Lerc2#DT_Int., DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt., DT_Floatcxx . . $ LercNS/Lerc2#DT_Float., DT_Doublecxx . . $ LercNS/Lerc2#DT_Double., DT_Undefinedcxx . . $ LercNS/Lerc2#DT_Undefined.}; |
| 101 | |
| 102 | struct HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo# |
| 103 | { |
| 104 | int versioncxx . . $ LercNS/Lerc2#HeaderInfo#version.; |
| 105 | unsigned int checksumcxx . . $ LercNS/Lerc2#HeaderInfo#checksum.; |
| 106 | int nRowscxx . . $ LercNS/Lerc2#HeaderInfo#nRows., |
| 107 | nColscxx . . $ LercNS/Lerc2#HeaderInfo#nCols., |
| 108 | nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth., |
| 109 | numValidPixelcxx . . $ LercNS/Lerc2#HeaderInfo#numValidPixel., |
| 110 | microBlockSizecxx . . $ LercNS/Lerc2#HeaderInfo#microBlockSize., |
| 111 | blobSizecxx . . $ LercNS/Lerc2#HeaderInfo#blobSize., |
| 112 | nBlobsMorecxx . . $ LercNS/Lerc2#HeaderInfo#nBlobsMore.; // for multi-band Lerc blob, how many more blobs or bands appended to this one |
| 113 | |
| 114 | Bytecxx . . $ LercNS/Byte# bPassNoDataValuescxx . . $ LercNS/Lerc2#HeaderInfo#bPassNoDataValues., // 1 - pass noData values to decoder, 0 - don't pass, ignore |
| 115 | bIsIntcxx . . $ LercNS/Lerc2#HeaderInfo#bIsInt., // 1 - float or double data is all integer numbers, 0 - not |
| 116 | bReserved3cxx . . $ LercNS/Lerc2#HeaderInfo#bReserved3., |
| 117 | bReserved4cxx . . $ LercNS/Lerc2#HeaderInfo#bReserved4.; |
| 118 | |
| 119 | DataTypecxx . . $ LercNS/Lerc2#DataType# dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt.; |
| 120 | |
| 121 | double maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError., |
| 122 | zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin., // if nDepth > 1, this is the overall range |
| 123 | zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax., |
| 124 | noDataValcxx . . $ LercNS/Lerc2#HeaderInfo#noDataVal., // temp noData value used for nDepth > 1 if bit mask cannot cover it |
| 125 | noDataValOrigcxx . . $ LercNS/Lerc2#HeaderInfo#noDataValOrig.; // orig noData value to map to in decode |
| 126 | |
| 127 | void RawInitcxx . . $ LercNS/Lerc2#HeaderInfo#RawInit(49f6e7a06ebc5aa8).() { memset(this, 0, sizeof(struct HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#)); } |
| 128 | |
| 129 | bool TryHuffmanIntcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanInt(50ce9a9e25b4a850).() const { return (versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 2) && (dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte. || dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Charcxx . . $ LercNS/Lerc2#DT_Char.) && (maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. == 0.5); } |
| 130 | bool TryHuffmanFltcxx . . $ LercNS/Lerc2#HeaderInfo#TryHuffmanFlt(50ce9a9e25b4a850).() const { return (versioncxx . . $ LercNS/Lerc2#HeaderInfo#version. >= 6) && (dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Floatcxx . . $ LercNS/Lerc2#DT_Float. || dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.) && (maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. == 0); } |
| 131 | }; |
| 132 | |
| 133 | static bool GetHeaderInfocxx . . $ LercNS/Lerc2#GetHeaderInfo(5bafa162245ba3da).(const Bytecxx . . $ LercNS/Byte#* pByte, size_t nBytesRemaining, struct HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& headerInfo, bool& bHasMask); |
| 134 | |
| 135 | bool GetRangescxx . . $ LercNS/Lerc2#GetRanges(bfe330d8d1b8c5bf).(const Bytecxx . . $ LercNS/Byte#* pByte, size_t nBytesRemaining, double* pMins, double* pMaxs); |
| 136 | |
| 137 | /// dst buffer already allocated; byte ptr is moved like a file pointer |
| 138 | template<class T> |
| 139 | bool Decodecxx . . $ LercNS/Lerc2#Decode(1e98a814b12037d0).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining, T* arr, Bytecxx . . $ LercNS/Byte#* pMaskBits = nullptr); // if mask ptr is not 0, mask bits are returned (even if all valid or same as previous) |
| 140 | |
| 141 | private: |
| 142 | |
| 143 | enum ImageEncodeModecxx . . $ LercNS/Lerc2#ImageEncodeMode# { IEM_Tilingcxx . . $ LercNS/Lerc2#IEM_Tiling. = 0, IEM_DeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaHuffman., IEM_Huffmancxx . . $ LercNS/Lerc2#IEM_Huffman., IEM_DeltaDeltaHuffmancxx . . $ LercNS/Lerc2#IEM_DeltaDeltaHuffman. }; |
| 144 | enum BlockEncodeModecxx . . $ LercNS/Lerc2#BlockEncodeMode# { BEM_RawBinarycxx . . $ LercNS/Lerc2#BEM_RawBinary. = 0, BEM_BitStuffSimplecxx . . $ LercNS/Lerc2#BEM_BitStuffSimple., BEM_BitStuffLUTcxx . . $ LercNS/Lerc2#BEM_BitStuffLUT. }; |
| 145 | |
| 146 | int m_microBlockSizecxx . . $ LercNS/Lerc2#m_microBlockSize., |
| 147 | m_maxValToQuantizecxx . . $ LercNS/Lerc2#m_maxValToQuantize.; |
| 148 | BitMaskcxx . . $ LercNS/BitMask# m_bitMaskcxx . . $ LercNS/Lerc2#m_bitMask.; |
| 149 | HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo# m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo.; |
| 150 | BitStuffer2cxx . . $ LercNS/BitStuffer2# m_bitStuffer2cxx . . $ LercNS/Lerc2#m_bitStuffer2.; |
| 151 | bool m_encodeMaskcxx . . $ LercNS/Lerc2#m_encodeMask., |
| 152 | m_writeDataOneSweepcxx . . $ LercNS/Lerc2#m_writeDataOneSweep., |
| 153 | m_minMaxSetcxx . . $ LercNS/Lerc2#m_minMaxSet.; |
| 154 | ImageEncodeModecxx . . $ LercNS/Lerc2#ImageEncodeMode# m_imageEncodeModecxx . . $ LercNS/Lerc2#m_imageEncodeMode.; |
| 155 | |
| 156 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<double> m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec., m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec.; |
| 157 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<unsigned short, unsigned int> > m_huffmanCodescxx . . $ LercNS/Lerc2#m_huffmanCodes.; // <= 256 codes, 1.5 kB |
| 158 | |
| 159 | LosslessFPCompressioncxx . . $ LercNS/LosslessFPCompression# m_lfpccxx . . $ LercNS/Lerc2#m_lfpc.; |
| 160 | |
| 161 | private: |
| 162 | static stdcxx . . $ std/::stringcxx . . $ std/string# FileKeycxx . . $ LercNS/Lerc2#FileKey(efd28698952f529a).() { return "Lerc2 "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; } |
| 163 | static bool IsLittleEndianSystemcxx . . $ LercNS/Lerc2#IsLittleEndianSystem(c9857a73d68e59ba).() { int n = 1; return (1 == *((Bytecxx . . $ LercNS/Byte#*)&n)) && (4 == sizeof(int)); } |
| 164 | void Initcxx . . $ LercNS/Lerc2#Init(49f6e7a06ebc5aa8).(); |
| 165 | |
| 166 | static unsigned int ComputeNumBytesHeaderToWritecxx . . $ LercNS/Lerc2#ComputeNumBytesHeaderToWrite(c71a4331653d1346).(const struct HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd); |
| 167 | static bool WriteHeadercxx . . $ LercNS/Lerc2#WriteHeader(a9c1fa508da30057).(Bytecxx . . $ LercNS/Byte#** ppByte, const struct HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd); |
| 168 | static bool ReadHeadercxx . . $ LercNS/Lerc2#ReadHeader(33258b37336fa9a0).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining, struct HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd); |
| 169 | |
| 170 | bool WriteMaskcxx . . $ LercNS/Lerc2#WriteMask(2c1b2a8bb0754e17).(Bytecxx . . $ LercNS/Byte#** ppByte) const; |
| 171 | bool ReadMaskcxx . . $ LercNS/Lerc2#ReadMask(79d815e0e9c169c7).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining); |
| 172 | |
| 173 | bool DoChecksOnEncodecxx . . $ LercNS/Lerc2#DoChecksOnEncode(8a03234bfcce5350).(Bytecxx . . $ LercNS/Byte#* pBlobBegin, Bytecxx . . $ LercNS/Byte#* pBlobEnd) const; |
| 174 | static unsigned int ComputeChecksumFletcher32cxx . . $ LercNS/Lerc2#ComputeChecksumFletcher32(f38ae389a4b85ca).(const Bytecxx . . $ LercNS/Byte#* pByte, int len); |
| 175 | |
| 176 | static void AddUIntToCountscxx . . $ LercNS/Lerc2#AddUIntToCounts(a4fdc77d1ddcd2d8).(int* pCounts, unsigned int val, int nBits); |
| 177 | static void AddIntToCountscxx . . $ LercNS/Lerc2#AddIntToCounts(5f3888e91f92d472).(int* pCounts, int val, int nBits); |
| 178 | |
| 179 | template<class T> |
| 180 | bool TryBitPlaneCompressioncxx . . $ LercNS/Lerc2#TryBitPlaneCompression(fcbe6167061550ea).(const T* data, double eps, double& newMaxZError) const; |
| 181 | |
| 182 | template<class T> |
| 183 | bool TryRaiseMaxZErrorcxx . . $ LercNS/Lerc2#TryRaiseMaxZError(b6fd15fa3aacb116).(const T* data, double& maxZError) const; |
| 184 | |
| 185 | static bool PruneCandidatescxx . . $ LercNS/Lerc2#PruneCandidates(5c611f0afd62edd0).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<double>& roundErr, stdcxx . . $ std/::vectorcxx . . $ std/vector#<double>& zErr, |
| 186 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& zFac, double maxZError); |
| 187 | |
| 188 | template<class T> |
| 189 | bool WriteDataOneSweepcxx . . $ LercNS/Lerc2#WriteDataOneSweep(cc83d641fe8bfa9b).(const T* data, Bytecxx . . $ LercNS/Byte#** ppByte) const; |
| 190 | |
| 191 | template<class T> |
| 192 | bool ReadDataOneSweepcxx . . $ LercNS/Lerc2#ReadDataOneSweep(d8761aea236c93e).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining, T* data) const; |
| 193 | |
| 194 | template<class T> |
| 195 | bool ComputeMinMaxRangescxx . . $ LercNS/Lerc2#ComputeMinMaxRanges(ac2d38011843179f).(const T* data, stdcxx . . $ std/::vectorcxx . . $ std/vector#<double>& zMinVec, stdcxx . . $ std/::vectorcxx . . $ std/vector#<double>& zMaxVec) const; |
| 196 | |
| 197 | template<class T> |
| 198 | bool WriteTilescxx . . $ LercNS/Lerc2#WriteTiles(b7537629c01bf85b).(const T* data, Bytecxx . . $ LercNS/Byte#** ppByte, int& numBytes) const; |
| 199 | |
| 200 | template<class T> |
| 201 | bool ReadTilescxx . . $ LercNS/Lerc2#ReadTiles(d8761aea236c93e).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining, T* data) const; |
| 202 | |
| 203 | template<class T> |
| 204 | bool GetValidDataAndStatscxx . . $ LercNS/Lerc2#GetValidDataAndStats(8703c438c2986eac).(const T* data, int i0, int i1, int j0, int j1, int iDepth, |
| 205 | T* dataBuf, T& zMin, T& zMax, int& numValidPixel, bool& tryLut) const; |
| 206 | |
| 207 | template<class T> |
| 208 | static bool ComputeDiffSliceIntcxx . . $ LercNS/Lerc2#ComputeDiffSliceInt(eab4b4994b480060).(const T* data, const T* prevData, int numValidPixel, bool bCheckForIntOverflow, |
| 209 | double maxZError, stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& diffDataVec, int& zMin, int& zMax, bool& tryLut); |
| 210 | |
| 211 | template<class T> |
| 212 | static bool ComputeDiffSliceFltcxx . . $ LercNS/Lerc2#ComputeDiffSliceFlt(97f9455deea0d2f9).(const T* data, const T* prevData, int numValidPixel, bool bCheckForFltRndErr, |
| 213 | double maxZError, stdcxx . . $ std/::vectorcxx . . $ std/vector#<T>& diffDataVec, T& zMin, T& zMax, bool& tryLut); |
| 214 | |
| 215 | static bool NeedToCheckForIntOverflowcxx . . $ LercNS/Lerc2#NeedToCheckForIntOverflow(bf20af955ee05b5d).(const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd); |
| 216 | static bool NeedToCheckForFltRndErrcxx . . $ LercNS/Lerc2#NeedToCheckForFltRndErr(bf20af955ee05b5d).(const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd); |
| 217 | |
| 218 | static double ComputeMaxValcxx . . $ LercNS/Lerc2#ComputeMaxVal(7678bba071383ab).(double zMin, double zMax, double maxZError); |
| 219 | |
| 220 | template<class T> |
| 221 | bool NeedToQuantizecxx . . $ LercNS/Lerc2#NeedToQuantize(2999a0978c8d2873).(int numValidPixel, T zMin, T zMax) const; |
| 222 | |
| 223 | template<class T> |
| 224 | void Quantizecxx . . $ LercNS/Lerc2#Quantize(e1565945717ed8ab).(const T* dataBuf, int num, T zMin, stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int>& quantVec) const; |
| 225 | |
| 226 | template<class T> |
| 227 | static void ScaleBackcxx . . $ LercNS/Lerc2#ScaleBack(89d102402d680757).(T* dataBuf, const stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int>& quantVec, |
| 228 | double zMin, bool bDiff, bool bClamp, double zMaxClamp, double maxZError); |
| 229 | |
| 230 | template<class T> |
| 231 | static void ScaleBackConstBlockcxx . . $ LercNS/Lerc2#ScaleBackConstBlock(774e296019d19ac7).(T* dataBuf, int num, double zMin, bool bClamp, double zMaxClamp); |
| 232 | |
| 233 | template<class T> |
| 234 | int NumBytesTilecxx . . $ LercNS/Lerc2#NumBytesTile(2ecbd70ef45e66ca).(int numValidPixel, T zMin, T zMax, DataTypecxx . . $ LercNS/Lerc2#DataType# dtZ, bool tryLut, BlockEncodeModecxx . . $ LercNS/Lerc2#BlockEncodeMode#& blockEncodeMode, |
| 235 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<unsigned int, unsigned int> >& sortedQuantVec) const; |
| 236 | |
| 237 | template<class T> |
| 238 | bool WriteTilecxx . . $ LercNS/Lerc2#WriteTile(a3208ab338cab164).(const T* dataBuf, int num, Bytecxx . . $ LercNS/Byte#** ppByte, int& numBytesWritten, int j0, T zMin, T zMax, |
| 239 | DataTypecxx . . $ LercNS/Lerc2#DataType# dtZ, bool bDiffEnc, const stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int>& quantVec, BlockEncodeModecxx . . $ LercNS/Lerc2#BlockEncodeMode# blockEncodeMode, |
| 240 | const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<unsigned int, unsigned int> >& sortedQuantVec) const; |
| 241 | |
| 242 | template<class T> |
| 243 | bool ReadTilecxx . . $ LercNS/Lerc2#ReadTile(e46b292ef6d163a3).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining, T* data, int i0, int i1, int j0, int j1, int iDepth, |
| 244 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int>& bufferVec) const; |
| 245 | |
| 246 | template<class T> |
| 247 | static int ReduceDataTypecxx . . $ LercNS/Lerc2#ReduceDataType(119daec24cbf5a2e).(T z, DataTypecxx . . $ LercNS/Lerc2#DataType# dt, DataTypecxx . . $ LercNS/Lerc2#DataType#& dtReduced); |
| 248 | |
| 249 | static DataTypecxx . . $ LercNS/Lerc2#DataType# GetDataTypeUsedcxx . . $ LercNS/Lerc2#GetDataTypeUsed(8734f81ae2289f0e).(DataTypecxx . . $ LercNS/Lerc2#DataType# dt, int reducedTypeCode); |
| 250 | |
| 251 | static DataTypecxx . . $ LercNS/Lerc2#DataType# ValidateDataTypecxx . . $ LercNS/Lerc2#ValidateDataType(a6ff7f099ebf935a).(int dt); |
| 252 | |
| 253 | static bool WriteVariableDataTypecxx . . $ LercNS/Lerc2#WriteVariableDataType(f74bd397b7d7cc62).(Bytecxx . . $ LercNS/Byte#** ppByte, double z, DataTypecxx . . $ LercNS/Lerc2#DataType# dtUsed); |
| 254 | |
| 255 | static double ReadVariableDataTypecxx . . $ LercNS/Lerc2#ReadVariableDataType(efb34eb88c208493).(const Bytecxx . . $ LercNS/Byte#** ppByte, DataTypecxx . . $ LercNS/Lerc2#DataType# dtUsed); |
| 256 | |
| 257 | template<class T> |
| 258 | static DataTypecxx . . $ LercNS/Lerc2#DataType# GetDataTypecxx . . $ LercNS/Lerc2#GetDataType(36b83e793b7541af).(T z); |
| 259 | |
| 260 | static unsigned int GetMaxValToQuantizecxx . . $ LercNS/Lerc2#GetMaxValToQuantize(3707fc1f19bbe2a2).(DataTypecxx . . $ LercNS/Lerc2#DataType# dt); |
| 261 | |
| 262 | static unsigned int GetDataTypeSizecxx . . $ LercNS/Lerc2#GetDataTypeSize(3707fc1f19bbe2a2).(DataTypecxx . . $ LercNS/Lerc2#DataType# dt); |
| 263 | |
| 264 | static void SortQuantArraycxx . . $ LercNS/Lerc2#SortQuantArray(3b8c1c1ca38f2c23).(const stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int>& quantVec, |
| 265 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<unsigned int, unsigned int> >& sortedQuantVec); |
| 266 | |
| 267 | template<class T> |
| 268 | void ComputeHuffmanCodescxx . . $ LercNS/Lerc2#ComputeHuffmanCodes(262ecf6b652a9a81).(const T* data, int& numBytes, ImageEncodeModecxx . . $ LercNS/Lerc2#ImageEncodeMode#& imageEncodeMode, |
| 269 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<unsigned short, unsigned int> >& codes) const; |
| 270 | |
| 271 | template<class T> |
| 272 | void ComputeHistoForHuffmancxx . . $ LercNS/Lerc2#ComputeHistoForHuffman(1286356d30332779).(const T* data, stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& histo, stdcxx . . $ std/::vectorcxx . . $ std/vector#<int>& deltaHisto) const; |
| 273 | |
| 274 | template<class T> |
| 275 | bool EncodeHuffmancxx . . $ LercNS/Lerc2#EncodeHuffman(cc83d641fe8bfa9b).(const T* data, Bytecxx . . $ LercNS/Byte#** ppByte) const; |
| 276 | |
| 277 | template<class T> |
| 278 | bool DecodeHuffmancxx . . $ LercNS/Lerc2#DecodeHuffman(d8761aea236c93e).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining, T* data) const; |
| 279 | |
| 280 | template<class T> |
| 281 | bool WriteMinMaxRangescxx . . $ LercNS/Lerc2#WriteMinMaxRanges(cc83d641fe8bfa9b).(const T* data, Bytecxx . . $ LercNS/Byte#** ppByte) const; |
| 282 | |
| 283 | template<class T> |
| 284 | bool ReadMinMaxRangescxx . . $ LercNS/Lerc2#ReadMinMaxRanges(823b49aaa8f6c8db).(const Bytecxx . . $ LercNS/Byte#** ppByte, size_t& nBytesRemaining, const T* data); |
| 285 | |
| 286 | bool CheckMinMaxRangescxx . . $ LercNS/Lerc2#CheckMinMaxRanges(dadd4ad61e27fbc).(bool& minMaxEqual) const; |
| 287 | |
| 288 | template<class T> |
| 289 | bool FillConstImagecxx . . $ LercNS/Lerc2#FillConstImage(688a48c7bc3386d6).(T* data) const; |
| 290 | }; |
| 291 | |
| 292 | // -------------------------------------------------------------------------- ; |
| 293 | // -------------------------------------------------------------------------- ; |
| 294 | |
| 295 | inline void Lerc2cxx . . $ LercNS/Lerc2#::AddUIntToCountscxx . . $ LercNS/Lerc2#AddUIntToCounts(a4fdc77d1ddcd2d8).(int* pCounts, unsigned int val, int nBits) |
| 296 | { |
| 297 | pCounts[0] += val & 1; |
| 298 | for (int i = 1; i < nBits; i++) |
| 299 | pCounts[i] += (val >>= 1) & 1; |
| 300 | } |
| 301 | |
| 302 | // -------------------------------------------------------------------------- ; |
| 303 | |
| 304 | inline void Lerc2cxx . . $ LercNS/Lerc2#::AddIntToCountscxx . . $ LercNS/Lerc2#AddIntToCounts(5f3888e91f92d472).(int* pCounts, int val, int nBits) |
| 305 | { |
| 306 | pCounts[0] += val & 1; |
| 307 | for (int i = 1; i < nBits; i++) |
| 308 | pCounts[i] += (val >>= 1) & 1; |
| 309 | } |
| 310 | |
| 311 | // -------------------------------------------------------------------------- ; |
| 312 | |
| 313 | inline bool Lerc2cxx . . $ LercNS/Lerc2#::NeedToCheckForIntOverflowcxx . . $ LercNS/Lerc2#NeedToCheckForIntOverflow(bf20af955ee05b5d).(const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd) |
| 314 | { |
| 315 | return (hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_Intcxx . . $ LercNS/Lerc2#DT_Int. || hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. == DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.) && (hd.zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax. - hd.zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin. >= 0x7FFFFFFF); |
| 316 | } |
| 317 | |
| 318 | // -------------------------------------------------------------------------- ; |
| 319 | |
| 320 | inline bool Lerc2cxx . . $ LercNS/Lerc2#::NeedToCheckForFltRndErrcxx . . $ LercNS/Lerc2#NeedToCheckForFltRndErr(bf20af955ee05b5d).(const HeaderInfocxx . . $ LercNS/Lerc2#HeaderInfo#& hd) |
| 321 | { |
| 322 | if (hd.dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. != DT_Floatcxx . . $ LercNS/Lerc2#DT_Float.) |
| 323 | return false; |
| 324 | |
| 325 | if (hd.zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax. - hd.zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin. > 100000) // prevent the below test falls through with extreme numbers like 10^38 |
| 326 | return true; |
| 327 | |
| 328 | float diff = (float)(hd.zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax. - hd.zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin.); |
| 329 | double testMax = (double)diff + hd.zMincxx . . $ LercNS/Lerc2#HeaderInfo#zMin.; |
| 330 | double fltRndErr = fabs(testMax - hd.zMaxcxx . . $ LercNS/Lerc2#HeaderInfo#zMax.); |
| 331 | |
| 332 | return (fltRndErr > hd.maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. / 8); |
| 333 | } |
| 334 | |
| 335 | // -------------------------------------------------------------------------- ; |
| 336 | |
| 337 | inline double Lerc2cxx . . $ LercNS/Lerc2#::ComputeMaxValcxx . . $ LercNS/Lerc2#ComputeMaxVal(7678bba071383ab).(double zMin, double zMax, double maxZError) |
| 338 | { |
| 339 | double fac = 1 / (2 * maxZError); // must match the code in Decode(), don't touch it |
| 340 | return (zMax - zMin) * fac; |
| 341 | } |
| 342 | |
| 343 | // -------------------------------------------------------------------------- ; |
| 344 | |
| 345 | template<class T> |
| 346 | inline bool Lerc2cxx . . $ LercNS/Lerc2#::NeedToQuantizecxx . . $ LercNS/Lerc2#NeedToQuantize(2999a0978c8d2873).(int numValidPixel, T zMin, T zMax) const |
| 347 | { |
| 348 | if (numValidPixel == 0 || m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. == 0) |
| 349 | return false; |
| 350 | |
| 351 | double maxVal = ComputeMaxValcxx . . $ LercNS/Lerc2#ComputeMaxVal(7678bba071383ab).(zMin, zMax, m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError.); |
| 352 | return !(maxVal > m_maxValToQuantizecxx . . $ LercNS/Lerc2#m_maxValToQuantize. || (unsigned int)(maxVal + 0.5) == 0); |
| 353 | } |
| 354 | |
| 355 | // -------------------------------------------------------------------------- ; |
| 356 | |
| 357 | template<class T> |
| 358 | inline void Lerc2cxx . . $ LercNS/Lerc2#::Quantizecxx . . $ LercNS/Lerc2#Quantize(e1565945717ed8ab).(const T* dataBuf, int num, T zMin, stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int>& quantVec) const |
| 359 | { |
| 360 | quantVec.resizecxx . . $ std/vector#resize(2c44cd906ae4e829).(num); |
| 361 | |
| 362 | if (m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..dtcxx . . $ LercNS/Lerc2#HeaderInfo#dt. < DT_Floatcxx . . $ LercNS/Lerc2#DT_Float. && m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError. == 0.5) // int lossless |
| 363 | { |
| 364 | for (int i = 0; i < num; i++) |
| 365 | quantVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] = (unsigned int)(dataBuf[i] - zMin); // ok: char, short get promoted to int by C++ integral promotion rule |
| 366 | } |
| 367 | else // float and/or lossy |
| 368 | { |
| 369 | double scale = 1 / (2 * m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError.); |
| 370 | double zMinDbl = (double)zMin; |
| 371 | |
| 372 | for (int i = 0; i < num; i++) |
| 373 | quantVec[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).i] = (unsigned int)(((double)dataBuf[i] - zMinDbl) * scale + 0.5); // ok, consistent with ComputeMaxVal(...) |
| 374 | //quantVec[i] = (unsigned int)((dataBuf[i] - zMin) * scale + 0.5); // bad, not consistent with ComputeMaxVal(...) |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | // -------------------------------------------------------------------------- ; |
| 379 | |
| 380 | template<class T> |
| 381 | inline void Lerc2cxx . . $ LercNS/Lerc2#::ScaleBackcxx . . $ LercNS/Lerc2#ScaleBack(89d102402d680757).(T* dataBuf, const stdcxx . . $ std/::vectorcxx . . $ std/vector#<unsigned int>& quantVec, |
| 382 | double zMin, bool bDiff, bool bClamp, double zMaxClamp, double maxZError) |
| 383 | { |
| 384 | double invScale = 2 * maxZError; // for int types this is int |
| 385 | int num = (int)quantVec.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 386 | |
| 387 | if (!bClamp) |
| 388 | for (int i = 0; i < num; i++) |
| 389 | { |
| 390 | double z = zMin + quantVec[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i] * invScale + (bDiff ? dataBuf[i] : 0); |
| 391 | dataBuf[i] = (T)z; |
| 392 | } |
| 393 | else |
| 394 | for (int i = 0; i < num; i++) |
| 395 | { |
| 396 | double z = zMin + quantVec[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).i] * invScale + (bDiff ? dataBuf[i] : 0); |
| 397 | dataBuf[i] = (T)stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(z, zMaxClamp); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | // -------------------------------------------------------------------------- ; |
| 402 | |
| 403 | template<class T> |
| 404 | inline void Lerc2cxx . . $ LercNS/Lerc2#::ScaleBackConstBlockcxx . . $ LercNS/Lerc2#ScaleBackConstBlock(774e296019d19ac7).(T* dataBuf, int num, double zMin, bool bClamp, double zMaxClamp) |
| 405 | { |
| 406 | if (!bClamp) |
| 407 | for (int i = 0; i < num; i++) |
| 408 | dataBuf[i] = (T)(zMin + dataBuf[i]); |
| 409 | else |
| 410 | for (int i = 0; i < num; i++) |
| 411 | dataBuf[i] = (T)stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(zMin + dataBuf[i], zMaxClamp); |
| 412 | } |
| 413 | |
| 414 | // -------------------------------------------------------------------------- ; |
| 415 | |
| 416 | template<class T> |
| 417 | inline int Lerc2cxx . . $ LercNS/Lerc2#::NumBytesTilecxx . . $ LercNS/Lerc2#NumBytesTile(2ecbd70ef45e66ca).(int numValidPixel, T zMin, T zMax, DataTypecxx . . $ LercNS/Lerc2#DataType# dtZ, bool tryLut, |
| 418 | BlockEncodeModecxx . . $ LercNS/Lerc2#BlockEncodeMode#& blockEncodeMode, const stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<unsigned int, unsigned int> >& sortedQuantVec) const |
| 419 | { |
| 420 | blockEncodeMode = BEM_RawBinarycxx . . $ LercNS/Lerc2#BEM_RawBinary.; |
| 421 | |
| 422 | if (numValidPixel == 0 || (zMin == 0 && zMax == 0)) |
| 423 | return 1; |
| 424 | |
| 425 | double maxVal = 0, maxZError = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..maxZErrorcxx . . $ LercNS/Lerc2#HeaderInfo#maxZError.; |
| 426 | int nBytesRaw = (int)(1 + numValidPixel * sizeof(T)); |
| 427 | |
| 428 | if ((maxZError == 0 && zMax > zMin) |
| 429 | || (maxZError > 0 && (maxVal = ComputeMaxValcxx . . $ LercNS/Lerc2#ComputeMaxVal(7678bba071383ab).(zMin, zMax, maxZError)) > m_maxValToQuantizecxx . . $ LercNS/Lerc2#m_maxValToQuantize.)) |
| 430 | { |
| 431 | return nBytesRaw; |
| 432 | } |
| 433 | else |
| 434 | { |
| 435 | DataTypecxx . . $ LercNS/Lerc2#DataType# dtReduced; |
| 436 | ReduceDataTypecxx . . $ LercNS/Lerc2#ReduceDataType(119daec24cbf5a2e).(zMin, dtZ, dtReduced); |
| 437 | int nBytes = 1 + GetDataTypeSizecxx . . $ LercNS/Lerc2#GetDataTypeSize(3707fc1f19bbe2a2).(dtReduced); |
| 438 | |
| 439 | unsigned int maxElem = (unsigned int)(maxVal + 0.5); |
| 440 | if (maxElem > 0) |
| 441 | { |
| 442 | nBytes += (!tryLut) ? BitStuffer2cxx . . $ LercNS/BitStuffer2#::ComputeNumBytesNeededSimplecxx . . $ LercNS/BitStuffer2#ComputeNumBytesNeededSimple(83f10ac8959d5577).(numValidPixel, maxElem) |
| 443 | : BitStuffer2cxx . . $ LercNS/BitStuffer2#::ComputeNumBytesNeededLutcxx . . $ LercNS/BitStuffer2#ComputeNumBytesNeededLut(9724331898c81567).(sortedQuantVec, tryLut); |
| 444 | } |
| 445 | |
| 446 | if (nBytes < nBytesRaw) |
| 447 | blockEncodeMode = (!tryLut || maxElem == 0) ? BEM_BitStuffSimplecxx . . $ LercNS/Lerc2#BEM_BitStuffSimple. : BEM_BitStuffLUTcxx . . $ LercNS/Lerc2#BEM_BitStuffLUT.; |
| 448 | else |
| 449 | nBytes = nBytesRaw; |
| 450 | |
| 451 | return nBytes; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | // -------------------------------------------------------------------------- ; |
| 456 | |
| 457 | template<class T> |
| 458 | inline int Lerc2cxx . . $ LercNS/Lerc2#::ReduceDataTypecxx . . $ LercNS/Lerc2#ReduceDataType(119daec24cbf5a2e).(T z, DataTypecxx . . $ LercNS/Lerc2#DataType# dt, DataTypecxx . . $ LercNS/Lerc2#DataType#& dtReduced) |
| 459 | { |
| 460 | // clamp to dst range first to guarantee portable code, see https://www.cplusplus.com/doc/tutorial/typecasting/ |
| 461 | |
| 462 | Bytecxx . . $ LercNS/Byte# b = (z >= 0 && z <= 255) ? (Bytecxx . . $ LercNS/Byte#)z : 0; |
| 463 | switch (dt) |
| 464 | { |
| 465 | case DT_Shortcxx . . $ LercNS/Lerc2#DT_Short.: |
| 466 | { |
| 467 | signed char c = (z >= (double)-128 && z <= 127) ? (signed char)z : 0; // avoid signed / unsigned warnings on some compilers |
| 468 | int tc = (T)c == z ? 2 : (T)b == z ? 1 : 0; |
| 469 | dtReduced = (DataTypecxx . . $ LercNS/Lerc2#DataType#)(dt - tc); |
| 470 | return tc; |
| 471 | } |
| 472 | case DT_UShortcxx . . $ LercNS/Lerc2#DT_UShort.: |
| 473 | { |
| 474 | int tc = (T)b == z ? 1 : 0; |
| 475 | dtReduced = (DataTypecxx . . $ LercNS/Lerc2#DataType#)(dt - 2 * tc); |
| 476 | return tc; |
| 477 | } |
| 478 | case DT_Intcxx . . $ LercNS/Lerc2#DT_Int.: |
| 479 | { |
| 480 | short s = (z >= (double)SHRT_MINcxx . . $ `<external>/2419331716647297546/limits.h:104:9`! && z <= SHRT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:106:9`!) ? (short)z : 0; |
| 481 | unsigned short us = (z >= 0 && z <= USHRT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:113:10`!) ? (unsigned short)z : 0; |
| 482 | int tc = (T)b == z ? 3 : (T)s == z ? 2 : (T)us == z ? 1 : 0; |
| 483 | dtReduced = (DataTypecxx . . $ LercNS/Lerc2#DataType#)(dt - tc); |
| 484 | return tc; |
| 485 | } |
| 486 | case DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.: |
| 487 | { |
| 488 | unsigned short us = (z >= 0 && z <= USHRT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:113:10`!) ? (unsigned short)z : 0; |
| 489 | int tc = (T)b == z ? 2 : (T)us == z ? 1 : 0; |
| 490 | dtReduced = (DataTypecxx . . $ LercNS/Lerc2#DataType#)(dt - 2 * tc); |
| 491 | return tc; |
| 492 | } |
| 493 | case DT_Floatcxx . . $ LercNS/Lerc2#DT_Float.: |
| 494 | { |
| 495 | short s = (z >= (float)SHRT_MINcxx . . $ `<external>/2419331716647297546/limits.h:104:9`! && z <= SHRT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:106:9`!) ? (short)z : 0; |
| 496 | int tc = (T)b == z ? 2 : (T)s == z ? 1 : 0; |
| 497 | dtReduced = tc == 0 ? dt : (tc == 1 ? DT_Shortcxx . . $ LercNS/Lerc2#DT_Short. : DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte.); |
| 498 | return tc; |
| 499 | } |
| 500 | case DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.: |
| 501 | { |
| 502 | short s = (z >= (double)SHRT_MINcxx . . $ `<external>/2419331716647297546/limits.h:104:9`! && z <= SHRT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:106:9`!) ? (short)z : 0; |
| 503 | int l = (z >= (double)INT_MINcxx . . $ `<external>/2419331716647297546/limits.h:118:9`! && z <= (double)INT_MAXcxx . . $ `<external>/2419331716647297546/limits.h:120:9`!) ? (int)z : 0; |
| 504 | float f = (z >= -FLT_MAXcxx . . $ `<external>/8223903785965736313/float.h:104:9`! && z <= FLT_MAXcxx . . $ `<external>/8223903785965736313/float.h:104:9`!) ? (float)z : 0; |
| 505 | int tc = (T)s == z ? 3 : (T)l == z ? 2 : (T)f == z ? 1 : 0; |
| 506 | dtReduced = tc == 0 ? dt : (DataTypecxx . . $ LercNS/Lerc2#DataType#)(dt - 2 * tc + 1); |
| 507 | return tc; |
| 508 | } |
| 509 | default: |
| 510 | { |
| 511 | dtReduced = dt; |
| 512 | return 0; |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | // -------------------------------------------------------------------------- ; |
| 518 | |
| 519 | inline Lerc2cxx . . $ LercNS/Lerc2#::DataTypecxx . . $ LercNS/Lerc2#DataType# Lerc2cxx . . $ LercNS/Lerc2#::ValidateDataTypecxx . . $ LercNS/Lerc2#ValidateDataType(a6ff7f099ebf935a).(int dt) |
| 520 | { |
| 521 | if (dt >= DT_Charcxx . . $ LercNS/Lerc2#DT_Char. && dt <= DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.) |
| 522 | return static_cast<DataTypecxx . . $ LercNS/Lerc2#DataType#>(dt); |
| 523 | return DT_Undefinedcxx . . $ LercNS/Lerc2#DT_Undefined.; |
| 524 | } |
| 525 | |
| 526 | // -------------------------------------------------------------------------- ; |
| 527 | |
| 528 | inline |
| 529 | Lerc2cxx . . $ LercNS/Lerc2#::DataTypecxx . . $ LercNS/Lerc2#DataType# Lerc2cxx . . $ LercNS/Lerc2#::GetDataTypeUsedcxx . . $ LercNS/Lerc2#GetDataTypeUsed(8734f81ae2289f0e).(DataTypecxx . . $ LercNS/Lerc2#DataType# dt, int tc) |
| 530 | { |
| 531 | switch (dt) |
| 532 | { |
| 533 | case DT_Shortcxx . . $ LercNS/Lerc2#DT_Short.: |
| 534 | case DT_Intcxx . . $ LercNS/Lerc2#DT_Int.: return ValidateDataTypecxx . . $ LercNS/Lerc2#ValidateDataType(a6ff7f099ebf935a).(dt - tc); |
| 535 | case DT_UShortcxx . . $ LercNS/Lerc2#DT_UShort.: |
| 536 | case DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.: return ValidateDataTypecxx . . $ LercNS/Lerc2#ValidateDataType(a6ff7f099ebf935a).(dt - 2 * tc); |
| 537 | case DT_Floatcxx . . $ LercNS/Lerc2#DT_Float.: return tc == 0 ? dt : (tc == 1 ? DT_Shortcxx . . $ LercNS/Lerc2#DT_Short. : DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte.); |
| 538 | case DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.: return tc == 0 ? dt : ValidateDataTypecxx . . $ LercNS/Lerc2#ValidateDataType(a6ff7f099ebf935a).(dt - 2 * tc + 1); |
| 539 | default: |
| 540 | return dt; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | // -------------------------------------------------------------------------- ; |
| 545 | |
| 546 | inline |
| 547 | bool Lerc2cxx . . $ LercNS/Lerc2#::WriteVariableDataTypecxx . . $ LercNS/Lerc2#WriteVariableDataType(f74bd397b7d7cc62).(Bytecxx . . $ LercNS/Byte#** ppByte, double z, DataTypecxx . . $ LercNS/Lerc2#DataType# dtUsed) |
| 548 | { |
| 549 | Bytecxx . . $ LercNS/Byte#* ptr = *ppByte; |
| 550 | |
| 551 | switch (dtUsed) |
| 552 | { |
| 553 | case DT_Charcxx . . $ LercNS/Lerc2#DT_Char.: |
| 554 | { |
| 555 | *((signed char*)ptr) = (signed char)z; |
| 556 | ptr++; |
| 557 | break; |
| 558 | } |
| 559 | case DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte.: |
| 560 | { |
| 561 | *((Bytecxx . . $ LercNS/Byte#*)ptr) = (Bytecxx . . $ LercNS/Byte#)z; |
| 562 | ptr++; |
| 563 | break; |
| 564 | } |
| 565 | case DT_Shortcxx . . $ LercNS/Lerc2#DT_Short.: |
| 566 | { |
| 567 | short s = (short)z; |
| 568 | memcpy(ptr, &s, sizeof(short)); |
| 569 | ptr += 2; |
| 570 | break; |
| 571 | } |
| 572 | case DT_UShortcxx . . $ LercNS/Lerc2#DT_UShort.: |
| 573 | { |
| 574 | unsigned short us = (unsigned short)z; |
| 575 | memcpy(ptr, &us, sizeof(unsigned short)); |
| 576 | ptr += 2; |
| 577 | break; |
| 578 | } |
| 579 | case DT_Intcxx . . $ LercNS/Lerc2#DT_Int.: |
| 580 | { |
| 581 | int i = (int)z; |
| 582 | memcpy(ptr, &i, sizeof(int)); |
| 583 | ptr += 4; |
| 584 | break; |
| 585 | } |
| 586 | case DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.: |
| 587 | { |
| 588 | unsigned int n = (unsigned int)z; |
| 589 | memcpy(ptr, &n, sizeof(unsigned int)); |
| 590 | ptr += 4; |
| 591 | break; |
| 592 | } |
| 593 | case DT_Floatcxx . . $ LercNS/Lerc2#DT_Float.: |
| 594 | { |
| 595 | float f = (float)z; |
| 596 | memcpy(ptr, &f, sizeof(float)); |
| 597 | ptr += 4; |
| 598 | break; |
| 599 | } |
| 600 | case DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.: |
| 601 | { |
| 602 | memcpy(ptr, &z, sizeof(double)); |
| 603 | ptr += 8; |
| 604 | break; |
| 605 | } |
| 606 | |
| 607 | default: |
| 608 | return false; |
| 609 | } |
| 610 | |
| 611 | *ppByte = ptr; |
| 612 | return true; |
| 613 | } |
| 614 | |
| 615 | // -------------------------------------------------------------------------- ; |
| 616 | |
| 617 | inline |
| 618 | double Lerc2cxx . . $ LercNS/Lerc2#::ReadVariableDataTypecxx . . $ LercNS/Lerc2#ReadVariableDataType(efb34eb88c208493).(const Bytecxx . . $ LercNS/Byte#** ppByte, DataTypecxx . . $ LercNS/Lerc2#DataType# dtUsed) |
| 619 | { |
| 620 | const Bytecxx . . $ LercNS/Byte#* ptr = *ppByte; |
| 621 | |
| 622 | switch (dtUsed) |
| 623 | { |
| 624 | case DT_Charcxx . . $ LercNS/Lerc2#DT_Char.: |
| 625 | { |
| 626 | signed char c = *((signed char*)ptr); |
| 627 | *ppByte = ptr + 1; |
| 628 | return c; |
| 629 | } |
| 630 | case DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte.: |
| 631 | { |
| 632 | Bytecxx . . $ LercNS/Byte# b = *((Bytecxx . . $ LercNS/Byte#*)ptr); |
| 633 | *ppByte = ptr + 1; |
| 634 | return b; |
| 635 | } |
| 636 | case DT_Shortcxx . . $ LercNS/Lerc2#DT_Short.: |
| 637 | { |
| 638 | short s; |
| 639 | memcpy(&s, ptr, sizeof(short)); |
| 640 | *ppByte = ptr + 2; |
| 641 | return s; |
| 642 | } |
| 643 | case DT_UShortcxx . . $ LercNS/Lerc2#DT_UShort.: |
| 644 | { |
| 645 | unsigned short us; |
| 646 | memcpy(&us, ptr, sizeof(unsigned short)); |
| 647 | *ppByte = ptr + 2; |
| 648 | return us; |
| 649 | } |
| 650 | case DT_Intcxx . . $ LercNS/Lerc2#DT_Int.: |
| 651 | { |
| 652 | int i; |
| 653 | memcpy(&i, ptr, sizeof(int)); |
| 654 | *ppByte = ptr + 4; |
| 655 | return i; |
| 656 | } |
| 657 | case DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.: |
| 658 | { |
| 659 | unsigned int n; |
| 660 | memcpy(&n, ptr, sizeof(unsigned int)); |
| 661 | *ppByte = ptr + 4; |
| 662 | return n; |
| 663 | } |
| 664 | case DT_Floatcxx . . $ LercNS/Lerc2#DT_Float.: |
| 665 | { |
| 666 | float f; |
| 667 | memcpy(&f, ptr, sizeof(float)); |
| 668 | *ppByte = ptr + 4; |
| 669 | return f; |
| 670 | } |
| 671 | case DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.: |
| 672 | { |
| 673 | double d; |
| 674 | memcpy(&d, ptr, sizeof(double)); |
| 675 | *ppByte = ptr + 8; |
| 676 | return d; |
| 677 | } |
| 678 | default: |
| 679 | return 0; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | // -------------------------------------------------------------------------- ; |
| 684 | |
| 685 | inline |
| 686 | unsigned int Lerc2cxx . . $ LercNS/Lerc2#::GetMaxValToQuantizecxx . . $ LercNS/Lerc2#GetMaxValToQuantize(3707fc1f19bbe2a2).(DataTypecxx . . $ LercNS/Lerc2#DataType# dt) |
| 687 | { |
| 688 | switch (dt) |
| 689 | { |
| 690 | case DT_Charcxx . . $ LercNS/Lerc2#DT_Char.: |
| 691 | case DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte.: //return (1 << 7) - 1; // disabled: allow LUT mode for 8 bit segmented |
| 692 | case DT_Shortcxx . . $ LercNS/Lerc2#DT_Short.: |
| 693 | case DT_UShortcxx . . $ LercNS/Lerc2#DT_UShort.: return (1 << 15) - 1; |
| 694 | |
| 695 | case DT_Intcxx . . $ LercNS/Lerc2#DT_Int.: |
| 696 | case DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.: |
| 697 | case DT_Floatcxx . . $ LercNS/Lerc2#DT_Float.: |
| 698 | case DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.: return (1 << 30) - 1; |
| 699 | |
| 700 | default: |
| 701 | return 0; |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | // -------------------------------------------------------------------------- ; |
| 706 | |
| 707 | inline |
| 708 | unsigned int Lerc2cxx . . $ LercNS/Lerc2#::GetDataTypeSizecxx . . $ LercNS/Lerc2#GetDataTypeSize(3707fc1f19bbe2a2).(DataTypecxx . . $ LercNS/Lerc2#DataType# dt) |
| 709 | { |
| 710 | switch (dt) |
| 711 | { |
| 712 | case DT_Charcxx . . $ LercNS/Lerc2#DT_Char.: |
| 713 | case DT_Bytecxx . . $ LercNS/Lerc2#DT_Byte.: return 1; |
| 714 | case DT_Shortcxx . . $ LercNS/Lerc2#DT_Short.: |
| 715 | case DT_UShortcxx . . $ LercNS/Lerc2#DT_UShort.: return 2; |
| 716 | case DT_Intcxx . . $ LercNS/Lerc2#DT_Int.: |
| 717 | case DT_UIntcxx . . $ LercNS/Lerc2#DT_UInt.: |
| 718 | case DT_Floatcxx . . $ LercNS/Lerc2#DT_Float.: return 4; |
| 719 | case DT_Doublecxx . . $ LercNS/Lerc2#DT_Double.: return 8; |
| 720 | |
| 721 | default: |
| 722 | return 0; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | // -------------------------------------------------------------------------- ; |
| 727 | |
| 728 | inline |
| 729 | bool Lerc2cxx . . $ LercNS/Lerc2#::CheckMinMaxRangescxx . . $ LercNS/Lerc2#CheckMinMaxRanges(dadd4ad61e27fbc).(bool& minMaxEqual) const |
| 730 | { |
| 731 | int nDepth = m_headerInfocxx . . $ LercNS/Lerc2#m_headerInfo..nDepthcxx . . $ LercNS/Lerc2#HeaderInfo#nDepth.; |
| 732 | if ((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) |
| 733 | return false; |
| 734 | |
| 735 | minMaxEqual = (0 == memcmp(&m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).0], &m_zMaxVeccxx . . $ LercNS/Lerc2#m_zMaxVec.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).0], nDepth * sizeof(m_zMinVeccxx . . $ LercNS/Lerc2#m_zMinVec.[cxx . . $ std/vector#`operator[]`(c8255e0fa326ac32).0]))); |
| 736 | return true; |
| 737 | } |
| 738 | |
| 739 | // -------------------------------------------------------------------------- ; |
| 740 | |
| 741 | NAMESPACE_LERC_ENDcxx . . $ `src/LercLib/Defines.h:36:9`! |
| 742 | #endif |