comparison mupdf-source/thirdparty/tesseract/src/ccstruct/mod128.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
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /**********************************************************************
2 * File: mod128.h (Formerly dir128.h)
3 * Description: Header for class which implements modulo arithmetic.
4 * Author: Ray Smith
5 *
6 * (C) Copyright 1991, Hewlett-Packard Ltd.
7 ** Licensed under the Apache License, Version 2.0 (the "License");
8 ** you may not use this file except in compliance with the License.
9 ** You may obtain a copy of the License at
10 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 *
17 **********************************************************************/
18
19 #ifndef MOD128_H
20 #define MOD128_H
21
22 #include "points.h"
23
24 namespace tesseract {
25
26 #define MODULUS 128 /*range of directions */
27 #define DIRBITS 7 // no of bits used
28 #define DIRSCALE 1000 // length of vector
29
30 class DIR128 {
31 public:
32 DIR128() = default;
33
34 DIR128( // constructor
35 int16_t value) { // value to assign
36 value %= MODULUS; // modulo arithmetic
37 if (value < 0) {
38 value += MODULUS; // done properly
39 }
40 dir = static_cast<int8_t>(value);
41 }
42 DIR128(const FCOORD fc); // quantize vector
43
44 DIR128 &operator=( // assign of int16_t
45 int16_t value) { // value to assign
46 value %= MODULUS; // modulo arithmetic
47 if (value < 0) {
48 value += MODULUS; // done properly
49 }
50 dir = static_cast<int8_t>(value);
51 return *this;
52 }
53 int8_t operator-( // subtraction
54 const DIR128 &minus) const // for signed result
55 {
56 // result
57 int16_t result = dir - minus.dir;
58
59 if (result > MODULUS / 2) {
60 result -= MODULUS; // get in range
61 } else if (result < -MODULUS / 2) {
62 result += MODULUS;
63 }
64 return static_cast<int8_t>(result);
65 }
66 DIR128 operator+( // addition
67 const DIR128 &add) const // of itself
68 {
69 DIR128 result; // sum
70
71 result = dir + add.dir; // let = do the work
72 return result;
73 }
74 DIR128 &operator+=( // same as +
75 const DIR128 &add) {
76 *this = dir + add.dir; // let = do the work
77 return *this;
78 }
79 int8_t get_dir() const { // access function
80 return dir;
81 }
82
83 int8_t dir; // a direction
84 };
85
86 } // namespace tesseract
87
88 #endif