Fixed things broken in the last commit.
[zxing.git] / cpp / core / src / zxing / qrcode / QRCodeReader.cpp
1 /*
2  *  QRCodeReader.cpp
3  *  zxing
4  *
5  *  Created by Christian Brunschen on 20/05/2008.
6  *  Copyright 2008 ZXing authors All rights reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #include <zxing/qrcode/QRCodeReader.h>
22 #include <zxing/qrcode/detector/Detector.h>
23
24 #include <iostream>
25
26 namespace zxing {
27         namespace qrcode {
28                 
29                 using namespace std;
30                 
31                 QRCodeReader::QRCodeReader() :decoder_() {
32                 }
33                 
34                 Ref<Result> QRCodeReader::decode(Ref<BinaryBitmap> image) {
35 #ifdef DEBUG
36                         cout << "decoding image " << image.object_ << ":\n" << flush;
37 #endif
38                         
39                         Detector detector(image->getBlackMatrix());
40                         
41                         
42 #ifdef DEBUG
43                         cout << "(1) created detector " << &detector << "\n" << flush;
44 #endif
45                         
46                         Ref<DetectorResult> detectorResult(detector.detect());
47 #ifdef DEBUG
48                         cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush;
49 #endif
50                         
51                         std::vector<Ref<ResultPoint> > points(detectorResult->getPoints());
52                         
53                         
54 #ifdef DEBUG
55                         cout << "(3) extracted points " << &points << "\n" << flush;
56                         cout << "found " << points->size() << " points:\n";
57                         for (size_t i = 0; i < points->size(); i++) {
58                                 cout << "   " << points[i]->getX() << "," << points[i]->getY() << "\n";
59                         }
60                         cout << "bits:\n";
61                         cout << *(detectorResult->getBits()) << "\n";
62 #endif
63                         
64                         Ref<DecoderResult> decoderResult(decoder_.decode(detectorResult->getBits()));
65 #ifdef DEBUG
66                         cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush;
67 #endif
68                         
69                         Ref<Result> result(
70                                                            new Result(decoderResult->getText(), decoderResult->getRawBytes(), points, BarcodeFormat_QR_CODE));
71 #ifdef DEBUG
72                         cout << "(5) created result " << result.object_ << ", returning\n" << flush;
73 #endif
74                         
75                         return result;
76                 }
77                 
78                 QRCodeReader::~QRCodeReader() {
79                 }
80                 
81         }
82 }