comparison mupdf-source/thirdparty/tesseract/src/ccmain/par_control.cpp @ 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: par_control.cpp
3 // Description: Control code for parallel implementation.
4 // Author: Ray Smith
5 //
6 // (C) Copyright 2013, Google Inc.
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 #include "tesseractclass.h"
20 #ifdef _OPENMP
21 # include <omp.h>
22 #endif // _OPENMP
23
24 namespace tesseract {
25
26 struct BlobData {
27 BlobData() = default;
28 BlobData(int index, Tesseract *tess, const WERD_RES &word)
29 : blob(word.chopped_word->blobs[index])
30 , tesseract(tess)
31 , choices(&(*word.ratings)(index, index)) {}
32
33 TBLOB *blob = nullptr;
34 Tesseract *tesseract = nullptr;
35 BLOB_CHOICE_LIST **choices = nullptr;
36 };
37
38 void Tesseract::PrerecAllWordsPar(const std::vector<WordData> &words) {
39 // Prepare all the blobs.
40 std::vector<BlobData> blobs;
41 for (const auto &w : words) {
42 if (w.word->ratings != nullptr && w.word->ratings->get(0, 0) == nullptr) {
43 for (size_t s = 0; s < w.lang_words.size(); ++s) {
44 Tesseract *sub = s < sub_langs_.size() ? sub_langs_[s] : this;
45 const WERD_RES &word = *w.lang_words[s];
46 for (unsigned b = 0; b < word.chopped_word->NumBlobs(); ++b) {
47 blobs.emplace_back(b, sub, word);
48 }
49 }
50 }
51 }
52 // Pre-classify all the blobs.
53 if (tessedit_parallelize > 1) {
54 #ifdef _OPENMP
55 # pragma omp parallel for num_threads(10)
56 #endif // _OPENMP
57 // NOLINTNEXTLINE(modernize-loop-convert)
58 for (size_t b = 0; b < blobs.size(); ++b) {
59 *blobs[b].choices =
60 blobs[b].tesseract->classify_blob(blobs[b].blob, "par", ScrollView::WHITE, nullptr);
61 }
62 } else {
63 // TODO(AMD) parallelize this.
64 for (auto &blob : blobs) {
65 *blob.choices = blob.tesseract->classify_blob(blob.blob, "par", ScrollView::WHITE, nullptr);
66 }
67 }
68 }
69
70 } // namespace tesseract.