All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
oldbasel.h File Reference
#include "params.h"
#include "blobbox.h"

Go to the source code of this file.

Functions

int get_blob_coords (TO_ROW *row, inT32 lineheight, TBOX *blobcoords, BOOL8 &holed_line, int &outcount)
 
void make_first_baseline (TBOX blobcoords[], int blobcount, int xcoords[], int ycoords[], QSPLINE *spline, QSPLINE *baseline, float jumplimit)
 
void make_holed_baseline (TBOX blobcoords[], int blobcount, QSPLINE *spline, QSPLINE *baseline, float gradient)
 
int partition_line (TBOX blobcoords[], int blobcount, int *numparts, char partids[], int partsizes[], QSPLINE *spline, float jumplimit, float ydiffs[])
 
void merge_oldbl_parts (TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int biggestpart, float jumplimit)
 
int get_ydiffs (TBOX blobcoords[], int blobcount, QSPLINE *spline, float ydiffs[])
 
int choose_partition (register float diff, float partdiffs[], int lastpart, float jumplimit, float *drift, float *last_delta, int *partcount)
 
int partition_coords (TBOX blobcoords[], int blobcount, char partids[], int bestpart, int xcoords[], int ycoords[])
 *merge_partitions(partids,partcount,blobcount,bestpart) discards funny looking More...
 
int segment_spline (TBOX blobcoords[], int blobcount, int xcoords[], int ycoords[], int degree, int pointcount, int xstarts[])
 
BOOL8 split_stepped_spline (QSPLINE *baseline, float jumplimit, int xcoords[], int xstarts[], int &segments)
 
void insert_spline_point (int xstarts[], int segment, int coord1, int coord2, int &segments)
 
void find_lesser_parts (TO_ROW *row, TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int partcount, int bestpart)
 
void old_first_xheight (TO_ROW *row, TBOX blobcoords[], int initialheight, int blobcount, QSPLINE *baseline, float jumplimit)
 
void make_first_xheight (TO_ROW *row, TBOX blobcoords[], int lineheight, int init_lineheight, int blobcount, QSPLINE *baseline, float jumplimit)
 
int * make_height_array (TBOX blobcoords[], int blobcount, QSPLINE *baseline)
 
void find_top_modes (STATS *stats, int statnum, int modelist[], int modenum)
 
void pick_x_height (TO_ROW *row, int modelist[], int lefts[], int rights[], STATS *heightstat, int mode_threshold)
 

Variables

bool textord_really_old_xheight = FALSE
 
bool textord_oldbl_debug = FALSE
 
bool textord_debug_baselines = FALSE
 
bool textord_oldbl_paradef = TRUE
 
bool textord_oldbl_split_splines = TRUE
 
bool textord_oldbl_merge_parts = TRUE
 
bool oldbl_xhfix = FALSE
 
int oldbl_holed_losscount = 10
 
double oldbl_dot_error_size = 1.26
 
double textord_oldbl_jumplimit = 0.15
 

Function Documentation

int choose_partition ( register float  diff,
float  partdiffs[],
int  lastpart,
float  jumplimit,
float *  drift,
float *  last_delta,
int *  partcount 
)

Definition at line 957 of file oldbasel.cpp.

965  {
966  register int partition; /*partition no */
967  int bestpart; /*best new partition */
968  float bestdelta; /*best gap from a part */
969  float delta; /*diff from part */
970 
971  if (lastpart < 0) {
972  partdiffs[0] = diff;
973  lastpart = 0; /*first point */
974  *drift = 0.0f;
975  *lastdelta = 0.0f;
976  }
977  /*adjusted diff from part */
978  delta = diff - partdiffs[lastpart] - *drift;
979  if (textord_oldbl_debug) {
980  tprintf ("Diff=%.2f, Delta=%.3f, Drift=%.3f, ", diff, delta, *drift);
981  }
982  if (ABS (delta) > jumplimit / 2) {
983  /*delta on part 0 */
984  bestdelta = diff - partdiffs[0] - *drift;
985  bestpart = 0; /*0 best so far */
986  for (partition = 1; partition < *partcount; partition++) {
987  delta = diff - partdiffs[partition] - *drift;
988  if (ABS (delta) < ABS (bestdelta)) {
989  bestdelta = delta;
990  bestpart = partition; /*part with nearest jump */
991  }
992  }
993  delta = bestdelta;
994  /*too far away */
995  if (ABS (bestdelta) > jumplimit
996  && *partcount < MAXPARTS) { /*and spare part left */
997  bestpart = (*partcount)++; /*best was new one */
998  /*start new one */
999  partdiffs[bestpart] = diff - *drift;
1000  delta = 0.0f;
1001  }
1002  }
1003  else {
1004  bestpart = lastpart; /*best was last one */
1005  }
1006 
1007  if (bestpart == lastpart
1008  && (ABS (delta - *lastdelta) < jumplimit / 2
1009  || ABS (delta) < jumplimit / 2))
1010  /*smooth the drift */
1011  *drift = (3 * *drift + delta) / 3;
1012  *lastdelta = delta;
1013 
1014  if (textord_oldbl_debug) {
1015  tprintf ("P=%d\n", bestpart);
1016  }
1017 
1018  return bestpart;
1019 }
#define tprintf(...)
Definition: tprintf.h:31
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:39
#define ABS(x)
Definition: oldbasel.cpp:73
#define MAXPARTS
Definition: oldbasel.cpp:70
void find_lesser_parts ( TO_ROW row,
TBOX  blobcoords[],
int  blobcount,
char  partids[],
int  partsizes[],
int  partcount,
int  bestpart 
)

Definition at line 1371 of file oldbasel.cpp.

