| 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 | #include "Defines.h"cxx . . $ `<file>/src/LercLib/Defines.h`/ |
| 25 | #include "BitMask.h"cxx . . $ `<file>/src/LercLib/BitMask.h`/ |
| 26 | #include <cstring> |
| 27 | |
| 28 | USING_NAMESPACE_LERCcxx . . $ `src/LercLib/Defines.h:37:9`! |
| 29 | |
| 30 | // -------------------------------------------------------------------------- ; |
| 31 | |
| 32 | BitMaskcxx . . $ LercNS/BitMask#::BitMaskcxx . . $ LercNS/BitMask#BitMask(99ea2fc795a214ed).(const BitMaskcxx . . $ LercNS/BitMask#& src) : m_pBitscxx . . $ LercNS/BitMask#m_pBits.(nullptr), m_nColscxx . . $ LercNS/BitMask#m_nCols.(0), m_nRowscxx . . $ LercNS/BitMask#m_nRows.(0) |
| 33 | { |
| 34 | SetSizecxx . . $ LercNS/BitMask#SetSize(cf9ef193275fa6d8).(src.m_nColscxx . . $ LercNS/BitMask#m_nCols., src.m_nRowscxx . . $ LercNS/BitMask#m_nRows.); |
| 35 | if (m_pBitscxx . . $ LercNS/BitMask#m_pBits. && src.m_pBitscxx . . $ LercNS/BitMask#m_pBits.) |
| 36 | memcpy(m_pBitscxx . . $ LercNS/BitMask#m_pBits., src.m_pBitscxx . . $ LercNS/BitMask#m_pBits., Sizecxx . . $ LercNS/BitMask#Size(fe4d2d262d4164a8).()); |
| 37 | } |
| 38 | |
| 39 | // -------------------------------------------------------------------------- ; |
| 40 | |
| 41 | BitMaskcxx . . $ LercNS/BitMask#& BitMaskcxx . . $ LercNS/BitMask#::operatorcxx . . $ LercNS/BitMask#`operator=`(7ed6a81e88dd5cab).= (const BitMaskcxx . . $ LercNS/BitMask#& src) |
| 42 | { |
| 43 | if (this == &src) return *this; |
| 44 | |
| 45 | SetSizecxx . . $ LercNS/BitMask#SetSize(cf9ef193275fa6d8).(src.m_nColscxx . . $ LercNS/BitMask#m_nCols., src.m_nRowscxx . . $ LercNS/BitMask#m_nRows.); |
| 46 | if (m_pBitscxx . . $ LercNS/BitMask#m_pBits. && src.m_pBitscxx . . $ LercNS/BitMask#m_pBits.) |
| 47 | memcpy(m_pBitscxx . . $ LercNS/BitMask#m_pBits., src.m_pBitscxx . . $ LercNS/BitMask#m_pBits., Sizecxx . . $ LercNS/BitMask#Size(fe4d2d262d4164a8).()); |
| 48 | |
| 49 | return *this; |
| 50 | } |
| 51 | |
| 52 | // -------------------------------------------------------------------------- ; |
| 53 | |
| 54 | void BitMaskcxx . . $ LercNS/BitMask#::SetAllValidcxx . . $ LercNS/BitMask#SetAllValid(83f5f38750778ac8).() const |
| 55 | { |
| 56 | memset(m_pBitscxx . . $ LercNS/BitMask#m_pBits., 255, Sizecxx . . $ LercNS/BitMask#Size(fe4d2d262d4164a8).()); |
| 57 | } |
| 58 | |
| 59 | void BitMaskcxx . . $ LercNS/BitMask#::SetAllInvalidcxx . . $ LercNS/BitMask#SetAllInvalid(83f5f38750778ac8).() const |
| 60 | { |
| 61 | memset(m_pBitscxx . . $ LercNS/BitMask#m_pBits., 0, Sizecxx . . $ LercNS/BitMask#Size(fe4d2d262d4164a8).()); |
| 62 | } |
| 63 | |
| 64 | // -------------------------------------------------------------------------- ; |
| 65 | |
| 66 | bool BitMaskcxx . . $ LercNS/BitMask#::SetSizecxx . . $ LercNS/BitMask#SetSize(cf9ef193275fa6d8).(int nCols, int nRows) |
| 67 | { |
| 68 | if (nCols <= 0 || nRows <= 0) |
| 69 | { |
| 70 | Clearcxx . . $ LercNS/BitMask#Clear(49f6e7a06ebc5aa8).(); |
| 71 | return (nCols == 0 && nRows == 0); |
| 72 | } |
| 73 | |
| 74 | if (nCols != m_nColscxx . . $ LercNS/BitMask#m_nCols. || nRows != m_nRowscxx . . $ LercNS/BitMask#m_nRows.) |
| 75 | { |
| 76 | Clearcxx . . $ LercNS/BitMask#Clear(49f6e7a06ebc5aa8).(); |
| 77 | |
| 78 | try |
| 79 | { |
| 80 | size_t nPix = (size_t)nCols * nRows; |
| 81 | m_pBitscxx . . $ LercNS/BitMask#m_pBits. = new Bytecxx . . $ LercNS/Byte#[(nPix + 7) >> 3]; |
| 82 | } |
| 83 | catch (...) |
| 84 | { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | if (!m_pBitscxx . . $ LercNS/BitMask#m_pBits.) |
| 89 | return false; |
| 90 | |
| 91 | m_nColscxx . . $ LercNS/BitMask#m_nCols. = nCols; |
| 92 | m_nRowscxx . . $ LercNS/BitMask#m_nRows. = nRows; |
| 93 | } |
| 94 | |
| 95 | return m_pBitscxx . . $ LercNS/BitMask#m_pBits. != nullptr; |
| 96 | } |
| 97 | |
| 98 | // -------------------------------------------------------------------------- ; |
| 99 | |
| 100 | int64_tcxx . . $ int64_t# BitMaskcxx . . $ LercNS/BitMask#::CountValidBitscxx . . $ LercNS/BitMask#CountValidBits(57a65ae535d7db84).() const |
| 101 | { |
| 102 | const Bytecxx . . $ LercNS/Byte# numBitsHB[16] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4}; |
| 103 | const Bytecxx . . $ LercNS/Byte#* ptr = m_pBitscxx . . $ LercNS/BitMask#m_pBits.; |
| 104 | int64_tcxx . . $ int64_t# sum = 0; |
| 105 | size_t i = Sizecxx . . $ LercNS/BitMask#Size(fe4d2d262d4164a8).(); |
| 106 | while (i--) |
| 107 | { |
| 108 | sum += numBitsHB[*ptr & 15] + numBitsHB[*ptr >> 4]; |
| 109 | ptr++; |
| 110 | } |
| 111 | |
| 112 | // subtract undefined bits potentially contained in the last byte |
| 113 | int64_tcxx . . $ int64_t# sizeX8 = (int64_tcxx . . $ int64_t#)(Sizecxx . . $ LercNS/BitMask#Size(fe4d2d262d4164a8).() * 8); |
| 114 | for (int64_tcxx . . $ int64_t# k = (int64_tcxx . . $ int64_t#)m_nColscxx . . $ LercNS/BitMask#m_nCols. * m_nRowscxx . . $ LercNS/BitMask#m_nRows.; k < sizeX8; k++) |
| 115 | if (IsValidcxx . . $ LercNS/BitMask#IsValid(7c969c143e367631).(k)) |
| 116 | sum--; |
| 117 | |
| 118 | return sum; |
| 119 | } |
| 120 | |
| 121 | // -------------------------------------------------------------------------- ; |
| 122 | |
| 123 | void BitMaskcxx . . $ LercNS/BitMask#::Clearcxx . . $ LercNS/BitMask#Clear(49f6e7a06ebc5aa8).() |
| 124 | { |
| 125 | delete[] m_pBitscxx . . $ LercNS/BitMask#m_pBits.; |
| 126 | m_pBitscxx . . $ LercNS/BitMask#m_pBits. = nullptr; |
| 127 | m_nColscxx . . $ LercNS/BitMask#m_nCols. = 0; |
| 128 | m_nRowscxx . . $ LercNS/BitMask#m_nRows. = 0; |
| 129 | } |
| 130 | |
| 131 | // -------------------------------------------------------------------------- ; |
| 132 |