4b4c69d8be24b78ce5c70d2f33e19ab528234f48
[zxing.git] / cpp / core / src / 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 "QRCodeReader.h"
22 #include "detector/Detector.h"
23
24 #include <iostream>
25
26 namespace qrcode {
27   
28   using namespace decoder;
29   using namespace detector;
30   using namespace common;
31   using namespace std;
32
33   Ref<Result> QRCodeReader::decode(Ref<MonochromeBitmapSource> image) {
34     cout << "decoding image " << image.object_ << ":\n" << flush;
35     Detector detector(image);
36     cout << "(1) created detector " << &detector << "\n" << flush;
37     Ref<DetectorResult> detectorResult(detector.detect());
38     cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush;
39     ArrayRef<Ref<ResultPoint> > points(detectorResult->getPoints());
40     cout << "(3) extracted points " << &points << "\n" << flush;
41     cout << "found " << points->size() << " points:\n";
42     for (size_t i = 0; i < points->size(); i++) {
43       cout << "   " << points[i]->getX() << "," << points[i]->getY() << "\n";
44     }
45     cout << "bits:\n";
46     cout << *(detectorResult->getBits()) << "\n";
47     Ref<DecoderResult> decoderResult(decoder_.decode(detectorResult->getBits()));
48     cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush;
49     Ref<Result> result(new Result(decoderResult->getText(), 
50                                   decoderResult->getRawBytes(),
51                                   points,
52                                   BarcodeFormat_QR_CODE));
53     cout << "(5) created result " << result.object_ << ", returning\n" << flush;
54     return result;
55   }
56   
57   QRCodeReader::~QRCodeReader() {
58   }
59
60 }