1379  {
1380  register int blobindex; /*index of blob */
1381  register int partition; /*current partition */
1382  int xcentre; /*centre of blob */
1383  int poscount; /*count of best up step */
1384  int negcount; /*count of best down step */
1385  float partsteps[MAXPARTS]; /*average step to part */
1386  float bestneg; /*best down step */
1387  int runlength; /*length of bad run */
1388  int biggestrun; /*biggest bad run */
1389 
1390  biggestrun = 0;
1391  for (partition = 0; partition < partcount; partition++)
1392  partsteps[partition] = 0.0; /*zero accumulators */
1393  for (runlength = 0, blobindex = 0; blobindex < blobcount; blobindex++) {
1394  xcentre = (blobcoords[blobindex].left ()
1395  + blobcoords[blobindex].right ()) >> 1;
1396  /*in other parts */
1397  int part_id =
1398  static_cast<int>(static_cast<unsigned char>(partids[blobindex]));
1399  if (part_id != bestpart) {
1400  runlength++; /*run of non bests */
1401  if (runlength > biggestrun)
1402  biggestrun = runlength;
1403  partsteps[part_id] += blobcoords[blobindex].bottom()
1404  - row->baseline.y(xcentre);
1405  }
1406  else
1407  runlength = 0;
1408  }
1409  if (biggestrun > MAXBADRUN)
1410  row->xheight = -1.0f; /*failed */
1411  else
1412  row->xheight = 1.0f; /*success */
1413  poscount = negcount = 0;
1414  bestneg = 0.0; /*no step yet */
1415  for (partition = 0; partition < partcount; partition++) {
1416  if (partition != bestpart) {
1417 
1418  //by jetsoft divide by zero possible
1419  if (partsizes[partition]==0)
1420  partsteps[partition]=0;
1421  else
1422  partsteps[partition] /= partsizes[partition];
1423  //
1424 
1425 
1426  if (partsteps[partition] >= MINASCRISE
1427  && partsizes[partition] > poscount) {
1428  poscount = partsizes[partition];
1429  }
1430  if (partsteps[partition] <= -MINASCRISE
1431  && partsizes[partition] > negcount) {
1432  /*ascender rise */
1433  bestneg = partsteps[partition];
1434  /*2nd most popular */
1435  negcount = partsizes[partition];
1436  }
1437  }
1438  }
1439  /*average x-height */
1440  partsteps[bestpart] /= blobcount;
1441  row->descdrop = bestneg;
1442 }
#define MINASCRISE
Definition: oldbasel.cpp:60
QSPLINE baseline
Definition: blobbox.h:666
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
#define MAXBADRUN
Definition: oldbasel.cpp:64
double y(double x) const
Definition: quspline.cpp:217
inT16 bottom() const
Definition: rect.h:61
#define MAXPARTS
Definition: oldbasel.cpp:70
float xheight
Definition: blobbox.h:653
float descdrop
Definition: blobbox.h:656
void find_top_modes ( STATS stats,
int  statnum,
int  modelist[],
int  modenum 
)

Definition at line 1624 of file oldbasel.cpp.

1628  {
1629  int mode_count;
1630  int last_i = 0;
1631  int last_max = MAX_INT32;
1632  int i;
1633  int mode;
1634  int total_max = 0;
1635  int mode_factor = textord_ocropus_mode ?
1637 
1638  for (mode_count = 0; mode_count < modenum; mode_count++) {
1639  mode = 0;
1640  for (i = 0; i < statnum; i++) {
1641  if (stats->pile_count (i) > stats->pile_count (mode)) {
1642  if ((stats->pile_count (i) < last_max) ||
1643  ((stats->pile_count (i) == last_max) && (i > last_i))) {
1644  mode = i;
1645  }
1646  }
1647  }
1648  last_i = mode;
1649  last_max = stats->pile_count (last_i);
1650  total_max += last_max;
1651  if (last_max <= total_max / mode_factor)
1652  mode = 0;
1653  modelist[mode_count] = mode;
1654  }
1655 }
const int kMinModeFactor
Definition: oldbasel.cpp:1621
CMD_EVENTS mode
Definition: pgedit.cpp:116
#define MAX_INT32
Definition: host.h:120
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:47
inT32 pile_count(inT32 value) const
Definition: statistc.h:78
const int kMinModeFactorOcropus
Definition: oldbasel.cpp:1620
int get_blob_coords ( TO_ROW row,
inT32  lineheight,
TBOX blobcoords,
BOOL8 holed_line,
int &  outcount 
)

Definition at line 441 of file oldbasel.cpp.

447  {
448  //blobs
449  BLOBNBOX_IT blob_it = row->blob_list ();
450  register int blobindex; /*no along text line */
451  int losscount; //lost blobs
452  int maxlosscount; //greatest lost blobs
453  /*height stat collection */
454  STATS heightstat (0, MAXHEIGHT);
455 
456  if (blob_it.empty ())
457  return 0; //none
458  maxlosscount = 0;
459  losscount = 0;
460  blob_it.mark_cycle_pt ();
461  blobindex = 0;
462  do {
463  blobcoords[blobindex] = box_next_pre_chopped (&blob_it);
464  if (blobcoords[blobindex].height () > lineheight * 0.25)
465  heightstat.add (blobcoords[blobindex].height (), 1);
466  if (blobindex == 0
467  || blobcoords[blobindex].height () > lineheight * 0.25
468  || blob_it.cycled_list ()) {
469  blobindex++; /*no of merged blobs */
470  losscount = 0;
471  }
472  else {
473  if (blobcoords[blobindex].height ()
474  < blobcoords[blobindex].width () * oldbl_dot_error_size
475  && blobcoords[blobindex].width ()
476  < blobcoords[blobindex].height () * oldbl_dot_error_size) {
477  //counts as dot
478  blobindex++;
479  losscount = 0;
480  }
481  else {
482  losscount++; //lost it
483  if (losscount > maxlosscount)
484  //remember max
485  maxlosscount = losscount;
486  }
487  }
488  }
489  while (!blob_it.cycled_list ());
490 
491  holed_line = maxlosscount > oldbl_holed_losscount;
492  outcount = blobindex; /*total blobs */
493 
494  if (heightstat.get_total () > 1)
495  /*guess x-height */
496  return (int) heightstat.ile (0.25);
497  else
498  return blobcoords[0].height ();
499 }
Definition: statistc.h:33
BLOBNBOX_LIST * blob_list()
Definition: blobbox.h:595
EXTERN double oldbl_dot_error_size
Definition: oldbasel.cpp:51
#define MAXHEIGHT
Definition: oldbasel.cpp:62
inT16 height() const
Definition: rect.h:104
inT16 width() const
Definition: rect.h:111
TBOX box_next_pre_chopped(BLOBNBOX_IT *it)
Definition: blobbox.cpp:658
EXTERN int oldbl_holed_losscount
Definition: oldbasel.cpp:50
int get_ydiffs ( TBOX  blobcoords[],
int  blobcount,
QSPLINE spline,
float  ydiffs[] 
)

Definition at line 906 of file oldbasel.cpp.

911  {
912  register int blobindex; /*current blob */
913  int xcentre; /*xcoord */
914  int lastx; /*last xcentre */
915  float diffsum; /*sum of diffs */
916  float diff; /*current difference */
917  float drift; /*sum of spline steps */
918  float bestsum; /*smallest diffsum */
919  int bestindex; /*index of bestsum */
920 
921  diffsum = 0.0f;
922  bestindex = 0;
923  bestsum = (float) MAX_INT32;
924  drift = 0.0f;
925  lastx = blobcoords[0].left ();
926  /*do each blob in row */
927  for (blobindex = 0; blobindex < blobcount; blobindex++) {
928  /*centre of blob */
929  xcentre = (blobcoords[blobindex].left () + blobcoords[blobindex].right ()) >> 1;
930  //step functions in spline
931  drift += spline->step (lastx, xcentre);
932  lastx = xcentre;
933  diff = blobcoords[blobindex].bottom ();
934  diff -= spline->y (xcentre);
935  diff += drift;
936  ydiffs[blobindex] = diff; /*store difference */
937  if (blobindex > 2)
938  /*remove old one */
939  diffsum -= ABS (ydiffs[blobindex - 3]);
940  diffsum += ABS (diff); /*add new one */
941  if (blobindex >= 2 && diffsum < bestsum) {
942  bestsum = diffsum; /*find min sum */
943  bestindex = blobindex - 1; /*middle of set */
944  }
945  }
946  return bestindex;
947 }
double step(double x1, double x2)
Definition: quspline.cpp:192
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
#define MAX_INT32
Definition: host.h:120
double y(double x) const
Definition: quspline.cpp:217
inT16 bottom() const
Definition: rect.h:61
#define ABS(x)
Definition: oldbasel.cpp:73
void insert_spline_point ( int  xstarts[],
int  segment,
int  coord1,
int  coord2,
int &  segments 
)

