Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/wordrec/pieces.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 * | |
| 3 * File: pieces.cpp | |
| 4 * Description: | |
| 5 * Author: Mark Seaman, OCR Technology | |
| 6 * | |
| 7 * (c) Copyright 1987, Hewlett-Packard Company. | |
| 8 ** Licensed under the Apache License, Version 2.0 (the "License"); | |
| 9 ** you may not use this file except in compliance with the License. | |
| 10 ** You may obtain a copy of the License at | |
| 11 ** http://www.apache.org/licenses/LICENSE-2.0 | |
| 12 ** Unless required by applicable law or agreed to in writing, software | |
| 13 ** distributed under the License is distributed on an "AS IS" BASIS, | |
| 14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 15 ** See the License for the specific language governing permissions and | |
| 16 ** limitations under the License. | |
| 17 * | |
| 18 *****************************************************************************/ | |
| 19 /*---------------------------------------------------------------------- | |
| 20 I n c l u d e s | |
| 21 ----------------------------------------------------------------------*/ | |
| 22 | |
| 23 #include "blobs.h" | |
| 24 #include "helpers.h" | |
| 25 #include "matrix.h" | |
| 26 #include "ratngs.h" | |
| 27 #include "seam.h" | |
| 28 #include "wordrec.h" | |
| 29 | |
| 30 // Include automatically generated configuration file if running autoconf. | |
| 31 #ifdef HAVE_CONFIG_H | |
| 32 # include "config_auto.h" | |
| 33 #endif | |
| 34 | |
| 35 using tesseract::ScoredFont; | |
| 36 | |
| 37 /*---------------------------------------------------------------------- | |
| 38 F u n c t i o n s | |
| 39 ----------------------------------------------------------------------*/ | |
| 40 | |
| 41 /********************************************************************** | |
| 42 * classify_piece | |
| 43 * | |
| 44 * Create a larger piece from a collection of smaller ones. Classify | |
| 45 * it and return the results. Take the large piece apart to leave | |
| 46 * the collection of small pieces un modified. | |
| 47 **********************************************************************/ | |
| 48 namespace tesseract { | |
| 49 BLOB_CHOICE_LIST *Wordrec::classify_piece(const std::vector<SEAM *> &seams, int16_t start, | |
| 50 int16_t end, const char *description, TWERD *word, | |
| 51 BlamerBundle *blamer_bundle) { | |
| 52 if (end > start) { | |
| 53 SEAM::JoinPieces(seams, word->blobs, start, end); | |
| 54 } | |
| 55 BLOB_CHOICE_LIST *choices = | |
| 56 classify_blob(word->blobs[start], description, ScrollView::WHITE, blamer_bundle); | |
| 57 // Set the matrix_cell_ entries in all the BLOB_CHOICES. | |
| 58 BLOB_CHOICE_IT bc_it(choices); | |
| 59 for (bc_it.mark_cycle_pt(); !bc_it.cycled_list(); bc_it.forward()) { | |
| 60 bc_it.data()->set_matrix_cell(start, end); | |
| 61 } | |
| 62 | |
| 63 if (end > start) { | |
| 64 SEAM::BreakPieces(seams, word->blobs, start, end); | |
| 65 } | |
| 66 | |
| 67 return (choices); | |
| 68 } | |
| 69 | |
| 70 template <class BLOB_CHOICE> | |
| 71 int SortByUnicharID(const void *void1, const void *void2) { | |
| 72 const BLOB_CHOICE *p1 = *static_cast<const BLOB_CHOICE *const *>(void1); | |
| 73 const BLOB_CHOICE *p2 = *static_cast<const BLOB_CHOICE *const *>(void2); | |
| 74 | |
| 75 return p1->unichar_id() - p2->unichar_id(); | |
| 76 } | |
| 77 | |
| 78 template <class BLOB_CHOICE> | |
| 79 int SortByRating(const void *void1, const void *void2) { | |
| 80 const BLOB_CHOICE *p1 = *static_cast<const BLOB_CHOICE *const *>(void1); | |
| 81 const BLOB_CHOICE *p2 = *static_cast<const BLOB_CHOICE *const *>(void2); | |
| 82 | |
| 83 if (p1->rating() < p2->rating()) { | |
| 84 return 1; | |
| 85 } | |
| 86 return -1; | |
| 87 } | |
| 88 | |
| 89 } // namespace tesseract |
