Skip to content

Commit 34e0d01

Browse files
committed
Add Image::operator&=().
1 parent 9e3da4a commit 34e0d01

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

src/ccmain/pagesegmain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static Image RemoveEnclosingCircle(Image pixs) {
6565
pixSeedfillBinary(pixc, pixc, pixsi, 4);
6666
pixInvert(pixc, pixc);
6767
pixsi.destroy();
68-
Image pixt = pixAnd(nullptr, pixs, pixc);
68+
Image pixt = pixs & pixc;
6969
l_int32 max_count;
7070
pixCountConnComp(pixt, 8, &max_count);
7171
// The count has to go up before we start looking for the minimum.
@@ -74,7 +74,7 @@ static Image RemoveEnclosingCircle(Image pixs) {
7474
for (int i = 1; i < kMaxCircleErosions; i++) {
7575
pixt.destroy();
7676
pixErodeBrick(pixc, pixc, 3, 3);
77-
pixt = pixAnd(nullptr, pixs, pixc);
77+
pixt = pixs & pixc;
7878
l_int32 count;
7979
pixCountConnComp(pixt, 8, &count);
8080
if (i == 1 || count > max_count) {

src/ccstruct/image.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,22 @@ bool Image::isZero() const {
3939
return r == 1;
4040
}
4141

42-
void Image::operator|=(Image i) {
42+
Image Image::operator|(Image i) const {
43+
return pixOr(nullptr, pix_, i);
44+
}
45+
46+
Image &Image::operator|=(Image i) {
4347
pixOr(pix_, pix_, i);
48+
return *this;
49+
}
50+
51+
Image Image::operator&(Image i) const {
52+
return pixAnd(nullptr, pix_, i);
53+
}
54+
55+
Image &Image::operator&=(Image i) {
56+
pixAnd(pix_, pix_, i);
57+
return *this;
4458
}
4559

4660
}

src/ccstruct/image.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ class TESS_API Image {
3939
Image copy() const; // does full copy
4040
void destroy();
4141
bool isZero() const;
42-
void operator|=(Image);
42+
43+
// ops
44+
Image operator|(Image) const;
45+
Image &operator|=(Image);
46+
Image operator&(Image) const;
47+
Image &operator&=(Image);
4348
};
4449

4550
} // namespace tesseract

src/textord/imagefind.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Image ImageFind::FindImages(Image pix, DebugPixa *pixa_debug) {
129129
pixa_debug->AddPix(pixcoarsemask, "CoarseMask");
130130
}
131131
// Combine the coarse and fine image masks.
132-
pixAnd(pixcoarsemask, pixcoarsemask, pixfinemask);
132+
pixcoarsemask &= pixfinemask;
133133
pixfinemask.destroy();
134134
// Dilate a bit to make sure we get everything.
135135
pixDilateBrick(pixcoarsemask, pixcoarsemask, 3, 3);
@@ -139,7 +139,7 @@ Image ImageFind::FindImages(Image pix, DebugPixa *pixa_debug) {
139139
pixa_debug->AddPix(pixmask, "MaskDilated");
140140
}
141141
// And the image mask with the line and bar remover.
142-
pixAnd(pixht, pixht, pixmask);
142+
pixht &= pixmask;
143143
pixmask.destroy();
144144
if (textord_tabfind_show_images && pixa_debug != nullptr) {
145145
pixa_debug->AddPix(pixht, "FinalMask");

src/textord/linefind.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void LineFinder::FindAndRemoveLines(int resolution, bool debug, Image pix, int *
259259
if (pix_hline != nullptr) {
260260
// Recompute intersections and re-filter false positive h-lines.
261261
if (pix_vline != nullptr) {
262-
pixAnd(pix_intersections, pix_vline, pix_hline);
262+
pix_intersections = pix_vline & pix_hline;
263263
} else {
264264
pix_intersections.destroy();
265265
}
@@ -278,7 +278,7 @@ void LineFinder::FindAndRemoveLines(int resolution, bool debug, Image pix, int *
278278
if (pix_vline != nullptr && pix_hline != nullptr) {
279279
// Remove joins (intersections) where lines cross, and the residue.
280280
// Recalculate the intersections, since some lines have been deleted.
281-
pixAnd(pix_intersections, pix_vline, pix_hline);
281+
pix_intersections = pix_vline & pix_hline;
282282
// Fatten up the intersections and seed-fill to get the intersection
283283
// residue.
284284
Image pix_join_residue = pixDilateBrick(nullptr, pix_intersections, 5, 5);
@@ -483,7 +483,7 @@ void LineFinder::FindLineVectors(const ICOORD &bleft, const ICOORD &tright,
483483
static Image FilterMusic(int resolution, Image pix_closed, Image pix_vline, Image pix_hline,
484484
bool &v_empty, bool &h_empty) {
485485
int max_stave_height = static_cast<int>(resolution * kMaxStaveHeight);
486-
Image intersection_pix = pixAnd(nullptr, pix_vline, pix_hline);
486+
Image intersection_pix = pix_vline & pix_hline;
487487
Boxa *boxa = pixConnComp(pix_vline, nullptr, 8);
488488
// Iterate over the boxes to find music bars.
489489
int nboxes = boxaGetCount(boxa);
@@ -637,7 +637,7 @@ void LineFinder::GetLineMasks(int resolution, Image src_pix, Image *pix_vline, I
637637
if (!h_empty) {
638638
pixSubtract(pix_nonlines, pix_nonlines, *pix_hline);
639639
// Intersections are a useful indicator for likelihood of being a line.
640-
*pix_intersections = pixAnd(nullptr, *pix_vline, *pix_hline);
640+
*pix_intersections = *pix_vline & *pix_hline;
641641
// Candidate vlines are not hlines (apart from the intersections)
642642
// and vice versa.
643643
extra_non_hlines = pixSubtract(nullptr, *pix_vline, *pix_intersections);

0 commit comments

Comments
 (0)