Definition at line 1347 of file oldbasel.cpp.

1352  {
1353  int index; //for shuffling
1354 
1355  for (index = segments; index > segment; index--)
1356  xstarts[index + 1] = xstarts[index];
1357  segments++;
1358  xstarts[segment] = coord1;
1359  xstarts[segment + 1] = coord2;
1360 }
void make_first_baseline ( TBOX  blobcoords[],
int  blobcount,
int  xcoords[],
int  ycoords[],
QSPLINE spline,
QSPLINE baseline,
float  jumplimit 
)

Definition at line 511 of file oldbasel.cpp.

519  {
520  int leftedge; /*left edge of line */
521  int rightedge; /*right edge of line */
522  int blobindex; /*current blob */
523  int segment; /*current segment */
524  float prevy, thisy, nexty; /*3 y coords */
525  float y1, y2, y3; /*3 smooth blobs */
526  float maxmax, minmin; /*absolute limits */
527  int x2 = 0; /*right edge of old y3 */
528  int ycount; /*no of ycoords in use */
529  float yturns[SPLINESIZE]; /*y coords of turn pts */
530  int xturns[SPLINESIZE]; /*xcoords of turn pts */
531  int xstarts[SPLINESIZE + 1];
532  int segments; //no of segments
533  ICOORD shift; //shift of spline
534 
535  prevy = 0;
536  /*left edge of row */
537  leftedge = blobcoords[0].left ();
538  /*right edge of line */
539  rightedge = blobcoords[blobcount - 1].right ();
540  if (spline == NULL /*no given spline */
541  || spline->segments < 3 /*or trivial */
542  /*or too non-overlap */
543  || spline->xcoords[1] > leftedge + MAXOVERLAP * (rightedge - leftedge)
544  || spline->xcoords[spline->segments - 1] < rightedge
545  - MAXOVERLAP * (rightedge - leftedge)) {
547  return; //use default
548  xstarts[0] = blobcoords[0].left () - 1;
549  for (blobindex = 0; blobindex < blobcount; blobindex++) {
550  xcoords[blobindex] = (blobcoords[blobindex].left ()
551  + blobcoords[blobindex].right ()) / 2;
552  ycoords[blobindex] = blobcoords[blobindex].bottom ();
553  }
554  xstarts[1] = blobcoords[blobcount - 1].right () + 1;
555  segments = 1; /*no of segments */
556 
557  /*linear */
558  *baseline = QSPLINE (xstarts, segments, xcoords, ycoords, blobcount, 1);
559 
560  if (blobcount >= 3) {
561  y1 = y2 = y3 = 0.0f;
562  ycount = 0;
563  segment = 0; /*no of segments */
564  maxmax = minmin = 0.0f;
565  thisy = ycoords[0] - baseline->y (xcoords[0]);
566  nexty = ycoords[1] - baseline->y (xcoords[1]);
567  for (blobindex = 2; blobindex < blobcount; blobindex++) {
568  prevy = thisy; /*shift ycoords */
569  thisy = nexty;
570  nexty = ycoords[blobindex] - baseline->y (xcoords[blobindex]);
571  /*middle of smooth y */
572  if (ABS (thisy - prevy) < jumplimit && ABS (thisy - nexty) < jumplimit) {
573  y1 = y2; /*shift window */
574  y2 = y3;
575  y3 = thisy; /*middle point */
576  ycount++;
577  /*local max */
578  if (ycount >= 3 && ((y1 < y2 && y2 >= y3)
579  /*local min */
580  || (y1 > y2 && y2 <= y3))) {
581  if (segment < SPLINESIZE - 2) {
582  /*turning pt */
583  xturns[segment] = x2;
584  yturns[segment] = y2;
585  segment++; /*no of spline segs */
586  }
587  }
588  if (ycount == 1) {
589  maxmax = minmin = y3;/*initialise limits */
590  }
591  else {
592  if (y3 > maxmax)
593  maxmax = y3; /*biggest max */
594  if (y3 < minmin)
595  minmin = y3; /*smallest min */
596  }
597  /*possible turning pt */
598  x2 = blobcoords[blobindex - 1].right ();
599  }
600  }
601 
602  jumplimit *= 1.2;
603  /*must be wavy */
604  if (maxmax - minmin > jumplimit) {
605  ycount = segment; /*no of segments */
606  for (blobindex = 0, segment = 1; blobindex < ycount;
607  blobindex++) {
608  if (yturns[blobindex] > minmin + jumplimit
609  || yturns[blobindex] < maxmax - jumplimit) {
610  /*significant peak */
611  if (segment == 1
612  || yturns[blobindex] > prevy + jumplimit
613  || yturns[blobindex] < prevy - jumplimit) {
614  /*different to previous */
615  xstarts[segment] = xturns[blobindex];
616  segment++;
617  prevy = yturns[blobindex];
618  }
619  /*bigger max */
620  else if ((prevy > minmin + jumplimit && yturns[blobindex] > prevy)
621  /*smaller min */
622  || (prevy < maxmax - jumplimit && yturns[blobindex] < prevy)) {
623  xstarts[segment - 1] = xturns[blobindex];
624  /*improved previous */
625  prevy = yturns[blobindex];
626  }
627  }
628  }
629  xstarts[segment] = blobcoords[blobcount - 1].right () + 1;
630  segments = segment; /*no of segments */
631  /*linear */
632  *baseline = QSPLINE (xstarts, segments, xcoords, ycoords, blobcount, 1);
633  }
634  }
635  }
636  else {
637  *baseline = *spline; /*copy it */
638  shift = ICOORD (0, (inT16) (blobcoords[0].bottom ()
639  - spline->y (blobcoords[0].right ())));
640  baseline->move (shift);
641  }
642 }
inT16 right() const
Definition: rect.h:75
EXTERN bool textord_oldbl_paradef
Definition: oldbasel.cpp:41
void move(ICOORD vec)
Definition: quspline.cpp:259
inT16 left() const
Definition: rect.h:68
#define SPLINESIZE
Definition: oldbasel.cpp:71
#define MAXOVERLAP
Definition: oldbasel.cpp:63
double y(double x) const
Definition: quspline.cpp:217
integer coordinate
Definition: points.h:30
inT16 bottom() const
Definition: rect.h:61
#define ABS(x)
Definition: oldbasel.cpp:73
#define NULL
Definition: host.h:144
short inT16
Definition: host.h:100
void make_first_xheight ( TO_ROW row,
TBOX  blobcoords[],
int  lineheight,
int  init_lineheight,
int  blobcount,
QSPLINE baseline,
float  jumplimit 
)

Definition at line 1539 of file oldbasel.cpp.

