tesseract  4.0.0-1-g2a2b
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  * Created: Mon Mar 18 14:39:00 GMT 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 #include "blread.h"
21 #include <cstdio> // for fclose, fopen, FILE
22 #include "host.h" // for TRUE
23 #include "ocrblock.h" // for BLOCK_IT, BLOCK, BLOCK_LIST (ptr only)
24 #include "scanutils.h" // for tfscanf
25 
26 #define UNLV_EXT ".uzn" // unlv zone file
27 
28 /**********************************************************************
29  * read_unlv_file
30  *
31  * Read a whole unlv zone file to make a list of blocks.
32  **********************************************************************/
33 
34 bool read_unlv_file( //print list of sides
35  STRING name, //basename of file
36  int32_t xsize, //image size
37  int32_t ysize, //image size
38  BLOCK_LIST *blocks //output list
39  ) {
40  FILE *pdfp; //file pointer
41  BLOCK *block; //current block
42  int x; //current top-down coords
43  int y;
44  int width; //of current block
45  int height;
46  BLOCK_IT block_it = blocks; //block iterator
47 
48  name += UNLV_EXT; //add extension
49  if ((pdfp = fopen (name.string (), "rb")) == nullptr) {
50  return false; //didn't read one
51  } else {
52  while (tfscanf(pdfp, "%d %d %d %d %*s", &x, &y, &width, &height) >= 4) {
53  //make rect block
54  block = new BLOCK (name.string (), TRUE, 0, 0,
55  (int16_t) x, (int16_t) (ysize - y - height),
56  (int16_t) (x + width), (int16_t) (ysize - y));
57  //on end of list
58  block_it.add_to_end (block);
59  }
60  fclose(pdfp);
61  }
62  return true;
63 }
64 
65 void FullPageBlock(int width, int height, BLOCK_LIST *blocks) {
66  BLOCK_IT block_it(blocks);
67  BLOCK* block = new BLOCK("", TRUE, 0, 0, 0, 0, width, height);
68  block_it.add_to_end(block);
69 }
int tfscanf(FILE *stream, const char *format,...)
Definition: scanutils.cpp:192
#define TRUE
Definition: capi.h:51
const char * string() const
Definition: strngs.cpp:196
Definition: ocrblock.h:30
Definition: strngs.h:45
bool read_unlv_file(STRING name, int32_t xsize, int32_t ysize, BLOCK_LIST *blocks)
Definition: blread.cpp:34
void FullPageBlock(int width, int height, BLOCK_LIST *blocks)
Definition: blread.cpp:65
#define UNLV_EXT
Definition: blread.cpp:26