1 ///////////////////////////////////////////////////////////////////////
2 // File: equationdetectbase.cpp
3 // Description: The base class equation detection class.
4 // Author: Zongyi (Joe) Liu (joeliu@google.com)
5 // Created: Fri Aug 31 11:13:01 PST 2011
6 //
7 // (C) Copyright 2011, Google Inc.
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 #ifdef HAVE_CONFIG_H
21 # include "config_auto.h"
22 #endif
23
24 #include "equationdetectbase.h"
25
26 #include "blobbox.h"
27
28 #include <allheaders.h>
29
30 namespace tesseract {
31
32 // Destructor.
33 // It is defined here, so the compiler can create a single vtable
34 // instead of weak vtables in every compilation unit.
35 EquationDetectBase::~EquationDetectBase() = default;
36
RenderSpecialText(Image pix,BLOBNBOX * blob)37 void EquationDetectBase::RenderSpecialText(Image pix, BLOBNBOX *blob) {
38 ASSERT_HOST(pix != nullptr && pixGetDepth(pix) == 32 && blob != nullptr);
39 const TBOX &tbox = blob->bounding_box();
40 int height = pixGetHeight(pix);
41 const int box_width = 5;
42
43 // Coordinate translation: tesseract use left bottom as the original, while
44 // leptonica uses left top as the original.
45 Box *box = boxCreate(tbox.left(), height - tbox.top(), tbox.width(), tbox.height());
46 switch (blob->special_text_type()) {
47 case BSTT_MATH: // Red box.
48 pixRenderBoxArb(pix, box, box_width, 255, 0, 0);
49 break;
50 case BSTT_DIGIT: // cyan box.
51 pixRenderBoxArb(pix, box, box_width, 0, 255, 255);
52 break;
53 case BSTT_ITALIC: // Green box.
54 pixRenderBoxArb(pix, box, box_width, 0, 255, 0);
55 break;
56 case BSTT_UNCLEAR: // blue box.
57 pixRenderBoxArb(pix, box, box_width, 0, 255, 0);
58 break;
59 case BSTT_NONE:
60 default:
61 // yellow box.
62 pixRenderBoxArb(pix, box, box_width, 255, 255, 0);
63 break;
64 }
65 boxDestroy(&box);
66 }
67
68 } // namespace tesseract
69