1547  {
1548  STATS heightstat (0, HEIGHTBUCKETS);
1549  int lefts[HEIGHTBUCKETS];
1550  int rights[HEIGHTBUCKETS];
1551  int modelist[MODENUM];
1552  int blobindex;
1553  int mode_count; //blobs to count in thr
1554  int sign_bit;
1555  int mode_threshold;
1556  const int kBaselineTouch = 2; // This really should change with resolution.
1557  const int kGoodStrength = 8; // Strength of baseline-touching heights.
1558  const float kMinHeight = 0.25; // Min fraction of lineheight to use.
1559 
1560  sign_bit = row->xheight > 0 ? 1 : -1;
1561 
1562  memset(lefts, 0, HEIGHTBUCKETS * sizeof(lefts[0]));
1563  memset(rights, 0, HEIGHTBUCKETS * sizeof(rights[0]));
1564  mode_count = 0;
1565  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1566  int xcenter = (blobcoords[blobindex].left () +
1567  blobcoords[blobindex].right ()) / 2;
1568  float base = baseline->y(xcenter);
1569  float bottomdiff = fabs(base - blobcoords[blobindex].bottom());
1570  int strength = textord_ocropus_mode &&
1571  bottomdiff <= kBaselineTouch ? kGoodStrength : 1;
1572  int height = static_cast<int>(blobcoords[blobindex].top () - base + 0.5);
1573  if (blobcoords[blobindex].height () > init_lineheight * kMinHeight) {
1574  if (height > lineheight * oldbl_xhfract
1575  && height > textord_min_xheight) {
1576  heightstat.add (height, strength);
1577  if (height < HEIGHTBUCKETS) {
1578  if (xcenter > rights[height])
1579  rights[height] = xcenter;
1580  if (xcenter > 0 && (lefts[height] == 0 || xcenter < lefts[height]))
1581  lefts[height] = xcenter;
1582  }
1583  }
1584  mode_count += strength;
1585  }
1586  }
1587 
1588  mode_threshold = (int) (blobcount * 0.1);
1589  if (oldbl_dot_error_size > 1 || oldbl_xhfix)
1590  mode_threshold = (int) (mode_count * 0.1);
1591 
1592  if (textord_oldbl_debug) {
1593  tprintf ("blobcount=%d, mode_count=%d, mode_t=%d\n",
1594  blobcount, mode_count, mode_threshold);
1595  }
1596  find_top_modes(&heightstat, HEIGHTBUCKETS, modelist, MODENUM);
1597  if (textord_oldbl_debug) {
1598  for (blobindex = 0; blobindex < MODENUM; blobindex++)
1599  tprintf ("mode[%d]=%d ", blobindex, modelist[blobindex]);
1600  tprintf ("\n");
1601  }
1602  pick_x_height(row, modelist, lefts, rights, &heightstat, mode_threshold);
1603 
1604  if (textord_oldbl_debug)
1605  tprintf ("Output xheight=%g\n", row->xheight);
1606  if (row->xheight < 0 && textord_oldbl_debug)
1607  tprintf ("warning: Row Line height < 0; %4.2f\n", row->xheight);
1608 
1609  if (sign_bit < 0)
1610  row->xheight = -row->xheight;
1611 }
#define tprintf(...)
Definition: tprintf.h:31
Definition: statistc.h:33
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:39
EXTERN bool oldbl_xhfix
Definition: oldbasel.cpp:46
inT16 right() const
Definition: rect.h:75
#define MODENUM
Definition: oldbasel.cpp:69
EXTERN double oldbl_xhfract
Definition: oldbasel.cpp:48
EXTERN double oldbl_dot_error_size
Definition: oldbasel.cpp:51
inT16 left() const
Definition: rect.h:68
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:47
void pick_x_height(TO_ROW *row, int modelist[], int lefts[], int rights[], STATS *heightstat, int mode_threshold)
Definition: oldbasel.cpp:1664
double y(double x) const
Definition: quspline.cpp:217
int textord_min_xheight
Definition: makerow.cpp:69
#define HEIGHTBUCKETS
Definition: oldbasel.cpp:65
void find_top_modes(STATS *stats, int statnum, int modelist[], int modenum)
Definition: oldbasel.cpp:1624
float xheight
Definition: blobbox.h:653
inT16 top() const
Definition: rect.h:54
int* make_height_array ( TBOX  blobcoords[],
int  blobcount,
QSPLINE baseline 
)
void make_holed_baseline ( TBOX  blobcoords[],
int  blobcount,
QSPLINE spline,
QSPLINE baseline,
float  gradient 
)

Definition at line 654 of file oldbasel.cpp.

660  {
661  int leftedge; /*left edge of line */
662  int rightedge; /*right edge of line */
663  int blobindex; /*current blob */
664  float x; //centre of row
665  ICOORD shift; //shift of spline
666 
667  tesseract::DetLineFit lms; // straight baseline
668  inT32 xstarts[2]; //straight line
669  double coeffs[3];
670  float c; //line parameter
671 
672  /*left edge of row */
673  leftedge = blobcoords[0].left ();
674  /*right edge of line */
675  rightedge = blobcoords[blobcount - 1].right();
676  for (blobindex = 0; blobindex < blobcount; blobindex++) {
677  lms.Add(ICOORD((blobcoords[blobindex].left() +
678  blobcoords[blobindex].right()) / 2,
679  blobcoords[blobindex].bottom()));
680  }
681  lms.ConstrainedFit(gradient, &c);
682  xstarts[0] = leftedge;
683  xstarts[1] = rightedge;
684  coeffs[0] = 0;
685  coeffs[1] = gradient;
686  coeffs[2] = c;
687  *baseline = QSPLINE (1, xstarts, coeffs);
688  if (spline != NULL /*no given spline */
689  && spline->segments >= 3 /*or trivial */
690  /*or too non-overlap */
691  && spline->xcoords[1] <= leftedge + MAXOVERLAP * (rightedge - leftedge)
692  && spline->xcoords[spline->segments - 1] >= rightedge
693  - MAXOVERLAP * (rightedge - leftedge)) {
694  *baseline = *spline; /*copy it */
695  x = (leftedge + rightedge) / 2.0;
696  shift = ICOORD (0, (inT16) (gradient * x + c - spline->y (x)));
697  baseline->move (shift);
698  }
699 }
inT16 right() const
Definition: rect.h:75
void move(ICOORD vec)
Definition: quspline.cpp:259
inT16 left() const
Definition: rect.h:68
#define MAXOVERLAP
Definition: oldbasel.cpp:63
double y(double x) const
Definition: quspline.cpp:217
integer coordinate
Definition: points.h:30
void Add(const ICOORD &pt)
Definition: detlinefit.cpp:52
#define NULL
Definition: host.h:144
double ConstrainedFit(const FCOORD &direction, double min_dist, double max_dist, bool debug, ICOORD *line_pt)
Definition: detlinefit.cpp:131
short inT16
Definition: host.h:100
int inT32
Definition: host.h:102
void merge_oldbl_parts ( TBOX  blobcoords[],
int  blobcount,
char  partids[],
int  partsizes[],
int  biggestpart,
float  jumplimit 
)

