tesseract  5.0.0-alpha-619-ge9db
blread.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * File: blread.cpp (Formerly pdread.c)
3  * Description: Friend function of BLOCK to read the uscan pd file.
4  * Author: Ray Smith
5  *
6  * (C) Copyright 1991, Hewlett-Packard Ltd.
7  ** Licensed under the Apache License, Version 2.0 (the "License");
8  ** you may not use this file except in compliance with the License.
9  ** You may obtain a copy of the License at
10  ** http://www.apache.org/licenses/LICENSE-2.0
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  *
17  **********************************************************************/
18 
19 #include "blread.h"
20 #include <cstdio> // for fclose, fopen, FILE
21 #include "ocrblock.h" // for BLOCK_IT, BLOCK, BLOCK_LIST (ptr only)
22 #include "scanutils.h" // for tfscanf
23 
24 #define UNLV_EXT ".uzn" // unlv zone file
25 
26 /**********************************************************************
27  * read_unlv_file
28  *
29  * Read a whole unlv zone file to make a list of blocks.
30  **********************************************************************/
31 
32 bool read_unlv_file( //print list of sides
33  STRING name, //basename of file
34  int32_t xsize, //image size
35  int32_t ysize, //image size
36  BLOCK_LIST *blocks //output list
37  ) {
38  FILE *pdfp; //file pointer
39  BLOCK *block; //current block
40  int x; //current top-down coords
41  int y;
42  int width; //of current block
43  int height;
44  BLOCK_IT block_it = blocks; //block iterator
45 
46  name += UNLV_EXT; //add extension
47  if ((pdfp = fopen (name.c_str (), "rb")) == nullptr) {
48  return false; //didn't read one
49  } else {
50  while (tfscanf(pdfp, "%d %d %d %d %*s", &x, &y, &width, &height) >= 4) {
51  //make rect block
52  block = new BLOCK (name.c_str (), true, 0, 0,
53  static_cast<int16_t>(x), static_cast<int16_t>(ysize - y - height),
54  static_cast<int16_t>(x + width), static_cast<int16_t>(ysize - y));
55  //on end of list
56  block_it.add_to_end (block);
57  }
58  fclose(pdfp);
59  }
60  tprintf("UZN file %s loaded.\n", name.c_str());
61  return true;
62 }
63 
64 void FullPageBlock(int width, int height, BLOCK_LIST *blocks) {
65  BLOCK_IT block_it(blocks);
66  auto* block = new BLOCK("", true, 0, 0, 0, 0, width, height);
67  block_it.add_to_end(block);
68 }
tfscanf
int tfscanf(FILE *stream, const char *format,...)
Definition: scanutils.cpp:181
blread.h
STRING
Definition: strngs.h:45
BLOCK
Definition: ocrblock.h:28
STRING::c_str
const char * c_str() const
Definition: strngs.cpp:192
UNLV_EXT
#define UNLV_EXT
Definition: blread.cpp:24
read_unlv_file
bool read_unlv_file(STRING name, int32_t xsize, int32_t ysize, BLOCK_LIST *blocks)
Definition: blread.cpp:31
scanutils.h
ocrblock.h
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
FullPageBlock
void FullPageBlock(int width, int height, BLOCK_LIST *blocks)
Definition: blread.cpp:63