comparison mupdf-source/thirdparty/zxing-cpp/core/src/ThresholdBinarizer.h @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 /*
2 * Copyright 2020 Axel Waggershauser
3 */
4 // SPDX-License-Identifier: Apache-2.0
5
6 #pragma once
7
8 #include "BinaryBitmap.h"
9 #include "BitMatrix.h"
10
11 #include <cstdint>
12
13 namespace ZXing {
14
15 class ThresholdBinarizer : public BinaryBitmap
16 {
17 const uint8_t _threshold = 0;
18
19 public:
20 ThresholdBinarizer(const ImageView& buffer, uint8_t threshold = 128) : BinaryBitmap(buffer), _threshold(threshold) {}
21
22 bool getPatternRow(int row, int rotation, PatternRow& res) const override
23 {
24 auto buffer = _buffer.rotated(rotation);
25
26 const int stride = buffer.pixStride();
27 const uint8_t* begin = buffer.data(0, row) + GreenIndex(buffer.format());
28 const uint8_t* end = begin + buffer.width() * stride;
29
30 auto* lastPos = begin;
31 bool lastVal = false;
32
33 res.clear();
34
35 for (const uint8_t* p = begin; p != end; p += stride) {
36 bool val = *p <= _threshold;
37 if (val != lastVal) {
38 res.push_back(narrow_cast<PatternRow::value_type>((p - lastPos) / stride));
39 lastVal = val;
40 lastPos = p;
41 }
42 }
43
44 res.push_back(narrow_cast<PatternRow::value_type>((end - lastPos) / stride));
45
46 if (*(end - stride) <= _threshold)
47 res.push_back(0); // last value is number of white pixels, here 0
48
49 return true;
50 }
51
52 std::shared_ptr<const BitMatrix> getBlackMatrix() const override
53 {
54 return std::make_shared<const BitMatrix>(binarize(_threshold));
55 }
56 };
57
58 } // ZXing