5 * Copyright 2010 ZXing authors All rights reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include "EAN8Reader.h"
21 #include <zxing/ReaderException.h>
26 EAN8Reader::EAN8Reader(){ }
28 int EAN8Reader::decodeMiddle(Ref<BitArray> row, int startGuardBegin, int startGuardEnd,
29 std::string& resultString){
30 const int countersLen = 4;
31 int counters[countersLen] = { 0, 0, 0, 0 };
33 int end = row->getSize();
34 int rowOffset = startGuardEnd;
36 for (int x = 0; x < 4 && rowOffset < end; x++) {
37 int bestMatch = decodeDigit(row, counters, countersLen, rowOffset,
38 UPC_EAN_PATTERNS_L_PATTERNS);
42 resultString.append(1, (char) ('0' + bestMatch));
43 for (int i = 0; i < countersLen; i++) {
44 rowOffset += counters[i];
50 if (findGuardPattern(row, rowOffset, true, (int*)getMIDDLE_PATTERN(),
51 getMIDDLE_PATTERN_LEN(), &middleRangeStart, &middleRangeEnd)) {
52 rowOffset = middleRangeEnd;
53 for (int x = 0; x < 4 && rowOffset < end; x++) {
54 int bestMatch = decodeDigit(row, counters, countersLen, rowOffset,
55 UPC_EAN_PATTERNS_L_PATTERNS);
59 resultString.append(1, (char) ('0' + bestMatch));
60 for (int i = 0; i < countersLen; i++) {
61 rowOffset += counters[i];
69 BarcodeFormat EAN8Reader::getBarcodeFormat(){
70 return BarcodeFormat_EAN_8;