Definition at line 793 of file oldbasel.cpp.

800  {
801  BOOL8 found_one; //found a bestpart blob
802  BOOL8 close_one; //found was close enough
803  register int blobindex; /*no along text line */
804  int prevpart; //previous iteration
805  int runlength; //no in this part
806  float diff; /*difference from line */
807  int startx; /*index of start blob */
808  int test_blob; //another index
809  FCOORD coord; //blob coordinate
810  float m, c; //fitted line
811  QLSQ stats; //line stuff
812 
813  prevpart = biggestpart;
814  runlength = 0;
815  startx = 0;
816  for (blobindex = 0; blobindex < blobcount; blobindex++) {
817  if (partids[blobindex] != prevpart) {
818  // tprintf("Partition change at (%d,%d) from %d to %d after run of %d\n",
819  // blobcoords[blobindex].left(),blobcoords[blobindex].bottom(),
820  // prevpart,partids[blobindex],runlength);
821  if (prevpart != biggestpart && runlength > MAXBADRUN) {
822  stats.clear ();
823  for (test_blob = startx; test_blob < blobindex; test_blob++) {
824  coord = FCOORD ((blobcoords[test_blob].left ()
825  + blobcoords[test_blob].right ()) / 2.0,
826  blobcoords[test_blob].bottom ());
827  stats.add (coord.x (), coord.y ());
828  }
829  stats.fit (1);
830  m = stats.get_b ();
831  c = stats.get_c ();
833  tprintf ("Fitted line y=%g x + %g\n", m, c);
834  found_one = FALSE;
835  close_one = FALSE;
836  for (test_blob = 1; !found_one
837  && (startx - test_blob >= 0
838  || blobindex + test_blob <= blobcount); test_blob++) {
839  if (startx - test_blob >= 0
840  && partids[startx - test_blob] == biggestpart) {
841  found_one = TRUE;
842  coord = FCOORD ((blobcoords[startx - test_blob].left ()
843  + blobcoords[startx -
844  test_blob].right ()) /
845  2.0,
846  blobcoords[startx -
847  test_blob].bottom ());
848  diff = m * coord.x () + c - coord.y ();
850  tprintf
851  ("Diff of common blob to suspect part=%g at (%g,%g)\n",
852  diff, coord.x (), coord.y ());
853  if (diff < jumplimit && -diff < jumplimit)
854  close_one = TRUE;
855  }
856  if (blobindex + test_blob <= blobcount
857  && partids[blobindex + test_blob - 1] == biggestpart) {
858  found_one = TRUE;
859  coord =
860  FCOORD ((blobcoords[blobindex + test_blob - 1].
861  left () + blobcoords[blobindex + test_blob -
862  1].right ()) / 2.0,
863  blobcoords[blobindex + test_blob -
864  1].bottom ());
865  diff = m * coord.x () + c - coord.y ();
867  tprintf
868  ("Diff of common blob to suspect part=%g at (%g,%g)\n",
869  diff, coord.x (), coord.y ());
870  if (diff < jumplimit && -diff < jumplimit)
871  close_one = TRUE;
872  }
873  }
874  if (close_one) {
876  tprintf
877  ("Merged %d blobs back into part %d from %d starting at (%d,%d)\n",
878  runlength, biggestpart, prevpart,
879  blobcoords[startx].left (),
880  blobcoords[startx].bottom ());
881  //switch sides
882  partsizes[prevpart] -= runlength;
883  for (test_blob = startx; test_blob < blobindex; test_blob++)
884  partids[test_blob] = biggestpart;
885  }
886  }
887  prevpart = partids[blobindex];
888  runlength = 1;
889  startx = blobindex;
890  }
891  else
892  runlength++;
893  }
894 }
float x() const
Definition: points.h:209
#define tprintf(...)
Definition: tprintf.h:31
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:39
unsigned char BOOL8
Definition: host.h:113
void add(double x, double y)
Definition: quadlsq.cpp:56
void fit(int degree)
Definition: quadlsq.cpp:100
#define MAXBADRUN
Definition: oldbasel.cpp:64
#define FALSE
Definition: capi.h:29
double get_b()
Definition: quadlsq.h:48
#define TRUE
Definition: capi.h:28
float y() const
Definition: points.h:212
Definition: quadlsq.h:25
double get_c()
Definition: quadlsq.h:51
Definition: points.h:189
void clear()
Definition: quadlsq.cpp:34
void old_first_xheight ( TO_ROW row,
TBOX  blobcoords[],
int  initialheight,
int  blobcount,
QSPLINE baseline,
float  jumplimit 
)

Definition at line 1454 of file oldbasel.cpp.

1461  {
1462  register int blobindex; /*current blob */
1463  /*height statistics */
1464  STATS heightstat (0, MAXHEIGHT);
1465  int height; /*height of blob */
1466  int xcentre; /*centre of blob */
1467  int lineheight; /*approx xheight */
1468  float ascenders; /*ascender sum */
1469  int asccount; /*no of ascenders */
1470  float xsum; /*xheight sum */
1471  int xcount; /*xheight count */
1472  register float diff; /*height difference */
1473 
1474  if (blobcount > 1) {
1475  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1476  xcentre = (blobcoords[blobindex].left ()
1477  + blobcoords[blobindex].right ()) / 2;
1478  /*height of blob */
1479  height = (int) (blobcoords[blobindex].top () - baseline->y (xcentre) + 0.5);
1480  if (height > initialheight * oldbl_xhfract
1481  && height > textord_min_xheight)
1482  heightstat.add (height, 1);
1483  }
1484  if (heightstat.get_total () > 3) {
1485  lineheight = (int) heightstat.ile (0.25);
1486  if (lineheight <= 0)
1487  lineheight = (int) heightstat.ile (0.5);
1488  }
1489  else
1490  lineheight = initialheight;
1491  }
1492  else {
1493  lineheight = (int) (blobcoords[0].top ()
1494  - baseline->y ((blobcoords[0].left ()
1495  + blobcoords[0].right ()) / 2) +
1496  0.5);
1497  }
1498 
1499  xsum = 0.0f;
1500  xcount = 0;
1501  for (ascenders = 0.0f, asccount = 0, blobindex = 0; blobindex < blobcount;
1502  blobindex++) {
1503  xcentre = (blobcoords[blobindex].left ()
1504  + blobcoords[blobindex].right ()) / 2;
1505  diff = blobcoords[blobindex].top () - baseline->y (xcentre);
1506  /*is it ascender */
1507  if (diff > lineheight + jumplimit) {
1508  ascenders += diff;
1509  asccount++; /*count ascenders */
1510  }
1511  else if (diff > lineheight - jumplimit) {
1512  xsum += diff; /*mean xheight */
1513  xcount++;
1514  }
1515  }
1516  if (xcount > 0)
1517  xsum /= xcount; /*average xheight */
1518  else
1519  xsum = (float) lineheight; /*guess it */
1520  row->xheight *= xsum;
1521  if (asccount > 0)
1522  row->ascrise = ascenders / asccount - xsum;
1523  else
1524  row->ascrise = 0.0f; /*had none */
1525  if (row->xheight == 0)
1526  row->xheight = -1.0f;
1527 }
Definition: statistc.h:33
inT16 right() const
Definition: rect.h:75
EXTERN double oldbl_xhfract
Definition: oldbasel.cpp:48
inT16 left() const
Definition: rect.h:68
float ascrise
Definition: blobbox.h:655
#define MAXHEIGHT
Definition: oldbasel.cpp:62
double y(double x) const
Definition: quspline.cpp:217
int textord_min_xheight
Definition: makerow.cpp:69
float xheight
Definition: blobbox.h:653
inT16 top() const
Definition: rect.h:54
int partition_coords ( TBOX  blobcoords[],
int  blobcount,
char  partids[],
int  bestpart,
int  xcoords[],
int  ycoords[] 
)

