From bce585286d2a1bc24e8bdb28ac34b60c37fe07d6 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 12 Aug 2019 14:33:55 +0200 Subject: [PATCH 1/4] Remove global array kPolyBlockNames from Tesseract library It is only used in unittest/layout_test.cc after moving a test from baseapi_test.cc to that file, so it can be made local. Signed-off-by: Stefan Weil --- src/ccstruct/Makefile.am | 2 +- src/ccstruct/publictypes.cpp | 40 ------------------------------------ src/ccstruct/publictypes.h | 6 +----- unittest/baseapi_test.cc | 8 -------- unittest/layout_test.cc | 28 +++++++++++++++++++++++++ 5 files changed, 30 insertions(+), 54 deletions(-) delete mode 100644 src/ccstruct/publictypes.cpp diff --git a/src/ccstruct/Makefile.am b/src/ccstruct/Makefile.am index ca4e180b..e3596287 100644 --- a/src/ccstruct/Makefile.am +++ b/src/ccstruct/Makefile.am @@ -38,7 +38,7 @@ libtesseract_ccstruct_la_SOURCES = \ linlsq.cpp matrix.cpp mod128.cpp normalis.cpp \ ocrblock.cpp ocrpara.cpp ocrrow.cpp otsuthr.cpp \ pageres.cpp pdblock.cpp points.cpp polyaprx.cpp polyblk.cpp \ - params_training_featdef.cpp publictypes.cpp \ + params_training_featdef.cpp \ quadlsq.cpp quspline.cpp ratngs.cpp rect.cpp rejctmap.cpp \ seam.cpp split.cpp statistc.cpp stepblob.cpp \ vecfuncs.cpp werd.cpp diff --git a/src/ccstruct/publictypes.cpp b/src/ccstruct/publictypes.cpp deleted file mode 100644 index 47a18009..00000000 --- a/src/ccstruct/publictypes.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/////////////////////////////////////////////////////////////////////// -// File: publictypes.cpp -// Description: Types used in both the API and internally -// Author: Ray Smith -// Created: Wed Mar 03 11:17:09 PST 2010 -// -// (C) Copyright 2010, Google Inc. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -/////////////////////////////////////////////////////////////////////// - -#include "publictypes.h" - -/** String name for each block type. Keep in sync with PolyBlockType. */ -const char* kPolyBlockNames[] = { - "Unknown", - "Flowing Text", - "Heading Text", - "Pullout Text", - "Equation", - "Inline Equation", - "Table", - "Vertical Text", - "Caption Text", - "Flowing Image", - "Heading Image", - "Pullout Image", - "Horizontal Line", - "Vertical Line", - "Noise", - "" // End marker for testing that sizes match. -}; diff --git a/src/ccstruct/publictypes.h b/src/ccstruct/publictypes.h index 6013f4e6..0901d8d6 100644 --- a/src/ccstruct/publictypes.h +++ b/src/ccstruct/publictypes.h @@ -2,7 +2,6 @@ // File: publictypes.h // Description: Types used in both the API and internally // Author: Ray Smith -// Created: Wed Mar 03 09:22:53 PST 2010 // // (C) Copyright 2010, Google Inc. // Licensed under the Apache License, Version 2.0 (the "License"); @@ -47,7 +46,7 @@ constexpr int kResolutionEstimationFactor = 10; /** * Possible types for a POLY_BLOCK or ColPartition. * Must be kept in sync with kPBColors in polyblk.cpp and PTIs*Type functions - * below, as well as kPolyBlockNames in publictypes.cpp. + * below, as well as kPolyBlockNames in layout_test.cc. * Used extensively by ColPartition, and POLY_BLOCK. */ enum PolyBlockType { @@ -90,9 +89,6 @@ inline bool PTIsPulloutType(PolyBlockType type) { return type == PT_PULLOUT_IMAGE || type == PT_PULLOUT_TEXT; } -/** String name for each block type. Keep in sync with PolyBlockType. */ -extern const char* kPolyBlockNames[]; - namespace tesseract { /** * +------------------+ Orientation Example: diff --git a/unittest/baseapi_test.cc b/unittest/baseapi_test.cc index 813c3a6c..724a0d29 100644 --- a/unittest/baseapi_test.cc +++ b/unittest/baseapi_test.cc @@ -63,14 +63,6 @@ class TesseractTest : public testing::Test { } }; -// Tests that array sizes match their intended size. -TEST_F(TesseractTest, ArraySizeTest) { - int size = 0; - for (size = 0; kPolyBlockNames[size][0] != '\0'; ++size) - ; - EXPECT_EQ(size, PT_COUNT); -} - // Tests that Tesseract gets exactly the right answer on phototest. TEST_F(TesseractTest, BasicTesseractTest) { tesseract::TessBaseAPI api; diff --git a/unittest/layout_test.cc b/unittest/layout_test.cc index 7c251a43..38e48092 100644 --- a/unittest/layout_test.cc +++ b/unittest/layout_test.cc @@ -31,6 +31,26 @@ using tesseract::MutableIterator; using tesseract::PageIteratorLevel; using tesseract::ResultIterator; +/** String name for each block type. Keep in sync with PolyBlockType. */ +static const char* kPolyBlockNames[] = { + "Unknown", + "Flowing Text", + "Heading Text", + "Pullout Text", + "Equation", + "Inline Equation", + "Table", + "Vertical Text", + "Caption Text", + "Flowing Image", + "Heading Image", + "Pullout Image", + "Horizontal Line", + "Vertical Line", + "Noise", + "" // End marker for testing that sizes match. +}; + const char* kStrings8087_054[] = { "dat", "Dalmatian", "", "DAMAGED DURING", "margarine,", nullptr}; const PolyBlockType kBlocks8087_054[] = {PT_HEADING_TEXT, PT_FLOWING_TEXT, @@ -171,6 +191,14 @@ class LayoutTest : public testing::Test { tesseract::TessBaseAPI api_; }; +// Tests that array sizes match their intended size. +TEST_F(LayoutTest, ArraySizeTest) { + int size = 0; + for (size = 0; kPolyBlockNames[size][0] != '\0'; ++size) + ; + EXPECT_EQ(size, PT_COUNT); +} + // Tests that Tesseract gets the important blocks and in the right order // on a UNLV page numbered 8087_054.3B.tif. (Dubrovnik) TEST_F(LayoutTest, UNLV8087_054) { From 23e605911fb0f70c13d3b65aecc3efefb56fbb51 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 12 Aug 2019 14:48:56 +0200 Subject: [PATCH 2/4] Remove unused function truncate_path and related files Signed-off-by: Stefan Weil --- CMakeLists.txt | 1 - src/ccmain/tessedit.cpp | 1 - src/ccutil/Makefile.am | 4 ++-- src/ccutil/basedir.cpp | 44 ----------------------------------------- src/ccutil/basedir.h | 31 ----------------------------- sw.cpp | 1 - 6 files changed, 2 insertions(+), 80 deletions(-) delete mode 100644 src/ccutil/basedir.cpp delete mode 100644 src/ccutil/basedir.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fe84c92..6ceb6848 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -527,7 +527,6 @@ install(FILES src/ccstruct/publictypes.h #from ccutil/makefile.am - src/ccutil/basedir.h src/ccutil/errcode.h src/ccutil/fileerr.h src/ccutil/genericvector.h diff --git a/src/ccmain/tessedit.cpp b/src/ccmain/tessedit.cpp index d06151a9..9cbbdfb8 100644 --- a/src/ccmain/tessedit.cpp +++ b/src/ccmain/tessedit.cpp @@ -23,7 +23,6 @@ # include "config_auto.h" #endif -#include "basedir.h" #include "control.h" # include "matchdefs.h" #include "pageres.h" diff --git a/src/ccutil/Makefile.am b/src/ccutil/Makefile.am index eaaf42d0..e12f678d 100644 --- a/src/ccutil/Makefile.am +++ b/src/ccutil/Makefile.am @@ -16,7 +16,7 @@ pkginclude_HEADERS = \ unichar.h noinst_HEADERS = \ - ambigs.h basedir.h bits16.h bitvector.h ccutil.h clst.h doubleptr.h elst2.h \ + ambigs.h bits16.h bitvector.h ccutil.h clst.h doubleptr.h elst2.h \ elst.h errcode.h fileerr.h \ genericheap.h globaloc.h host.h \ indexmapbidi.h kdpair.h lsterr.h \ @@ -28,7 +28,7 @@ noinst_HEADERS = \ noinst_LTLIBRARIES = libtesseract_ccutil.la libtesseract_ccutil_la_SOURCES = \ - ambigs.cpp basedir.cpp bitvector.cpp \ + ambigs.cpp bitvector.cpp \ ccutil.cpp clst.cpp \ elst2.cpp elst.cpp errcode.cpp \ globaloc.cpp indexmapbidi.cpp \ diff --git a/src/ccutil/basedir.cpp b/src/ccutil/basedir.cpp deleted file mode 100644 index ad2fd70e..00000000 --- a/src/ccutil/basedir.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/********************************************************************** - * File: basedir.cpp (Formerly getpath.c) - * Description: Find the directory location of the current executable using - *PATH. Author: Ray Smith Created: Mon Jul 09 09:06:39 BST 1990 - * - * (C) Copyright 1990, Hewlett-Packard Ltd. - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** http://www.apache.org/licenses/LICENSE-2.0 - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ** See the License for the specific language governing permissions and - ** limitations under the License. - * - **********************************************************************/ - -#include "basedir.h" - -#include - -// Assuming that code_path is the name of some file in a desired directory, -// returns the given code_path stripped back to the last slash, leaving -// the last slash in place. If there is no slash, returns ./ assuming that -// the input was the name of something in the current directory. -// Useful for getting to the directory of argv[0], but does not search -// any paths. -TESS_API void truncate_path(const char *code_path, STRING* trunc_path) { - int trunc_index = -1; - if (code_path != nullptr) { - const char* last_slash = strrchr(code_path, '/'); - if (last_slash != nullptr && last_slash + 1 - code_path > trunc_index) - trunc_index = last_slash + 1 - code_path; - last_slash = strrchr(code_path, '\\'); - if (last_slash != nullptr && last_slash + 1 - code_path > trunc_index) - trunc_index = last_slash + 1 - code_path; - } - *trunc_path = code_path; - if (trunc_index >= 0) - trunc_path->truncate_at(trunc_index); - else - *trunc_path = "./"; -} diff --git a/src/ccutil/basedir.h b/src/ccutil/basedir.h deleted file mode 100644 index 60d56ba6..00000000 --- a/src/ccutil/basedir.h +++ /dev/null @@ -1,31 +0,0 @@ -/********************************************************************** - * File: basedir.h (Formerly getpath.h) - * Description: Header file for getpath.c. Provides relocatability of data. - * Author: Ray Smith - * Created: Mon Jul 09 09:13:03 BST 1990 - * - * (C) Copyright 1990, Hewlett-Packard Ltd. - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** http://www.apache.org/licenses/LICENSE-2.0 - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ** See the License for the specific language governing permissions and - ** limitations under the License. - * - **********************************************************************/ - -#ifndef BASEDIR_H -#define BASEDIR_H - -#include "platform.h" -#include "strngs.h" - -// Returns the given code_path truncated to the last slash. -// Useful for getting to the directory of argv[0], but does not search -// any paths. -TESS_API void truncate_path(const char *code_path, STRING* trunc_path); - -#endif diff --git a/sw.cpp b/sw.cpp index af1122f9..4d26c123 100644 --- a/sw.cpp +++ b/sw.cpp @@ -116,7 +116,6 @@ void build(Solution &s) "src/ccstruct/publictypes.h", //from ccutil/makefile.am - "src/ccutil/basedir.h", "src/ccutil/errcode.h", "src/ccutil/fileerr.h", "src/ccutil/genericvector.h", From 970622fbd1b51c04f67b51ceafea22d271b1f454 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 12 Aug 2019 15:04:10 +0200 Subject: [PATCH 3/4] Remove unused functions create_edges_window, draw_raw_edge Signed-off-by: Stefan Weil --- src/textord/Makefile.am | 4 +- src/textord/drawedg.cpp | 81 ----------------------------------------- src/textord/drawedg.h | 37 ------------------- src/textord/edgblob.cpp | 1 - src/textord/edgloop.cpp | 8 ++-- 5 files changed, 5 insertions(+), 126 deletions(-) delete mode 100644 src/textord/drawedg.cpp delete mode 100644 src/textord/drawedg.h diff --git a/src/textord/Makefile.am b/src/textord/Makefile.am index 56f7bd30..db0366ce 100644 --- a/src/textord/Makefile.am +++ b/src/textord/Makefile.am @@ -22,7 +22,7 @@ noinst_HEADERS = \ alignedblob.h baselinedetect.h bbgrid.h blkocc.h blobgrid.h \ ccnontextdetect.h cjkpitch.h colfind.h colpartition.h colpartitionset.h \ colpartitiongrid.h \ - devanagari_processing.h drawedg.h drawtord.h edgblob.h edgloop.h \ + devanagari_processing.h drawtord.h edgblob.h edgloop.h \ equationdetectbase.h \ fpchop.h gap_map.h imagefind.h linefind.h makerow.h oldbasel.h \ pithsync.h pitsync1.h scanedg.h sortflts.h strokewidth.h \ @@ -37,7 +37,7 @@ libtesseract_textord_la_SOURCES = \ alignedblob.cpp baselinedetect.cpp bbgrid.cpp blkocc.cpp blobgrid.cpp \ ccnontextdetect.cpp cjkpitch.cpp colfind.cpp colpartition.cpp colpartitionset.cpp \ colpartitiongrid.cpp devanagari_processing.cpp \ - drawedg.cpp drawtord.cpp edgblob.cpp edgloop.cpp \ + drawtord.cpp edgblob.cpp edgloop.cpp \ equationdetectbase.cpp \ fpchop.cpp gap_map.cpp imagefind.cpp linefind.cpp makerow.cpp oldbasel.cpp \ pithsync.cpp pitsync1.cpp scanedg.cpp sortflts.cpp strokewidth.cpp \ diff --git a/src/textord/drawedg.cpp b/src/textord/drawedg.cpp deleted file mode 100644 index f677969d..00000000 --- a/src/textord/drawedg.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/********************************************************************** - * File: drawedg.cpp (Formerly drawedge.c) - * Description: Collection of functions to draw things to do with edge - * detection. - * Author: Ray Smith - * Created: Thu Jun 06 13:29:20 BST 1991 - * - * (C) Copyright 1991, Hewlett-Packard Ltd. - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** http://www.apache.org/licenses/LICENSE-2.0 - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ** See the License for the specific language governing permissions and - ** limitations under the License. - * - **********************************************************************/ - -#include "drawedg.h" - -// Include automatically generated configuration file if running autoconf. -#ifdef HAVE_CONFIG_H -#include "config_auto.h" -#endif - -#ifndef GRAPHICS_DISABLED - -/** title of window */ -#define IMAGE_WIN_NAME "Edges" -#define IMAGE_XPOS 250 -/** default position */ -#define IMAGE_YPOS 0 - -/** - * @name create_edges_window - * - * Create the edges window. - * @param page_tr size of image - */ - -ScrollView* create_edges_window(ICOORD page_tr) { - ScrollView* image_win; //image window - - //create the window - image_win = new ScrollView (IMAGE_WIN_NAME, IMAGE_XPOS, IMAGE_YPOS, 0, 0, page_tr.x (), page_tr.y ()); - return image_win; //window -} - - -/** - * @name draw_raw_edge - * - * Draw the raw steps to the given window in the given colour. - * @param fd window to draw in - * @param start start of loop - * @param colour colour to draw in - */ - -void draw_raw_edge(ScrollView* fd, - CRACKEDGE *start, - ScrollView::Color colour) { - CRACKEDGE *edgept; //current point - - fd->Pen(colour); - edgept = start; - fd->SetCursor(edgept->pos.x (), edgept->pos.y ()); - do { - do - edgept = edgept->next; - //merge straight lines - while (edgept != start && edgept->prev->stepx == edgept->stepx && edgept->prev->stepy == edgept->stepy); - - //draw lines - fd->DrawTo(edgept->pos.x (), edgept->pos.y ()); - } - while (edgept != start); -} - -#endif // GRAPHICS_DISABLED diff --git a/src/textord/drawedg.h b/src/textord/drawedg.h deleted file mode 100644 index ef5ed5e2..00000000 --- a/src/textord/drawedg.h +++ /dev/null @@ -1,37 +0,0 @@ -/********************************************************************** - * File: drawedg.h (Formerly drawedge.h) - * Description: Collection of functions to draw things to do with edge - *detection. - * Author: Ray Smith - * Created: Thu Jun 06 13:29:20 BST 1991 - * - * (C) Copyright 1991, Hewlett-Packard Ltd. - ** Licensed under the Apache License, Version 2.0 (the "License"); - ** you may not use this file except in compliance with the License. - ** You may obtain a copy of the License at - ** http://www.apache.org/licenses/LICENSE-2.0 - ** Unless required by applicable law or agreed to in writing, software - ** distributed under the License is distributed on an "AS IS" BASIS, - ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ** See the License for the specific language governing permissions and - ** limitations under the License. - * - **********************************************************************/ - -#ifndef DRAWEDG_H -#define DRAWEDG_H -#ifndef GRAPHICS_DISABLED - -#include "scrollview.h" -#include "crakedge.h" - -ScrollView* create_edges_window( //make window - ICOORD page_tr //size of image - ); -void draw_raw_edge( //draw the cracks - ScrollView* fd, //window to draw in - CRACKEDGE *start, //start of loop - ScrollView::Color colour //colour to draw in - ); -#endif -#endif diff --git a/src/textord/edgblob.cpp b/src/textord/edgblob.cpp index 477d2d54..de65b99d 100644 --- a/src/textord/edgblob.cpp +++ b/src/textord/edgblob.cpp @@ -17,7 +17,6 @@ **********************************************************************/ #include "scanedg.h" -#include "drawedg.h" #include "edgloop.h" #include "edgblob.h" diff --git a/src/textord/edgloop.cpp b/src/textord/edgloop.cpp index f051e2df..e47843fc 100644 --- a/src/textord/edgloop.cpp +++ b/src/textord/edgloop.cpp @@ -1,8 +1,7 @@ /********************************************************************** * File: edgloop.cpp (Formerly edgeloop.c) * Description: Functions to clean up an outline before approximation. - * Author: Ray Smith - * Created: Tue Mar 26 16:56:25 GMT 1991 + * Author: Ray Smith * * (C) Copyright 1991, Hewlett-Packard Ltd. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,9 +16,8 @@ * **********************************************************************/ -#include "scanedg.h" -#include "drawedg.h" -#include "edgloop.h" +#include "scanedg.h" +#include "edgloop.h" // Include automatically generated configuration file if running autoconf. #ifdef HAVE_CONFIG_H From ba17bc82040f3d9f20294234194a8097c4ba0160 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Mon, 12 Aug 2019 15:13:45 +0200 Subject: [PATCH 4/4] OpenCL: Add static attribute for kernel_src It is only used in openclwrapper.cpp. Signed-off-by: Stefan Weil --- src/opencl/oclkernels.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opencl/oclkernels.h b/src/opencl/oclkernels.h index 6d47f360..b2560f4b 100644 --- a/src/opencl/oclkernels.h +++ b/src/opencl/oclkernels.h @@ -18,7 +18,7 @@ // cl_amd_fp64: AMD extension // use build option outside to define fp_t ///////////////////////////////////////////// -const char *kernel_src = KERNEL( +static const char* kernel_src = KERNEL( \n#ifdef KHR_DP_EXTENSION\n \n#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n \n#elif AMD_DP_EXTENSION\n