Skip to content

Commit fe43396

Browse files
committed
Merge pull request #3199 from kim-ninh:wechatqr/hybrid_binarizer
2 parents 7a35d3d + a2550a5 commit fe43396

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

modules/wechat_qrcode/src/zxing/common/binarizer/hybrid_binarizer.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ Ref<Binarizer> HybridBinarizer::createBinarizer(Ref<LuminanceSource> source) {
5555
}
5656

5757
int HybridBinarizer::initBlockIntegral() {
58-
blockIntegral_ = new Array<int>(width * height);
58+
blockIntegralWidth = subWidth_ + 1;
59+
blockIntegralHeight = subHeight_ + 1;
60+
blockIntegral_ = new Array<int>(blockIntegralWidth * blockIntegralHeight);
5961

6062
int* integral = blockIntegral_->data();
6163

@@ -64,34 +66,27 @@ int HybridBinarizer::initBlockIntegral() {
6466
// first row only
6567
int rs = 0;
6668

67-
for (int j = 0; j < width; j++) {
69+
for (int j = 0; j < blockIntegralWidth; j++) {
6870
integral[j] = 0;
6971
}
7072

71-
for (int i = 0; i < height; i++) {
72-
integral[i * width] = 0;
73-
}
74-
75-
for (int j = 0; j < subWidth_; j++) {
76-
rs += blocks_[j].threshold;
77-
integral[width + j + 1] = rs;
73+
for (int i = 0; i < blockIntegralHeight; i++) {
74+
integral[i * blockIntegralWidth] = 0;
7875
}
7976

8077
// remaining cells are sum above and to the left
81-
int offset = width;
8278
int offsetBlock = 0;
79+
int offsetIntegral = 0;
8380

84-
for (int i = 1; i < subHeight_; ++i) {
81+
for (int i = 0; i < subHeight_; ++i) {
8582
// therow = grayByte_->getByteRow(i);
8683
offsetBlock = i * subWidth_;
87-
84+
offsetIntegral = (i + 1) * blockIntegralWidth;
8885
rs = 0;
8986

90-
offset += width;
91-
9287
for (int j = 0; j < subWidth_; ++j) {
9388
rs += blocks_[offsetBlock + j].threshold;
94-
integral[offset + j + 1] = rs + integral[offset - width + j + 1];
89+
integral[offsetIntegral + j + 1] = rs + integral[offsetIntegral - blockIntegralWidth + j + 1];
9590
}
9691
}
9792

@@ -201,8 +196,8 @@ void HybridBinarizer::calculateThresholdForBlock(Ref<ByteMatrix>& _luminances, i
201196
int sum = 0;
202197
// int sum2 = 0;
203198

204-
int offset1 = (top - THRES_BLOCKSIZE) * (subWidth + 1) + left - THRES_BLOCKSIZE;
205-
int offset2 = (top + THRES_BLOCKSIZE + 1) * (subWidth + 1) + left - THRES_BLOCKSIZE;
199+
int offset1 = (top - THRES_BLOCKSIZE) * blockIntegralWidth + left - THRES_BLOCKSIZE;
200+
int offset2 = (top + THRES_BLOCKSIZE + 1) * blockIntegralWidth + left - THRES_BLOCKSIZE;
206201

207202
int blocksize = THRES_BLOCKSIZE * 2 + 1;
208203

modules/wechat_qrcode/src/zxing/common/binarizer/hybrid_binarizer.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class HybridBinarizer : public GlobalHistogramBinarizer {
3535

3636
int subWidth_;
3737
int subHeight_;
38+
int blockIntegralWidth;
39+
int blockIntegralHeight;
3840

3941
public:
4042
explicit HybridBinarizer(Ref<LuminanceSource> source);

0 commit comments

Comments
 (0)