*merge_partitions(partids,partcount,blobcount,bestpart) discards funny looking

Definition at line 1084 of file oldbasel.cpp.

1091  {
1092  register int blobindex; /*no along text line */
1093  int pointcount; /*no of points */
1094 
1095  pointcount = 0;
1096  for (blobindex = 0; blobindex < blobcount; blobindex++) {
1097  if (partids[blobindex] == bestpart) {
1098  /*centre of blob */
1099  xcoords[pointcount] = (blobcoords[blobindex].left () + blobcoords[blobindex].right ()) >> 1;
1100  ycoords[pointcount++] = blobcoords[blobindex].bottom ();
1101  }
1102  }
1103  return pointcount; /*no of points found */
1104 }
inT16 right() const
Definition: rect.h:75
inT16 left() const
Definition: rect.h:68
inT16 bottom() const
Definition: rect.h:61
int partition_line ( TBOX  blobcoords[],
int  blobcount,
int *  numparts,
char  partids[],
int  partsizes[],
QSPLINE spline,
float  jumplimit,
float  ydiffs[] 
)

Definition at line 712 of file oldbasel.cpp.

721  {
722  register int blobindex; /*no along text line */
723  int bestpart; /*best new partition */
724  int biggestpart; /*part with most members */
725  float diff; /*difference from line */
726  int startx; /*index of start blob */
727  float partdiffs[MAXPARTS]; /*step between parts */
728 
729  for (bestpart = 0; bestpart < MAXPARTS; bestpart++)
730  partsizes[bestpart] = 0; /*zero them all */
731 
732  startx = get_ydiffs (blobcoords, blobcount, spline, ydiffs);
733  *numparts = 1; /*1 partition */
734  bestpart = -1; /*first point */
735  float drift = 0.0f;
736  float last_delta = 0.0f;
737  for (blobindex = startx; blobindex < blobcount; blobindex++) {
738  /*do each blob in row */
739  diff = ydiffs[blobindex]; /*diff from line */
740  if (textord_oldbl_debug) {
741  tprintf ("%d(%d,%d), ", blobindex,
742  blobcoords[blobindex].left (),
743  blobcoords[blobindex].bottom ());
744  }
745  bestpart = choose_partition(diff, partdiffs, bestpart, jumplimit,
746  &drift, &last_delta, numparts);
747  /*record partition */
748  partids[blobindex] = bestpart;
749  partsizes[bestpart]++; /*another in it */
750  }
751 
752  bestpart = -1; /*first point */
753  drift = 0.0f;
754  last_delta = 0.0f;
755  partsizes[0]--; /*doing 1st pt again */
756  /*do each blob in row */
757  for (blobindex = startx; blobindex >= 0; blobindex--) {
758  diff = ydiffs[blobindex]; /*diff from line */
759  if (textord_oldbl_debug) {
760  tprintf ("%d(%d,%d), ", blobindex,
761  blobcoords[blobindex].left (),
762  blobcoords[blobindex].bottom ());
763  }
764  bestpart = choose_partition(diff, partdiffs, bestpart, jumplimit,
765  &drift, &last_delta, numparts);
766  /*record partition */
767  partids[blobindex] = bestpart;
768  partsizes[bestpart]++; /*another in it */
769  }
770 
771  for (biggestpart = 0, bestpart = 1; bestpart < *numparts; bestpart++)
772  if (partsizes[bestpart] >= partsizes[biggestpart])
773  biggestpart = bestpart; /*new biggest */
775  merge_oldbl_parts(blobcoords,
776  blobcount,
777  partids,
778  partsizes,
779  biggestpart,
780  jumplimit);
781  return biggestpart; /*biggest partition */
782 }
EXTERN bool textord_oldbl_merge_parts
Definition: oldbasel.cpp:43
#define tprintf(...)
Definition: tprintf.h:31
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:39
int get_ydiffs(TBOX blobcoords[], int blobcount, QSPLINE *spline, float ydiffs[])
Definition: oldbasel.cpp:906
void merge_oldbl_parts(TBOX blobcoords[], int blobcount, char partids[], int partsizes[], int biggestpart, float jumplimit)
Definition: oldbasel.cpp:793
int choose_partition(register float diff, float partdiffs[], int lastpart, float jumplimit, float *drift, float *lastdelta, int *partcount)
Definition: oldbasel.cpp:957
#define MAXPARTS
Definition: oldbasel.cpp:70
void pick_x_height ( TO_ROW row,
int  modelist[],
int  lefts[],
int  rights[],
STATS heightstat,
int  mode_threshold 
)

Definition at line 1664 of file oldbasel.cpp.

