74a1b2c6356dbf52565a5deb1d89b1a775059d44
[zxing.git] / cpp / core / src / zxing / datamatrix / DataMatrixReader.cpp
1 /*
2  *  DataMatrixReader.cpp
3  *  zxing
4  *
5  *  Created by Luiz Silva on 09/02/2010.
6  *  Copyright 2010 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/datamatrix/DataMatrixReader.h>
22 #include <zxing/datamatrix/detector/Detector.h>
23 #include <iostream>
24
25 namespace zxing {
26 namespace datamatrix {
27
28 using namespace std;
29
30 DataMatrixReader::DataMatrixReader() :
31     decoder_() {
32 }
33
34 Ref<Result> DataMatrixReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
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_DATA_MATRIX));
71 #ifdef DEBUG
72   cout << "(5) created result " << result.object_ << ", returning\n" << flush;
73 #endif
74
75   return result;
76 }
77
78 DataMatrixReader::~DataMatrixReader() {
79 }
80
81 }
82 }