feat: 集成Tesseract源码到项目中
Description: 由于仓库中的Tesseract不是最新版本导致产生了一个bug,因此将Tesseract源码集成到项目中 Log: no Change-Id: I088de95d6c6ab670406daa8d47ed2ed46929c2c0
This commit is contained in:
88
3rdparty/tesseract_ocr/tesseract/src/cutil/bitvec.h
vendored
Normal file
88
3rdparty/tesseract_ocr/tesseract/src/cutil/bitvec.h
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
/******************************************************************************
|
||||
** Filename: bitvec.h
|
||||
** Purpose: Routines for manipulating bit vectors
|
||||
** Author: Dan Johnson
|
||||
**
|
||||
** (c) Copyright Hewlett-Packard Company, 1988.
|
||||
** 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 BITVEC_H
|
||||
#define BITVEC_H
|
||||
|
||||
#include <cstddef> // for size_t
|
||||
#include <cstdint> // for uint32_t
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
Include Files and Type Defines
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
using BIT_VECTOR = uint32_t *;
|
||||
|
||||
//< no of bits in a BIT_VECTOR element
|
||||
const size_t BITSINLONG = 8 * sizeof(uint32_t);
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
Public Function Prototypes
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
static inline void zero_all_bits(BIT_VECTOR array, size_t length) {
|
||||
for (size_t index = 0; index < length; index++) {
|
||||
array[index] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void set_all_bits(BIT_VECTOR array, size_t length) {
|
||||
for (size_t index = 0; index < length; index++) {
|
||||
array[index] = ~0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void copy_all_bits(BIT_VECTOR source, BIT_VECTOR dest, size_t length) {
|
||||
for (size_t index = 0; index < length; index++) {
|
||||
dest[index] = source[index];
|
||||
}
|
||||
}
|
||||
|
||||
#define SET_BIT(array, bit) (array[bit / BITSINLONG] |= 1 << (bit & (BITSINLONG - 1)))
|
||||
|
||||
#define reset_bit(array, bit) (array[bit / BITSINLONG] &= ~(1 << (bit & (BITSINLONG - 1))))
|
||||
|
||||
#define test_bit(array, bit) (array[bit / BITSINLONG] & (1 << (bit & (BITSINLONG - 1))))
|
||||
|
||||
static inline size_t WordsInVectorOfSize(size_t NumBits) {
|
||||
return (NumBits + BITSINLONG - 1) / BITSINLONG;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine frees a bit vector.
|
||||
*
|
||||
* @param BitVector bit vector to be freed
|
||||
*
|
||||
*/
|
||||
static inline void FreeBitVector(BIT_VECTOR BitVector) {
|
||||
delete[] BitVector;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Allocate and return a new bit vector large enough to
|
||||
* hold the specified number of bits.
|
||||
*
|
||||
* @param NumBits number of bits in new bit vector
|
||||
*
|
||||
* @return New bit vector.
|
||||
*/
|
||||
static inline BIT_VECTOR NewBitVector(size_t NumBits) {
|
||||
return new uint32_t[WordsInVectorOfSize(NumBits)];
|
||||
}
|
||||
|
||||
#endif
|
220
3rdparty/tesseract_ocr/tesseract/src/cutil/oldlist.cpp
vendored
Normal file
220
3rdparty/tesseract_ocr/tesseract/src/cutil/oldlist.cpp
vendored
Normal file
@ -0,0 +1,220 @@
|
||||
/******************************************************************************
|
||||
#
|
||||
# File: oldlist.cpp
|
||||
# Description: List processing procedures.
|
||||
# Author: Mark Seaman, Software Productivity
|
||||
#
|
||||
# (c) Copyright 1987, Hewlett-Packard Company.
|
||||
** 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.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
This file contains a set of general purpose list manipulation routines.
|
||||
These routines can be used in a wide variety of ways to provide several
|
||||
different popular data structures. A new list can be created by declaring
|
||||
a variable of type 'LIST', and can be initialized with the value 'NIL_LIST'.
|
||||
All of these routines check for the NIL_LIST condition before dereferencing
|
||||
pointers. NOTE: There is a users' manual available in printed form from
|
||||
Mark Seaman at (303) 350-4492 at Greeley Hard Copy.
|
||||
|
||||
To implement a STACK use:
|
||||
|
||||
push to add to the Stack l = push(l, (LIST)"jim");
|
||||
pop to remove items from the Stack l = pop(l);
|
||||
first_node to access the head name = (char *)first_node(l);
|
||||
|
||||
To implement a QUEUE use:
|
||||
|
||||
push_last to add to the Queue l = push_last(l, (LIST)"x");
|
||||
pop remove items from the Queue l = pop(l);
|
||||
first_node to access the head name = (char *)first_node (l);
|
||||
|
||||
To implement LISP like functions use:
|
||||
|
||||
first_node CAR x = (int)first_node(l);
|
||||
rest CDR l = list_rest (l);
|
||||
push CONS l = push(l, (LIST)this);
|
||||
last LAST x = last(l);
|
||||
concat APPEND l = concat(r, s);
|
||||
count LENGTH x = count(l);
|
||||
search MEMBER if (search(l, x, nullptr))
|
||||
|
||||
The following rules of closure exist for the functions provided.
|
||||
a = first_node (push (a, b))
|
||||
b = list_rest (push (a, b))
|
||||
a = push (pop (a), a)) For all a <> NIL_LIST
|
||||
a = reverse (reverse (a))
|
||||
|
||||
******************************************************************************/
|
||||
#include "oldlist.h"
|
||||
|
||||
#include "errcode.h" // for ASSERT_HOST
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring> // for strcmp
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
F u n c t i o n s
|
||||
----------------------------------------------------------------------*/
|
||||
|
||||
/**********************************************************************
|
||||
* i s s a m e
|
||||
*
|
||||
* Compare the list node with the key value return true (non-zero)
|
||||
* if they are equivalent strings. (Return false if not)
|
||||
**********************************************************************/
|
||||
static int is_same(void *item1, void *item2) {
|
||||
return strcmp(static_cast<char *>(item1), static_cast<char *>(item2)) == 0;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* d e l e t e d
|
||||
*
|
||||
* Delete all the elements out of the current list that match the key.
|
||||
* This operation destroys the original list. The caller will supply a
|
||||
* routine that will compare each node to the
|
||||
* key, and return a non-zero value when they match.
|
||||
**********************************************************************/
|
||||
LIST delete_d(LIST list, void *key, int_compare is_equal) {
|
||||
LIST result = NIL_LIST;
|
||||
LIST last_one = NIL_LIST;
|
||||
|
||||
if (is_equal == nullptr) {
|
||||
is_equal = is_same;
|
||||
}
|
||||
|
||||
while (list != NIL_LIST) {
|
||||
if (!(*is_equal)(list->first_node(), key)) {
|
||||
if (last_one == NIL_LIST) {
|
||||
last_one = list;
|
||||
list = list->list_rest();
|
||||
result = last_one;
|
||||
set_rest(last_one, NIL_LIST);
|
||||
} else {
|
||||
set_rest(last_one, list);
|
||||
last_one = list;
|
||||
list = list->list_rest();
|
||||
set_rest(last_one, NIL_LIST);
|
||||
}
|
||||
} else {
|
||||
list = pop(list);
|
||||
}
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* d e s t r o y
|
||||
*
|
||||
* Return the space taken by a list to the heap.
|
||||
**********************************************************************/
|
||||
LIST destroy(LIST list) {
|
||||
LIST next;
|
||||
|
||||
while (list != NIL_LIST) {
|
||||
next = list->list_rest();
|
||||
delete list;
|
||||
list = next;
|
||||
}
|
||||
return (NIL_LIST);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* d e s t r o y n o d e s
|
||||
*
|
||||
* Return the space taken by the LISTs of a list to the heap.
|
||||
**********************************************************************/
|
||||
void destroy_nodes(LIST list, void_dest destructor) {
|
||||
ASSERT_HOST(destructor != nullptr);
|
||||
|
||||
while (list != NIL_LIST) {
|
||||
if (list->first_node() != nullptr) {
|
||||
(*destructor)(list->first_node());
|
||||
}
|
||||
list = pop(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* l a s t
|
||||
*
|
||||
* Return the last list item (this is list type).
|
||||
**********************************************************************/
|
||||
LIST last(LIST var_list) {
|
||||
while (var_list->list_rest() != NIL_LIST) {
|
||||
var_list = var_list->list_rest();
|
||||
}
|
||||
return var_list;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* p o p
|
||||
*
|
||||
* Return the list with the first element removed. Destroy the space
|
||||
* that it occupied in the list.
|
||||
**********************************************************************/
|
||||
LIST pop(LIST list) {
|
||||
LIST temp = list->list_rest();
|
||||
delete list;
|
||||
return temp;
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* p u s h
|
||||
*
|
||||
* Create a list element. Push the second parameter (the node) onto
|
||||
* the first parameter (the list). Return the new list to the caller.
|
||||
**********************************************************************/
|
||||
LIST push(LIST list, void *element) {
|
||||
LIST t;
|
||||
|
||||
t = new list_rec;
|
||||
t->node = static_cast<LIST>(element);
|
||||
set_rest(t, list);
|
||||
return (t);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* p u s h l a s t
|
||||
*
|
||||
* Create a list element. Add the element onto the end of the list.
|
||||
**********************************************************************/
|
||||
LIST push_last(LIST list, void *item) {
|
||||
LIST t;
|
||||
|
||||
if (list != NIL_LIST) {
|
||||
t = last(list);
|
||||
t->next = push(NIL_LIST, item);
|
||||
return (list);
|
||||
} else {
|
||||
return (push(NIL_LIST, item));
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* s e a r c h
|
||||
*
|
||||
* Search list, return NIL_LIST if not found. Return the list starting from
|
||||
* the item if found. The compare routine "is_equal" is passed in as
|
||||
* the third parameter to this routine.
|
||||
**********************************************************************/
|
||||
LIST search(LIST list, void *key, int_compare is_equal) {
|
||||
if (is_equal == nullptr) {
|
||||
is_equal = is_same;
|
||||
}
|
||||
|
||||
iterate(list) if ((*is_equal)(list->first_node(), key)) return list;
|
||||
return (NIL_LIST);
|
||||
}
|
||||
|
||||
} // namespace tesseract
|
152
3rdparty/tesseract_ocr/tesseract/src/cutil/oldlist.h
vendored
Normal file
152
3rdparty/tesseract_ocr/tesseract/src/cutil/oldlist.h
vendored
Normal file
@ -0,0 +1,152 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* File: oldlist.h (Formerly list.h)
|
||||
* Description: List processing procedures declarations.
|
||||
* Author: Mark Seaman, SW Productivity
|
||||
*
|
||||
* (c) Copyright 1987, Hewlett-Packard Company.
|
||||
** 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.
|
||||
*
|
||||
******************************************************************************
|
||||
*
|
||||
* This file contains the interface for a set of general purpose list
|
||||
* manipulation routines. For the implementation of these routines see
|
||||
* the file "list.c".
|
||||
*
|
||||
******************************************************************************
|
||||
*
|
||||
* INDEX
|
||||
* =======
|
||||
*
|
||||
* BASICS:
|
||||
* -------
|
||||
* first_node - Macro to return the first list node (not the cell).
|
||||
* list_rest - Macro the return the second list cell
|
||||
* pop - Destroy one list cell
|
||||
* push - Create one list cell and set the node and next fields
|
||||
*
|
||||
* ITERATION:
|
||||
* -----------------
|
||||
* iterate - Macro to create a for loop to visit each cell.
|
||||
*
|
||||
* LIST CELL COUNTS:
|
||||
* -----------------
|
||||
* count - Returns the number of list cells in the list.
|
||||
* last - Returns the last list cell.
|
||||
*
|
||||
* TRANSFORMS: (Note: These functions all modify the input list.)
|
||||
* ----------
|
||||
* delete_d - Removes the requested elements from the list.
|
||||
* push_last - Add a new element onto the end of a list.
|
||||
*
|
||||
* SETS:
|
||||
* -----
|
||||
* search - Return the pointer to the list cell whose node matches.
|
||||
*
|
||||
* CELL OPERATIONS:
|
||||
* -----------------
|
||||
* destroy - Return all list cells in a list.
|
||||
* destroy_nodes - Apply a function to each list cell and destroy the list.
|
||||
* set_rest - Assign the next field in a list cell.
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef LIST_H
|
||||
#define LIST_H
|
||||
|
||||
#include <tesseract/export.h>
|
||||
|
||||
#include <cstddef> // for size_t
|
||||
|
||||
namespace tesseract {
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
T y p e s
|
||||
----------------------------------------------------------------------*/
|
||||
|
||||
#define NIL_LIST static_cast<LIST>(nullptr)
|
||||
|
||||
using int_compare = int (*)(void *, void *);
|
||||
using void_dest = void (*)(void *);
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
M a c r o s
|
||||
----------------------------------------------------------------------*/
|
||||
|
||||
/**********************************************************************
|
||||
* i t e r a t e
|
||||
*
|
||||
* Visit each node in the list. Replace the old list with the list
|
||||
* minus the head. Continue until the list is NIL_LIST.
|
||||
**********************************************************************/
|
||||
|
||||
#define iterate(l) for (; (l) != nullptr; (l) = (l)->list_rest())
|
||||
|
||||
/**********************************************************************
|
||||
* s e t r e s t
|
||||
*
|
||||
* Change the "next" field of a list element to point to a desired place.
|
||||
*
|
||||
* #define set_rest(l,node) l->next = node;
|
||||
**********************************************************************/
|
||||
|
||||
#define set_rest(l, cell) ((l)->next = (cell))
|
||||
|
||||
struct list_rec {
|
||||
list_rec *node;
|
||||
list_rec *next;
|
||||
|
||||
list_rec *first_node() {
|
||||
return node;
|
||||
}
|
||||
|
||||
list_rec *list_rest() {
|
||||
return next;
|
||||
}
|
||||
|
||||
//********************************************************************
|
||||
// Recursively count the elements in a list. Return the count.
|
||||
//********************************************************************
|
||||
size_t size() {
|
||||
auto var_list = this;
|
||||
size_t n = 0;
|
||||
iterate(var_list) n++;
|
||||
return n;
|
||||
}
|
||||
};
|
||||
using LIST = list_rec *;
|
||||
|
||||
/*----------------------------------------------------------------------
|
||||
Public Function Prototypes
|
||||
----------------------------------------------------------------------*/
|
||||
|
||||
LIST delete_d(LIST list, void *key, int_compare is_equal);
|
||||
|
||||
TESS_API
|
||||
LIST destroy(LIST list);
|
||||
|
||||
void destroy_nodes(LIST list, void_dest destructor);
|
||||
|
||||
LIST last(LIST var_list);
|
||||
|
||||
LIST pop(LIST list);
|
||||
|
||||
TESS_API
|
||||
LIST push(LIST list, void *element);
|
||||
|
||||
TESS_API
|
||||
LIST push_last(LIST list, void *item);
|
||||
|
||||
LIST search(LIST list, void *key, int_compare is_equal);
|
||||
|
||||
} // namespace tesseract
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user