1668  {
1669  int x;
1670  int y;
1671  int z;
1672  float ratio;
1673  int found_one_bigger = FALSE;
1674  int best_x_height = 0;
1675  int best_asc = 0;
1676  int num_in_best;
1677 
1678  for (x = 0; x < MODENUM; x++) {
1679  for (y = 0; y < MODENUM; y++) {
1680  /* Check for two modes */
1681  if (modelist[x] && modelist[y] &&
1682  heightstat->pile_count (modelist[x]) > mode_threshold &&
1684  MIN(rights[modelist[x]], rights[modelist[y]]) >
1685  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1686  ratio = (float) modelist[y] / (float) modelist[x];
1687  if (1.2 < ratio && ratio < 1.8) {
1688  /* Two modes found */
1689  best_x_height = modelist[x];
1690  num_in_best = heightstat->pile_count (modelist[x]);
1691 
1692  /* Try to get one higher */
1693  do {
1694  found_one_bigger = FALSE;
1695  for (z = 0; z < MODENUM; z++) {
1696  if (modelist[z] == best_x_height + 1 &&
1698  MIN(rights[modelist[x]], rights[modelist[y]]) >
1699  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1700  ratio = (float) modelist[y] / (float) modelist[z];
1701  if ((1.2 < ratio && ratio < 1.8) &&
1702  /* Should be half of best */
1703  heightstat->pile_count (modelist[z]) >
1704  num_in_best * 0.5) {
1705  best_x_height++;
1706  found_one_bigger = TRUE;
1707  break;
1708  }
1709  }
1710  }
1711  }
1712  while (found_one_bigger);
1713 
1714  /* try to get a higher ascender */
1715 
1716  best_asc = modelist[y];
1717  num_in_best = heightstat->pile_count (modelist[y]);
1718 
1719  /* Try to get one higher */
1720  do {
1721  found_one_bigger = FALSE;
1722  for (z = 0; z < MODENUM; z++) {
1723  if (modelist[z] > best_asc &&
1725  MIN(rights[modelist[x]], rights[modelist[y]]) >
1726  MAX(lefts[modelist[x]], lefts[modelist[y]]))) {
1727  ratio = (float) modelist[z] / (float) best_x_height;
1728  if ((1.2 < ratio && ratio < 1.8) &&
1729  /* Should be half of best */
1730  heightstat->pile_count (modelist[z]) >
1731  num_in_best * 0.5) {
1732  best_asc = modelist[z];
1733  found_one_bigger = TRUE;
1734  break;
1735  }
1736  }
1737  }
1738  }
1739  while (found_one_bigger);
1740 
1741  row->xheight = (float) best_x_height;
1742  row->ascrise = (float) best_asc - best_x_height;
1743  return;
1744  }
1745  }
1746  }
1747  }
1748 
1749  best_x_height = modelist[0]; /* Single Mode found */
1750  num_in_best = heightstat->pile_count (best_x_height);
1751  do {
1752  /* Try to get one higher */
1753  found_one_bigger = FALSE;
1754  for (z = 1; z < MODENUM; z++) {
1755  /* Should be half of best */
1756  if ((modelist[z] == best_x_height + 1) &&
1757  (heightstat->pile_count (modelist[z]) > num_in_best * 0.5)) {
1758  best_x_height++;
1759  found_one_bigger = TRUE;
1760  break;
1761  }
1762  }
1763  }
1764  while (found_one_bigger);
1765 
1766  row->ascrise = 0.0f;
1767  row->xheight = (float) best_x_height;
1768  if (row->xheight == 0)
1769  row->xheight = -1.0f;
1770 }
#define MAX(x, y)
Definition: ndminx.h:24
#define MIN(x, y)
Definition: ndminx.h:28
#define MODENUM
Definition: oldbasel.cpp:69
float ascrise
Definition: blobbox.h:655
EXTERN bool textord_ocropus_mode
Definition: oldbasel.cpp:47
#define FALSE
Definition: capi.h:29
#define TRUE
Definition: capi.h:28
inT32 pile_count(inT32 value) const
Definition: statistc.h:78
float xheight
Definition: blobbox.h:653
int segment_spline ( TBOX  blobcoords[],
int  blobcount,
int  xcoords[],
int  ycoords[],
int  degree,
int  pointcount,
int  xstarts[] 
)

Definition at line 1115 of file oldbasel.cpp.

1122  {
1123  register int ptindex; /*no along text line */
1124  register int segment; /*partition no */
1125  int lastmin, lastmax; /*possible turn points */
1126  int turnpoints[SPLINESIZE]; /*good turning points */
1127  int turncount; /*no of turning points */
1128  int max_x; //max specified coord
1129 
1130  xstarts[0] = xcoords[0] - 1; //leftmost defined pt
1131  max_x = xcoords[pointcount - 1] + 1;
1132  if (degree < 2)
1133  pointcount = 0;
1134  turncount = 0; /*no turning points yet */
1135  if (pointcount > 3) {
1136  ptindex = 1;
1137  lastmax = lastmin = 0; /*start with first one */
1138  while (ptindex < pointcount - 1 && turncount < SPLINESIZE - 1) {
1139  /*minimum */
1140  if (ycoords[ptindex - 1] > ycoords[ptindex] && ycoords[ptindex] <= ycoords[ptindex + 1]) {
1141  if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT) {
1142  if (turncount == 0 || turnpoints[turncount - 1] != lastmax)
1143  /*new max point */
1144  turnpoints[turncount++] = lastmax;
1145  lastmin = ptindex; /*latest minimum */
1146  }
1147  else if (ycoords[ptindex] < ycoords[lastmin]) {
1148  lastmin = ptindex; /*lower minimum */
1149  }
1150  }
1151 
1152  /*maximum */
1153  if (ycoords[ptindex - 1] < ycoords[ptindex] && ycoords[ptindex] >= ycoords[ptindex + 1]) {
1154  if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT) {
1155  if (turncount == 0 || turnpoints[turncount - 1] != lastmin)
1156  /*new min point */
1157  turnpoints[turncount++] = lastmin;
1158  lastmax = ptindex; /*latest maximum */
1159  }
1160  else if (ycoords[ptindex] > ycoords[lastmax]) {
1161  lastmax = ptindex; /*higher maximum */
1162  }
1163  }
1164  ptindex++;
1165  }
1166  /*possible global min */
1167  if (ycoords[ptindex] < ycoords[lastmax] - TURNLIMIT
1168  && (turncount == 0 || turnpoints[turncount - 1] != lastmax)) {
1169  if (turncount < SPLINESIZE - 1)
1170  /*2 more turns */
1171  turnpoints[turncount++] = lastmax;
1172  if (turncount < SPLINESIZE - 1)
1173  turnpoints[turncount++] = ptindex;
1174  }
1175  else if (ycoords[ptindex] > ycoords[lastmin] + TURNLIMIT
1176  /*possible global max */
1177  && (turncount == 0 || turnpoints[turncount - 1] != lastmin)) {
1178  if (turncount < SPLINESIZE - 1)
1179  /*2 more turns */
1180  turnpoints[turncount++] = lastmin;
1181  if (turncount < SPLINESIZE - 1)
1182  turnpoints[turncount++] = ptindex;
1183  }
1184  else if (turncount > 0 && turnpoints[turncount - 1] == lastmin
1185  && turncount < SPLINESIZE - 1) {
1186  if (ycoords[ptindex] > ycoords[lastmax])
1187  turnpoints[turncount++] = ptindex;
1188  else
1189  turnpoints[turncount++] = lastmax;
1190  }
1191  else if (turncount > 0 && turnpoints[turncount - 1] == lastmax
1192  && turncount < SPLINESIZE - 1) {
1193  if (ycoords[ptindex] < ycoords[lastmin])
1194  turnpoints[turncount++] = ptindex;
1195  else
1196  turnpoints[turncount++] = lastmin;
1197  }
1198  }
1199 
1200  if (textord_oldbl_debug && turncount > 0)
1201  tprintf ("First turn is %d at (%d,%d)\n",
1202  turnpoints[0], xcoords[turnpoints[0]], ycoords[turnpoints[0]]);
1203  for (segment = 1; segment < turncount; segment++) {
1204  /*centre y coord */
1205  lastmax = (ycoords[turnpoints[segment - 1]] + ycoords[turnpoints[segment]]) / 2;
1206 
1207  /* fix alg so that it works with both rising and falling sections */
1208  if (ycoords[turnpoints[segment - 1]] < ycoords[turnpoints[segment]])
1209  /*find rising y centre */
1210  for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] <= lastmax; ptindex++);
1211  else
1212  /*find falling y centre */
1213  for (ptindex = turnpoints[segment - 1] + 1; ptindex < turnpoints[segment] && ycoords[ptindex + 1] >= lastmax; ptindex++);
1214 
1215  /*centre x */
1216  xstarts[segment] = (xcoords[ptindex - 1] + xcoords[ptindex]
1217  + xcoords[turnpoints[segment - 1]]
1218  + xcoords[turnpoints[segment]] + 2) / 4;
1219  /*halfway between turns */
1220  if (textord_oldbl_debug)
1221  tprintf ("Turn %d is %d at (%d,%d), mid pt is %d@%d, final @%d\n",
1222  segment, turnpoints[segment],
1223  xcoords[turnpoints[segment]], ycoords[turnpoints[segment]],
1224  ptindex - 1, xcoords[ptindex - 1], xstarts[segment]);
1225  }
1226 
1227  xstarts[segment] = max_x;
1228  return segment; /*no of splines */
1229 }
#define TURNLIMIT
Definition: oldbasel.cpp:55
#define tprintf(...)
Definition: tprintf.h:31
EXTERN bool textord_oldbl_debug
Definition: oldbasel.cpp:39
#define SPLINESIZE
Definition: oldbasel.cpp:71
BOOL8 split_stepped_spline ( QSPLINE baseline,
float  jumplimit,
int  xcoords[],
int  xstarts[],
int &  segments 
)

