Skip to content

Commit

Permalink
c++: fix improper use of NDEBUG
Browse files Browse the repository at this point in the history
Thanks to Antonio Rojas for pointing it out to me.
  • Loading branch information
axxel committed Jan 5, 2025
1 parent 63702f3 commit 82806f5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions core/src/HybridBinarizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static std::shared_ptr<BitMatrix> CalculateMatrix(const uint8_t* __restrict lumi
{
auto matrix = std::make_shared<BitMatrix>(width, height);

#ifndef NDEBUG
#ifdef PRINT_DEBUG
Matrix<uint8_t> out(width, height);
Matrix<uint8_t> out2(width, height);
#endif
Expand All @@ -163,7 +163,7 @@ static std::shared_ptr<BitMatrix> CalculateMatrix(const uint8_t* __restrict lumi
int average = sum / 25;
ThresholdBlock(luminances, xoffset, yoffset, average, rowStride, *matrix);

#ifndef NDEBUG
#ifdef PRINT_DEBUG
for (int yy = 0; yy < 8; ++yy)
for (int xx = 0; xx < 8; ++xx) {
out.set(xoffset + xx, yoffset + yy, blackPoints(x, y));
Expand All @@ -173,7 +173,7 @@ static std::shared_ptr<BitMatrix> CalculateMatrix(const uint8_t* __restrict lumi
}
}

#ifndef NDEBUG
#ifdef PRINT_DEBUG
std::ofstream file("thresholds.pnm");
file << "P5\n" << out.width() << ' ' << out.height() << "\n255\n";
file.write(reinterpret_cast<const char*>(out.data()), out.size());
Expand Down Expand Up @@ -260,7 +260,7 @@ static std::shared_ptr<BitMatrix> ThresholdImage(const ImageView iv, const Matri
{
auto matrix = std::make_shared<BitMatrix>(iv.width(), iv.height());

#ifndef NDEBUG
#ifdef PRINT_DEBUG
Matrix<uint8_t> out(iv.width(), iv.height());
#endif

Expand All @@ -270,15 +270,15 @@ static std::shared_ptr<BitMatrix> ThresholdImage(const ImageView iv, const Matri
int xoffset = std::min(x * BLOCK_SIZE, iv.width() - BLOCK_SIZE);
ThresholdBlock(iv.data(), xoffset, yoffset, thresholds(x, y), iv.rowStride(), *matrix);

#ifndef NDEBUG
#ifdef PRINT_DEBUG
for (int yy = 0; yy < 8; ++yy)
for (int xx = 0; xx < 8; ++xx)
out.set(xoffset + xx, yoffset + yy, thresholds(x, y));
#endif
}
}

#ifndef NDEBUG
#ifdef PRINT_DEBUG
std::ofstream file("thresholds_new.pnm");
file << "P5\n" << out.width() << ' ' << out.height() << "\n255\n";
file.write(reinterpret_cast<const char*>(out.data()), out.size());
Expand Down
2 changes: 1 addition & 1 deletion core/src/oned/ODDataBarCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ inline bool IsFinder(int a, int b, int c, int d, int e)
// (c < 5 + 10 * e) &&
(a < 2 + 4 * e) &&
(4 * a > n);
#if !defined(NDEBUG) && 0
#if defined(PRINT_DEBUG) && 0
printf("[");
for (bool v :
{w + 5 > 9 * n,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/datamatrix/DMEncodeDecodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace {
ASSERT_EQ(matrix.empty(), false);

DecoderResult res = DataMatrix::Decode(matrix);
#ifndef NDEBUG
#ifdef PRINT_DEBUG
if (!res.isValid() || data != res.text())
SaveAsPBM(matrix, "failed-datamatrix.pbm", 4);
#endif
Expand Down

0 comments on commit 82806f5

Please sign in to comment.