Skip to content

Commit 65318e1

Browse files
committed
LogMatrix: add LogMatrixWriter helper for writing on scope exit
1 parent 41cf54c commit 65318e1

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

core/src/GridSampler.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,11 @@
2424

2525
namespace ZXing {
2626

27-
#ifndef NDEBUG
28-
std::vector<PointF> theGrid;
29-
#endif
30-
3127
DetectorResult SampleGrid(const BitMatrix& image, int width, int height, const PerspectiveTransform& transform)
3228
{
3329
#ifndef NDEBUG
34-
theGrid.clear();
35-
theGrid.reserve(width * height);
3630
LogMatrix log;
37-
log.init(&image, 5);
31+
LogMatrixWriter lmw(log, image, 5, "grid.pnm");
3832
#endif
3933
auto project = [&](PointI p) { return PointI(transform(p + PointF(0.5, 0.5))); };
4034
auto isInside = [&](PointI p) {
@@ -51,15 +45,11 @@ DetectorResult SampleGrid(const BitMatrix& image, int width, int height, const P
5145
for (int x = 0; x < width; ++x) {
5246
auto p = project({x, y});
5347
#ifndef NDEBUG
54-
theGrid.emplace_back(p);
5548
log(p, 3);
5649
#endif
5750
if (image.get(p))
5851
res.set(x, y);
5952
}
60-
#ifndef NDEBUG
61-
log.write("grid.pnm");
62-
#endif
6353

6454
auto projectCorner = [&](PointI p) { return PointI(transform(PointF(p)) + PointF(0.5, 0.5)); };
6555
return {

core/src/LogMatrix.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class LogMatrix
5959
case 1: r = g = b = _scale > 1 ? 128 : (r ? 230 : 50); break;
6060
case 2: r = b = 50, g = 220; break;
6161
case 3: g = r = 100, b = 250; break;
62+
case 4: g = b = 100, r = 250; break;
6263
}
6364
fwrite(&r, 1, 1, f);
6465
fwrite(&g, 1, 1, f);
@@ -82,8 +83,17 @@ class LogMatrix
8283
}
8384
};
8485

85-
#ifndef NDEBUG
86-
extern std::vector<PointF> theGrid;
87-
#endif
86+
class LogMatrixWriter
87+
{
88+
LogMatrix &log;
89+
std::string fn;
90+
91+
public:
92+
LogMatrixWriter(LogMatrix& log, const BitMatrix& image, int scale, std::string fn) : log(log), fn(fn)
93+
{
94+
log.init(&image, scale);
95+
}
96+
~LogMatrixWriter() { log.write(fn.c_str()); }
97+
};
8898

8999
} // namespace ZXing

core/src/datamatrix/DMDetector.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ static DetectorResult DetectNew(const BitMatrix& image, bool tryRotate)
740740
{
741741
// walk to the left at first
742742
#ifdef PRINT_DEBUG
743-
log.init(&image);
743+
LogMatrixWriter lmw(log, image, 1, "dm-log.pnm");
744744
for (auto startDirection : {PointF(-1, 0)}) {
745745
#else
746746
for (auto startDirection : {PointF(-1, 0), PointF(-1, 0), PointF(1, 0), PointF(0, -1), PointF(0, 1)}) {
@@ -884,10 +884,6 @@ static DetectorResult DetectNew(const BitMatrix& image, bool tryRotate)
884884

885885
for (RegressionLine* l : {&lineL, &lineB, &lineT, &lineR})
886886
log(l->points());
887-
888-
log(theGrid, 3);
889-
890-
log.write("log.pnm");
891887
#endif
892888

893889
if (!res.isValid())
@@ -902,10 +898,6 @@ static DetectorResult DetectNew(const BitMatrix& image, bool tryRotate)
902898
break; // only test left direction
903899
}
904900

905-
#ifdef PRINT_DEBUG
906-
log.write("log.pnm");
907-
#endif
908-
909901
return {};
910902
}
911903

0 commit comments

Comments
 (0)