Definition at line 1240 of file oldbasel.cpp.

1246  {
1247  BOOL8 doneany; //return value
1248  register int segment; /*partition no */
1249  int startindex, centreindex, endindex;
1250  float leftcoord, rightcoord;
1251  int leftindex, rightindex;
1252  float step; //spline step
1253 
1254  doneany = FALSE;
1255  startindex = 0;
1256  for (segment = 1; segment < segments - 1; segment++) {
1257  step = baseline->step ((xstarts[segment - 1] + xstarts[segment]) / 2.0,
1258  (xstarts[segment] + xstarts[segment + 1]) / 2.0);
1259  if (step < 0)
1260  step = -step;
1261  if (step > jumplimit) {
1262  while (xcoords[startindex] < xstarts[segment - 1])
1263  startindex++;
1264  centreindex = startindex;
1265  while (xcoords[centreindex] < xstarts[segment])
1266  centreindex++;
1267  endindex = centreindex;
1268  while (xcoords[endindex] < xstarts[segment + 1])
1269  endindex++;
1270  if (segments >= SPLINESIZE) {
1272  tprintf ("Too many segments to resegment spline!!\n");
1273  }
1274  else if (endindex - startindex >= textord_spline_medianwin * 3) {
1275  while (centreindex - startindex <
1276  textord_spline_medianwin * 3 / 2)
1277  centreindex++;
1278  while (endindex - centreindex <
1279  textord_spline_medianwin * 3 / 2)
1280  centreindex--;
1281  leftindex = (startindex + startindex + centreindex) / 3;
1282  rightindex = (centreindex + endindex + endindex) / 3;
1283  leftcoord =
1284  (xcoords[startindex] * 2 + xcoords[centreindex]) / 3.0;
1285  rightcoord =
1286  (xcoords[centreindex] + xcoords[endindex] * 2) / 3.0;
1287  while (xcoords[leftindex] > leftcoord
1288  && leftindex - startindex > textord_spline_medianwin)
1289  leftindex--;
1290  while (xcoords[leftindex] < leftcoord
1291  && centreindex - leftindex >
1293  leftindex++;
1294  if (xcoords[leftindex] - leftcoord >
1295  leftcoord - xcoords[leftindex - 1])
1296  leftindex--;
1297  while (xcoords[rightindex] > rightcoord
1298  && rightindex - centreindex >
1300  rightindex--;
1301  while (xcoords[rightindex] < rightcoord
1302  && endindex - rightindex > textord_spline_medianwin)
1303  rightindex++;
1304  if (xcoords[rightindex] - rightcoord >
1305  rightcoord - xcoords[rightindex - 1])
1306  rightindex--;
1308  tprintf ("Splitting spline at %d with step %g at (%d,%d)\n",
1309  xstarts[segment],
1310  baseline->
1311  step ((xstarts[segment - 1] +
1312  xstarts[segment]) / 2.0,
1313  (xstarts[segment] +
1314  xstarts[segment + 1]) / 2.0),
1315  (xcoords[leftindex - 1] + xcoords[leftindex]) / 2,
1316  (xcoords[rightindex - 1] + xcoords[rightindex]) / 2);
1317  insert_spline_point (xstarts, segment,
1318  (xcoords[leftindex - 1] +
1319  xcoords[leftindex]) / 2,
1320  (xcoords[rightindex - 1] +
1321  xcoords[rightindex]) / 2, segments);
1322  doneany = TRUE;
1323  }
1324  else if (textord_debug_baselines) {
1325  tprintf
1326  ("Resegmenting spline failed - insufficient pts (%d,%d,%d,%d)\n",
1327  startindex, centreindex, endindex,
1329  }
1330  }
1331  // else tprintf("Spline step at %d is %g\n",
1332  // xstarts[segment],
1333  // baseline->step((xstarts[segment-1]+xstarts[segment])/2.0,
1334  // (xstarts[segment]+xstarts[segment+1])/2.0));
1335  }
1336  return doneany;
1337 }
double step(double x1, double x2)
Definition: quspline.cpp:192
int textord_spline_medianwin
Definition: makerow.cpp:66
#define tprintf(...)
Definition: tprintf.h:31
unsigned char BOOL8
Definition: host.h:113
void insert_spline_point(int xstarts[], int segment, int coord1, int coord2, int &segments)
Definition: oldbasel.cpp:1347
#define SPLINESIZE
Definition: oldbasel.cpp:71
#define FALSE
Definition: capi.h:29
#define TRUE
Definition: capi.h:28
EXTERN bool textord_debug_baselines
Definition: oldbasel.cpp:40
int inT32
Definition: host.h:102

Variable Documentation

double oldbl_dot_error_size = 1.26

"Max aspect ratio of a dot"

Definition at line 51 of file oldbasel.cpp.

int oldbl_holed_losscount = 10

"Max lost before fallback line used"

Definition at line 50 of file oldbasel.cpp.

bool oldbl_xhfix = FALSE

"Fix bug in modes threshold for xheights"

Definition at line 46 of file oldbasel.cpp.

bool textord_debug_baselines = FALSE

"Debug baseline generation"

Definition at line 40 of file oldbasel.cpp.

bool textord_oldbl_debug = FALSE

"Debug old baseline generation"

Definition at line 39 of file oldbasel.cpp.

double textord_oldbl_jumplimit = 0.15

"X fraction for new partition"

Definition at line 53 of file oldbasel.cpp.

bool textord_oldbl_merge_parts = TRUE

"Merge suspect partitions"

Definition at line 43 of file oldbasel.cpp.

bool textord_oldbl_paradef = TRUE

"Use para default mechanism"

Definition at line 41 of file oldbasel.cpp.

bool textord_oldbl_split_splines = TRUE

"Split stepped splines"

Definition at line 42 of file oldbasel.cpp.

bool textord_really_old_xheight = FALSE

"Use original wiseowl xheight"

Definition at line 38 of file oldbasel.cpp.