C++ port: fixed warnings for Symbian build
[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() :
32     decoder_() {
33 }
34
35 Ref<Result> QRCodeReader::decode(Ref<BinaryBitmap> image) {
36 #ifdef DEBUG
37   cout << "decoding image " << image.object_ << ":\n" << flush;
38 #endif
39
40   Detector detector(image->getBlackMatrix());
41
42
43 #ifdef DEBUG
44   cout << "(1) created detector " << &detector << "\n" << flush;
45 #endif
46
47   Ref<DetectorResult> detectorResult(detector.detect());
48 #ifdef DEBUG
49   cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush;
50 #endif
51
52   std::vector<Ref<ResultPoint> > points(detectorResult->getPoints());
53
54
55 #ifdef DEBUG
56   cout << "(3) extracted points " << &points << "\n" << flush;
57   cout << "found " << points->size() << " points:\n";
58   for (size_t i = 0; i < points->size(); i++) {
59     cout << "   " << points[i]->getX() << "," << points[i]->getY() << "\n";
60   }
61   cout << "bits:\n";
62   cout << *(detectorResult->getBits()) << "\n";
63 #endif
64
65   Ref<DecoderResult> decoderResult(decoder_.decode(detectorResult->getBits()));
66 #ifdef DEBUG
67   cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush;
68 #endif
69
70   Ref<Result> result(
71     new Result(decoderResult->getText(), decoderResult->getRawBytes(), points, BarcodeFormat_QR_CODE));
72 #ifdef DEBUG
73   cout << "(5) created result " << result.object_ << ", returning\n" << flush;
74 #endif
75
76   return result;
77 }
78
79 QRCodeReader::~QRCodeReader() {
80 }
81
82 }
83 }