Skip to content

Commit dbb2adb

Browse files
committed
Improve flexibility of MoveAndClipBox
1 parent facd55a commit dbb2adb

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/ccstruct/pageres.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,11 +1349,11 @@ static TBOX ComputeWordBounds(const tesseract::PointerVector<WERD_RES> &words,
13491349
return clipped_box;
13501350
}
13511351

1352-
// Helper moves the blob from src to dest. If it isn't contained by clip_box,
1353-
// the blob is replaced by a fake that is contained.
1354-
static TBOX MoveAndClipBlob(C_BLOB_IT *src_it, C_BLOB_IT *dest_it,
1355-
const TBOX &clip_box) {
1356-
C_BLOB *src_blob = src_it->extract();
1352+
// Helper moves the src_blob to dest. If it isn't contained by clip_box,
1353+
// the blob is replaced by a fake that is contained. The helper takes ownership
1354+
// of the blob.
1355+
static TBOX ClipAndAddBlob(C_BLOB *src_blob, C_BLOB_IT *dest_it,
1356+
const TBOX &clip_box) {
13571357
TBOX box = src_blob->bounding_box();
13581358
if (!clip_box.contains(box)) {
13591359
int left =
@@ -1447,17 +1447,17 @@ void PAGE_RES_IT::ReplaceCurrentWord(
14471447
// Add the blobs up to end_x.
14481448
while (!src_b_it.empty() &&
14491449
src_b_it.data()->bounding_box().x_middle() < end_x) {
1450-
blob_box += MoveAndClipBlob(&src_b_it, &dest_it, clip_box);
1450+
blob_box += ClipAndAddBlob(src_b_it.extract(), &dest_it, clip_box);
14511451
src_b_it.forward();
14521452
}
14531453
while (!rej_b_it.empty() &&
14541454
rej_b_it.data()->bounding_box().x_middle() < end_x) {
1455-
blob_box += MoveAndClipBlob(&rej_b_it, &dest_it, clip_box);
1455+
blob_box += ClipAndAddBlob(rej_b_it.extract(), &dest_it, clip_box);
14561456
rej_b_it.forward();
14571457
}
14581458
if (blob_box.null_box()) {
14591459
// Use the original box as a back-up.
1460-
blob_box = MoveAndClipBlob(&fake_b_it, &dest_it, clip_box);
1460+
blob_box = ClipAndAddBlob(fake_b_it.extract(), &dest_it, clip_box);
14611461
}
14621462
box_word->InsertBox(i, blob_box);
14631463
}

0 commit comments

Comments
 (0)