DLLSYM void block_edges( //get edges in a block IMAGE *t_image, //threshold image PDBLK *block, //block in image ICOORD page_tr //corner of page ) { uinT8 margin; //margin colour inT16 x; //line coords inT16 y; //current line ICOORD bleft; //bounding box ICOORD tright; ICOORD block_bleft; //bounding box ICOORD block_tright; int xindex; //index to pixel BLOCK_LINE_IT line_it = block; //line iterator IMAGELINE bwline; //thresholded line //lines in progress CRACKEDGE **ptrline = new CRACKEDGE*[t_image->get_xsize()+1]; block->bounding_box (bleft, tright); // block box block_bleft = bleft; block_tright = tright; for (x = tright.x () - bleft.x (); x >= 0; x--) ptrline[x] = NULL; //no lines in progress bwline.init (t_image->get_xsize()); margin = WHITE_PIX; for (y = tright.y () - 1; y >= bleft.y () - 1; y--) { if (y >= block_bleft.y () && y < block_tright.y ()) { t_image->get_line (bleft.x (), y, tright.x () - bleft.x (), &bwline, 0); make_margins (block, &line_it, bwline.pixels, margin, bleft.x (), tright.x (), y); } else { x = tright.x () - bleft.x (); for (xindex = 0; xindex < x; xindex++) bwline.pixels[xindex] = margin; } line_edges (bleft.x (), y, tright.x () - bleft.x (), margin, bwline.pixels, ptrline); } free_crackedges(free_cracks); //really free them free_cracks = NULL; delete [] ptrline; }
void block_edges(Pix *t_pix, // thresholded image PDBLK *block, // block in image C_OUTLINE_IT* outline_it) { ICOORD bleft; // bounding box ICOORD tright; BLOCK_LINE_IT line_it = block; // line iterator int width = pixGetWidth(t_pix); int height = pixGetHeight(t_pix); int wpl = pixGetWpl(t_pix); // lines in progress CRACKEDGE **ptrline = new CRACKEDGE*[width + 1]; CRACKEDGE *free_cracks = NULL; block->bounding_box(bleft, tright); // block box int block_width = tright.x() - bleft.x(); for (int x = block_width; x >= 0; x--) ptrline[x] = NULL; // no lines in progress uinT8* bwline = new uinT8[width]; uinT8 margin = WHITE_PIX; for (int y = tright.y() - 1; y >= bleft.y() - 1; y--) { if (y >= bleft.y() && y < tright.y()) { // Get the binary pixels from the image. l_uint32* line = pixGetData(t_pix) + wpl * (height - 1 - y); for (int x = 0; x < block_width; ++x) { bwline[x] = GET_DATA_BIT(line, x + bleft.x()) ^ 1; } make_margins(block, &line_it, bwline, margin, bleft.x(), tright.x(), y); } else { memset(bwline, margin, block_width * sizeof(bwline[0])); } line_edges(bleft.x(), y, block_width, margin, bwline, ptrline, &free_cracks, outline_it); } free_crackedges(free_cracks); // really free them delete[] ptrline; delete[] bwline; }