e2075c130aa8470191a932770005af0ab64414a8
[zxing.git] / cpp / core / src / zxing / oned / UPCAReader.cpp
1 /*
2  *  UPCAReader.cpp
3  *  ZXing
4  *
5  *  Copyright 2010 ZXing authors All rights reserved.
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 #include "UPCAReader.h"
21 #include <zxing/ReaderException.h>
22
23 namespace zxing {
24         namespace oned {
25                 UPCAReader::UPCAReader() : ean13Reader() {
26                 }
27
28                 Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row) {
29                         return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row));
30                 }
31
32                 Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row, int startGuardRange[]) {
33                         return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange));
34                 }
35
36                 Ref<Result> UPCAReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
37                         return maybeReturnResult(ean13Reader.decode(image, hints));
38                 }
39
40                 int UPCAReader::decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
41                     std::string& resultString) {
42                         return ean13Reader.decodeMiddle(row, startRange, startRangeLen, resultString);
43                 }
44
45                 Ref<Result> UPCAReader::maybeReturnResult(Ref<Result> result) {
46                   if (result.empty()) {
47                     return result;
48                   }
49                         const std::string& text = (result->getText())->getText();
50                         if (text[0] == '0') {
51                                 Ref<String> resultString(new String(text.substr(1)));
52                                 Ref<Result> res(new Result(resultString, result->getRawBytes(), result->getResultPoints(),
53                                     BarcodeFormat_UPC_A));
54                                 return res;
55                         }
56                         return Ref<Result>();
57                 }
58
59                 BarcodeFormat UPCAReader::getBarcodeFormat(){
60                         return BarcodeFormat_UPC_A;
61                 }
62         }
63 }