Mercurial > hgrepos > Python2 > PyMuPDF
diff mupdf-source/thirdparty/tesseract/src/cutil/bitvec.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mupdf-source/thirdparty/tesseract/src/cutil/bitvec.h Mon Sep 15 11:43:07 2025 +0200 @@ -0,0 +1,88 @@ +/****************************************************************************** + ** Filename: bitvec.h + ** Purpose: Routines for manipulating bit vectors + ** Author: Dan Johnson + ** + ** (c) Copyright Hewlett-Packard Company, 1988. + ** Licensed under the Apache License, Version 2.0 (the "License"); + ** you may not use this file except in compliance with the License. + ** You may obtain a copy of the License at + ** http://www.apache.org/licenses/LICENSE-2.0 + ** Unless required by applicable law or agreed to in writing, software + ** distributed under the License is distributed on an "AS IS" BASIS, + ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ** See the License for the specific language governing permissions and + ** limitations under the License. + ******************************************************************************/ + +#ifndef BITVEC_H +#define BITVEC_H + +#include <cstddef> // for size_t +#include <cstdint> // for uint32_t + +/*----------------------------------------------------------------------------- + Include Files and Type Defines +-----------------------------------------------------------------------------*/ + +using BIT_VECTOR = uint32_t *; + +//< no of bits in a BIT_VECTOR element +const size_t BITSINLONG = 8 * sizeof(uint32_t); + +/*----------------------------------------------------------------------------- + Public Function Prototypes +-----------------------------------------------------------------------------*/ + +static inline void zero_all_bits(BIT_VECTOR array, size_t length) { + for (size_t index = 0; index < length; index++) { + array[index] = 0; + } +} + +static inline void set_all_bits(BIT_VECTOR array, size_t length) { + for (size_t index = 0; index < length; index++) { + array[index] = ~0; + } +} + +static inline void copy_all_bits(BIT_VECTOR source, BIT_VECTOR dest, size_t length) { + for (size_t index = 0; index < length; index++) { + dest[index] = source[index]; + } +} + +#define SET_BIT(array, bit) (array[bit / BITSINLONG] |= 1 << (bit & (BITSINLONG - 1))) + +#define reset_bit(array, bit) (array[bit / BITSINLONG] &= ~(1 << (bit & (BITSINLONG - 1)))) + +#define test_bit(array, bit) (array[bit / BITSINLONG] & (1 << (bit & (BITSINLONG - 1)))) + +static inline size_t WordsInVectorOfSize(size_t NumBits) { + return (NumBits + BITSINLONG - 1) / BITSINLONG; +} + +/** + * This routine frees a bit vector. + * + * @param BitVector bit vector to be freed + * + */ +static inline void FreeBitVector(BIT_VECTOR BitVector) { + delete[] BitVector; +} + +/*---------------------------------------------------------------------------*/ +/** + * Allocate and return a new bit vector large enough to + * hold the specified number of bits. + * + * @param NumBits number of bits in new bit vector + * + * @return New bit vector. + */ +static inline BIT_VECTOR NewBitVector(size_t NumBits) { + return new uint32_t[WordsInVectorOfSize(NumBits)]; +} + +#endif
