Coverage Report

Created: 2025-09-27 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tesseract/src/ccstruct/stepblob.h
Line
Count
Source
1
/**********************************************************************
2
 * File:        stepblob.h  (Formerly cblob.h)
3
 * Description: Code for C_BLOB class.
4
 * Author:      Ray Smith
5
 * Created:     Tue Oct 08 10:41:13 BST 1991
6
 *
7
 * (C) Copyright 1991, Hewlett-Packard Ltd.
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
#ifndef STEPBLOB_H
21
#define STEPBLOB_H
22
23
#include "coutln.h"     // for C_OUTLINE_LIST, C_OUTLINE
24
#include "elst.h"       // for ELIST_ITERATOR, ELISTIZEH, ELIST_LINK
25
#include "points.h"     // for FCOORD, ICOORD (ptr only)
26
#include "rect.h"       // for TBOX
27
#include "scrollview.h" // for ScrollView, ScrollView::Color
28
29
#include <cstdint> // for int32_t, int16_t
30
31
struct Pix;
32
33
namespace tesseract {
34
35
class C_BLOB;
36
class DENORM;
37
38
ELISTIZEH(C_BLOB)
39
class TESS_API C_BLOB : public ELIST<C_BLOB>::LINK {
40
public:
41
548k
  C_BLOB() = default;
42
  explicit C_BLOB(C_OUTLINE_LIST *outline_list);
43
  // Simpler constructor to build a blob from a single outline that has
44
  // already been fully initialized.
45
  explicit C_BLOB(C_OUTLINE *outline);
46
47
  // Builds a set of one or more blobs from a list of outlines.
48
  // Input: one outline on outline_list contains all the others, but the
49
  // nesting and order are undefined.
50
  // If good_blob is true, the blob is added to good_blobs_it, unless
51
  // an illegal (generation-skipping) parent-child relationship is found.
52
  // If so, the parent blob goes to bad_blobs_it, and the immediate children
53
  // are promoted to the top level, recursively being sent to good_blobs_it.
54
  // If good_blob is false, all created blobs will go to the bad_blobs_it.
55
  // Output: outline_list is empty. One or more blobs are added to
56
  // good_blobs_it and/or bad_blobs_it.
57
  static void ConstructBlobsFromOutlines(bool good_blob, C_OUTLINE_LIST *outline_list,
58
                                         C_BLOB_IT *good_blobs_it, C_BLOB_IT *bad_blobs_it);
59
60
  // Sets the COUT_INVERSE flag appropriately on the outlines and their
61
  // children recursively, reversing the outlines if needed so that
62
  // everything has an anticlockwise top-level.
63
  void CheckInverseFlagAndDirection();
64
65
  // Build and return a fake blob containing a single fake outline with no
66
  // steps.
67
  static C_BLOB *FakeBlob(const TBOX &box);
68
69
24.4M
  C_OUTLINE_LIST *out_list() { // get outline list
70
24.4M
    return &outlines;
71
24.4M
  }
72
73
  TBOX bounding_box() const; // compute bounding box
74
  int32_t area();            // compute area
75
  int32_t perimeter();       // Total perimeter of outlines and 1st level children.
76
  int32_t outer_area();      // compute area
77
  int32_t count_transitions( // count maxima
78
      int32_t threshold);    // size threshold
79
80
  void move(const ICOORD vec);         // reposition blob by vector
81
  void rotate(const FCOORD &rotation); // Rotate by given vector.
82
83
  // Adds sub-pixel resolution EdgeOffsets for the outlines using greyscale
84
  // if the supplied pix is 8-bit or the binary edges if nullptr.
85
  void ComputeEdgeOffsets(int threshold, Image pix);
86
87
  // Estimates and returns the baseline position based on the shape of the
88
  // outlines.
89
  int16_t EstimateBaselinePosition();
90
91
  // Returns a Pix rendering of the blob. pixDestroy after use.
92
  Image render();
93
  // Returns a Pix rendering of the outline of the blob. (no fill).
94
  // pixDestroy after use.
95
  Image render_outline();
96
97
#ifndef GRAPHICS_DISABLED
98
  void plot(                           // draw one
99
      ScrollView *window,              // window to draw in
100
      ScrollView::Color blob_colour,   // for outer bits
101
      ScrollView::Color child_colour); // for holes
102
  // Draws the blob in the given colour, and child_colour, normalized
103
  // using the given denorm, making use of sub-pixel accurate information
104
  // if available.
105
  void plot_normed(const DENORM &denorm, ScrollView::Color blob_colour,
106
                   ScrollView::Color child_colour, ScrollView *window);
107
#endif // !GRAPHICS_DISABLED
108
109
548k
  C_BLOB &operator=(const C_BLOB &source) {
110
548k
    if (!outlines.empty()) {
111
0
      outlines.clear();
112
0
    }
113
548k
    outlines.deep_copy(&source.outlines, &C_OUTLINE::deep_copy);
114
548k
    return *this;
115
548k
  }
116
117
548k
  static C_BLOB *deep_copy(const C_BLOB *src) {
118
548k
    auto *blob = new C_BLOB;
119
548k
    *blob = *src;
120
548k
    return blob;
121
548k
  }
122
123
861k
  static int SortByXMiddle(const C_BLOB *blob1, const C_BLOB *blob2) {
124
861k
    return blob1->bounding_box().x_middle() - blob2->bounding_box().x_middle();
125
861k
  }
126
127
private:
128
  C_OUTLINE_LIST outlines; // master elements
129
};
130
131
} // namespace tesseract
132
133
#endif