Tesseract  3.02
tesseract-ocr/ccstruct/blread.cpp
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        blread.cpp  (Formerly pdread.c)
00003  * Description: Friend function of BLOCK to read the uscan pd file.
00004  * Author:              Ray Smith
00005  * Created:             Mon Mar 18 14:39:00 GMT 1991
00006  *
00007  * (C) Copyright 1991, Hewlett-Packard Ltd.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  *
00018  **********************************************************************/
00019 
00020 #include "mfcpch.h"
00021 #include          <stdlib.h>
00022 #ifdef __UNIX__
00023 #include          <assert.h>
00024 #endif
00025 #include          "scanutils.h"
00026 #include          "fileerr.h"
00027 #include          "blread.h"
00028 
00029 #define UNLV_EXT  ".uzn"  // unlv zone file
00030 
00031 /**********************************************************************
00032  * read_unlv_file
00033  *
00034  * Read a whole unlv zone file to make a list of blocks.
00035  **********************************************************************/
00036 
00037 bool read_unlv_file(                    //print list of sides
00038                      STRING name,        //basename of file
00039                      inT32 xsize,        //image size
00040                      inT32 ysize,        //image size
00041                      BLOCK_LIST *blocks  //output list
00042                     ) {
00043   FILE *pdfp;                    //file pointer
00044   BLOCK *block;                  //current block
00045   int x;                         //current top-down coords
00046   int y;
00047   int width;                     //of current block
00048   int height;
00049   BLOCK_IT block_it = blocks;    //block iterator
00050 
00051   name += UNLV_EXT;              //add extension
00052   if ((pdfp = fopen (name.string (), "rb")) == NULL) {
00053     return false;                //didn't read one
00054   }
00055   else {
00056     while (fscanf (pdfp, "%d %d %d %d %*s", &x, &y, &width, &height) >= 4) {
00057                                  //make rect block
00058       block = new BLOCK (name.string (), TRUE, 0, 0,
00059                          (inT16) x, (inT16) (ysize - y - height),
00060                          (inT16) (x + width), (inT16) (ysize - y));
00061                                  //on end of list
00062       block_it.add_to_end (block);
00063     }
00064     fclose(pdfp);
00065   }
00066   return true;
00067 }
00068 
00069 void FullPageBlock(int width, int height, BLOCK_LIST *blocks) {
00070   BLOCK_IT block_it(blocks);
00071   BLOCK* block = new BLOCK("", TRUE, 0, 0, 0, 0, width, height);
00072   block_it.add_to_end(block);
00073 }