Skip to content

Commit cda04b1

Browse files
committed
tordmain: Replace alloc_mem, free_mem by C++ std::vector
Signed-off-by: Stefan Weil <[email protected]>
1 parent 3032b65 commit cda04b1

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

src/textord/tordmain.cpp

+23-30
Original file line numberDiff line numberDiff line change
@@ -459,16 +459,16 @@ bool Textord::clean_noise_from_row( //remove empties
459459
ROW* row //row to clean
460460
) {
461461
bool testing_on;
462-
TBOX blob_box; //bounding box
462+
TBOX blob_box; //bounding box
463463
C_BLOB *blob; //current blob
464464
C_OUTLINE *outline; //current outline
465465
WERD *word; //current word
466-
int32_t blob_size; //biggest size
467-
int32_t trans_count = 0; //no of transitions
468-
int32_t trans_threshold; //noise tolerance
469-
int32_t dot_count; //small objects
470-
int32_t norm_count; //normal objects
471-
int32_t super_norm_count; //real char-like
466+
int32_t blob_size; //biggest size
467+
int32_t trans_count = 0; //no of transitions
468+
int32_t trans_threshold; //noise tolerance
469+
int32_t dot_count; //small objects
470+
int32_t norm_count; //normal objects
471+
int32_t super_norm_count; //real char-like
472472
//words of row
473473
WERD_IT word_it = row->word_list ();
474474
C_BLOB_IT blob_it; //blob iterator
@@ -559,19 +559,18 @@ bool Textord::clean_noise_from_row( //remove empties
559559
void Textord::clean_noise_from_words( //remove empties
560560
ROW *row //row to clean
561561
) {
562-
TBOX blob_box; //bounding box
563-
int8_t *word_dud; //was it chucked
562+
TBOX blob_box; //bounding box
564563
C_BLOB *blob; //current blob
565564
C_OUTLINE *outline; //current outline
566565
WERD *word; //current word
567-
int32_t blob_size; //biggest size
568-
int32_t trans_count; //no of transitions
569-
int32_t trans_threshold; //noise tolerance
570-
int32_t dot_count; //small objects
571-
int32_t norm_count; //normal objects
572-
int32_t dud_words; //number discarded
573-
int32_t ok_words; //number remaining
574-
int32_t word_index; //current word
566+
int32_t blob_size; //biggest size
567+
int32_t trans_count; //no of transitions
568+
int32_t trans_threshold; //noise tolerance
569+
int32_t dot_count; //small objects
570+
int32_t norm_count; //normal objects
571+
int32_t dud_words; //number discarded
572+
int32_t ok_words; //number remaining
573+
int32_t word_index; //current word
575574
//words of row
576575
WERD_IT word_it = row->word_list ();
577576
C_BLOB_IT blob_it; //blob iterator
@@ -580,7 +579,8 @@ void Textord::clean_noise_from_words( //remove empties
580579
ok_words = word_it.length ();
581580
if (ok_words == 0 || textord_no_rejects)
582581
return;
583-
word_dud = (int8_t *) alloc_mem (ok_words * sizeof (int8_t));
582+
// was it chucked
583+
std::vector<int8_t> word_dud(ok_words);
584584
dud_words = 0;
585585
ok_words = 0;
586586
word_index = 0;
@@ -664,7 +664,6 @@ void Textord::clean_noise_from_words( //remove empties
664664
}
665665
word_index++;
666666
}
667-
free_mem(word_dud);
668667
}
669668

670669
// Remove outlines that are a tiny fraction in either width or height
@@ -885,8 +884,6 @@ void tweak_row_baseline(ROW *row,
885884
int32_t blob_count; //no of blobs
886885
int32_t src_index; //source segment
887886
int32_t dest_index; //destination segment
888-
int32_t *xstarts; //spline segments
889-
double *coeffs; //spline coeffs
890887
float ydiff; //baseline error
891888
float x_centre; //centre of blob
892889
//words of row
@@ -901,12 +898,10 @@ void tweak_row_baseline(ROW *row,
901898
}
902899
if (blob_count == 0)
903900
return;
904-
xstarts =
905-
(int32_t *) alloc_mem ((blob_count + row->baseline.segments + 1) *
906-
sizeof (int32_t));
907-
coeffs =
908-
(double *) alloc_mem ((blob_count + row->baseline.segments) * 3 *
909-
sizeof (double));
901+
// spline segments
902+
std::vector<int32_t> xstarts(blob_count + row->baseline.segments + 1);
903+
// spline coeffs
904+
std::vector<double> coeffs((blob_count + row->baseline.segments) * 3);
910905

911906
src_index = 0;
912907
dest_index = 0;
@@ -978,7 +973,5 @@ void tweak_row_baseline(ROW *row,
978973
xstarts[dest_index] = row->baseline.xcoords[src_index];
979974
}
980975
//turn to spline
981-
row->baseline = QSPLINE (dest_index, xstarts, coeffs);
982-
free_mem(xstarts);
983-
free_mem(coeffs);
976+
row->baseline = QSPLINE(dest_index, &xstarts[0], &coeffs[0]);
984977
}

0 commit comments

Comments
 (0)