diff --git a/symbian/QZXing/binary/Harmattan-Maemo5/QZXing_global.h b/symbian/QZXing/binary/Harmattan-Maemo5/QZXing_global.h index 83ef95c57..d55ab0523 100644 --- a/symbian/QZXing/binary/Harmattan-Maemo5/QZXing_global.h +++ b/symbian/QZXing/binary/Harmattan-Maemo5/QZXing_global.h @@ -1,7 +1,8 @@ #ifndef QZXING_GLOBAL_H #define QZXING_GLOBAL_H -#include +#include +#include #if defined(QZXING_LIBRARY) # define QZXINGSHARED_EXPORT Q_DECL_EXPORT @@ -9,4 +10,4 @@ # define QZXINGSHARED_EXPORT Q_DECL_IMPORT #endif -#endif // QZXING_GLOBAL_H +#endif //QZXING_GLOBAL_H diff --git a/symbian/QZXing/binary/Harmattan-Maemo5/libQZXing.rar b/symbian/QZXing/binary/Harmattan-Maemo5/libQZXing.rar deleted file mode 100644 index a6ed195ef..000000000 Binary files a/symbian/QZXing/binary/Harmattan-Maemo5/libQZXing.rar and /dev/null differ diff --git a/symbian/QZXing/binary/Harmattan-Maemo5/qzxing.h b/symbian/QZXing/binary/Harmattan-Maemo5/qzxing.h index 3fd3e692a..33e1240dd 100644 --- a/symbian/QZXing/binary/Harmattan-Maemo5/qzxing.h +++ b/symbian/QZXing/binary/Harmattan-Maemo5/qzxing.h @@ -32,7 +32,8 @@ public: DecoderFormat_EAN_13 = 32, DecoderFormat_CODE_128 = 64, DecoderFormat_CODE_39 = 128, - DecoderFormat_ITF = 256 + DecoderFormat_ITF = 256, + DecoderFormat_Aztec = 512 } ; typedef unsigned int DecoderFormatType; @@ -49,7 +50,7 @@ public: #if QT_VERSION >= 0x040700 static void registerQMLTypes() { - qmlRegisterType("QZXing", 1, 0, "QZXing"); + qmlRegisterType("QZXing", 1, 2, "QZXing"); } #endif @@ -60,6 +61,19 @@ public slots: */ QString decodeImage(QImage image); + /** + * The decoding function accessible from QML + */ + QString decodeImageQML(QObject *item); + + /** + * The decoding function accessible from QML. Able to set the decoding + * of a portion of the image. + */ + QString decodeSubImageQML(QObject* item, + const double offsetX = 0 , const double offsetY = 0, + const double width = 0, const double height = 0); + signals: void decodingStarted(); void decodingFinished(bool succeeded); @@ -68,6 +82,7 @@ signals: private: void* decoder; DecoderFormatType supportedFormats; + QObject* imageHandler; }; #endif // QZXING_H diff --git a/symbian/QZXing/binary/Harmattan-Maemo5/readme.txt b/symbian/QZXing/binary/Harmattan-Maemo5/readme.txt deleted file mode 100644 index f36db26c8..000000000 --- a/symbian/QZXing/binary/Harmattan-Maemo5/readme.txt +++ /dev/null @@ -1 +0,0 @@ -libQZXing.rar is compressed to save space. Decompress to use. \ No newline at end of file diff --git a/symbian/QZXing/binary/Qt_4.7.3_Symbian/InstallToDevice/QZXing.sis b/symbian/QZXing/binary/Qt_4.7.3_Symbian/InstallToDevice/QZXing.sis deleted file mode 100644 index 2a98383af..000000000 Binary files a/symbian/QZXing/binary/Qt_4.7.3_Symbian/InstallToDevice/QZXing.sis and /dev/null differ diff --git a/symbian/QZXing/binary/Qt_4.7.3_Symbian/InstallToDevice/QZXing_selfsigned.sis b/symbian/QZXing/binary/Qt_4.7.3_Symbian/InstallToDevice/QZXing_selfsigned.sis index 047210802..9a3940bbb 100644 Binary files a/symbian/QZXing/binary/Qt_4.7.3_Symbian/InstallToDevice/QZXing_selfsigned.sis and b/symbian/QZXing/binary/Qt_4.7.3_Symbian/InstallToDevice/QZXing_selfsigned.sis differ diff --git a/symbian/QZXing/binary/Qt_4.7.3_Symbian/InstallToDevice/QZXing_unsigned.sis b/symbian/QZXing/binary/Qt_4.7.3_Symbian/InstallToDevice/QZXing_unsigned.sis new file mode 100644 index 000000000..d5e4d4c16 Binary files /dev/null and b/symbian/QZXing/binary/Qt_4.7.3_Symbian/InstallToDevice/QZXing_unsigned.sis differ diff --git a/symbian/QZXing/binary/Qt_4.7.3_Symbian/include/QZXing.h b/symbian/QZXing/binary/Qt_4.7.3_Symbian/include/QZXing.h index 3fd3e692a..33e1240dd 100644 --- a/symbian/QZXing/binary/Qt_4.7.3_Symbian/include/QZXing.h +++ b/symbian/QZXing/binary/Qt_4.7.3_Symbian/include/QZXing.h @@ -32,7 +32,8 @@ public: DecoderFormat_EAN_13 = 32, DecoderFormat_CODE_128 = 64, DecoderFormat_CODE_39 = 128, - DecoderFormat_ITF = 256 + DecoderFormat_ITF = 256, + DecoderFormat_Aztec = 512 } ; typedef unsigned int DecoderFormatType; @@ -49,7 +50,7 @@ public: #if QT_VERSION >= 0x040700 static void registerQMLTypes() { - qmlRegisterType("QZXing", 1, 0, "QZXing"); + qmlRegisterType("QZXing", 1, 2, "QZXing"); } #endif @@ -60,6 +61,19 @@ public slots: */ QString decodeImage(QImage image); + /** + * The decoding function accessible from QML + */ + QString decodeImageQML(QObject *item); + + /** + * The decoding function accessible from QML. Able to set the decoding + * of a portion of the image. + */ + QString decodeSubImageQML(QObject* item, + const double offsetX = 0 , const double offsetY = 0, + const double width = 0, const double height = 0); + signals: void decodingStarted(); void decodingFinished(bool succeeded); @@ -68,6 +82,7 @@ signals: private: void* decoder; DecoderFormatType supportedFormats; + QObject* imageHandler; }; #endif // QZXING_H diff --git a/symbian/QZXing/binary/Qt_4.7.3_Symbian/release/armv5/lib/QZXing.dso b/symbian/QZXing/binary/Qt_4.7.3_Symbian/release/armv5/lib/QZXing.dso index c19f0bd50..ab565eec1 100644 Binary files a/symbian/QZXing/binary/Qt_4.7.3_Symbian/release/armv5/lib/QZXing.dso and b/symbian/QZXing/binary/Qt_4.7.3_Symbian/release/armv5/lib/QZXing.dso differ diff --git a/symbian/QZXing/binary/Qt_4.7.3_Symbian/release/armv5/lib/QZXing{00010100}.dso b/symbian/QZXing/binary/Qt_4.7.3_Symbian/release/armv5/lib/QZXing{00010100}.dso deleted file mode 100644 index c19f0bd50..000000000 Binary files a/symbian/QZXing/binary/Qt_4.7.3_Symbian/release/armv5/lib/QZXing{00010100}.dso and /dev/null differ diff --git a/symbian/QZXing/binary/Qt_4.7.3_Symbian/release/armv5/lib/QZXing{00010200}.dso b/symbian/QZXing/binary/Qt_4.7.3_Symbian/release/armv5/lib/QZXing{00010200}.dso new file mode 100644 index 000000000..ab565eec1 Binary files /dev/null and b/symbian/QZXing/binary/Qt_4.7.3_Symbian/release/armv5/lib/QZXing{00010200}.dso differ diff --git a/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/QZXing.h b/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/QZXing.h index 3fd3e692a..33e1240dd 100644 --- a/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/QZXing.h +++ b/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/QZXing.h @@ -32,7 +32,8 @@ public: DecoderFormat_EAN_13 = 32, DecoderFormat_CODE_128 = 64, DecoderFormat_CODE_39 = 128, - DecoderFormat_ITF = 256 + DecoderFormat_ITF = 256, + DecoderFormat_Aztec = 512 } ; typedef unsigned int DecoderFormatType; @@ -49,7 +50,7 @@ public: #if QT_VERSION >= 0x040700 static void registerQMLTypes() { - qmlRegisterType("QZXing", 1, 0, "QZXing"); + qmlRegisterType("QZXing", 1, 2, "QZXing"); } #endif @@ -60,6 +61,19 @@ public slots: */ QString decodeImage(QImage image); + /** + * The decoding function accessible from QML + */ + QString decodeImageQML(QObject *item); + + /** + * The decoding function accessible from QML. Able to set the decoding + * of a portion of the image. + */ + QString decodeSubImageQML(QObject* item, + const double offsetX = 0 , const double offsetY = 0, + const double width = 0, const double height = 0); + signals: void decodingStarted(); void decodingFinished(bool succeeded); @@ -68,6 +82,7 @@ signals: private: void* decoder; DecoderFormatType supportedFormats; + QObject* imageHandler; }; #endif // QZXING_H diff --git a/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/QZXing1.dll b/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/QZXing1.dll new file mode 100644 index 000000000..0c9afcfbc Binary files /dev/null and b/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/QZXing1.dll differ diff --git a/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/QZXing1.rar b/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/QZXing1.rar deleted file mode 100644 index 3e53d0138..000000000 Binary files a/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/QZXing1.rar and /dev/null differ diff --git a/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/readme.txt b/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/readme.txt deleted file mode 100644 index f6a79098c..000000000 --- a/symbian/QZXing/binary/Qt_4.7.4_Desktop_Mingw/readme.txt +++ /dev/null @@ -1 +0,0 @@ -QZXing1.rar is compressed to save space. Decompress to use. \ No newline at end of file diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/CameraButton.qml b/symbian/QZXing/examples/QMLBarcodeScanner/CameraButton.qml similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/CameraButton.qml rename to symbian/QZXing/examples/QMLBarcodeScanner/CameraButton.qml diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/CameraPropertyButton.qml b/symbian/QZXing/examples/QMLBarcodeScanner/CameraPropertyButton.qml similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/CameraPropertyButton.qml rename to symbian/QZXing/examples/QMLBarcodeScanner/CameraPropertyButton.qml diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/CameraPropertyPopup.qml b/symbian/QZXing/examples/QMLBarcodeScanner/CameraPropertyPopup.qml similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/CameraPropertyPopup.qml rename to symbian/QZXing/examples/QMLBarcodeScanner/CameraPropertyPopup.qml diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/CaptureControls.qml b/symbian/QZXing/examples/QMLBarcodeScanner/CaptureControls.qml similarity index 94% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/CaptureControls.qml rename to symbian/QZXing/examples/QMLBarcodeScanner/CaptureControls.qml index 8307995f1..e2704d5df 100644 --- a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/CaptureControls.qml +++ b/symbian/QZXing/examples/QMLBarcodeScanner/CaptureControls.qml @@ -47,7 +47,7 @@ FocusScope { property alias whiteBalance : wbModesButton.value property alias flashMode : flashModesButton.value - property alias exposureCompensation : exposureCompensationButton.value + //property alias exposureCompensation : exposureCompensationButton.value property int buttonsPanelWidth: buttonPaneShadow.width @@ -84,7 +84,7 @@ FocusScope { } CameraButton { - text: "Capture" + text: "Decode" onClicked: camera.captureImage() } @@ -147,9 +147,9 @@ FocusScope { } } - ExposureCompensationButton { - id : exposureCompensationButton - } +// ExposureCompensationButton { +// id : exposureCompensationButton +// } CameraButton { text: "View" diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/ExposureCompensationButton.qml b/symbian/QZXing/examples/QMLBarcodeScanner/ExposureCompensationButton.qml similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/ExposureCompensationButton.qml rename to symbian/QZXing/examples/QMLBarcodeScanner/ExposureCompensationButton.qml diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/FlickableList.qml b/symbian/QZXing/examples/QMLBarcodeScanner/FlickableList.qml similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/FlickableList.qml rename to symbian/QZXing/examples/QMLBarcodeScanner/FlickableList.qml diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/FocusButton.qml b/symbian/QZXing/examples/QMLBarcodeScanner/FocusButton.qml similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/FocusButton.qml rename to symbian/QZXing/examples/QMLBarcodeScanner/FocusButton.qml diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/MessageDialog.qml b/symbian/QZXing/examples/QMLBarcodeScanner/MessageDialog.qml new file mode 100644 index 000000000..73a35259d --- /dev/null +++ b/symbian/QZXing/examples/QMLBarcodeScanner/MessageDialog.qml @@ -0,0 +1,23 @@ +import QtQuick 1.1 +import com.nokia.symbian 1.1 + +CommonDialog { + id: dialog + titleText: "Decoded message" + //titleIcon: "images/QrButton_toolbar.svg" + buttonTexts: ["OK"] + + property alias text: messageLabel.text + + content: Rectangle { + height: messageLabel.height + width: messageLabel.width + color: "#ff000000" + anchors.horizontalCenter: parent.horizontalCenter + + Text{ + id: messageLabel + color: "white" + } + } +} diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/PhotoPreview.qml b/symbian/QZXing/examples/QMLBarcodeScanner/PhotoPreview.qml new file mode 100644 index 000000000..580d45686 --- /dev/null +++ b/symbian/QZXing/examples/QMLBarcodeScanner/PhotoPreview.qml @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import Qt 4.7 +import QtMultimediaKit 1.1 + +Item { + property alias source : preview.source + signal closed + + Image { + id: preview + anchors.fill : parent + fillMode: Image.PreserveAspectFit + smooth: true + } + + MouseArea { + anchors.fill: parent + onClicked: { + parent.closed(); + } + } +} + diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.pro b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.pro new file mode 100644 index 000000000..653d198df --- /dev/null +++ b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.pro @@ -0,0 +1,38 @@ +TEMPLATE=app + +VERSION = 1.1.0 + +QT += declarative network + +!maemo5 { + contains(QT_CONFIG, opengl) { + # QT += opengl + } +} + +win32 { + #required by Qt SDK to resolve Mobility libraries + CONFIG+=mobility + MOBILITY+=multimedia +} + +SOURCES += $$PWD/qmlcamera.cpp +!mac:TARGET = QMLBarcodeReader +else:TARGET = QMLBarcodeReader + +RESOURCES += declarative-camera.qrc + +symbian { + TARGET.CAPABILITY = UserEnvironment NetworkServices Location ReadUserData WriteUserData + TARGET.EPOCHEAPSIZE = 0x20000 0x3000000 + + LIBS += -lqzxing + + customrules.pkg_prerules = \ + ";QZXing" \ + "@\"$$(EPOCROOT)Epoc32/InstallToDevice/QZXing_selfsigned.sis\",(0xE618743C)"\ + " " + DEPLOYMENT += customrules +} + +ICON = QMLBarcodeReader.svg diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.rss b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.rss new file mode 100644 index 000000000..74f9f7acb --- /dev/null +++ b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.rss @@ -0,0 +1,22 @@ +// ============================================================================ +// * Generated by qmake (2.01a) (Qt 4.7.4) on: 2012-05-19T19:03:01 +// * This file is generated by qmake and should not be modified by the +// * user. +// ============================================================================ + +CHARACTER_SET UTF8 +#include +#include "QMLBarcodeReader.loc" + +RESOURCE LOCALISABLE_APP_INFO r_localisable_app_info + { + short_caption = STRING_r_short_caption; + caption_and_icon = + CAPTION_AND_ICON_INFO + { + caption = STRING_r_caption; + number_of_icons = 0; + icon_file = "\\resource\\apps\\QMLBarcodeReader.mif"; + }; + } + diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.sis b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.sis new file mode 100644 index 000000000..03e96c7b9 Binary files /dev/null and b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.sis differ diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.svg b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.svg new file mode 100644 index 000000000..7580e9229 --- /dev/null +++ b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader.svg @@ -0,0 +1,426 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader_installer.sis b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader_installer.sis new file mode 100644 index 000000000..ca280eb25 Binary files /dev/null and b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeReader_installer.sis differ diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.pro b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.pro deleted file mode 100644 index 89c870333..000000000 --- a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.pro +++ /dev/null @@ -1,52 +0,0 @@ -# Add more folders to ship with the application, here -folder_01.source = qml/QMLBarcodeScanner -folder_01.target = qml -DEPLOYMENTFOLDERS = folder_01 - -# Additional import path used to resolve QML modules in Creator's code model -QML_IMPORT_PATH = - -symbian:TARGET.UID3 = 0xE35E8B99 - -# Smart Installer package's UID -# This UID is from the protected range and therefore the package will -# fail to install if self-signed. By default qmake uses the unprotected -# range value if unprotected UID is defined for the application and -# 0x2002CCCF value if protected UID is given to the application -#symbian:DEPLOYMENT.installer_header = 0x2002CCCF - -# Allow network access on Symbian -#symbian:TARGET.CAPABILITY += NetworkServices - -# If your application uses the Qt Mobility libraries, uncomment the following -# lines and add the respective components to the MOBILITY variable. -# CONFIG += mobility -# MOBILITY += - -# Speed up launching on MeeGo/Harmattan when using applauncherd daemon -# CONFIG += qdeclarative-boostable - -# Add dependency to Symbian components -# CONFIG += qt-components - -# The .cpp file which was generated for your project. Feel free to hack it. -SOURCES += main.cpp - -symbian{ - LIBS += -lqzxing - customrules.pkg_prerules = \ - ";QZXing" \ - "@\"$$(EPOCROOT)Epoc32/InstallToDevice/QZXing_selfsigned.sis\",(0xE618743C)"\ - " " - DEPLOYMENT += customrules -} - -win32{ - LIBS += -LC:/QtSDKProjects/QMLBarcodeScanner/Qt_4.7.4_Desktop_Mingw \ - -lQZXing -} - -# Please do not modify the following two lines. Required for deployment. -include(qmlapplicationviewer/qmlapplicationviewer.pri) -qtcAddDeployment() - diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.pro.user b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.pro.user deleted file mode 100644 index 31638c5c8..000000000 --- a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.pro.user +++ /dev/null @@ -1,716 +0,0 @@ - - - - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - - Cpp - - false - CppGlobal - true - false - true - false - false - false - true - true - false - true - false - false - false - true - false - - - 1 - System - Project - 4 - true - 1 - true - false - true - - Cpp - - true - false - CppGlobal - 4 - 1 - false - true - 0 - 8 - - - - QmlJS - - true - false - QmlJSGlobal - 4 - 1 - false - true - 0 - 8 - - - 2 - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.Target.0 - - Symbian Device - Symbian Device - Qt4ProjectManager.Target.S60DeviceTarget - 0 - 0 - 0 - - Qt4ProjectManager.ToolChain.GCCE:C:/QtSDK/Symbian/tools/gcce4/bin/arm-none-symbianelf-g++.exe.arm-symbian-device-elf-32bit.C:/QtSDK/pythongdb/python_2.7based/gdb-arm-none-symbianelf.exe - - - qmake - - QtProjectManager.QMakeBuildStep - false - true - - true - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt 4.7.4 for Symbian Anna (Qt SDK) Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - C:/QtSDKProjects/QZXing/examples/QMLBarcodeScanner - 28 - false - - - Qt4ProjectManager.ToolChain.GCCE:C:/QtSDK/Symbian/tools/gcce4/bin/arm-none-symbianelf-g++.exe.arm-symbian-device-elf-32bit.C:/QtSDK/pythongdb/python_2.7based/gdb-arm-none-symbianelf.exe - - - qmake - - QtProjectManager.QMakeBuildStep - false - true - - true - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt 4.7.4 for Symbian Anna (Qt SDK) Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - C:/QtSDKProjects/QZXing/examples/QMLBarcodeScanner - 28 - false - - - Qt4ProjectManager.ToolChain.GCCE:C:/QtSDK/Symbian/tools/gcce4/bin/arm-none-symbianelf-g++.exe.arm-symbian-device-elf-32bit.C:/QtSDK/pythongdb/python_2.7based/gdb-arm-none-symbianelf.exe - - - qmake - - QtProjectManager.QMakeBuildStep - false - true - - true - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt 4.7.3 for Symbian^1 (Qt SDK) (2) Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - C:/QtSDKProjects/QZXing/examples/QMLBarcodeScanner - 5 - false - - - Qt4ProjectManager.ToolChain.GCCE:C:/QtSDK/Symbian/tools/gcce4/bin/arm-none-symbianelf-g++.exe.arm-symbian-device-elf-32bit.C:/QtSDK/pythongdb/python_2.7based/gdb-arm-none-symbianelf.exe - - - qmake - - QtProjectManager.QMakeBuildStep - false - true - - true - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt 4.7.3 for Symbian^1 (Qt SDK) (2) Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - C:/QtSDKProjects/QZXing/examples/QMLBarcodeScanner - 5 - false - - - Qt4ProjectManager.ToolChain.GCCE:C:/QtSDK/Symbian/tools/gcce4/bin/arm-none-symbianelf-g++.exe.arm-symbian-device-elf-32bit.C:/QtSDK/pythongdb/python_2.7based/gdb-arm-none-symbianelf.exe - - - qmake - - QtProjectManager.QMakeBuildStep - false - true - - true - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt 4.7.3 for S60 5th Edition (Qt SDK) Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - C:/QtSDKProjects/QZXing/examples/QMLBarcodeScanner - 30 - false - - - Qt4ProjectManager.ToolChain.GCCE:C:/QtSDK/Symbian/tools/gcce4/bin/arm-none-symbianelf-g++.exe.arm-symbian-device-elf-32bit.C:/QtSDK/pythongdb/python_2.7based/gdb-arm-none-symbianelf.exe - - - qmake - - QtProjectManager.QMakeBuildStep - false - true - - true - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt 4.7.3 for S60 5th Edition (Qt SDK) Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - C:/QtSDKProjects/QZXing/examples/QMLBarcodeScanner - 30 - false - - - Qt4ProjectManager.ToolChain.GCCE:C:/QtSDK/Symbian/tools/gcce4/bin/arm-none-symbianelf-g++.exe.arm-symbian-device-elf-32bit.C:/QtSDK/pythongdb/python_2.7based/gdb-arm-none-symbianelf.exe - - - qmake - - QtProjectManager.QMakeBuildStep - false - true - - true - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt 4.6.3 for Symbian^1 (Qt SDK) (2) Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - C:/QtSDKProjects/QZXing/examples/QMLBarcodeScanner - 15 - false - - - Qt4ProjectManager.ToolChain.GCCE:C:/QtSDK/Symbian/tools/gcce4/bin/arm-none-symbianelf-g++.exe.arm-symbian-device-elf-32bit.C:/QtSDK/pythongdb/python_2.7based/gdb-arm-none-symbianelf.exe - - - qmake - - QtProjectManager.QMakeBuildStep - false - true - - true - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt 4.6.3 for Symbian^1 (Qt SDK) (2) Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - C:/QtSDKProjects/QZXing/examples/QMLBarcodeScanner - 15 - false - - - Qt4ProjectManager.ToolChain.GCCE:C:/QtSDK/Symbian/tools/gcce4/bin/arm-none-symbianelf-g++.exe.arm-symbian-device-elf-32bit.C:/QtSDK/pythongdb/python_2.7based/gdb-arm-none-symbianelf.exe - - - qmake - - QtProjectManager.QMakeBuildStep - false - true - - true - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt 4.6.3 for Symbian^1 (Qt SDK) Debug - - Qt4ProjectManager.Qt4BuildConfiguration - 2 - C:/QtSDKProjects/QZXing/examples/QMLBarcodeScanner - 31 - false - - - Qt4ProjectManager.ToolChain.GCCE:C:/QtSDK/Symbian/tools/gcce4/bin/arm-none-symbianelf-g++.exe.arm-symbian-device-elf-32bit.C:/QtSDK/pythongdb/python_2.7based/gdb-arm-none-symbianelf.exe - - - qmake - - QtProjectManager.QMakeBuildStep - false - true - - true - - - Make - - Qt4ProjectManager.MakeStep - false - - - - 2 - Build - - ProjectExplorer.BuildSteps.Build - - - - Make - - Qt4ProjectManager.MakeStep - true - clean - - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Qt 4.6.3 for Symbian^1 (Qt SDK) Release - - Qt4ProjectManager.Qt4BuildConfiguration - 0 - C:/QtSDKProjects/QZXing/examples/QMLBarcodeScanner - 31 - false - - 10 - - - - Create SIS Package - - Qt4ProjectManager.S60SignBuildStep - - - 0 - false - false - - - Deploy - - Qt4ProjectManager.S60DeployStep - - 2 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy QMLBarcodeScanner to Symbian device - - Qt4ProjectManager.S60DeployConfiguration - 0 - - 65029 - C - - true - - 1 - - true - true - - - false - false - false - false - false - false - false - false - true - true - 0.01 - 0.01 - 10 - 10 - true - true - 25 - 25 - - - true - true - valgrind - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - QMLBarcodeScanner on Symbian Device - - Qt4ProjectManager.S60DeviceRunConfiguration - - QMLBarcodeScanner.pro - 3768 - true - true - false - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.EnvironmentId - {167d5df2-461a-41e0-a9f8-c131845c1f19} - - - ProjectExplorer.Project.Updater.FileVersion - 10 - - diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.sis b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.sis deleted file mode 100644 index a1af3dae4..000000000 Binary files a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.sis and /dev/null differ diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.svg b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.svg deleted file mode 100644 index 84b252bbf..000000000 --- a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner.svg +++ /dev/null @@ -1,345 +0,0 @@ - - - - - - - diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner_installer.sis b/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner_installer.sis deleted file mode 100644 index 1d099ef95..000000000 Binary files a/symbian/QZXing/examples/QMLBarcodeScanner/QMLBarcodeScanner_installer.sis and /dev/null differ diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/ZXing_Licence.txt b/symbian/QZXing/examples/QMLBarcodeScanner/ZXing_Licence.txt deleted file mode 100644 index 29f81d812..000000000 --- a/symbian/QZXing/examples/QMLBarcodeScanner/ZXing_Licence.txt +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/ZoomControl.qml b/symbian/QZXing/examples/QMLBarcodeScanner/ZoomControl.qml similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/ZoomControl.qml rename to symbian/QZXing/examples/QMLBarcodeScanner/ZoomControl.qml diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/declarative-camera.qml b/symbian/QZXing/examples/QMLBarcodeScanner/declarative-camera.qml similarity index 59% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/declarative-camera.qml rename to symbian/QZXing/examples/QMLBarcodeScanner/declarative-camera.qml index 60f2a3aae..568f5b01b 100644 --- a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/declarative-camera.qml +++ b/symbian/QZXing/examples/QMLBarcodeScanner/declarative-camera.qml @@ -40,7 +40,7 @@ import Qt 4.7 import QtMultimediaKit 1.1 -import QZXing 1.0 +import QZXing 1.2 Rectangle { id : cameraUI @@ -57,88 +57,34 @@ Rectangle { flashMode: stillControls.flashMode whiteBalanceMode: stillControls.whiteBalance - exposureCompensation: stillControls.exposureCompensation +// exposureCompensation: stillControls.exposureCompensation onImageCaptured : { - decoder.decodeImage(preview); + imageToDecode.source = preview + decoder.decodeImageQML(imageToDecode); } } + Image{ + id: imageToDecode + visible: false + } + CaptureControls { id: stillControls anchors.fill: parent camera: camera } + MessageDialog{ + id:dialog + } + QZXing{ id: decoder onTagFound: { - messageBox.setText(tag) - messageBox.state = "visible" + dialog.text = tag + dialog.open(); } - - function enableQrCodeAndEAN() - { - setDecoder(DecoderFormat_QR_CODE | DecoderFormat_EAN_13); - } - } - - Rectangle{ - id: messageBox - anchors.left: cameraUI.left - anchors.leftMargin: 10 - anchors.right: cameraUI.right - anchors.rightMargin: 10 - y: cameraUI.height / 4 - height: cameraUI.height/2 - - state: "hidden" - - function setText(str) - { - textArea.text = str; - } - - Text{ - id: textArea - anchors.centerIn: parent - } - - Rectangle{ - border.width: 2 - width: tagLabel.width - height: tagLabel.height - anchors.bottom: messageBox.bottom - anchors.bottomMargin: 5 - anchors.right: messageBox.right - anchors.rightMargin: 5 - - Text{ - id: tagLabel - text: "close" - } - MouseArea{ - anchors.fill: parent - onClicked: messageBox.state = "hidden" - } - } - - states:[ - State{ - name: "visible" - PropertyChanges { - target: messageBox - opacity: 1 - } - }, - State{ - name: "hidden" - PropertyChanges { - target: messageBox - opacity: 0 - } - } - ] - Behavior on opacity{NumberAnimation{duration:100}} } } diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/declarative-camera.qmlproject b/symbian/QZXing/examples/QMLBarcodeScanner/declarative-camera.qmlproject new file mode 100644 index 000000000..0d93065fd --- /dev/null +++ b/symbian/QZXing/examples/QMLBarcodeScanner/declarative-camera.qmlproject @@ -0,0 +1,18 @@ +/* File generated by QtCreator */ + +import QmlProject 1.0 + +Project { + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } + /* List of plugin directories passed to QML runtime */ + // importPaths: [ "../exampleplugin" ] +} diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/declarative-camera.qrc b/symbian/QZXing/examples/QMLBarcodeScanner/declarative-camera.qrc new file mode 100644 index 000000000..a4f417299 --- /dev/null +++ b/symbian/QZXing/examples/QMLBarcodeScanner/declarative-camera.qrc @@ -0,0 +1,27 @@ + + + declarative-camera.qml + CameraButton.qml + CameraPropertyPopup.qml + CameraPropertyButton.qml + CaptureControls.qml + ExposureCompensationButton.qml + FlickableList.qml + FocusButton.qml + PhotoPreview.qml + ZoomControl.qml + images/camera_auto_mode.png + images/camera_camera_setting.png + images/camera_flash_auto.png + images/camera_flash_fill.png + images/camera_flash_off.png + images/camera_flash_redeye.png + images/camera_white_balance_cloudy.png + images/camera_white_balance_flourescent.png + images/camera_white_balance_incandescent.png + images/camera_white_balance_sunny.png + images/toolbutton.png + images/toolbutton.sci + MessageDialog.qml + + diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_auto_mode.png b/symbian/QZXing/examples/QMLBarcodeScanner/images/camera_auto_mode.png similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_auto_mode.png rename to symbian/QZXing/examples/QMLBarcodeScanner/images/camera_auto_mode.png diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_camera_setting.png b/symbian/QZXing/examples/QMLBarcodeScanner/images/camera_camera_setting.png similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_camera_setting.png rename to symbian/QZXing/examples/QMLBarcodeScanner/images/camera_camera_setting.png diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_flash_auto.png b/symbian/QZXing/examples/QMLBarcodeScanner/images/camera_flash_auto.png similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_flash_auto.png rename to symbian/QZXing/examples/QMLBarcodeScanner/images/camera_flash_auto.png diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_flash_fill.png b/symbian/QZXing/examples/QMLBarcodeScanner/images/camera_flash_fill.png similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_flash_fill.png rename to symbian/QZXing/examples/QMLBarcodeScanner/images/camera_flash_fill.png diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_flash_off.png b/symbian/QZXing/examples/QMLBarcodeScanner/images/camera_flash_off.png similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_flash_off.png rename to symbian/QZXing/examples/QMLBarcodeScanner/images/camera_flash_off.png diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_flash_redeye.png b/symbian/QZXing/examples/QMLBarcodeScanner/images/camera_flash_redeye.png similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_flash_redeye.png rename to symbian/QZXing/examples/QMLBarcodeScanner/images/camera_flash_redeye.png diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_white_balance_cloudy.png b/symbian/QZXing/examples/QMLBarcodeScanner/images/camera_white_balance_cloudy.png similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_white_balance_cloudy.png rename to symbian/QZXing/examples/QMLBarcodeScanner/images/camera_white_balance_cloudy.png diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_white_balance_flourescent.png b/symbian/QZXing/examples/QMLBarcodeScanner/images/camera_white_balance_flourescent.png similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_white_balance_flourescent.png rename to symbian/QZXing/examples/QMLBarcodeScanner/images/camera_white_balance_flourescent.png diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_white_balance_incandescent.png b/symbian/QZXing/examples/QMLBarcodeScanner/images/camera_white_balance_incandescent.png similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_white_balance_incandescent.png rename to symbian/QZXing/examples/QMLBarcodeScanner/images/camera_white_balance_incandescent.png diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_white_balance_sunny.png b/symbian/QZXing/examples/QMLBarcodeScanner/images/camera_white_balance_sunny.png similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/camera_white_balance_sunny.png rename to symbian/QZXing/examples/QMLBarcodeScanner/images/camera_white_balance_sunny.png diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/toolbutton.png b/symbian/QZXing/examples/QMLBarcodeScanner/images/toolbutton.png similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/toolbutton.png rename to symbian/QZXing/examples/QMLBarcodeScanner/images/toolbutton.png diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/toolbutton.sci b/symbian/QZXing/examples/QMLBarcodeScanner/images/toolbutton.sci similarity index 100% rename from symbian/QZXing/examples/QMLBarcodeScanner/qml/QMLBarcodeScanner/images/toolbutton.sci rename to symbian/QZXing/examples/QMLBarcodeScanner/images/toolbutton.sci diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/main.cpp b/symbian/QZXing/examples/QMLBarcodeScanner/main.cpp deleted file mode 100644 index 5dbb64b5d..000000000 --- a/symbian/QZXing/examples/QMLBarcodeScanner/main.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include -#include "qmlapplicationviewer.h" - -int main(int argc, char *argv[]) -{ - QScopedPointer app(createApplication(argc, argv)); - QScopedPointer viewer(QmlApplicationViewer::create()); - - QZXing::registerQMLTypes(); - - viewer->setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait); - viewer->setMainQmlFile(QLatin1String("qml/QMLBarcodeScanner/declarative-camera.qml")); - viewer->showExpanded(); - - return app->exec(); -} diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qmlapplicationviewer/qmlapplicationviewer.cpp b/symbian/QZXing/examples/QMLBarcodeScanner/qmlapplicationviewer/qmlapplicationviewer.cpp deleted file mode 100644 index 132b41d25..000000000 --- a/symbian/QZXing/examples/QMLBarcodeScanner/qmlapplicationviewer/qmlapplicationviewer.cpp +++ /dev/null @@ -1,200 +0,0 @@ -// checksum 0x78c version 0x60010 -/* - This file was generated by the Qt Quick Application wizard of Qt Creator. - QmlApplicationViewer is a convenience class containing mobile device specific - code such as screen orientation handling. Also QML paths and debugging are - handled here. - It is recommended not to modify this file, since newer versions of Qt Creator - may offer an updated version of it. -*/ - -#include "qmlapplicationviewer.h" - -#include -#include -#include -#include -#include -#include - -#include // MEEGO_EDITION_HARMATTAN - -#ifdef HARMATTAN_BOOSTER -#include -#endif - -#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 - -#include - -#if !defined(NO_JSDEBUGGER) -#include -#endif -#if !defined(NO_QMLOBSERVER) -#include -#endif - -// Enable debugging before any QDeclarativeEngine is created -struct QmlJsDebuggingEnabler -{ - QmlJsDebuggingEnabler() - { - QDeclarativeDebugHelper::enableDebugging(); - } -}; - -// Execute code in constructor before first QDeclarativeEngine is instantiated -static QmlJsDebuggingEnabler enableDebuggingHelper; - -#endif // QMLJSDEBUGGER - -class QmlApplicationViewerPrivate -{ - QmlApplicationViewerPrivate(QDeclarativeView *view_) : view(view_) {} - - QString mainQmlFile; - QDeclarativeView *view; - friend class QmlApplicationViewer; - QString adjustPath(const QString &path); -}; - -QString QmlApplicationViewerPrivate::adjustPath(const QString &path) -{ -#ifdef Q_OS_UNIX -#ifdef Q_OS_MAC - if (!QDir::isAbsolutePath(path)) - return QCoreApplication::applicationDirPath() - + QLatin1String("/../Resources/") + path; -#else - QString pathInInstallDir; - const QString applicationDirPath = QCoreApplication::applicationDirPath(); - pathInInstallDir = QString::fromAscii("%1/../%2").arg(applicationDirPath, path); - - if (QFileInfo(pathInInstallDir).exists()) - return pathInInstallDir; -#endif -#endif - return path; -} - -QmlApplicationViewer::QmlApplicationViewer(QWidget *parent) - : QDeclarativeView(parent) - , d(new QmlApplicationViewerPrivate(this)) -{ - connect(engine(), SIGNAL(quit()), SLOT(close())); - setResizeMode(QDeclarativeView::SizeRootObjectToView); - // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in -#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 -#if !defined(NO_JSDEBUGGER) - new QmlJSDebugger::JSDebuggerAgent(d->view->engine()); -#endif -#if !defined(NO_QMLOBSERVER) - new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view); -#endif -#endif -} - -QmlApplicationViewer::QmlApplicationViewer(QDeclarativeView *view, QWidget *parent) - : QDeclarativeView(parent) - , d(new QmlApplicationViewerPrivate(view)) -{ - connect(view->engine(), SIGNAL(quit()), view, SLOT(close())); - view->setResizeMode(QDeclarativeView::SizeRootObjectToView); - // Qt versions prior to 4.8.0 don't have QML/JS debugging services built in -#if defined(QMLJSDEBUGGER) && QT_VERSION < 0x040800 -#if !defined(NO_JSDEBUGGER) - new QmlJSDebugger::JSDebuggerAgent(d->view->engine()); -#endif -#if !defined(NO_QMLOBSERVER) - new QmlJSDebugger::QDeclarativeViewObserver(d->view, d->view); -#endif -#endif -} - -QmlApplicationViewer::~QmlApplicationViewer() -{ - delete d; -} - -QmlApplicationViewer *QmlApplicationViewer::create() -{ -#ifdef HARMATTAN_BOOSTER - return new QmlApplicationViewer(MDeclarativeCache::qDeclarativeView(), 0); -#else - return new QmlApplicationViewer(); -#endif -} - -void QmlApplicationViewer::setMainQmlFile(const QString &file) -{ - d->mainQmlFile = d->adjustPath(file); - d->view->setSource(QUrl::fromLocalFile(d->mainQmlFile)); -} - -void QmlApplicationViewer::addImportPath(const QString &path) -{ - d->view->engine()->addImportPath(d->adjustPath(path)); -} - -void QmlApplicationViewer::setOrientation(ScreenOrientation orientation) -{ -#if defined(Q_OS_SYMBIAN) - // If the version of Qt on the device is < 4.7.2, that attribute won't work - if (orientation != ScreenOrientationAuto) { - const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.')); - if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) { - qWarning("Screen orientation locking only supported with Qt 4.7.2 and above"); - return; - } - } -#endif // Q_OS_SYMBIAN - - Qt::WidgetAttribute attribute; - switch (orientation) { -#if QT_VERSION < 0x040702 - // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes - case ScreenOrientationLockPortrait: - attribute = static_cast(128); - break; - case ScreenOrientationLockLandscape: - attribute = static_cast(129); - break; - default: - case ScreenOrientationAuto: - attribute = static_cast(130); - break; -#else // QT_VERSION < 0x040702 - case ScreenOrientationLockPortrait: - attribute = Qt::WA_LockPortraitOrientation; - break; - case ScreenOrientationLockLandscape: - attribute = Qt::WA_LockLandscapeOrientation; - break; - default: - case ScreenOrientationAuto: - attribute = Qt::WA_AutoOrientation; - break; -#endif // QT_VERSION < 0x040702 - }; - setAttribute(attribute, true); -} - -void QmlApplicationViewer::showExpanded() -{ -#if defined(Q_OS_SYMBIAN) || defined(MEEGO_EDITION_HARMATTAN) || defined(Q_WS_SIMULATOR) - d->view->showFullScreen(); -#elif defined(Q_WS_MAEMO_5) - d->view->showMaximized(); -#else - d->view->show(); -#endif -} - -QApplication *createApplication(int &argc, char **argv) -{ -#ifdef HARMATTAN_BOOSTER - return MDeclarativeCache::qApplication(argc, argv); -#else - return new QApplication(argc, argv); -#endif -} diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qmlapplicationviewer/qmlapplicationviewer.h b/symbian/QZXing/examples/QMLBarcodeScanner/qmlapplicationviewer/qmlapplicationviewer.h deleted file mode 100644 index 48151cec8..000000000 --- a/symbian/QZXing/examples/QMLBarcodeScanner/qmlapplicationviewer/qmlapplicationviewer.h +++ /dev/null @@ -1,47 +0,0 @@ -// checksum 0x82ed version 0x60010 -/* - This file was generated by the Qt Quick Application wizard of Qt Creator. - QmlApplicationViewer is a convenience class containing mobile device specific - code such as screen orientation handling. Also QML paths and debugging are - handled here. - It is recommended not to modify this file, since newer versions of Qt Creator - may offer an updated version of it. -*/ - -#ifndef QMLAPPLICATIONVIEWER_H -#define QMLAPPLICATIONVIEWER_H - -#include - -class QmlApplicationViewer : public QDeclarativeView -{ - Q_OBJECT - -public: - enum ScreenOrientation { - ScreenOrientationLockPortrait, - ScreenOrientationLockLandscape, - ScreenOrientationAuto - }; - - explicit QmlApplicationViewer(QWidget *parent = 0); - virtual ~QmlApplicationViewer(); - - static QmlApplicationViewer *create(); - - void setMainQmlFile(const QString &file); - void addImportPath(const QString &path); - - // Note that this will only have an effect on Symbian and Fremantle. - void setOrientation(ScreenOrientation orientation); - - void showExpanded(); - -private: - explicit QmlApplicationViewer(QDeclarativeView *view, QWidget *parent); - class QmlApplicationViewerPrivate *d; -}; - -QApplication *createApplication(int &argc, char **argv); - -#endif // QMLAPPLICATIONVIEWER_H diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qmlapplicationviewer/qmlapplicationviewer.pri b/symbian/QZXing/examples/QMLBarcodeScanner/qmlapplicationviewer/qmlapplicationviewer.pri deleted file mode 100644 index 8357ac31d..000000000 --- a/symbian/QZXing/examples/QMLBarcodeScanner/qmlapplicationviewer/qmlapplicationviewer.pri +++ /dev/null @@ -1,146 +0,0 @@ -# checksum 0x368d version 0x60010 -# This file was generated by the Qt Quick Application wizard of Qt Creator. -# The code below adds the QmlApplicationViewer to the project and handles the -# activation of QML debugging. -# It is recommended not to modify this file, since newer versions of Qt Creator -# may offer an updated version of it. - -QT += declarative - -SOURCES += $$PWD/qmlapplicationviewer.cpp -HEADERS += $$PWD/qmlapplicationviewer.h -INCLUDEPATH += $$PWD - -# Include JS debugger library if QMLJSDEBUGGER_PATH is set -!isEmpty(QMLJSDEBUGGER_PATH) { - include($$QMLJSDEBUGGER_PATH/qmljsdebugger-lib.pri) -} else { - DEFINES -= QMLJSDEBUGGER -} - -contains(CONFIG,qdeclarative-boostable):contains(MEEGO_EDITION,harmattan) { - DEFINES += HARMATTAN_BOOSTER -} -# This file was generated by an application wizard of Qt Creator. -# The code below handles deployment to Symbian and Maemo, aswell as copying -# of the application data to shadow build directories on desktop. -# It is recommended not to modify this file, since newer versions of Qt Creator -# may offer an updated version of it. - -defineTest(qtcAddDeployment) { -for(deploymentfolder, DEPLOYMENTFOLDERS) { - item = item$${deploymentfolder} - itemsources = $${item}.sources - $$itemsources = $$eval($${deploymentfolder}.source) - itempath = $${item}.path - $$itempath= $$eval($${deploymentfolder}.target) - export($$itemsources) - export($$itempath) - DEPLOYMENT += $$item -} - -MAINPROFILEPWD = $$PWD - -symbian { - isEmpty(ICON):exists($${TARGET}.svg):ICON = $${TARGET}.svg - isEmpty(TARGET.EPOCHEAPSIZE):TARGET.EPOCHEAPSIZE = 0x20000 0x2000000 -} else:win32 { - copyCommand = - for(deploymentfolder, DEPLOYMENTFOLDERS) { - source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) - source = $$replace(source, /, \\) - sourcePathSegments = $$split(source, \\) - target = $$OUT_PWD/$$eval($${deploymentfolder}.target)/$$last(sourcePathSegments) - target = $$replace(target, /, \\) - !isEqual(source,$$target) { - !isEmpty(copyCommand):copyCommand += && - isEqual(QMAKE_DIR_SEP, \\) { - copyCommand += $(COPY_DIR) \"$$source\" \"$$target\" - } else { - source = $$replace(source, \\\\, /) - target = $$OUT_PWD/$$eval($${deploymentfolder}.target) - target = $$replace(target, \\\\, /) - copyCommand += test -d \"$$target\" || mkdir -p \"$$target\" && cp -r \"$$source\" \"$$target\" - } - } - } - !isEmpty(copyCommand) { - copyCommand = @echo Copying application data... && $$copyCommand - copydeploymentfolders.commands = $$copyCommand - first.depends = $(first) copydeploymentfolders - export(first.depends) - export(copydeploymentfolders.commands) - QMAKE_EXTRA_TARGETS += first copydeploymentfolders - } -} else:unix { - maemo5 { - desktopfile.files = $${TARGET}.desktop - desktopfile.path = /usr/share/applications/hildon - icon.files = $${TARGET}64.png - icon.path = /usr/share/icons/hicolor/64x64/apps - } else:!isEmpty(MEEGO_VERSION_MAJOR) { - desktopfile.files = $${TARGET}_harmattan.desktop - desktopfile.path = /usr/share/applications - icon.files = $${TARGET}80.png - icon.path = /usr/share/icons/hicolor/80x80/apps - } else { # Assumed to be a Desktop Unix - copyCommand = - for(deploymentfolder, DEPLOYMENTFOLDERS) { - source = $$MAINPROFILEPWD/$$eval($${deploymentfolder}.source) - source = $$replace(source, \\\\, /) - macx { - target = $$OUT_PWD/$${TARGET}.app/Contents/Resources/$$eval($${deploymentfolder}.target) - } else { - target = $$OUT_PWD/$$eval($${deploymentfolder}.target) - } - target = $$replace(target, \\\\, /) - sourcePathSegments = $$split(source, /) - targetFullPath = $$target/$$last(sourcePathSegments) - !isEqual(source,$$targetFullPath) { - !isEmpty(copyCommand):copyCommand += && - copyCommand += $(MKDIR) \"$$target\" - copyCommand += && $(COPY_DIR) \"$$source\" \"$$target\" - } - } - !isEmpty(copyCommand) { - copyCommand = @echo Copying application data... && $$copyCommand - copydeploymentfolders.commands = $$copyCommand - first.depends = $(first) copydeploymentfolders - export(first.depends) - export(copydeploymentfolders.commands) - QMAKE_EXTRA_TARGETS += first copydeploymentfolders - } - } - installPrefix = /opt/$${TARGET} - for(deploymentfolder, DEPLOYMENTFOLDERS) { - item = item$${deploymentfolder} - itemfiles = $${item}.files - $$itemfiles = $$eval($${deploymentfolder}.source) - itempath = $${item}.path - $$itempath = $${installPrefix}/$$eval($${deploymentfolder}.target) - export($$itemfiles) - export($$itempath) - INSTALLS += $$item - } - - !isEmpty(desktopfile.path) { - export(icon.files) - export(icon.path) - export(desktopfile.files) - export(desktopfile.path) - INSTALLS += icon desktopfile - } - - target.path = $${installPrefix}/bin - export(target.path) - INSTALLS += target -} - -export (ICON) -export (INSTALLS) -export (DEPLOYMENT) -export (TARGET.EPOCHEAPSIZE) -export (TARGET.CAPABILITY) -export (LIBS) -export (QMAKE_EXTRA_TARGETS) -} diff --git a/symbian/QZXing/examples/QMLBarcodeScanner/qmlcamera.cpp b/symbian/QZXing/examples/QMLBarcodeScanner/qmlcamera.cpp new file mode 100644 index 000000000..3958f9b8a --- /dev/null +++ b/symbian/QZXing/examples/QMLBarcodeScanner/qmlcamera.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +#include + +#if !defined(QT_NO_OPENGL) +#include +#endif + +int main(int argc, char *argv[]) +{ + + QZXing::registerQMLTypes(); + +#if defined (Q_WS_X11) || defined (Q_WS_MAC) || defined (Q_OS_SYMBIAN) + //### default to using raster graphics backend for now + bool gsSpecified = false; + for (int i = 0; i < argc; ++i) { + QString arg = argv[i]; + if (arg == "-graphicssystem") { + gsSpecified = true; + break; + } + } + + if (!gsSpecified) + QApplication::setGraphicsSystem("raster"); +#endif + + QApplication application(argc, argv); + const QString mainQmlApp = QLatin1String("qrc:/declarative-camera.qml"); + QDeclarativeView view; +#if !defined(QT_NO_OPENGL) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_S60) + view.setViewport(new QGLWidget); +#endif + view.setSource(QUrl(mainQmlApp)); + view.setResizeMode(QDeclarativeView::SizeRootObjectToView); + // Qt.quit() called in embedded .qml by default only emits + // quit() signal, so do this (optionally use Qt.exit()). + QObject::connect(view.engine(), SIGNAL(quit()), qApp, SLOT(quit())); +#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) + view.setGeometry(application.desktop()->screenGeometry()); + view.showFullScreen(); +#else + view.setGeometry(QRect(100, 100, 800, 480)); + view.show(); +#endif + return application.exec(); +} + diff --git a/symbian/QZXing/examples/QQrDecoder/.gitignore b/symbian/QZXing/examples/QQrDecoder/.gitignore new file mode 100644 index 000000000..6fa3bc538 --- /dev/null +++ b/symbian/QZXing/examples/QQrDecoder/.gitignore @@ -0,0 +1,14 @@ +moc/ +obj/ +rcc/ +tmp/ +ui/ +.make.cache +*.BAT +*.inf +Makefile +*.mk +*.loc +*.user +*.mmp +*.pkg \ No newline at end of file diff --git a/symbian/QZXing/examples/QQrDecoder/MyVideoSurface.cpp b/symbian/QZXing/examples/QQrDecoder/MyVideoSurface.cpp index 22b4885a1..88623527c 100644 --- a/symbian/QZXing/examples/QQrDecoder/MyVideoSurface.cpp +++ b/symbian/QZXing/examples/QQrDecoder/MyVideoSurface.cpp @@ -71,6 +71,7 @@ QList MyVideoSurface::supportedPixelFormats( { if (handleType == QAbstractVideoBuffer::NoHandle) { return QList() + << QVideoFrame::Format_UYVY << QVideoFrame::Format_RGB32 << QVideoFrame::Format_ARGB32 << QVideoFrame::Format_ARGB32_Premultiplied diff --git a/symbian/QZXing/examples/QQrDecoder/Nokia_Licence.txt b/symbian/QZXing/examples/QQrDecoder/Nokia_Licence.txt new file mode 100644 index 000000000..80f675d91 --- /dev/null +++ b/symbian/QZXing/examples/QQrDecoder/Nokia_Licence.txt @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ \ No newline at end of file diff --git a/symbian/QZXing/examples/QQrDecoder/QCameraControllerWidget.cpp b/symbian/QZXing/examples/QQrDecoder/QCameraControllerWidget.cpp index 54b9185fb..ad3273cf0 100644 --- a/symbian/QZXing/examples/QQrDecoder/QCameraControllerWidget.cpp +++ b/symbian/QZXing/examples/QQrDecoder/QCameraControllerWidget.cpp @@ -153,6 +153,8 @@ QCameraControllerWidget::~QCameraControllerWidget() void QCameraControllerWidget::enableCamera() { + + //QVideoFrame::Format_UYVY; m_camera = new QCamera(); m_camera->setCaptureMode(QCamera::CaptureStillImage); connect(m_camera, SIGNAL(error(QCamera::Error)), this, SLOT(error(QCamera::Error))); diff --git a/symbian/QZXing/examples/QQrDecoder/QQrDecoder.cpp b/symbian/QZXing/examples/QQrDecoder/QQrDecoder.cpp index 029a6fcf1..02ea56d5f 100644 --- a/symbian/QZXing/examples/QQrDecoder/QQrDecoder.cpp +++ b/symbian/QZXing/examples/QQrDecoder/QQrDecoder.cpp @@ -44,7 +44,7 @@ QQrDecoder::QQrDecoder(QWidget *parent): QMainWindow(parent), decoder(this) //by default all decoders available are enabled //decoder.setDecoder( QZXing::DecoderFormat_DATA_MATRIX); - //decoder.setDecoder( DecoderFormat_QR_CODE | DecoderFormat_EAN_13 ); + //decoder.setDecoder( QZXing::DecoderFormat_Aztec ); } QQrDecoder::~QQrDecoder() diff --git a/symbian/QZXing/examples/QQrDecoder/QQrDecoder.pro b/symbian/QZXing/examples/QQrDecoder/QQrDecoder.pro index 101d16e97..08a0a36fe 100644 --- a/symbian/QZXing/examples/QQrDecoder/QQrDecoder.pro +++ b/symbian/QZXing/examples/QQrDecoder/QQrDecoder.pro @@ -4,7 +4,7 @@ QT += core \ gui \ declarative -VERSION = 1.2.1 +VERSION = 1.3.0 CONFIG += mobility MOBILITY = multimedia #\ diff --git a/symbian/QZXing/examples/QQrDecoder/QQrDecoder.rss b/symbian/QZXing/examples/QQrDecoder/QQrDecoder.rss new file mode 100644 index 000000000..aaa13e7e4 --- /dev/null +++ b/symbian/QZXing/examples/QQrDecoder/QQrDecoder.rss @@ -0,0 +1,22 @@ +// ============================================================================ +// * Generated by qmake (2.01a) (Qt 4.7.3) on: 2012-05-14T15:44:30 +// * This file is generated by qmake and should not be modified by the +// * user. +// ============================================================================ + +CHARACTER_SET UTF8 +#include +#include "QQrDecoder.loc" + +RESOURCE LOCALISABLE_APP_INFO r_localisable_app_info + { + short_caption = STRING_r_short_caption; + caption_and_icon = + CAPTION_AND_ICON_INFO + { + caption = STRING_r_caption; + number_of_icons = 1; + icon_file = "\\resource\\apps\\QQrDecoder.mif"; + }; + } + diff --git a/symbian/QZXing/examples/QQrDecoder/QQrDecoder.sis b/symbian/QZXing/examples/QQrDecoder/QQrDecoder.sis index d23818a55..43f3174ec 100644 Binary files a/symbian/QZXing/examples/QQrDecoder/QQrDecoder.sis and b/symbian/QZXing/examples/QQrDecoder/QQrDecoder.sis differ diff --git a/symbian/QZXing/examples/QQrDecoder/QQrDecoder.svg b/symbian/QZXing/examples/QQrDecoder/QQrDecoder.svg index c8a28b15d..7580e9229 100644 --- a/symbian/QZXing/examples/QQrDecoder/QQrDecoder.svg +++ b/symbian/QZXing/examples/QQrDecoder/QQrDecoder.svg @@ -1,356 +1,426 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/symbian/QZXing/examples/QQrDecoder/QQrDecoder_reg.rss b/symbian/QZXing/examples/QQrDecoder/QQrDecoder_reg.rss new file mode 100644 index 000000000..c140664e6 --- /dev/null +++ b/symbian/QZXing/examples/QQrDecoder/QQrDecoder_reg.rss @@ -0,0 +1,18 @@ +// ============================================================================ +// * Generated by qmake (2.01a) (Qt 4.7.3) on: 2012-05-14T15:44:30 +// * This file is generated by qmake and should not be modified by the +// * user. +// ============================================================================ + +#include +#include + +UID2 KUidAppRegistrationResourceFile +UID3 0xEF2CE79D + +RESOURCE APP_REGISTRATION_INFO + { + app_file="QQrDecoder"; + localisable_resource_file="\\resource\\apps\\QQrDecoder"; + + } diff --git a/symbian/QZXing/examples/QQrDecoder_tutorial.txt b/symbian/QZXing/examples/QQrDecoder_tutorial.txt deleted file mode 100644 index 8050daaef..000000000 --- a/symbian/QZXing/examples/QQrDecoder_tutorial.txt +++ /dev/null @@ -1,55 +0,0 @@ -QQrDecoder project is developed entirely in Qt SDK + using the CPP part of the ZXing library. -It supports the latest version of Qt in Symbian (4.7.x) and the camera is controled using the Camera APIs from Qt Mobility project. -Thus we reasure the compatibility with future releases of Qt and the compatibility with newer device with Symbian^3, Belle and Anna (and S60 5th). - -The project's folder contains the code as well as the an installation file in case you want try it out without compiling the project. - -NOTE: this project, since it uses Camera APIs from Qt Mobility breaks the backward compatibility with non touch-screen devices. So this project -can't be used at device with OS: S60 3rd. - -== Prerequisities to compile == - -* Have Qt SDK installed. This will give you all the tools needed such as the Qt SDK, Qt Mobility APIs and the Qt Creator IDE. - http://qt.nokia.com/downloads/ - -== Prerequisities to install and run to device == - -* Have Qt 4.7.3 (and newer) binaries installed to the device. -* Have Qt Mobility 1.1.0 (and newer) binaries installed to the device. - -NOTE: those binaries, if Qt SDK is installed, can be found under the path \QtSDK\Symbian\sis\Symbian^X\ - -== Importing the project == - -For this step, Qt Creator IDE will be used (contained in Qt SDK). The project can be imported/opened with 2 ways. - -NOTE: The project folder must be placed under the same drive letter as the installed Qt SDK. For example "C:\QtSDK" and "C:\QtProjects\QQrDecoder" - -# Go the the project's folder and double-click the QQrDecoder.pro file. This will result the Qt Creator to open. (This requires that Qt Creator is - selected as the predefined program to open such files which is automatically set when installing Qt SDK.) -# Alternatively, open Qt Creator manualy, and go under: "File" -> "Open File or Project...", go to the project's folder and select once again the - QQrDecoder.pro. - -Whichever step from the above you have followed, now you are led to screen named "Project Setup". Here you select the Target Platform. -You can select "Symbian Device" to target directly for a physical device, or "Qt Simulator" to first test it to the build-in simulator. - -== Building the project == - -At this point you have imported the project and you are ready to compile it. At the left toolbar in Qt Creator, above the green arrow you can see the -current target platform selected. Press to select which you want. - -Now by pressing Ctrl+B or the "hammer icon" on the left at the bottom. Normaly this should be completed without errors (might be lots of wrning though -which we selectively reject them from our mind :P ) - -This step compiles the project BUT doesn't produces the .sis file (the installation file). To create the installation file you have to press the "Run button". -It that "Green arrow" on your left, or by simply pressing Ctrl+R. Regardless if you have a device or not, the .sis file will be created. - -Now you can install it to your device. - -== Additional information == -For afew more details about the implementation you can see the following page: -http://wiki.forum.nokia.com/index.php/Qr_Decoder_in_Qt - -== The same project in Symbian C++ == - -In case you are interested in using this project with only Symbian C++, take a look at ZXingBarcodeReader folder. \ No newline at end of file diff --git a/symbian/QZXing/source/.gitignore b/symbian/QZXing/source/.gitignore new file mode 100644 index 000000000..6fa3bc538 --- /dev/null +++ b/symbian/QZXing/source/.gitignore @@ -0,0 +1,14 @@ +moc/ +obj/ +rcc/ +tmp/ +ui/ +.make.cache +*.BAT +*.inf +Makefile +*.mk +*.loc +*.user +*.mmp +*.pkg \ No newline at end of file diff --git a/symbian/QZXing/source/QZXing.pro b/symbian/QZXing/source/QZXing.pro index 37ab309bc..22208c70f 100644 --- a/symbian/QZXing/source/QZXing.pro +++ b/symbian/QZXing/source/QZXing.pro @@ -6,182 +6,204 @@ QT += core gui -VERSION = 1.1 +VERSION = 1.2 greaterThan(QT_VERSION, 4.7): QT += declarative TARGET = QZXing TEMPLATE = lib +# CONFIG += staticlib + DEFINES += QZXING_LIBRARY \ ZXING_ICONV_CONST INCLUDEPATH += ./ -HEADERS += zxing/BarcodeFormat.h \ - zxing/Binarizer.h \ - zxing/BinaryBitmap.h \ - zxing/DecodeHints.h \ - zxing/Exception.h \ - zxing/LuminanceSource.h \ - zxing/MultiFormatReader.h \ - zxing/Reader.h \ - zxing/ReaderException.h \ - zxing/Result.h \ - zxing/ResultPoint.h \ +HEADERS += QZXing_global.h \ + CameraImageWrapper.h \ + imagehandler.h \ + qzxing.h \ zxing/ResultPointCallback.h \ - zxing/FormatException.h \ + zxing/ResultPoint.h \ + zxing/Result.h \ + zxing/ReaderException.h \ + zxing/Reader.h \ zxing/NotFoundException.h \ + zxing/MultiFormatReader.h \ + zxing/LuminanceSource.h \ + zxing/FormatException.h \ + zxing/Exception.h \ + zxing/DecodeHints.h \ + zxing/BinaryBitmap.h \ + zxing/Binarizer.h \ + zxing/BarcodeFormat.h \ + zxing/aztec/AztecReader.h \ + zxing/aztec/AztecDetectorResult.h \ + zxing/aztec/decoder/Decoder.h \ + zxing/aztec/detector/Detector.h \ zxing/common/StringUtils.h \ - zxing/common/CharacterSetECI.h \ - zxing/common/ECI.h \ - zxing/common/Array.h \ - zxing/common/BitArray.h \ - zxing/common/BitMatrix.h \ - zxing/common/BitSource.h \ - zxing/common/Counted.h \ - zxing/common/DecoderResult.h \ - zxing/common/DetectorResult.h \ - zxing/common/EdgeDetector.h \ - zxing/common/GlobalHistogramBinarizer.h \ - zxing/common/GreyscaleLuminanceSource.h \ - zxing/common/GreyscaleRotatedLuminanceSource.h \ - zxing/common/GridSampler.h \ - zxing/common/HybridBinarizer.h \ - zxing/common/IllegalArgumentException.h \ - zxing/common/PerspectiveTransform.h \ - zxing/common/Point.h \ zxing/common/Str.h \ - zxing/common/reedsolomon/GF256.h \ - zxing/common/reedsolomon/GF256Poly.h \ - zxing/common/reedsolomon/ReedSolomonDecoder.h \ - zxing/common/reedsolomon/ReedSolomonException.h \ - zxing/common/detector/MonochromeRectangleDetector.h \ + zxing/common/Point.h \ + zxing/common/PerspectiveTransform.h \ + zxing/common/IllegalArgumentException.h \ + zxing/common/HybridBinarizer.h \ + zxing/common/GridSampler.h \ + zxing/common/GreyscaleRotatedLuminanceSource.h \ + zxing/common/GreyscaleLuminanceSource.h \ + zxing/common/GlobalHistogramBinarizer.h \ + zxing/common/EdgeDetector.h \ + zxing/common/DetectorResult.h \ + zxing/common/DecoderResult.h \ + zxing/common/Counted.h \ + zxing/common/CharacterSetECI.h \ + zxing/common/BitSource.h \ + zxing/common/BitMatrix.h \ + zxing/common/BitArray.h \ + zxing/common/Array.h \ zxing/common/detector/WhiteRectangleDetector.h \ - zxing/oned/Code128Reader.h \ - zxing/oned/Code39Reader.h \ + zxing/common/detector/MonochromeRectangleDetector.h \ + zxing/common/reedsolomon/ReedSolomonException.h \ + zxing/common/reedsolomon/ReedSolomonDecoder.h \ + zxing/common/reedsolomon/GenericGFPoly.h \ + zxing/common/reedsolomon/GenericGF.h \ + zxing/datamatrix/Version.h \ + zxing/datamatrix/DataMatrixReader.h \ + zxing/datamatrix/decoder/Decoder.h \ + zxing/datamatrix/decoder/DecodedBitStreamParser.h \ + zxing/datamatrix/decoder/DataBlock.h \ + zxing/datamatrix/decoder/BitMatrixParser.h \ + zxing/datamatrix/detector/MonochromeRectangleDetector.h \ + zxing/datamatrix/detector/DetectorException.h \ + zxing/datamatrix/detector/Detector.h \ + zxing/datamatrix/detector/CornerPoint.h \ + zxing/oned/UPCEReader.h \ + zxing/oned/UPCEANReader.h \ + zxing/oned/UPCAReader.h \ + zxing/oned/OneDResultPoint.h \ + zxing/oned/OneDReader.h \ + zxing/oned/MultiFormatUPCEANReader.h \ + zxing/oned/MultiFormatOneDReader.h \ + zxing/oned/ITFReader.h \ zxing/oned/EAN13Reader.h \ zxing/oned/EAN8Reader.h \ - zxing/oned/ITFReader.h \ - zxing/oned/MultiFormatOneDReader.h \ - zxing/oned/MultiFormatUPCEANReader.h \ - zxing/oned/OneDReader.h \ - zxing/oned/OneDResultPoint.h \ - zxing/oned/UPCAReader.h \ - zxing/oned/UPCEANReader.h \ - zxing/oned/UPCEReader.h \ - zxing/qrcode/ErrorCorrectionLevel.h \ - zxing/qrcode/FormatInformation.h \ - zxing/qrcode/QRCodeReader.h \ + zxing/oned/Code128Reader.h \ + zxing/oned/Code39Reader.h \ zxing/qrcode/Version.h \ - zxing/qrcode/decoder/BitMatrixParser.h \ - zxing/qrcode/decoder/DataBlock.h \ - zxing/qrcode/decoder/DataMask.h \ - zxing/qrcode/decoder/DecodedBitStreamParser.h \ - zxing/qrcode/decoder/Decoder.h \ + zxing/qrcode/QRCodeReader.h \ + zxing/qrcode/FormatInformation.h \ + zxing/qrcode/ErrorCorrectionLevel.h \ zxing/qrcode/decoder/Mode.h \ - zxing/qrcode/detector/AlignmentPattern.h \ - zxing/qrcode/detector/AlignmentPatternFinder.h \ - zxing/qrcode/detector/Detector.h \ - zxing/qrcode/detector/FinderPattern.h \ - zxing/qrcode/detector/FinderPatternFinder.h \ - zxing/qrcode/detector/FinderPatternInfo.h \ + zxing/qrcode/decoder/Decoder.h \ + zxing/qrcode/decoder/DecodedBitStreamParser.h \ + zxing/qrcode/decoder/DataMask.h \ + zxing/qrcode/decoder/DataBlock.h \ + zxing/qrcode/decoder/BitMatrixParser.h \ zxing/qrcode/detector/QREdgeDetector.h \ - zxing/datamatrix/VersionDM.h \ - zxing/datamatrix/DataMatrixReader.h \ - zxing/datamatrix/decoder/BitMatrixParserDM.h \ - zxing/datamatrix/decoder/DataBlockDM.h \ - zxing/datamatrix/decoder/DecodedBitStreamParserDM.h \ - zxing/datamatrix/decoder/DecoderDM.h \ - zxing/datamatrix/detector/CornerPoint.h \ - zxing/datamatrix/detector/DetectorDM.h \ - zxing/datamatrix/detector/DetectorException.h \ - zxing/datamatrix/detector/MonochromeRectangleDetectorDM.h \ - QZXing_global.h \ - CameraImageWrapper.h \ - qzxing.h + zxing/qrcode/detector/FinderPatternInfo.h \ + zxing/qrcode/detector/FinderPatternFinder.h \ + zxing/qrcode/detector/FinderPattern.h \ + zxing/qrcode/detector/Detector.h \ + zxing/qrcode/detector/AlignmentPatternFinder.h \ + zxing/qrcode/detector/AlignmentPattern.h \ + zxing/multi/MultipleBarcodeReader.h \ + zxing/multi/GenericMultipleBarcodeReader.h \ + zxing/multi/ByQuadrantReader.h \ + zxing/multi/qrcode/QRCodeMultiReader.h \ + zxing/multi/qrcode/detector/MultiFinderPatternFinder.h \ + zxing/multi/qrcode/detector/MultiDetector.h -SOURCES += zxing/BarcodeFormat.cpp \ - zxing/Binarizer.cpp \ - zxing/BinaryBitmap.cpp \ - zxing/DecodeHints.cpp \ - zxing/Exception.cpp \ - zxing/LuminanceSource.cpp \ - zxing/MultiFormatReader.cpp \ - zxing/Reader.cpp \ - zxing/ReaderException.cpp \ - zxing/Result.cpp \ - zxing/ResultPoint.cpp \ +SOURCES += CameraImageWrapper.cpp \ + qzxing.cpp \ + imagehandler.cpp \ zxing/ResultPointCallback.cpp \ - zxing/FormatException.cpp \ + zxing/ResultPoint.cpp \ + zxing/Result.cpp \ + zxing/ReaderException.cpp \ + zxing/Reader.cpp \ zxing/NotFoundException.cpp \ + zxing/MultiFormatReader.cpp \ + zxing/LuminanceSource.cpp \ + zxing/FormatException.cpp \ + zxing/Exception.cpp \ + zxing/DecodeHints.cpp \ + zxing/BinaryBitmap.cpp \ + zxing/Binarizer.cpp \ + zxing/BarcodeFormat.cpp \ + zxing/aztec/AztecReader.cpp \ + zxing/aztec/AztecDetectorResult.cpp \ zxing/common/StringUtils.cpp \ - zxing/common/CharacterSetECI.cpp \ - zxing/common/ECI.cpp \ - zxing/common/Array.cpp \ - zxing/common/BitArray.cpp \ - zxing/common/BitMatrix.cpp \ - zxing/common/BitSource.cpp \ - zxing/common/Counted.cpp \ - zxing/common/DecoderResult.cpp \ - zxing/common/DetectorResult.cpp \ - zxing/common/EdgeDetector.cpp \ - zxing/common/GlobalHistogramBinarizer.cpp \ - zxing/common/GreyscaleLuminanceSource.cpp \ - zxing/common/GreyscaleRotatedLuminanceSource.cpp \ - zxing/common/GridSampler.cpp \ - zxing/common/HybridBinarizer.cpp \ - zxing/common/IllegalArgumentException.cpp \ - zxing/common/PerspectiveTransform.cpp \ zxing/common/Str.cpp \ - zxing/common/reedsolomon/GF256.cpp \ - zxing/common/reedsolomon/GF256Poly.cpp \ - zxing/common/reedsolomon/ReedSolomonDecoder.cpp \ - zxing/common/reedsolomon/ReedSolomonException.cpp \ - zxing/common/detector/MonochromeRectangleDetector.cpp \ + zxing/common/PerspectiveTransform.cpp \ + zxing/common/IllegalArgumentException.cpp \ + zxing/common/HybridBinarizer.cpp \ + zxing/common/GridSampler.cpp \ + zxing/common/GreyscaleRotatedLuminanceSource.cpp \ + zxing/common/GreyscaleLuminanceSource.cpp \ + zxing/common/GlobalHistogramBinarizer.cpp \ + zxing/common/EdgeDetector.cpp \ + zxing/common/DetectorResult.cpp \ + zxing/common/DecoderResult.cpp \ + zxing/common/Counted.cpp \ + zxing/common/CharacterSetECI.cpp \ + zxing/common/BitSource.cpp \ + zxing/common/BitMatrix.cpp \ + zxing/common/BitArray.cpp \ + zxing/common/Array.cpp \ zxing/common/detector/WhiteRectangleDetector.cpp \ - zxing/oned/Code128Reader.cpp \ - zxing/oned/Code39Reader.cpp \ + zxing/common/detector/MonochromeRectangleDetector.cpp \ + zxing/common/reedsolomon/ReedSolomonException.cpp \ + zxing/common/reedsolomon/ReedSolomonDecoder.cpp \ + zxing/common/reedsolomon/GenericGFPoly.cpp \ + zxing/common/reedsolomon/GenericGF.cpp \ + zxing/datamatrix/DataMatrixReader.cpp \ + zxing/oned/UPCEReader.cpp \ + zxing/oned/UPCEANReader.cpp \ + zxing/oned/UPCAReader.cpp \ + zxing/oned/OneDResultPoint.cpp \ + zxing/oned/OneDReader.cpp \ + zxing/oned/MultiFormatUPCEANReader.cpp \ + zxing/oned/MultiFormatOneDReader.cpp \ + zxing/oned/ITFReader.cpp \ zxing/oned/EAN13Reader.cpp \ zxing/oned/EAN8Reader.cpp \ - zxing/oned/ITFReader.cpp \ - zxing/oned/MultiFormatOneDReader.cpp \ - zxing/oned/MultiFormatUPCEANReader.cpp \ - zxing/oned/OneDReader.cpp \ - zxing/oned/OneDResultPoint.cpp \ - zxing/oned/UPCAReader.cpp \ - zxing/oned/UPCEANReader.cpp \ - zxing/oned/UPCEReader.cpp \ - zxing/qrcode/ErrorCorrectionLevel.cpp \ - zxing/qrcode/FormatInformation.cpp \ + zxing/oned/Code128Reader.cpp \ + zxing/oned/Code39Reader.cpp \ zxing/qrcode/QRCodeReader.cpp \ - zxing/qrcode/Version.cpp \ - zxing/qrcode/decoder/BitMatrixParser.cpp \ - zxing/qrcode/decoder/DataBlock.cpp \ - zxing/qrcode/decoder/DataMask.cpp \ - zxing/qrcode/decoder/DecodedBitStreamParser.cpp \ - zxing/qrcode/decoder/Decoder.cpp \ - zxing/qrcode/decoder/Mode.cpp \ - zxing/qrcode/detector/AlignmentPattern.cpp \ - zxing/qrcode/detector/AlignmentPatternFinder.cpp \ - zxing/qrcode/detector/Detector.cpp \ - zxing/qrcode/detector/FinderPattern.cpp \ - zxing/qrcode/detector/FinderPatternFinder.cpp \ - zxing/qrcode/detector/FinderPatternInfo.cpp \ zxing/qrcode/detector/QREdgeDetector.cpp \ - zxing/datamatrix/VersionDM.cpp \ - zxing/datamatrix/DataMatrixReader.cpp \ - zxing/datamatrix/decoder/BitMatrixParserDM.cpp \ - zxing/datamatrix/decoder/DataBlockDM.cpp\ - zxing/datamatrix/decoder/DecodedBitStreamParserDM.cpp \ - zxing/datamatrix/decoder/DecoderDM.cpp \ - zxing/datamatrix/detector/CornerPoint.cpp \ - zxing/datamatrix/detector/DetectorDM.cpp \ - zxing/datamatrix/detector/DetectorException.cpp \ - zxing/datamatrix/detector/MonochromeRectangleDetectorDM.cpp \ - CameraImageWrapper.cpp \ - qzxing.cpp + zxing/multi/MultipleBarcodeReader.cpp \ + zxing/multi/GenericMultipleBarcodeReader.cpp \ + zxing/multi/ByQuadrantReader.cpp \ + zxing/multi/qrcode/QRCodeMultiReader.cpp \ + zxing/multi/qrcode/detector/MultiFinderPatternFinder.cpp \ + zxing/multi/qrcode/detector/MultiDetector.cpp \ + zxing/aztec/decoder/AztecDecoder.cpp \ + zxing/aztec/detector/AztecDetector.cpp \ + zxing/datamatrix/DataMatrixVersion.cpp \ + zxing/datamatrix/decoder/DataMatrixDecoder.cpp \ + zxing/datamatrix/decoder/DataMatrixBitMatrixParser.cpp \ + zxing/datamatrix/decoder/DataMatrixDataBlock.cpp \ + zxing/datamatrix/decoder/DataMatrixDecodedBitStreamParser.cpp \ + zxing/datamatrix/detector/DataMatrixCornerPoint.cpp \ + zxing/datamatrix/detector/DataMatrixDetector.cpp \ + zxing/datamatrix/detector/DataMatrixDetectorException.cpp \ + zxing/datamatrix/detector/DataMatrixMonochromeRectangleDetector.cpp \ + zxing/qrcode/decoder/QRBitMatrixParser.cpp \ + zxing/qrcode/decoder/QRDataBlock.cpp \ + zxing/qrcode/decoder/QRDataMask.cpp \ + zxing/qrcode/decoder/QRDecodedBitStreamParser.cpp \ + zxing/qrcode/decoder/QRDecoder.cpp \ + zxing/qrcode/decoder/QRMode.cpp \ + zxing/qrcode/detector/QRAlignmentPattern.cpp \ + zxing/qrcode/detector/QRAlignmentPatternFinder.cpp \ + zxing/qrcode/detector/QRDetector.cpp \ + zxing/qrcode/detector/QRFinderPattern.cpp \ + zxing/qrcode/detector/QRFinderPatternFinder.cpp \ + zxing/qrcode/detector/QRFinderPatternInfo.cpp \ + zxing/qrcode/QRVersion.cpp \ + zxing/qrcode/QRFormatInformation.cpp \ + zxing/qrcode/QRErrorCorrectionLevel.cpp symbian { TARGET.UID3 = 0xE618743C @@ -189,13 +211,13 @@ symbian { addFiles.sources = QZXing.dll addFiles.path = !:/sys/bin DEPLOYMENT += addFiles - #TARGET.CAPABILITY = All -TCB -AllFiles -DRM - TARGET.CAPABILITY += NetworkServices \ - ReadUserData \ - WriteUserData \ - LocalServices \ - UserEnvironment \ - Location + TARGET.CAPABILITY = All -TCB -AllFiles -DRM +# TARGET.CAPABILITY += NetworkServices \ +# ReadUserData \ +# WriteUserData \ +# LocalServices \ +# UserEnvironment \ +# Location } unix:!symbian { @@ -214,18 +236,18 @@ win32{ } OTHER_FILES += \ + qtc_packaging/debian_fremantle/rules \ + qtc_packaging/debian_fremantle/README \ + qtc_packaging/debian_fremantle/copyright \ + qtc_packaging/debian_fremantle/control \ + qtc_packaging/debian_fremantle/compat \ + qtc_packaging/debian_fremantle/changelog \ qtc_packaging/debian_harmattan/rules \ qtc_packaging/debian_harmattan/README \ qtc_packaging/debian_harmattan/manifest.aegis \ qtc_packaging/debian_harmattan/copyright \ qtc_packaging/debian_harmattan/control \ qtc_packaging/debian_harmattan/compat \ - qtc_packaging/debian_harmattan/changelog \ - qtc_packaging/debian_fremantle/rules \ - qtc_packaging/debian_fremantle/README \ - qtc_packaging/debian_fremantle/copyright \ - qtc_packaging/debian_fremantle/control \ - qtc_packaging/debian_fremantle/compat \ - qtc_packaging/debian_fremantle/changelog + qtc_packaging/debian_harmattan/changelog diff --git a/symbian/QZXing/source/QZXing_global.h b/symbian/QZXing/source/QZXing_global.h index 83ef95c57..d55ab0523 100644 --- a/symbian/QZXing/source/QZXing_global.h +++ b/symbian/QZXing/source/QZXing_global.h @@ -1,7 +1,8 @@ #ifndef QZXING_GLOBAL_H #define QZXING_GLOBAL_H -#include +#include +#include #if defined(QZXING_LIBRARY) # define QZXINGSHARED_EXPORT Q_DECL_EXPORT @@ -9,4 +10,4 @@ # define QZXINGSHARED_EXPORT Q_DECL_IMPORT #endif -#endif // QZXING_GLOBAL_H +#endif //QZXING_GLOBAL_H diff --git a/symbian/QZXing/source/QZXing_unsigned.sis b/symbian/QZXing/source/QZXing_unsigned.sis new file mode 100644 index 000000000..d5e4d4c16 Binary files /dev/null and b/symbian/QZXing/source/QZXing_unsigned.sis differ diff --git a/symbian/QZXing/source/eabi/QZXingu.def b/symbian/QZXing/source/eabi/QZXingu.def index fba212b28..4f86474ff 100644 --- a/symbian/QZXing/source/eabi/QZXingu.def +++ b/symbian/QZXing/source/eabi/QZXingu.def @@ -3,100 +3,116 @@ EXPORTS _ZN6QZXing11decodeImageE6QImage @ 2 NONAME _ZN6QZXing11qt_metacallEN11QMetaObject4CallEiPPv @ 3 NONAME _ZN6QZXing11qt_metacastEPKc @ 4 NONAME - _ZN6QZXing15decodingStartedEv @ 5 NONAME - _ZN6QZXing16decodingFinishedEb @ 6 NONAME - _ZN6QZXing16staticMetaObjectE @ 7 NONAME DATA 16 - _ZN6QZXing19getStaticMetaObjectEv @ 8 NONAME - _ZN6QZXing8tagFoundE7QString @ 9 NONAME - _ZN6QZXingC1EP7QObject @ 10 NONAME - _ZN6QZXingC2EP7QObject @ 11 NONAME - _ZNK6QZXing10metaObjectEv @ 12 NONAME - _ZTI18CameraImageWrapper @ 13 NONAME - _ZTI6QZXing @ 14 NONAME - _ZTIN5zxing10datamatrix16DataMatrixReaderE @ 15 NONAME - _ZTIN5zxing10datamatrix17DetectorExceptionE @ 16 NONAME - _ZTIN5zxing10datamatrix7VersionE @ 17 NONAME - _ZTIN5zxing10datamatrix8DetectorE @ 18 NONAME - _ZTIN5zxing11ResultPointE @ 19 NONAME - _ZTIN5zxing12BinaryBitmapE @ 20 NONAME - _ZTIN5zxing15FormatExceptionE @ 21 NONAME - _ZTIN5zxing15HybridBinarizerE @ 22 NONAME - _ZTIN5zxing15LuminanceSourceE @ 23 NONAME - _ZTIN5zxing15ReaderExceptionE @ 24 NONAME - _ZTIN5zxing17MultiFormatReaderE @ 25 NONAME - _ZTIN5zxing17NotFoundExceptionE @ 26 NONAME - _ZTIN5zxing19ResultPointCallbackE @ 27 NONAME - _ZTIN5zxing20ReedSolomonExceptionE @ 28 NONAME - _ZTIN5zxing24GlobalHistogramBinarizerE @ 29 NONAME - _ZTIN5zxing24GreyscaleLuminanceSourceE @ 30 NONAME - _ZTIN5zxing24IllegalArgumentExceptionE @ 31 NONAME - _ZTIN5zxing31GreyscaleRotatedLuminanceSourceE @ 32 NONAME - _ZTIN5zxing4oned10EAN8ReaderE @ 33 NONAME - _ZTIN5zxing4oned10OneDReaderE @ 34 NONAME - _ZTIN5zxing4oned10UPCAReaderE @ 35 NONAME - _ZTIN5zxing4oned10UPCEReaderE @ 36 NONAME - _ZTIN5zxing4oned11EAN13ReaderE @ 37 NONAME - _ZTIN5zxing4oned12Code39ReaderE @ 38 NONAME - _ZTIN5zxing4oned12UPCEANReaderE @ 39 NONAME - _ZTIN5zxing4oned13Code128ReaderE @ 40 NONAME - _ZTIN5zxing4oned21MultiFormatOneDReaderE @ 41 NONAME - _ZTIN5zxing4oned23MultiFormatUPCEANReaderE @ 42 NONAME - _ZTIN5zxing4oned9ITFReaderE @ 43 NONAME - _ZTIN5zxing6ReaderE @ 44 NONAME - _ZTIN5zxing6ResultE @ 45 NONAME - _ZTIN5zxing6qrcode12QRCodeReaderE @ 46 NONAME - _ZTIN5zxing6qrcode14QREdgeDetectorE @ 47 NONAME - _ZTIN5zxing6qrcode22AlignmentPatternFinderE @ 48 NONAME - _ZTIN5zxing6qrcode7VersionE @ 49 NONAME - _ZTIN5zxing6qrcode8DataMaskE @ 50 NONAME - _ZTIN5zxing6qrcode8DetectorE @ 51 NONAME - _ZTIN5zxing8BitArrayE @ 52 NONAME - _ZTIN5zxing9BinarizerE @ 53 NONAME - _ZTIN5zxing9BitMatrixE @ 54 NONAME - _ZTIN5zxing9ExceptionE @ 55 NONAME - _ZTIN5zxing9GF256PolyE @ 56 NONAME - _ZTV18CameraImageWrapper @ 57 NONAME - _ZTV6QZXing @ 58 NONAME - _ZTVN5zxing10datamatrix16DataMatrixReaderE @ 59 NONAME - _ZTVN5zxing10datamatrix17DetectorExceptionE @ 60 NONAME - _ZTVN5zxing10datamatrix7VersionE @ 61 NONAME - _ZTVN5zxing10datamatrix8DetectorE @ 62 NONAME - _ZTVN5zxing11ResultPointE @ 63 NONAME - _ZTVN5zxing12BinaryBitmapE @ 64 NONAME - _ZTVN5zxing15FormatExceptionE @ 65 NONAME - _ZTVN5zxing15HybridBinarizerE @ 66 NONAME - _ZTVN5zxing15LuminanceSourceE @ 67 NONAME - _ZTVN5zxing15ReaderExceptionE @ 68 NONAME - _ZTVN5zxing17MultiFormatReaderE @ 69 NONAME - _ZTVN5zxing17NotFoundExceptionE @ 70 NONAME - _ZTVN5zxing19ResultPointCallbackE @ 71 NONAME - _ZTVN5zxing20ReedSolomonExceptionE @ 72 NONAME - _ZTVN5zxing24GlobalHistogramBinarizerE @ 73 NONAME - _ZTVN5zxing24GreyscaleLuminanceSourceE @ 74 NONAME - _ZTVN5zxing24IllegalArgumentExceptionE @ 75 NONAME - _ZTVN5zxing31GreyscaleRotatedLuminanceSourceE @ 76 NONAME - _ZTVN5zxing4oned10EAN8ReaderE @ 77 NONAME - _ZTVN5zxing4oned10OneDReaderE @ 78 NONAME - _ZTVN5zxing4oned10UPCAReaderE @ 79 NONAME - _ZTVN5zxing4oned10UPCEReaderE @ 80 NONAME - _ZTVN5zxing4oned11EAN13ReaderE @ 81 NONAME - _ZTVN5zxing4oned12Code39ReaderE @ 82 NONAME - _ZTVN5zxing4oned12UPCEANReaderE @ 83 NONAME - _ZTVN5zxing4oned13Code128ReaderE @ 84 NONAME - _ZTVN5zxing4oned21MultiFormatOneDReaderE @ 85 NONAME - _ZTVN5zxing4oned23MultiFormatUPCEANReaderE @ 86 NONAME - _ZTVN5zxing4oned9ITFReaderE @ 87 NONAME - _ZTVN5zxing6ReaderE @ 88 NONAME - _ZTVN5zxing6ResultE @ 89 NONAME - _ZTVN5zxing6qrcode12QRCodeReaderE @ 90 NONAME - _ZTVN5zxing6qrcode14QREdgeDetectorE @ 91 NONAME - _ZTVN5zxing6qrcode22AlignmentPatternFinderE @ 92 NONAME - _ZTVN5zxing6qrcode7VersionE @ 93 NONAME - _ZTVN5zxing6qrcode8DataMaskE @ 94 NONAME - _ZTVN5zxing6qrcode8DetectorE @ 95 NONAME - _ZTVN5zxing8BitArrayE @ 96 NONAME - _ZTVN5zxing9BinarizerE @ 97 NONAME - _ZTVN5zxing9BitMatrixE @ 98 NONAME - _ZTVN5zxing9ExceptionE @ 99 NONAME - _ZTVN5zxing9GF256PolyE @ 100 NONAME + _ZN6QZXing14decodeImageQMLEP7QObject @ 5 NONAME + _ZN6QZXing15decodingStartedEv @ 6 NONAME + _ZN6QZXing16decodingFinishedEb @ 7 NONAME + _ZN6QZXing16staticMetaObjectE @ 8 NONAME DATA 16 + _ZN6QZXing17decodeSubImageQMLEP7QObjectdddd @ 9 NONAME + _ZN6QZXing19getStaticMetaObjectEv @ 10 NONAME + _ZN6QZXing8tagFoundE7QString @ 11 NONAME + _ZN6QZXingC1EP7QObject @ 12 NONAME + _ZN6QZXingC2EP7QObject @ 13 NONAME + _ZNK6QZXing10metaObjectEv @ 14 NONAME + _ZTI12ImageHandler @ 15 NONAME + _ZTI18CameraImageWrapper @ 16 NONAME + _ZTI6QZXing @ 17 NONAME + _ZTIN5zxing10datamatrix16DataMatrixReaderE @ 18 NONAME + _ZTIN5zxing10datamatrix17DetectorExceptionE @ 19 NONAME + _ZTIN5zxing10datamatrix7VersionE @ 20 NONAME + _ZTIN5zxing10datamatrix8DetectorE @ 21 NONAME + _ZTIN5zxing11ResultPointE @ 22 NONAME + _ZTIN5zxing12BinaryBitmapE @ 23 NONAME + _ZTIN5zxing15FormatExceptionE @ 24 NONAME + _ZTIN5zxing15HybridBinarizerE @ 25 NONAME + _ZTIN5zxing15LuminanceSourceE @ 26 NONAME + _ZTIN5zxing15ReaderExceptionE @ 27 NONAME + _ZTIN5zxing17MultiFormatReaderE @ 28 NONAME + _ZTIN5zxing17NotFoundExceptionE @ 29 NONAME + _ZTIN5zxing19ResultPointCallbackE @ 30 NONAME + _ZTIN5zxing20ReedSolomonExceptionE @ 31 NONAME + _ZTIN5zxing24GlobalHistogramBinarizerE @ 32 NONAME + _ZTIN5zxing24GreyscaleLuminanceSourceE @ 33 NONAME + _ZTIN5zxing24IllegalArgumentExceptionE @ 34 NONAME + _ZTIN5zxing31GreyscaleRotatedLuminanceSourceE @ 35 NONAME + _ZTIN5zxing4oned10EAN8ReaderE @ 36 NONAME + _ZTIN5zxing4oned10OneDReaderE @ 37 NONAME + _ZTIN5zxing4oned10UPCAReaderE @ 38 NONAME + _ZTIN5zxing4oned10UPCEReaderE @ 39 NONAME + _ZTIN5zxing4oned11EAN13ReaderE @ 40 NONAME + _ZTIN5zxing4oned12Code39ReaderE @ 41 NONAME + _ZTIN5zxing4oned12UPCEANReaderE @ 42 NONAME + _ZTIN5zxing4oned13Code128ReaderE @ 43 NONAME + _ZTIN5zxing4oned21MultiFormatOneDReaderE @ 44 NONAME + _ZTIN5zxing4oned23MultiFormatUPCEANReaderE @ 45 NONAME + _ZTIN5zxing4oned9ITFReaderE @ 46 NONAME + _ZTIN5zxing5aztec11AztecReaderE @ 47 NONAME + _ZTIN5zxing5multi13MultiDetectorE @ 48 NONAME + _ZTIN5zxing5multi16ByQuadrantReaderE @ 49 NONAME + _ZTIN5zxing5multi17QRCodeMultiReaderE @ 50 NONAME + _ZTIN5zxing5multi21MultipleBarcodeReaderE @ 51 NONAME + _ZTIN5zxing5multi24MultiFinderPatternFinderE @ 52 NONAME + _ZTIN5zxing5multi28GenericMultipleBarcodeReaderE @ 53 NONAME + _ZTIN5zxing6ReaderE @ 54 NONAME + _ZTIN5zxing6ResultE @ 55 NONAME + _ZTIN5zxing6qrcode12QRCodeReaderE @ 56 NONAME + _ZTIN5zxing6qrcode14QREdgeDetectorE @ 57 NONAME + _ZTIN5zxing6qrcode22AlignmentPatternFinderE @ 58 NONAME + _ZTIN5zxing6qrcode7VersionE @ 59 NONAME + _ZTIN5zxing6qrcode8DataMaskE @ 60 NONAME + _ZTIN5zxing6qrcode8DetectorE @ 61 NONAME + _ZTIN5zxing8BitArrayE @ 62 NONAME + _ZTIN5zxing9BinarizerE @ 63 NONAME + _ZTIN5zxing9BitMatrixE @ 64 NONAME + _ZTIN5zxing9ExceptionE @ 65 NONAME + _ZTV12ImageHandler @ 66 NONAME + _ZTV18CameraImageWrapper @ 67 NONAME + _ZTV6QZXing @ 68 NONAME + _ZTVN5zxing10datamatrix16DataMatrixReaderE @ 69 NONAME + _ZTVN5zxing10datamatrix17DetectorExceptionE @ 70 NONAME + _ZTVN5zxing10datamatrix7VersionE @ 71 NONAME + _ZTVN5zxing10datamatrix8DetectorE @ 72 NONAME + _ZTVN5zxing11ResultPointE @ 73 NONAME + _ZTVN5zxing12BinaryBitmapE @ 74 NONAME + _ZTVN5zxing15FormatExceptionE @ 75 NONAME + _ZTVN5zxing15HybridBinarizerE @ 76 NONAME + _ZTVN5zxing15LuminanceSourceE @ 77 NONAME + _ZTVN5zxing15ReaderExceptionE @ 78 NONAME + _ZTVN5zxing17MultiFormatReaderE @ 79 NONAME + _ZTVN5zxing17NotFoundExceptionE @ 80 NONAME + _ZTVN5zxing19ResultPointCallbackE @ 81 NONAME + _ZTVN5zxing20ReedSolomonExceptionE @ 82 NONAME + _ZTVN5zxing24GlobalHistogramBinarizerE @ 83 NONAME + _ZTVN5zxing24GreyscaleLuminanceSourceE @ 84 NONAME + _ZTVN5zxing24IllegalArgumentExceptionE @ 85 NONAME + _ZTVN5zxing31GreyscaleRotatedLuminanceSourceE @ 86 NONAME + _ZTVN5zxing4oned10EAN8ReaderE @ 87 NONAME + _ZTVN5zxing4oned10OneDReaderE @ 88 NONAME + _ZTVN5zxing4oned10UPCAReaderE @ 89 NONAME + _ZTVN5zxing4oned10UPCEReaderE @ 90 NONAME + _ZTVN5zxing4oned11EAN13ReaderE @ 91 NONAME + _ZTVN5zxing4oned12Code39ReaderE @ 92 NONAME + _ZTVN5zxing4oned12UPCEANReaderE @ 93 NONAME + _ZTVN5zxing4oned13Code128ReaderE @ 94 NONAME + _ZTVN5zxing4oned21MultiFormatOneDReaderE @ 95 NONAME + _ZTVN5zxing4oned23MultiFormatUPCEANReaderE @ 96 NONAME + _ZTVN5zxing4oned9ITFReaderE @ 97 NONAME + _ZTVN5zxing5aztec11AztecReaderE @ 98 NONAME + _ZTVN5zxing5multi13MultiDetectorE @ 99 NONAME + _ZTVN5zxing5multi16ByQuadrantReaderE @ 100 NONAME + _ZTVN5zxing5multi17QRCodeMultiReaderE @ 101 NONAME + _ZTVN5zxing5multi21MultipleBarcodeReaderE @ 102 NONAME + _ZTVN5zxing5multi24MultiFinderPatternFinderE @ 103 NONAME + _ZTVN5zxing5multi28GenericMultipleBarcodeReaderE @ 104 NONAME + _ZTVN5zxing6ReaderE @ 105 NONAME + _ZTVN5zxing6ResultE @ 106 NONAME + _ZTVN5zxing6qrcode12QRCodeReaderE @ 107 NONAME + _ZTVN5zxing6qrcode14QREdgeDetectorE @ 108 NONAME + _ZTVN5zxing6qrcode22AlignmentPatternFinderE @ 109 NONAME + _ZTVN5zxing6qrcode7VersionE @ 110 NONAME + _ZTVN5zxing6qrcode8DataMaskE @ 111 NONAME + _ZTVN5zxing6qrcode8DetectorE @ 112 NONAME + _ZTVN5zxing8BitArrayE @ 113 NONAME + _ZTVN5zxing9BinarizerE @ 114 NONAME + _ZTVN5zxing9BitMatrixE @ 115 NONAME + _ZTVN5zxing9ExceptionE @ 116 NONAME diff --git a/symbian/QZXing/source/imagehandler.cpp b/symbian/QZXing/source/imagehandler.cpp new file mode 100644 index 000000000..5aaa5c0a0 --- /dev/null +++ b/symbian/QZXing/source/imagehandler.cpp @@ -0,0 +1,44 @@ +#include "imagehandler.h" +#include +#include +#include +#include +#include + +ImageHandler::ImageHandler(QObject *parent) : + QObject(parent) +{ +} + +QImage ImageHandler::extractQImage(QObject *imageObj, + const double offsetX, const double offsetY, + const double width, const double height) +{ + QGraphicsObject *item = qobject_cast(imageObj); + + if (!item) { + qDebug() << "Item is NULL"; + return QImage(); + } + + QImage img(item->boundingRect().size().toSize(), QImage::Format_RGB32); + img.fill(QColor(255, 255, 255).rgb()); + QPainter painter(&img); + QStyleOptionGraphicsItem styleOption; + item->paint(&painter, &styleOption); + + if(offsetX == 0 && offsetY == 0 && width == 0 && height == 0) + return img; + else + { + return img.copy(offsetX, offsetY, width, height); + } +} + +void ImageHandler::save(QObject *imageObj, const QString &path, + const double offsetX, const double offsetY, + const double width, const double height) +{ + QImage img = extractQImage(imageObj, offsetX, offsetY, width, height); + img.save(path); +} diff --git a/symbian/QZXing/source/imagehandler.h b/symbian/QZXing/source/imagehandler.h new file mode 100644 index 000000000..fac548963 --- /dev/null +++ b/symbian/QZXing/source/imagehandler.h @@ -0,0 +1,23 @@ +#ifndef IMAGEHANDLER_H +#define IMAGEHANDLER_H + +#include +#include + +class ImageHandler : public QObject +{ + Q_OBJECT +public: + explicit ImageHandler(QObject *parent = 0); + + QImage extractQImage(QObject *imageObj, + const double offsetX = 0 , const double offsetY = 0, + const double width = 0, const double height = 0); + +public slots: + void save(QObject *item, const QString &path, + const double offsetX = 0, const double offsetY = 0, + const double width = 0, const double height = 0); +}; + +#endif // IMAGEHANDLER_H diff --git a/symbian/QZXing/source/qtc_packaging/debian_fremantle/README b/symbian/QZXing/source/qtc_packaging/debian_fremantle/README index 03880e590..c64208637 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_fremantle/README +++ b/symbian/QZXing/source/qtc_packaging/debian_fremantle/README @@ -1,6 +1,6 @@ -The Debian Package qzxing ----------------------------- - -Comments regarding the Package - - -- unknown <> Wed, 16 Nov 2011 18:02:57 +0200 +The Debian Package qzxing +---------------------------- + +Comments regarding the Package + + -- unknown <> Wed, 16 Nov 2011 18:02:57 +0200 diff --git a/symbian/QZXing/source/qtc_packaging/debian_fremantle/changelog b/symbian/QZXing/source/qtc_packaging/debian_fremantle/changelog index c604a40ca..c047e509e 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_fremantle/changelog +++ b/symbian/QZXing/source/qtc_packaging/debian_fremantle/changelog @@ -1,5 +1,5 @@ -qzxing (0.0.1) unstable; urgency=low - - * Initial Release. - - -- unknown <> Wed, 16 Nov 2011 18:02:57 +0200 +qzxing (0.0.1) unstable; urgency=low + + * Initial Release. + + -- unknown <> Wed, 16 Nov 2011 18:02:57 +0200 diff --git a/symbian/QZXing/source/qtc_packaging/debian_fremantle/compat b/symbian/QZXing/source/qtc_packaging/debian_fremantle/compat index 7f8f011eb..e30739cb5 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_fremantle/compat +++ b/symbian/QZXing/source/qtc_packaging/debian_fremantle/compat @@ -1 +1 @@ -7 +7 diff --git a/symbian/QZXing/source/qtc_packaging/debian_fremantle/control b/symbian/QZXing/source/qtc_packaging/debian_fremantle/control index 34586d781..db321b37d 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_fremantle/control +++ b/symbian/QZXing/source/qtc_packaging/debian_fremantle/control @@ -1,15 +1,15 @@ -Source: qzxing -Section: user/hidden -Priority: optional -Maintainer: unknown <> -Build-Depends: debhelper (>= 5), libqt4-dev -Standards-Version: 3.7.3 -Homepage: - -Package: qzxing -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: - -XB-Maemo-Display-Name: QZXing -XB-Maemo-Icon-26: +Source: qzxing +Section: user/hidden +Priority: optional +Maintainer: unknown <> +Build-Depends: debhelper (>= 5), libqt4-dev +Standards-Version: 3.7.3 +Homepage: + +Package: qzxing +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: + +XB-Maemo-Display-Name: QZXing +XB-Maemo-Icon-26: diff --git a/symbian/QZXing/source/qtc_packaging/debian_fremantle/copyright b/symbian/QZXing/source/qtc_packaging/debian_fremantle/copyright index e2c734660..07ab403ef 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_fremantle/copyright +++ b/symbian/QZXing/source/qtc_packaging/debian_fremantle/copyright @@ -1,40 +1,40 @@ -This package was debianized by unknown <> on -Wed, 16 Nov 2011 18:02:57 +0200. - -It was downloaded from - -Upstream Author(s): - - - - -Copyright: - - - - -License: - - This package is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This package is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this package; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -On Debian systems, the complete text of the GNU General -Public License can be found in `/usr/share/common-licenses/GPL'. - -The Debian packaging is (C) 2011, unknown <> and -is licensed under the GPL, see above. - - -# Please also look if there are files or directories which have a -# different copyright/license attached and list them here. +This package was debianized by unknown <> on +Wed, 16 Nov 2011 18:02:57 +0200. + +It was downloaded from + +Upstream Author(s): + + + + +Copyright: + + + + +License: + + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +On Debian systems, the complete text of the GNU General +Public License can be found in `/usr/share/common-licenses/GPL'. + +The Debian packaging is (C) 2011, unknown <> and +is licensed under the GPL, see above. + + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. diff --git a/symbian/QZXing/source/qtc_packaging/debian_fremantle/rules b/symbian/QZXing/source/qtc_packaging/debian_fremantle/rules index daba84b9a..84a80c236 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_fremantle/rules +++ b/symbian/QZXing/source/qtc_packaging/debian_fremantle/rules @@ -1,91 +1,91 @@ -#!/usr/bin/make -f -# -*- makefile -*- -# Sample debian/rules that uses debhelper. -# This file was originally written by Joey Hess and Craig Small. -# As a special exception, when this file is copied by dh-make into a -# dh-make output file, you may use that output file without restriction. -# This special exception was added by Craig Small in version 0.37 of dh-make. - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - - - - - -configure: configure-stamp -configure-stamp: - dh_testdir - # qmake PREFIX=/usr# Uncomment this line for use without Qt Creator - - touch configure-stamp - - -build: build-stamp - -build-stamp: configure-stamp - dh_testdir - - # Add here commands to compile the package. - # $(MAKE) # Uncomment this line for use without Qt Creator - #docbook-to-man debian/qzxing.sgml > qzxing.1 - - touch $@ - -clean: - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - - # Add here commands to clean up after the build process. - $(MAKE) clean - - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - # Add here commands to install the package into debian/qzxing. - $(MAKE) INSTALL_ROOT="$(CURDIR)"/debian/qzxing install - - -# Build architecture-independent files here. -binary-indep: build install -# We have nothing to do by default. - -# Build architecture-dependent files here. -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples -# dh_install -# dh_installmenu -# dh_installdebconf -# dh_installlogrotate -# dh_installemacsen -# dh_installpam -# dh_installmime -# dh_python -# dh_installinit -# dh_installcron -# dh_installinfo - dh_installman - dh_link - dh_strip - dh_compress - dh_fixperms -# dh_perl -# dh_makeshlibs - dh_installdeb - # dh_shlibdeps # Uncomment this line for use without Qt Creator - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install configure +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + + + + + +configure: configure-stamp +configure-stamp: + dh_testdir + # qmake PREFIX=/usr# Uncomment this line for use without Qt Creator + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + # $(MAKE) # Uncomment this line for use without Qt Creator + #docbook-to-man debian/qzxing.sgml > qzxing.1 + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + $(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/qzxing. + $(MAKE) INSTALL_ROOT="$(CURDIR)"/debian/qzxing install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip + dh_compress + dh_fixperms +# dh_perl +# dh_makeshlibs + dh_installdeb + # dh_shlibdeps # Uncomment this line for use without Qt Creator + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/symbian/QZXing/source/qtc_packaging/debian_harmattan/README b/symbian/QZXing/source/qtc_packaging/debian_harmattan/README index 014123700..c4bf5e0f9 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_harmattan/README +++ b/symbian/QZXing/source/qtc_packaging/debian_harmattan/README @@ -1,6 +1,6 @@ -The Debian Package qzxing ----------------------------- - -Comments regarding the Package - - -- unknown <> Wed, 16 Nov 2011 18:02:42 +0200 +The Debian Package qzxing +---------------------------- + +Comments regarding the Package + + -- unknown <> Mon, 14 May 2012 15:23:23 +0300 diff --git a/symbian/QZXing/source/qtc_packaging/debian_harmattan/changelog b/symbian/QZXing/source/qtc_packaging/debian_harmattan/changelog index d8b7e263c..ab896f52f 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_harmattan/changelog +++ b/symbian/QZXing/source/qtc_packaging/debian_harmattan/changelog @@ -1,5 +1,5 @@ -qzxing (0.0.1) unstable; urgency=low - - * Initial Release. - - -- unknown <> Wed, 16 Nov 2011 18:02:42 +0200 +qzxing (0.0.1) unstable; urgency=low + + * Initial Release. + + -- unknown <> Mon, 14 May 2012 15:23:23 +0300 diff --git a/symbian/QZXing/source/qtc_packaging/debian_harmattan/compat b/symbian/QZXing/source/qtc_packaging/debian_harmattan/compat index 7f8f011eb..e30739cb5 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_harmattan/compat +++ b/symbian/QZXing/source/qtc_packaging/debian_harmattan/compat @@ -1 +1 @@ -7 +7 diff --git a/symbian/QZXing/source/qtc_packaging/debian_harmattan/control b/symbian/QZXing/source/qtc_packaging/debian_harmattan/control index f64aa463b..479ccd011 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_harmattan/control +++ b/symbian/QZXing/source/qtc_packaging/debian_harmattan/control @@ -1,15 +1,14 @@ -Source: qzxing -Section: user/other -Priority: optional -Maintainer: unknown <> -Build-Depends: debhelper (>= 5), libqt4-dev -Standards-Version: 3.7.3 -Homepage: - -Package: qzxing -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: - -XSBC-Maemo-Display-Name: QZXing -XB-Maemo-Icon-26: +Source: qzxing +Section: user/other +Priority: optional +Maintainer: unknown <> +Build-Depends: debhelper (>= 5), libqt4-dev +Standards-Version: 3.7.3 +Homepage: + +Package: qzxing +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: + +XSBC-Maemo-Display-Name: QZXing diff --git a/symbian/QZXing/source/qtc_packaging/debian_harmattan/copyright b/symbian/QZXing/source/qtc_packaging/debian_harmattan/copyright index f185c78a2..96c2347d2 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_harmattan/copyright +++ b/symbian/QZXing/source/qtc_packaging/debian_harmattan/copyright @@ -1,40 +1,40 @@ -This package was debianized by unknown <> on -Wed, 16 Nov 2011 18:02:42 +0200. - -It was downloaded from - -Upstream Author(s): - - - - -Copyright: - - - - -License: - - This package is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This package is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this package; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -On Debian systems, the complete text of the GNU General -Public License can be found in `/usr/share/common-licenses/GPL'. - -The Debian packaging is (C) 2011, unknown <> and -is licensed under the GPL, see above. - - -# Please also look if there are files or directories which have a -# different copyright/license attached and list them here. +This package was debianized by unknown <> on +Mon, 14 May 2012 15:23:23 +0300. + +It was downloaded from + +Upstream Author(s): + + + + +Copyright: + + + + +License: + + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this package; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +On Debian systems, the complete text of the GNU General +Public License can be found in `/usr/share/common-licenses/GPL'. + +The Debian packaging is (C) 2012, unknown <> and +is licensed under the GPL, see above. + + +# Please also look if there are files or directories which have a +# different copyright/license attached and list them here. diff --git a/symbian/QZXing/source/qtc_packaging/debian_harmattan/manifest.aegis b/symbian/QZXing/source/qtc_packaging/debian_harmattan/manifest.aegis index e69de29bb..a26d3c93e 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_harmattan/manifest.aegis +++ b/symbian/QZXing/source/qtc_packaging/debian_harmattan/manifest.aegis @@ -0,0 +1,70 @@ +AutoGenerateAegisFile + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/symbian/QZXing/source/qtc_packaging/debian_harmattan/rules b/symbian/QZXing/source/qtc_packaging/debian_harmattan/rules index daba84b9a..84a80c236 100644 --- a/symbian/QZXing/source/qtc_packaging/debian_harmattan/rules +++ b/symbian/QZXing/source/qtc_packaging/debian_harmattan/rules @@ -1,91 +1,91 @@ -#!/usr/bin/make -f -# -*- makefile -*- -# Sample debian/rules that uses debhelper. -# This file was originally written by Joey Hess and Craig Small. -# As a special exception, when this file is copied by dh-make into a -# dh-make output file, you may use that output file without restriction. -# This special exception was added by Craig Small in version 0.37 of dh-make. - -# Uncomment this to turn on verbose mode. -#export DH_VERBOSE=1 - - - - - -configure: configure-stamp -configure-stamp: - dh_testdir - # qmake PREFIX=/usr# Uncomment this line for use without Qt Creator - - touch configure-stamp - - -build: build-stamp - -build-stamp: configure-stamp - dh_testdir - - # Add here commands to compile the package. - # $(MAKE) # Uncomment this line for use without Qt Creator - #docbook-to-man debian/qzxing.sgml > qzxing.1 - - touch $@ - -clean: - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - - # Add here commands to clean up after the build process. - $(MAKE) clean - - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - # Add here commands to install the package into debian/qzxing. - $(MAKE) INSTALL_ROOT="$(CURDIR)"/debian/qzxing install - - -# Build architecture-independent files here. -binary-indep: build install -# We have nothing to do by default. - -# Build architecture-dependent files here. -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples -# dh_install -# dh_installmenu -# dh_installdebconf -# dh_installlogrotate -# dh_installemacsen -# dh_installpam -# dh_installmime -# dh_python -# dh_installinit -# dh_installcron -# dh_installinfo - dh_installman - dh_link - dh_strip - dh_compress - dh_fixperms -# dh_perl -# dh_makeshlibs - dh_installdeb - # dh_shlibdeps # Uncomment this line for use without Qt Creator - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install configure +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + + + + + +configure: configure-stamp +configure-stamp: + dh_testdir + # qmake PREFIX=/usr# Uncomment this line for use without Qt Creator + + touch configure-stamp + + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + # $(MAKE) # Uncomment this line for use without Qt Creator + #docbook-to-man debian/qzxing.sgml > qzxing.1 + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + + # Add here commands to clean up after the build process. + $(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/qzxing. + $(MAKE) INSTALL_ROOT="$(CURDIR)"/debian/qzxing install + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installchangelogs + dh_installdocs + dh_installexamples +# dh_install +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo + dh_installman + dh_link + dh_strip + dh_compress + dh_fixperms +# dh_perl +# dh_makeshlibs + dh_installdeb + # dh_shlibdeps # Uncomment this line for use without Qt Creator + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure diff --git a/symbian/QZXing/source/qzxing.cpp b/symbian/QZXing/source/qzxing.cpp index 51b549321..deb169321 100644 --- a/symbian/QZXing/source/qzxing.cpp +++ b/symbian/QZXing/source/qzxing.cpp @@ -6,6 +6,7 @@ #include #include #include "CameraImageWrapper.h" +#include "imagehandler.h" using namespace zxing; @@ -20,7 +21,9 @@ QZXing::QZXing(QObject *parent) : QObject(parent) DecoderFormat_EAN_13 | DecoderFormat_CODE_128 | DecoderFormat_CODE_39 | - DecoderFormat_ITF); + DecoderFormat_ITF | + DecoderFormat_Aztec); + imageHandler = new ImageHandler(); } void QZXing::setDecoder(DecoderFormatType hint) @@ -54,6 +57,9 @@ void QZXing::setDecoder(DecoderFormatType hint) if(hint & DecoderFormat_ITF) newHints.addFormat((BarcodeFormat)BarcodeFormat_ITF); + if(hint & DecoderFormat_Aztec) + newHints.addFormat((BarcodeFormat)BarcodeFormat_AZTEC); + supportedFormats = newHints.getCurrentHint(); } @@ -84,3 +90,25 @@ QString QZXing::decodeImage(QImage image) return ""; } } + +QString QZXing::decodeImageQML(QObject *item) +{ + return decodeSubImageQML(item); +} + +QString QZXing::decodeSubImageQML(QObject* item, + const double offsetX, const double offsetY, + const double width, const double height) +{ + if(item == NULL) + { + emit decodingFinished(false); + return ""; + } + + QImage img = ((ImageHandler*)imageHandler)->extractQImage(item, offsetX, offsetY, width, height); + + return decodeImage(img); +} + + diff --git a/symbian/QZXing/source/qzxing.h b/symbian/QZXing/source/qzxing.h index 3fd3e692a..33e1240dd 100644 --- a/symbian/QZXing/source/qzxing.h +++ b/symbian/QZXing/source/qzxing.h @@ -32,7 +32,8 @@ public: DecoderFormat_EAN_13 = 32, DecoderFormat_CODE_128 = 64, DecoderFormat_CODE_39 = 128, - DecoderFormat_ITF = 256 + DecoderFormat_ITF = 256, + DecoderFormat_Aztec = 512 } ; typedef unsigned int DecoderFormatType; @@ -49,7 +50,7 @@ public: #if QT_VERSION >= 0x040700 static void registerQMLTypes() { - qmlRegisterType("QZXing", 1, 0, "QZXing"); + qmlRegisterType("QZXing", 1, 2, "QZXing"); } #endif @@ -60,6 +61,19 @@ public slots: */ QString decodeImage(QImage image); + /** + * The decoding function accessible from QML + */ + QString decodeImageQML(QObject *item); + + /** + * The decoding function accessible from QML. Able to set the decoding + * of a portion of the image. + */ + QString decodeSubImageQML(QObject* item, + const double offsetX = 0 , const double offsetY = 0, + const double width = 0, const double height = 0); + signals: void decodingStarted(); void decodingFinished(bool succeeded); @@ -68,6 +82,7 @@ signals: private: void* decoder; DecoderFormatType supportedFormats; + QObject* imageHandler; }; #endif // QZXING_H diff --git a/symbian/QZXing/source/zxing/BarcodeFormat.cpp b/symbian/QZXing/source/zxing/BarcodeFormat.cpp index 7badb2abf..552ed768b 100644 --- a/symbian/QZXing/source/zxing/BarcodeFormat.cpp +++ b/symbian/QZXing/source/zxing/BarcodeFormat.cpp @@ -1,38 +1,37 @@ -/* - * BarcodeFormat.cpp - * zxing - * - * Created by Christian Brunschen on 13/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -const char *barcodeFormatNames[] = { - "None", - "QR_CODE", - "DATA_MATRIX", - "UPC_E", - "UPC_A", - "EAN_8", - "EAN_13", - "CODE_128", - "CODE_39", - "ITF" -}; - -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Created by Christian Brunschen on 13/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +const char *barcodeFormatNames[] = { + "None", + "QR_CODE", + "DATA_MATRIX", + "UPC_E", + "UPC_A", + "EAN_8", + "EAN_13", + "CODE_128", + "CODE_39", + "ITF", + "AZTEC" +}; + +} diff --git a/symbian/QZXing/source/zxing/BarcodeFormat.h b/symbian/QZXing/source/zxing/BarcodeFormat.h index 78e6f8c8e..bbc21a971 100644 --- a/symbian/QZXing/source/zxing/BarcodeFormat.h +++ b/symbian/QZXing/source/zxing/BarcodeFormat.h @@ -1,42 +1,44 @@ -#ifndef __BARCODE_FORMAT_H__ -#define __BARCODE_FORMAT_H__ - -/* - * BarcodeFormat.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace zxing { - - typedef enum BarcodeFormat { - BarcodeFormat_None = 0, - BarcodeFormat_QR_CODE, - BarcodeFormat_DATA_MATRIX, - BarcodeFormat_UPC_E, - BarcodeFormat_UPC_A, - BarcodeFormat_EAN_8, - BarcodeFormat_EAN_13, - BarcodeFormat_CODE_128, - BarcodeFormat_CODE_39, - BarcodeFormat_ITF - } BarcodeFormat; - - /* if you update the enum, please update the name in BarcodeFormat.cpp */ - extern const char *barcodeFormatNames[]; -} - -#endif // __BARCODE_FORMAT_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __BARCODE_FORMAT_H__ +#define __BARCODE_FORMAT_H__ + +/* + * BarcodeFormat.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace zxing { + + typedef enum BarcodeFormat { + BarcodeFormat_None = 0, + BarcodeFormat_QR_CODE, + BarcodeFormat_DATA_MATRIX, + BarcodeFormat_UPC_E, + BarcodeFormat_UPC_A, + BarcodeFormat_EAN_8, + BarcodeFormat_EAN_13, + BarcodeFormat_CODE_128, + BarcodeFormat_CODE_39, + BarcodeFormat_ITF, + BarcodeFormat_AZTEC + } BarcodeFormat; + + /* if you update the enum, please update the name in BarcodeFormat.cpp */ + extern const char *barcodeFormatNames[]; +} + +#endif // __BARCODE_FORMAT_H__ diff --git a/symbian/QZXing/source/zxing/Binarizer.cpp b/symbian/QZXing/source/zxing/Binarizer.cpp index 86d891558..ff6cbab97 100644 --- a/symbian/QZXing/source/zxing/Binarizer.cpp +++ b/symbian/QZXing/source/zxing/Binarizer.cpp @@ -1,37 +1,37 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Binarizer.cpp - * zxing - * - * Created by Ralf Kistner on 16/10/2009. - * Copyright 2008 ZXing authors All rights reserved. - * Modified by Lukasz Warchol on 02/02/2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - - Binarizer::Binarizer(Ref source) : source_(source) { - } - - Binarizer::~Binarizer() { - } - - Ref Binarizer::getLuminanceSource() const { - return source_; - } - -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Binarizer.cpp + * zxing + * + * Created by Ralf Kistner on 16/10/2009. + * Copyright 2008 ZXing authors All rights reserved. + * Modified by Lukasz Warchol on 02/02/2010. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + + Binarizer::Binarizer(Ref source) : source_(source) { + } + + Binarizer::~Binarizer() { + } + + Ref Binarizer::getLuminanceSource() const { + return source_; + } + +} diff --git a/symbian/QZXing/source/zxing/Binarizer.h b/symbian/QZXing/source/zxing/Binarizer.h index 8ae258d7f..e7292b057 100644 --- a/symbian/QZXing/source/zxing/Binarizer.h +++ b/symbian/QZXing/source/zxing/Binarizer.h @@ -1,46 +1,46 @@ -#ifndef BINARIZER_H_ -#define BINARIZER_H_ - -/* - * Binarizer.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { - -class Binarizer : public Counted { - private: - Ref source_; - - public: - Binarizer(Ref source); - virtual ~Binarizer(); - - virtual Ref getBlackRow(int y, Ref row) = 0; - virtual Ref getBlackMatrix() = 0; - - Ref getLuminanceSource() const ; - virtual Ref createBinarizer(Ref source) = 0; -}; - -} -#endif /* BINARIZER_H_ */ +#ifndef BINARIZER_H_ +#define BINARIZER_H_ + +/* + * Binarizer.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { + +class Binarizer : public Counted { + private: + Ref source_; + + public: + Binarizer(Ref source); + virtual ~Binarizer(); + + virtual Ref getBlackRow(int y, Ref row) = 0; + virtual Ref getBlackMatrix() = 0; + + Ref getLuminanceSource() const ; + virtual Ref createBinarizer(Ref source) = 0; +}; + +} +#endif /* BINARIZER_H_ */ diff --git a/symbian/QZXing/source/zxing/BinaryBitmap.cpp b/symbian/QZXing/source/zxing/BinaryBitmap.cpp index a1c68dbf4..853893123 100644 --- a/symbian/QZXing/source/zxing/BinaryBitmap.cpp +++ b/symbian/QZXing/source/zxing/BinaryBitmap.cpp @@ -1,67 +1,67 @@ -/* - * BinaryBitmap.cpp - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - - BinaryBitmap::BinaryBitmap(Ref binarizer) : binarizer_(binarizer) { - - } - - BinaryBitmap::~BinaryBitmap() { - } - - Ref BinaryBitmap::getBlackRow(int y, Ref row) { - return binarizer_->getBlackRow(y, row); - } - - Ref BinaryBitmap::getBlackMatrix() { - return binarizer_->getBlackMatrix(); - } - - int BinaryBitmap::getWidth() const { - return getLuminanceSource()->getWidth(); - } - - int BinaryBitmap::getHeight() const { - return getLuminanceSource()->getHeight(); - } - - Ref BinaryBitmap::getLuminanceSource() const { - return binarizer_->getLuminanceSource(); - } - - - bool BinaryBitmap::isCropSupported() const { - return getLuminanceSource()->isCropSupported(); - } - - Ref BinaryBitmap::crop(int left, int top, int width, int height) { - return Ref (new BinaryBitmap(binarizer_->createBinarizer(getLuminanceSource()->crop(left, top, width, height)))); - } - - bool BinaryBitmap::isRotateSupported() const { - return getLuminanceSource()->isRotateSupported(); - } - - Ref BinaryBitmap::rotateCounterClockwise() { - return Ref (new BinaryBitmap(binarizer_->createBinarizer(getLuminanceSource()->rotateCounterClockwise()))); - } -} +/* + * BinaryBitmap.cpp + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + + BinaryBitmap::BinaryBitmap(Ref binarizer) : binarizer_(binarizer) { + + } + + BinaryBitmap::~BinaryBitmap() { + } + + Ref BinaryBitmap::getBlackRow(int y, Ref row) { + return binarizer_->getBlackRow(y, row); + } + + Ref BinaryBitmap::getBlackMatrix() { + return binarizer_->getBlackMatrix(); + } + + int BinaryBitmap::getWidth() const { + return getLuminanceSource()->getWidth(); + } + + int BinaryBitmap::getHeight() const { + return getLuminanceSource()->getHeight(); + } + + Ref BinaryBitmap::getLuminanceSource() const { + return binarizer_->getLuminanceSource(); + } + + + bool BinaryBitmap::isCropSupported() const { + return getLuminanceSource()->isCropSupported(); + } + + Ref BinaryBitmap::crop(int left, int top, int width, int height) { + return Ref (new BinaryBitmap(binarizer_->createBinarizer(getLuminanceSource()->crop(left, top, width, height)))); + } + + bool BinaryBitmap::isRotateSupported() const { + return getLuminanceSource()->isRotateSupported(); + } + + Ref BinaryBitmap::rotateCounterClockwise() { + return Ref (new BinaryBitmap(binarizer_->createBinarizer(getLuminanceSource()->rotateCounterClockwise()))); + } +} diff --git a/symbian/QZXing/source/zxing/BinaryBitmap.h b/symbian/QZXing/source/zxing/BinaryBitmap.h index 23f6dd21e..391eb2e5d 100644 --- a/symbian/QZXing/source/zxing/BinaryBitmap.h +++ b/symbian/QZXing/source/zxing/BinaryBitmap.h @@ -1,57 +1,57 @@ -#ifndef __BINARYBITMAP_H__ -#define __BINARYBITMAP_H__ - -/* - * BinaryBitmap.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { - - class BinaryBitmap : public Counted { - private: - Ref binarizer_; - int cached_y_; - - public: - BinaryBitmap(Ref binarizer); - virtual ~BinaryBitmap(); - - Ref getBlackRow(int y, Ref row); - Ref getBlackMatrix(); - - Ref getLuminanceSource() const; - - int getWidth() const; - int getHeight() const; - - bool isRotateSupported() const; - Ref rotateCounterClockwise(); - - bool isCropSupported() const; - Ref crop(int left, int top, int width, int height); - - }; - -} - -#endif /* BINARYBITMAP_H_ */ +#ifndef __BINARYBITMAP_H__ +#define __BINARYBITMAP_H__ + +/* + * BinaryBitmap.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { + + class BinaryBitmap : public Counted { + private: + Ref binarizer_; + int cached_y_; + + public: + BinaryBitmap(Ref binarizer); + virtual ~BinaryBitmap(); + + Ref getBlackRow(int y, Ref row); + Ref getBlackMatrix(); + + Ref getLuminanceSource() const; + + int getWidth() const; + int getHeight() const; + + bool isRotateSupported() const; + Ref rotateCounterClockwise(); + + bool isCropSupported() const; + Ref crop(int left, int top, int width, int height); + + }; + +} + +#endif /* BINARYBITMAP_H_ */ diff --git a/symbian/QZXing/source/zxing/DecodeHints.cpp b/symbian/QZXing/source/zxing/DecodeHints.cpp index a8ea4ece6..0842c302e 100644 --- a/symbian/QZXing/source/zxing/DecodeHints.cpp +++ b/symbian/QZXing/source/zxing/DecodeHints.cpp @@ -1,117 +1,120 @@ -/* - * DecodeHintType.cpp - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -namespace zxing { - -const DecodeHintType DecodeHints::CHARACTER_SET; - -const DecodeHints DecodeHints::PRODUCT_HINT( - BARCODEFORMAT_UPC_E_HINT | - BARCODEFORMAT_UPC_A_HINT | - BARCODEFORMAT_EAN_8_HINT | - BARCODEFORMAT_EAN_13_HINT); - -const DecodeHints DecodeHints::ONED_HINT( - BARCODEFORMAT_UPC_E_HINT | - BARCODEFORMAT_UPC_A_HINT | - BARCODEFORMAT_EAN_8_HINT | - BARCODEFORMAT_EAN_13_HINT | - BARCODEFORMAT_CODE_128_HINT | - BARCODEFORMAT_CODE_39_HINT | - BARCODEFORMAT_ITF_HINT); - -const DecodeHints DecodeHints::DEFAULT_HINT( - BARCODEFORMAT_UPC_E_HINT | - BARCODEFORMAT_UPC_A_HINT | - BARCODEFORMAT_EAN_8_HINT | - BARCODEFORMAT_EAN_13_HINT | - BARCODEFORMAT_CODE_128_HINT | - BARCODEFORMAT_CODE_39_HINT | - BARCODEFORMAT_ITF_HINT | - BARCODEFORMAT_DATA_MATRIX_HINT | - BARCODEFORMAT_QR_CODE_HINT); - -DecodeHints::DecodeHints() { - hints = 0; -} - -DecodeHints::DecodeHints(DecodeHintType init) { - hints = init; -} - -void DecodeHints::addFormat(BarcodeFormat toadd) { - switch (toadd) { - case BarcodeFormat_QR_CODE: hints |= BARCODEFORMAT_QR_CODE_HINT; break; - case BarcodeFormat_DATA_MATRIX: hints |= BARCODEFORMAT_DATA_MATRIX_HINT; break; - case BarcodeFormat_UPC_E: hints |= BARCODEFORMAT_UPC_E_HINT; break; - case BarcodeFormat_UPC_A: hints |= BARCODEFORMAT_UPC_A_HINT; break; - case BarcodeFormat_EAN_8: hints |= BARCODEFORMAT_EAN_8_HINT; break; - case BarcodeFormat_EAN_13: hints |= BARCODEFORMAT_EAN_13_HINT; break; - case BarcodeFormat_CODE_128: hints |= BARCODEFORMAT_CODE_128_HINT; break; - case BarcodeFormat_CODE_39: hints |= BARCODEFORMAT_CODE_39_HINT; break; - case BarcodeFormat_ITF: hints |= BARCODEFORMAT_ITF_HINT; break; - default: throw IllegalArgumentException("Unrecognizd barcode format"); - } -} - -bool DecodeHints::containsFormat(BarcodeFormat tocheck) const { - DecodeHintType checkAgainst; - switch (tocheck) { - case BarcodeFormat_QR_CODE: checkAgainst = BARCODEFORMAT_QR_CODE_HINT; break; - case BarcodeFormat_DATA_MATRIX: checkAgainst = BARCODEFORMAT_DATA_MATRIX_HINT; break; - case BarcodeFormat_UPC_E: checkAgainst = BARCODEFORMAT_UPC_E_HINT; break; - case BarcodeFormat_UPC_A: checkAgainst = BARCODEFORMAT_UPC_A_HINT; break; - case BarcodeFormat_EAN_8: checkAgainst = BARCODEFORMAT_EAN_8_HINT; break; - case BarcodeFormat_EAN_13: checkAgainst = BARCODEFORMAT_EAN_13_HINT; break; - case BarcodeFormat_CODE_128: checkAgainst = BARCODEFORMAT_CODE_128_HINT; break; - case BarcodeFormat_CODE_39: checkAgainst = BARCODEFORMAT_CODE_39_HINT; break; - case BarcodeFormat_ITF: checkAgainst = BARCODEFORMAT_ITF_HINT; break; - default: throw IllegalArgumentException("Unrecognizd barcode format"); - } - return (hints & checkAgainst); -} - -void DecodeHints::setTryHarder(bool toset) { - if (toset) { - hints |= TRYHARDER_HINT; - } else { - hints &= ~TRYHARDER_HINT; - } -} - -bool DecodeHints::getTryHarder() const { - return (hints & TRYHARDER_HINT); -} - -void DecodeHints::setResultPointCallback(Ref const& _callback) { - callback = _callback; -} - -Ref DecodeHints::getResultPointCallback() const { - return callback; -} - -DecodeHintType DecodeHints::getCurrentHint() -{ - return hints; -} - -} /* namespace */ +/* + * DecodeHintType.cpp + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +namespace zxing { + +const DecodeHintType DecodeHints::CHARACTER_SET; + +const DecodeHints DecodeHints::PRODUCT_HINT( + BARCODEFORMAT_UPC_E_HINT | + BARCODEFORMAT_UPC_A_HINT | + BARCODEFORMAT_EAN_8_HINT | + BARCODEFORMAT_EAN_13_HINT); + +const DecodeHints DecodeHints::ONED_HINT( + BARCODEFORMAT_UPC_E_HINT | + BARCODEFORMAT_UPC_A_HINT | + BARCODEFORMAT_EAN_8_HINT | + BARCODEFORMAT_EAN_13_HINT | + BARCODEFORMAT_CODE_128_HINT | + BARCODEFORMAT_CODE_39_HINT | + BARCODEFORMAT_ITF_HINT); + +const DecodeHints DecodeHints::DEFAULT_HINT( + BARCODEFORMAT_UPC_E_HINT | + BARCODEFORMAT_UPC_A_HINT | + BARCODEFORMAT_EAN_8_HINT | + BARCODEFORMAT_EAN_13_HINT | + BARCODEFORMAT_CODE_128_HINT | + BARCODEFORMAT_CODE_39_HINT | + BARCODEFORMAT_ITF_HINT | + BARCODEFORMAT_DATA_MATRIX_HINT | + BARCODEFORMAT_AZTEC_HINT | + BARCODEFORMAT_QR_CODE_HINT); + +DecodeHints::DecodeHints() { + hints = 0; +} + +DecodeHints::DecodeHints(DecodeHintType init) { + hints = init; +} + +void DecodeHints::addFormat(BarcodeFormat toadd) { + switch (toadd) { + case BarcodeFormat_AZTEC: hints |= BARCODEFORMAT_AZTEC_HINT; break; + case BarcodeFormat_QR_CODE: hints |= BARCODEFORMAT_QR_CODE_HINT; break; + case BarcodeFormat_DATA_MATRIX: hints |= BARCODEFORMAT_DATA_MATRIX_HINT; break; + case BarcodeFormat_UPC_E: hints |= BARCODEFORMAT_UPC_E_HINT; break; + case BarcodeFormat_UPC_A: hints |= BARCODEFORMAT_UPC_A_HINT; break; + case BarcodeFormat_EAN_8: hints |= BARCODEFORMAT_EAN_8_HINT; break; + case BarcodeFormat_EAN_13: hints |= BARCODEFORMAT_EAN_13_HINT; break; + case BarcodeFormat_CODE_128: hints |= BARCODEFORMAT_CODE_128_HINT; break; + case BarcodeFormat_CODE_39: hints |= BARCODEFORMAT_CODE_39_HINT; break; + case BarcodeFormat_ITF: hints |= BARCODEFORMAT_ITF_HINT; break; + default: throw IllegalArgumentException("Unrecognizd barcode format"); + } +} + +bool DecodeHints::containsFormat(BarcodeFormat tocheck) const { + DecodeHintType checkAgainst; + switch (tocheck) { + case BarcodeFormat_AZTEC: checkAgainst = BARCODEFORMAT_AZTEC_HINT; break; + case BarcodeFormat_QR_CODE: checkAgainst = BARCODEFORMAT_QR_CODE_HINT; break; + case BarcodeFormat_DATA_MATRIX: checkAgainst = BARCODEFORMAT_DATA_MATRIX_HINT; break; + case BarcodeFormat_UPC_E: checkAgainst = BARCODEFORMAT_UPC_E_HINT; break; + case BarcodeFormat_UPC_A: checkAgainst = BARCODEFORMAT_UPC_A_HINT; break; + case BarcodeFormat_EAN_8: checkAgainst = BARCODEFORMAT_EAN_8_HINT; break; + case BarcodeFormat_EAN_13: checkAgainst = BARCODEFORMAT_EAN_13_HINT; break; + case BarcodeFormat_CODE_128: checkAgainst = BARCODEFORMAT_CODE_128_HINT; break; + case BarcodeFormat_CODE_39: checkAgainst = BARCODEFORMAT_CODE_39_HINT; break; + case BarcodeFormat_ITF: checkAgainst = BARCODEFORMAT_ITF_HINT; break; + default: throw IllegalArgumentException("Unrecognizd barcode format"); + } + return (hints & checkAgainst); +} + +void DecodeHints::setTryHarder(bool toset) { + if (toset) { + hints |= TRYHARDER_HINT; + } else { + hints &= ~TRYHARDER_HINT; + } +} + +bool DecodeHints::getTryHarder() const { + return (hints & TRYHARDER_HINT); +} + +void DecodeHints::setResultPointCallback(Ref const& _callback) { + callback = _callback; +} + +Ref DecodeHints::getResultPointCallback() const { + return callback; +} + +DecodeHintType DecodeHints::getCurrentHint() +{ + return hints; +} + +} /* namespace */ diff --git a/symbian/QZXing/source/zxing/DecodeHints.h b/symbian/QZXing/source/zxing/DecodeHints.h index 0557dae4b..04f9c9c0b 100644 --- a/symbian/QZXing/source/zxing/DecodeHints.h +++ b/symbian/QZXing/source/zxing/DecodeHints.h @@ -1,71 +1,72 @@ -#ifndef __DECODEHINTS_H_ -#define __DECODEHINTS_H_ -/* - * DecodeHintType.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - -typedef unsigned int DecodeHintType; - -class DecodeHints { - - private: - - DecodeHintType hints; - - Ref callback; - - public: - - static const DecodeHintType BARCODEFORMAT_QR_CODE_HINT = 1 << BarcodeFormat_QR_CODE; - static const DecodeHintType BARCODEFORMAT_DATA_MATRIX_HINT = 1 << BarcodeFormat_DATA_MATRIX; - static const DecodeHintType BARCODEFORMAT_UPC_E_HINT = 1 << BarcodeFormat_UPC_E; - static const DecodeHintType BARCODEFORMAT_UPC_A_HINT = 1 << BarcodeFormat_UPC_A; - static const DecodeHintType BARCODEFORMAT_EAN_8_HINT = 1 << BarcodeFormat_EAN_8; - static const DecodeHintType BARCODEFORMAT_EAN_13_HINT = 1 << BarcodeFormat_EAN_13; - static const DecodeHintType BARCODEFORMAT_CODE_128_HINT = 1 << BarcodeFormat_CODE_128; - static const DecodeHintType BARCODEFORMAT_CODE_39_HINT = 1 << BarcodeFormat_CODE_39; - static const DecodeHintType BARCODEFORMAT_ITF_HINT = 1 << BarcodeFormat_ITF; - static const DecodeHintType CHARACTER_SET = 1 << 30; - static const DecodeHintType TRYHARDER_HINT = 1 << 31; - - static const DecodeHints PRODUCT_HINT; - static const DecodeHints ONED_HINT; - static const DecodeHints DEFAULT_HINT; - - DecodeHints(); - DecodeHints(DecodeHintType init); - - void addFormat(BarcodeFormat toadd); - bool containsFormat(BarcodeFormat tocheck) const; - void setTryHarder(bool toset); - bool getTryHarder() const; - - void setResultPointCallback(Ref const&); - Ref getResultPointCallback() const; - - DecodeHintType getCurrentHint(); -}; - -} - -#endif +#ifndef __DECODEHINTS_H_ +#define __DECODEHINTS_H_ +/* + * DecodeHintType.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + +typedef unsigned int DecodeHintType; + +class DecodeHints { + + private: + + DecodeHintType hints; + + Ref callback; + + public: + + static const DecodeHintType BARCODEFORMAT_QR_CODE_HINT = 1 << BarcodeFormat_QR_CODE; + static const DecodeHintType BARCODEFORMAT_DATA_MATRIX_HINT = 1 << BarcodeFormat_DATA_MATRIX; + static const DecodeHintType BARCODEFORMAT_UPC_E_HINT = 1 << BarcodeFormat_UPC_E; + static const DecodeHintType BARCODEFORMAT_UPC_A_HINT = 1 << BarcodeFormat_UPC_A; + static const DecodeHintType BARCODEFORMAT_EAN_8_HINT = 1 << BarcodeFormat_EAN_8; + static const DecodeHintType BARCODEFORMAT_EAN_13_HINT = 1 << BarcodeFormat_EAN_13; + static const DecodeHintType BARCODEFORMAT_CODE_128_HINT = 1 << BarcodeFormat_CODE_128; + static const DecodeHintType BARCODEFORMAT_CODE_39_HINT = 1 << BarcodeFormat_CODE_39; + static const DecodeHintType BARCODEFORMAT_ITF_HINT = 1 << BarcodeFormat_ITF; + static const DecodeHintType BARCODEFORMAT_AZTEC_HINT = 1 << BarcodeFormat_AZTEC; + static const DecodeHintType CHARACTER_SET = 1 << 30; + static const DecodeHintType TRYHARDER_HINT = 1 << 31; + + static const DecodeHints PRODUCT_HINT; + static const DecodeHints ONED_HINT; + static const DecodeHints DEFAULT_HINT; + + DecodeHints(); + DecodeHints(DecodeHintType init); + + void addFormat(BarcodeFormat toadd); + bool containsFormat(BarcodeFormat tocheck) const; + void setTryHarder(bool toset); + bool getTryHarder() const; + + void setResultPointCallback(Ref const&); + Ref getResultPointCallback() const; + + DecodeHintType getCurrentHint(); +}; + +} + +#endif diff --git a/symbian/QZXing/source/zxing/Exception.cpp b/symbian/QZXing/source/zxing/Exception.cpp index ca8c21d05..1cb8036f1 100644 --- a/symbian/QZXing/source/zxing/Exception.cpp +++ b/symbian/QZXing/source/zxing/Exception.cpp @@ -1,40 +1,40 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Exception.cpp - * ZXing - * - * Created by Christian Brunschen on 03/06/2008. - * Copyright 2008-2011 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - - */ - -#include - -namespace zxing { - -Exception::Exception() {} - -Exception::Exception(const char *msg) : - message(msg) { -} - -const char* Exception::what() const throw() { - return message.c_str(); -} - -Exception::~Exception() throw() { -} - -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Exception.cpp + * ZXing + * + * Created by Christian Brunschen on 03/06/2008. + * Copyright 2008-2011 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + + */ + +#include + +namespace zxing { + +Exception::Exception() {} + +Exception::Exception(const char *msg) : + message(msg) { +} + +const char* Exception::what() const throw() { + return message.c_str(); +} + +Exception::~Exception() throw() { +} + +} diff --git a/symbian/QZXing/source/zxing/Exception.h b/symbian/QZXing/source/zxing/Exception.h index 67dd97abe..719d41fd9 100644 --- a/symbian/QZXing/source/zxing/Exception.h +++ b/symbian/QZXing/source/zxing/Exception.h @@ -1,40 +1,40 @@ -#ifndef __EXCEPTION_H__ -#define __EXCEPTION_H__ - -/* - * Exception.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - -class Exception : public std::exception { -private: - std::string message; - -public: - Exception(); - Exception(const char *msg); - virtual const char* what() const throw(); - virtual ~Exception() throw(); -}; - -} -#endif // __EXCEPTION_H__ +#ifndef __EXCEPTION_H__ +#define __EXCEPTION_H__ + +/* + * Exception.h + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + +class Exception : public std::exception { +private: + std::string message; + +public: + Exception(); + Exception(const char *msg); + virtual const char* what() const throw(); + virtual ~Exception() throw(); +}; + +} +#endif // __EXCEPTION_H__ diff --git a/symbian/QZXing/source/zxing/FormatException.cpp b/symbian/QZXing/source/zxing/FormatException.cpp index d3981c50f..fe9b10346 100644 --- a/symbian/QZXing/source/zxing/FormatException.cpp +++ b/symbian/QZXing/source/zxing/FormatException.cpp @@ -1,35 +1,35 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * FormatException.cpp - * zxing - * - * Created by Christian Brunschen on 13/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -FormatException::FormatException() {} - -FormatException::FormatException(const char *msg) : - ReaderException(msg) { -} - -FormatException::~FormatException() throw() { -} - -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * FormatException.cpp + * zxing + * + * Created by Christian Brunschen on 13/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +FormatException::FormatException() {} + +FormatException::FormatException(const char *msg) : + ReaderException(msg) { +} + +FormatException::~FormatException() throw() { +} + +} diff --git a/symbian/QZXing/source/zxing/FormatException.h b/symbian/QZXing/source/zxing/FormatException.h index da50b501e..fd18e69a8 100644 --- a/symbian/QZXing/source/zxing/FormatException.h +++ b/symbian/QZXing/source/zxing/FormatException.h @@ -1,35 +1,35 @@ -#ifndef __FORMAT_EXCEPTION_H__ -#define __FORMAT_EXCEPTION_H__ - -/* - * FormatException.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -class FormatException : public ReaderException { -public: - FormatException(); - FormatException(const char *msg); - ~FormatException() throw(); -}; - -} -#endif // __FORMAT_EXCEPTION_H__ +#ifndef __FORMAT_EXCEPTION_H__ +#define __FORMAT_EXCEPTION_H__ + +/* + * FormatException.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +class FormatException : public ReaderException { +public: + FormatException(); + FormatException(const char *msg); + ~FormatException() throw(); +}; + +} +#endif // __FORMAT_EXCEPTION_H__ diff --git a/symbian/QZXing/source/zxing/LuminanceSource.cpp b/symbian/QZXing/source/zxing/LuminanceSource.cpp index 99d54dffa..77f129007 100644 --- a/symbian/QZXing/source/zxing/LuminanceSource.cpp +++ b/symbian/QZXing/source/zxing/LuminanceSource.cpp @@ -1,76 +1,80 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * LuminanceSource.cpp - * zxing - * - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { - -LuminanceSource::LuminanceSource() { -} - -LuminanceSource::~LuminanceSource() { -} - -bool LuminanceSource::isCropSupported() const { - return false; -} - -Ref LuminanceSource::crop(int left, int top, int width, int height) { - throw IllegalArgumentException("This luminance source does not support cropping."); -} - -bool LuminanceSource::isRotateSupported() const { - return false; -} - -Ref LuminanceSource::rotateCounterClockwise() { - throw IllegalArgumentException("This luminance source does not support rotation."); -} - -LuminanceSource::operator std::string() { - unsigned char* row = 0; - std::ostringstream oss; - for (int y = 0; y < getHeight(); y++) { - row = getRow(y, row); - for (int x = 0; x < getWidth(); x++) { - int luminance = row[x] & 0xFF; - char c; - if (luminance < 0x40) { - c = '#'; - } else if (luminance < 0x80) { - c = '+'; - } else if (luminance < 0xC0) { - c = '.'; - } else { - c = ' '; - } - oss << c; - } - oss << '\n'; - } - delete [] row; - return oss.str(); -} - - - -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * LuminanceSource.cpp + * zxing + * + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { + +LuminanceSource::LuminanceSource() { +} + +LuminanceSource::~LuminanceSource() { +} + +bool LuminanceSource::isCropSupported() const { + return false; +} + +Ref LuminanceSource::crop(int left, int top, int width, int height) { + (void)left; + (void)top; + (void)width; + (void)height; + throw IllegalArgumentException("This luminance source does not support cropping."); +} + +bool LuminanceSource::isRotateSupported() const { + return false; +} + +Ref LuminanceSource::rotateCounterClockwise() { + throw IllegalArgumentException("This luminance source does not support rotation."); +} + +LuminanceSource::operator std::string() { + unsigned char* row = 0; + std::ostringstream oss; + for (int y = 0; y < getHeight(); y++) { + row = getRow(y, row); + for (int x = 0; x < getWidth(); x++) { + int luminance = row[x] & 0xFF; + char c; + if (luminance < 0x40) { + c = '#'; + } else if (luminance < 0x80) { + c = '+'; + } else if (luminance < 0xC0) { + c = '.'; + } else { + c = ' '; + } + oss << c; + } + oss << '\n'; + } + delete [] row; + return oss.str(); +} + + + +} diff --git a/symbian/QZXing/source/zxing/LuminanceSource.h b/symbian/QZXing/source/zxing/LuminanceSource.h index 7130808f5..5d8cba2ec 100644 --- a/symbian/QZXing/source/zxing/LuminanceSource.h +++ b/symbian/QZXing/source/zxing/LuminanceSource.h @@ -1,52 +1,52 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __LUMINANCESOURCE_H__ -#define __LUMINANCESOURCE_H__ -/* - * LuminanceSource.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - -class LuminanceSource : public Counted { -public: - LuminanceSource(); - virtual ~LuminanceSource(); - - virtual int getWidth() const = 0; - virtual int getHeight() const = 0; - - // Callers take ownership of the returned memory and must call delete [] on it themselves. - virtual unsigned char* getRow(int y, unsigned char* row) = 0; - virtual unsigned char* getMatrix() = 0; - - virtual bool isCropSupported() const; - virtual Ref crop(int left, int top, int width, int height); - - virtual bool isRotateSupported() const; - virtual Ref rotateCounterClockwise(); - - operator std::string (); // should be const but don't want to make sure a - // large breaking change right now -}; - -} - -#endif /* LUMINANCESOURCE_H_ */ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __LUMINANCESOURCE_H__ +#define __LUMINANCESOURCE_H__ +/* + * LuminanceSource.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + +class LuminanceSource : public Counted { +public: + LuminanceSource(); + virtual ~LuminanceSource(); + + virtual int getWidth() const = 0; + virtual int getHeight() const = 0; + + // Callers take ownership of the returned memory and must call delete [] on it themselves. + virtual unsigned char* getRow(int y, unsigned char* row) = 0; + virtual unsigned char* getMatrix() = 0; + + virtual bool isCropSupported() const; + virtual Ref crop(int left, int top, int width, int height); + + virtual bool isRotateSupported() const; + virtual Ref rotateCounterClockwise(); + + operator std::string (); // should be const but don't want to make sure a + // large breaking change right now +}; + +} + +#endif /* LUMINANCESOURCE_H_ */ diff --git a/symbian/QZXing/source/zxing/MultiFormatReader.cpp b/symbian/QZXing/source/zxing/MultiFormatReader.cpp index be181de7e..8e6f72ff2 100644 --- a/symbian/QZXing/source/zxing/MultiFormatReader.cpp +++ b/symbian/QZXing/source/zxing/MultiFormatReader.cpp @@ -1,102 +1,106 @@ -/* - * MultiFormatBarcodeReader.cpp - * ZXing - * - * Created by Lukasz Warchol on 10-01-26. - * Modified by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace zxing { - MultiFormatReader::MultiFormatReader() { - - } - - Ref MultiFormatReader::decode(Ref image) { - setHints(DecodeHints::DEFAULT_HINT); - return decodeInternal(image); - } - - Ref MultiFormatReader::decode(Ref image, DecodeHints hints) { - setHints(hints); - return decodeInternal(image); - } - - Ref MultiFormatReader::decodeWithState(Ref image) { - // Make sure to set up the default state so we don't crash - if (readers_.size() == 0) { - setHints(DecodeHints::DEFAULT_HINT); - } - return decodeInternal(image); - } - - void MultiFormatReader::setHints(DecodeHints hints) { - hints_ = hints; - readers_.clear(); - bool tryHarder = hints.getTryHarder(); - - bool addOneDReader = hints.containsFormat(BarcodeFormat_UPC_E) || - hints.containsFormat(BarcodeFormat_UPC_A) || - hints.containsFormat(BarcodeFormat_EAN_8) || - hints.containsFormat(BarcodeFormat_EAN_13) || - hints.containsFormat(BarcodeFormat_CODE_128) || - hints.containsFormat(BarcodeFormat_CODE_39) || - hints.containsFormat(BarcodeFormat_ITF); - if (addOneDReader && !tryHarder) { - readers_.push_back(Ref(new zxing::oned::MultiFormatOneDReader(hints))); - } - if (hints.containsFormat(BarcodeFormat_QR_CODE)) { - readers_.push_back(Ref(new zxing::qrcode::QRCodeReader())); - } - if (hints.containsFormat(BarcodeFormat_DATA_MATRIX)) { - readers_.push_back(Ref(new zxing::datamatrix::DataMatrixReader())); - } - //TODO: add PDF417 here once PDF417 reader is implemented - if (addOneDReader && tryHarder) { - readers_.push_back(Ref(new zxing::oned::MultiFormatOneDReader(hints))); - } - if (readers_.size() == 0) { - if (!tryHarder) { - readers_.push_back(Ref(new zxing::oned::MultiFormatOneDReader(hints))); - } - readers_.push_back(Ref(new zxing::qrcode::QRCodeReader())); - if (tryHarder) { - readers_.push_back(Ref(new zxing::oned::MultiFormatOneDReader(hints))); - } - } - } - - Ref MultiFormatReader::decodeInternal(Ref image) { - for (unsigned int i = 0; i < readers_.size(); i++) { - try { - return readers_[i]->decode(image, hints_); - } catch (ReaderException const& re) { - // continue - } - } - throw ReaderException("No code detected"); - } - - MultiFormatReader::~MultiFormatReader() { - - } -} +/* + * MultiFormatBarcodeReader.cpp + * ZXing + * + * Created by Lukasz Warchol on 10-01-26. + * Modified by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +namespace zxing { + MultiFormatReader::MultiFormatReader() { + + } + + Ref MultiFormatReader::decode(Ref image) { + setHints(DecodeHints::DEFAULT_HINT); + return decodeInternal(image); + } + + Ref MultiFormatReader::decode(Ref image, DecodeHints hints) { + setHints(hints); + return decodeInternal(image); + } + + Ref MultiFormatReader::decodeWithState(Ref image) { + // Make sure to set up the default state so we don't crash + if (readers_.size() == 0) { + setHints(DecodeHints::DEFAULT_HINT); + } + return decodeInternal(image); + } + + void MultiFormatReader::setHints(DecodeHints hints) { + hints_ = hints; + readers_.clear(); + bool tryHarder = hints.getTryHarder(); + + bool addOneDReader = hints.containsFormat(BarcodeFormat_UPC_E) || + hints.containsFormat(BarcodeFormat_UPC_A) || + hints.containsFormat(BarcodeFormat_EAN_8) || + hints.containsFormat(BarcodeFormat_EAN_13) || + hints.containsFormat(BarcodeFormat_CODE_128) || + hints.containsFormat(BarcodeFormat_CODE_39) || + hints.containsFormat(BarcodeFormat_ITF); + if (addOneDReader && !tryHarder) { + readers_.push_back(Ref(new zxing::oned::MultiFormatOneDReader(hints))); + } + if (hints.containsFormat(BarcodeFormat_QR_CODE)) { + readers_.push_back(Ref(new zxing::qrcode::QRCodeReader())); + } + if (hints.containsFormat(BarcodeFormat_DATA_MATRIX)) { + readers_.push_back(Ref(new zxing::datamatrix::DataMatrixReader())); + } + if (hints.containsFormat(BarcodeFormat_AZTEC)) { + readers_.push_back(Ref(new zxing::aztec::AztecReader())); + } + //TODO: add PDF417 here once PDF417 reader is implemented + if (addOneDReader && tryHarder) { + readers_.push_back(Ref(new zxing::oned::MultiFormatOneDReader(hints))); + } + if (readers_.size() == 0) { + if (!tryHarder) { + readers_.push_back(Ref(new zxing::oned::MultiFormatOneDReader(hints))); + } + readers_.push_back(Ref(new zxing::qrcode::QRCodeReader())); + if (tryHarder) { + readers_.push_back(Ref(new zxing::oned::MultiFormatOneDReader(hints))); + } + } + } + + Ref MultiFormatReader::decodeInternal(Ref image) { + for (unsigned int i = 0; i < readers_.size(); i++) { + try { + return readers_[i]->decode(image, hints_); + } catch (ReaderException const& re) { + // continue + } + } + throw ReaderException("No code detected"); + } + + MultiFormatReader::~MultiFormatReader() { + + } +} diff --git a/symbian/QZXing/source/zxing/MultiFormatReader.h b/symbian/QZXing/source/zxing/MultiFormatReader.h index 9411cfbf1..f4b377c84 100644 --- a/symbian/QZXing/source/zxing/MultiFormatReader.h +++ b/symbian/QZXing/source/zxing/MultiFormatReader.h @@ -1,49 +1,49 @@ -#ifndef __MULTI_FORMAT_READER_H__ -#define __MULTI_FORMAT_READER_H__ - -/* - * MultiFormatBarcodeReader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include - -namespace zxing { - class MultiFormatReader : public Reader { - - private: - Ref decodeInternal(Ref image); - - std::vector > readers_; - DecodeHints hints_; - - public: - MultiFormatReader(); - - Ref decode(Ref image); - Ref decode(Ref image, DecodeHints hints); - Ref decodeWithState(Ref image); - void setHints(DecodeHints hints); - ~MultiFormatReader(); - }; -} - -#endif +#ifndef __MULTI_FORMAT_READER_H__ +#define __MULTI_FORMAT_READER_H__ + +/* + * MultiFormatBarcodeReader.h + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include + +namespace zxing { + class MultiFormatReader : public Reader { + + private: + Ref decodeInternal(Ref image); + + std::vector > readers_; + DecodeHints hints_; + + public: + MultiFormatReader(); + + Ref decode(Ref image); + Ref decode(Ref image, DecodeHints hints); + Ref decodeWithState(Ref image); + void setHints(DecodeHints hints); + ~MultiFormatReader(); + }; +} + +#endif diff --git a/symbian/QZXing/source/zxing/Reader.cpp b/symbian/QZXing/source/zxing/Reader.cpp index d64f8251f..6926ab4fb 100644 --- a/symbian/QZXing/source/zxing/Reader.cpp +++ b/symbian/QZXing/source/zxing/Reader.cpp @@ -1,31 +1,31 @@ -/* - * Reader.cpp - * zxing - * - * Created by Christian Brunschen on 13/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -Reader::~Reader() { } - -Ref Reader::decode(Ref image) { - return decode(image, DecodeHints::DEFAULT_HINT); -} - -} +/* + * Reader.cpp + * zxing + * + * Created by Christian Brunschen on 13/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +Reader::~Reader() { } + +Ref Reader::decode(Ref image) { + return decode(image, DecodeHints::DEFAULT_HINT); +} + +} diff --git a/symbian/QZXing/source/zxing/Reader.h b/symbian/QZXing/source/zxing/Reader.h index 05c741b4e..bd5469191 100644 --- a/symbian/QZXing/source/zxing/Reader.h +++ b/symbian/QZXing/source/zxing/Reader.h @@ -1,40 +1,40 @@ -#ifndef __READER_H__ -#define __READER_H__ - -/* - * Reader.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { - - class Reader : public Counted { - protected: - Reader() {} - public: - virtual Ref decode(Ref image); - virtual Ref decode(Ref image, DecodeHints hints) = 0; - virtual ~Reader(); -}; - -} - -#endif // __READER_H__ +#ifndef __READER_H__ +#define __READER_H__ + +/* + * Reader.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { + + class Reader : public Counted { + protected: + Reader() {} + public: + virtual Ref decode(Ref image); + virtual Ref decode(Ref image, DecodeHints hints) = 0; + virtual ~Reader(); +}; + +} + +#endif // __READER_H__ diff --git a/symbian/QZXing/source/zxing/ReaderException.cpp b/symbian/QZXing/source/zxing/ReaderException.cpp index 07d4bb697..7321f17d6 100644 --- a/symbian/QZXing/source/zxing/ReaderException.cpp +++ b/symbian/QZXing/source/zxing/ReaderException.cpp @@ -1,35 +1,35 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * ReaderException.cpp - * zxing - * - * Created by Christian Brunschen on 13/05/2008. - * Copyright 2008-2011 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -ReaderException::ReaderException() {} - -ReaderException::ReaderException(const char *msg) : - Exception(msg) { -} - -ReaderException::~ReaderException() throw() { -} - -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * ReaderException.cpp + * zxing + * + * Created by Christian Brunschen on 13/05/2008. + * Copyright 2008-2011 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +ReaderException::ReaderException() {} + +ReaderException::ReaderException(const char *msg) : + Exception(msg) { +} + +ReaderException::~ReaderException() throw() { +} + +} diff --git a/symbian/QZXing/source/zxing/ReaderException.h b/symbian/QZXing/source/zxing/ReaderException.h index d54ae62b4..17b471bf3 100644 --- a/symbian/QZXing/source/zxing/ReaderException.h +++ b/symbian/QZXing/source/zxing/ReaderException.h @@ -1,35 +1,35 @@ -#ifndef __READER_EXCEPTION_H__ -#define __READER_EXCEPTION_H__ - -/* - * ReaderException.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -class ReaderException : public Exception { -public: - ReaderException(); - ReaderException(const char *msg); - ~ReaderException() throw(); -}; - -} -#endif // __READER_EXCEPTION_H__ +#ifndef __READER_EXCEPTION_H__ +#define __READER_EXCEPTION_H__ + +/* + * ReaderException.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +class ReaderException : public Exception { +public: + ReaderException(); + ReaderException(const char *msg); + ~ReaderException() throw(); +}; + +} +#endif // __READER_EXCEPTION_H__ diff --git a/symbian/QZXing/source/zxing/Result.cpp b/symbian/QZXing/source/zxing/Result.cpp index 7ab6e312c..ccaf66971 100644 --- a/symbian/QZXing/source/zxing/Result.cpp +++ b/symbian/QZXing/source/zxing/Result.cpp @@ -1,64 +1,64 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Result.cpp - * zxing - * - * Created by Christian Brunschen on 13/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { -using namespace std; - -Result::Result(Ref text, ArrayRef rawBytes, std::vector > resultPoints, - BarcodeFormat format) : - text_(text), rawBytes_(rawBytes), resultPoints_(resultPoints), format_(format) { -} - -Result::~Result() { -} - -Ref Result::getText() { - return text_; -} - -ArrayRef Result::getRawBytes() { - return rawBytes_; -} - -const std::vector >& Result::getResultPoints() const { - return resultPoints_; -} - -std::vector >& Result::getResultPoints() { - return resultPoints_; -} - -BarcodeFormat Result::getBarcodeFormat() const { - return format_; -} - -ostream& operator<<(ostream &out, Result& result) { - if (result.text_ != 0) { - out << result.text_->getText(); - } else { - out << "[" << result.rawBytes_->size() << " bytes]"; - } - return out; -} - -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Result.cpp + * zxing + * + * Created by Christian Brunschen on 13/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { +using namespace std; + +Result::Result(Ref text, ArrayRef rawBytes, std::vector > resultPoints, + BarcodeFormat format) : + text_(text), rawBytes_(rawBytes), resultPoints_(resultPoints), format_(format) { +} + +Result::~Result() { +} + +Ref Result::getText() { + return text_; +} + +ArrayRef Result::getRawBytes() { + return rawBytes_; +} + +const std::vector >& Result::getResultPoints() const { + return resultPoints_; +} + +std::vector >& Result::getResultPoints() { + return resultPoints_; +} + +BarcodeFormat Result::getBarcodeFormat() const { + return format_; +} + +ostream& operator<<(ostream &out, Result& result) { + if (result.text_ != 0) { + out << result.text_->getText(); + } else { + out << "[" << result.rawBytes_->size() << " bytes]"; + } + return out; +} + +} diff --git a/symbian/QZXing/source/zxing/Result.h b/symbian/QZXing/source/zxing/Result.h index 711605962..030bba7ee 100644 --- a/symbian/QZXing/source/zxing/Result.h +++ b/symbian/QZXing/source/zxing/Result.h @@ -1,54 +1,54 @@ -#ifndef __RESULT_H__ -#define __RESULT_H__ - -/* - * Result.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace zxing { - -class Result : public Counted { -private: - Ref text_; - ArrayRef rawBytes_; - std::vector > resultPoints_; - BarcodeFormat format_; - -public: - Result(Ref text, ArrayRef rawBytes, std::vector > resultPoints, - BarcodeFormat format); - ~Result(); - Ref getText(); - ArrayRef getRawBytes(); - const std::vector >& getResultPoints() const; - std::vector >& getResultPoints(); - BarcodeFormat getBarcodeFormat() const; - - friend std::ostream& operator<<(std::ostream &out, Result& result); -}; - -} -#endif // __RESULT_H__ +#ifndef __RESULT_H__ +#define __RESULT_H__ + +/* + * Result.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +namespace zxing { + +class Result : public Counted { +private: + Ref text_; + ArrayRef rawBytes_; + std::vector > resultPoints_; + BarcodeFormat format_; + +public: + Result(Ref text, ArrayRef rawBytes, std::vector > resultPoints, + BarcodeFormat format); + ~Result(); + Ref getText(); + ArrayRef getRawBytes(); + const std::vector >& getResultPoints() const; + std::vector >& getResultPoints(); + BarcodeFormat getBarcodeFormat() const; + + friend std::ostream& operator<<(std::ostream &out, Result& result); +}; + +} +#endif // __RESULT_H__ diff --git a/symbian/QZXing/source/zxing/ResultPoint.cpp b/symbian/QZXing/source/zxing/ResultPoint.cpp index fa31588a1..6fb05fece 100644 --- a/symbian/QZXing/source/zxing/ResultPoint.cpp +++ b/symbian/QZXing/source/zxing/ResultPoint.cpp @@ -1,100 +1,100 @@ -/* - * ResultPoint.cpp - * zxing - * - * Created by Christian Brunschen on 13/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - -ResultPoint::ResultPoint() : posX_(0), posY_(0) {} - -ResultPoint::ResultPoint(float x, float y) : posX_(x), posY_(y) {} - -ResultPoint::~ResultPoint() {} - -float ResultPoint::getX() const { - return posX_; -} - -float ResultPoint::getY() const { - return posY_; -} - -bool ResultPoint::equals(Ref other) { - return posX_ == other->getX() && posY_ == other->getY(); -} - -/** - *

Orders an array of three ResultPoints in an order [A,B,C] such that AB < AC and - * BC < AC and the angle between BC and BA is less than 180 degrees. - */ -void ResultPoint::orderBestPatterns(std::vector > &patterns) { - // Find distances between pattern centers - float zeroOneDistance = distance(patterns[0]->getX(), patterns[1]->getX(),patterns[0]->getY(), patterns[1]->getY()); - float oneTwoDistance = distance(patterns[1]->getX(), patterns[2]->getX(),patterns[1]->getY(), patterns[2]->getY()); - float zeroTwoDistance = distance(patterns[0]->getX(), patterns[2]->getX(),patterns[0]->getY(), patterns[2]->getY()); - - Ref pointA, pointB, pointC; - // Assume one closest to other two is B; A and C will just be guesses at first - if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance) { - pointB = patterns[0]; - pointA = patterns[1]; - pointC = patterns[2]; - } else if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance) { - pointB = patterns[1]; - pointA = patterns[0]; - pointC = patterns[2]; - } else { - pointB = patterns[2]; - pointA = patterns[0]; - pointC = patterns[1]; - } - - // Use cross product to figure out whether A and C are correct or flipped. - // This asks whether BC x BA has a positive z component, which is the arrangement - // we want for A, B, C. If it's negative, then we've got it flipped around and - // should swap A and C. - if (crossProductZ(pointA, pointB, pointC) < 0.0f) { - Ref temp = pointA; - pointA = pointC; - pointC = temp; - } - - patterns[0] = pointA; - patterns[1] = pointB; - patterns[2] = pointC; -} - -float ResultPoint::distance(Ref point1, Ref point2) { - return distance(point1->getX(), point1->getY(), point2->getX(), point2->getY()); -} - -float ResultPoint::distance(float x1, float x2, float y1, float y2) { - float xDiff = x1 - x2; - float yDiff = y1 - y2; - return (float) sqrt((double) (xDiff * xDiff + yDiff * yDiff)); -} - -float ResultPoint::crossProductZ(Ref pointA, Ref pointB, Ref pointC) { - float bX = pointB->getX(); - float bY = pointB->getY(); - return ((pointC->getX() - bX) * (pointA->getY() - bY)) - ((pointC->getY() - bY) * (pointA->getX() - bX)); -} -} +/* + * ResultPoint.cpp + * zxing + * + * Created by Christian Brunschen on 13/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + +ResultPoint::ResultPoint() : posX_(0), posY_(0) {} + +ResultPoint::ResultPoint(float x, float y) : posX_(x), posY_(y) {} + +ResultPoint::~ResultPoint() {} + +float ResultPoint::getX() const { + return posX_; +} + +float ResultPoint::getY() const { + return posY_; +} + +bool ResultPoint::equals(Ref other) { + return posX_ == other->getX() && posY_ == other->getY(); +} + +/** + *

Orders an array of three ResultPoints in an order [A,B,C] such that AB < AC and + * BC < AC and the angle between BC and BA is less than 180 degrees. + */ +void ResultPoint::orderBestPatterns(std::vector > &patterns) { + // Find distances between pattern centers + float zeroOneDistance = distance(patterns[0]->getX(), patterns[1]->getX(),patterns[0]->getY(), patterns[1]->getY()); + float oneTwoDistance = distance(patterns[1]->getX(), patterns[2]->getX(),patterns[1]->getY(), patterns[2]->getY()); + float zeroTwoDistance = distance(patterns[0]->getX(), patterns[2]->getX(),patterns[0]->getY(), patterns[2]->getY()); + + Ref pointA, pointB, pointC; + // Assume one closest to other two is B; A and C will just be guesses at first + if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance) { + pointB = patterns[0]; + pointA = patterns[1]; + pointC = patterns[2]; + } else if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance) { + pointB = patterns[1]; + pointA = patterns[0]; + pointC = patterns[2]; + } else { + pointB = patterns[2]; + pointA = patterns[0]; + pointC = patterns[1]; + } + + // Use cross product to figure out whether A and C are correct or flipped. + // This asks whether BC x BA has a positive z component, which is the arrangement + // we want for A, B, C. If it's negative, then we've got it flipped around and + // should swap A and C. + if (crossProductZ(pointA, pointB, pointC) < 0.0f) { + Ref temp = pointA; + pointA = pointC; + pointC = temp; + } + + patterns[0] = pointA; + patterns[1] = pointB; + patterns[2] = pointC; +} + +float ResultPoint::distance(Ref point1, Ref point2) { + return distance(point1->getX(), point1->getY(), point2->getX(), point2->getY()); +} + +float ResultPoint::distance(float x1, float x2, float y1, float y2) { + float xDiff = x1 - x2; + float yDiff = y1 - y2; + return (float) sqrt((double) (xDiff * xDiff + yDiff * yDiff)); +} + +float ResultPoint::crossProductZ(Ref pointA, Ref pointB, Ref pointC) { + float bX = pointB->getX(); + float bY = pointB->getY(); + return ((pointC->getX() - bX) * (pointA->getY() - bY)) - ((pointC->getY() - bY) * (pointA->getX() - bX)); +} +} diff --git a/symbian/QZXing/source/zxing/ResultPoint.h b/symbian/QZXing/source/zxing/ResultPoint.h index ae48b8434..d7561c780 100644 --- a/symbian/QZXing/source/zxing/ResultPoint.h +++ b/symbian/QZXing/source/zxing/ResultPoint.h @@ -1,54 +1,54 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __RESULT_POINT_H__ -#define __RESULT_POINT_H__ - -/* - * ResultPoint.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - -class ResultPoint : public Counted { -protected: - float posX_; - float posY_; - -public: - ResultPoint(); - ResultPoint(float x, float y); - virtual ~ResultPoint(); - - virtual float getX() const; - virtual float getY() const; - - bool equals(Ref other); - - static void orderBestPatterns(std::vector > &patterns); - static float distance(Ref point1, Ref point2); - static float distance(float x1, float x2, float y1, float y2); - -private: - static float crossProductZ(Ref pointA, Ref pointB, Ref pointC); -}; - -} - -#endif // __RESULT_POINT_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __RESULT_POINT_H__ +#define __RESULT_POINT_H__ + +/* + * ResultPoint.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + +class ResultPoint : public Counted { +protected: + float posX_; + float posY_; + +public: + ResultPoint(); + ResultPoint(float x, float y); + virtual ~ResultPoint(); + + virtual float getX() const; + virtual float getY() const; + + bool equals(Ref other); + + static void orderBestPatterns(std::vector > &patterns); + static float distance(Ref point1, Ref point2); + static float distance(float x1, float x2, float y1, float y2); + +private: + static float crossProductZ(Ref pointA, Ref pointB, Ref pointC); +}; + +} + +#endif // __RESULT_POINT_H__ diff --git a/symbian/QZXing/source/zxing/ResultPointCallback.cpp b/symbian/QZXing/source/zxing/ResultPointCallback.cpp index 723942aba..7b7f82f03 100644 --- a/symbian/QZXing/source/zxing/ResultPointCallback.cpp +++ b/symbian/QZXing/source/zxing/ResultPointCallback.cpp @@ -1,26 +1,26 @@ -/* - * ResultPointCallback.cpp - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -ResultPointCallback::~ResultPointCallback() {} - -} +/* + * ResultPointCallback.cpp + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +ResultPointCallback::~ResultPointCallback() {} + +} diff --git a/symbian/QZXing/source/zxing/ResultPointCallback.h b/symbian/QZXing/source/zxing/ResultPointCallback.h index 26876563a..47c175e6f 100644 --- a/symbian/QZXing/source/zxing/ResultPointCallback.h +++ b/symbian/QZXing/source/zxing/ResultPointCallback.h @@ -1,39 +1,39 @@ -#ifndef __RESULT_POINT_CALLBACK_H__ -#define __RESULT_POINT_CALLBACK_H__ - -/* - * ResultPointCallback.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -class ResultPoint; - -class ResultPointCallback : public Counted { -protected: - ResultPointCallback() {} -public: - virtual void foundPossibleResultPoint(ResultPoint const& point) = 0; - virtual ~ResultPointCallback(); -}; - -} - -#endif // __RESULT_POINT_CALLBACK_H__ +#ifndef __RESULT_POINT_CALLBACK_H__ +#define __RESULT_POINT_CALLBACK_H__ + +/* + * ResultPointCallback.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +class ResultPoint; + +class ResultPointCallback : public Counted { +protected: + ResultPointCallback() {} +public: + virtual void foundPossibleResultPoint(ResultPoint const& point) = 0; + virtual ~ResultPointCallback(); +}; + +} + +#endif // __RESULT_POINT_CALLBACK_H__ diff --git a/symbian/QZXing/source/zxing/aztec/AztecDetectorResult.cpp b/symbian/QZXing/source/zxing/aztec/AztecDetectorResult.cpp new file mode 100644 index 000000000..ade9ef0e6 --- /dev/null +++ b/symbian/QZXing/source/zxing/aztec/AztecDetectorResult.cpp @@ -0,0 +1,45 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * AtztecDetecorResult.cpp + * zxing + * + * Created by Lukas Stabe on 08/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + namespace aztec { + AztecDetectorResult::AztecDetectorResult(Ref bits, std::vector > points, bool compact, int nbDatablocks, int nbLayers) + : DetectorResult(bits, points), + compact_(compact), + nbDatablocks_(nbDatablocks), + nbLayers_(nbLayers) { + } + + bool AztecDetectorResult::isCompact() { + return compact_; + } + + int AztecDetectorResult::getNBDatablocks() { + return nbDatablocks_; + } + + int AztecDetectorResult::getNBLayers() { + return nbLayers_; + } + } +} diff --git a/symbian/QZXing/source/zxing/aztec/AztecDetectorResult.h b/symbian/QZXing/source/zxing/aztec/AztecDetectorResult.h new file mode 100644 index 000000000..28822e5e3 --- /dev/null +++ b/symbian/QZXing/source/zxing/aztec/AztecDetectorResult.h @@ -0,0 +1,42 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * AtztecDetecorResult.h + * zxing + * + * Created by Lukas Stabe on 08/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#ifndef ZXingWidget_AtztecDetecorResult_h +#define ZXingWidget_AtztecDetecorResult_h + +namespace zxing { + namespace aztec { + class AztecDetectorResult : public DetectorResult { + private: + bool compact_; + int nbDatablocks_, nbLayers_; + public: + AztecDetectorResult(Ref bits, std::vector > points, bool compact, int nbDatablocks, int nbLayers); + bool isCompact(); + int getNBDatablocks(); + int getNBLayers(); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/aztec/AztecReader.cpp b/symbian/QZXing/source/zxing/aztec/AztecReader.cpp new file mode 100644 index 000000000..8600163f7 --- /dev/null +++ b/symbian/QZXing/source/zxing/aztec/AztecReader.cpp @@ -0,0 +1,64 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * AztecReader.cpp + * zxing + * + * Created by Lukas Stabe on 08/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { + namespace aztec { + + AztecReader::AztecReader() : decoder_() { + // nothing + } + + Ref AztecReader::decode(Ref image) { + Detector detector(image->getBlackMatrix()); + + Ref detectorResult(detector.detect()); + + std::vector > points(detectorResult->getPoints()); + + Ref decoderResult(decoder_.decode(detectorResult)); + + Ref result(new Result(decoderResult->getText(), + decoderResult->getRawBytes(), + points, + BarcodeFormat_AZTEC)); + + return result; + } + + Ref AztecReader::decode(Ref image, DecodeHints) { + //cout << "decoding with hints not supported for aztec" << "\n" << flush; + return this->decode(image); + } + + AztecReader::~AztecReader() { + // nothing + } + + Decoder& AztecReader::getDecoder() { + return decoder_; + } + + } +} diff --git a/symbian/QZXing/source/zxing/aztec/AztecReader.h b/symbian/QZXing/source/zxing/aztec/AztecReader.h new file mode 100644 index 000000000..ede8a4d3f --- /dev/null +++ b/symbian/QZXing/source/zxing/aztec/AztecReader.h @@ -0,0 +1,49 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * AztecReader.h + * zxing + * + * Created by Lukas Stabe on 08/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#ifndef ZXingWidget_AztecReader_h +#define ZXingWidget_AztecReader_h + +namespace zxing { + namespace aztec { + + class AztecReader : public Reader { + private: + Decoder decoder_; + + protected: + Decoder &getDecoder(); + + public: + AztecReader(); + virtual Ref decode(Ref image); + virtual Ref decode(Ref image, DecodeHints hints); + virtual ~AztecReader(); + }; + + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/aztec/decoder/AztecDecoder.cpp b/symbian/QZXing/source/zxing/aztec/decoder/AztecDecoder.cpp new file mode 100644 index 000000000..f88df80f4 --- /dev/null +++ b/symbian/QZXing/source/zxing/aztec/decoder/AztecDecoder.cpp @@ -0,0 +1,496 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Decoder.cpp + * zxing + * + * Created by Lukas Stabe on 08/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#ifndef NO_ICONV +#include +#endif +#include +#include +#include +#include +#include +#include + +#include + +using zxing::aztec::Decoder; +using zxing::DecoderResult; +using zxing::String; +using zxing::BitArray; +using zxing::BitMatrix; +using zxing::Ref; + +using std::string; + +namespace { + void add(string& result, unsigned char character) { +#ifndef NO_ICONV + char s[] = { character & 0xff }; + char* ss = s; + size_t sl = sizeof(s); + char d[4]; + char* ds = d; + size_t dl = sizeof(d); + iconv_t ic = iconv_open("UTF-8", "ISO-8859-1"); + + +#if defined(Q_OS_SYMBIAN) + iconv(ic, (const char**)&ss, &sl, &ds, &dl); // for Symbian and Mingw +#else + iconv(ic, (char**)&ss, &sl, &ds, &dl); // for Harmattan +#endif + iconv_close(ic); + d[sizeof(d)-dl] = 0; + result.append(d); +#else + result.push_back(character); +#endif + } + + const int NB_BITS_COMPACT[] = { + 0, 104, 240, 408, 608 + }; + + const int NB_BITS[] = { + 0, 128, 288, 480, 704, 960, 1248, 1568, 1920, 2304, 2720, 3168, 3648, 4160, 4704, 5280, 5888, 6528, + 7200, 7904, 8640, 9408, 10208, 11040, 11904, 12800, 13728, 14688, 15680, 16704, 17760, 18848, 19968 + }; + + const int NB_DATABLOCK_COMPACT[] = { + 0, 17, 40, 51, 76 + }; + + const int NB_DATABLOCK[] = { + 0, 21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790, 864, + 940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664 + }; + + const char* UPPER_TABLE[] = { + "CTRL_PS", " ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", + "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "CTRL_LL", "CTRL_ML", "CTRL_DL", "CTRL_BS" + }; + + const char* LOWER_TABLE[] = { + "CTRL_PS", " ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", + "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "CTRL_US", "CTRL_ML", "CTRL_DL", "CTRL_BS" + }; + + const char* MIXED_TABLE[] = { + "CTRL_PS", " ", "\1", "\2", "\3", "\4", "\5", "\6", "\7", "\b", "\t", "\n", + "\13", "\f", "\r", "\33", "\34", "\35", "\36", "\37", "@", "\\", "^", "_", + "`", "|", "~", "\177", "CTRL_LL", "CTRL_UL", "CTRL_PL", "CTRL_BS" + }; + + const char* PUNCT_TABLE[] = { + "", "\r", "\r\n", ". ", ", ", ": ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", + "*", "+", ",", "-", ".", "/", ":", ";", "<", "=", ">", "?", "[", "]", "{", "}", "CTRL_UL" + }; + + const char* DIGIT_TABLE[] = { + "CTRL_PS", " ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", ".", "CTRL_UL", "CTRL_US" + }; +} + +Decoder::Table Decoder::getTable(char t) { + switch (t) { + case 'L': + return LOWER; + case 'P': + return PUNCT; + case 'M': + return MIXED; + case 'D': + return DIGIT; + case 'B': + return BINARY; + case 'U': + default: + return UPPER; + } +} + +const char* Decoder::getCharacter(zxing::aztec::Decoder::Table table, int code) { + switch (table) { + case UPPER: + return UPPER_TABLE[code]; + case LOWER: + return LOWER_TABLE[code]; + case MIXED: + return MIXED_TABLE[code]; + case PUNCT: + return PUNCT_TABLE[code]; + case DIGIT: + return DIGIT_TABLE[code]; + default: + return ""; + } +} + +Decoder::Decoder() { + // nothing +} + +Ref Decoder::decode(Ref detectorResult) { + ddata_ = detectorResult; + + // std::printf("getting bits\n"); + + Ref matrix = detectorResult->getBits(); + + if (!ddata_->isCompact()) { + // std::printf("removing lines\n"); + matrix = removeDashedLines(ddata_->getBits()); + } + + // std::printf("extracting bits\n"); + Ref rawbits = extractBits(matrix); + + // std::printf("correcting bits\n"); + Ref aCorrectedBits = correctBits(rawbits); + + // std::printf("decoding bits\n"); + Ref result = getEncodedData(aCorrectedBits); + + // std::printf("constructing array\n"); + ArrayRef arrayOut(aCorrectedBits->getSize()); + for (int i = 0; i < aCorrectedBits->count(); i++) { + arrayOut[i] = (unsigned char)aCorrectedBits->get(i); + } + + // std::printf("returning\n"); + + return Ref(new DecoderResult(arrayOut, result)); +} + +Ref Decoder::getEncodedData(Ref correctedBits) { + int endIndex = codewordSize_ * ddata_->getNBDatablocks() - invertedBitCount_; + if (endIndex > (int)correctedBits->getSize()) { + // std::printf("invalid input\n"); + throw FormatException("invalid input data"); + } + + Table lastTable = UPPER; + Table table = UPPER; + int startIndex = 0; + std::string result; + bool end = false; + bool shift = false; + bool switchShift = false; + bool binaryShift = false; + + while (!end) { + // std::printf("decoooooding\n"); + + if (shift) { + switchShift = true; + } else { + lastTable = table; + } + + int code; + if (binaryShift) { + if (endIndex - startIndex < 5) { + break; + } + + int length = readCode(correctedBits, startIndex, 5); + startIndex += 5; + if (length == 0) { + if (endIndex - startIndex < 11) { + break; + } + + length = readCode(correctedBits, startIndex, 11) + 31; + startIndex += 11; + } + for (int charCount = 0; charCount < length; charCount++) { + if (endIndex - startIndex < 8) { + end = true; + break; + } + + code = readCode(correctedBits, startIndex, 8); + add(result, code); + startIndex += 8; + } + binaryShift = false; + } else { + if (table == BINARY) { + if (endIndex - startIndex < 8) { + end = true; + break; + } + code = readCode(correctedBits, startIndex, 8); + startIndex += 8; + + add(result, code); + } else { + int size = 5; + + if (table == DIGIT) { + size = 4; + } + + if (endIndex - startIndex < size) { + end = true; + break; + } + + code = readCode(correctedBits, startIndex, size); + startIndex += size; + + const char *str = getCharacter(table, code); + std::string string(str); + if ((int)string.find("CTRL_") != -1) { + table = getTable(str[5]); + + if (str[6] == 'S') { + shift = true; + if (str[5] == 'B') { + binaryShift = true; + } + } + } else { + result.append(string); + } + + } + } + + if (switchShift) { + table = lastTable; + shift = false; + switchShift = false; + } + + + } + + return Ref(new String(result)); + +} + +Ref Decoder::correctBits(Ref rawbits) { + //return rawbits; + // std::printf("decoding stuff:%d datablocks in %d layers\n", ddata_->getNBDatablocks(), ddata_->getNBLayers()); + + Ref gf = GenericGF::AZTEC_DATA_6; + + if (ddata_->getNBLayers() <= 2) { + codewordSize_ = 6; + gf = GenericGF::AZTEC_DATA_6; + } else if (ddata_->getNBLayers() <= 8) { + codewordSize_ = 8; + gf = GenericGF::AZTEC_DATA_8; + } else if (ddata_->getNBLayers() <= 22) { + codewordSize_ = 10; + gf = GenericGF::AZTEC_DATA_10; + } else { + codewordSize_ = 12; + gf = GenericGF::AZTEC_DATA_12; + } + + int numDataCodewords = ddata_->getNBDatablocks(); + int numECCodewords; + int offset; + + if (ddata_->isCompact()) { + offset = NB_BITS_COMPACT[ddata_->getNBLayers()] - numCodewords_ * codewordSize_; + numECCodewords = NB_DATABLOCK_COMPACT[ddata_->getNBLayers()] - numDataCodewords; + } else { + offset = NB_BITS[ddata_->getNBLayers()] - numCodewords_ * codewordSize_; + numECCodewords = NB_DATABLOCK[ddata_->getNBLayers()] - numDataCodewords; + } + + ArrayRef dataWords(numCodewords_); + + for (int i = 0; i < numCodewords_; i++) { + int flag = 1; + for (int j = 1; j <= codewordSize_; j++) { + if (rawbits->get(codewordSize_ * i + codewordSize_ - j + offset)) { + dataWords[i] += flag; + } + flag <<= 1; + } + + // + // + // + } + + try { + // std::printf("trying reed solomon, numECCodewords:%d\n", numECCodewords); + ReedSolomonDecoder rsDecoder(gf); + rsDecoder.decode(dataWords, numECCodewords); + } catch (ReedSolomonException& rse) { + // std::printf("got reed solomon exception:%s, throwing formatexception\n", rse.what()); + throw FormatException("rs decoding failed"); + } catch (IllegalArgumentException& iae) { + // std::printf("illegal argument exception: %s", iae.what()); + } + + offset = 0; + invertedBitCount_ = 0; + + Ref correctedBits(new BitArray(numDataCodewords * codewordSize_)); + for (int i = 0; i < numDataCodewords; i++) { + + bool seriesColor = false; + int seriesCount = 0; + int flag = 1 << (codewordSize_ - 1); + + for (int j = 0; j < codewordSize_; j++) { + + bool color = (dataWords[i] & flag) == flag; + + if (seriesCount == codewordSize_ - 1) { + + if (color == seriesColor) { + throw FormatException("bit was not inverted"); + } + + seriesColor = false; + seriesCount = 0; + offset++; + invertedBitCount_++; + + } else { + + if (seriesColor == color) { + seriesCount++; + } else { + seriesCount = 1; + seriesColor = color; + } + + if (color) correctedBits->set(i * codewordSize_ + j - offset); + + } + + flag = (unsigned int)flag >> 1; + + } + } + + return correctedBits; +} + +Ref Decoder::extractBits(Ref matrix) { + std::vector rawbits; + + if (ddata_->isCompact()) { + if (ddata_->getNBLayers() > 5) { //NB_BITS_COMPACT length + throw FormatException("data is too long"); + } + rawbits = std::vector(NB_BITS_COMPACT[ddata_->getNBLayers()]); + numCodewords_ = NB_DATABLOCK_COMPACT[ddata_->getNBLayers()]; + } else { + if (ddata_->getNBLayers() > 33) { //NB_BITS length + throw FormatException("data is too long"); + } + rawbits = std::vector(NB_BITS[ddata_->getNBLayers()]); + numCodewords_ = NB_DATABLOCK[ddata_->getNBLayers()]; + } + + int layer = ddata_->getNBLayers(); + int size = matrix->getHeight(); + int rawbitsOffset = 0; + int matrixOffset = 0; + + + while (layer != 0) { + + int flip = 0; + for (int i = 0; i < 2 * size - 4; i++) { + rawbits[rawbitsOffset + i] = matrix->get(matrixOffset + flip, matrixOffset + i / 2); + rawbits[rawbitsOffset + 2 * size - 4 + i] = matrix->get(matrixOffset + i / 2, matrixOffset + size - 1 - flip); + flip = (flip + 1) % 2; + } + + flip = 0; + for (int i = 2 * size + 1; i > 5; i--) { + rawbits[rawbitsOffset + 4 * size - 8 + (2 * size - i) + 1] = + matrix->get(matrixOffset + size - 1 - flip, matrixOffset + i / 2 - 1); + rawbits[rawbitsOffset + 6 * size - 12 + (2 * size - i) + 1] = + matrix->get(matrixOffset + i / 2 - 1, matrixOffset + flip); + flip = (flip + 1) % 2; + } + + matrixOffset += 2; + rawbitsOffset += 8 * size - 16; + layer--; + size -= 4; + + } + + Ref returnValue(new BitArray(rawbits.size())); + for (int i = 0; i < (int)rawbits.size(); i++) { + if (rawbits[i]) returnValue->set(i); + } + + return returnValue; + +} + +Ref Decoder::removeDashedLines(Ref matrix) { + int nbDashed = 1 + 2 * ((matrix->getWidth() - 1) / 2 / 16); + Ref newMatrix(new BitMatrix(matrix->getWidth() - nbDashed, matrix->getHeight() - nbDashed)); + + int nx = 0; + + for (int x = 0; x < (int)matrix->getWidth(); x++) { + + if ((matrix->getWidth() / 2 - x) % 16 == 0) { + continue; + } + + int ny = 0; + for (int y = 0; y < (int)matrix->getHeight(); y++) { + + if ((matrix->getWidth() / 2 - y) % 16 == 0) { + continue; + } + + if (matrix->get(x, y)) { + newMatrix->set(nx, ny); + } + ny++; + + } + nx++; + + } + return newMatrix; +} + +int Decoder::readCode(Ref rawbits, int startIndex, int length) { + int res = 0; + + for (int i = startIndex; i < startIndex + length; i++) { + res <<= 1; + if (rawbits->get(i)) { + res ++; + } + } + + return res; +} diff --git a/symbian/QZXing/source/zxing/aztec/decoder/Decoder.h b/symbian/QZXing/source/zxing/aztec/decoder/Decoder.h new file mode 100644 index 000000000..6e8a5d04f --- /dev/null +++ b/symbian/QZXing/source/zxing/aztec/decoder/Decoder.h @@ -0,0 +1,63 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Decoder.h + * zxing + * + * Created by Lukas Stabe on 08/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { + namespace aztec { + + class Decoder : public Counted { + private: + enum Table { + UPPER, + LOWER, + MIXED, + DIGIT, + PUNCT, + BINARY + }; + + static Table getTable(char t); + static const char* getCharacter(Table table, int code); + + int numCodewords_; + int codewordSize_; + Ref ddata_; + int invertedBitCount_; + + Ref getEncodedData(Ref correctedBits); + Ref correctBits(Ref rawbits); + Ref extractBits(Ref matrix); + static Ref removeDashedLines(Ref matrix); + static int readCode(Ref rawbits, int startIndex, int length); + + + public: + Decoder(); + Ref decode(Ref detectorResult); + }; + + } +} + diff --git a/symbian/QZXing/source/zxing/aztec/detector/AztecDetector.cpp b/symbian/QZXing/source/zxing/aztec/detector/AztecDetector.cpp new file mode 100644 index 000000000..f90372170 --- /dev/null +++ b/symbian/QZXing/source/zxing/aztec/detector/AztecDetector.cpp @@ -0,0 +1,541 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Detector.cpp + * zxing + * + * Created by Lukas Stabe on 08/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using zxing::aztec::Detector; +using zxing::aztec::Point; +using zxing::aztec::AztecDetectorResult; +using zxing::Ref; +using zxing::ResultPoint; +using zxing::BitArray; +using zxing::BitMatrix; + +Detector::Detector(Ref image): + image_(image), + nbLayers_(0), + nbDataBlocks_(0), + nbCenterLayers_(0) { + +} + +// using namespace std; + +Ref Detector::detect() { + Ref pCenter = getMatrixCenter(); + + std::vector > bullEyeCornerPoints = getBullEyeCornerPoints(pCenter); + + extractParameters(bullEyeCornerPoints); + + std::vector > corners = getMatrixCornerPoints(bullEyeCornerPoints); + + Ref bits = sampleGrid(image_, corners[shift_%4], corners[(shift_+3)%4], corners[(shift_+2)%4], corners[(shift_+1)%4]); + + // std::printf("------------\ndetected: compact:%s, nbDataBlocks:%d, nbLayers:%d\n------------\n",compact_?"YES":"NO", nbDataBlocks_, nbLayers_); + + return Ref(new AztecDetectorResult(bits, corners, compact_, nbDataBlocks_, nbLayers_)); +} + +void Detector::extractParameters(std::vector > bullEyeCornerPoints) { + // get the bits around the bull's eye + Ref resab = sampleLine(bullEyeCornerPoints[0], bullEyeCornerPoints[1], 2*nbCenterLayers_+1); + Ref resbc = sampleLine(bullEyeCornerPoints[1], bullEyeCornerPoints[2], 2*nbCenterLayers_+1); + Ref rescd = sampleLine(bullEyeCornerPoints[2], bullEyeCornerPoints[3], 2*nbCenterLayers_+1); + Ref resda = sampleLine(bullEyeCornerPoints[3], bullEyeCornerPoints[0], 2*nbCenterLayers_+1); + + // determin the orientation of the matrix + if (resab->get(0) && resab->get(2 * nbCenterLayers_)) { + shift_ = 0; + } else if (resbc->get(0) && resbc->get(2 * nbCenterLayers_)) { + shift_ = 1; + } else if (rescd->get(0) && rescd->get(2 * nbCenterLayers_)) { + shift_ = 2; + } else if (resda->get(0) && resda->get(2 * nbCenterLayers_)) { + shift_ = 3; + } else { + // std::printf("could not detemine orientation\n"); + throw ReaderException("could not determine orientation"); + } + + //d a + // + //c b + + //flatten the bits in a single array + Ref parameterData(new BitArray(compact_?28:40)); + Ref shiftedParameterData(new BitArray(compact_?28:40)); + + if (compact_) { + for (int i = 0; i < 7; i++) { + if (resab->get(2+i)) shiftedParameterData->set(i); + if (resbc->get(2+i)) shiftedParameterData->set(i+7); + if (rescd->get(2+i)) shiftedParameterData->set(i+14); + if (resda->get(2+i)) shiftedParameterData->set(i+21); + } + for (int i = 0; i < 28; i++) { + if (shiftedParameterData->get((i+shift_*7)%28)) parameterData->set(i); + } + + } else { + for (int i = 0; i < 11; i++) { + if (i < 5) { + if (resab->get(2+i)) shiftedParameterData->set(i); + if (resbc->get(2+i)) shiftedParameterData->set(i+10); + if (rescd->get(2+i)) shiftedParameterData->set(i+20); + if (resda->get(2+i)) shiftedParameterData->set(i+30); + } + if (i > 5) { + if (resab->get(2+i)) shiftedParameterData->set(i-1); + if (resbc->get(2+i)) shiftedParameterData->set(i+10-1); + if (rescd->get(2+i)) shiftedParameterData->set(i+20-1); + if (resda->get(2+i)) shiftedParameterData->set(i+30-1); + } + } + for (int i = 0; i < 40; i++) { + if (shiftedParameterData->get((i+shift_*10)%40)) parameterData->set(i); + } + } + + correctParameterData(parameterData, compact_); + + getParameters(parameterData); +} + +std::vector > Detector::getMatrixCornerPoints(std::vector > bullEyeCornerPoints) { + float ratio = (2 * nbLayers_ + (nbLayers_ > 4 ? 1 : 0) + (nbLayers_ - 4) / 8) / (2.0f * nbCenterLayers_); + + int dx = bullEyeCornerPoints[0]->x - bullEyeCornerPoints[2]->x; + dx += dx > 0 ? 1 : -1; + int dy = bullEyeCornerPoints[0]->y - bullEyeCornerPoints[2]->y; + dy += dy > 0 ? 1 : -1; + + int targetcx = ROUND(bullEyeCornerPoints[2]->x - ratio * dx); + int targetcy = ROUND(bullEyeCornerPoints[2]->y - ratio * dy); + + int targetax = ROUND(bullEyeCornerPoints[0]->x + ratio * dx); + int targetay = ROUND(bullEyeCornerPoints[0]->y + ratio * dy); + + dx = bullEyeCornerPoints[1]->x - bullEyeCornerPoints[3]->x; + dx += dx > 0 ? 1 : -1; + dy = bullEyeCornerPoints[1]->y - bullEyeCornerPoints[3]->y; + dy += dy > 0 ? 1 : -1; + + int targetdx = ROUND(bullEyeCornerPoints[3]->x - ratio * dx); + int targetdy = ROUND(bullEyeCornerPoints[3]->y - ratio * dy); + int targetbx = ROUND(bullEyeCornerPoints[1]->x + ratio * dx); + int targetby = ROUND(bullEyeCornerPoints[1]->y + ratio * dy); + + if (!isValid(targetax, targetay) || + !isValid(targetbx, targetby) || + !isValid(targetcx, targetcy) || + !isValid(targetdx, targetdy)) { + throw ReaderException("matrix extends over image bounds"); + } + std::vector > returnValue; + returnValue.push_back(Ref(new ResultPoint(targetax, targetay))); + returnValue.push_back(Ref(new ResultPoint(targetbx, targetby))); + returnValue.push_back(Ref(new ResultPoint(targetcx, targetcy))); + returnValue.push_back(Ref(new ResultPoint(targetdx, targetdy))); + + return returnValue; + +} + +void Detector::correctParameterData(Ref parameterData, bool compact) { + int numCodewords; + int numDataCodewords; + + if (compact) { + numCodewords = 7; + numDataCodewords = 2; + } else { + numCodewords = 10; + numDataCodewords = 4; + } + + int numECCodewords = numCodewords - numDataCodewords; + + ArrayRef parameterWords(new Array(numCodewords)); + + int codewordSize = 4; + for (int i = 0; i < numCodewords; i++) { + int flag = 1; + for (int j = 1; j <= codewordSize; j++) { + if (parameterData->get(codewordSize*i + codewordSize - j)) { + parameterWords[i] += flag; + } + flag <<= 1; + } + } + + try { + // std::printf("parameter data reed solomon\n"); + ReedSolomonDecoder rsDecoder(GenericGF::AZTEC_PARAM); + rsDecoder.decode(parameterWords, numECCodewords); + } catch (ReedSolomonException& e) { + // std::printf("reed solomon decoding failed\n"); + throw ReaderException("failed to decode parameter data"); + } + + parameterData->clear(); + for (int i = 0; i < numDataCodewords; i++) { + int flag = 1; + for (int j = 1; j <= codewordSize; j++) { + if ((parameterWords[i] & flag) == flag) { + parameterData->set(i*codewordSize+codewordSize-j); + } + flag <<= 1; + } + } +} + +std::vector > Detector::getBullEyeCornerPoints(Ref pCenter) { + Ref pina = pCenter; + Ref pinb = pCenter; + Ref pinc = pCenter; + Ref pind = pCenter; + + bool color = true; + + for (nbCenterLayers_ = 1; nbCenterLayers_ < 9; nbCenterLayers_++) { + Ref pouta = getFirstDifferent(pina, color, 1, -1); + Ref poutb = getFirstDifferent(pinb, color, 1, 1); + Ref poutc = getFirstDifferent(pinc, color, -1, 1); + Ref poutd = getFirstDifferent(pind, color, -1, -1); + + //d a + // + //c b + + if (nbCenterLayers_ > 2) { + float q = distance(poutd, pouta) * nbCenterLayers_ / (distance(pind, pina) * (nbCenterLayers_ + 2)); + if (q < 0.75 || q > 1.25 || !isWhiteOrBlackRectangle(pouta, poutb, poutc, poutd)) { + break; + } + } + + pina = pouta; + pinb = poutb; + pinc = poutc; + pind = poutd; + + color = !color; + } + + if (nbCenterLayers_ != 5 && nbCenterLayers_ != 7) { + throw ReaderException("encountered wrong bullseye ring count"); + } + + compact_ = nbCenterLayers_ == 5; + + + + float ratio = 0.75f*2 / (2*nbCenterLayers_-3); + + int dx = pina->x - pind->x; + int dy = pina->y - pinc->y; + + int targetcx = ROUND(pinc->x - ratio * dx); + int targetcy = ROUND(pinc->y - ratio * dy); + int targetax = ROUND(pina->x + ratio * dx); + int targetay = ROUND(pina->y + ratio * dy); + + dx = pinb->x - pind->x; + dy = pinb->y - pind->y; + + int targetdx = ROUND(pind->x - ratio * dx); + int targetdy = ROUND(pind->y - ratio * dy); + int targetbx = ROUND(pinb->x + ratio * dx); + int targetby = ROUND(pinb->y + ratio * dy); + + if (!isValid(targetax, targetay) || + !isValid(targetbx, targetby) || + !isValid(targetcx, targetcy) || + !isValid(targetdx, targetdy)) { + throw ReaderException("bullseye extends over image bounds"); + } + + std::vector > returnValue; + returnValue.push_back(Ref(new Point(targetax, targetay))); + returnValue.push_back(Ref(new Point(targetbx, targetby))); + returnValue.push_back(Ref(new Point(targetcx, targetcy))); + returnValue.push_back(Ref(new Point(targetdx, targetdy))); + + return returnValue; + +} + +Ref Detector::getMatrixCenter() { + Ref pointA, pointB, pointC, pointD; + try { + + std::vector > cornerPoints = WhiteRectangleDetector(image_).detect(); + pointA = cornerPoints[0]; + pointB = cornerPoints[1]; + pointC = cornerPoints[2]; + pointD = cornerPoints[3]; + + } catch (NotFoundException& e) { + + int cx = image_->getWidth() / 2; + int cy = image_->getHeight() / 2; + + pointA = getFirstDifferent(Ref(new Point(cx+15/2, cy-15/2)), false, 1, -1)->toResultPoint(); + pointB = getFirstDifferent(Ref(new Point(cx+15/2, cy+15/2)), false, 1, 1)->toResultPoint(); + pointC = getFirstDifferent(Ref(new Point(cx-15/2, cy+15/2)), false, -1, -1)->toResultPoint(); + pointD = getFirstDifferent(Ref(new Point(cx-15/2, cy-15/2)), false, -1, -1)->toResultPoint(); + + } + + int cx = ROUND((pointA->getX() + pointD->getX() + pointB->getX() + pointC->getX()) / 4); + int cy = ROUND((pointA->getY() + pointD->getY() + pointB->getY() + pointC->getY()) / 4); + + try { + + std::vector > cornerPoints = WhiteRectangleDetector(image_, 15, cx, cy).detect(); + pointA = cornerPoints[0]; + pointB = cornerPoints[1]; + pointC = cornerPoints[2]; + pointD = cornerPoints[3]; + + } catch (NotFoundException& e) { + + pointA = getFirstDifferent(Ref(new Point(cx+15/2, cy-15/2)), false, 1, -1)->toResultPoint(); + pointB = getFirstDifferent(Ref(new Point(cx+15/2, cy+15/2)), false, 1, 1)->toResultPoint(); + pointC = getFirstDifferent(Ref(new Point(cx-15/2, cy+15/2)), false, -1, -1)->toResultPoint(); + pointD = getFirstDifferent(Ref(new Point(cx-15/2, cy-15/2)), false, -1, -1)->toResultPoint(); + + } + + cx = ROUND((pointA->getX() + pointD->getX() + pointB->getX() + pointC->getX()) / 4); + cy = ROUND((pointA->getY() + pointD->getY() + pointB->getY() + pointC->getY()) / 4); + + return Ref(new Point(cx, cy)); + +} + +Ref Detector::sampleGrid(Ref image, + Ref topLeft, + Ref bottomLeft, + Ref bottomRight, + Ref topRight) { + int dimension; + if (compact_) { + dimension = 4 * nbLayers_+11; + } else { + if (nbLayers_ <= 4) { + dimension = 4 * nbLayers_ + 15; + } else { + dimension = 4 * nbLayers_ + 2 * ((nbLayers_-4)/8 + 1) + 15; + } + } + + GridSampler sampler = GridSampler::getInstance(); + + return sampler.sampleGrid(image, + dimension, + 0.5f, + 0.5f, + dimension - 0.5f, + 0.5f, + dimension - 0.5f, + dimension - 0.5f, + 0.5f, + dimension - 0.5f, + topLeft->getX(), + topLeft->getY(), + topRight->getX(), + topRight->getY(), + bottomRight->getX(), + bottomRight->getY(), + bottomLeft->getX(), + bottomLeft->getY()); +} + +void Detector::getParameters(Ref parameterData) { + nbLayers_ = 0; + nbDataBlocks_ = 0; + + int nbBitsForNbLayers; + int nbBitsForNbDatablocks; + + if (compact_) { + nbBitsForNbLayers = 2; + nbBitsForNbDatablocks = 6; + } else { + nbBitsForNbLayers = 5; + nbBitsForNbDatablocks = 11; + } + + for (int i = 0; i < nbBitsForNbLayers; i++) { + nbLayers_ <<= 1; + if (parameterData->get(i)) { + nbLayers_ += 1; + } + } + + for (int i = nbBitsForNbLayers; i < nbBitsForNbLayers + nbBitsForNbDatablocks; i++) { + nbDataBlocks_ <<= 1; + if (parameterData->get(i)) { + nbDataBlocks_ += 1; + } + } + + nbLayers_ ++; + nbDataBlocks_ ++; +} + +Ref Detector::sampleLine(Ref p1, Ref p2, int size) { + Ref res(new BitArray(size)); + + float d = distance(p1, p2); + float moduleSize = d / (size-1); + float dx = moduleSize * (p2->x - p1->x)/d; + float dy = moduleSize * (p2->y - p1->y)/d; + + float px = p1->x; + float py = p1->y; + + for (int i = 0; i < size; i++) { + if (image_->get(ROUND(px), ROUND(py))) res->set(i); + px += dx; + py += dy; + } + + return res; +} + +bool Detector::isWhiteOrBlackRectangle(Ref p1, + Ref p2, + Ref p3, + Ref p4) { + int corr = 3; + + p1 = new Point(p1->x - corr, p1->y + corr); + p2 = new Point(p2->x - corr, p2->y - corr); + p3 = new Point(p3->x + corr, p3->y - corr); + p4 = new Point(p4->x + corr, p4->y + corr); + + int cInit = getColor(p4, p1); + + if (cInit == 0) { + return false; + } + + int c = getColor(p1, p2); + + if (c != cInit) { + return false; + } + + c = getColor(p2, p3); + + if (c != cInit) { + return false; + } + + c = getColor(p3, p4); + + if (c != cInit) { + return false; + } + + return true; +} + +int Detector::getColor(Ref p1, Ref p2) { + float d = distance(p1, p2); + + float dx = (p2->x - p1->x) / d; + float dy = (p2->y - p1->y) / d; + + int error = 0; + + float px = p1->x; + float py = p1->y; + + bool colorModel = image_->get(p1->x, p1->y); + + for (int i = 0; i < d; i++) { + px += dx; + py += dy; + if (image_->get(ROUND(px), ROUND(py)) != colorModel) { + error ++; + } + } + + float errRatio = (float)error/d; + + + if (errRatio > 0.1 && errRatio < 0.9) { + return 0; + } + + if (errRatio <= 0.1) { + return colorModel?1:-1; + } else { + return colorModel?-1:1; + } +} + +Ref Detector::getFirstDifferent(Ref init, bool color, int dx, int dy) { + int x = init->x + dx; + int y = init->y + dy; + + while (isValid(x, y) && image_->get(x, y) == color) { + x += dx; + y += dy; + } + + x -= dx; + y -= dy; + + while (isValid(x, y) && image_->get(x, y) == color) { + x += dx; + } + + x -= dx; + + while (isValid(x, y) && image_->get(x, y) == color) { + y += dy; + } + + y -= dy; + + return Ref(new Point(x, y)); +} + +bool Detector::isValid(int x, int y) { + return x >= 0 && x < (int)image_->getWidth() && y > 0 && y < (int)image_->getHeight(); +} + +float Detector::distance(Ref a, Ref b) { + return sqrtf((float)((a->x - b->x) * (a->x - b->x) + (a->y - b->y) * (a->y - b->y))); +} diff --git a/symbian/QZXing/source/zxing/aztec/detector/Detector.h b/symbian/QZXing/source/zxing/aztec/detector/Detector.h new file mode 100644 index 000000000..072297183 --- /dev/null +++ b/symbian/QZXing/source/zxing/aztec/detector/Detector.h @@ -0,0 +1,87 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Detector.h + * zxing + * + * Created by Lukas Stabe on 08/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include +#include +#include +#include +#include + +#define ROUND(a) ((int)(a + 0.5f)) + +namespace zxing { + namespace aztec { + + class Point : public Counted { + public: + int x; + int y; + + Ref toResultPoint() { + return Ref(new ResultPoint(x, y)); + } + + Point(int ax, int ay):x(ax),y(ay) {}; + + }; + + class Detector : public Counted { + + private: + Ref image_; + + bool compact_; + int nbLayers_; + int nbDataBlocks_; + int nbCenterLayers_; + int shift_; + + void extractParameters(std::vector > bullEyeCornerPoints); + std::vector > getMatrixCornerPoints(std::vector > bullEyeCornerPoints); + static void correctParameterData(Ref parameterData, bool compact); + std::vector > getBullEyeCornerPoints(Ref pCenter); + Ref getMatrixCenter(); + Ref sampleGrid(Ref image, + Ref topLeft, + Ref bottomLeft, + Ref bottomRight, + Ref topRight); + void getParameters(Ref parameterData); + Ref sampleLine(Ref p1, Ref p2, int size); + bool isWhiteOrBlackRectangle(Ref p1, + Ref p2, + Ref p3, + Ref p4); + int getColor(Ref p1, Ref p2); + Ref getFirstDifferent(Ref init, bool color, int dx, int dy); + bool isValid(int x, int y); + static float distance(Ref a, Ref b); + + public: + Detector(Ref image); + Ref detect(); + }; + + } +} diff --git a/symbian/QZXing/source/zxing/common/Array.cpp b/symbian/QZXing/source/zxing/common/Array.cpp index aa1834a27..a9d19b305 100644 --- a/symbian/QZXing/source/zxing/common/Array.cpp +++ b/symbian/QZXing/source/zxing/common/Array.cpp @@ -1,22 +1,22 @@ -/* - * Array.cpp - * zxing - * - * Created by Christian Brunschen on 07/05/2008. - * Copyright 2008 Google UK. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - +/* + * Array.cpp + * zxing + * + * Created by Christian Brunschen on 07/05/2008. + * Copyright 2008 Google UK. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + diff --git a/symbian/QZXing/source/zxing/common/Array.h b/symbian/QZXing/source/zxing/common/Array.h index 9c676b4a1..d2c639175 100644 --- a/symbian/QZXing/source/zxing/common/Array.h +++ b/symbian/QZXing/source/zxing/common/Array.h @@ -1,208 +1,208 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __ARRAY_H__ -#define __ARRAY_H__ - -/* - * Array.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#ifdef DEBUG_COUNTING -#include -#include -#endif - -#include - - -namespace zxing { - -template class Array : public Counted { -protected: -public: - std::vector values_; - Array(size_t n) : - Counted(), values_(n, T()) { - } - Array(T *ts, size_t n) : - Counted(), values_(ts, ts+n) { - } - Array(T v, size_t n) : - Counted(), values_(n, v) { - } - Array(std::vector &v) : - Counted(), values_(v) { - } - Array(Array &other) : - Counted(), values_(other.values_) { - } - Array(Array *other) : - Counted(), values_(other->values_) { - } - virtual ~Array() { - } - Array& operator=(const Array &other) { -#ifdef DEBUG_COUNTING - cout << "assigning values from Array " << &other << " to this Array " << this << ", "; -#endif - values_ = other.values_; -#ifdef DEBUG_COUNTING - cout << "new size = " << values_.size() << "\n"; -#endif - return *this; - } - Array& operator=(const std::vector &array) { -#ifdef DEBUG_COUNTING - cout << "assigning values from Array " << &array << " to this Array " << this << ", "; -#endif - values_ = array; -#ifdef DEBUG_COUNTING - cout << "new size = " << values_.size() << "\n"; -#endif - return *this; - } - T operator[](size_t i) const { - return values_[i]; - } - T& operator[](size_t i) { - return values_[i]; - } - size_t size() const { - return values_.size(); - } - std::vector values() const { - return values_; - } - std::vector& values() { - return values_; - } -}; - -template class ArrayRef : public Counted { -private: -public: - Array *array_; - ArrayRef() : - array_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating empty ArrayRef " << this << "\n"; -#endif - } - ArrayRef(size_t n) : - array_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating ArrayRef " << this << "with size " << n << "\n"; -#endif - reset(new Array (n)); - } - ArrayRef(T *ts, size_t n) : - array_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating ArrayRef " << this << "with " << n << " elements at " << (void *)ts << "\n"; -#endif - reset(new Array (ts, n)); - } - ArrayRef(Array *a) : - array_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating ArrayRef " << this << " from pointer:\n"; -#endif - reset(a); - } - ArrayRef(const Array &a) : - array_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating ArrayRef " << this << " from reference to Array " << (void *)&a << ":\n"; -#endif - reset(const_cast *>(&a)); - } - ArrayRef(const ArrayRef &other) : - Counted(), array_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating ArrayRef " << this << " from ArrayRef " << &other << ":\n"; -#endif - reset(other.array_); - } - - template - ArrayRef(const ArrayRef &other) : - array_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating ArrayRef " << this << " from ArrayRef " << &other << ":\n"; -#endif - reset(static_cast *>(other.array_)); - } - - ~ArrayRef() { -#ifdef DEBUG_COUNTING - cout << "destroying ArrayRef " << this << " with " << (array_ ? typeid(*array_).name() : "NULL") << " " - << array_ << "\n"; -#endif - if (array_) { - array_->release(); - } - array_ = 0; - } - - T operator[](size_t i) const { - return (*array_)[i]; - } - T& operator[](size_t i) { - return (*array_)[i]; - } - size_t size() const { - return array_->size(); - } - - void reset(Array *a) { -#ifdef DEBUG_COUNTING - cout << "resetting ArrayRef " << this << " from " << (array_ ? typeid(*array_).name() : "NULL") << " " - << array_ << " to " << (a ? typeid(*a).name() : "NULL") << " " << a << "\n"; -#endif - if (a) { - a->retain(); - } - if (array_) { - array_->release(); - } - array_ = a; - } - void reset(const ArrayRef &other) { - reset(other.array_); - } - ArrayRef& operator=(const ArrayRef &other) { - reset(other); - return *this; - } - ArrayRef& operator=(Array *a) { - reset(a); - return *this; - } - - Array& operator*() { - return *array_; - } - Array* operator->() { - return array_; - } -}; - -} // namespace zxing - -#endif // __ARRAY_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __ARRAY_H__ +#define __ARRAY_H__ + +/* + * Array.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#ifdef DEBUG_COUNTING +#include +#include +#endif + +#include + + +namespace zxing { + +template class Array : public Counted { +protected: +public: + std::vector values_; + Array(size_t n) : + Counted(), values_(n, T()) { + } + Array(T *ts, size_t n) : + Counted(), values_(ts, ts+n) { + } + Array(T v, size_t n) : + Counted(), values_(n, v) { + } + Array(std::vector &v) : + Counted(), values_(v) { + } + Array(Array &other) : + Counted(), values_(other.values_) { + } + Array(Array *other) : + Counted(), values_(other->values_) { + } + virtual ~Array() { + } + Array& operator=(const Array &other) { +#ifdef DEBUG_COUNTING + cout << "assigning values from Array " << &other << " to this Array " << this << ", "; +#endif + values_ = other.values_; +#ifdef DEBUG_COUNTING + cout << "new size = " << values_.size() << "\n"; +#endif + return *this; + } + Array& operator=(const std::vector &array) { +#ifdef DEBUG_COUNTING + cout << "assigning values from Array " << &array << " to this Array " << this << ", "; +#endif + values_ = array; +#ifdef DEBUG_COUNTING + cout << "new size = " << values_.size() << "\n"; +#endif + return *this; + } + T operator[](size_t i) const { + return values_[i]; + } + T& operator[](size_t i) { + return values_[i]; + } + size_t size() const { + return values_.size(); + } + std::vector values() const { + return values_; + } + std::vector& values() { + return values_; + } +}; + +template class ArrayRef : public Counted { +private: +public: + Array *array_; + ArrayRef() : + array_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating empty ArrayRef " << this << "\n"; +#endif + } + ArrayRef(size_t n) : + array_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating ArrayRef " << this << "with size " << n << "\n"; +#endif + reset(new Array (n)); + } + ArrayRef(T *ts, size_t n) : + array_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating ArrayRef " << this << "with " << n << " elements at " << (void *)ts << "\n"; +#endif + reset(new Array (ts, n)); + } + ArrayRef(Array *a) : + array_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating ArrayRef " << this << " from pointer:\n"; +#endif + reset(a); + } + ArrayRef(const Array &a) : + array_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating ArrayRef " << this << " from reference to Array " << (void *)&a << ":\n"; +#endif + reset(const_cast *>(&a)); + } + ArrayRef(const ArrayRef &other) : + Counted(), array_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating ArrayRef " << this << " from ArrayRef " << &other << ":\n"; +#endif + reset(other.array_); + } + + template + ArrayRef(const ArrayRef &other) : + array_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating ArrayRef " << this << " from ArrayRef " << &other << ":\n"; +#endif + reset(static_cast *>(other.array_)); + } + + ~ArrayRef() { +#ifdef DEBUG_COUNTING + cout << "destroying ArrayRef " << this << " with " << (array_ ? typeid(*array_).name() : "NULL") << " " + << array_ << "\n"; +#endif + if (array_) { + array_->release(); + } + array_ = 0; + } + + T operator[](size_t i) const { + return (*array_)[i]; + } + T& operator[](size_t i) { + return (*array_)[i]; + } + size_t size() const { + return array_->size(); + } + + void reset(Array *a) { +#ifdef DEBUG_COUNTING + cout << "resetting ArrayRef " << this << " from " << (array_ ? typeid(*array_).name() : "NULL") << " " + << array_ << " to " << (a ? typeid(*a).name() : "NULL") << " " << a << "\n"; +#endif + if (a) { + a->retain(); + } + if (array_) { + array_->release(); + } + array_ = a; + } + void reset(const ArrayRef &other) { + reset(other.array_); + } + ArrayRef& operator=(const ArrayRef &other) { + reset(other); + return *this; + } + ArrayRef& operator=(Array *a) { + reset(a); + return *this; + } + + Array& operator*() { + return *array_; + } + Array* operator->() { + return array_; + } +}; + +} // namespace zxing + +#endif // __ARRAY_H__ diff --git a/symbian/QZXing/source/zxing/common/BitArray.cpp b/symbian/QZXing/source/zxing/common/BitArray.cpp index 92a19a82c..c1c9cae37 100644 --- a/symbian/QZXing/source/zxing/common/BitArray.cpp +++ b/symbian/QZXing/source/zxing/common/BitArray.cpp @@ -1,148 +1,127 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * BitArray.cpp - * zxing - * - * Copyright 2010 ZXing authors. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -using namespace std; - -namespace zxing { - -static unsigned int logDigits(unsigned digits) { - unsigned log = 0; - unsigned val = 1; - while (val < digits) { - log++; - val <<= 1; - } - return log; -} - -const unsigned int BitArray::bitsPerWord_ = numeric_limits::digits; -const unsigned int BitArray::logBits_ = logDigits(bitsPerWord_); -const unsigned int BitArray::bitsMask_ = (1 << logBits_) - 1; - -size_t BitArray::wordsForBits(size_t bits) { - int arraySize = bits >> logBits_; - if (bits - (arraySize << logBits_) != 0) { - arraySize++; - } - return arraySize; -} - -BitArray::BitArray(size_t size) : - size_(size), bits_(wordsForBits(size), (const unsigned int)0) { -} - -BitArray::~BitArray() { -} - -size_t BitArray::getSize() { - return size_; -} - -void BitArray::setBulk(size_t i, unsigned int newBits) { - bits_[i >> logBits_] = newBits; -} - -void BitArray::setRange(int start, int end) { - if (end < start) { - throw IllegalArgumentException("invalid call to BitArray::setRange"); - } - if (end == start) { - return; - } - end--; // will be easier to treat this as the last actually set bit -- inclusive - int firstInt = start >> 5; - int lastInt = end >> 5; - for (int i = firstInt; i <= lastInt; i++) { - int firstBit = i > firstInt ? 0 : start & 0x1F; - int lastBit = i < lastInt ? 31 : end & 0x1F; - int mask; - if (firstBit == 0 && lastBit == 31) { - mask = -1; - } else { - mask = 0; - for (int j = firstBit; j <= lastBit; j++) { - mask |= 1 << j; - } - } - bits_[i] |= mask; - } -} - -void BitArray::clear() { - size_t max = bits_.size(); - for (size_t i = 0; i < max; i++) { - bits_[i] = 0; - } -} - -bool BitArray::isRange(size_t start, size_t end, bool value) { - if (end < start) { - throw IllegalArgumentException("end must be after start"); - } - if (end == start) { - return true; - } - // treat the 'end' as inclusive, rather than exclusive - end--; - size_t firstWord = start >> logBits_; - size_t lastWord = end >> logBits_; - for (size_t i = firstWord; i <= lastWord; i++) { - size_t firstBit = i > firstWord ? 0 : start & bitsMask_; - size_t lastBit = i < lastWord ? bitsPerWord_ - 1: end & bitsMask_; - unsigned int mask; - if (firstBit == 0 && lastBit == bitsPerWord_ - 1) { - mask = numeric_limits::max(); - } else { - mask = 0; - for (size_t j = firstBit; j <= lastBit; j++) { - mask |= 1 << j; - } - } - if (value) { - if ((bits_[i] & mask) != mask) { - return false; - } - } else { - if ((bits_[i] & mask) != 0) { - return false; - } - } - } - return true; -} - -vector& BitArray::getBitArray() { - return bits_; -} - -void BitArray::reverse() { - std::vector newBits(bits_.size(),(const unsigned int) 0); - for (size_t i = 0; i < size_; i++) { - if (get(size_ - i - 1)) { - newBits[i >> logBits_] |= 1<< (i & bitsMask_); - } - } - bits_ = newBits; -} -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Copyright 2010 ZXing authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +using namespace std; + +namespace zxing { + + +size_t BitArray::wordsForBits(size_t bits) { + int arraySize = (bits + bitsPerWord_ - 1) >> logBits_; + return arraySize; +} + +BitArray::BitArray(size_t size) : + size_(size), bits_(wordsForBits(size), (const unsigned int)0) { +} + +BitArray::~BitArray() { +} + +size_t BitArray::getSize() { + return size_; +} + +void BitArray::setBulk(size_t i, unsigned int newBits) { + bits_[i >> logBits_] = newBits; +} + +void BitArray::setRange(int start, int end) { + if (end < start) { + throw IllegalArgumentException("invalid call to BitArray::setRange"); + } + if (end == start) { + return; + } + end--; // will be easier to treat this as the last actually set bit -- inclusive + int firstInt = start >> 5; + int lastInt = end >> 5; + for (int i = firstInt; i <= lastInt; i++) { + int firstBit = i > firstInt ? 0 : start & 0x1F; + int lastBit = i < lastInt ? 31 : end & 0x1F; + int mask; + if (firstBit == 0 && lastBit == 31) { + mask = -1; + } else { + mask = 0; + for (int j = firstBit; j <= lastBit; j++) { + mask |= 1 << j; + } + } + bits_[i] |= mask; + } +} + +void BitArray::clear() { + size_t max = bits_.size(); + for (size_t i = 0; i < max; i++) { + bits_[i] = 0; + } +} + +bool BitArray::isRange(size_t start, size_t end, bool value) { + if (end < start) { + throw IllegalArgumentException("end must be after start"); + } + if (end == start) { + return true; + } + // treat the 'end' as inclusive, rather than exclusive + end--; + size_t firstWord = start >> logBits_; + size_t lastWord = end >> logBits_; + for (size_t i = firstWord; i <= lastWord; i++) { + size_t firstBit = i > firstWord ? 0 : start & bitsMask_; + size_t lastBit = i < lastWord ? bitsPerWord_ - 1: end & bitsMask_; + unsigned int mask; + if (firstBit == 0 && lastBit == bitsPerWord_ - 1) { + mask = numeric_limits::max(); + } else { + mask = 0; + for (size_t j = firstBit; j <= lastBit; j++) { + mask |= 1 << j; + } + } + if (value) { + if ((bits_[i] & mask) != mask) { + return false; + } + } else { + if ((bits_[i] & mask) != 0) { + return false; + } + } + } + return true; +} + +vector& BitArray::getBitArray() { + return bits_; +} + +void BitArray::reverse() { + std::vector newBits(bits_.size(),(const unsigned int) 0); + for (size_t i = 0; i < size_; i++) { + if (get(size_ - i - 1)) { + newBits[i >> logBits_] |= 1<< (i & bitsMask_); + } + } + bits_ = newBits; +} +} diff --git a/symbian/QZXing/source/zxing/common/BitArray.h b/symbian/QZXing/source/zxing/common/BitArray.h index 437ae50c1..2db4e75b1 100644 --- a/symbian/QZXing/source/zxing/common/BitArray.h +++ b/symbian/QZXing/source/zxing/common/BitArray.h @@ -1,64 +1,70 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __BIT_ARRAY_H__ -#define __BIT_ARRAY_H__ - -/* - * BitArray.h - * zxing - * - * Copyright 2010 ZXing authors. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { - -class BitArray : public Counted { -private: - size_t size_; - std::vector bits_; - static const unsigned int bitsPerWord_; - static const unsigned int logBits_; - static const unsigned int bitsMask_; - static size_t wordsForBits(size_t bits); - explicit BitArray(); - -public: - BitArray(size_t size); - ~BitArray(); - size_t getSize(); - - bool get(size_t i) { - return (bits_[i >> logBits_] & (1 << (i & bitsMask_))) != 0; - } - - void set(size_t i) { - bits_[i >> logBits_] |= 1 << (i & bitsMask_); - } - - void setBulk(size_t i, unsigned int newBits); - void setRange(int start, int end); - void clear(); - bool isRange(size_t start, size_t end, bool value); - std::vector& getBitArray(); - void reverse(); -}; - -} - -#endif // __BIT_ARRAY_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __BIT_ARRAY_H__ +#define __BIT_ARRAY_H__ + +/* + * Copyright 2010 ZXing authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { + +#define ZX_LOG_DIGITS(digits) \ + ((digits == 8) ? 3 : \ + ((digits == 16) ? 4 : \ + ((digits == 32) ? 5 : \ + ((digits == 64) ? 6 : \ + ((digits == 128) ? 7 : \ + (-1)))))) + +class BitArray : public Counted { +private: + size_t size_; + std::vector bits_; + static const unsigned int bitsPerWord_ = + std::numeric_limits::digits; + static const unsigned int logBits_ = ZX_LOG_DIGITS(bitsPerWord_); + static const unsigned int bitsMask_ = (1 << logBits_) - 1; + static size_t wordsForBits(size_t bits); + explicit BitArray(); + +public: + BitArray(size_t size); + ~BitArray(); + size_t getSize(); + + bool get(size_t i) { + return (bits_[i >> logBits_] & (1 << (i & bitsMask_))) != 0; + } + + void set(size_t i) { + bits_[i >> logBits_] |= 1 << (i & bitsMask_); + } + + void setBulk(size_t i, unsigned int newBits); + void setRange(int start, int end); + void clear(); + bool isRange(size_t start, size_t end, bool value); + std::vector& getBitArray(); + void reverse(); +}; + +} + +#endif // __BIT_ARRAY_H__ diff --git a/symbian/QZXing/source/zxing/common/BitMatrix.cpp b/symbian/QZXing/source/zxing/common/BitMatrix.cpp index 643c7a2da..45106d94f 100644 --- a/symbian/QZXing/source/zxing/common/BitMatrix.cpp +++ b/symbian/QZXing/source/zxing/common/BitMatrix.cpp @@ -1,162 +1,157 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * BitMatrix.cpp - * zxing - * - * Copyright 2010 ZXing authors. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include -#include - -using std::ostream; -using std::ostringstream; - -using zxing::BitMatrix; -using zxing::BitArray; -using zxing::Ref; - -namespace { - size_t wordsForSize(size_t width, - size_t height, - unsigned int logBits) { - size_t bits = width * height; - int arraySize = bits >> logBits; - if (bits - (arraySize << logBits) != 0) { - arraySize++; - } - return arraySize; - } -} - -BitMatrix::BitMatrix(size_t dimension) : - width_(dimension), height_(dimension), words_(0), bits_(NULL) { - words_ = wordsForSize(width_, height_, logBits); - bits_ = new unsigned int[words_]; - clear(); -} - -BitMatrix::BitMatrix(size_t width, size_t height) : - width_(width), height_(height), words_(0), bits_(NULL) { - words_ = wordsForSize(width_, height_, logBits); - bits_ = new unsigned int[words_]; - clear(); -} - -BitMatrix::~BitMatrix() { - delete[] bits_; -} - - -void BitMatrix::flip(size_t x, size_t y) { - size_t offset = x + width_ * y; - bits_[offset >> logBits] ^= 1 << (offset & bitsMask); -} - -void BitMatrix::clear() { - std::fill(bits_, bits_+words_, 0); -} - -void BitMatrix::setRegion(size_t left, size_t top, size_t width, size_t height) { - if ((long)top < 0 || (long)left < 0) { - throw IllegalArgumentException("topI and leftJ must be nonnegative"); - } - if (height < 1 || width < 1) { - throw IllegalArgumentException("height and width must be at least 1"); - } - size_t right = left + width; - size_t bottom = top + height; - if (right > width_ || bottom > height_) { - throw IllegalArgumentException("top + height and left + width must be <= matrix dimension"); - } - for (size_t y = top; y < bottom; y++) { - int yOffset = width_ * y; - for (size_t x = left; x < right; x++) { - size_t offset = x + yOffset; - bits_[offset >> logBits] |= 1 << (offset & bitsMask); - } - } -} - -Ref BitMatrix::getRow(int y, Ref row) { - if (row.empty() || row->getSize() < width_) { - row = new BitArray(width_); - } else { - row->clear(); - } - size_t start = y * width_; - size_t end = start + width_ - 1; // end is inclusive - size_t firstWord = start >> logBits; - size_t lastWord = end >> logBits; - size_t bitOffset = start & bitsMask; - for (size_t i = firstWord; i <= lastWord; i++) { - size_t firstBit = i > firstWord ? 0 : start & bitsMask; - size_t lastBit = i < lastWord ? bitsPerWord - 1 : end & bitsMask; - unsigned int mask; - if (firstBit == 0 && lastBit == logBits) { - mask = std::numeric_limits::max(); - } else { - mask = 0; - for (size_t j = firstBit; j <= lastBit; j++) { - mask |= 1 << j; - } - } - row->setBulk((i - firstWord) << logBits, (bits_[i] & mask) >> bitOffset); - if (firstBit == 0 && bitOffset != 0) { - unsigned int prevBulk = row->getBitArray()[i - firstWord - 1]; - prevBulk |= (bits_[i] & mask) << (bitsPerWord - bitOffset); - row->setBulk((i - firstWord - 1) << logBits, prevBulk); - } - } - return row; -} - -size_t BitMatrix::getWidth() const { - return width_; -} - -size_t BitMatrix::getHeight() const { - return height_; -} - -size_t BitMatrix::getDimension() const { - return width_; -} - -unsigned int* BitMatrix::getBits() const { - return bits_; -} - -namespace zxing { - ostream& operator<<(ostream &out, const BitMatrix &bm) { - for (size_t y = 0; y < bm.height_; y++) { - for (size_t x = 0; x < bm.width_; x++) { - out << (bm.get(x, y) ? "X " : " "); - } - out << "\n"; - } - return out; - } -} - -const char* BitMatrix::description() { - ostringstream out; - out << *this; - return out.str().c_str(); -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Copyright 2010 ZXing authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include +#include + +using std::ostream; +using std::ostringstream; + +using zxing::BitMatrix; +using zxing::BitArray; +using zxing::Ref; + +namespace { + size_t wordsForSize(size_t width, + size_t height, + unsigned int bitsPerWord, + unsigned int logBits) { + size_t bits = width * height; + int arraySize = (bits + bitsPerWord - 1) >> logBits; + return arraySize; + } +} + +BitMatrix::BitMatrix(size_t dimension) : + width_(dimension), height_(dimension), words_(0), bits_(NULL) { + words_ = wordsForSize(width_, height_, bitsPerWord, logBits); + bits_ = new unsigned int[words_]; + clear(); +} + +BitMatrix::BitMatrix(size_t width, size_t height) : + width_(width), height_(height), words_(0), bits_(NULL) { + words_ = wordsForSize(width_, height_, bitsPerWord, logBits); + bits_ = new unsigned int[words_]; + clear(); +} + +BitMatrix::~BitMatrix() { + delete[] bits_; +} + + +void BitMatrix::flip(size_t x, size_t y) { + size_t offset = x + width_ * y; + bits_[offset >> logBits] ^= 1 << (offset & bitsMask); +} + +void BitMatrix::clear() { + std::fill(bits_, bits_+words_, 0); +} + +void BitMatrix::setRegion(size_t left, size_t top, size_t width, size_t height) { + if ((long)top < 0 || (long)left < 0) { + throw IllegalArgumentException("topI and leftJ must be nonnegative"); + } + if (height < 1 || width < 1) { + throw IllegalArgumentException("height and width must be at least 1"); + } + size_t right = left + width; + size_t bottom = top + height; + if (right > width_ || bottom > height_) { + throw IllegalArgumentException("top + height and left + width must be <= matrix dimension"); + } + for (size_t y = top; y < bottom; y++) { + int yOffset = width_ * y; + for (size_t x = left; x < right; x++) { + size_t offset = x + yOffset; + bits_[offset >> logBits] |= 1 << (offset & bitsMask); + } + } +} + +Ref BitMatrix::getRow(int y, Ref row) { + if (row.empty() || row->getSize() < width_) { + row = new BitArray(width_); + } else { + row->clear(); + } + size_t start = y * width_; + size_t end = start + width_ - 1; // end is inclusive + size_t firstWord = start >> logBits; + size_t lastWord = end >> logBits; + size_t bitOffset = start & bitsMask; + for (size_t i = firstWord; i <= lastWord; i++) { + size_t firstBit = i > firstWord ? 0 : start & bitsMask; + size_t lastBit = i < lastWord ? bitsPerWord - 1 : end & bitsMask; + unsigned int mask; + if (firstBit == 0 && lastBit == logBits) { + mask = std::numeric_limits::max(); + } else { + mask = 0; + for (size_t j = firstBit; j <= lastBit; j++) { + mask |= 1 << j; + } + } + row->setBulk((i - firstWord) << logBits, (bits_[i] & mask) >> bitOffset); + if (firstBit == 0 && bitOffset != 0) { + unsigned int prevBulk = row->getBitArray()[i - firstWord - 1]; + prevBulk |= (bits_[i] & mask) << (bitsPerWord - bitOffset); + row->setBulk((i - firstWord - 1) << logBits, prevBulk); + } + } + return row; +} + +size_t BitMatrix::getWidth() const { + return width_; +} + +size_t BitMatrix::getHeight() const { + return height_; +} + +size_t BitMatrix::getDimension() const { + return width_; +} + +unsigned int* BitMatrix::getBits() const { + return bits_; +} + +namespace zxing { + ostream& operator<<(ostream &out, const BitMatrix &bm) { + for (size_t y = 0; y < bm.height_; y++) { + for (size_t x = 0; x < bm.width_; x++) { + out << (bm.get(x, y) ? "X " : " "); + } + out << "\n"; + } + return out; + } +} + +const char* BitMatrix::description() { + ostringstream out; + out << *this; + return out.str().c_str(); +} diff --git a/symbian/QZXing/source/zxing/common/BitMatrix.h b/symbian/QZXing/source/zxing/common/BitMatrix.h index 2a78a5aad..e47ebf3b3 100644 --- a/symbian/QZXing/source/zxing/common/BitMatrix.h +++ b/symbian/QZXing/source/zxing/common/BitMatrix.h @@ -1,87 +1,87 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __BIT_MATRIX_H__ -#define __BIT_MATRIX_H__ - -/* - * BitMatrix.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { - -class BitMatrix : public Counted { -private: - size_t width_; - size_t height_; - size_t words_; - unsigned int* bits_; - -#define ZX_LOG_DIGITS(digits) \ - ((digits == 8) ? 3 : \ - ((digits == 16) ? 4 : \ - ((digits == 32) ? 5 : \ - ((digits == 64) ? 6 : \ - ((digits == 128) ? 7 : \ - (-1)))))) - - static const unsigned int bitsPerWord = - std::numeric_limits::digits; - static const unsigned int logBits = ZX_LOG_DIGITS(bitsPerWord); - static const unsigned int bitsMask = (1 << logBits) - 1; - -public: - BitMatrix(size_t dimension); - BitMatrix(size_t width, size_t height); - - ~BitMatrix(); - - bool get(size_t x, size_t y) const { - size_t offset = x + width_ * y; - return ((bits_[offset >> logBits] >> (offset & bitsMask)) & 0x01) != 0; - } - - void set(size_t x, size_t y) { - size_t offset = x + width_ * y; - bits_[offset >> logBits] |= 1 << (offset & bitsMask); - } - - void flip(size_t x, size_t y); - void clear(); - void setRegion(size_t left, size_t top, size_t width, size_t height); - Ref getRow(int y, Ref row); - - size_t getDimension() const; - size_t getWidth() const; - size_t getHeight() const; - - unsigned int* getBits() const; - - friend std::ostream& operator<<(std::ostream &out, const BitMatrix &bm); - const char *description(); - -private: - BitMatrix(const BitMatrix&); - BitMatrix& operator =(const BitMatrix&); -}; - -} - -#endif // __BIT_MATRIX_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __BIT_MATRIX_H__ +#define __BIT_MATRIX_H__ + +/* + * BitMatrix.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { + +class BitMatrix : public Counted { +private: + size_t width_; + size_t height_; + size_t words_; + unsigned int* bits_; + +#define ZX_LOG_DIGITS(digits) \ + ((digits == 8) ? 3 : \ + ((digits == 16) ? 4 : \ + ((digits == 32) ? 5 : \ + ((digits == 64) ? 6 : \ + ((digits == 128) ? 7 : \ + (-1)))))) + + static const unsigned int bitsPerWord = + std::numeric_limits::digits; + static const unsigned int logBits = ZX_LOG_DIGITS(bitsPerWord); + static const unsigned int bitsMask = (1 << logBits) - 1; + +public: + BitMatrix(size_t dimension); + BitMatrix(size_t width, size_t height); + + ~BitMatrix(); + + bool get(size_t x, size_t y) const { + size_t offset = x + width_ * y; + return ((bits_[offset >> logBits] >> (offset & bitsMask)) & 0x01) != 0; + } + + void set(size_t x, size_t y) { + size_t offset = x + width_ * y; + bits_[offset >> logBits] |= 1 << (offset & bitsMask); + } + + void flip(size_t x, size_t y); + void clear(); + void setRegion(size_t left, size_t top, size_t width, size_t height); + Ref getRow(int y, Ref row); + + size_t getDimension() const; + size_t getWidth() const; + size_t getHeight() const; + + unsigned int* getBits() const; + + friend std::ostream& operator<<(std::ostream &out, const BitMatrix &bm); + const char *description(); + +private: + BitMatrix(const BitMatrix&); + BitMatrix& operator =(const BitMatrix&); +}; + +} + +#endif // __BIT_MATRIX_H__ diff --git a/symbian/QZXing/source/zxing/common/BitSource.cpp b/symbian/QZXing/source/zxing/common/BitSource.cpp index d0ff48438..8a8d64b2f 100644 --- a/symbian/QZXing/source/zxing/common/BitSource.cpp +++ b/symbian/QZXing/source/zxing/common/BitSource.cpp @@ -1,74 +1,74 @@ -/* - * BitSource.cpp - * zxing - * - * Created by Christian Brunschen on 09/05/2008. - * Copyright 2008 Google UK. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - -int BitSource::readBits(int numBits) { - if (numBits < 0 || numBits > 32) { - throw IllegalArgumentException("cannot read <1 or >32 bits"); - } else if (numBits > available()) { - throw IllegalArgumentException("reading more bits than are available"); - } - - int result = 0; - - // First, read remainder from current byte - if (bitOffset_ > 0) { - int bitsLeft = 8 - bitOffset_; - int toRead = numBits < bitsLeft ? numBits : bitsLeft; - int bitsToNotRead = bitsLeft - toRead; - int mask = (0xFF >> (8 - toRead)) << bitsToNotRead; - result = (bytes_[byteOffset_] & mask) >> bitsToNotRead; - numBits -= toRead; - bitOffset_ += toRead; - if (bitOffset_ == 8) { - bitOffset_ = 0; - byteOffset_++; - } - } - - // Next read whole bytes - if (numBits > 0) { - while (numBits >= 8) { - result = (result << 8) | (bytes_[byteOffset_] & 0xFF); - byteOffset_++; - numBits -= 8; - } - - - // Finally read a partial byte - if (numBits > 0) { - int bitsToNotRead = 8 - numBits; - int mask = (0xFF >> bitsToNotRead) << bitsToNotRead; - result = (result << numBits) | ((bytes_[byteOffset_] & mask) >> bitsToNotRead); - bitOffset_ += numBits; - } - } - - return result; -} - -int BitSource::available() { - return 8 * (bytes_.size() - byteOffset_) - bitOffset_; -} -} +/* + * BitSource.cpp + * zxing + * + * Created by Christian Brunschen on 09/05/2008. + * Copyright 2008 Google UK. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + +int BitSource::readBits(int numBits) { + if (numBits < 0 || numBits > 32) { + throw IllegalArgumentException("cannot read <1 or >32 bits"); + } else if (numBits > available()) { + throw IllegalArgumentException("reading more bits than are available"); + } + + int result = 0; + + // First, read remainder from current byte + if (bitOffset_ > 0) { + int bitsLeft = 8 - bitOffset_; + int toRead = numBits < bitsLeft ? numBits : bitsLeft; + int bitsToNotRead = bitsLeft - toRead; + int mask = (0xFF >> (8 - toRead)) << bitsToNotRead; + result = (bytes_[byteOffset_] & mask) >> bitsToNotRead; + numBits -= toRead; + bitOffset_ += toRead; + if (bitOffset_ == 8) { + bitOffset_ = 0; + byteOffset_++; + } + } + + // Next read whole bytes + if (numBits > 0) { + while (numBits >= 8) { + result = (result << 8) | (bytes_[byteOffset_] & 0xFF); + byteOffset_++; + numBits -= 8; + } + + + // Finally read a partial byte + if (numBits > 0) { + int bitsToNotRead = 8 - numBits; + int mask = (0xFF >> bitsToNotRead) << bitsToNotRead; + result = (result << numBits) | ((bytes_[byteOffset_] & mask) >> bitsToNotRead); + bitOffset_ += numBits; + } + } + + return result; +} + +int BitSource::available() { + return 8 * (bytes_.size() - byteOffset_) - bitOffset_; +} +} diff --git a/symbian/QZXing/source/zxing/common/BitSource.h b/symbian/QZXing/source/zxing/common/BitSource.h index 4a7dfd599..0b077c3d7 100644 --- a/symbian/QZXing/source/zxing/common/BitSource.h +++ b/symbian/QZXing/source/zxing/common/BitSource.h @@ -1,70 +1,70 @@ -#ifndef __BIT_SOURCE_H__ -#define __BIT_SOURCE_H__ - -/* - * BitSource.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { -/** - *

This provides an easy abstraction to read bits at a time from a sequence of bytes, where the - * number of bits read is not often a multiple of 8.

- * - *

This class is not thread-safe.

- * - * @author srowen@google.com (Sean Owen) - * @author christian.brunschen@gmail.com (Christian Brunschen) - */ -class BitSource : public Counted { - typedef unsigned char byte; -private: - ArrayRef bytes_; - int byteOffset_; - int bitOffset_; -public: - /** - * @param bytes bytes from which this will read bits. Bits will be read from the first byte first. - * Bits are read within a byte from most-significant to least-significant bit. - */ - BitSource(ArrayRef &bytes) : - bytes_(bytes), byteOffset_(0), bitOffset_(0) { - } - - int getByteOffset() { - return byteOffset_; - } - - /** - * @param numBits number of bits to read - * @return int representing the bits read. The bits will appear as the least-significant - * bits of the int - * @throws IllegalArgumentException if numBits isn't in [1,32] - */ - int readBits(int numBits); - - /** - * @return number of bits that can be read successfully - */ - int available(); -}; - -} - -#endif // __BIT_SOURCE_H__ +#ifndef __BIT_SOURCE_H__ +#define __BIT_SOURCE_H__ + +/* + * BitSource.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { +/** + *

This provides an easy abstraction to read bits at a time from a sequence of bytes, where the + * number of bits read is not often a multiple of 8.

+ * + *

This class is not thread-safe.

+ * + * @author srowen@google.com (Sean Owen) + * @author christian.brunschen@gmail.com (Christian Brunschen) + */ +class BitSource : public Counted { + typedef unsigned char byte; +private: + ArrayRef bytes_; + int byteOffset_; + int bitOffset_; +public: + /** + * @param bytes bytes from which this will read bits. Bits will be read from the first byte first. + * Bits are read within a byte from most-significant to least-significant bit. + */ + BitSource(ArrayRef &bytes) : + bytes_(bytes), byteOffset_(0), bitOffset_(0) { + } + + int getByteOffset() { + return byteOffset_; + } + + /** + * @param numBits number of bits to read + * @return int representing the bits read. The bits will appear as the least-significant + * bits of the int + * @throws IllegalArgumentException if numBits isn't in [1,32] + */ + int readBits(int numBits); + + /** + * @return number of bits that can be read successfully + */ + int available(); +}; + +} + +#endif // __BIT_SOURCE_H__ diff --git a/symbian/QZXing/source/zxing/common/CharacterSetECI.cpp b/symbian/QZXing/source/zxing/common/CharacterSetECI.cpp index 534138cac..54d1479fc 100644 --- a/symbian/QZXing/source/zxing/common/CharacterSetECI.cpp +++ b/symbian/QZXing/source/zxing/common/CharacterSetECI.cpp @@ -1,87 +1,104 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2008-2011 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -using std::string; - -using zxing::common::CharacterSetECI; -using zxing::IllegalArgumentException; - -std::map CharacterSetECI::VALUE_TO_ECI; -std::map CharacterSetECI::NAME_TO_ECI; - -const bool CharacterSetECI::inited = CharacterSetECI::init_tables(); - -bool CharacterSetECI::init_tables() { - addCharacterSet(0, "Cp437"); - { char const* s[] = {"ISO8859_1", "ISO-8859-1", 0}; - addCharacterSet(1, s); } - addCharacterSet(2, "Cp437"); - { char const* s[] = {"ISO8859_1", "ISO-8859-1", 0}; - addCharacterSet(3, s); } - addCharacterSet(4, "ISO8859_2"); - addCharacterSet(5, "ISO8859_3"); - addCharacterSet(6, "ISO8859_4"); - addCharacterSet(7, "ISO8859_5"); - addCharacterSet(8, "ISO8859_6"); - addCharacterSet(9, "ISO8859_7"); - addCharacterSet(10, "ISO8859_8"); - addCharacterSet(11, "ISO8859_9"); - addCharacterSet(12, "ISO8859_10"); - addCharacterSet(13, "ISO8859_11"); - addCharacterSet(15, "ISO8859_13"); - addCharacterSet(16, "ISO8859_14"); - addCharacterSet(17, "ISO8859_15"); - addCharacterSet(18, "ISO8859_16"); - { char const* s[] = {"SJIS", "Shift_JIS", 0}; - addCharacterSet(20, s ); } - return true; -} - -CharacterSetECI::CharacterSetECI(int value, char const* encodingName_) - : ECI(value), encodingName(encodingName_) {} - -char const* CharacterSetECI::getEncodingName() { - return encodingName; -} - -void CharacterSetECI::addCharacterSet(int value, char const* encodingName) { - CharacterSetECI* eci = new CharacterSetECI(value, encodingName); - VALUE_TO_ECI[value] = eci; // can't use valueOf - NAME_TO_ECI[string(encodingName)] = eci; -} - -void CharacterSetECI::addCharacterSet(int value, char const* const* encodingNames) { - CharacterSetECI* eci = new CharacterSetECI(value, encodingNames[0]); - VALUE_TO_ECI[value] = eci; - for (int i = 0; encodingNames[i]; i++) { - NAME_TO_ECI[string(encodingNames[i])] = eci; - } -} - -CharacterSetECI* CharacterSetECI::getCharacterSetECIByValue(int value) { - if (value < 0 || value >= 900) { - throw IllegalArgumentException("Bad ECI value: " + value); - } - return VALUE_TO_ECI[value]; -} - -CharacterSetECI* CharacterSetECI::getCharacterSetECIByName(string const& name) { - return NAME_TO_ECI[name]; -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Copyright 2008-2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +using std::string; + +using zxing::common::CharacterSetECI; +using zxing::IllegalArgumentException; + +std::map CharacterSetECI::VALUE_TO_ECI; +std::map CharacterSetECI::NAME_TO_ECI; + +const bool CharacterSetECI::inited = CharacterSetECI::init_tables(); + +#define ADD_CHARACTER_SET(VALUES, STRINGS) \ + { static int values[] = {VALUES, -1}; \ + static char const* strings[] = {STRINGS, 0}; \ + addCharacterSet(values, strings); } + +#define XC , + +bool CharacterSetECI::init_tables() { + ADD_CHARACTER_SET(0 XC 2, "Cp437"); + ADD_CHARACTER_SET(1 XC 3, "ISO8859_1" XC "ISO-8859-1"); + ADD_CHARACTER_SET(4, "ISO8859_2" XC "ISO-8859-2"); + ADD_CHARACTER_SET(5, "ISO8859_3" XC "ISO-8859-3"); + ADD_CHARACTER_SET(6, "ISO8859_4" XC "ISO-8859-4"); + ADD_CHARACTER_SET(7, "ISO8859_5" XC "ISO-8859-5"); + ADD_CHARACTER_SET(8, "ISO8859_6" XC "ISO-8859-6"); + ADD_CHARACTER_SET(9, "ISO8859_7" XC "ISO-8859-7"); + ADD_CHARACTER_SET(10, "ISO8859_8" XC "ISO-8859-8"); + ADD_CHARACTER_SET(11, "ISO8859_9" XC "ISO-8859-9"); + ADD_CHARACTER_SET(12, "ISO8859_10" XC "ISO-8859-10"); + ADD_CHARACTER_SET(13, "ISO8859_11" XC "ISO-8859-11"); + ADD_CHARACTER_SET(15, "ISO8859_13" XC "ISO-8859-13"); + ADD_CHARACTER_SET(16, "ISO8859_14" XC "ISO-8859-14"); + ADD_CHARACTER_SET(17, "ISO8859_15" XC "ISO-8859-15"); + ADD_CHARACTER_SET(18, "ISO8859_16" XC "ISO-8859-16"); + ADD_CHARACTER_SET(20, "SJIS" XC "Shift_JIS"); + ADD_CHARACTER_SET(21, "Cp1250" XC "windows-1250"); + ADD_CHARACTER_SET(22, "Cp1251" XC "windows-1251"); + ADD_CHARACTER_SET(23, "Cp1252" XC "windows-1252"); + ADD_CHARACTER_SET(24, "Cp1256" XC "windows-1256"); + ADD_CHARACTER_SET(25, "UnicodeBigUnmarked" XC "UTF-16BE" XC "UnicodeBig"); + ADD_CHARACTER_SET(26, "UTF8" XC "UTF-8"); + ADD_CHARACTER_SET(27 XC 170, "ASCII" XC "US-ASCII"); + ADD_CHARACTER_SET(28, "Big5"); + ADD_CHARACTER_SET(29, "GB18030" XC "GB2312" XC "EUC_CN" XC "GBK"); + ADD_CHARACTER_SET(30, "EUC_KR" XC "EUC-KR"); + return true; +} + +#undef XC + +CharacterSetECI::CharacterSetECI(int const* values, + char const* const* names) + : values_(values), names_(names) { + for(int const* values = values_; *values != -1; values++) { + VALUE_TO_ECI[*values] = this; + } + for(char const* const* names = names_; *names; names++) { + NAME_TO_ECI[string(*names)] = this; + } +} + +char const* CharacterSetECI::name() const { + return names_[0]; +} + +int CharacterSetECI::getValue() const { + return values_[0]; +} + +void CharacterSetECI::addCharacterSet(int const* values, char const* const* names) { + new CharacterSetECI(values, names); +} + +CharacterSetECI* CharacterSetECI::getCharacterSetECIByValue(int value) { + if (value < 0 || value >= 900) { + throw FormatException(); + } + return VALUE_TO_ECI[value]; +} + +CharacterSetECI* CharacterSetECI::getCharacterSetECIByName(string const& name) { + return NAME_TO_ECI[name]; +} diff --git a/symbian/QZXing/source/zxing/common/CharacterSetECI.h b/symbian/QZXing/source/zxing/common/CharacterSetECI.h index 59dd41309..3cabe603e 100644 --- a/symbian/QZXing/source/zxing/common/CharacterSetECI.h +++ b/symbian/QZXing/source/zxing/common/CharacterSetECI.h @@ -1,53 +1,53 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- - -#ifndef __CHARACTERSET_ECI__ -#define __CHARACTERSET_ECI__ - -/* - * Copyright 2008-2011 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { - namespace common { - class CharacterSetECI; - } -} - -class zxing::common::CharacterSetECI : public ECI { -private: - static std::map VALUE_TO_ECI; - static std::map NAME_TO_ECI; - static const bool inited; - static bool init_tables(); - - char const* const encodingName; - - CharacterSetECI(int value, char const* encodingName); - - static void addCharacterSet(int value, char const* encodingName); - static void addCharacterSet(int value, char const* const* encodingNames); - -public: - char const* getEncodingName(); - - static CharacterSetECI* getCharacterSetECIByValue(int value); - static CharacterSetECI* getCharacterSetECIByName(std::string const& name); -}; - -#endif +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- + +#ifndef __CHARACTERSET_ECI__ +#define __CHARACTERSET_ECI__ + +/* + * Copyright 2008-2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + namespace common { + class CharacterSetECI; + } +} + +class zxing::common::CharacterSetECI { +private: + static std::map VALUE_TO_ECI; + static std::map NAME_TO_ECI; + static const bool inited; + static bool init_tables(); + + int const* const values_; + char const* const* const names_; + + CharacterSetECI(int const* values, char const* const* names); + + static void addCharacterSet(int const* value, char const* const* encodingNames); + +public: + char const* name() const; + int getValue() const; + + static CharacterSetECI* getCharacterSetECIByValue(int value); + static CharacterSetECI* getCharacterSetECIByName(std::string const& name); +}; + +#endif diff --git a/symbian/QZXing/source/zxing/common/Counted.cpp b/symbian/QZXing/source/zxing/common/Counted.cpp index fb2a99b06..61747a286 100644 --- a/symbian/QZXing/source/zxing/common/Counted.cpp +++ b/symbian/QZXing/source/zxing/common/Counted.cpp @@ -1,32 +1,32 @@ -/* - * Counted.cpp - * zxing - * - * Created by Christian Brunschen on 07/05/2008. - * Copyright 2008 Google UK. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -using namespace std; - -template -ostream& operator<<(ostream &out, Ref& ref) { - out << "Ref(" << (ref.object_ ? (*ref.object_) : "NULL") << ")"; - return out; -} -} +/* + * Counted.cpp + * zxing + * + * Created by Christian Brunschen on 07/05/2008. + * Copyright 2008 Google UK. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +using namespace std; + +template +ostream& operator<<(ostream &out, Ref& ref) { + out << "Ref(" << (ref.object_ ? (*ref.object_) : "NULL") << ")"; + return out; +} +} diff --git a/symbian/QZXing/source/zxing/common/Counted.h b/symbian/QZXing/source/zxing/common/Counted.h index dad79e3ad..81827a10b 100644 --- a/symbian/QZXing/source/zxing/common/Counted.h +++ b/symbian/QZXing/source/zxing/common/Counted.h @@ -1,204 +1,202 @@ -#ifndef __COUNTED_H__ -#define __COUNTED_H__ - -/* - * Counted.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//#define DEBUG_COUNTING - -#include - -#ifdef DEBUG_COUNTING -#include -#endif - -namespace zxing { - -/* base class for reference-counted objects */ -class Counted { -private: - unsigned int count_; -public: - Counted() : - count_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating " << typeid(*this).name() << " " << this << - " @ " << count_ << "\n"; -#endif - } - virtual ~Counted() { - } - Counted *retain() { -#ifdef DEBUG_COUNTING - cout << "retaining " << typeid(*this).name() << " " << this << - " @ " << count_; -#endif - count_++; -#ifdef DEBUG_COUNTING - cout << "->" << count_ << "\n"; -#endif - return this; - } - void release() { -#ifdef DEBUG_COUNTING - cout << "releasing " << typeid(*this).name() << " " << this << - " @ " << count_; -#endif - if (count_ == 0 || count_ == 54321) { -#ifdef DEBUG_COUNTING - cout << "\nOverreleasing already-deleted object " << this << "!!!\n"; -#endif - throw 4711; - } - count_--; -#ifdef DEBUG_COUNTING - cout << "->" << count_ << "\n"; -#endif - if (count_ == 0) { -#ifdef DEBUG_COUNTING - cout << "deleting " << typeid(*this).name() << " " << this << "\n"; -#endif - count_ = 0xDEADF001; - delete this; - } - } - - - /* return the current count for denugging purposes or similar */ - int count() const { - return count_; - } -}; - -/* counting reference to reference-counted objects */ -template class Ref { -private: -public: - T *object_; - explicit Ref(T *o = 0) : - object_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating Ref " << this << " from pointer" << o << "\n"; -#endif - reset(o); - } - - explicit Ref(const T &o) : - object_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating Ref " << this << " from reference\n"; -#endif - reset(const_cast(&o)); - } - - Ref(const Ref &other) : - object_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating Ref " << this << " from Ref " << &other << "\n"; -#endif - reset(other.object_); - } - - template - Ref(const Ref &other) : - object_(0) { -#ifdef DEBUG_COUNTING - cout << "instantiating Ref " << this << " from reference\n"; -#endif - reset(other.object_); - } - - ~Ref() { -#ifdef DEBUG_COUNTING - cout << "destroying Ref " << this << " with " << - (object_ ? typeid(*object_).name() : "NULL") << " " << object_ << "\n"; -#endif - if (object_) { - object_->release(); - } - } - - void reset(T *o) { -#ifdef DEBUG_COUNTING - cout << "resetting Ref " << this << " from " << - (object_ ? typeid(*object_).name() : "NULL") << " " << object_ << - " to " << (o ? typeid(*o).name() : "NULL") << " " << o << "\n"; -#endif - if (o) { - o->retain(); - } - if (object_ != 0) { - object_->release(); - } - object_ = o; - } - Ref& operator=(const Ref &other) { - reset(other.object_); - return *this; - } - template - Ref& operator=(const Ref &other) { - reset(other.object_); - return *this; - } - Ref& operator=(T* o) { - reset(o); - return *this; - } - template - Ref& operator=(Y* o) { - reset(o); - return *this; - } - - T& operator*() { - return *object_; - } - T* operator->() const { - return object_; - } - operator T*() const { - return object_; - } - - bool operator==(const int x) { - return x == 0 ? object_ == 0 : false; - } - bool operator==(const Ref &other) const { - return object_ == other.object_ || *object_ == *(other.object_); - } - template - bool operator==(const Ref &other) const { - return object_ == other.object_ || *object_ == *(other.object_); - } - - bool operator!=(const int x) { - return x == 0 ? object_ != 0 : true; - } - - bool empty() const { - return object_ == 0; - } - - template - friend std::ostream& operator<<(std::ostream &out, Ref& ref); -}; -} - -#endif // __COUNTED_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __COUNTED_H__ +#define __COUNTED_H__ + +/* + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//#define DEBUG_COUNTING + +#include + +#ifdef DEBUG_COUNTING +#include +#endif + +namespace zxing { + +/* base class for reference-counted objects */ +class Counted { +private: + unsigned int count_; +public: + Counted() : + count_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating " << typeid(*this).name() << " " << this << + " @ " << count_ << "\n"; +#endif + } + virtual ~Counted() { + } + Counted *retain() { +#ifdef DEBUG_COUNTING + cout << "retaining " << typeid(*this).name() << " " << this << + " @ " << count_; +#endif + count_++; +#ifdef DEBUG_COUNTING + cout << "->" << count_ << "\n"; +#endif + return this; + } + void release() { +#ifdef DEBUG_COUNTING + cout << "releasing " << typeid(*this).name() << " " << this << + " @ " << count_; +#endif + if (count_ == 0 || count_ == 54321) { +#ifdef DEBUG_COUNTING + cout << "\nOverreleasing already-deleted object " << this << "!!!\n"; +#endif + throw 4711; + } + count_--; +#ifdef DEBUG_COUNTING + cout << "->" << count_ << "\n"; +#endif + if (count_ == 0) { +#ifdef DEBUG_COUNTING + cout << "deleting " << typeid(*this).name() << " " << this << "\n"; +#endif + count_ = 0xDEADF001; + delete this; + } + } + + + /* return the current count for denugging purposes or similar */ + int count() const { + return count_; + } +}; + +/* counting reference to reference-counted objects */ +template class Ref { +private: +public: + T *object_; + explicit Ref(T *o = 0) : + object_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating Ref " << this << " from pointer" << o << "\n"; +#endif + reset(o); + } + + explicit Ref(const T &o) : + object_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating Ref " << this << " from reference\n"; +#endif + reset(const_cast(&o)); + } + + Ref(const Ref &other) : + object_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating Ref " << this << " from Ref " << &other << "\n"; +#endif + reset(other.object_); + } + + template + Ref(const Ref &other) : + object_(0) { +#ifdef DEBUG_COUNTING + cout << "instantiating Ref " << this << " from reference\n"; +#endif + reset(other.object_); + } + + ~Ref() { +#ifdef DEBUG_COUNTING + cout << "destroying Ref " << this << " with " << + (object_ ? typeid(*object_).name() : "NULL") << " " << object_ << "\n"; +#endif + if (object_) { + object_->release(); + } + } + + void reset(T *o) { +#ifdef DEBUG_COUNTING + cout << "resetting Ref " << this << " from " << + (object_ ? typeid(*object_).name() : "NULL") << " " << object_ << + " to " << (o ? typeid(*o).name() : "NULL") << " " << o << "\n"; +#endif + if (o) { + o->retain(); + } + if (object_ != 0) { + object_->release(); + } + object_ = o; + } + Ref& operator=(const Ref &other) { + reset(other.object_); + return *this; + } + template + Ref& operator=(const Ref &other) { + reset(other.object_); + return *this; + } + Ref& operator=(T* o) { + reset(o); + return *this; + } + template + Ref& operator=(Y* o) { + reset(o); + return *this; + } + + T& operator*() { + return *object_; + } + T* operator->() const { + return object_; + } + operator T*() const { + return object_; + } + + bool operator==(const T* that) { + return object_ == that; + } + bool operator==(const Ref &other) const { + return object_ == other.object_ || *object_ == *(other.object_); + } + template + bool operator==(const Ref &other) const { + return object_ == other.object_ || *object_ == *(other.object_); + } + + bool operator!=(const T* that) { + return !(*this == that); + } + + bool empty() const { + return object_ == 0; + } + + template + friend std::ostream& operator<<(std::ostream &out, Ref& ref); +}; +} + +#endif // __COUNTED_H__ diff --git a/symbian/QZXing/source/zxing/common/DecoderResult.h b/symbian/QZXing/source/zxing/common/DecoderResult.h index d26caa3aa..5cb8193e1 100644 --- a/symbian/QZXing/source/zxing/common/DecoderResult.h +++ b/symbian/QZXing/source/zxing/common/DecoderResult.h @@ -1,51 +1,51 @@ -#ifndef __DECODER_RESULT_H__ -#define __DECODER_RESULT_H__ - -/* - * DecoderResult.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { - -class DecoderResult : public Counted { -private: - ArrayRef rawBytes_; - Ref text_; - ArrayRef< ArrayRef > byteSegments_; - std::string ecLevel_; - -public: - DecoderResult(ArrayRef rawBytes, - Ref text, - ArrayRef< ArrayRef >& byteSegments, - std::string const& ecLevel); - - DecoderResult(ArrayRef rawBytes, Ref text); - - ArrayRef getRawBytes(); - Ref getText(); -}; - -} - -#endif // __DECODER_RESULT_H__ +#ifndef __DECODER_RESULT_H__ +#define __DECODER_RESULT_H__ + +/* + * DecoderResult.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { + +class DecoderResult : public Counted { +private: + ArrayRef rawBytes_; + Ref text_; + ArrayRef< ArrayRef > byteSegments_; + std::string ecLevel_; + +public: + DecoderResult(ArrayRef rawBytes, + Ref text, + ArrayRef< ArrayRef >& byteSegments, + std::string const& ecLevel); + + DecoderResult(ArrayRef rawBytes, Ref text); + + ArrayRef getRawBytes(); + Ref getText(); +}; + +} + +#endif // __DECODER_RESULT_H__ diff --git a/symbian/QZXing/source/zxing/common/DetectorResult.cpp b/symbian/QZXing/source/zxing/common/DetectorResult.cpp index 0769137de..cf68a9808 100644 --- a/symbian/QZXing/source/zxing/common/DetectorResult.cpp +++ b/symbian/QZXing/source/zxing/common/DetectorResult.cpp @@ -1,42 +1,38 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * DetectorResult.cpp - * zxing - * - * Created by Christian Brunschen on 14/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -DetectorResult::DetectorResult(Ref bits, std::vector > points, Ref transform) : - bits_(bits), points_(points), transform_(transform) { -} - -Ref DetectorResult::getBits() { - return bits_; -} - -std::vector > DetectorResult::getPoints() { - return points_; -} - -Ref DetectorResult::getTransform() { - return transform_; -} - -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * DetectorResult.cpp + * zxing + * + * Created by Christian Brunschen on 14/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +DetectorResult::DetectorResult(Ref bits, std::vector > points) : + bits_(bits), points_(points) { +} + +Ref DetectorResult::getBits() { + return bits_; +} + +std::vector > DetectorResult::getPoints() { + return points_; +} + +} diff --git a/symbian/QZXing/source/zxing/common/DetectorResult.h b/symbian/QZXing/source/zxing/common/DetectorResult.h index 945848e0e..6ee933f73 100644 --- a/symbian/QZXing/source/zxing/common/DetectorResult.h +++ b/symbian/QZXing/source/zxing/common/DetectorResult.h @@ -1,46 +1,43 @@ -#ifndef __DETECTOR_RESULT_H__ -#define __DETECTOR_RESULT_H__ - -/* - * DetectorResult.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace zxing { - -class DetectorResult : public Counted { -private: - Ref bits_; - std::vector > points_; - Ref transform_; - -public: - DetectorResult(Ref bits, std::vector > points, Ref transform); - Ref getBits(); - std::vector > getPoints(); - Ref getTransform(); -}; -} - -#endif // __DETECTOR_RESULT_H__ +#ifndef __DETECTOR_RESULT_H__ +#define __DETECTOR_RESULT_H__ + +/* + * DetectorResult.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +namespace zxing { + +class DetectorResult : public Counted { +private: + Ref bits_; + std::vector > points_; + +public: + DetectorResult(Ref bits, std::vector > points); + Ref getBits(); + std::vector > getPoints(); +}; +} + +#endif // __DETECTOR_RESULT_H__ diff --git a/symbian/QZXing/source/zxing/common/ECI.cpp b/symbian/QZXing/source/zxing/common/ECI.cpp deleted file mode 100644 index dc382dfb5..000000000 --- a/symbian/QZXing/source/zxing/common/ECI.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2008-2011 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -using zxing::common::ECI; -using zxing::IllegalArgumentException; - -ECI::ECI(int value_) : value(value_) {} - -int ECI::getValue() const { - return value; -} - -ECI* ECI::getECIByValue(int value) { - if (value < 0 || value > 999999) { - throw IllegalArgumentException("Bad ECI value: " + value); - } - if (value < 900) { // Character set ECIs use 000000 - 000899 - return CharacterSetECI::getCharacterSetECIByValue(value); - } - return 0; -} diff --git a/symbian/QZXing/source/zxing/common/ECI.h b/symbian/QZXing/source/zxing/common/ECI.h deleted file mode 100644 index e1e6ca01c..000000000 --- a/symbian/QZXing/source/zxing/common/ECI.h +++ /dev/null @@ -1,40 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- - -#ifndef __ECI__ -#define __ECI__ - -/* - * Copyright 2008-2011 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace zxing { - namespace common { - class ECI; - } -} -class zxing::common::ECI { -private: - const int value; - -protected: - ECI(int value); - -public: - int getValue() const; - - static ECI* getECIByValue(int value); -}; - -#endif diff --git a/symbian/QZXing/source/zxing/common/EdgeDetector.cpp b/symbian/QZXing/source/zxing/common/EdgeDetector.cpp index 70ac8c5de..a24fd9432 100644 --- a/symbian/QZXing/source/zxing/common/EdgeDetector.cpp +++ b/symbian/QZXing/source/zxing/common/EdgeDetector.cpp @@ -1,191 +1,191 @@ -/* - * EdgeDetector.cpp - * zxing - * - * Created by Ralf Kistner on 7/12/2009. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -using namespace std; - -namespace zxing { -namespace EdgeDetector { - -void findEdgePoints(std::vector& points, const BitMatrix& image, Point start, Point end, bool invert, int skip, float deviation) { - float xdist = end.x - start.x; - float ydist = end.y - start.y; - float length = sqrt(xdist * xdist + ydist * ydist); - - - int var; - - if (abs(xdist) > abs(ydist)) { - // Horizontal - if (xdist < 0) - skip = -skip; - - var = int(abs(deviation * length / xdist)); - - float dy = ydist / xdist * skip; - bool left = (skip < 0) ^ invert; - int x = int(start.x); - - int steps = int(xdist / skip); - for (int i = 0; i < steps; i++) { - x += skip; - if (x < 0 || x >= (int)image.getWidth()) - continue; // In case we start off the edge - int my = int(start.y + dy * i); - int ey = min(my + var + 1, (int)image.getHeight() - 1); - int sy = max(my - var, 0); - for (int y = sy + 1; y < ey; y++) { - if (left) { - if (image.get(x, y) && !image.get(x, y + 1)) { - points.push_back(Point(x, y + 0.5f)); - } - } else { - if (!image.get(x, y) && image.get(x, y + 1)) { - points.push_back(Point(x, y + 0.5f)); - } - } - } - } - } else { - // Vertical - if (ydist < 0) - skip = -skip; - - var = int(abs(deviation * length / ydist)); - - float dx = xdist / ydist * skip; - bool down = (skip > 0) ^ invert; - int y = int(start.y); - - int steps = int(ydist / skip); - for (int i = 0; i < steps; i++) { - y += skip; - if (y < 0 || y >= (int)image.getHeight()) - continue; // In case we start off the edge - int mx = int(start.x + dx * i); - int ex = min(mx + var + 1, (int)image.getWidth() - 1); - int sx = max(mx - var, 0); - for (int x = sx + 1; x < ex; x++) { - if (down) { - if (image.get(x, y) && !image.get(x + 1, y)) { - points.push_back(Point(x + 0.5f, y)); - } - - } else { - if (!image.get(x, y) && image.get(x + 1, y)) { - points.push_back(Point(x + 0.5f, y)); - } - } - - } - } - - } -} - -Line findLine(const BitMatrix& image, Line estimate, bool invert, int deviation, float threshold, int skip) { - float t = threshold * threshold; - - Point start = estimate.start; - Point end = estimate.end; - - vector edges; - edges.clear(); - findEdgePoints(edges, image, start, end, invert, skip, deviation); - - int n = edges.size(); - - float xdist = end.x - start.x; - float ydist = end.y - start.y; - - bool horizontal = abs(xdist) > abs(ydist); - - float max = 0; - Line bestLine(start, end); // prepopulate with the given line, in case we can't find any line for some reason - - for (int i = -deviation; i < deviation; i++) { - float x1, y1; - if (horizontal) { - y1 = start.y + i; - x1 = start.x - i * ydist / xdist; - } else { - y1 = start.y - i * xdist / ydist; - x1 = start.x + i; - } - - for (int j = -deviation; j < deviation; j++) { - float x2, y2; - if (horizontal) { - y2 = end.y + j; - x2 = end.x - j * ydist / xdist; - } else { - y2 = end.y - j * xdist / ydist; - x2 = end.x + j; - } - - float dx = x1 - x2; - float dy = y1 - y2; - float length = sqrt(dx * dx + dy * dy); - - float score = 0; - - for(int k = 0; k < n; k++) { - const Point& edge = edges[k]; - float dist = ((x1 - edge.x) * dy - (y1 - edge.y) * dx) / length; - // Similar to least squares method - float s = t - dist * dist; - if (s > 0) - score += s; - } - - if (score > max) { - max = score; - bestLine.start = Point(x1, y1); - bestLine.end = Point(x2, y2); - } - } - } - - return bestLine; -} - -Point intersection(Line a, Line b) { - float dxa = a.start.x - a.end.x; - float dxb = b.start.x - b.end.x; - float dya = a.start.y - a.end.y; - float dyb = b.start.y - b.end.y; - - float p = a.start.x * a.end.y - a.start.y * a.end.x; - float q = b.start.x * b.end.y - b.start.y * b.end.x; - float denom = dxa * dyb - dya * dxb; - if(denom == 0) // Lines don't intersect - return Point(INFINITY, INFINITY); - - float x = (p * dxb - dxa * q) / denom; - float y = (p * dyb - dya * q) / denom; - - return Point(x, y); -} - -} // namespace EdgeDetector -} // namespace zxing +/* + * EdgeDetector.cpp + * zxing + * + * Created by Ralf Kistner on 7/12/2009. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +using namespace std; + +namespace zxing { +namespace EdgeDetector { + +void findEdgePoints(std::vector& points, const BitMatrix& image, Point start, Point end, bool invert, int skip, float deviation) { + float xdist = end.x - start.x; + float ydist = end.y - start.y; + float length = sqrt(xdist * xdist + ydist * ydist); + + + int var; + + if (abs(xdist) > abs(ydist)) { + // Horizontal + if (xdist < 0) + skip = -skip; + + var = int(abs(deviation * length / xdist)); + + float dy = ydist / xdist * skip; + bool left = (skip < 0) ^ invert; + int x = int(start.x); + + int steps = int(xdist / skip); + for (int i = 0; i < steps; i++) { + x += skip; + if (x < 0 || x >= (int)image.getWidth()) + continue; // In case we start off the edge + int my = int(start.y + dy * i); + int ey = min(my + var + 1, (int)image.getHeight() - 1); + int sy = max(my - var, 0); + for (int y = sy + 1; y < ey; y++) { + if (left) { + if (image.get(x, y) && !image.get(x, y + 1)) { + points.push_back(Point(x, y + 0.5f)); + } + } else { + if (!image.get(x, y) && image.get(x, y + 1)) { + points.push_back(Point(x, y + 0.5f)); + } + } + } + } + } else { + // Vertical + if (ydist < 0) + skip = -skip; + + var = int(abs(deviation * length / ydist)); + + float dx = xdist / ydist * skip; + bool down = (skip > 0) ^ invert; + int y = int(start.y); + + int steps = int(ydist / skip); + for (int i = 0; i < steps; i++) { + y += skip; + if (y < 0 || y >= (int)image.getHeight()) + continue; // In case we start off the edge + int mx = int(start.x + dx * i); + int ex = min(mx + var + 1, (int)image.getWidth() - 1); + int sx = max(mx - var, 0); + for (int x = sx + 1; x < ex; x++) { + if (down) { + if (image.get(x, y) && !image.get(x + 1, y)) { + points.push_back(Point(x + 0.5f, y)); + } + + } else { + if (!image.get(x, y) && image.get(x + 1, y)) { + points.push_back(Point(x + 0.5f, y)); + } + } + + } + } + + } +} + +Line findLine(const BitMatrix& image, Line estimate, bool invert, int deviation, float threshold, int skip) { + float t = threshold * threshold; + + Point start = estimate.start; + Point end = estimate.end; + + vector edges; + edges.clear(); + findEdgePoints(edges, image, start, end, invert, skip, deviation); + + int n = edges.size(); + + float xdist = end.x - start.x; + float ydist = end.y - start.y; + + bool horizontal = abs(xdist) > abs(ydist); + + float max = 0; + Line bestLine(start, end); // prepopulate with the given line, in case we can't find any line for some reason + + for (int i = -deviation; i < deviation; i++) { + float x1, y1; + if (horizontal) { + y1 = start.y + i; + x1 = start.x - i * ydist / xdist; + } else { + y1 = start.y - i * xdist / ydist; + x1 = start.x + i; + } + + for (int j = -deviation; j < deviation; j++) { + float x2, y2; + if (horizontal) { + y2 = end.y + j; + x2 = end.x - j * ydist / xdist; + } else { + y2 = end.y - j * xdist / ydist; + x2 = end.x + j; + } + + float dx = x1 - x2; + float dy = y1 - y2; + float length = sqrt(dx * dx + dy * dy); + + float score = 0; + + for(int k = 0; k < n; k++) { + const Point& edge = edges[k]; + float dist = ((x1 - edge.x) * dy - (y1 - edge.y) * dx) / length; + // Similar to least squares method + float s = t - dist * dist; + if (s > 0) + score += s; + } + + if (score > max) { + max = score; + bestLine.start = Point(x1, y1); + bestLine.end = Point(x2, y2); + } + } + } + + return bestLine; +} + +Point intersection(Line a, Line b) { + float dxa = a.start.x - a.end.x; + float dxb = b.start.x - b.end.x; + float dya = a.start.y - a.end.y; + float dyb = b.start.y - b.end.y; + + float p = a.start.x * a.end.y - a.start.y * a.end.x; + float q = b.start.x * b.end.y - b.start.y * b.end.x; + float denom = dxa * dyb - dya * dxb; + if(denom == 0) // Lines don't intersect + return Point(INFINITY, INFINITY); + + float x = (p * dxb - dxa * q) / denom; + float y = (p * dyb - dya * q) / denom; + + return Point(x, y); +} + +} // namespace EdgeDetector +} // namespace zxing diff --git a/symbian/QZXing/source/zxing/common/EdgeDetector.h b/symbian/QZXing/source/zxing/common/EdgeDetector.h index 243154ca4..6b2ee9794 100644 --- a/symbian/QZXing/source/zxing/common/EdgeDetector.h +++ b/symbian/QZXing/source/zxing/common/EdgeDetector.h @@ -1,38 +1,38 @@ -#ifndef __EDGEDETECTOR_H__ -#define __EDGEDETECTOR_H__ -/* - * EdgeDetector.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - - -#include -#include -#include - -namespace zxing { -namespace EdgeDetector { - -void findEdgePoints(std::vector& points, const BitMatrix& image, Point start, Point end, bool invert, int skip, float deviation); -Line findLine(const BitMatrix& image, Line estimate, bool invert, int deviation, float threshold, int skip); - -Point intersection(Line a, Line b); - -} -} -#endif /* EDGEDETECTOR_H_ */ +#ifndef __EDGEDETECTOR_H__ +#define __EDGEDETECTOR_H__ +/* + * EdgeDetector.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#include +#include +#include + +namespace zxing { +namespace EdgeDetector { + +void findEdgePoints(std::vector& points, const BitMatrix& image, Point start, Point end, bool invert, int skip, float deviation); +Line findLine(const BitMatrix& image, Line estimate, bool invert, int deviation, float threshold, int skip); + +Point intersection(Line a, Line b); + +} +} +#endif /* EDGEDETECTOR_H_ */ diff --git a/symbian/QZXing/source/zxing/common/GlobalHistogramBinarizer.cpp b/symbian/QZXing/source/zxing/common/GlobalHistogramBinarizer.cpp index 2a1467331..a32fe2795 100644 --- a/symbian/QZXing/source/zxing/common/GlobalHistogramBinarizer.cpp +++ b/symbian/QZXing/source/zxing/common/GlobalHistogramBinarizer.cpp @@ -1,209 +1,209 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * GlobalHistogramBinarizer.cpp - * zxing - * - * Copyright 2010 ZXing authors. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -using namespace std; - -const int LUMINANCE_BITS = 5; -const int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS; -const int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS; - -GlobalHistogramBinarizer::GlobalHistogramBinarizer(Ref source) : - Binarizer(source), cached_matrix_(NULL), cached_row_(NULL), cached_row_num_(-1) { - -} - -GlobalHistogramBinarizer::~GlobalHistogramBinarizer() { -} - - -Ref GlobalHistogramBinarizer::getBlackRow(int y, Ref row) { - if (y == cached_row_num_) { - if (cached_row_ != NULL) { - return cached_row_; - } else { - throw IllegalArgumentException("Too little dynamic range in luminance"); - } - } - - vector histogram(LUMINANCE_BUCKETS, 0); - LuminanceSource& source = *getLuminanceSource(); - int width = source.getWidth(); - if (row == NULL || static_cast(row->getSize()) < width) { - row = new BitArray(width); - } else { - row->clear(); - } - - //TODO(flyashi): cache this instead of allocating and deleting per row - unsigned char* row_pixels = NULL; - try { - row_pixels = new unsigned char[width]; - row_pixels = source.getRow(y, row_pixels); - for (int x = 0; x < width; x++) { - histogram[row_pixels[x] >> LUMINANCE_SHIFT]++; - } - int blackPoint = estimate(histogram) << LUMINANCE_SHIFT; - - BitArray& array = *row; - int left = row_pixels[0]; - int center = row_pixels[1]; - for (int x = 1; x < width - 1; x++) { - int right = row_pixels[x + 1]; - // A simple -1 4 -1 box filter with a weight of 2. - int luminance = ((center << 2) - left - right) >> 1; - if (luminance < blackPoint) { - array.set(x); - } - left = center; - center = right; - } - - cached_row_ = row; - cached_row_num_ = y; - delete [] row_pixels; - return row; - } catch (IllegalArgumentException const& iae) { - // Cache the fact that this row failed. - cached_row_ = NULL; - cached_row_num_ = y; - delete [] row_pixels; - throw iae; - } -} - -Ref GlobalHistogramBinarizer::getBlackMatrix() { - if (cached_matrix_ != NULL) { - return cached_matrix_; - } - - // Faster than working with the reference - LuminanceSource& source = *getLuminanceSource(); - int width = source.getWidth(); - int height = source.getHeight(); - vector histogram(LUMINANCE_BUCKETS, 0); - - // Quickly calculates the histogram by sampling four rows from the image. - // This proved to be more robust on the blackbox tests than sampling a - // diagonal as we used to do. - ArrayRef ref (width); - unsigned char* row = &ref[0]; - for (int y = 1; y < 5; y++) { - int rownum = height * y / 5; - int right = (width << 2) / 5; - row = source.getRow(rownum, row); - for (int x = width / 5; x < right; x++) { - histogram[row[x] >> LUMINANCE_SHIFT]++; - } - } - - int blackPoint = estimate(histogram) << LUMINANCE_SHIFT; - - Ref matrix_ref(new BitMatrix(width, height)); - BitMatrix& matrix = *matrix_ref; - for (int y = 0; y < height; y++) { - row = source.getRow(y, row); - for (int x = 0; x < width; x++) { - if (row[x] <= blackPoint) - matrix.set(x, y); - } - } - - cached_matrix_ = matrix_ref; - // delete [] row; - return matrix_ref; -} - -int GlobalHistogramBinarizer::estimate(vector &histogram) { - int numBuckets = histogram.size(); - int maxBucketCount = 0; - - // Find tallest peak in histogram - int firstPeak = 0; - int firstPeakSize = 0; - for (int i = 0; i < numBuckets; i++) { - if (histogram[i] > firstPeakSize) { - firstPeak = i; - firstPeakSize = histogram[i]; - } - if (histogram[i] > maxBucketCount) { - maxBucketCount = histogram[i]; - } - } - - // Find second-tallest peak -- well, another peak that is tall and not - // so close to the first one - int secondPeak = 0; - int secondPeakScore = 0; - for (int i = 0; i < numBuckets; i++) { - int distanceToBiggest = i - firstPeak; - // Encourage more distant second peaks by multiplying by square of distance - int score = histogram[i] * distanceToBiggest * distanceToBiggest; - if (score > secondPeakScore) { - secondPeak = i; - secondPeakScore = score; - } - } - - // Put firstPeak first - if (firstPeak > secondPeak) { - int temp = firstPeak; - firstPeak = secondPeak; - secondPeak = temp; - } - - // Kind of arbitrary; if the two peaks are very close, then we figure there is - // so little dynamic range in the image, that discriminating black and white - // is too error-prone. - // Decoding the image/line is either pointless, or may in some cases lead to - // a false positive for 1D formats, which are relatively lenient. - // We arbitrarily say "close" is - // "<= 1/16 of the total histogram buckets apart" - if (secondPeak - firstPeak <= numBuckets >> 4) { - throw IllegalArgumentException("Too little dynamic range in luminance"); - } - - // Find a valley between them that is low and closer to the white peak - int bestValley = secondPeak - 1; - int bestValleyScore = -1; - for (int i = secondPeak - 1; i > firstPeak; i--) { - int fromFirst = i - firstPeak; - // Favor a "valley" that is not too close to either peak -- especially not - // the black peak -- and that has a low value of course - int score = fromFirst * fromFirst * (secondPeak - i) * - (maxBucketCount - histogram[i]); - if (score > bestValleyScore) { - bestValley = i; - bestValleyScore = score; - } - } - - return bestValley; -} - -Ref GlobalHistogramBinarizer::createBinarizer(Ref source) { - return Ref (new GlobalHistogramBinarizer(source)); -} - -} // namespace zxing +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * GlobalHistogramBinarizer.cpp + * zxing + * + * Copyright 2010 ZXing authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { +using namespace std; + +const int LUMINANCE_BITS = 5; +const int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS; +const int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS; + +GlobalHistogramBinarizer::GlobalHistogramBinarizer(Ref source) : + Binarizer(source), cached_matrix_(NULL), cached_row_(NULL), cached_row_num_(-1) { + +} + +GlobalHistogramBinarizer::~GlobalHistogramBinarizer() { +} + + +Ref GlobalHistogramBinarizer::getBlackRow(int y, Ref row) { + if (y == cached_row_num_) { + if (cached_row_ != NULL) { + return cached_row_; + } else { + throw IllegalArgumentException("Too little dynamic range in luminance"); + } + } + + vector histogram(LUMINANCE_BUCKETS, 0); + LuminanceSource& source = *getLuminanceSource(); + int width = source.getWidth(); + if (row == NULL || static_cast(row->getSize()) < width) { + row = new BitArray(width); + } else { + row->clear(); + } + + //TODO(flyashi): cache this instead of allocating and deleting per row + unsigned char* row_pixels = NULL; + try { + row_pixels = new unsigned char[width]; + row_pixels = source.getRow(y, row_pixels); + for (int x = 0; x < width; x++) { + histogram[row_pixels[x] >> LUMINANCE_SHIFT]++; + } + int blackPoint = estimate(histogram); + + BitArray& array = *row; + int left = row_pixels[0]; + int center = row_pixels[1]; + for (int x = 1; x < width - 1; x++) { + int right = row_pixels[x + 1]; + // A simple -1 4 -1 box filter with a weight of 2. + int luminance = ((center << 2) - left - right) >> 1; + if (luminance < blackPoint) { + array.set(x); + } + left = center; + center = right; + } + + cached_row_ = row; + cached_row_num_ = y; + delete [] row_pixels; + return row; + } catch (IllegalArgumentException const& iae) { + // Cache the fact that this row failed. + cached_row_ = NULL; + cached_row_num_ = y; + delete [] row_pixels; + throw iae; + } +} + +Ref GlobalHistogramBinarizer::getBlackMatrix() { + if (cached_matrix_ != NULL) { + return cached_matrix_; + } + + // Faster than working with the reference + LuminanceSource& source = *getLuminanceSource(); + int width = source.getWidth(); + int height = source.getHeight(); + vector histogram(LUMINANCE_BUCKETS, 0); + + // Quickly calculates the histogram by sampling four rows from the image. + // This proved to be more robust on the blackbox tests than sampling a + // diagonal as we used to do. + ArrayRef ref (width); + unsigned char* row = &ref[0]; + for (int y = 1; y < 5; y++) { + int rownum = height * y / 5; + int right = (width << 2) / 5; + row = source.getRow(rownum, row); + for (int x = width / 5; x < right; x++) { + histogram[row[x] >> LUMINANCE_SHIFT]++; + } + } + + int blackPoint = estimate(histogram); + + Ref matrix_ref(new BitMatrix(width, height)); + BitMatrix& matrix = *matrix_ref; + for (int y = 0; y < height; y++) { + row = source.getRow(y, row); + for (int x = 0; x < width; x++) { + if (row[x] < blackPoint) + matrix.set(x, y); + } + } + + cached_matrix_ = matrix_ref; + // delete [] row; + return matrix_ref; +} + +int GlobalHistogramBinarizer::estimate(vector &histogram) { + int numBuckets = histogram.size(); + int maxBucketCount = 0; + + // Find tallest peak in histogram + int firstPeak = 0; + int firstPeakSize = 0; + for (int i = 0; i < numBuckets; i++) { + if (histogram[i] > firstPeakSize) { + firstPeak = i; + firstPeakSize = histogram[i]; + } + if (histogram[i] > maxBucketCount) { + maxBucketCount = histogram[i]; + } + } + + // Find second-tallest peak -- well, another peak that is tall and not + // so close to the first one + int secondPeak = 0; + int secondPeakScore = 0; + for (int i = 0; i < numBuckets; i++) { + int distanceToBiggest = i - firstPeak; + // Encourage more distant second peaks by multiplying by square of distance + int score = histogram[i] * distanceToBiggest * distanceToBiggest; + if (score > secondPeakScore) { + secondPeak = i; + secondPeakScore = score; + } + } + + // Put firstPeak first + if (firstPeak > secondPeak) { + int temp = firstPeak; + firstPeak = secondPeak; + secondPeak = temp; + } + + // Kind of arbitrary; if the two peaks are very close, then we figure there is + // so little dynamic range in the image, that discriminating black and white + // is too error-prone. + // Decoding the image/line is either pointless, or may in some cases lead to + // a false positive for 1D formats, which are relatively lenient. + // We arbitrarily say "close" is + // "<= 1/16 of the total histogram buckets apart" + if (secondPeak - firstPeak <= numBuckets >> 4) { + throw IllegalArgumentException("Too little dynamic range in luminance"); + } + + // Find a valley between them that is low and closer to the white peak + int bestValley = secondPeak - 1; + int bestValleyScore = -1; + for (int i = secondPeak - 1; i > firstPeak; i--) { + int fromFirst = i - firstPeak; + // Favor a "valley" that is not too close to either peak -- especially not + // the black peak -- and that has a low value of course + int score = fromFirst * fromFirst * (secondPeak - i) * + (maxBucketCount - histogram[i]); + if (score > bestValleyScore) { + bestValley = i; + bestValleyScore = score; + } + } + + return bestValley << LUMINANCE_SHIFT; +} + +Ref GlobalHistogramBinarizer::createBinarizer(Ref source) { + return Ref (new GlobalHistogramBinarizer(source)); +} + +} // namespace zxing diff --git a/symbian/QZXing/source/zxing/common/GlobalHistogramBinarizer.h b/symbian/QZXing/source/zxing/common/GlobalHistogramBinarizer.h index 72b59296b..af27061c6 100644 --- a/symbian/QZXing/source/zxing/common/GlobalHistogramBinarizer.h +++ b/symbian/QZXing/source/zxing/common/GlobalHistogramBinarizer.h @@ -1,47 +1,47 @@ -#ifndef __GLOBALHISTOGRAMBINARIZER_H__ -#define __GLOBALHISTOGRAMBINARIZER_H__ -/* - * GlobalHistogramBinarizer.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { - - class GlobalHistogramBinarizer : public Binarizer { - private: - Ref cached_matrix_; - Ref cached_row_; - int cached_row_num_; - - public: - GlobalHistogramBinarizer(Ref source); - virtual ~GlobalHistogramBinarizer(); - - virtual Ref getBlackRow(int y, Ref row); - virtual Ref getBlackMatrix(); - static int estimate(std::vector &histogram); - Ref createBinarizer(Ref source); - }; - -} - -#endif /* GLOBALHISTOGRAMBINARIZER_H_ */ +#ifndef __GLOBALHISTOGRAMBINARIZER_H__ +#define __GLOBALHISTOGRAMBINARIZER_H__ +/* + * GlobalHistogramBinarizer.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { + + class GlobalHistogramBinarizer : public Binarizer { + private: + Ref cached_matrix_; + Ref cached_row_; + int cached_row_num_; + + public: + GlobalHistogramBinarizer(Ref source); + virtual ~GlobalHistogramBinarizer(); + + virtual Ref getBlackRow(int y, Ref row); + virtual Ref getBlackMatrix(); + static int estimate(std::vector &histogram); + Ref createBinarizer(Ref source); + }; + +} + +#endif /* GLOBALHISTOGRAMBINARIZER_H_ */ diff --git a/symbian/QZXing/source/zxing/common/GreyscaleLuminanceSource.cpp b/symbian/QZXing/source/zxing/common/GreyscaleLuminanceSource.cpp index 4910b653d..82dc1c87e 100644 --- a/symbian/QZXing/source/zxing/common/GreyscaleLuminanceSource.cpp +++ b/symbian/QZXing/source/zxing/common/GreyscaleLuminanceSource.cpp @@ -1,70 +1,70 @@ -/* - * GreyscaleLuminanceSource.cpp - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { - -GreyscaleLuminanceSource::GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth, - int dataHeight, int left, int top, int width, int height) : greyData_(greyData), - dataWidth_(dataWidth), dataHeight_(dataHeight), left_(left), top_(top), width_(width), - height_(height) { - - if (left + width > dataWidth || top + height > dataHeight || top < 0 || left < 0) { - throw IllegalArgumentException("Crop rectangle does not fit within image data."); - } -} - -unsigned char* GreyscaleLuminanceSource::getRow(int y, unsigned char* row) { - if (y < 0 || y >= this->getHeight()) { - throw IllegalArgumentException("Requested row is outside the image: " + y); - } - int width = getWidth(); - // TODO(flyashi): determine if row has enough size. - if (row == NULL) { - row = new unsigned char[width_]; - } - int offset = (y + top_) * dataWidth_ + left_; - memcpy(row, &greyData_[offset], width); - return row; -} - -unsigned char* GreyscaleLuminanceSource::getMatrix() { - int size = width_ * height_; - unsigned char* result = new unsigned char[size]; - if (left_ == 0 && top_ == 0 && dataWidth_ == width_ && dataHeight_ == height_) { - memcpy(result, greyData_, size); - } else { - for (int row = 0; row < height_; row++) { - memcpy(result + row * width_, greyData_ + (top_ + row) * dataWidth_ + left_, width_); - } - } - return result; -} - -Ref GreyscaleLuminanceSource::rotateCounterClockwise() { - // Intentionally flip the left, top, width, and height arguments as needed. dataWidth and - // dataHeight are always kept unrotated. - return Ref (new GreyscaleRotatedLuminanceSource(greyData_, dataWidth_, - dataHeight_, top_, left_, height_, width_)); -} - -} /* namespace */ +/* + * GreyscaleLuminanceSource.cpp + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { + +GreyscaleLuminanceSource::GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth, + int dataHeight, int left, int top, int width, int height) : greyData_(greyData), + dataWidth_(dataWidth), dataHeight_(dataHeight), left_(left), top_(top), width_(width), + height_(height) { + + if (left + width > dataWidth || top + height > dataHeight || top < 0 || left < 0) { + throw IllegalArgumentException("Crop rectangle does not fit within image data."); + } +} + +unsigned char* GreyscaleLuminanceSource::getRow(int y, unsigned char* row) { + if (y < 0 || y >= this->getHeight()) { + throw IllegalArgumentException("Requested row is outside the image."); + } + int width = getWidth(); + // TODO(flyashi): determine if row has enough size. + if (row == NULL) { + row = new unsigned char[width_]; + } + int offset = (y + top_) * dataWidth_ + left_; + memcpy(row, &greyData_[offset], width); + return row; +} + +unsigned char* GreyscaleLuminanceSource::getMatrix() { + int size = width_ * height_; + unsigned char* result = new unsigned char[size]; + if (left_ == 0 && top_ == 0 && dataWidth_ == width_ && dataHeight_ == height_) { + memcpy(result, greyData_, size); + } else { + for (int row = 0; row < height_; row++) { + memcpy(result + row * width_, greyData_ + (top_ + row) * dataWidth_ + left_, width_); + } + } + return result; +} + +Ref GreyscaleLuminanceSource::rotateCounterClockwise() { + // Intentionally flip the left, top, width, and height arguments as needed. dataWidth and + // dataHeight are always kept unrotated. + return Ref (new GreyscaleRotatedLuminanceSource(greyData_, dataWidth_, + dataHeight_, top_, left_, height_, width_)); +} + +} /* namespace */ diff --git a/symbian/QZXing/source/zxing/common/GreyscaleLuminanceSource.h b/symbian/QZXing/source/zxing/common/GreyscaleLuminanceSource.h index 4729191f3..c819de230 100644 --- a/symbian/QZXing/source/zxing/common/GreyscaleLuminanceSource.h +++ b/symbian/QZXing/source/zxing/common/GreyscaleLuminanceSource.h @@ -1,62 +1,62 @@ -#ifndef __GREYSCALE_LUMINANCE_SOURCE__ -#define __GREYSCALE_LUMINANCE_SOURCE__ -/* - * GreyscaleLuminanceSource.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -class GreyscaleLuminanceSource : public LuminanceSource { - - private: - unsigned char* greyData_; - int dataWidth_; - int dataHeight_; - int left_; - int top_; - int width_; - int height_; - - public: - GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, int left, - int top, int width, int height); - - unsigned char* getRow(int y, unsigned char* row); - unsigned char* getMatrix(); - - bool isRotateSupported() const { - return true; - } - - int getWidth() const { - return width_; - } - - int getHeight() const { - return height_; - } - - Ref rotateCounterClockwise(); - -}; - -} /* namespace */ - -#endif +#ifndef __GREYSCALE_LUMINANCE_SOURCE__ +#define __GREYSCALE_LUMINANCE_SOURCE__ +/* + * GreyscaleLuminanceSource.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +class GreyscaleLuminanceSource : public LuminanceSource { + + private: + unsigned char* greyData_; + int dataWidth_; + int dataHeight_; + int left_; + int top_; + int width_; + int height_; + + public: + GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, int left, + int top, int width, int height); + + unsigned char* getRow(int y, unsigned char* row); + unsigned char* getMatrix(); + + bool isRotateSupported() const { + return true; + } + + int getWidth() const { + return width_; + } + + int getHeight() const { + return height_; + } + + Ref rotateCounterClockwise(); + +}; + +} /* namespace */ + +#endif diff --git a/symbian/QZXing/source/zxing/common/GreyscaleRotatedLuminanceSource.cpp b/symbian/QZXing/source/zxing/common/GreyscaleRotatedLuminanceSource.cpp index 498b5ea0d..f2c0b386d 100644 --- a/symbian/QZXing/source/zxing/common/GreyscaleRotatedLuminanceSource.cpp +++ b/symbian/QZXing/source/zxing/common/GreyscaleRotatedLuminanceSource.cpp @@ -1,65 +1,65 @@ -/* - * GreyscaleRotatedLuminanceSource.cpp - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include - -namespace zxing { - -// Note that dataWidth and dataHeight are not reversed, as we need to be able to traverse the -// greyData correctly, which does not get rotated. -GreyscaleRotatedLuminanceSource::GreyscaleRotatedLuminanceSource(unsigned char* greyData, - int dataWidth, int dataHeight, int left, int top, int width, int height) : greyData_(greyData), - dataWidth_(dataWidth), dataHeight_(dataHeight), left_(left), top_(top), width_(width), - height_(height) { - - // Intentionally comparing to the opposite dimension since we're rotated. - if (left + width > dataHeight || top + height > dataWidth) { - throw IllegalArgumentException("Crop rectangle does not fit within image data."); - } -} - -// The API asks for rows, but we're rotated, so we return columns. -unsigned char* GreyscaleRotatedLuminanceSource::getRow(int y, unsigned char* row) { - if (y < 0 || y >= getHeight()) { - throw IllegalArgumentException("Requested row is outside the image: " + y); - } - int width = getWidth(); - if (row == NULL) { - row = new unsigned char[width]; - } - int offset = (left_ * dataWidth_) + (dataWidth_ - (y + top_)); - for (int x = 0; x < width; x++) { - row[x] = greyData_[offset]; - offset += dataWidth_; - } - return row; -} - -unsigned char* GreyscaleRotatedLuminanceSource::getMatrix() { - unsigned char* result = new unsigned char[width_ * height_]; - // This depends on getRow() honoring its second parameter. - for (int y = 0; y < height_; y++) { - getRow(y, &result[y * width_]); - } - return result; -} - -} // namespace +/* + * GreyscaleRotatedLuminanceSource.cpp + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include + +namespace zxing { + +// Note that dataWidth and dataHeight are not reversed, as we need to be able to traverse the +// greyData correctly, which does not get rotated. +GreyscaleRotatedLuminanceSource::GreyscaleRotatedLuminanceSource(unsigned char* greyData, + int dataWidth, int dataHeight, int left, int top, int width, int height) : greyData_(greyData), + dataWidth_(dataWidth), dataHeight_(dataHeight), left_(left), top_(top), width_(width), + height_(height) { + + // Intentionally comparing to the opposite dimension since we're rotated. + if (left + width > dataHeight || top + height > dataWidth) { + throw IllegalArgumentException("Crop rectangle does not fit within image data."); + } +} + +// The API asks for rows, but we're rotated, so we return columns. +unsigned char* GreyscaleRotatedLuminanceSource::getRow(int y, unsigned char* row) { + if (y < 0 || y >= getHeight()) { + throw IllegalArgumentException("Requested row is outside the image."); + } + int width = getWidth(); + if (row == NULL) { + row = new unsigned char[width]; + } + int offset = (left_ * dataWidth_) + (dataWidth_ - (y + top_)); + for (int x = 0; x < width; x++) { + row[x] = greyData_[offset]; + offset += dataWidth_; + } + return row; +} + +unsigned char* GreyscaleRotatedLuminanceSource::getMatrix() { + unsigned char* result = new unsigned char[width_ * height_]; + // This depends on getRow() honoring its second parameter. + for (int y = 0; y < height_; y++) { + getRow(y, &result[y * width_]); + } + return result; +} + +} // namespace diff --git a/symbian/QZXing/source/zxing/common/GreyscaleRotatedLuminanceSource.h b/symbian/QZXing/source/zxing/common/GreyscaleRotatedLuminanceSource.h index 80535ab08..cb06e6062 100644 --- a/symbian/QZXing/source/zxing/common/GreyscaleRotatedLuminanceSource.h +++ b/symbian/QZXing/source/zxing/common/GreyscaleRotatedLuminanceSource.h @@ -1,60 +1,60 @@ -#ifndef __GREYSCALE_ROTATED_LUMINANCE_SOURCE__ -#define __GREYSCALE_ROTATED_LUMINANCE_SOURCE__ -/* - * GreyscaleRotatedLuminanceSource.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include - -namespace zxing { - -class GreyscaleRotatedLuminanceSource : public LuminanceSource { - private: - unsigned char* greyData_; - int dataWidth_; - int dataHeight_; - int left_; - int top_; - int width_; - int height_; - -public: - GreyscaleRotatedLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, - int left, int top, int width, int height); - - unsigned char* getRow(int y, unsigned char* row); - unsigned char* getMatrix(); - - bool isRotateSupported() const { - return false; - } - - int getWidth() const { - return width_; - } - - int getHeight() const { - return height_; - } - -}; - -} /* namespace */ - -#endif +#ifndef __GREYSCALE_ROTATED_LUMINANCE_SOURCE__ +#define __GREYSCALE_ROTATED_LUMINANCE_SOURCE__ +/* + * GreyscaleRotatedLuminanceSource.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +namespace zxing { + +class GreyscaleRotatedLuminanceSource : public LuminanceSource { + private: + unsigned char* greyData_; + int dataWidth_; + int dataHeight_; + int left_; + int top_; + int width_; + int height_; + +public: + GreyscaleRotatedLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, + int left, int top, int width, int height); + + unsigned char* getRow(int y, unsigned char* row); + unsigned char* getMatrix(); + + bool isRotateSupported() const { + return false; + } + + int getWidth() const { + return width_; + } + + int getHeight() const { + return height_; + } + +}; + +} /* namespace */ + +#endif diff --git a/symbian/QZXing/source/zxing/common/GridSampler.cpp b/symbian/QZXing/source/zxing/common/GridSampler.cpp index 0bdd008fd..3419a9603 100644 --- a/symbian/QZXing/source/zxing/common/GridSampler.cpp +++ b/symbian/QZXing/source/zxing/common/GridSampler.cpp @@ -1,122 +1,122 @@ -/* - * GridSampler.cpp - * zxing - * - * Created by Christian Brunschen on 18/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace zxing { -using namespace std; - -GridSampler GridSampler::gridSampler; - -GridSampler::GridSampler() { -} - -Ref GridSampler::sampleGrid(Ref image, int dimension, Ref transform) { - Ref bits(new BitMatrix(dimension)); - vector points(dimension << 1, (const float)0.0f); - for (int y = 0; y < dimension; y++) { - int max = points.size(); - float yValue = (float)y + 0.5f; - for (int x = 0; x < max; x += 2) { - points[x] = (float)(x >> 1) + 0.5f; - points[x + 1] = yValue; - } - transform->transformPoints(points); - checkAndNudgePoints(image, points); - for (int x = 0; x < max; x += 2) { - if (image->get((int)points[x], (int)points[x + 1])) { - bits->set(x >> 1, y); - } - } - } - return bits; -} - -Ref GridSampler::sampleGrid(Ref image, int dimensionX, int dimensionY, Ref transform) { - Ref bits(new BitMatrix(dimensionX, dimensionY)); - vector points(dimensionX << 1, (const float)0.0f); - for (int y = 0; y < dimensionY; y++) { - int max = points.size(); - float yValue = (float)y + 0.5f; - for (int x = 0; x < max; x += 2) { - points[x] = (float)(x >> 1) + 0.5f; - points[x + 1] = yValue; - } - transform->transformPoints(points); - checkAndNudgePoints(image, points); - for (int x = 0; x < max; x += 2) { - if (image->get((int)points[x], (int)points[x + 1])) { - bits->set(x >> 1, y); - } - } - } - return bits; -} - -Ref GridSampler::sampleGrid(Ref image, int dimension, float p1ToX, float p1ToY, float p2ToX, - float p2ToY, float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX, - float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY) { - Ref transform(PerspectiveTransform::quadrilateralToQuadrilateral(p1ToX, p1ToY, p2ToX, p2ToY, - p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY)); - - return sampleGrid(image, dimension, transform); - -} - -void GridSampler::checkAndNudgePoints(Ref image, vector &points) { - int width = image->getWidth(); - int height = image->getHeight(); - - - // The Java code assumes that if the start and end points are in bounds, the rest will also be. - // However, in some unusual cases points in the middle may also be out of bounds. - // Since we can't rely on an ArrayIndexOutOfBoundsException like Java, we check every point. - - for (size_t offset = 0; offset < points.size(); offset += 2) { - int x = (int)points[offset]; - int y = (int)points[offset + 1]; - if (x < -1 || x > width || y < -1 || y > height) { - ostringstream s; - s << "Transformed point out of bounds at " << x << "," << y; - throw ReaderException(s.str().c_str()); - } - - if (x == -1) { - points[offset] = 0.0f; - } else if (x == width) { - points[offset] = width - 1; - } - if (y == -1) { - points[offset + 1] = 0.0f; - } else if (y == height) { - points[offset + 1] = height - 1; - } - } - -} - -GridSampler &GridSampler::getInstance() { - return gridSampler; -} -} +/* + * GridSampler.cpp + * zxing + * + * Created by Christian Brunschen on 18/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +namespace zxing { +using namespace std; + +GridSampler GridSampler::gridSampler; + +GridSampler::GridSampler() { +} + +Ref GridSampler::sampleGrid(Ref image, int dimension, Ref transform) { + Ref bits(new BitMatrix(dimension)); + vector points(dimension << 1, (const float)0.0f); + for (int y = 0; y < dimension; y++) { + int max = points.size(); + float yValue = (float)y + 0.5f; + for (int x = 0; x < max; x += 2) { + points[x] = (float)(x >> 1) + 0.5f; + points[x + 1] = yValue; + } + transform->transformPoints(points); + checkAndNudgePoints(image, points); + for (int x = 0; x < max; x += 2) { + if (image->get((int)points[x], (int)points[x + 1])) { + bits->set(x >> 1, y); + } + } + } + return bits; +} + +Ref GridSampler::sampleGrid(Ref image, int dimensionX, int dimensionY, Ref transform) { + Ref bits(new BitMatrix(dimensionX, dimensionY)); + vector points(dimensionX << 1, (const float)0.0f); + for (int y = 0; y < dimensionY; y++) { + int max = points.size(); + float yValue = (float)y + 0.5f; + for (int x = 0; x < max; x += 2) { + points[x] = (float)(x >> 1) + 0.5f; + points[x + 1] = yValue; + } + transform->transformPoints(points); + checkAndNudgePoints(image, points); + for (int x = 0; x < max; x += 2) { + if (image->get((int)points[x], (int)points[x + 1])) { + bits->set(x >> 1, y); + } + } + } + return bits; +} + +Ref GridSampler::sampleGrid(Ref image, int dimension, float p1ToX, float p1ToY, float p2ToX, + float p2ToY, float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX, + float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY) { + Ref transform(PerspectiveTransform::quadrilateralToQuadrilateral(p1ToX, p1ToY, p2ToX, p2ToY, + p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY)); + + return sampleGrid(image, dimension, transform); + +} + +void GridSampler::checkAndNudgePoints(Ref image, vector &points) { + int width = image->getWidth(); + int height = image->getHeight(); + + + // The Java code assumes that if the start and end points are in bounds, the rest will also be. + // However, in some unusual cases points in the middle may also be out of bounds. + // Since we can't rely on an ArrayIndexOutOfBoundsException like Java, we check every point. + + for (size_t offset = 0; offset < points.size(); offset += 2) { + int x = (int)points[offset]; + int y = (int)points[offset + 1]; + if (x < -1 || x > width || y < -1 || y > height) { + ostringstream s; + s << "Transformed point out of bounds at " << x << "," << y; + throw ReaderException(s.str().c_str()); + } + + if (x == -1) { + points[offset] = 0.0f; + } else if (x == width) { + points[offset] = width - 1; + } + if (y == -1) { + points[offset + 1] = 0.0f; + } else if (y == height) { + points[offset + 1] = height - 1; + } + } + +} + +GridSampler &GridSampler::getInstance() { + return gridSampler; +} +} diff --git a/symbian/QZXing/source/zxing/common/GridSampler.h b/symbian/QZXing/source/zxing/common/GridSampler.h index d7f74e5b2..f11652691 100644 --- a/symbian/QZXing/source/zxing/common/GridSampler.h +++ b/symbian/QZXing/source/zxing/common/GridSampler.h @@ -1,45 +1,45 @@ -#ifndef __GRID_SAMPLER_H__ -#define __GRID_SAMPLER_H__ - -/* - * GridSampler.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -class GridSampler { -private: - static GridSampler gridSampler; - GridSampler(); - -public: - Ref sampleGrid(Ref image, int dimension, Ref transform); - Ref sampleGrid(Ref image, int dimensionX, int dimensionY, Ref transform); - - Ref sampleGrid(Ref image, int dimension, float p1ToX, float p1ToY, float p2ToX, float p2ToY, - float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX, - float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY); - static void checkAndNudgePoints(Ref image, std::vector &points); - static GridSampler &getInstance(); -}; -} - -#endif // __GRID_SAMPLER_H__ +#ifndef __GRID_SAMPLER_H__ +#define __GRID_SAMPLER_H__ + +/* + * GridSampler.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { +class GridSampler { +private: + static GridSampler gridSampler; + GridSampler(); + +public: + Ref sampleGrid(Ref image, int dimension, Ref transform); + Ref sampleGrid(Ref image, int dimensionX, int dimensionY, Ref transform); + + Ref sampleGrid(Ref image, int dimension, float p1ToX, float p1ToY, float p2ToX, float p2ToY, + float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX, + float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY); + static void checkAndNudgePoints(Ref image, std::vector &points); + static GridSampler &getInstance(); +}; +} + +#endif // __GRID_SAMPLER_H__ diff --git a/symbian/QZXing/source/zxing/common/HybridBinarizer.cpp b/symbian/QZXing/source/zxing/common/HybridBinarizer.cpp index dc912c8ff..6f1bb28b5 100644 --- a/symbian/QZXing/source/zxing/common/HybridBinarizer.cpp +++ b/symbian/QZXing/source/zxing/common/HybridBinarizer.cpp @@ -1,211 +1,221 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * HybridBinarizer.cpp - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include - -using namespace std; -using namespace zxing; - -namespace { - const int LUMINANCE_BITS = 5; - const int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS; - const int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS; - - const int BLOCK_SIZE_POWER = 3; - const int BLOCK_SIZE = 1 << BLOCK_SIZE_POWER; - const int BLOCK_SIZE_MASK = BLOCK_SIZE - 1; - const int MINIMUM_DIMENSION = BLOCK_SIZE * 5; -} - -HybridBinarizer::HybridBinarizer(Ref source) : - GlobalHistogramBinarizer(source), matrix_(NULL), cached_row_(NULL), cached_row_num_(-1) { -} - -HybridBinarizer::~HybridBinarizer() { -} - - -Ref -HybridBinarizer::createBinarizer(Ref source) { - return Ref (new HybridBinarizer(source)); -} - -Ref HybridBinarizer::getBlackMatrix() { - // Calculates the final BitMatrix once for all requests. This could - // be called once from the constructor instead, but there are some - // advantages to doing it lazily, such as making profiling easier, - // and not doing heavy lifting when callers don't expect it. - if (matrix_) { - return matrix_; - } - LuminanceSource& source = *getLuminanceSource(); - if (source.getWidth() >= MINIMUM_DIMENSION && - source.getHeight() >= MINIMUM_DIMENSION) { - unsigned char* luminances = source.getMatrix(); - int width = source.getWidth(); - int height = source.getHeight(); - int subWidth = width >> BLOCK_SIZE_POWER; - if ((width & BLOCK_SIZE_MASK) != 0) { - subWidth++; - } - int subHeight = height >> BLOCK_SIZE_POWER; - if ((height & BLOCK_SIZE_MASK) != 0) { - subHeight++; - } - int* blackPoints = - calculateBlackPoints(luminances, subWidth, subHeight, width, height); - - Ref newMatrix (new BitMatrix(width, height)); - calculateThresholdForBlock(luminances, - subWidth, - subHeight, - width, - height, - blackPoints, - newMatrix); - matrix_ = newMatrix; - - // N.B.: these deletes are inadequate if anything between the new - // and this point can throw. As of this writing, it doesn't look - // like they do. - - delete [] blackPoints; - delete [] luminances; - } else { - // If the image is too small, fall back to the global histogram approach. - matrix_ = GlobalHistogramBinarizer::getBlackMatrix(); - } - return matrix_; -} - -void -HybridBinarizer::calculateThresholdForBlock(unsigned char* luminances, - int subWidth, - int subHeight, - int width, - int height, - int blackPoints[], - Ref const& matrix) { - for (int y = 0; y < subHeight; y++) { - int yoffset = y << BLOCK_SIZE_POWER; - if (yoffset + BLOCK_SIZE >= height) { - yoffset = height - BLOCK_SIZE; - } - for (int x = 0; x < subWidth; x++) { - int xoffset = x << BLOCK_SIZE_POWER; - if (xoffset + BLOCK_SIZE >= width) { - xoffset = width - BLOCK_SIZE; - } - int left = (x > 1) ? x : 2; - left = (left < subWidth - 2) ? left : subWidth - 3; - int top = (y > 1) ? y : 2; - top = (top < subHeight - 2) ? top : subHeight - 3; - int sum = 0; - for (int z = -2; z <= 2; z++) { - int *blackRow = &blackPoints[(top + z) * subWidth]; - sum += blackRow[left - 2]; - sum += blackRow[left - 1]; - sum += blackRow[left]; - sum += blackRow[left + 1]; - sum += blackRow[left + 2]; - } - int average = sum / 25; - threshold8x8Block(luminances, xoffset, yoffset, average, width, matrix); - } - } -} - -void HybridBinarizer::threshold8x8Block(unsigned char* luminances, - int xoffset, - int yoffset, - int threshold, - int stride, - Ref const& matrix) { - for (int y = 0, offset = yoffset * stride + xoffset; - y < BLOCK_SIZE; - y++, offset += stride) { - for (int x = 0; x < BLOCK_SIZE; x++) { - int pixel = luminances[offset + x] & 0xff; - if (pixel <= threshold) { - matrix->set(xoffset + x, yoffset + y); - } - } - } -} - -namespace { - inline int getBlackPointFromNeighbors(int* blackPoints, int subWidth, int x, int y) { - return (blackPoints[(y-1)*subWidth+x] + - 2*blackPoints[y*subWidth+x-1] + - blackPoints[(y-1)*subWidth+x-1]) >> 2; - } -} - -int* HybridBinarizer::calculateBlackPoints(unsigned char* luminances, int subWidth, int subHeight, - int width, int height) { - int *blackPoints = new int[subHeight * subWidth]; - for (int y = 0; y < subHeight; y++) { - int yoffset = y << BLOCK_SIZE_POWER; - if (yoffset + BLOCK_SIZE >= height) { - yoffset = height - BLOCK_SIZE; - } - for (int x = 0; x < subWidth; x++) { - int xoffset = x << BLOCK_SIZE_POWER; - if (xoffset + BLOCK_SIZE >= width) { - xoffset = width - BLOCK_SIZE; - } - int sum = 0; - int min = 0xFF; - int max = 0; - for (int yy = 0, offset = yoffset * width + xoffset; - yy < BLOCK_SIZE; - yy++, offset += width) { - for (int xx = 0; xx < BLOCK_SIZE; xx++) { - int pixel = luminances[offset + xx] & 0xFF; - sum += pixel; - if (pixel < min) { - min = pixel; - } - if (pixel > max) { - max = pixel; - } - } - } - - // See - // http://groups.google.com/group/zxing/browse_thread/thread/d06efa2c35a7ddc0 - int average = sum >> 6; - if (max - min <= 24) { - average = min >> 1; - if (y > 0 && x > 0) { - int bp = getBlackPointFromNeighbors(blackPoints, subWidth, x, y); - if (min < bp) { - average = bp; - } - } - } - blackPoints[y * subWidth + x] = average; - } - } - return blackPoints; -} - +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * HybridBinarizer.cpp + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +using namespace std; +using namespace zxing; + +namespace { + const int BLOCK_SIZE_POWER = 3; + const int BLOCK_SIZE = 1 << BLOCK_SIZE_POWER; + const int BLOCK_SIZE_MASK = BLOCK_SIZE - 1; + const int MINIMUM_DIMENSION = BLOCK_SIZE * 5; +} + +HybridBinarizer::HybridBinarizer(Ref source) : + GlobalHistogramBinarizer(source), matrix_(NULL), cached_row_(NULL), cached_row_num_(-1) { +} + +HybridBinarizer::~HybridBinarizer() { +} + + +Ref +HybridBinarizer::createBinarizer(Ref source) { + return Ref (new HybridBinarizer(source)); +} + +Ref HybridBinarizer::getBlackMatrix() { + // Calculates the final BitMatrix once for all requests. This could + // be called once from the constructor instead, but there are some + // advantages to doing it lazily, such as making profiling easier, + // and not doing heavy lifting when callers don't expect it. + if (matrix_) { + return matrix_; + } + LuminanceSource& source = *getLuminanceSource(); + if (source.getWidth() >= MINIMUM_DIMENSION && + source.getHeight() >= MINIMUM_DIMENSION) { + unsigned char* luminances = source.getMatrix(); + int width = source.getWidth(); + int height = source.getHeight(); + int subWidth = width >> BLOCK_SIZE_POWER; + if ((width & BLOCK_SIZE_MASK) != 0) { + subWidth++; + } + int subHeight = height >> BLOCK_SIZE_POWER; + if ((height & BLOCK_SIZE_MASK) != 0) { + subHeight++; + } + int* blackPoints = + calculateBlackPoints(luminances, subWidth, subHeight, width, height); + + Ref newMatrix (new BitMatrix(width, height)); + calculateThresholdForBlock(luminances, + subWidth, + subHeight, + width, + height, + blackPoints, + newMatrix); + matrix_ = newMatrix; + + // N.B.: these deletes are inadequate if anything between the new + // and this point can throw. As of this writing, it doesn't look + // like they do. + + delete [] blackPoints; + delete [] luminances; + } else { + // If the image is too small, fall back to the global histogram approach. + matrix_ = GlobalHistogramBinarizer::getBlackMatrix(); + } + return matrix_; +} + +void +HybridBinarizer::calculateThresholdForBlock(unsigned char* luminances, + int subWidth, + int subHeight, + int width, + int height, + int blackPoints[], + Ref const& matrix) { + for (int y = 0; y < subHeight; y++) { + int yoffset = y << BLOCK_SIZE_POWER; + if (yoffset + BLOCK_SIZE >= height) { + yoffset = height - BLOCK_SIZE; + } + for (int x = 0; x < subWidth; x++) { + int xoffset = x << BLOCK_SIZE_POWER; + if (xoffset + BLOCK_SIZE >= width) { + xoffset = width - BLOCK_SIZE; + } + int left = (x > 1) ? x : 2; + left = (left < subWidth - 2) ? left : subWidth - 3; + int top = (y > 1) ? y : 2; + top = (top < subHeight - 2) ? top : subHeight - 3; + int sum = 0; + for (int z = -2; z <= 2; z++) { + int *blackRow = &blackPoints[(top + z) * subWidth]; + sum += blackRow[left - 2]; + sum += blackRow[left - 1]; + sum += blackRow[left]; + sum += blackRow[left + 1]; + sum += blackRow[left + 2]; + } + int average = sum / 25; + threshold8x8Block(luminances, xoffset, yoffset, average, width, matrix); + } + } +} + +void HybridBinarizer::threshold8x8Block(unsigned char* luminances, + int xoffset, + int yoffset, + int threshold, + int stride, + Ref const& matrix) { + for (int y = 0, offset = yoffset * stride + xoffset; + y < BLOCK_SIZE; + y++, offset += stride) { + for (int x = 0; x < BLOCK_SIZE; x++) { + int pixel = luminances[offset + x] & 0xff; + if (pixel <= threshold) { + matrix->set(xoffset + x, yoffset + y); + } + } + } +} + +namespace { + inline int getBlackPointFromNeighbors(int* blackPoints, int subWidth, int x, int y) { + return (blackPoints[(y-1)*subWidth+x] + + 2*blackPoints[y*subWidth+x-1] + + blackPoints[(y-1)*subWidth+x-1]) >> 2; + } +} + + +int* HybridBinarizer::calculateBlackPoints(unsigned char* luminances, int subWidth, int subHeight, + int width, int height) { + const int minDynamicRange = 24; + + int *blackPoints = new int[subHeight * subWidth]; + for (int y = 0; y < subHeight; y++) { + int yoffset = y << BLOCK_SIZE_POWER; + if (yoffset + BLOCK_SIZE >= height) { + yoffset = height - BLOCK_SIZE; + } + for (int x = 0; x < subWidth; x++) { + int xoffset = x << BLOCK_SIZE_POWER; + if (xoffset + BLOCK_SIZE >= width) { + xoffset = width - BLOCK_SIZE; + } + int sum = 0; + int min = 0xFF; + int max = 0; + for (int yy = 0, offset = yoffset * width + xoffset; + yy < BLOCK_SIZE; + yy++, offset += width) { + for (int xx = 0; xx < BLOCK_SIZE; xx++) { + int pixel = luminances[offset + xx] & 0xFF; + sum += pixel; + // still looking for good contrast + if (pixel < min) { + min = pixel; + } + if (pixel > max) { + max = pixel; + } + } + + // short-circuit min/max tests once dynamic range is met + if (max - min > minDynamicRange) { + // finish the rest of the rows quickly + for (yy++, offset += width; yy < BLOCK_SIZE; yy++, offset += width) { + for (int xx = 0; xx < BLOCK_SIZE; xx += 2) { + sum += luminances[offset + xx] & 0xFF; + sum += luminances[offset + xx + 1] & 0xFF; + } + } + } + } + // See + // http://groups.google.com/group/zxing/browse_thread/thread/d06efa2c35a7ddc0 + int average = sum >> (BLOCK_SIZE_POWER * 2); + if (max - min <= minDynamicRange) { + average = min >> 1; + if (y > 0 && x > 0) { + int bp = getBlackPointFromNeighbors(blackPoints, subWidth, x, y); + if (min < bp) { + average = bp; + } + } + } + blackPoints[y * subWidth + x] = average; + } + } + return blackPoints; +} + diff --git a/symbian/QZXing/source/zxing/common/HybridBinarizer.h b/symbian/QZXing/source/zxing/common/HybridBinarizer.h index e7b74646a..6371e13b1 100644 --- a/symbian/QZXing/source/zxing/common/HybridBinarizer.h +++ b/symbian/QZXing/source/zxing/common/HybridBinarizer.h @@ -1,68 +1,68 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __HYBRIDBINARIZER_H__ -#define __HYBRIDBINARIZER_H__ -/* - * HybridBinarizer.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace zxing { - - class HybridBinarizer : public GlobalHistogramBinarizer { - private: - Ref matrix_; - Ref cached_row_; - int cached_row_num_; - - public: - HybridBinarizer(Ref source); - virtual ~HybridBinarizer(); - - virtual Ref getBlackMatrix(); - Ref createBinarizer(Ref source); - private: - // We'll be using one-D arrays because C++ can't dynamically allocate 2D - // arrays - int* calculateBlackPoints(unsigned char* luminances, - int subWidth, - int subHeight, - int width, - int height); - void calculateThresholdForBlock(unsigned char* luminances, - int subWidth, - int subHeight, - int width, - int height, - int blackPoints[], - Ref const& matrix); - void threshold8x8Block(unsigned char* luminances, - int xoffset, - int yoffset, - int threshold, - int stride, - Ref const& matrix); - }; - -} - -#endif +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __HYBRIDBINARIZER_H__ +#define __HYBRIDBINARIZER_H__ +/* + * HybridBinarizer.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +namespace zxing { + + class HybridBinarizer : public GlobalHistogramBinarizer { + private: + Ref matrix_; + Ref cached_row_; + int cached_row_num_; + + public: + HybridBinarizer(Ref source); + virtual ~HybridBinarizer(); + + virtual Ref getBlackMatrix(); + Ref createBinarizer(Ref source); + private: + // We'll be using one-D arrays because C++ can't dynamically allocate 2D + // arrays + int* calculateBlackPoints(unsigned char* luminances, + int subWidth, + int subHeight, + int width, + int height); + void calculateThresholdForBlock(unsigned char* luminances, + int subWidth, + int subHeight, + int width, + int height, + int blackPoints[], + Ref const& matrix); + void threshold8x8Block(unsigned char* luminances, + int xoffset, + int yoffset, + int threshold, + int stride, + Ref const& matrix); + }; + +} + +#endif diff --git a/symbian/QZXing/source/zxing/common/IllegalArgumentException.cpp b/symbian/QZXing/source/zxing/common/IllegalArgumentException.cpp index 49068ca5d..6a582f0d2 100644 --- a/symbian/QZXing/source/zxing/common/IllegalArgumentException.cpp +++ b/symbian/QZXing/source/zxing/common/IllegalArgumentException.cpp @@ -1,31 +1,31 @@ -/* - * IllegalArgumentException.cpp - * zxing - * - * Created by Christian Brunschen on 06/05/2008. - * Copyright 2008 Google UK. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -IllegalArgumentException::IllegalArgumentException(const char *msg) : - Exception(msg) { -} -IllegalArgumentException::~IllegalArgumentException() throw() { - -} -} +/* + * IllegalArgumentException.cpp + * zxing + * + * Created by Christian Brunschen on 06/05/2008. + * Copyright 2008 Google UK. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + +IllegalArgumentException::IllegalArgumentException(const char *msg) : + Exception(msg) { +} +IllegalArgumentException::~IllegalArgumentException() throw() { + +} +} diff --git a/symbian/QZXing/source/zxing/common/IllegalArgumentException.h b/symbian/QZXing/source/zxing/common/IllegalArgumentException.h index 9d536c384..0851c6ff1 100644 --- a/symbian/QZXing/source/zxing/common/IllegalArgumentException.h +++ b/symbian/QZXing/source/zxing/common/IllegalArgumentException.h @@ -1,33 +1,33 @@ -#ifndef __ILLEGAL_ARGUMENT_EXCEPTION_H__ -#define __ILLEGAL_ARGUMENT_EXCEPTION_H__ - -/* - * IllegalArgumentException.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { -class IllegalArgumentException : public zxing::Exception { -public: - IllegalArgumentException(const char *msg); - ~IllegalArgumentException() throw(); -}; -} - -#endif // __ILLEGAL_ARGUMENT_EXCEPTION_H__ +#ifndef __ILLEGAL_ARGUMENT_EXCEPTION_H__ +#define __ILLEGAL_ARGUMENT_EXCEPTION_H__ + +/* + * IllegalArgumentException.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { +class IllegalArgumentException : public zxing::Exception { +public: + IllegalArgumentException(const char *msg); + ~IllegalArgumentException() throw(); +}; +} + +#endif // __ILLEGAL_ARGUMENT_EXCEPTION_H__ diff --git a/symbian/QZXing/source/zxing/common/LocalBlockBinarizer.cpp b/symbian/QZXing/source/zxing/common/LocalBlockBinarizer.cpp deleted file mode 100644 index e613043af..000000000 --- a/symbian/QZXing/source/zxing/common/LocalBlockBinarizer.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * LocalBlockBinarizer.cpp - * zxing - * - * Created by Ralf Kistner on 17/10/2009. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - -const int GLOBAL = 0; -const int THRESHOLD = 1; - -LocalBlockBinarizer::LocalBlockBinarizer(Ref source) : - Binarizer(source) { - -} - -LocalBlockBinarizer::~LocalBlockBinarizer() { -} - -Ref LocalBlockBinarizer::estimateBlackRow(int y, Ref row) { - //TODO: implement - return Ref(); -} - -// Calculates the final BitMatrix once for all requests. This could be called once from the -// constructor instead, but there are some advantages to doing it lazily, such as making -// profiling easier, and not doing heavy lifting when callers don't expect it. -Ref LocalBlockBinarizer::estimateBlackMatrix() { - Ref source = getLuminanceSource(); - unsigned char* luminances = source->getMatrix(); - int width = source->getWidth(); - int height = source->getHeight(); - // Sharpening does not really help for 2d barcodes - // sharpenRow(luminances, width, height); - - int subWidth = width >> 3; - int subHeight = height >> 3; - - unsigned char* averages = new unsigned char[subWidth * subHeight]; - unsigned char* types = new unsigned char[subWidth * subHeight]; - - calculateBlackPoints(luminances, averages, types, subWidth, subHeight, width); - - Ref matrix(new BitMatrix(width, height)); - calculateThresholdForBlock(luminances, subWidth, subHeight, width, averages, types, *matrix); - - delete[] averages; - delete[] types; - delete[] luminances; - - return matrix; -} - -// For each 8x8 block in the image, calculate the average black point using a 5x5 grid -// of the blocks around it. Also handles the corner cases, but will ignore up to 7 pixels -// on the right edge and 7 pixels at the bottom of the image if the overall dimensions are not -// multiples of eight. In practice, leaving those pixels white does not seem to be a problem. -void LocalBlockBinarizer::calculateThresholdForBlock(const unsigned char* luminances, int subWidth, int subHeight, - int stride, const unsigned char* averages, const unsigned char* types, BitMatrix& matrix) { - // Calculate global average - int global = 0; - for (int y = 0; y < subHeight; y++) { - for (int x = 0; x < subWidth; x++) { - global += averages[y * subWidth + x]; - } - } - - global /= subWidth * subHeight; - - - for (int y = 0; y < subHeight; y++) { - for (int x = 0; x < subWidth; x++) { - int left = (x > 0) ? x : 1; - left = (left < subWidth - 1) ? left : subWidth - 2; - int top = (y > 0) ? y : 1; - top = (top < subHeight - 1) ? top : subHeight - 2; - int sum = 0; - int contrast = 0; - for (int z = -1; z <= 1; z++) { -// sum += averages[(top + z) * subWidth + left - 2]; - sum += averages[(top + z) * subWidth + left - 1]; - sum += averages[(top + z) * subWidth + left]; - sum += averages[(top + z) * subWidth + left + 1]; -// sum += averages[(top + z) * subWidth + left + 2]; - -// type += types[(top + z) * subWidth + left - 2]; - contrast += types[(top + z) * subWidth + left - 1]; - contrast += types[(top + z) * subWidth + left]; - contrast += types[(top + z) * subWidth + left + 1]; -// type += types[(top + z) * subWidth + left + 2]; - } - int average = sum / 9; - - - if (contrast > 2) - threshold8x8Block(luminances, x << 3, y << 3, average, stride, matrix); -// else if(average < global) // Black -// matrix.setRegion(x << 3, y << 3, 8, 8); - // If white, we don't need to do anything - the block is already cleared. - } - } -} - -// Applies a single threshold to an 8x8 block of pixels. -void LocalBlockBinarizer::threshold8x8Block(const unsigned char* luminances, int xoffset, int yoffset, int threshold, - int stride, BitMatrix& matrix) { - for (int y = 0; y < 8; y++) { - int offset = (yoffset + y) * stride + xoffset; - for (int x = 0; x < 8; x++) { - int pixel = luminances[offset + x]; - if (pixel < threshold) { - matrix.set(xoffset + x, yoffset + y); - } - } - } -} - -// Calculates a single black point for each 8x8 block of pixels and saves it away. -void LocalBlockBinarizer::calculateBlackPoints(const unsigned char* luminances, unsigned char* averages, - unsigned char* types, int subWidth, int subHeight, int stride) { - for (int y = 0; y < subHeight; y++) { - for (int x = 0; x < subWidth; x++) { - int sum = 0; - int min = 255; - int max = 0; - for (int yy = 0; yy < 8; yy++) { - int offset = ((y << 3) + yy) * stride + (x << 3); - const unsigned char* lumo = luminances + offset; - for (int xx = 0; xx < 8; xx++) { - int pixel = lumo[xx]; - sum += pixel; - if (pixel < min) { - min = pixel; - } - if (pixel > max) { - max = pixel; - } - } - } - - // If the contrast is inadequate, we treat the block as white. - // An arbitrary value is chosen here. Higher values mean less noise, but may also reduce - // the ability to recognise some barcodes. - int average = sum >> 6; - int type; - - if (max - min > 30) - type = THRESHOLD; - else - type = GLOBAL; - // int average = (max - min > 24) ? (sum >> 6) : (min-1); - averages[y * subWidth + x] = average; - types[y * subWidth + x] = type; - } - } -} - -// Applies a simple -1 4 -1 box filter with a weight of 2 to each row. -void LocalBlockBinarizer::sharpenRow(unsigned char* luminances, int width, int height) { - for (int y = 0; y < height; y++) { - int offset = y * width; - int left = luminances[offset]; - int center = luminances[offset + 1]; - for (int x = 1; x < width - 1; x++) { - unsigned char right = luminances[offset + x + 1]; - int pixel = ((center << 2) - left - right) >> 1; - // Must clamp values to 0..255 so they will fit in a byte. - if (pixel > 255) { - pixel = 255; - } else if (pixel < 0) { - pixel = 0; - } - luminances[offset + x] = (unsigned char)pixel; - left = center; - center = right; - } - } -} - -} diff --git a/symbian/QZXing/source/zxing/common/LocalBlockBinarizer.h b/symbian/QZXing/source/zxing/common/LocalBlockBinarizer.h deleted file mode 100644 index ba5091e43..000000000 --- a/symbian/QZXing/source/zxing/common/LocalBlockBinarizer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * LocalBlockBinarizer.h - * zxing - * - * Created by Ralf Kistner on 17/10/2009. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LOCALBLOCKBINARIZER_H_ -#define LOCALBLOCKBINARIZER_H_ - -#include -#include - -namespace zxing { -class LocalBlockBinarizer : public Binarizer { -public: - LocalBlockBinarizer(Ref source); - virtual ~LocalBlockBinarizer(); - - virtual Ref estimateBlackMatrix(); - Ref estimateBlackRow(int y, Ref row); - -private: - - void calculateThresholdForBlock(const unsigned char* luminances, int subWidth, int subHeight, - int stride, const unsigned char* averages, const unsigned char* types, BitMatrix& matrix); - void sharpenRow(unsigned char* luminances, int width, int height); - void calculateBlackPoints(const unsigned char* luminances, unsigned char* averages, unsigned char* types, int subWidth, int subHeight, int stride); - void threshold8x8Block(const unsigned char* luminances, int xoffset, int yoffset, int threshold, - int stride, BitMatrix& matrix); -}; -} - -#endif /* LOCALBLOCKBINARIZER_H_ */ diff --git a/symbian/QZXing/source/zxing/common/PerspectiveTransform.cpp b/symbian/QZXing/source/zxing/common/PerspectiveTransform.cpp index 5b4ae2e8b..cfa2e326a 100644 --- a/symbian/QZXing/source/zxing/common/PerspectiveTransform.cpp +++ b/symbian/QZXing/source/zxing/common/PerspectiveTransform.cpp @@ -1,107 +1,107 @@ -/* - * PerspectiveTransform.cpp - * zxing - * - * Created by Christian Brunschen on 12/05/2008. - * Copyright 2008 Google UK. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { -using namespace std; - -PerspectiveTransform::PerspectiveTransform(float inA11, float inA21, - float inA31, float inA12, - float inA22, float inA32, - float inA13, float inA23, - float inA33) : - a11(inA11), a12(inA12), a13(inA13), a21(inA21), a22(inA22), a23(inA23), - a31(inA31), a32(inA32), a33(inA33) {} - -Ref PerspectiveTransform::quadrilateralToQuadrilateral(float x0, float y0, float x1, float y1, - float x2, float y2, float x3, float y3, float x0p, float y0p, float x1p, float y1p, float x2p, float y2p, - float x3p, float y3p) { - Ref qToS = PerspectiveTransform::quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3); - Ref sToQ = - PerspectiveTransform::squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p); - return sToQ->times(qToS); -} - -Ref PerspectiveTransform::squareToQuadrilateral(float x0, float y0, float x1, float y1, float x2, - float y2, float x3, float y3) { - float dy2 = y3 - y2; - float dy3 = y0 - y1 + y2 - y3; - if (dy2 == 0.0f && dy3 == 0.0f) { - Ref result(new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0f, - 0.0f, 1.0f)); - return result; - } else { - float dx1 = x1 - x2; - float dx2 = x3 - x2; - float dx3 = x0 - x1 + x2 - x3; - float dy1 = y1 - y2; - float denominator = dx1 * dy2 - dx2 * dy1; - float a13 = (dx3 * dy2 - dx2 * dy3) / denominator; - float a23 = (dx1 * dy3 - dx3 * dy1) / denominator; - Ref result(new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 - + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0f)); - return result; - } -} - -Ref PerspectiveTransform::quadrilateralToSquare(float x0, float y0, float x1, float y1, float x2, - float y2, float x3, float y3) { - // Here, the adjoint serves as the inverse: - return squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3)->buildAdjoint(); -} - -Ref PerspectiveTransform::buildAdjoint() { - // Adjoint is the transpose of the cofactor matrix: - Ref result(new PerspectiveTransform(a22 * a33 - a23 * a32, a23 * a31 - a21 * a33, a21 * a32 - - a22 * a31, a13 * a32 - a12 * a33, a11 * a33 - a13 * a31, a12 * a31 - a11 * a32, a12 * a23 - a13 * a22, - a13 * a21 - a11 * a23, a11 * a22 - a12 * a21)); - return result; -} - -Ref PerspectiveTransform::times(Ref other) { - Ref result(new PerspectiveTransform(a11 * other->a11 + a21 * other->a12 + a31 * other->a13, - a11 * other->a21 + a21 * other->a22 + a31 * other->a23, a11 * other->a31 + a21 * other->a32 + a31 - * other->a33, a12 * other->a11 + a22 * other->a12 + a32 * other->a13, a12 * other->a21 + a22 - * other->a22 + a32 * other->a23, a12 * other->a31 + a22 * other->a32 + a32 * other->a33, a13 - * other->a11 + a23 * other->a12 + a33 * other->a13, a13 * other->a21 + a23 * other->a22 + a33 - * other->a23, a13 * other->a31 + a23 * other->a32 + a33 * other->a33)); - return result; -} - -void PerspectiveTransform::transformPoints(vector &points) { - int max = points.size(); - for (int i = 0; i < max; i += 2) { - float x = points[i]; - float y = points[i + 1]; - float denominator = a13 * x + a23 * y + a33; - points[i] = (a11 * x + a21 * y + a31) / denominator; - points[i + 1] = (a12 * x + a22 * y + a32) / denominator; - } -} - -ostream& operator<<(ostream& out, const PerspectiveTransform &pt) { - out << pt.a11 << ", " << pt.a12 << ", " << pt.a13 << ", \n"; - out << pt.a21 << ", " << pt.a22 << ", " << pt.a23 << ", \n"; - out << pt.a31 << ", " << pt.a32 << ", " << pt.a33 << "\n"; - return out; -} - -} +/* + * PerspectiveTransform.cpp + * zxing + * + * Created by Christian Brunschen on 12/05/2008. + * Copyright 2008 Google UK. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { +using namespace std; + +PerspectiveTransform::PerspectiveTransform(float inA11, float inA21, + float inA31, float inA12, + float inA22, float inA32, + float inA13, float inA23, + float inA33) : + a11(inA11), a12(inA12), a13(inA13), a21(inA21), a22(inA22), a23(inA23), + a31(inA31), a32(inA32), a33(inA33) {} + +Ref PerspectiveTransform::quadrilateralToQuadrilateral(float x0, float y0, float x1, float y1, + float x2, float y2, float x3, float y3, float x0p, float y0p, float x1p, float y1p, float x2p, float y2p, + float x3p, float y3p) { + Ref qToS = PerspectiveTransform::quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3); + Ref sToQ = + PerspectiveTransform::squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p); + return sToQ->times(qToS); +} + +Ref PerspectiveTransform::squareToQuadrilateral(float x0, float y0, float x1, float y1, float x2, + float y2, float x3, float y3) { + float dx3 = x0 - x1 + x2 - x3; + float dy3 = y0 - y1 + y2 - y3; + if (dx3 == 0.0f && dy3 == 0.0f) { + Ref result(new PerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0, y2 - y1, y0, 0.0f, + 0.0f, 1.0f)); + return result; + } else { + float dx1 = x1 - x2; + float dx2 = x3 - x2; + float dy1 = y1 - y2; + float dy2 = y3 - y2; + float denominator = dx1 * dy2 - dx2 * dy1; + float a13 = (dx3 * dy2 - dx2 * dy3) / denominator; + float a23 = (dx1 * dy3 - dx3 * dy1) / denominator; + Ref result(new PerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + + a13 * y1, y3 - y0 + a23 * y3, y0, a13, a23, 1.0f)); + return result; + } +} + +Ref PerspectiveTransform::quadrilateralToSquare(float x0, float y0, float x1, float y1, float x2, + float y2, float x3, float y3) { + // Here, the adjoint serves as the inverse: + return squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3)->buildAdjoint(); +} + +Ref PerspectiveTransform::buildAdjoint() { + // Adjoint is the transpose of the cofactor matrix: + Ref result(new PerspectiveTransform(a22 * a33 - a23 * a32, a23 * a31 - a21 * a33, a21 * a32 + - a22 * a31, a13 * a32 - a12 * a33, a11 * a33 - a13 * a31, a12 * a31 - a11 * a32, a12 * a23 - a13 * a22, + a13 * a21 - a11 * a23, a11 * a22 - a12 * a21)); + return result; +} + +Ref PerspectiveTransform::times(Ref other) { + Ref result(new PerspectiveTransform(a11 * other->a11 + a21 * other->a12 + a31 * other->a13, + a11 * other->a21 + a21 * other->a22 + a31 * other->a23, a11 * other->a31 + a21 * other->a32 + a31 + * other->a33, a12 * other->a11 + a22 * other->a12 + a32 * other->a13, a12 * other->a21 + a22 + * other->a22 + a32 * other->a23, a12 * other->a31 + a22 * other->a32 + a32 * other->a33, a13 + * other->a11 + a23 * other->a12 + a33 * other->a13, a13 * other->a21 + a23 * other->a22 + a33 + * other->a23, a13 * other->a31 + a23 * other->a32 + a33 * other->a33)); + return result; +} + +void PerspectiveTransform::transformPoints(vector &points) { + int max = points.size(); + for (int i = 0; i < max; i += 2) { + float x = points[i]; + float y = points[i + 1]; + float denominator = a13 * x + a23 * y + a33; + points[i] = (a11 * x + a21 * y + a31) / denominator; + points[i + 1] = (a12 * x + a22 * y + a32) / denominator; + } +} + +ostream& operator<<(ostream& out, const PerspectiveTransform &pt) { + out << pt.a11 << ", " << pt.a12 << ", " << pt.a13 << ", \n"; + out << pt.a21 << ", " << pt.a22 << ", " << pt.a23 << ", \n"; + out << pt.a31 << ", " << pt.a32 << ", " << pt.a33 << "\n"; + return out; +} + +} diff --git a/symbian/QZXing/source/zxing/common/PerspectiveTransform.h b/symbian/QZXing/source/zxing/common/PerspectiveTransform.h index 43b7fa146..357a0b6c7 100644 --- a/symbian/QZXing/source/zxing/common/PerspectiveTransform.h +++ b/symbian/QZXing/source/zxing/common/PerspectiveTransform.h @@ -1,49 +1,49 @@ -#ifndef __PERSPECTIVE_TANSFORM_H__ -#define __PERSPECTIVE_TANSFORM_H__ - -/* - * PerspectiveTransform.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { -class PerspectiveTransform : public Counted { -private: - float a11, a12, a13, a21, a22, a23, a31, a32, a33; - PerspectiveTransform(float a11, float a21, float a31, float a12, float a22, float a32, float a13, float a23, - float a33); - -public: - static Ref - quadrilateralToQuadrilateral(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, - float x0p, float y0p, float x1p, float y1p, float x2p, float y2p, float x3p, float y3p); - static Ref squareToQuadrilateral(float x0, float y0, float x1, float y1, float x2, float y2, - float x3, float y3); - static Ref quadrilateralToSquare(float x0, float y0, float x1, float y1, float x2, float y2, - float x3, float y3); - Ref buildAdjoint(); - Ref times(Ref other); - void transformPoints(std::vector &points); - - friend std::ostream& operator<<(std::ostream& out, const PerspectiveTransform &pt); -}; -} - -#endif // __PERSPECTIVE_TANSFORM_H__ +#ifndef __PERSPECTIVE_TANSFORM_H__ +#define __PERSPECTIVE_TANSFORM_H__ + +/* + * PerspectiveTransform.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { +class PerspectiveTransform : public Counted { +private: + float a11, a12, a13, a21, a22, a23, a31, a32, a33; + PerspectiveTransform(float a11, float a21, float a31, float a12, float a22, float a32, float a13, float a23, + float a33); + +public: + static Ref + quadrilateralToQuadrilateral(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, + float x0p, float y0p, float x1p, float y1p, float x2p, float y2p, float x3p, float y3p); + static Ref squareToQuadrilateral(float x0, float y0, float x1, float y1, float x2, float y2, + float x3, float y3); + static Ref quadrilateralToSquare(float x0, float y0, float x1, float y1, float x2, float y2, + float x3, float y3); + Ref buildAdjoint(); + Ref times(Ref other); + void transformPoints(std::vector &points); + + friend std::ostream& operator<<(std::ostream& out, const PerspectiveTransform &pt); +}; +} + +#endif // __PERSPECTIVE_TANSFORM_H__ diff --git a/symbian/QZXing/source/zxing/common/Point.h b/symbian/QZXing/source/zxing/common/Point.h index cae032b75..1bd071d12 100644 --- a/symbian/QZXing/source/zxing/common/Point.h +++ b/symbian/QZXing/source/zxing/common/Point.h @@ -1,47 +1,47 @@ -#ifndef __POINT_H__ -#define __POINT_H__ - -/* - * Point.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace zxing { -class PointI { -public: - int x; - int y; -}; - -class Point { -public: - Point() : x(0.0f), y(0.0f) {}; - Point(float x_, float y_) : x(x_), y(y_) {}; - - float x; - float y; -}; - -class Line { -public: - Line(Point start_, Point end_) : start(start_), end(end_) {}; - - Point start; - Point end; -}; -} -#endif // POINT_H_ +#ifndef __POINT_H__ +#define __POINT_H__ + +/* + * Point.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace zxing { +class PointI { +public: + int x; + int y; +}; + +class Point { +public: + Point() : x(0.0f), y(0.0f) {}; + Point(float x_, float y_) : x(x_), y(y_) {}; + + float x; + float y; +}; + +class Line { +public: + Line(Point start_, Point end_) : start(start_), end(end_) {}; + + Point start; + Point end; +}; +} +#endif // POINT_H_ diff --git a/symbian/QZXing/source/zxing/common/Str.cpp b/symbian/QZXing/source/zxing/common/Str.cpp index 6259f9477..f2158cd1e 100644 --- a/symbian/QZXing/source/zxing/common/Str.cpp +++ b/symbian/QZXing/source/zxing/common/Str.cpp @@ -1,38 +1,38 @@ -/* - * String.cpp - * zxing - * - * Created by Christian Brunschen on 20/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { -using namespace std; - -String::String(const std::string &text) : - text_(text) { -} -const std::string& String::getText() const { - return text_; -} - -ostream &operator<<(ostream &out, const String &s) { - out << s.text_; - return out; -} - -} +/* + * String.cpp + * zxing + * + * Created by Christian Brunschen on 20/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { +using namespace std; + +String::String(const std::string &text) : + text_(text) { +} +const std::string& String::getText() const { + return text_; +} + +ostream &operator<<(ostream &out, const String &s) { + out << s.text_; + return out; +} + +} diff --git a/symbian/QZXing/source/zxing/common/Str.h b/symbian/QZXing/source/zxing/common/Str.h index 8f093591e..b758c96a7 100644 --- a/symbian/QZXing/source/zxing/common/Str.h +++ b/symbian/QZXing/source/zxing/common/Str.h @@ -1,40 +1,40 @@ -#ifndef __STR_H__ -#define __STR_H__ - -/* - * Str.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { - -class String : public Counted { -private: - std::string text_; -public: - String(const std::string &text); - const std::string &getText() const; - friend std::ostream &operator<<(std::ostream &out, const String &s); -}; - -} - -#endif // __COMMON__STRING_H__ +#ifndef __STR_H__ +#define __STR_H__ + +/* + * Str.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { + +class String : public Counted { +private: + std::string text_; +public: + String(const std::string &text); + const std::string &getText() const; + friend std::ostream &operator<<(std::ostream &out, const String &s); +}; + +} + +#endif // __COMMON__STRING_H__ diff --git a/symbian/QZXing/source/zxing/common/StringUtils.cpp b/symbian/QZXing/source/zxing/common/StringUtils.cpp index 01ac8405c..fd2cf2e09 100644 --- a/symbian/QZXing/source/zxing/common/StringUtils.cpp +++ b/symbian/QZXing/source/zxing/common/StringUtils.cpp @@ -1,175 +1,198 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- - -/* - * Copyright (C) 2010-2011 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -using namespace std; -using namespace zxing; -using namespace zxing::common; - -// N.B.: these are the iconv strings for at least some versions of iconv - -char const* const StringUtils::PLATFORM_DEFAULT_ENCODING = "UTF-8"; -char const* const StringUtils::ASCII = "ASCII"; -char const* const StringUtils::SHIFT_JIS = "SHIFT_JIS"; -char const* const StringUtils::GB2312 = "GBK"; -char const* const StringUtils::EUC_JP = "EUC-JP"; -char const* const StringUtils::UTF8 = "UTF-8"; -char const* const StringUtils::ISO88591 = "ISO8859-1"; -const bool StringUtils::ASSUME_SHIFT_JIS = false; - -string -StringUtils::guessEncoding(unsigned char* bytes, int length, Hashtable const& hints) { - Hashtable::const_iterator i = hints.find(DecodeHints::CHARACTER_SET); - if (i != hints.end()) { - return i->second; - } - // Does it start with the UTF-8 byte order mark? then guess it's UTF-8 - if (length > 3 && - bytes[0] == (unsigned char) 0xEF && - bytes[1] == (unsigned char) 0xBB && - bytes[2] == (unsigned char) 0xBF) { - return UTF8; - } - // For now, merely tries to distinguish ISO-8859-1, UTF-8 and Shift_JIS, - // which should be by far the most common encodings. ISO-8859-1 - // should not have bytes in the 0x80 - 0x9F range, while Shift_JIS - // uses this as a first byte of a two-byte character. If we see this - // followed by a valid second byte in Shift_JIS, assume it is Shift_JIS. - // If we see something else in that second byte, we'll make the risky guess - // that it's UTF-8. - bool canBeISO88591 = true; - bool canBeShiftJIS = true; - bool canBeUTF8 = true; - int utf8BytesLeft = 0; - int maybeDoubleByteCount = 0; - int maybeSingleByteKatakanaCount = 0; - bool sawLatin1Supplement = false; - bool sawUTF8Start = false; - bool lastWasPossibleDoubleByteStart = false; - - for (int i = 0; - i < length && (canBeISO88591 || canBeShiftJIS || canBeUTF8); - i++) { - - int value = bytes[i] & 0xFF; - - // UTF-8 stuff - if (value >= 0x80 && value <= 0xBF) { - if (utf8BytesLeft > 0) { - utf8BytesLeft--; - } - } else { - if (utf8BytesLeft > 0) { - canBeUTF8 = false; - } - if (value >= 0xC0 && value <= 0xFD) { - sawUTF8Start = true; - int valueCopy = value; - while ((valueCopy & 0x40) != 0) { - utf8BytesLeft++; - valueCopy <<= 1; - } - } - } - - // ISO-8859-1 stuff - - if ((value == 0xC2 || value == 0xC3) && i < length - 1) { - // This is really a poor hack. The slightly more exotic characters people might want to put in - // a QR Code, by which I mean the Latin-1 supplement characters (e.g. u-umlaut) have encodings - // that start with 0xC2 followed by [0xA0,0xBF], or start with 0xC3 followed by [0x80,0xBF]. - int nextValue = bytes[i + 1] & 0xFF; - if (nextValue <= 0xBF && - ((value == 0xC2 && nextValue >= 0xA0) || (value == 0xC3 && nextValue >= 0x80))) { - sawLatin1Supplement = true; - } - } - if (value >= 0x7F && value <= 0x9F) { - canBeISO88591 = false; - } - - // Shift_JIS stuff - - if (value >= 0xA1 && value <= 0xDF) { - // count the number of characters that might be a Shift_JIS single-byte Katakana character - if (!lastWasPossibleDoubleByteStart) { - maybeSingleByteKatakanaCount++; - } - } - if (!lastWasPossibleDoubleByteStart && - ((value >= 0xF0 && value <= 0xFF) || value == 0x80 || value == 0xA0)) { - canBeShiftJIS = false; - } - if ((value >= 0x81 && value <= 0x9F) || (value >= 0xE0 && value <= 0xEF)) { - // These start double-byte characters in Shift_JIS. Let's see if it's followed by a valid - // second byte. - if (lastWasPossibleDoubleByteStart) { - // If we just checked this and the last byte for being a valid double-byte - // char, don't check starting on this byte. If this and the last byte - // formed a valid pair, then this shouldn't be checked to see if it starts - // a double byte pair of course. - lastWasPossibleDoubleByteStart = false; - } else { - // ... otherwise do check to see if this plus the next byte form a valid - // double byte pair encoding a character. - lastWasPossibleDoubleByteStart = true; - if (i >= length - 1) { - canBeShiftJIS = false; - } else { - int nextValue = bytes[i + 1] & 0xFF; - if (nextValue < 0x40 || nextValue > 0xFC) { - canBeShiftJIS = false; - } else { - maybeDoubleByteCount++; - } - // There is some conflicting information out there about which bytes can follow which in - // double-byte Shift_JIS characters. The rule above seems to be the one that matches practice. - } - } - } else { - lastWasPossibleDoubleByteStart = false; - } - } - if (utf8BytesLeft > 0) { - canBeUTF8 = false; - } - - // Easy -- if assuming Shift_JIS and no evidence it can't be, done - if (canBeShiftJIS && ASSUME_SHIFT_JIS) { - return SHIFT_JIS; - } - if (canBeUTF8 && sawUTF8Start) { - return UTF8; - } - // Distinguishing Shift_JIS and ISO-8859-1 can be a little tough. The crude heuristic is: - // - If we saw - // - at least 3 bytes that starts a double-byte value (bytes that are rare in ISO-8859-1), or - // - over 5% of bytes could be single-byte Katakana (also rare in ISO-8859-1), - // - and, saw no sequences that are invalid in Shift_JIS, then we conclude Shift_JIS - if (canBeShiftJIS && (maybeDoubleByteCount >= 3 || 20 * maybeSingleByteKatakanaCount > length)) { - return SHIFT_JIS; - } - // Otherwise, we default to ISO-8859-1 unless we know it can't be - if (!sawLatin1Supplement && canBeISO88591) { - return ISO88591; - } - // Otherwise, we take a wild guess with platform encoding - return PLATFORM_DEFAULT_ENCODING; -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- + +/* + * Copyright (C) 2010-2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +using namespace std; +using namespace zxing; +using namespace zxing::common; + +// N.B.: these are the iconv strings for at least some versions of iconv + +char const* const StringUtils::PLATFORM_DEFAULT_ENCODING = "UTF-8"; +char const* const StringUtils::ASCII = "ASCII"; +char const* const StringUtils::SHIFT_JIS = "SHIFT_JIS"; +char const* const StringUtils::GB2312 = "GBK"; +char const* const StringUtils::EUC_JP = "EUC-JP"; +char const* const StringUtils::UTF8 = "UTF-8"; +char const* const StringUtils::ISO88591 = "ISO8859-1"; +const bool StringUtils::ASSUME_SHIFT_JIS = false; + +string +StringUtils::guessEncoding(unsigned char* bytes, int length, + Hashtable const& hints) { + Hashtable::const_iterator i = hints.find(DecodeHints::CHARACTER_SET); + if (i != hints.end()) { + return i->second; + } + typedef bool boolean; + // For now, merely tries to distinguish ISO-8859-1, UTF-8 and Shift_JIS, + // which should be by far the most common encodings. + boolean canBeISO88591 = true; + boolean canBeShiftJIS = true; + boolean canBeUTF8 = true; + int utf8BytesLeft = 0; + //int utf8LowChars = 0; + int utf2BytesChars = 0; + int utf3BytesChars = 0; + int utf4BytesChars = 0; + int sjisBytesLeft = 0; + //int sjisLowChars = 0; + int sjisKatakanaChars = 0; + //int sjisDoubleBytesChars = 0; + int sjisCurKatakanaWordLength = 0; + int sjisCurDoubleBytesWordLength = 0; + int sjisMaxKatakanaWordLength = 0; + int sjisMaxDoubleBytesWordLength = 0; + //int isoLowChars = 0; + //int isoHighChars = 0; + int isoHighOther = 0; + + typedef unsigned char byte; + boolean utf8bom = length > 3 && + bytes[0] == (byte) 0xEF && + bytes[1] == (byte) 0xBB && + bytes[2] == (byte) 0xBF; + + for (int i = 0; + i < length && (canBeISO88591 || canBeShiftJIS || canBeUTF8); + i++) { + + int value = bytes[i] & 0xFF; + + // UTF-8 stuff + if (canBeUTF8) { + if (utf8BytesLeft > 0) { + if ((value & 0x80) == 0) { + canBeUTF8 = false; + } else { + utf8BytesLeft--; + } + } else if ((value & 0x80) != 0) { + if ((value & 0x40) == 0) { + canBeUTF8 = false; + } else { + utf8BytesLeft++; + if ((value & 0x20) == 0) { + utf2BytesChars++; + } else { + utf8BytesLeft++; + if ((value & 0x10) == 0) { + utf3BytesChars++; + } else { + utf8BytesLeft++; + if ((value & 0x08) == 0) { + utf4BytesChars++; + } else { + canBeUTF8 = false; + } + } + } + } + } //else { + //utf8LowChars++; + //} + } + + // ISO-8859-1 stuff + if (canBeISO88591) { + if (value > 0x7F && value < 0xA0) { + canBeISO88591 = false; + } else if (value > 0x9F) { + if (value < 0xC0 || value == 0xD7 || value == 0xF7) { + isoHighOther++; + } //else { + //isoHighChars++; + //} + } //else { + //isoLowChars++; + //} + } + + // Shift_JIS stuff + if (canBeShiftJIS) { + if (sjisBytesLeft > 0) { + if (value < 0x40 || value == 0x7F || value > 0xFC) { + canBeShiftJIS = false; + } else { + sjisBytesLeft--; + } + } else if (value == 0x80 || value == 0xA0 || value > 0xEF) { + canBeShiftJIS = false; + } else if (value > 0xA0 && value < 0xE0) { + sjisKatakanaChars++; + sjisCurDoubleBytesWordLength = 0; + sjisCurKatakanaWordLength++; + if (sjisCurKatakanaWordLength > sjisMaxKatakanaWordLength) { + sjisMaxKatakanaWordLength = sjisCurKatakanaWordLength; + } + } else if (value > 0x7F) { + sjisBytesLeft++; + //sjisDoubleBytesChars++; + sjisCurKatakanaWordLength = 0; + sjisCurDoubleBytesWordLength++; + if (sjisCurDoubleBytesWordLength > sjisMaxDoubleBytesWordLength) { + sjisMaxDoubleBytesWordLength = sjisCurDoubleBytesWordLength; + } + } else { + //sjisLowChars++; + sjisCurKatakanaWordLength = 0; + sjisCurDoubleBytesWordLength = 0; + } + } + } + + if (canBeUTF8 && utf8BytesLeft > 0) { + canBeUTF8 = false; + } + if (canBeShiftJIS && sjisBytesLeft > 0) { + canBeShiftJIS = false; + } + + // Easy -- if there is BOM or at least 1 valid not-single byte character (and no evidence it can't be UTF-8), done + if (canBeUTF8 && (utf8bom || utf2BytesChars + utf3BytesChars + utf4BytesChars > 0)) { + return UTF8; + } + // Easy -- if assuming Shift_JIS or at least 3 valid consecutive not-ascii characters (and no evidence it can't be), done + if (canBeShiftJIS && (ASSUME_SHIFT_JIS || sjisMaxKatakanaWordLength >= 3 || sjisMaxDoubleBytesWordLength >= 3)) { + return SHIFT_JIS; + } + // Distinguishing Shift_JIS and ISO-8859-1 can be a little tough for short words. The crude heuristic is: + // - If we saw + // - only two consecutive katakana chars in the whole text, or + // - at least 10% of bytes that could be "upper" not-alphanumeric Latin1, + // - then we conclude Shift_JIS, else ISO-8859-1 + if (canBeISO88591 && canBeShiftJIS) { + return (sjisMaxKatakanaWordLength == 2 && sjisKatakanaChars == 2) || isoHighOther * 10 >= length + ? SHIFT_JIS : ISO88591; + } + + // Otherwise, try in order ISO-8859-1, Shift JIS, UTF-8 and fall back to default platform encoding + if (canBeISO88591) { + return ISO88591; + } + if (canBeShiftJIS) { + return SHIFT_JIS; + } + if (canBeUTF8) { + return UTF8; + } + // Otherwise, we take a wild guess with platform encoding + return PLATFORM_DEFAULT_ENCODING; +} diff --git a/symbian/QZXing/source/zxing/common/StringUtils.h b/symbian/QZXing/source/zxing/common/StringUtils.h index 87ffb3b15..21385bc69 100644 --- a/symbian/QZXing/source/zxing/common/StringUtils.h +++ b/symbian/QZXing/source/zxing/common/StringUtils.h @@ -1,52 +1,52 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- - -#ifndef __STRING_UTILS__ -#define __STRING_UTILS__ - -/* - * Copyright (C) 2010-2011 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { - namespace common { - class StringUtils; - } -} - -class zxing::common::StringUtils { -private: - static char const* const PLATFORM_DEFAULT_ENCODING; - - StringUtils() {} - -public: - static char const* const ASCII; - static char const* const SHIFT_JIS; - static char const* const GB2312; - static char const* const EUC_JP; - static char const* const UTF8; - static char const* const ISO88591; - static const bool ASSUME_SHIFT_JIS; - - typedef std::map Hashtable; - - static std::string guessEncoding(unsigned char* bytes, int length, Hashtable const& hints); -}; - -#endif +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- + +#ifndef __STRING_UTILS__ +#define __STRING_UTILS__ + +/* + * Copyright (C) 2010-2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { + namespace common { + class StringUtils; + } +} + +class zxing::common::StringUtils { +private: + static char const* const PLATFORM_DEFAULT_ENCODING; + + StringUtils() {} + +public: + static char const* const ASCII; + static char const* const SHIFT_JIS; + static char const* const GB2312; + static char const* const EUC_JP; + static char const* const UTF8; + static char const* const ISO88591; + static const bool ASSUME_SHIFT_JIS; + + typedef std::map Hashtable; + + static std::string guessEncoding(unsigned char* bytes, int length, Hashtable const& hints); +}; + +#endif diff --git a/symbian/QZXing/source/zxing/common/detector/MonochromeRectangleDetector.h b/symbian/QZXing/source/zxing/common/detector/MonochromeRectangleDetector.h index dcce05eab..75d2dd0f3 100644 --- a/symbian/QZXing/source/zxing/common/detector/MonochromeRectangleDetector.h +++ b/symbian/QZXing/source/zxing/common/detector/MonochromeRectangleDetector.h @@ -42,7 +42,7 @@ private: Ref image_; public: - MonochromeRectangleDetector(Ref image) : image_(image) { } + MonochromeRectangleDetector(Ref image) : image_(image) { }; std::vector > detect(); @@ -53,7 +53,7 @@ private: Ref blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, bool horizontal); - int max(int a, float b) { return (float) a > b ? a : (int) b;} + int max(int a, float b) { return (float) a > b ? a : (int) b;}; }; } diff --git a/symbian/QZXing/source/zxing/common/detector/WhiteRectangleDetector.cpp b/symbian/QZXing/source/zxing/common/detector/WhiteRectangleDetector.cpp index 735127b78..4decd31ab 100644 --- a/symbian/QZXing/source/zxing/common/detector/WhiteRectangleDetector.cpp +++ b/symbian/QZXing/source/zxing/common/detector/WhiteRectangleDetector.cpp @@ -33,7 +33,31 @@ int WhiteRectangleDetector::CORR = 1; WhiteRectangleDetector::WhiteRectangleDetector(Ref image) : image_(image) { width_ = image->getWidth(); height_ = image->getHeight(); -}; + + leftInit_ = (width_ - INIT_SIZE) >> 1; + rightInit_ = (width_ + INIT_SIZE) >> 1; + upInit_ = (height_ - INIT_SIZE) >> 1; + downInit_ = (height_ + INIT_SIZE) >> 1; + + if (upInit_ < 0 || leftInit_ < 0 || downInit_ >= height_ || rightInit_ >= width_) { + throw NotFoundException("Invalid dimensions WhiteRectangleDetector"); +} +} + +WhiteRectangleDetector::WhiteRectangleDetector(Ref image, int initSize, int x, int y) : image_(image) { + width_ = image->getWidth(); + height_ = image->getHeight(); + + int halfsize = initSize >> 1; + leftInit_ = x - halfsize; + rightInit_ = x + halfsize; + upInit_ = y - halfsize; + downInit_ = y + halfsize; + + if (upInit_ < 0 || leftInit_ < 0 || downInit_ >= height_ || rightInit_ >= width_) { + throw NotFoundException("Invalid dimensions WhiteRectangleDetector"); + } +} /** *

@@ -50,13 +74,10 @@ WhiteRectangleDetector::WhiteRectangleDetector(Ref image) : image_(im * @throws NotFoundException if no Data Matrix Code can be found */ std::vector > WhiteRectangleDetector::detect() { - int left = (width_ - INIT_SIZE) >> 1; - int right = (width_ + INIT_SIZE) >> 1; - int up = (height_ - INIT_SIZE) >> 1; - int down = (height_ + INIT_SIZE) >> 1; - if (up < 0 || left < 0 || down >= height_ || right >= width_) { - throw NotFoundException("Invalid dimensions WhiteRectangleDetector"); - } + int left = leftInit_; + int right = rightInit_; + int up = upInit_; + int down = downInit_; bool sizeExceeded = false; bool aBlackPointFoundOnBorder = true; diff --git a/symbian/QZXing/source/zxing/common/detector/WhiteRectangleDetector.h b/symbian/QZXing/source/zxing/common/detector/WhiteRectangleDetector.h index 87de26a6b..2a8b8a4ff 100644 --- a/symbian/QZXing/source/zxing/common/detector/WhiteRectangleDetector.h +++ b/symbian/QZXing/source/zxing/common/detector/WhiteRectangleDetector.h @@ -38,9 +38,14 @@ class WhiteRectangleDetector : public Counted { Ref image_; int width_; int height_; + int leftInit_; + int rightInit_; + int downInit_; + int upInit_; public: WhiteRectangleDetector(Ref image); + WhiteRectangleDetector(Ref image, int initSize, int x, int y); std::vector > detect(); private: diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/GF256.cpp b/symbian/QZXing/source/zxing/common/reedsolomon/GF256.cpp deleted file mode 100644 index 51b621e8e..000000000 --- a/symbian/QZXing/source/zxing/common/reedsolomon/GF256.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * GF256.cpp - * zxing - * - * Created by Christian Brunschen on 05/05/2008. - * Copyright 2008 Google UK. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace zxing { -using namespace std; - -static inline ArrayRef makeArray(int value) { - ArrayRef valuesRef(new Array (value, 1)); - return valuesRef; -} - -static inline Ref refPoly(GF256 &field, int value) { - ArrayRef values(makeArray(value)); - Ref result(new GF256Poly(field, values)); - return result; -} - -GF256::GF256(int primitive) : - exp_(256, (const int)0), log_(256, (const int)0), zero_(refPoly(*this, 0)), one_(refPoly(*this, 1)) { - int x = 1; - for (int i = 0; i < 256; i++) { - exp_[i] = x; - x <<= 1; - if (x >= 0x100) { - x ^= primitive; - } - } - - // log(0) == 0, but should never be used - log_[0] = 0; - for (int i = 0; i < 255; i++) { - log_[exp_[i]] = i; - } -} - -Ref GF256::getZero() { - return zero_; -} - -Ref GF256::getOne() { - return one_; -} - -Ref GF256::buildMonomial(int degree, int coefficient) { -#ifdef DEBUG - cout << __FUNCTION__ << "\n"; -#endif - if (degree < 0) { - throw IllegalArgumentException("Degree must be non-negative"); - } - if (coefficient == 0) { - return zero_; - } - int nCoefficients = degree + 1; - ArrayRef coefficients(new Array (nCoefficients)); - coefficients[0] = coefficient; - Ref result(new GF256Poly(*this, coefficients)); - return result; -} - -int GF256::addOrSubtract(int a, int b) { - return a ^ b; -} - -int GF256::exp(int a) { - return exp_[a]; -} - -int GF256::log(int a) { - if (a == 0) { - throw IllegalArgumentException("Cannot take the logarithm of 0"); - } - return log_[a]; -} - -int GF256::inverse(int a) { - if (a == 0) { - throw IllegalArgumentException("Cannot calculate the inverse of 0"); - } - return exp_[255 - log_[a]]; -} - -int GF256::multiply(int a, int b) { - if (a == 0 || b == 0) { - return 0; - } - int logSum = log_[a] + log_[b]; - // index is a sped-up alternative to logSum % 255 since sum - // is in [0,510]. Thanks to jmsachs for the idea - return exp_[(logSum & 0xFF) + (logSum >> 8)]; -} - -GF256 GF256::QR_CODE_FIELD(0x011D); // x^8 + x^4 + x^3 + x^2 + 1 -GF256 GF256::DATA_MATRIX_FIELD(0x012D); // x^8 + x^5 + x^3 + x^2 + 1 - -ostream& operator<<(ostream& out, const GF256& field) { - out << "Field[\nexp=("; - out << field.exp_[0]; - for (int i = 1; i < 256; i++) { - out << "," << field.exp_[i]; - } - out << "),\nlog=("; - out << field.log_[0]; - for (int i = 1; i < 256; i++) { - out << "," << field.log_[i]; - } - out << ")\n]"; - return out; -} - -} diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/GF256.h b/symbian/QZXing/source/zxing/common/reedsolomon/GF256.h deleted file mode 100644 index 821fba505..000000000 --- a/symbian/QZXing/source/zxing/common/reedsolomon/GF256.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef __GF256_H__ -#define __GF256_H__ - -/* - * GF256.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -class GF256Poly; - -class GF256 { - /** - *

This class contains utility methods for performing mathematical - * operations over the Galois Field GF(256). Operations use a given - * primitive polynomial in calculations.

- * - *

Throughout this package, elements of GF(256) are represented as an - * int for convenience and speed (but at the cost of memory). - * Only the bottom 8 bits are really used.

- * - * @author srowen@google.com (Sean Owen) - * @author christian.brunschen@gmail.com (Christian Brunschen) - */ -private: - std::vector exp_; - std::vector log_; - Ref zero_; - Ref one_; - - GF256(int primitive); - -public: - Ref getZero(); - Ref getOne(); - Ref buildMonomial(int degree, int coefficient); - static int addOrSubtract(int a, int b); - int exp(int a); - int log(int a); - int inverse(int a); - int multiply(int a, int b); - - static GF256 QR_CODE_FIELD; - static GF256 DATA_MATRIX_FIELD; - - friend std::ostream& operator<<(std::ostream& out, const GF256& field); -}; -} - -#endif // __GF256_H__ diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/GF256Poly.cpp b/symbian/QZXing/source/zxing/common/reedsolomon/GF256Poly.cpp deleted file mode 100644 index 2c7f4812e..000000000 --- a/symbian/QZXing/source/zxing/common/reedsolomon/GF256Poly.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* - * GF256Poly.cpp - * zxing - * - * Created by Christian Brunschen on 05/05/2008. - * Copyright 2008 Google UK. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace zxing { -using namespace std; - -void GF256Poly::fixCoefficients() { - int coefficientsLength = coefficients.size(); - if (coefficientsLength > 1 && coefficients[0] == 0) { - // Leading term must be non-zero for anything except - // the constant polynomial "0" - int firstNonZero = 1; - while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0) { - firstNonZero++; - } - if (firstNonZero == coefficientsLength) { - coefficientsLength = field.getZero()->coefficients.size(); - coefficients.reset(new Array (coefficientsLength)); - *coefficients = *(field.getZero()->coefficients); - } else { - ArrayRef c(coefficients); - coefficientsLength -= firstNonZero; - coefficients.reset(new Array (coefficientsLength)); - for (int i = 0; i < coefficientsLength; i++) { - coefficients[i] = c[i + firstNonZero]; - } - } - } -} - -GF256Poly::GF256Poly(GF256 &f, ArrayRef c) : - Counted(), field(f), coefficients(c) { - fixCoefficients(); -} - -GF256Poly::~GF256Poly() { - -} - -int GF256Poly::getDegree() { - return coefficients.size() - 1; -} - -bool GF256Poly::isZero() { - return coefficients[0] == 0; -} - -int GF256Poly::getCoefficient(int degree) { - return coefficients[coefficients.size() - 1 - degree]; -} - -int GF256Poly::evaluateAt(int a) { - if (a == 0) { - return getCoefficient(0); - } - int size = coefficients.size(); - if (a == 1) { - // Just the sum of the coefficients - int result = 0; - for (int i = 0; i < size; i++) { - result = GF256::addOrSubtract(result, coefficients[i]); - } - return result; - } - int result = coefficients[0]; - for (int i = 1; i < size; i++) { - result = GF256::addOrSubtract(field.multiply(a, result), coefficients[i]); - } - return result; -} - -Ref GF256Poly::addOrSubtract(Ref b) { - if (&field != &b->field) { - throw IllegalArgumentException("Fields must be the same"); - } - if (isZero()) { - return b; - } - if (b->isZero()) { - return Ref(this); - } - - ArrayRef largerCoefficients = coefficients; - ArrayRef smallerCoefficients = b->coefficients; - if (smallerCoefficients.size() > largerCoefficients.size()) { - ArrayRef tmp(smallerCoefficients); - smallerCoefficients = largerCoefficients; - largerCoefficients = tmp; - } - - ArrayRef sumDiff(new Array (largerCoefficients.size())); - - unsigned lengthDiff = largerCoefficients.size() - smallerCoefficients.size(); - for (unsigned i = 0; i < lengthDiff; i++) { - sumDiff[i] = largerCoefficients[i]; - } - for (unsigned i = lengthDiff; i < largerCoefficients.size(); i++) { - sumDiff[i] = GF256::addOrSubtract(smallerCoefficients[i - lengthDiff], largerCoefficients[i]); - } - return Ref(new GF256Poly(field, sumDiff)); -} - -Ref GF256Poly::multiply(Ref b) { - if (&field != &b->field) { - throw IllegalArgumentException("Fields must be the same"); - } - if (isZero() || b->isZero()) { - return field.getZero(); - } - ArrayRef aCoefficients = coefficients; - int aLength = aCoefficients.size(); - ArrayRef bCoefficients = b->coefficients; - int bLength = bCoefficients.size(); - int productLength = aLength + bLength - 1; - ArrayRef product(new Array (productLength)); - for (int i = 0; i < aLength; i++) { - int aCoeff = aCoefficients[i]; - for (int j = 0; j < bLength; j++) { - product[i + j] = GF256::addOrSubtract(product[i + j], field.multiply(aCoeff, bCoefficients[j])); - } - } - - return Ref(new GF256Poly(field, product)); -} - -Ref GF256Poly::multiply(int scalar) { - if (scalar == 0) { - return field.getZero(); - } - if (scalar == 1) { - return Ref(this); - } - int size = coefficients.size(); - ArrayRef product(new Array (size)); - for (int i = 0; i < size; i++) { - product[i] = field.multiply(coefficients[i], scalar); - } - return Ref(new GF256Poly(field, product)); -} - -Ref GF256Poly::multiplyByMonomial(int degree, int coefficient) { - if (degree < 0) { - throw IllegalArgumentException("Degree must be non-negative"); - } - if (coefficient == 0) { - return field.getZero(); - } - int size = coefficients.size(); - ArrayRef product(new Array (size + degree)); - for (int i = 0; i < size; i++) { - product[i] = field.multiply(coefficients[i], coefficient); - } - return Ref(new GF256Poly(field, product)); -} - -const char *GF256Poly::description() const { - ostringstream result; - result << *this; - return result.str().c_str(); -} - -ostream& operator<<(ostream& out, const GF256Poly& p) { - GF256Poly &poly = const_cast(p); - out << "Poly[" << poly.coefficients.size() << "]"; - if (poly.coefficients.size() > 0) { - out << "(" << poly.coefficients[0]; - for (unsigned i = 1; i < poly.coefficients.size(); i++) { - out << "," << poly.coefficients[i]; - } - out << ")"; - } - return out; -} - -} diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/GF256Poly.h b/symbian/QZXing/source/zxing/common/reedsolomon/GF256Poly.h deleted file mode 100644 index 0397be60b..000000000 --- a/symbian/QZXing/source/zxing/common/reedsolomon/GF256Poly.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __GF256_POLY_H__ -#define __GF256_POLY_H__ - -/* - * GF256Poly.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -class GF256; - -class GF256Poly : public Counted { -private: - GF256 &field; - ArrayRef coefficients; - void fixCoefficients(); -public: - GF256Poly(GF256 &field, ArrayRef c); - ~GF256Poly(); - - int getDegree(); - bool isZero(); - int getCoefficient(int degree); - int evaluateAt(int a); - Ref addOrSubtract(Ref other); - Ref multiply(Ref other); - Ref multiply(int scalar); - Ref multiplyByMonomial(int degree, int coefficient); - const char *description() const; - friend std::ostream& operator<<(std::ostream& out, const GF256Poly& poly); - -}; -} - -#endif // __GF256_POLY_H__ diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/GenericGF.cpp b/symbian/QZXing/source/zxing/common/reedsolomon/GenericGF.cpp new file mode 100644 index 000000000..7e35cbc7b --- /dev/null +++ b/symbian/QZXing/source/zxing/common/reedsolomon/GenericGF.cpp @@ -0,0 +1,147 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * GenericGF.cpp + * zxing + * + * Created by Lukas Stabe on 13/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +using zxing::GenericGF; +using zxing::GenericGFPoly; +using zxing::Ref; + +Ref GenericGF::QR_CODE_FIELD_256(new GenericGF(0x011D, 256)); +Ref GenericGF::DATA_MATRIX_FIELD_256(new GenericGF(0x012D, 256)); +Ref GenericGF::AZTEC_PARAM(new GenericGF(0x13, 16)); +Ref GenericGF::AZTEC_DATA_6(new GenericGF(0x43, 64)); +Ref GenericGF::AZTEC_DATA_8(GenericGF::DATA_MATRIX_FIELD_256); +Ref GenericGF::AZTEC_DATA_10(new GenericGF(0x409, 1024)); +Ref GenericGF::AZTEC_DATA_12(new GenericGF(0x1069, 4096)); + + +static int INITIALIZATION_THRESHOLD = 0; + +GenericGF::GenericGF(int primitive, int size) + : size_(size), primitive_(primitive), initialized_(false) { + if (size <= INITIALIZATION_THRESHOLD) { + initialize(); + } +} + +void GenericGF::initialize() { + //expTable_ = std::vector(size_, (const int) 0); + //logTable_ = std::vector(size_, (const int) 0); + expTable_.resize(size_); + logTable_.resize(size_); + + int x = 1; + + for (int i = 0; i < size_; i++) { + expTable_[i] = x; + x <<= 1; // x = x * 2; we're assuming the generator alpha is 2 + if (x >= size_) { + x ^= primitive_; + x &= size_-1; + } + } + for (int i = 0; i < size_-1; i++) { + logTable_[expTable_[i]] = i; + } + //logTable_[0] == 0 but this should never be used + + zero_ = Ref(new GenericGFPoly(Ref(this), ArrayRef(new Array(1)))); + zero_->getCoefficients()[0] = 0; + one_ = Ref(new GenericGFPoly(Ref(this), ArrayRef(new Array(1)))); + one_->getCoefficients()[0] = 1; + + initialized_ = true; +} + +void GenericGF::checkInit() { + if (!initialized_) { + initialize(); + } +} + +Ref GenericGF::getZero() { + checkInit(); + return zero_; +} + +Ref GenericGF::getOne() { + checkInit(); + return one_; +} + +Ref GenericGF::buildMonomial(int degree, int coefficient) { + checkInit(); + + if (degree < 0) { + throw IllegalArgumentException("Degree must be non-negative"); + } + if (coefficient == 0) { + return zero_; + } + ArrayRef coefficients(new Array(degree + 1)); + coefficients[0] = coefficient; + + //return new GenericGFPoly(this, coefficients); + return Ref(new GenericGFPoly(Ref(this), coefficients)); +} + +int GenericGF::addOrSubtract(int a, int b) { + return a ^ b; +} + +int GenericGF::exp(int a) { + checkInit(); + return expTable_[a]; +} + +int GenericGF::log(int a) { + checkInit(); + if (a == 0) { + throw IllegalArgumentException("cannot give log(0)"); + } + return logTable_[a]; +} + +int GenericGF::inverse(int a) { + checkInit(); + if (a == 0) { + throw IllegalArgumentException("Cannot calculate the inverse of 0"); + } + return expTable_[size_ - logTable_[a] - 1]; +} + +int GenericGF::multiply(int a, int b) { + checkInit(); + + if (a == 0 || b == 0) { + return 0; + } + + return expTable_[(logTable_[a] + logTable_[b]) % (size_ - 1)]; + } + +int GenericGF::getSize() { + return size_; +} diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/GenericGF.h b/symbian/QZXing/source/zxing/common/reedsolomon/GenericGF.h new file mode 100644 index 000000000..0dd7e293d --- /dev/null +++ b/symbian/QZXing/source/zxing/common/reedsolomon/GenericGF.h @@ -0,0 +1,78 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * GenericGF.h + * zxing + * + * Created by Lukas Stabe on 13/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GENERICGF_H +#define GENERICGF_H + +#include +#include + +namespace zxing { + class GenericGFPoly; + + class GenericGF : public Counted { + + private: + std::vector expTable_; + std::vector logTable_; + Ref zero_; + Ref one_; + int size_; + int primitive_; + bool initialized_; + + void initialize(); + void checkInit(); + + public: + static Ref AZTEC_DATA_12; + static Ref AZTEC_DATA_10; + static Ref AZTEC_DATA_8; + static Ref AZTEC_DATA_6; + static Ref AZTEC_PARAM; + static Ref QR_CODE_FIELD_256; + static Ref DATA_MATRIX_FIELD_256; + + GenericGF(int primitive, int size); + + Ref getZero(); + Ref getOne(); + int getSize(); + Ref buildMonomial(int degree, int coefficient); + + static int addOrSubtract(int a, int b); + int exp(int a); + int log(int a); + int inverse(int a); + int multiply(int a, int b); + + bool operator==(GenericGF other) { + return (other.getSize() == this->size_ && + other.primitive_ == this->primitive_); + } + + //#warning todo: add print method + + }; +} + +#endif //GENERICGF_H + diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/GenericGFPoly.cpp b/symbian/QZXing/source/zxing/common/reedsolomon/GenericGFPoly.cpp new file mode 100644 index 000000000..464253dcb --- /dev/null +++ b/symbian/QZXing/source/zxing/common/reedsolomon/GenericGFPoly.cpp @@ -0,0 +1,215 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * GenericGFPoly.cpp + * zxing + * + * Created by Lukas Stabe on 13/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +using zxing::GenericGFPoly; +using zxing::ArrayRef; +using zxing::Ref; + +GenericGFPoly::GenericGFPoly(Ref field, + ArrayRef coefficients) + : field_(field) { + if (coefficients.size() == 0) { + throw IllegalArgumentException("need coefficients"); + } + int coefficientsLength = coefficients.size(); + if (coefficientsLength > 1 && coefficients[0] == 0) { + // Leading term must be non-zero for anything except the constant polynomial "0" + int firstNonZero = 1; + while (firstNonZero < coefficientsLength && coefficients[firstNonZero] == 0) { + firstNonZero++; + } + if (firstNonZero == coefficientsLength) { + coefficients_ = field->getZero()->getCoefficients(); + } else { + coefficients_ = ArrayRef(new Array(coefficientsLength-firstNonZero)); + for (int i = 0; i < (int)coefficients_.size(); i++) { + coefficients_[i] = coefficients[i + firstNonZero]; + } + } + } else { + coefficients_ = coefficients; + } +} + +ArrayRef GenericGFPoly::getCoefficients() { + return coefficients_; +} + +int GenericGFPoly::getDegree() { + return coefficients_.size() - 1; +} + +bool GenericGFPoly::isZero() { + return coefficients_[0] == 0; +} + +int GenericGFPoly::getCoefficient(int degree) { + return coefficients_[coefficients_.size() - 1 - degree]; +} + +int GenericGFPoly::evaluateAt(int a) { + if (a == 0) { + // Just return the x^0 coefficient + return getCoefficient(0); + } + + int size = coefficients_.size(); + if (a == 1) { + // Just the sum of the coefficients + int result = 0; + for (int i = 0; i < size; i++) { + result = GenericGF::addOrSubtract(result, coefficients_[i]); + } + return result; + } + int result = coefficients_[0]; + for (int i = 1; i < size; i++) { + result = GenericGF::addOrSubtract(field_->multiply(a, result), coefficients_[i]); + } + return result; +} + +Ref GenericGFPoly::addOrSubtract(Ref other) { + if (!(field_.object_ == other->field_.object_)) { + throw IllegalArgumentException("GenericGFPolys do not have same GenericGF field"); + } + if (isZero()) { + return other; + } + if (other->isZero()) { + return Ref(this); + } + + ArrayRef smallerCoefficients = coefficients_; + ArrayRef largerCoefficients = other->getCoefficients(); + if (smallerCoefficients.size() > largerCoefficients.size()) { + ArrayRef temp = smallerCoefficients; + smallerCoefficients = largerCoefficients; + largerCoefficients = temp; + } + + ArrayRef sumDiff(new Array(largerCoefficients.size())); + int lengthDiff = largerCoefficients.size() - smallerCoefficients.size(); + // Copy high-order terms only found in higher-degree polynomial's coefficients + for (int i = 0; i < lengthDiff; i++) { + sumDiff[i] = largerCoefficients[i]; + } + + for (int i = lengthDiff; i < (int)largerCoefficients.size(); i++) { + sumDiff[i] = GenericGF::addOrSubtract(smallerCoefficients[i-lengthDiff], + largerCoefficients[i]); + } + + return Ref(new GenericGFPoly(field_, sumDiff)); +} + +Ref GenericGFPoly::multiply(Ref other) { + if (!(field_.object_ == other->field_.object_)) { + throw IllegalArgumentException("GenericGFPolys do not have same GenericGF field"); + } + + if (isZero() || other->isZero()) { + return field_->getZero(); + } + + ArrayRef aCoefficients = coefficients_; + int aLength = aCoefficients.size(); + + ArrayRef bCoefficients = other->getCoefficients(); + int bLength = bCoefficients.size(); + + ArrayRef product(new Array(aLength + bLength - 1)); + for (int i = 0; i < aLength; i++) { + int aCoeff = aCoefficients[i]; + for (int j = 0; j < bLength; j++) { + product[i+j] = GenericGF::addOrSubtract(product[i+j], + field_->multiply(aCoeff, bCoefficients[j])); + } + } + + return Ref(new GenericGFPoly(field_, product)); +} + +Ref GenericGFPoly::multiply(int scalar) { + if (scalar == 0) { + return field_->getZero(); + } + if (scalar == 1) { + return Ref(this); + } + int size = coefficients_.size(); + ArrayRef product(new Array(size)); + for (int i = 0; i < size; i++) { + product[i] = field_->multiply(coefficients_[i], scalar); + } + return Ref(new GenericGFPoly(field_, product)); +} + +Ref GenericGFPoly::multiplyByMonomial(int degree, int coefficient) { + if (degree < 0) { + throw IllegalArgumentException("degree must not be less then 0"); + } + if (coefficient == 0) { + return field_->getZero(); + } + int size = coefficients_.size(); + ArrayRef product(new Array(size+degree)); + for (int i = 0; i < size; i++) { + product[i] = field_->multiply(coefficients_[i], coefficient); + } + return Ref(new GenericGFPoly(field_, product)); +} + +std::vector > GenericGFPoly::divide(Ref other) { + if (!(field_.object_ == other->field_.object_)) { + throw IllegalArgumentException("GenericGFPolys do not have same GenericGF field"); + } + if (other->isZero()) { + throw IllegalArgumentException("divide by 0"); + } + + Ref quotient = field_->getZero(); + Ref remainder = Ref(this); + + int denominatorLeadingTerm = other->getCoefficient(other->getDegree()); + int inverseDenominatorLeadingTerm = field_->inverse(denominatorLeadingTerm); + + while (remainder->getDegree() >= other->getDegree() && !remainder->isZero()) { + int degreeDifference = remainder->getDegree() - other->getDegree(); + int scale = field_->multiply(remainder->getCoefficient(remainder->getDegree()), + inverseDenominatorLeadingTerm); + Ref term = other->multiplyByMonomial(degreeDifference, scale); + Ref iterationQuotiont = field_->buildMonomial(degreeDifference, + scale); + quotient = quotient->addOrSubtract(iterationQuotiont); + remainder = remainder->addOrSubtract(term); + } + + std::vector > returnValue; + returnValue[0] = quotient; + returnValue[1] = remainder; + return returnValue; +} diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/GenericGFPoly.h b/symbian/QZXing/source/zxing/common/reedsolomon/GenericGFPoly.h new file mode 100644 index 000000000..663a0a42a --- /dev/null +++ b/symbian/QZXing/source/zxing/common/reedsolomon/GenericGFPoly.h @@ -0,0 +1,54 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * GenericGFPoly.h + * zxing + * + * Created by Lukas Stabe on 13/02/2012. + * Copyright 2012 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GENERICGFPOLY_H +#define GENERICGFPOLY_H + +#include +#include +#include + +namespace zxing { + class GenericGF; + + class GenericGFPoly : public Counted { + private: + Ref field_; + ArrayRef coefficients_; + + public: + GenericGFPoly(Ref field, ArrayRef coefficients); + ArrayRef getCoefficients(); + int getDegree(); + bool isZero(); + int getCoefficient(int degree); + int evaluateAt(int a); + Ref addOrSubtract(Ref other); + Ref multiply(Ref other); + Ref multiply(int scalar); + Ref multiplyByMonomial(int degree, int coefficient); + std::vector > divide(Ref other); + + //#warning todo: add print method + }; +} + +#endif //GENERICGFPOLY_H \ No newline at end of file diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonDecoder.cpp b/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonDecoder.cpp index 58a95a8e1..1868db9d7 100644 --- a/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonDecoder.cpp +++ b/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonDecoder.cpp @@ -1,193 +1,199 @@ -/* - * ReedSolomonDecoder.cpp - * zxing - * - * Created by Christian Brunschen on 05/05/2008. - * Copyright 2008 Google UK. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#include -#include -#include -#include -#include - -using namespace std; - -namespace zxing { - -ReedSolomonDecoder::ReedSolomonDecoder(GF256 &fld) : - field(fld) { -} - -ReedSolomonDecoder::~ReedSolomonDecoder() { -} - -void ReedSolomonDecoder::decode(ArrayRef received, int twoS) { - - Ref poly(new GF256Poly(field, received)); - - -#ifdef DEBUG - cout << "decoding with poly " << *poly << "\n"; -#endif - - ArrayRef syndromeCoefficients(new Array (twoS)); - - -#ifdef DEBUG - cout << "syndromeCoefficients array = " << - syndromeCoefficients.array_ << "\n"; -#endif - - bool noError = true; - for (int i = 0; i < twoS; i++) { - int eval = poly->evaluateAt(field.exp(i)); - syndromeCoefficients[syndromeCoefficients->size() - 1 - i] = eval; - if (eval != 0) { - noError = false; - } - } - if (noError) { - return; - } - - Ref syndrome(new GF256Poly(field, syndromeCoefficients)); - Ref monomial(field.buildMonomial(twoS, 1)); - vector > sigmaOmega(runEuclideanAlgorithm(monomial, syndrome, twoS)); - ArrayRef errorLocations = findErrorLocations(sigmaOmega[0]); - ArrayRef errorMagitudes = findErrorMagnitudes(sigmaOmega[1], errorLocations); - for (unsigned i = 0; i < errorLocations->size(); i++) { - int position = received->size() - 1 - field.log(errorLocations[i]); - //TODO: check why the position would be invalid - if (position < 0 || (size_t)position >= received.size()) - throw IllegalArgumentException("Invalid position (ReedSolomonDecoder)"); - received[position] = GF256::addOrSubtract(received[position], errorMagitudes[i]); - } -} - -vector > ReedSolomonDecoder::runEuclideanAlgorithm(Ref a, Ref b, int R) { - // Assume a's degree is >= b's - if (a->getDegree() < b->getDegree()) { - Ref tmp = a; - a = b; - b = tmp; - } - - Ref rLast(a); - Ref r(b); - Ref sLast(field.getOne()); - Ref s(field.getZero()); - Ref tLast(field.getZero()); - Ref t(field.getOne()); - - - // Run Euclidean algorithm until r's degree is less than R/2 - while (r->getDegree() >= R / 2) { - Ref rLastLast(rLast); - Ref sLastLast(sLast); - Ref tLastLast(tLast); - rLast = r; - sLast = s; - tLast = t; - - - // Divide rLastLast by rLast, with quotient q and remainder r - if (rLast->isZero()) { - // Oops, Euclidean algorithm already terminated? - throw ReedSolomonException("r_{i-1} was zero"); - } - r = rLastLast; - Ref q(field.getZero()); - int denominatorLeadingTerm = rLast->getCoefficient(rLast->getDegree()); - int dltInverse = field.inverse(denominatorLeadingTerm); - while (r->getDegree() >= rLast->getDegree() && !r->isZero()) { - int degreeDiff = r->getDegree() - rLast->getDegree(); - int scale = field.multiply(r->getCoefficient(r->getDegree()), dltInverse); - q = q->addOrSubtract(field.buildMonomial(degreeDiff, scale)); - r = r->addOrSubtract(rLast->multiplyByMonomial(degreeDiff, scale)); - } - - s = q->multiply(sLast)->addOrSubtract(sLastLast); - t = q->multiply(tLast)->addOrSubtract(tLastLast); - } - - int sigmaTildeAtZero = t->getCoefficient(0); - if (sigmaTildeAtZero == 0) { - throw ReedSolomonException("sigmaTilde(0) was zero"); - } - - int inverse = field.inverse(sigmaTildeAtZero); - Ref sigma(t->multiply(inverse)); - Ref omega(r->multiply(inverse)); - - -#ifdef DEBUG - cout << "t = " << *t << "\n"; - cout << "r = " << *r << "\n"; - cout << "sigma = " << *sigma << "\n"; - cout << "omega = " << *omega << "\n"; -#endif - - vector > result(2); - result[0] = sigma; - result[1] = omega; - return result; -} - -ArrayRef ReedSolomonDecoder::findErrorLocations(Ref errorLocator) { - // This is a direct application of Chien's search - int numErrors = errorLocator->getDegree(); - if (numErrors == 1) { // shortcut - ArrayRef result(1); - result[0] = errorLocator->getCoefficient(1); - return result; - } - ArrayRef result(numErrors); - int e = 0; - for (int i = 1; i < 256 && e < numErrors; i++) { - // cout << "errorLocator(" << i << ") == " << errorLocator->evaluateAt(i) << "\n"; - if (errorLocator->evaluateAt(i) == 0) { - result[e] = field.inverse(i); - e++; - } - } - if (e != numErrors) { - throw ReedSolomonException("Error locator degree does not match number of roots"); - } - return result; -} - -ArrayRef ReedSolomonDecoder::findErrorMagnitudes(Ref errorEvaluator, ArrayRef errorLocations) { - // This is directly applying Forney's Formula - int s = errorLocations.size(); - ArrayRef result(s); - for (int i = 0; i < s; i++) { - int xiInverse = field.inverse(errorLocations[i]); - int denominator = 1; - for (int j = 0; j < s; j++) { - if (i != j) { - denominator = field.multiply(denominator, GF256::addOrSubtract(1, field.multiply(errorLocations[j], - xiInverse))); - } - } - result[i] = field.multiply(errorEvaluator->evaluateAt(xiInverse), field.inverse(denominator)); - } - return result; -} -} +/* + * ReedSolomonDecoder.cpp + * zxing + * + * Created by Christian Brunschen on 05/05/2008. + * Copyright 2008 Google UK. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +using namespace std; + +namespace zxing { + +ReedSolomonDecoder::ReedSolomonDecoder(Ref fld) : + field(fld) { +} + +ReedSolomonDecoder::~ReedSolomonDecoder() { +} + +void ReedSolomonDecoder::decode(ArrayRef received, int twoS) { + + Ref poly(new GenericGFPoly(field, received)); + + +#ifdef DEBUG + cout << "decoding with poly " << *poly << "\n"; +#endif + + ArrayRef syndromeCoefficients(new Array (twoS)); + + +#ifdef DEBUG + cout << "syndromeCoefficients array = " << + syndromeCoefficients.array_ << "\n"; +#endif + + bool dataMatrix = (field.object_ == GenericGF::DATA_MATRIX_FIELD_256.object_); + bool noError = true; + for (int i = 0; i < twoS; i++) { + int eval = poly->evaluateAt(field->exp(dataMatrix ? i + 1 : i)); + syndromeCoefficients[syndromeCoefficients->size() - 1 - i] = eval; + if (eval != 0) { + noError = false; + } + } + if (noError) { + return; + } + + Ref syndrome(new GenericGFPoly(field, syndromeCoefficients)); + Ref monomial = field->buildMonomial(twoS, 1); + vector > sigmaOmega = runEuclideanAlgorithm(monomial, syndrome, twoS); + ArrayRef errorLocations = findErrorLocations(sigmaOmega[0]); + ArrayRef errorMagitudes = findErrorMagnitudes(sigmaOmega[1], errorLocations, dataMatrix); + for (unsigned i = 0; i < errorLocations->size(); i++) { + int position = received->size() - 1 - field->log(errorLocations[i]); + //TODO: check why the position would be invalid + if (position < 0 || (size_t)position >= received.size()) + throw IllegalArgumentException("Invalid position (ReedSolomonDecoder)"); + received[position] = GenericGF::addOrSubtract(received[position], errorMagitudes[i]); + } +} + +vector > ReedSolomonDecoder::runEuclideanAlgorithm(Ref a, + Ref b, + int R) { + // Assume a's degree is >= b's + if (a->getDegree() < b->getDegree()) { + Ref tmp = a; + a = b; + b = tmp; + } + + Ref rLast(a); + Ref r(b); + Ref sLast(field->getOne()); + Ref s(field->getZero()); + Ref tLast(field->getZero()); + Ref t(field->getOne()); + + + // Run Euclidean algorithm until r's degree is less than R/2 + while (r->getDegree() >= R / 2) { + Ref rLastLast(rLast); + Ref sLastLast(sLast); + Ref tLastLast(tLast); + rLast = r; + sLast = s; + tLast = t; + + + // Divide rLastLast by rLast, with quotient q and remainder r + if (rLast->isZero()) { + // Oops, Euclidean algorithm already terminated? + throw ReedSolomonException("r_{i-1} was zero"); + } + r = rLastLast; + Ref q(field->getZero()); + int denominatorLeadingTerm = rLast->getCoefficient(rLast->getDegree()); + int dltInverse = field->inverse(denominatorLeadingTerm); + while (r->getDegree() >= rLast->getDegree() && !r->isZero()) { + int degreeDiff = r->getDegree() - rLast->getDegree(); + int scale = field->multiply(r->getCoefficient(r->getDegree()), dltInverse); + q = q->addOrSubtract(field->buildMonomial(degreeDiff, scale)); + r = r->addOrSubtract(rLast->multiplyByMonomial(degreeDiff, scale)); + } + + s = q->multiply(sLast)->addOrSubtract(sLastLast); + t = q->multiply(tLast)->addOrSubtract(tLastLast); + + } + + int sigmaTildeAtZero = t->getCoefficient(0); + if (sigmaTildeAtZero == 0) { + throw ReedSolomonException("sigmaTilde(0) was zero"); + } + + int inverse = field->inverse(sigmaTildeAtZero); + Ref sigma(t->multiply(inverse)); + Ref omega(r->multiply(inverse)); + + +#ifdef DEBUG + cout << "t = " << *t << "\n"; + cout << "r = " << *r << "\n"; + cout << "sigma = " << *sigma << "\n"; + cout << "omega = " << *omega << "\n"; +#endif + + vector > result(2); + result[0] = sigma; + result[1] = omega; + return result; +} + +ArrayRef ReedSolomonDecoder::findErrorLocations(Ref errorLocator) { + // This is a direct application of Chien's search + int numErrors = errorLocator->getDegree(); + if (numErrors == 1) { // shortcut + ArrayRef result(new Array(1)); + result[0] = errorLocator->getCoefficient(1); + return result; + } + ArrayRef result(new Array(numErrors)); + int e = 0; + for (int i = 1; i < field->getSize() && e < numErrors; i++) { + // cout << "errorLocator(" << i << ") == " << errorLocator->evaluateAt(i) << "\n"; + if (errorLocator->evaluateAt(i) == 0) { + result[e] = field->inverse(i); + e++; + } + } + if (e != numErrors) { + throw ReedSolomonException("Error locator degree does not match number of roots"); + } + return result; +} + +ArrayRef ReedSolomonDecoder::findErrorMagnitudes(Ref errorEvaluator, ArrayRef errorLocations, bool dataMatrix) { + // This is directly applying Forney's Formula + int s = errorLocations.size(); + ArrayRef result(new Array(s)); + for (int i = 0; i < s; i++) { + int xiInverse = field->inverse(errorLocations[i]); + int denominator = 1; + for (int j = 0; j < s; j++) { + if (i != j) { + denominator = field->multiply(denominator, GenericGF::addOrSubtract(1, field->multiply(errorLocations[j], + xiInverse))); + } + } + result[i] = field->multiply(errorEvaluator->evaluateAt(xiInverse), field->inverse(denominator)); + + if (dataMatrix) { + result[i] = field->multiply(result[i], xiInverse); + } + } + return result; +} +} diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonDecoder.h b/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonDecoder.h index f7ad98a8f..01eb9c02a 100644 --- a/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonDecoder.h +++ b/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonDecoder.h @@ -1,46 +1,48 @@ -#ifndef __REED_SOLOMON_DECODER_H__ -#define __REED_SOLOMON_DECODER_H__ - -/* - * ReedSolomonDecoder.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { -class GF256; -class GF256Poly; - -class ReedSolomonDecoder { -private: - GF256 &field; -public: - ReedSolomonDecoder(GF256 &fld); - ~ReedSolomonDecoder(); - void decode(ArrayRef received, int twoS); -private: - std::vector > runEuclideanAlgorithm(Ref a, Ref b, int R); - ArrayRef findErrorLocations(Ref errorLocator); - ArrayRef findErrorMagnitudes(Ref errorEvaluator, ArrayRef errorLocations); -}; -} - -#endif // __REED_SOLOMON_DECODER_H__ +#ifndef __REED_SOLOMON_DECODER_H__ +#define __REED_SOLOMON_DECODER_H__ + +/* + * ReedSolomonDecoder.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +namespace zxing { +class GenericGFPoly; +class GenericGF; + +class ReedSolomonDecoder { +private: + Ref field; +public: + ReedSolomonDecoder(Ref fld); + ~ReedSolomonDecoder(); + void decode(ArrayRef received, int twoS); +private: + std::vector > runEuclideanAlgorithm(Ref a, Ref b, int R); + ArrayRef findErrorLocations(Ref errorLocator); + ArrayRef findErrorMagnitudes(Ref errorEvaluator, ArrayRef errorLocations, bool dataMatrix); +}; +} + +#endif // __REED_SOLOMON_DECODER_H__ diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonException.cpp b/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonException.cpp index 20af025bb..a2fc3924f 100644 --- a/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonException.cpp +++ b/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonException.cpp @@ -1,30 +1,30 @@ -/* - * ReedSolomonException.cpp - * zxing - * - * Created by Christian Brunschen on 06/05/2008. - * Copyright 2008 Google UK. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { -ReedSolomonException::ReedSolomonException(const char *msg) throw() : - Exception(msg) { -} -ReedSolomonException::~ReedSolomonException() throw() { -} - -} +/* + * ReedSolomonException.cpp + * zxing + * + * Created by Christian Brunschen on 06/05/2008. + * Copyright 2008 Google UK. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { +ReedSolomonException::ReedSolomonException(const char *msg) throw() : + Exception(msg) { +} +ReedSolomonException::~ReedSolomonException() throw() { +} + +} diff --git a/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonException.h b/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonException.h index 1c01250b5..5ca7e99fd 100644 --- a/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonException.h +++ b/symbian/QZXing/source/zxing/common/reedsolomon/ReedSolomonException.h @@ -1,33 +1,33 @@ -#ifndef __REED_SOLOMON_EXCEPTION_H__ -#define __REED_SOLOMON_EXCEPTION_H__ - -/* - * ReedSolomonException.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { -class ReedSolomonException : public Exception { -public: - ReedSolomonException(const char *msg) throw(); - ~ReedSolomonException() throw(); -}; -} - -#endif // __REED_SOLOMON_EXCEPTION_H__ +#ifndef __REED_SOLOMON_EXCEPTION_H__ +#define __REED_SOLOMON_EXCEPTION_H__ + +/* + * ReedSolomonException.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { +class ReedSolomonException : public Exception { +public: + ReedSolomonException(const char *msg) throw(); + ~ReedSolomonException() throw(); +}; +} + +#endif // __REED_SOLOMON_EXCEPTION_H__ diff --git a/symbian/QZXing/source/zxing/datamatrix/DataMatrixReader.cpp b/symbian/QZXing/source/zxing/datamatrix/DataMatrixReader.cpp index 56c00d480..845253fe9 100644 --- a/symbian/QZXing/source/zxing/datamatrix/DataMatrixReader.cpp +++ b/symbian/QZXing/source/zxing/datamatrix/DataMatrixReader.cpp @@ -1,82 +1,84 @@ -/* - * DataMatrixReader.cpp - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -namespace datamatrix { - -using namespace std; - -DataMatrixReader::DataMatrixReader() : - decoder_() { -} - -Ref DataMatrixReader::decode(Ref image, DecodeHints hints) { -#ifdef DEBUG - cout << "decoding image " << image.object_ << ":\n" << flush; -#endif - - Detector detector(image->getBlackMatrix()); - - -#ifdef DEBUG - cout << "(1) created detector " << &detector << "\n" << flush; -#endif - - Ref detectorResult(detector.detect()); -#ifdef DEBUG - cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush; -#endif - - std::vector > points(detectorResult->getPoints()); - - -#ifdef DEBUG - cout << "(3) extracted points " << &points << "\n" << flush; - cout << "found " << points.size() << " points:\n"; - for (size_t i = 0; i < points.size(); i++) { - cout << " " << points[i]->getX() << "," << points[i]->getY() << "\n"; - } - cout << "bits:\n"; - cout << *(detectorResult->getBits()) << "\n"; -#endif - - Ref decoderResult(decoder_.decode(detectorResult->getBits())); -#ifdef DEBUG - cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush; -#endif - - Ref result( - new Result(decoderResult->getText(), decoderResult->getRawBytes(), points, BarcodeFormat_DATA_MATRIX)); -#ifdef DEBUG - cout << "(5) created result " << result.object_ << ", returning\n" << flush; -#endif - - return result; -} - -DataMatrixReader::~DataMatrixReader() { -} - -} -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * DataMatrixReader.cpp + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { +namespace datamatrix { + +using namespace std; + +DataMatrixReader::DataMatrixReader() : + decoder_() { +} + +Ref DataMatrixReader::decode(Ref image, DecodeHints hints) { + (void)hints; +#ifdef DEBUG + cout << "decoding image " << image.object_ << ":\n" << flush; +#endif + + Detector detector(image->getBlackMatrix()); + + +#ifdef DEBUG + cout << "(1) created detector " << &detector << "\n" << flush; +#endif + + Ref detectorResult(detector.detect()); +#ifdef DEBUG + cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush; +#endif + + std::vector > points(detectorResult->getPoints()); + + +#ifdef DEBUG + cout << "(3) extracted points " << &points << "\n" << flush; + cout << "found " << points.size() << " points:\n"; + for (size_t i = 0; i < points.size(); i++) { + cout << " " << points[i]->getX() << "," << points[i]->getY() << "\n"; + } + cout << "bits:\n"; + cout << *(detectorResult->getBits()) << "\n"; +#endif + + Ref decoderResult(decoder_.decode(detectorResult->getBits())); +#ifdef DEBUG + cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush; +#endif + + Ref result( + new Result(decoderResult->getText(), decoderResult->getRawBytes(), points, BarcodeFormat_DATA_MATRIX)); +#ifdef DEBUG + cout << "(5) created result " << result.object_ << ", returning\n" << flush; +#endif + + return result; +} + +DataMatrixReader::~DataMatrixReader() { +} + +} +} diff --git a/symbian/QZXing/source/zxing/datamatrix/DataMatrixReader.h b/symbian/QZXing/source/zxing/datamatrix/DataMatrixReader.h index 3359a197c..94295b822 100644 --- a/symbian/QZXing/source/zxing/datamatrix/DataMatrixReader.h +++ b/symbian/QZXing/source/zxing/datamatrix/DataMatrixReader.h @@ -1,45 +1,45 @@ -#ifndef __DATA_MATRIX_READER_H__ -#define __DATA_MATRIX_READER_H__ - -/* - * DataMatrixReader.h - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -namespace datamatrix { - -class DataMatrixReader : public Reader { -private: - Decoder decoder_; - -public: - DataMatrixReader(); - virtual Ref decode(Ref image, DecodeHints hints); - virtual ~DataMatrixReader(); - -}; - -} -} - -#endif // __DATA_MATRIX_READER_H__ +#ifndef __DATA_MATRIX_READER_H__ +#define __DATA_MATRIX_READER_H__ + +/* + * DataMatrixReader.h + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { +namespace datamatrix { + +class DataMatrixReader : public Reader { +private: + Decoder decoder_; + +public: + DataMatrixReader(); + virtual Ref decode(Ref image, DecodeHints hints); + virtual ~DataMatrixReader(); + +}; + +} +} + +#endif // __DATA_MATRIX_READER_H__ diff --git a/symbian/QZXing/source/zxing/datamatrix/VersionDM.cpp b/symbian/QZXing/source/zxing/datamatrix/DataMatrixVersion.cpp similarity index 96% rename from symbian/QZXing/source/zxing/datamatrix/VersionDM.cpp rename to symbian/QZXing/source/zxing/datamatrix/DataMatrixVersion.cpp index d7a69f3a2..af4505cb1 100644 --- a/symbian/QZXing/source/zxing/datamatrix/VersionDM.cpp +++ b/symbian/QZXing/source/zxing/datamatrix/DataMatrixVersion.cpp @@ -1,199 +1,199 @@ -/* - * Version.cpp - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -namespace datamatrix { -using namespace std; - -ECB::ECB(int count, int dataCodewords) : - count_(count), dataCodewords_(dataCodewords) { -} - -int ECB::getCount() { - return count_; -} - -int ECB::getDataCodewords() { - return dataCodewords_; -} - -ECBlocks::ECBlocks(int ecCodewords, ECB *ecBlocks) : - ecCodewords_(ecCodewords), ecBlocks_(1, ecBlocks) { -} - -ECBlocks::ECBlocks(int ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2) : - ecCodewords_(ecCodewords), ecBlocks_(1, ecBlocks1) { - ecBlocks_.push_back(ecBlocks2); -} - -int ECBlocks::getECCodewords() { - return ecCodewords_; -} - -std::vector& ECBlocks::getECBlocks() { - return ecBlocks_; -} - -ECBlocks::~ECBlocks() { - for (size_t i = 0; i < ecBlocks_.size(); i++) { - delete ecBlocks_[i]; - } -} - -vector > Version::VERSIONS; -static int N_VERSIONS = Version::buildVersions(); - -Version::Version(int versionNumber, int symbolSizeRows, int symbolSizeColumns, int dataRegionSizeRows, - int dataRegionSizeColumns, ECBlocks* ecBlocks) : versionNumber_(versionNumber), - symbolSizeRows_(symbolSizeRows), symbolSizeColumns_(symbolSizeColumns), - dataRegionSizeRows_(dataRegionSizeRows), dataRegionSizeColumns_(dataRegionSizeColumns), - ecBlocks_(ecBlocks), totalCodewords_(0) { - // Calculate the total number of codewords - int total = 0; - int ecCodewords = ecBlocks_->getECCodewords(); - vector &ecbArray = ecBlocks_->getECBlocks(); - for (unsigned int i = 0; i < ecbArray.size(); i++) { - ECB *ecBlock = ecbArray[i]; - total += ecBlock->getCount() * (ecBlock->getDataCodewords() + ecCodewords); - } - totalCodewords_ = total; -} - -Version::~Version() { - delete ecBlocks_; -} - -int Version::getVersionNumber() { - return versionNumber_; -} - -int Version::getSymbolSizeRows() { - return symbolSizeRows_; -} - -int Version::getSymbolSizeColumns() { - return symbolSizeColumns_; -} - -int Version::getDataRegionSizeRows() { - return dataRegionSizeRows_; -} - -int Version::getDataRegionSizeColumns() { - return dataRegionSizeColumns_; -} - -int Version::getTotalCodewords() { - return totalCodewords_; -} - -ECBlocks* Version::getECBlocks() { - return ecBlocks_; -} - -Ref Version::getVersionForDimensions(int numRows, int numColumns) { - if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) { - throw ReaderException("Number of rows and columns must be even"); - } - - // TODO(bbrown): This is doing a linear search through the array of versions. - // If we interleave the rectangular versions with the square versions we could - // do a binary search. - for (int i = 0; i < N_VERSIONS; ++i){ - Ref version(VERSIONS[i]); - if (version->getSymbolSizeRows() == numRows && version->getSymbolSizeColumns() == numColumns) { - return version; - } - } - throw ReaderException("Error version not found"); - } - -/** - * See ISO 16022:2006 5.5.1 Table 7 - */ -int Version::buildVersions() { - VERSIONS.push_back(Ref(new Version(1, 10, 10, 8, 8, - new ECBlocks(5, new ECB(1, 3))))); - VERSIONS.push_back(Ref(new Version(2, 12, 12, 10, 10, - new ECBlocks(7, new ECB(1, 5))))); - VERSIONS.push_back(Ref(new Version(3, 14, 14, 12, 12, - new ECBlocks(10, new ECB(1, 8))))); - VERSIONS.push_back(Ref(new Version(4, 16, 16, 14, 14, - new ECBlocks(12, new ECB(1, 12))))); - VERSIONS.push_back(Ref(new Version(5, 18, 18, 16, 16, - new ECBlocks(14, new ECB(1, 18))))); - VERSIONS.push_back(Ref(new Version(6, 20, 20, 18, 18, - new ECBlocks(18, new ECB(1, 22))))); - VERSIONS.push_back(Ref(new Version(7, 22, 22, 20, 20, - new ECBlocks(20, new ECB(1, 30))))); - VERSIONS.push_back(Ref(new Version(8, 24, 24, 22, 22, - new ECBlocks(24, new ECB(1, 36))))); - VERSIONS.push_back(Ref(new Version(9, 26, 26, 24, 24, - new ECBlocks(28, new ECB(1, 44))))); - VERSIONS.push_back(Ref(new Version(10, 32, 32, 14, 14, - new ECBlocks(36, new ECB(1, 62))))); - VERSIONS.push_back(Ref(new Version(11, 36, 36, 16, 16, - new ECBlocks(42, new ECB(1, 86))))); - VERSIONS.push_back(Ref(new Version(12, 40, 40, 18, 18, - new ECBlocks(48, new ECB(1, 114))))); - VERSIONS.push_back(Ref(new Version(13, 44, 44, 20, 20, - new ECBlocks(56, new ECB(1, 144))))); - VERSIONS.push_back(Ref(new Version(14, 48, 48, 22, 22, - new ECBlocks(68, new ECB(1, 174))))); - VERSIONS.push_back(Ref(new Version(15, 52, 52, 24, 24, - new ECBlocks(42, new ECB(2, 102))))); - VERSIONS.push_back(Ref(new Version(16, 64, 64, 14, 14, - new ECBlocks(56, new ECB(2, 140))))); - VERSIONS.push_back(Ref(new Version(17, 72, 72, 16, 16, - new ECBlocks(36, new ECB(4, 92))))); - VERSIONS.push_back(Ref(new Version(18, 80, 80, 18, 18, - new ECBlocks(48, new ECB(4, 114))))); - VERSIONS.push_back(Ref(new Version(19, 88, 88, 20, 20, - new ECBlocks(56, new ECB(4, 144))))); - VERSIONS.push_back(Ref(new Version(20, 96, 96, 22, 22, - new ECBlocks(68, new ECB(4, 174))))); - VERSIONS.push_back(Ref(new Version(21, 104, 104, 24, 24, - new ECBlocks(56, new ECB(6, 136))))); - VERSIONS.push_back(Ref(new Version(22, 120, 120, 18, 18, - new ECBlocks(68, new ECB(6, 175))))); - VERSIONS.push_back(Ref(new Version(23, 132, 132, 20, 20, - new ECBlocks(62, new ECB(8, 163))))); - VERSIONS.push_back(Ref(new Version(24, 144, 144, 22, 22, - new ECBlocks(62, new ECB(8, 156), new ECB(2, 155))))); - VERSIONS.push_back(Ref(new Version(25, 8, 18, 6, 16, - new ECBlocks(7, new ECB(1, 5))))); - VERSIONS.push_back(Ref(new Version(26, 8, 32, 6, 14, - new ECBlocks(11, new ECB(1, 10))))); - VERSIONS.push_back(Ref(new Version(27, 12, 26, 10, 24, - new ECBlocks(14, new ECB(1, 16))))); - VERSIONS.push_back(Ref(new Version(28, 12, 36, 10, 16, - new ECBlocks(18, new ECB(1, 22))))); - VERSIONS.push_back(Ref(new Version(29, 16, 36, 14, 16, - new ECBlocks(24, new ECB(1, 32))))); - VERSIONS.push_back(Ref(new Version(30, 16, 48, 14, 22, - new ECBlocks(28, new ECB(1, 49))))); - return VERSIONS.size(); -} -} -} +/* + * Version.cpp + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { +namespace datamatrix { +using namespace std; + +ECB::ECB(int count, int dataCodewords) : + count_(count), dataCodewords_(dataCodewords) { +} + +int ECB::getCount() { + return count_; +} + +int ECB::getDataCodewords() { + return dataCodewords_; +} + +ECBlocks::ECBlocks(int ecCodewords, ECB *ecBlocks) : + ecCodewords_(ecCodewords), ecBlocks_(1, ecBlocks) { +} + +ECBlocks::ECBlocks(int ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2) : + ecCodewords_(ecCodewords), ecBlocks_(1, ecBlocks1) { + ecBlocks_.push_back(ecBlocks2); +} + +int ECBlocks::getECCodewords() { + return ecCodewords_; +} + +std::vector& ECBlocks::getECBlocks() { + return ecBlocks_; +} + +ECBlocks::~ECBlocks() { + for (size_t i = 0; i < ecBlocks_.size(); i++) { + delete ecBlocks_[i]; + } +} + +vector > Version::VERSIONS; +static int N_VERSIONS = Version::buildVersions(); + +Version::Version(int versionNumber, int symbolSizeRows, int symbolSizeColumns, int dataRegionSizeRows, + int dataRegionSizeColumns, ECBlocks* ecBlocks) : versionNumber_(versionNumber), + symbolSizeRows_(symbolSizeRows), symbolSizeColumns_(symbolSizeColumns), + dataRegionSizeRows_(dataRegionSizeRows), dataRegionSizeColumns_(dataRegionSizeColumns), + ecBlocks_(ecBlocks), totalCodewords_(0) { + // Calculate the total number of codewords + int total = 0; + int ecCodewords = ecBlocks_->getECCodewords(); + vector &ecbArray = ecBlocks_->getECBlocks(); + for (unsigned int i = 0; i < ecbArray.size(); i++) { + ECB *ecBlock = ecbArray[i]; + total += ecBlock->getCount() * (ecBlock->getDataCodewords() + ecCodewords); + } + totalCodewords_ = total; +} + +Version::~Version() { + delete ecBlocks_; +} + +int Version::getVersionNumber() { + return versionNumber_; +} + +int Version::getSymbolSizeRows() { + return symbolSizeRows_; +} + +int Version::getSymbolSizeColumns() { + return symbolSizeColumns_; +} + +int Version::getDataRegionSizeRows() { + return dataRegionSizeRows_; +} + +int Version::getDataRegionSizeColumns() { + return dataRegionSizeColumns_; +} + +int Version::getTotalCodewords() { + return totalCodewords_; +} + +ECBlocks* Version::getECBlocks() { + return ecBlocks_; +} + +Ref Version::getVersionForDimensions(int numRows, int numColumns) { + if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) { + throw ReaderException("Number of rows and columns must be even"); + } + + // TODO(bbrown): This is doing a linear search through the array of versions. + // If we interleave the rectangular versions with the square versions we could + // do a binary search. + for (int i = 0; i < N_VERSIONS; ++i){ + Ref version(VERSIONS[i]); + if (version->getSymbolSizeRows() == numRows && version->getSymbolSizeColumns() == numColumns) { + return version; + } + } + throw ReaderException("Error version not found"); + } + +/** + * See ISO 16022:2006 5.5.1 Table 7 + */ +int Version::buildVersions() { + VERSIONS.push_back(Ref(new Version(1, 10, 10, 8, 8, + new ECBlocks(5, new ECB(1, 3))))); + VERSIONS.push_back(Ref(new Version(2, 12, 12, 10, 10, + new ECBlocks(7, new ECB(1, 5))))); + VERSIONS.push_back(Ref(new Version(3, 14, 14, 12, 12, + new ECBlocks(10, new ECB(1, 8))))); + VERSIONS.push_back(Ref(new Version(4, 16, 16, 14, 14, + new ECBlocks(12, new ECB(1, 12))))); + VERSIONS.push_back(Ref(new Version(5, 18, 18, 16, 16, + new ECBlocks(14, new ECB(1, 18))))); + VERSIONS.push_back(Ref(new Version(6, 20, 20, 18, 18, + new ECBlocks(18, new ECB(1, 22))))); + VERSIONS.push_back(Ref(new Version(7, 22, 22, 20, 20, + new ECBlocks(20, new ECB(1, 30))))); + VERSIONS.push_back(Ref(new Version(8, 24, 24, 22, 22, + new ECBlocks(24, new ECB(1, 36))))); + VERSIONS.push_back(Ref(new Version(9, 26, 26, 24, 24, + new ECBlocks(28, new ECB(1, 44))))); + VERSIONS.push_back(Ref(new Version(10, 32, 32, 14, 14, + new ECBlocks(36, new ECB(1, 62))))); + VERSIONS.push_back(Ref(new Version(11, 36, 36, 16, 16, + new ECBlocks(42, new ECB(1, 86))))); + VERSIONS.push_back(Ref(new Version(12, 40, 40, 18, 18, + new ECBlocks(48, new ECB(1, 114))))); + VERSIONS.push_back(Ref(new Version(13, 44, 44, 20, 20, + new ECBlocks(56, new ECB(1, 144))))); + VERSIONS.push_back(Ref(new Version(14, 48, 48, 22, 22, + new ECBlocks(68, new ECB(1, 174))))); + VERSIONS.push_back(Ref(new Version(15, 52, 52, 24, 24, + new ECBlocks(42, new ECB(2, 102))))); + VERSIONS.push_back(Ref(new Version(16, 64, 64, 14, 14, + new ECBlocks(56, new ECB(2, 140))))); + VERSIONS.push_back(Ref(new Version(17, 72, 72, 16, 16, + new ECBlocks(36, new ECB(4, 92))))); + VERSIONS.push_back(Ref(new Version(18, 80, 80, 18, 18, + new ECBlocks(48, new ECB(4, 114))))); + VERSIONS.push_back(Ref(new Version(19, 88, 88, 20, 20, + new ECBlocks(56, new ECB(4, 144))))); + VERSIONS.push_back(Ref(new Version(20, 96, 96, 22, 22, + new ECBlocks(68, new ECB(4, 174))))); + VERSIONS.push_back(Ref(new Version(21, 104, 104, 24, 24, + new ECBlocks(56, new ECB(6, 136))))); + VERSIONS.push_back(Ref(new Version(22, 120, 120, 18, 18, + new ECBlocks(68, new ECB(6, 175))))); + VERSIONS.push_back(Ref(new Version(23, 132, 132, 20, 20, + new ECBlocks(62, new ECB(8, 163))))); + VERSIONS.push_back(Ref(new Version(24, 144, 144, 22, 22, + new ECBlocks(62, new ECB(8, 156), new ECB(2, 155))))); + VERSIONS.push_back(Ref(new Version(25, 8, 18, 6, 16, + new ECBlocks(7, new ECB(1, 5))))); + VERSIONS.push_back(Ref(new Version(26, 8, 32, 6, 14, + new ECBlocks(11, new ECB(1, 10))))); + VERSIONS.push_back(Ref(new Version(27, 12, 26, 10, 24, + new ECBlocks(14, new ECB(1, 16))))); + VERSIONS.push_back(Ref(new Version(28, 12, 36, 10, 16, + new ECBlocks(18, new ECB(1, 22))))); + VERSIONS.push_back(Ref(new Version(29, 16, 36, 14, 16, + new ECBlocks(24, new ECB(1, 32))))); + VERSIONS.push_back(Ref(new Version(30, 16, 48, 14, 22, + new ECBlocks(28, new ECB(1, 49))))); + return VERSIONS.size(); +} +} +} diff --git a/symbian/QZXing/source/zxing/datamatrix/VersionDM.h b/symbian/QZXing/source/zxing/datamatrix/Version.h similarity index 93% rename from symbian/QZXing/source/zxing/datamatrix/VersionDM.h rename to symbian/QZXing/source/zxing/datamatrix/Version.h index 762d2a7d2..b200c498c 100644 --- a/symbian/QZXing/source/zxing/datamatrix/VersionDM.h +++ b/symbian/QZXing/source/zxing/datamatrix/Version.h @@ -1,87 +1,87 @@ -#ifndef __VERSION_DM_H__ -#define __VERSION_DM_H__ - -/* - * Version.h - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { -namespace datamatrix { - -class ECB { -private: - int count_; - int dataCodewords_; -public: - ECB(int count, int dataCodewords); - int getCount(); - int getDataCodewords(); -}; - -class ECBlocks { -private: - int ecCodewords_; - std::vector ecBlocks_; -public: - ECBlocks(int ecCodewords, ECB *ecBlocks); - ECBlocks(int ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2); - int getECCodewords(); - std::vector& getECBlocks(); - ~ECBlocks(); -}; - -class Version : public Counted { -private: - int versionNumber_; - int symbolSizeRows_; - int symbolSizeColumns_; - int dataRegionSizeRows_; - int dataRegionSizeColumns_; - ECBlocks* ecBlocks_; - int totalCodewords_; - Version(int versionNumber, int symbolSizeRows, int symbolSizeColumns, int dataRegionSizeRows, - int dataRegionSizeColumns, ECBlocks *ecBlocks); - -public: - static std::vector > VERSIONS; - - ~Version(); - int getVersionNumber(); - int getSymbolSizeRows(); - int getSymbolSizeColumns(); - int getDataRegionSizeRows(); - int getDataRegionSizeColumns(); - int getTotalCodewords(); - ECBlocks* getECBlocks(); - static int buildVersions(); - Ref getVersionForDimensions(int numRows, int numColumns); - -private: - Version(const Version&); - Version & operator=(const Version&); -}; -} -} - -#endif // __VERSION_DM_H__ +#ifndef __VERSION_H__ +#define __VERSION_H__ + +/* + * Version.h + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { +namespace datamatrix { + +class ECB { +private: + int count_; + int dataCodewords_; +public: + ECB(int count, int dataCodewords); + int getCount(); + int getDataCodewords(); +}; + +class ECBlocks { +private: + int ecCodewords_; + std::vector ecBlocks_; +public: + ECBlocks(int ecCodewords, ECB *ecBlocks); + ECBlocks(int ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2); + int getECCodewords(); + std::vector& getECBlocks(); + ~ECBlocks(); +}; + +class Version : public Counted { +private: + int versionNumber_; + int symbolSizeRows_; + int symbolSizeColumns_; + int dataRegionSizeRows_; + int dataRegionSizeColumns_; + ECBlocks* ecBlocks_; + int totalCodewords_; + Version(int versionNumber, int symbolSizeRows, int symbolSizeColumns, int dataRegionSizeRows, + int dataRegionSizeColumns, ECBlocks *ecBlocks); + +public: + static std::vector > VERSIONS; + + ~Version(); + int getVersionNumber(); + int getSymbolSizeRows(); + int getSymbolSizeColumns(); + int getDataRegionSizeRows(); + int getDataRegionSizeColumns(); + int getTotalCodewords(); + ECBlocks* getECBlocks(); + static int buildVersions(); + Ref getVersionForDimensions(int numRows, int numColumns); + +private: + Version(const Version&); + Version & operator=(const Version&); +}; +} +} + +#endif // __VERSION_H__ diff --git a/symbian/QZXing/source/zxing/datamatrix/decoder/BitMatrixParserDM.h b/symbian/QZXing/source/zxing/datamatrix/decoder/BitMatrixParser.h similarity index 94% rename from symbian/QZXing/source/zxing/datamatrix/decoder/BitMatrixParserDM.h rename to symbian/QZXing/source/zxing/datamatrix/decoder/BitMatrixParser.h index c7cdd79c7..0770da1fc 100644 --- a/symbian/QZXing/source/zxing/datamatrix/decoder/BitMatrixParserDM.h +++ b/symbian/QZXing/source/zxing/datamatrix/decoder/BitMatrixParser.h @@ -1,59 +1,59 @@ -#ifndef __BIT_MATRIX_PARSER_DM_H__ -#define __BIT_MATRIX_PARSER_DM_H__ - -/* - * BitMatrixParser.h - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace zxing { -namespace datamatrix { - -class BitMatrixParser : public Counted { -private: - Ref bitMatrix_; - Ref parsedVersion_; - Ref readBitMatrix_; - - int copyBit(size_t x, size_t y, int versionBits); - -public: - BitMatrixParser(Ref bitMatrix); - Ref readVersion(Ref bitMatrix); - ArrayRef readCodewords(); - bool readModule(int row, int column, int numRows, int numColumns); - -private: - int readUtah(int row, int column, int numRows, int numColumns); - int readCorner1(int numRows, int numColumns); - int readCorner2(int numRows, int numColumns); - int readCorner3(int numRows, int numColumns); - int readCorner4(int numRows, int numColumns); - Ref extractDataRegion(Ref bitMatrix); -}; - -} -} - -#endif // __BIT_MATRIX_PARSER_DM_H__ +#ifndef __BIT_MATRIX_PARSER_DM_H__ +#define __BIT_MATRIX_PARSER_DM_H__ + +/* + * BitMatrixParser.h + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +namespace zxing { +namespace datamatrix { + +class BitMatrixParser : public Counted { +private: + Ref bitMatrix_; + Ref parsedVersion_; + Ref readBitMatrix_; + + int copyBit(size_t x, size_t y, int versionBits); + +public: + BitMatrixParser(Ref bitMatrix); + Ref readVersion(Ref bitMatrix); + ArrayRef readCodewords(); + bool readModule(int row, int column, int numRows, int numColumns); + +private: + int readUtah(int row, int column, int numRows, int numColumns); + int readCorner1(int numRows, int numColumns); + int readCorner2(int numRows, int numColumns); + int readCorner3(int numRows, int numColumns); + int readCorner4(int numRows, int numColumns); + Ref extractDataRegion(Ref bitMatrix); +}; + +} +} + +#endif // __BIT_MATRIX_PARSER_DM_H__ diff --git a/symbian/QZXing/source/zxing/datamatrix/decoder/DataBlockDM.h b/symbian/QZXing/source/zxing/datamatrix/decoder/DataBlock.h similarity index 93% rename from symbian/QZXing/source/zxing/datamatrix/decoder/DataBlockDM.h rename to symbian/QZXing/source/zxing/datamatrix/decoder/DataBlock.h index 44fc1fb34..ed245499c 100644 --- a/symbian/QZXing/source/zxing/datamatrix/decoder/DataBlockDM.h +++ b/symbian/QZXing/source/zxing/datamatrix/decoder/DataBlock.h @@ -1,49 +1,49 @@ -#ifndef __DATA_BLOCK_DM_H__ -#define __DATA_BLOCK_DM_H__ - -/* - * DataBlock.h - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { -namespace datamatrix { - -class DataBlock : public Counted { -private: - int numDataCodewords_; - ArrayRef codewords_; - - DataBlock(int numDataCodewords, ArrayRef codewords); - -public: - static std::vector > getDataBlocks(ArrayRef rawCodewords, Version *version); - - int getNumDataCodewords(); - ArrayRef getCodewords(); -}; - -} -} - -#endif // __DATA_BLOCK_DM_H__ +#ifndef __DATA_BLOCK_DM_H__ +#define __DATA_BLOCK_DM_H__ + +/* + * DataBlock.h + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { +namespace datamatrix { + +class DataBlock : public Counted { +private: + int numDataCodewords_; + ArrayRef codewords_; + + DataBlock(int numDataCodewords, ArrayRef codewords); + +public: + static std::vector > getDataBlocks(ArrayRef rawCodewords, Version *version); + + int getNumDataCodewords(); + ArrayRef getCodewords(); +}; + +} +} + +#endif // __DATA_BLOCK_DM_H__ diff --git a/symbian/QZXing/source/zxing/datamatrix/decoder/BitMatrixParserDM.cpp b/symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixBitMatrixParser.cpp similarity index 96% rename from symbian/QZXing/source/zxing/datamatrix/decoder/BitMatrixParserDM.cpp rename to symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixBitMatrixParser.cpp index df307bb77..67c8de8ca 100644 --- a/symbian/QZXing/source/zxing/datamatrix/decoder/BitMatrixParserDM.cpp +++ b/symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixBitMatrixParser.cpp @@ -1,361 +1,361 @@ -/* - * BitMatrixParser.cpp - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include - -namespace zxing { -namespace datamatrix { - -int BitMatrixParser::copyBit(size_t x, size_t y, int versionBits) { - return bitMatrix_->get(x, y) ? (versionBits << 1) | 0x1 : versionBits << 1; -} - -BitMatrixParser::BitMatrixParser(Ref bitMatrix) : bitMatrix_(NULL), - parsedVersion_(NULL), - readBitMatrix_(NULL) { - size_t dimension = bitMatrix->getDimension(); - if (dimension < 8 || dimension > 144 || (dimension & 0x01) != 0) - throw ReaderException("Dimension must be even, > 8 < 144"); - - parsedVersion_ = readVersion(bitMatrix); - bitMatrix_ = extractDataRegion(bitMatrix); - readBitMatrix_ = new BitMatrix(bitMatrix_->getWidth(), bitMatrix_->getHeight()); -} - -Ref BitMatrixParser::readVersion(Ref bitMatrix) { - if (parsedVersion_ != 0) { - return parsedVersion_; - } - - int numRows = bitMatrix->getHeight();//getDimension(); - int numColumns = bitMatrix->getWidth();//numRows; - - Ref version = parsedVersion_->getVersionForDimensions(numRows, numColumns); - if (version != 0) { - return version; - } - throw ReaderException("Couldn't decode version"); -} - -ArrayRef BitMatrixParser::readCodewords() { - ArrayRef result(parsedVersion_->getTotalCodewords()); - int resultOffset = 0; - int row = 4; - int column = 0; - - int numRows = bitMatrix_->getHeight(); - int numColumns = bitMatrix_->getWidth(); - - bool corner1Read = false; - bool corner2Read = false; - bool corner3Read = false; - bool corner4Read = false; - - // Read all of the codewords - do { - // Check the four corner cases - if ((row == numRows) && (column == 0) && !corner1Read) { - result[resultOffset++] = (unsigned char) readCorner1(numRows, numColumns); - row -= 2; - column +=2; - corner1Read = true; - } else if ((row == numRows-2) && (column == 0) && ((numColumns & 0x03) != 0) && !corner2Read) { - result[resultOffset++] = (unsigned char) readCorner2(numRows, numColumns); - row -= 2; - column +=2; - corner2Read = true; - } else if ((row == numRows+4) && (column == 2) && ((numColumns & 0x07) == 0) && !corner3Read) { - result[resultOffset++] = (unsigned char) readCorner3(numRows, numColumns); - row -= 2; - column +=2; - corner3Read = true; - } else if ((row == numRows-2) && (column == 0) && ((numColumns & 0x07) == 4) && !corner4Read) { - result[resultOffset++] = (unsigned char) readCorner4(numRows, numColumns); - row -= 2; - column +=2; - corner4Read = true; - } else { - // Sweep upward diagonally to the right - do { - if ((row < numRows) && (column >= 0) && !readBitMatrix_->get(column, row)) { - result[resultOffset++] = (unsigned char) readUtah(row, column, numRows, numColumns); - } - row -= 2; - column +=2; - } while ((row >= 0) && (column < numColumns)); - row += 1; - column +=3; - - // Sweep downward diagonally to the left - do { - if ((row >= 0) && (column < numColumns) && !readBitMatrix_->get(column, row)) { - result[resultOffset++] = (unsigned char) readUtah(row, column, numRows, numColumns); - } - row += 2; - column -=2; - } while ((row < numRows) && (column >= 0)); - row += 3; - column +=1; - } - } while ((row < numRows) || (column < numColumns)); - - if (resultOffset != parsedVersion_->getTotalCodewords()) { - throw ReaderException("Did not read all codewords"); - } - return result; -} - -bool BitMatrixParser::readModule(int row, int column, int numRows, int numColumns) { - // Adjust the row and column indices based on boundary wrapping - if (row < 0) { - row += numRows; - column += 4 - ((numRows + 4) & 0x07); - } - if (column < 0) { - column += numColumns; - row += 4 - ((numColumns + 4) & 0x07); - } - readBitMatrix_->set(column, row); - return bitMatrix_->get(column, row); - } - -int BitMatrixParser::readUtah(int row, int column, int numRows, int numColumns) { - int currentByte = 0; - if (readModule(row - 2, column - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row - 2, column - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row - 1, column - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row - 1, column - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row - 1, column, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row, column - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row, column - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(row, column, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; - } - -int BitMatrixParser::readCorner1(int numRows, int numColumns) { - int currentByte = 0; - if (readModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 1, 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 1, 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(2, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(3, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; - } - -int BitMatrixParser::readCorner2(int numRows, int numColumns) { - int currentByte = 0; - if (readModule(numRows - 3, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 2, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 4, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 3, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; - } - -int BitMatrixParser::readCorner3(int numRows, int numColumns) { - int currentByte = 0; - if (readModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 3, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 3, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; - } - -int BitMatrixParser::readCorner4(int numRows, int numColumns) { - int currentByte = 0; - if (readModule(numRows - 3, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 2, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(2, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (readModule(3, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; - } - -Ref BitMatrixParser::extractDataRegion(Ref bitMatrix) { - int symbolSizeRows = parsedVersion_->getSymbolSizeRows(); - int symbolSizeColumns = parsedVersion_->getSymbolSizeColumns(); - - if ((int)bitMatrix->getHeight() != symbolSizeRows) { - throw IllegalArgumentException("Dimension of bitMatrix must match the version size"); - } - - int dataRegionSizeRows = parsedVersion_->getDataRegionSizeRows(); - int dataRegionSizeColumns = parsedVersion_->getDataRegionSizeColumns(); - - int numDataRegionsRow = symbolSizeRows / dataRegionSizeRows; - int numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns; - - int sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows; - int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns; - - Ref bitMatrixWithoutAlignment(new BitMatrix(sizeDataRegionColumn, sizeDataRegionRow)); - for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) { - int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows; - for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) { - int dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns; - for (int i = 0; i < dataRegionSizeRows; ++i) { - int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i; - int writeRowOffset = dataRegionRowOffset + i; - for (int j = 0; j < dataRegionSizeColumns; ++j) { - int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j; - if (bitMatrix->get(readColumnOffset, readRowOffset)) { - int writeColumnOffset = dataRegionColumnOffset + j; - bitMatrixWithoutAlignment->set(writeColumnOffset, writeRowOffset); - } - } - } - } - } - return bitMatrixWithoutAlignment; -} - -} -} +/* + * BitMatrixParser.cpp + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include + +namespace zxing { +namespace datamatrix { + +int BitMatrixParser::copyBit(size_t x, size_t y, int versionBits) { + return bitMatrix_->get(x, y) ? (versionBits << 1) | 0x1 : versionBits << 1; +} + +BitMatrixParser::BitMatrixParser(Ref bitMatrix) : bitMatrix_(NULL), + parsedVersion_(NULL), + readBitMatrix_(NULL) { + size_t dimension = bitMatrix->getDimension(); + if (dimension < 8 || dimension > 144 || (dimension & 0x01) != 0) + throw ReaderException("Dimension must be even, > 8 < 144"); + + parsedVersion_ = readVersion(bitMatrix); + bitMatrix_ = extractDataRegion(bitMatrix); + readBitMatrix_ = new BitMatrix(bitMatrix_->getWidth(), bitMatrix_->getHeight()); +} + +Ref BitMatrixParser::readVersion(Ref bitMatrix) { + if (parsedVersion_ != 0) { + return parsedVersion_; + } + + int numRows = bitMatrix->getHeight();//getDimension(); + int numColumns = bitMatrix->getWidth();//numRows; + + Ref version = parsedVersion_->getVersionForDimensions(numRows, numColumns); + if (version != 0) { + return version; + } + throw ReaderException("Couldn't decode version"); +} + +ArrayRef BitMatrixParser::readCodewords() { + ArrayRef result(parsedVersion_->getTotalCodewords()); + int resultOffset = 0; + int row = 4; + int column = 0; + + int numRows = bitMatrix_->getHeight(); + int numColumns = bitMatrix_->getWidth(); + + bool corner1Read = false; + bool corner2Read = false; + bool corner3Read = false; + bool corner4Read = false; + + // Read all of the codewords + do { + // Check the four corner cases + if ((row == numRows) && (column == 0) && !corner1Read) { + result[resultOffset++] = (unsigned char) readCorner1(numRows, numColumns); + row -= 2; + column +=2; + corner1Read = true; + } else if ((row == numRows-2) && (column == 0) && ((numColumns & 0x03) != 0) && !corner2Read) { + result[resultOffset++] = (unsigned char) readCorner2(numRows, numColumns); + row -= 2; + column +=2; + corner2Read = true; + } else if ((row == numRows+4) && (column == 2) && ((numColumns & 0x07) == 0) && !corner3Read) { + result[resultOffset++] = (unsigned char) readCorner3(numRows, numColumns); + row -= 2; + column +=2; + corner3Read = true; + } else if ((row == numRows-2) && (column == 0) && ((numColumns & 0x07) == 4) && !corner4Read) { + result[resultOffset++] = (unsigned char) readCorner4(numRows, numColumns); + row -= 2; + column +=2; + corner4Read = true; + } else { + // Sweep upward diagonally to the right + do { + if ((row < numRows) && (column >= 0) && !readBitMatrix_->get(column, row)) { + result[resultOffset++] = (unsigned char) readUtah(row, column, numRows, numColumns); + } + row -= 2; + column +=2; + } while ((row >= 0) && (column < numColumns)); + row += 1; + column +=3; + + // Sweep downward diagonally to the left + do { + if ((row >= 0) && (column < numColumns) && !readBitMatrix_->get(column, row)) { + result[resultOffset++] = (unsigned char) readUtah(row, column, numRows, numColumns); + } + row += 2; + column -=2; + } while ((row < numRows) && (column >= 0)); + row += 3; + column +=1; + } + } while ((row < numRows) || (column < numColumns)); + + if (resultOffset != parsedVersion_->getTotalCodewords()) { + throw ReaderException("Did not read all codewords"); + } + return result; +} + +bool BitMatrixParser::readModule(int row, int column, int numRows, int numColumns) { + // Adjust the row and column indices based on boundary wrapping + if (row < 0) { + row += numRows; + column += 4 - ((numRows + 4) & 0x07); + } + if (column < 0) { + column += numColumns; + row += 4 - ((numColumns + 4) & 0x07); + } + readBitMatrix_->set(column, row); + return bitMatrix_->get(column, row); + } + +int BitMatrixParser::readUtah(int row, int column, int numRows, int numColumns) { + int currentByte = 0; + if (readModule(row - 2, column - 2, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(row - 2, column - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(row - 1, column - 2, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(row - 1, column - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(row - 1, column, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(row, column - 2, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(row, column - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(row, column, numRows, numColumns)) { + currentByte |= 1; + } + return currentByte; + } + +int BitMatrixParser::readCorner1(int numRows, int numColumns) { + int currentByte = 0; + if (readModule(numRows - 1, 0, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(numRows - 1, 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(numRows - 1, 2, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(0, numColumns - 2, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(0, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(1, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(2, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(3, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + return currentByte; + } + +int BitMatrixParser::readCorner2(int numRows, int numColumns) { + int currentByte = 0; + if (readModule(numRows - 3, 0, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(numRows - 2, 0, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(numRows - 1, 0, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(0, numColumns - 4, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(0, numColumns - 3, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(0, numColumns - 2, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(0, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(1, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + return currentByte; + } + +int BitMatrixParser::readCorner3(int numRows, int numColumns) { + int currentByte = 0; + if (readModule(numRows - 1, 0, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(numRows - 1, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(0, numColumns - 3, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(0, numColumns - 2, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(0, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(1, numColumns - 3, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(1, numColumns - 2, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(1, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + return currentByte; + } + +int BitMatrixParser::readCorner4(int numRows, int numColumns) { + int currentByte = 0; + if (readModule(numRows - 3, 0, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(numRows - 2, 0, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(numRows - 1, 0, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(0, numColumns - 2, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(0, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(1, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(2, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + currentByte <<= 1; + if (readModule(3, numColumns - 1, numRows, numColumns)) { + currentByte |= 1; + } + return currentByte; + } + +Ref BitMatrixParser::extractDataRegion(Ref bitMatrix) { + int symbolSizeRows = parsedVersion_->getSymbolSizeRows(); + int symbolSizeColumns = parsedVersion_->getSymbolSizeColumns(); + + if ((int)bitMatrix->getHeight() != symbolSizeRows) { + throw IllegalArgumentException("Dimension of bitMatrix must match the version size"); + } + + int dataRegionSizeRows = parsedVersion_->getDataRegionSizeRows(); + int dataRegionSizeColumns = parsedVersion_->getDataRegionSizeColumns(); + + int numDataRegionsRow = symbolSizeRows / dataRegionSizeRows; + int numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns; + + int sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows; + int sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns; + + Ref bitMatrixWithoutAlignment(new BitMatrix(sizeDataRegionColumn, sizeDataRegionRow)); + for (int dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) { + int dataRegionRowOffset = dataRegionRow * dataRegionSizeRows; + for (int dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; ++dataRegionColumn) { + int dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns; + for (int i = 0; i < dataRegionSizeRows; ++i) { + int readRowOffset = dataRegionRow * (dataRegionSizeRows + 2) + 1 + i; + int writeRowOffset = dataRegionRowOffset + i; + for (int j = 0; j < dataRegionSizeColumns; ++j) { + int readColumnOffset = dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j; + if (bitMatrix->get(readColumnOffset, readRowOffset)) { + int writeColumnOffset = dataRegionColumnOffset + j; + bitMatrixWithoutAlignment->set(writeColumnOffset, writeRowOffset); + } + } + } + } + } + return bitMatrixWithoutAlignment; +} + +} +} diff --git a/symbian/QZXing/source/zxing/datamatrix/decoder/DataBlockDM.cpp b/symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixDataBlock.cpp similarity index 96% rename from symbian/QZXing/source/zxing/datamatrix/decoder/DataBlockDM.cpp rename to symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixDataBlock.cpp index 1f7e1929d..fee4e2504 100644 --- a/symbian/QZXing/source/zxing/datamatrix/decoder/DataBlockDM.cpp +++ b/symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixDataBlock.cpp @@ -1,113 +1,113 @@ -/* - * DataBlock.cpp - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { -namespace datamatrix { - -using namespace std; - -DataBlock::DataBlock(int numDataCodewords, ArrayRef codewords) : - numDataCodewords_(numDataCodewords), codewords_(codewords) { -} - -int DataBlock::getNumDataCodewords() { - return numDataCodewords_; -} - -ArrayRef DataBlock::getCodewords() { - return codewords_; -} - -std::vector > DataBlock::getDataBlocks(ArrayRef rawCodewords, Version *version) { - // Figure out the number and size of data blocks used by this version and - // error correction level - ECBlocks* ecBlocks = version->getECBlocks(); - - // First count the total number of data blocks - int totalBlocks = 0; - vector ecBlockArray = ecBlocks->getECBlocks(); - for (size_t i = 0; i < ecBlockArray.size(); i++) { - totalBlocks += ecBlockArray[i]->getCount(); - } - - // Now establish DataBlocks of the appropriate size and number of data codewords - std::vector > result(totalBlocks); - int numResultBlocks = 0; - for (size_t j = 0; j < ecBlockArray.size(); j++) { - ECB *ecBlock = ecBlockArray[j]; - for (int i = 0; i < ecBlock->getCount(); i++) { - int numDataCodewords = ecBlock->getDataCodewords(); - int numBlockCodewords = ecBlocks->getECCodewords() + numDataCodewords; - ArrayRef buffer(numBlockCodewords); - Ref blockRef(new DataBlock(numDataCodewords, buffer)); - result[numResultBlocks++] = blockRef; - } - } - - // All blocks have the same amount of data, except that the last n - // (where n may be 0) have 1 more byte. Figure out where these start. - int shorterBlocksTotalCodewords = result[0]->codewords_.size(); - int longerBlocksStartAt = result.size() - 1; - while (longerBlocksStartAt >= 0) { - int numCodewords = result[longerBlocksStartAt]->codewords_.size(); - if (numCodewords == shorterBlocksTotalCodewords) { - break; - } - if (numCodewords != shorterBlocksTotalCodewords + 1) { - throw IllegalArgumentException("Data block sizes differ by more than 1"); - } - longerBlocksStartAt--; - } - longerBlocksStartAt++; - - int shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks->getECCodewords(); - // The last elements of result may be 1 element longer; - // first fill out as many elements as all of them have - int rawCodewordsOffset = 0; - for (int i = 0; i < shorterBlocksNumDataCodewords; i++) { - for (int j = 0; j < numResultBlocks; j++) { - result[j]->codewords_[i] = rawCodewords[rawCodewordsOffset++]; - } - } - // Fill out the last data block in the longer ones - for (int j = longerBlocksStartAt; j < numResultBlocks; j++) { - result[j]->codewords_[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++]; - } - // Now add in error correction blocks - int max = result[0]->codewords_.size(); - for (int i = shorterBlocksNumDataCodewords; i < max; i++) { - for (int j = 0; j < numResultBlocks; j++) { - int iOffset = j < longerBlocksStartAt ? i : i + 1; - result[j]->codewords_[iOffset] = rawCodewords[rawCodewordsOffset++]; - } - } - - if ((size_t)rawCodewordsOffset != rawCodewords.size()) { - throw IllegalArgumentException("rawCodewordsOffset != rawCodewords.length"); - } - - return result; -} - -} -} +/* + * DataBlock.cpp + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { +namespace datamatrix { + +using namespace std; + +DataBlock::DataBlock(int numDataCodewords, ArrayRef codewords) : + numDataCodewords_(numDataCodewords), codewords_(codewords) { +} + +int DataBlock::getNumDataCodewords() { + return numDataCodewords_; +} + +ArrayRef DataBlock::getCodewords() { + return codewords_; +} + +std::vector > DataBlock::getDataBlocks(ArrayRef rawCodewords, Version *version) { + // Figure out the number and size of data blocks used by this version and + // error correction level + ECBlocks* ecBlocks = version->getECBlocks(); + + // First count the total number of data blocks + int totalBlocks = 0; + vector ecBlockArray = ecBlocks->getECBlocks(); + for (size_t i = 0; i < ecBlockArray.size(); i++) { + totalBlocks += ecBlockArray[i]->getCount(); + } + + // Now establish DataBlocks of the appropriate size and number of data codewords + std::vector > result(totalBlocks); + int numResultBlocks = 0; + for (size_t j = 0; j < ecBlockArray.size(); j++) { + ECB *ecBlock = ecBlockArray[j]; + for (int i = 0; i < ecBlock->getCount(); i++) { + int numDataCodewords = ecBlock->getDataCodewords(); + int numBlockCodewords = ecBlocks->getECCodewords() + numDataCodewords; + ArrayRef buffer(numBlockCodewords); + Ref blockRef(new DataBlock(numDataCodewords, buffer)); + result[numResultBlocks++] = blockRef; + } + } + + // All blocks have the same amount of data, except that the last n + // (where n may be 0) have 1 more byte. Figure out where these start. + int shorterBlocksTotalCodewords = result[0]->codewords_.size(); + int longerBlocksStartAt = result.size() - 1; + while (longerBlocksStartAt >= 0) { + int numCodewords = result[longerBlocksStartAt]->codewords_.size(); + if (numCodewords == shorterBlocksTotalCodewords) { + break; + } + if (numCodewords != shorterBlocksTotalCodewords + 1) { + throw IllegalArgumentException("Data block sizes differ by more than 1"); + } + longerBlocksStartAt--; + } + longerBlocksStartAt++; + + int shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks->getECCodewords(); + // The last elements of result may be 1 element longer; + // first fill out as many elements as all of them have + int rawCodewordsOffset = 0; + for (int i = 0; i < shorterBlocksNumDataCodewords; i++) { + for (int j = 0; j < numResultBlocks; j++) { + result[j]->codewords_[i] = rawCodewords[rawCodewordsOffset++]; + } + } + // Fill out the last data block in the longer ones + for (int j = longerBlocksStartAt; j < numResultBlocks; j++) { + result[j]->codewords_[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++]; + } + // Now add in error correction blocks + int max = result[0]->codewords_.size(); + for (int i = shorterBlocksNumDataCodewords; i < max; i++) { + for (int j = 0; j < numResultBlocks; j++) { + int iOffset = j < longerBlocksStartAt ? i : i + 1; + result[j]->codewords_[iOffset] = rawCodewords[rawCodewordsOffset++]; + } + } + + if ((size_t)rawCodewordsOffset != rawCodewords.size()) { + throw IllegalArgumentException("rawCodewordsOffset != rawCodewords.length"); + } + + return result; +} + +} +} diff --git a/symbian/QZXing/source/zxing/datamatrix/decoder/DecodedBitStreamParserDM.cpp b/symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixDecodedBitStreamParser.cpp similarity index 96% rename from symbian/QZXing/source/zxing/datamatrix/decoder/DecodedBitStreamParserDM.cpp rename to symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixDecodedBitStreamParser.cpp index 47baaa3f1..3be36f2d6 100644 --- a/symbian/QZXing/source/zxing/datamatrix/decoder/DecodedBitStreamParserDM.cpp +++ b/symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixDecodedBitStreamParser.cpp @@ -1,417 +1,417 @@ -/* - * DecodedBitStreamParser.cpp - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { -namespace datamatrix { - -using namespace std; - -const char DecodedBitStreamParser::C40_BASIC_SET_CHARS[] = { - '*', '*', '*', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' -}; - -const char DecodedBitStreamParser::C40_SHIFT2_SET_CHARS[] = { - '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', - '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_' -}; - -const char DecodedBitStreamParser::TEXT_BASIC_SET_CHARS[] = { - '*', '*', '*', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' -}; - -const char DecodedBitStreamParser::TEXT_SHIFT3_SET_CHARS[] = { - '\'', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', (char) 127 -}; - -Ref DecodedBitStreamParser::decode(ArrayRef bytes) { - Ref bits(new BitSource(bytes)); - ostringstream result; - ostringstream resultTrailer; - vector byteSegments; - int mode = ASCII_ENCODE; - do { - if (mode == ASCII_ENCODE) { - mode = decodeAsciiSegment(bits, result, resultTrailer); - } else { - switch (mode) { - case C40_ENCODE: - decodeC40Segment(bits, result); - break; - case TEXT_ENCODE: - decodeTextSegment(bits, result); - break; - case ANSIX12_ENCODE: - decodeAnsiX12Segment(bits, result); - break; - case EDIFACT_ENCODE: - decodeEdifactSegment(bits, result); - break; - case BASE256_ENCODE: - decodeBase256Segment(bits, result, byteSegments); - break; - default: - throw FormatException("Unsupported mode indicator"); - } - mode = ASCII_ENCODE; - } - } while (mode != PAD_ENCODE && bits->available() > 0); - - if (resultTrailer.str().size() > 0) { - result << resultTrailer.str(); - } - ArrayRef rawBytes(bytes); - Ref text(new String(result.str())); - return Ref(new DecoderResult(rawBytes, text)); -} - -int DecodedBitStreamParser::decodeAsciiSegment(Ref bits, ostringstream & result, - ostringstream & resultTrailer) { - bool upperShift = false; - do { - int oneByte = bits->readBits(8); - if (oneByte == 0) { - throw FormatException("Not enough bits to decode"); - } else if (oneByte <= 128) { // ASCII data (ASCII value + 1) - oneByte = upperShift ? (oneByte + 128) : oneByte; - // upperShift = false; - result << (char) (oneByte - 1); - return ASCII_ENCODE; - } else if (oneByte == 129) { // Pad - return PAD_ENCODE; - } else if (oneByte <= 229) { // 2-digit data 00-99 (Numeric Value + 130) - int value = oneByte - 130; - if (value < 10) { // padd with '0' for single digit values - result << '0'; - } - result << value; - } else if (oneByte == 230) { // Latch to C40 encodation - return C40_ENCODE; - } else if (oneByte == 231) { // Latch to Base 256 encodation - return BASE256_ENCODE; - } else if (oneByte == 232) { // FNC1 - result << ((char) 29); // translate as ASCII 29 - } else if (oneByte == 233 || oneByte == 234) { - // Structured Append, Reader Programming - // Ignore these symbols for now - // throw FormatException.getInstance(); - } else if (oneByte == 235) { // Upper Shift (shift to Extended ASCII) - upperShift = true; - } else if (oneByte == 236) { // 05 Macro - result << ("[)>RS05GS"); - resultTrailer << ("RSEOT"); - } else if (oneByte == 237) { // 06 Macro - result << ("[)>RS06GS"); - resultTrailer << ("RSEOT"); - } else if (oneByte == 238) { // Latch to ANSI X12 encodation - return ANSIX12_ENCODE; - } else if (oneByte == 239) { // Latch to Text encodation - return TEXT_ENCODE; - } else if (oneByte == 240) { // Latch to EDIFACT encodation - return EDIFACT_ENCODE; - } else if (oneByte == 241) { // ECI Character - // TODO(bbrown): I think we need to support ECI - // throw FormatException.getInstance(); - // Ignore this symbol for now - } else if (oneByte >= 242) { // Not to be used in ASCII encodation - // ... but work around encoders that end with 254, latch back to ASCII - if (oneByte == 254 && bits->available() == 0) { - // Ignore - } else { - throw FormatException("Not to be used in ASCII encodation"); - } - } - } while (bits->available() > 0); - return ASCII_ENCODE; -} - -void DecodedBitStreamParser::decodeC40Segment(Ref bits, ostringstream & result) { - // Three C40 values are encoded in a 16-bit value as - // (1600 * C1) + (40 * C2) + C3 + 1 - // TODO(bbrown): The Upper Shift with C40 doesn't work in the 4 value scenario all the time - bool upperShift = false; - - int* cValues = new int[3]; - int shift = 0; - do { - // If there is only one byte left then it will be encoded as ASCII - if (bits->available() == 8) { - return; - } - int firstByte = bits->readBits(8); - if (firstByte == 254) { // Unlatch codeword - return; - } - - parseTwoBytes(firstByte, bits->readBits(8), cValues); - - for (int i = 0; i < 3; i++) { - int cValue = cValues[i]; - switch (shift) { - case 0: - if (cValue < 3) { - shift = cValue + 1; - } else { - if (upperShift) { - result << (char) (C40_BASIC_SET_CHARS[cValue] + 128); - upperShift = false; - } else { - result << C40_BASIC_SET_CHARS[cValue]; - } - } - break; - case 1: - if (upperShift) { - result << (char) (cValue + 128); - upperShift = false; - } else { - result << (char) cValue; - } - shift = 0; - break; - case 2: - if (cValue < 27) { - if (upperShift) { - result << (char) (C40_SHIFT2_SET_CHARS[cValue] + 128); - upperShift = false; - } else { - result << C40_SHIFT2_SET_CHARS[cValue]; - } - } else if (cValue == 27) { // FNC1 - result << ((char) 29); // translate as ASCII 29 - } else if (cValue == 30) { // Upper Shift - upperShift = true; - } else { - throw FormatException("decodeC40Segment: Upper Shift"); - } - shift = 0; - break; - case 3: - if (upperShift) { - result << (char) (cValue + 224); - upperShift = false; - } else { - result << (char) (cValue + 96); - } - shift = 0; - break; - default: - throw FormatException("decodeC40Segment: no case"); - } - } - } while (bits->available() > 0); -} - -void DecodedBitStreamParser::decodeTextSegment(Ref bits, ostringstream & result) { - // Three Text values are encoded in a 16-bit value as - // (1600 * C1) + (40 * C2) + C3 + 1 - // TODO(bbrown): The Upper Shift with Text doesn't work in the 4 value scenario all the time - bool upperShift = false; - - int* cValues = new int[3]; - int shift = 0; - do { - // If there is only one byte left then it will be encoded as ASCII - if (bits->available() == 8) { - return; - } - int firstByte = bits->readBits(8); - if (firstByte == 254) { // Unlatch codeword - return; - } - - parseTwoBytes(firstByte, bits->readBits(8), cValues); - - for (int i = 0; i < 3; i++) { - int cValue = cValues[i]; - switch (shift) { - case 0: - if (cValue < 3) { - shift = cValue + 1; - } else { - if (upperShift) { - result << (char) (TEXT_BASIC_SET_CHARS[cValue] + 128); - upperShift = false; - } else { - result << (TEXT_BASIC_SET_CHARS[cValue]); - } - } - break; - case 1: - if (upperShift) { - result << (char) (cValue + 128); - upperShift = false; - } else { - result << (char) (cValue); - } - shift = 0; - break; - case 2: - // Shift 2 for Text is the same encoding as C40 - if (cValue < 27) { - if (upperShift) { - result << (char) (C40_SHIFT2_SET_CHARS[cValue] + 128); - upperShift = false; - } else { - result << (C40_SHIFT2_SET_CHARS[cValue]); - } - } else if (cValue == 27) { // FNC1 - result << ((char) 29); // translate as ASCII 29 - } else if (cValue == 30) { // Upper Shift - upperShift = true; - } else { - throw FormatException("decodeTextSegment: Upper Shift"); - } - shift = 0; - break; - case 3: - if (upperShift) { - result << (char) (TEXT_SHIFT3_SET_CHARS[cValue] + 128); - upperShift = false; - } else { - result << (TEXT_SHIFT3_SET_CHARS[cValue]); - } - shift = 0; - break; - default: - throw FormatException("decodeTextSegment: no case"); - } - } - } while (bits->available() > 0); -} - -void DecodedBitStreamParser::decodeAnsiX12Segment(Ref bits, ostringstream & result) { - // Three ANSI X12 values are encoded in a 16-bit value as - // (1600 * C1) + (40 * C2) + C3 + 1 - - int* cValues = new int[3]; - do { - // If there is only one byte left then it will be encoded as ASCII - if (bits->available() == 8) { - return; - } - int firstByte = bits->readBits(8); - if (firstByte == 254) { // Unlatch codeword - return; - } - - parseTwoBytes(firstByte, bits->readBits(8), cValues); - - for (int i = 0; i < 3; i++) { - int cValue = cValues[i]; - if (cValue == 0) { // X12 segment terminator - result << '\r'; - } else if (cValue == 1) { // X12 segment separator * - result << '*'; - } else if (cValue == 2) { // X12 sub-element separator > - result << '>'; - } else if (cValue == 3) { // space - result << ' '; - } else if (cValue < 14) { // 0 - 9 - result << (char) (cValue + 44); - } else if (cValue < 40) { // A - Z - result << (char) (cValue + 51); - } else { - throw FormatException("decodeAnsiX12Segment: no case"); - } - } - } while (bits->available() > 0); -} - -void DecodedBitStreamParser::parseTwoBytes(int firstByte, int secondByte, int*& result) { - int fullBitValue = (firstByte << 8) + secondByte - 1; - int temp = fullBitValue / 1600; - result[0] = temp; - fullBitValue -= temp * 1600; - temp = fullBitValue / 40; - result[1] = temp; - result[2] = fullBitValue - temp * 40; -} - -void DecodedBitStreamParser::decodeEdifactSegment(Ref bits, ostringstream & result) { - bool unlatch = false; - do { - // If there is only two or less bytes left then it will be encoded as ASCII - if (bits->available() <= 16) { - return; - } - - for (int i = 0; i < 4; i++) { - int edifactValue = bits->readBits(6); - - // Check for the unlatch character - if (edifactValue == 0x2B67) { // 011111 - unlatch = true; - // If we encounter the unlatch code then continue reading because the Codeword triple - // is padded with 0's - } - - if (!unlatch) { - if ((edifactValue & 0x20) == 0) { // no 1 in the leading (6th) bit - edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value - } - result << (char)(edifactValue); - } - } - } while (!unlatch && bits->available() > 0); -} - -void DecodedBitStreamParser::decodeBase256Segment(Ref bits, ostringstream& result, vector byteSegments) { - // Figure out how long the Base 256 Segment is. - int codewordPosition = 1 + bits->getByteOffset(); // position is 1-indexed - int d1 = unrandomize255State(bits->readBits(8), codewordPosition++); - int count; - if (d1 == 0) { // Read the remainder of the symbol - count = bits->available() / 8; - } else if (d1 < 250) { - count = d1; - } else { - count = 250 * (d1 - 249) + unrandomize255State(bits->readBits(8), codewordPosition++); - } - - // We're seeing NegativeArraySizeException errors from users. - if (count < 0) { - throw FormatException("NegativeArraySizeException"); - } - - unsigned char* bytes = new unsigned char[count]; - for (int i = 0; i < count; i++) { - // Have seen this particular error in the wild, such as at - // http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2 - if (bits->available() < 8) { - throw FormatException("byteSegments"); - } - bytes[i] = unrandomize255State(bits->readBits(8), codewordPosition++); - byteSegments.push_back(bytes[i]); - result << (char)bytes[i]; - } -} -} -} - +/* + * DecodedBitStreamParser.cpp + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { +namespace datamatrix { + +using namespace std; + +const char DecodedBitStreamParser::C40_BASIC_SET_CHARS[] = { + '*', '*', '*', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' +}; + +const char DecodedBitStreamParser::C40_SHIFT2_SET_CHARS[] = { + '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', + '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_' +}; + +const char DecodedBitStreamParser::TEXT_BASIC_SET_CHARS[] = { + '*', '*', '*', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', + 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' +}; + +const char DecodedBitStreamParser::TEXT_SHIFT3_SET_CHARS[] = { + '\'', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', (char) 127 +}; + +Ref DecodedBitStreamParser::decode(ArrayRef bytes) { + Ref bits(new BitSource(bytes)); + ostringstream result; + ostringstream resultTrailer; + vector byteSegments; + int mode = ASCII_ENCODE; + do { + if (mode == ASCII_ENCODE) { + mode = decodeAsciiSegment(bits, result, resultTrailer); + } else { + switch (mode) { + case C40_ENCODE: + decodeC40Segment(bits, result); + break; + case TEXT_ENCODE: + decodeTextSegment(bits, result); + break; + case ANSIX12_ENCODE: + decodeAnsiX12Segment(bits, result); + break; + case EDIFACT_ENCODE: + decodeEdifactSegment(bits, result); + break; + case BASE256_ENCODE: + decodeBase256Segment(bits, result, byteSegments); + break; + default: + throw FormatException("Unsupported mode indicator"); + } + mode = ASCII_ENCODE; + } + } while (mode != PAD_ENCODE && bits->available() > 0); + + if (resultTrailer.str().size() > 0) { + result << resultTrailer.str(); + } + ArrayRef rawBytes(bytes); + Ref text(new String(result.str())); + return Ref(new DecoderResult(rawBytes, text)); +} + +int DecodedBitStreamParser::decodeAsciiSegment(Ref bits, ostringstream & result, + ostringstream & resultTrailer) { + bool upperShift = false; + do { + int oneByte = bits->readBits(8); + if (oneByte == 0) { + throw FormatException("Not enough bits to decode"); + } else if (oneByte <= 128) { // ASCII data (ASCII value + 1) + oneByte = upperShift ? (oneByte + 128) : oneByte; + // upperShift = false; + result << (char) (oneByte - 1); + return ASCII_ENCODE; + } else if (oneByte == 129) { // Pad + return PAD_ENCODE; + } else if (oneByte <= 229) { // 2-digit data 00-99 (Numeric Value + 130) + int value = oneByte - 130; + if (value < 10) { // padd with '0' for single digit values + result << '0'; + } + result << value; + } else if (oneByte == 230) { // Latch to C40 encodation + return C40_ENCODE; + } else if (oneByte == 231) { // Latch to Base 256 encodation + return BASE256_ENCODE; + } else if (oneByte == 232) { // FNC1 + result << ((char) 29); // translate as ASCII 29 + } else if (oneByte == 233 || oneByte == 234) { + // Structured Append, Reader Programming + // Ignore these symbols for now + // throw FormatException.getInstance(); + } else if (oneByte == 235) { // Upper Shift (shift to Extended ASCII) + upperShift = true; + } else if (oneByte == 236) { // 05 Macro + result << ("[)>RS05GS"); + resultTrailer << ("RSEOT"); + } else if (oneByte == 237) { // 06 Macro + result << ("[)>RS06GS"); + resultTrailer << ("RSEOT"); + } else if (oneByte == 238) { // Latch to ANSI X12 encodation + return ANSIX12_ENCODE; + } else if (oneByte == 239) { // Latch to Text encodation + return TEXT_ENCODE; + } else if (oneByte == 240) { // Latch to EDIFACT encodation + return EDIFACT_ENCODE; + } else if (oneByte == 241) { // ECI Character + // TODO(bbrown): I think we need to support ECI + // throw FormatException.getInstance(); + // Ignore this symbol for now + } else if (oneByte >= 242) { // Not to be used in ASCII encodation + // ... but work around encoders that end with 254, latch back to ASCII + if (oneByte == 254 && bits->available() == 0) { + // Ignore + } else { + throw FormatException("Not to be used in ASCII encodation"); + } + } + } while (bits->available() > 0); + return ASCII_ENCODE; +} + +void DecodedBitStreamParser::decodeC40Segment(Ref bits, ostringstream & result) { + // Three C40 values are encoded in a 16-bit value as + // (1600 * C1) + (40 * C2) + C3 + 1 + // TODO(bbrown): The Upper Shift with C40 doesn't work in the 4 value scenario all the time + bool upperShift = false; + + int* cValues = new int[3]; + int shift = 0; + do { + // If there is only one byte left then it will be encoded as ASCII + if (bits->available() == 8) { + return; + } + int firstByte = bits->readBits(8); + if (firstByte == 254) { // Unlatch codeword + return; + } + + parseTwoBytes(firstByte, bits->readBits(8), cValues); + + for (int i = 0; i < 3; i++) { + int cValue = cValues[i]; + switch (shift) { + case 0: + if (cValue < 3) { + shift = cValue + 1; + } else { + if (upperShift) { + result << (char) (C40_BASIC_SET_CHARS[cValue] + 128); + upperShift = false; + } else { + result << C40_BASIC_SET_CHARS[cValue]; + } + } + break; + case 1: + if (upperShift) { + result << (char) (cValue + 128); + upperShift = false; + } else { + result << (char) cValue; + } + shift = 0; + break; + case 2: + if (cValue < 27) { + if (upperShift) { + result << (char) (C40_SHIFT2_SET_CHARS[cValue] + 128); + upperShift = false; + } else { + result << C40_SHIFT2_SET_CHARS[cValue]; + } + } else if (cValue == 27) { // FNC1 + result << ((char) 29); // translate as ASCII 29 + } else if (cValue == 30) { // Upper Shift + upperShift = true; + } else { + throw FormatException("decodeC40Segment: Upper Shift"); + } + shift = 0; + break; + case 3: + if (upperShift) { + result << (char) (cValue + 224); + upperShift = false; + } else { + result << (char) (cValue + 96); + } + shift = 0; + break; + default: + throw FormatException("decodeC40Segment: no case"); + } + } + } while (bits->available() > 0); +} + +void DecodedBitStreamParser::decodeTextSegment(Ref bits, ostringstream & result) { + // Three Text values are encoded in a 16-bit value as + // (1600 * C1) + (40 * C2) + C3 + 1 + // TODO(bbrown): The Upper Shift with Text doesn't work in the 4 value scenario all the time + bool upperShift = false; + + int* cValues = new int[3]; + int shift = 0; + do { + // If there is only one byte left then it will be encoded as ASCII + if (bits->available() == 8) { + return; + } + int firstByte = bits->readBits(8); + if (firstByte == 254) { // Unlatch codeword + return; + } + + parseTwoBytes(firstByte, bits->readBits(8), cValues); + + for (int i = 0; i < 3; i++) { + int cValue = cValues[i]; + switch (shift) { + case 0: + if (cValue < 3) { + shift = cValue + 1; + } else { + if (upperShift) { + result << (char) (TEXT_BASIC_SET_CHARS[cValue] + 128); + upperShift = false; + } else { + result << (TEXT_BASIC_SET_CHARS[cValue]); + } + } + break; + case 1: + if (upperShift) { + result << (char) (cValue + 128); + upperShift = false; + } else { + result << (char) (cValue); + } + shift = 0; + break; + case 2: + // Shift 2 for Text is the same encoding as C40 + if (cValue < 27) { + if (upperShift) { + result << (char) (C40_SHIFT2_SET_CHARS[cValue] + 128); + upperShift = false; + } else { + result << (C40_SHIFT2_SET_CHARS[cValue]); + } + } else if (cValue == 27) { // FNC1 + result << ((char) 29); // translate as ASCII 29 + } else if (cValue == 30) { // Upper Shift + upperShift = true; + } else { + throw FormatException("decodeTextSegment: Upper Shift"); + } + shift = 0; + break; + case 3: + if (upperShift) { + result << (char) (TEXT_SHIFT3_SET_CHARS[cValue] + 128); + upperShift = false; + } else { + result << (TEXT_SHIFT3_SET_CHARS[cValue]); + } + shift = 0; + break; + default: + throw FormatException("decodeTextSegment: no case"); + } + } + } while (bits->available() > 0); +} + +void DecodedBitStreamParser::decodeAnsiX12Segment(Ref bits, ostringstream & result) { + // Three ANSI X12 values are encoded in a 16-bit value as + // (1600 * C1) + (40 * C2) + C3 + 1 + + int* cValues = new int[3]; + do { + // If there is only one byte left then it will be encoded as ASCII + if (bits->available() == 8) { + return; + } + int firstByte = bits->readBits(8); + if (firstByte == 254) { // Unlatch codeword + return; + } + + parseTwoBytes(firstByte, bits->readBits(8), cValues); + + for (int i = 0; i < 3; i++) { + int cValue = cValues[i]; + if (cValue == 0) { // X12 segment terminator + result << '\r'; + } else if (cValue == 1) { // X12 segment separator * + result << '*'; + } else if (cValue == 2) { // X12 sub-element separator > + result << '>'; + } else if (cValue == 3) { // space + result << ' '; + } else if (cValue < 14) { // 0 - 9 + result << (char) (cValue + 44); + } else if (cValue < 40) { // A - Z + result << (char) (cValue + 51); + } else { + throw FormatException("decodeAnsiX12Segment: no case"); + } + } + } while (bits->available() > 0); +} + +void DecodedBitStreamParser::parseTwoBytes(int firstByte, int secondByte, int*& result) { + int fullBitValue = (firstByte << 8) + secondByte - 1; + int temp = fullBitValue / 1600; + result[0] = temp; + fullBitValue -= temp * 1600; + temp = fullBitValue / 40; + result[1] = temp; + result[2] = fullBitValue - temp * 40; +} + +void DecodedBitStreamParser::decodeEdifactSegment(Ref bits, ostringstream & result) { + bool unlatch = false; + do { + // If there is only two or less bytes left then it will be encoded as ASCII + if (bits->available() <= 16) { + return; + } + + for (int i = 0; i < 4; i++) { + int edifactValue = bits->readBits(6); + + // Check for the unlatch character + if (edifactValue == 0x2B67) { // 011111 + unlatch = true; + // If we encounter the unlatch code then continue reading because the Codeword triple + // is padded with 0's + } + + if (!unlatch) { + if ((edifactValue & 0x20) == 0) { // no 1 in the leading (6th) bit + edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value + } + result << (char)(edifactValue); + } + } + } while (!unlatch && bits->available() > 0); +} + +void DecodedBitStreamParser::decodeBase256Segment(Ref bits, ostringstream& result, vector byteSegments) { + // Figure out how long the Base 256 Segment is. + int codewordPosition = 1 + bits->getByteOffset(); // position is 1-indexed + int d1 = unrandomize255State(bits->readBits(8), codewordPosition++); + int count; + if (d1 == 0) { // Read the remainder of the symbol + count = bits->available() / 8; + } else if (d1 < 250) { + count = d1; + } else { + count = 250 * (d1 - 249) + unrandomize255State(bits->readBits(8), codewordPosition++); + } + + // We're seeing NegativeArraySizeException errors from users. + if (count < 0) { + throw FormatException("NegativeArraySizeException"); + } + + unsigned char* bytes = new unsigned char[count]; + for (int i = 0; i < count; i++) { + // Have seen this particular error in the wild, such as at + // http://www.bcgen.com/demo/IDAutomationStreamingDataMatrix.aspx?MODE=3&D=Fred&PFMT=3&PT=F&X=0.3&O=0&LM=0.2 + if (bits->available() < 8) { + throw FormatException("byteSegments"); + } + bytes[i] = unrandomize255State(bits->readBits(8), codewordPosition++); + byteSegments.push_back(bytes[i]); + result << (char)bytes[i]; + } +} +} +} + diff --git a/symbian/QZXing/source/zxing/datamatrix/decoder/DecoderDM.cpp b/symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixDecoder.cpp similarity index 88% rename from symbian/QZXing/source/zxing/datamatrix/decoder/DecoderDM.cpp rename to symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixDecoder.cpp index 1a442a926..34d7a9a14 100644 --- a/symbian/QZXing/source/zxing/datamatrix/decoder/DecoderDM.cpp +++ b/symbian/QZXing/source/zxing/datamatrix/decoder/DataMatrixDecoder.cpp @@ -1,94 +1,94 @@ -/* - * Decoder.cpp - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace zxing { -namespace datamatrix { - -using namespace std; - -Decoder::Decoder() : - rsDecoder_(GF256::DATA_MATRIX_FIELD) { -} - - -void Decoder::correctErrors(ArrayRef codewordBytes, int numDataCodewords) { - int numCodewords = codewordBytes->size(); - ArrayRef codewordInts(numCodewords); - for (int i = 0; i < numCodewords; i++) { - codewordInts[i] = codewordBytes[i] & 0xff; - } - int numECCodewords = numCodewords - numDataCodewords; - try { - rsDecoder_.decode(codewordInts, numECCodewords); - } catch (ReedSolomonException const& ex) { - ReaderException rex(ex.what()); - throw rex; - } - // Copy back into array of bytes -- only need to worry about the bytes that were data - // We don't care about errors in the error-correction codewords - for (int i = 0; i < numDataCodewords; i++) { - codewordBytes[i] = (unsigned char)codewordInts[i]; - } -} - -Ref Decoder::decode(Ref bits) { - // Construct a parser and read version, error-correction level - BitMatrixParser parser(bits); - Version *version = parser.readVersion(bits); - - // Read codewords - ArrayRef codewords(parser.readCodewords()); - // Separate into data blocks - std::vector > dataBlocks = DataBlock::getDataBlocks(codewords, version); - - int dataBlocksCount = dataBlocks.size(); - - // Count total number of data bytes - int totalBytes = 0; - for (int i = 0; i < dataBlocksCount; i++) { - totalBytes += dataBlocks[i]->getNumDataCodewords(); - } - ArrayRef resultBytes(totalBytes); - - // Error-correct and copy data blocks together into a stream of bytes - for (int j = 0; j < dataBlocksCount; j++) { - Ref dataBlock(dataBlocks[j]); - ArrayRef codewordBytes = dataBlock->getCodewords(); - int numDataCodewords = dataBlock->getNumDataCodewords(); - correctErrors(codewordBytes, numDataCodewords); - for (int i = 0; i < numDataCodewords; i++) { - // De-interlace data blocks. - resultBytes[i * dataBlocksCount + j] = codewordBytes[i]; - } - } - // Decode the contents of that stream of bytes - DecodedBitStreamParser decodedBSParser; - return Ref (decodedBSParser.decode(resultBytes)); -} -} -} +/* + * Decoder.cpp + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +namespace zxing { +namespace datamatrix { + +using namespace std; + +Decoder::Decoder() : + rsDecoder_(GenericGF::DATA_MATRIX_FIELD_256) { +} + + +void Decoder::correctErrors(ArrayRef codewordBytes, int numDataCodewords) { + int numCodewords = codewordBytes->size(); + ArrayRef codewordInts(numCodewords); + for (int i = 0; i < numCodewords; i++) { + codewordInts[i] = codewordBytes[i] & 0xff; + } + int numECCodewords = numCodewords - numDataCodewords; + try { + rsDecoder_.decode(codewordInts, numECCodewords); + } catch (ReedSolomonException const& ex) { + ReaderException rex(ex.what()); + throw rex; + } + // Copy back into array of bytes -- only need to worry about the bytes that were data + // We don't care about errors in the error-correction codewords + for (int i = 0; i < numDataCodewords; i++) { + codewordBytes[i] = (unsigned char)codewordInts[i]; + } +} + +Ref Decoder::decode(Ref bits) { + // Construct a parser and read version, error-correction level + BitMatrixParser parser(bits); + Version *version = parser.readVersion(bits); + + // Read codewords + ArrayRef codewords(parser.readCodewords()); + // Separate into data blocks + std::vector > dataBlocks = DataBlock::getDataBlocks(codewords, version); + + int dataBlocksCount = dataBlocks.size(); + + // Count total number of data bytes + int totalBytes = 0; + for (int i = 0; i < dataBlocksCount; i++) { + totalBytes += dataBlocks[i]->getNumDataCodewords(); + } + ArrayRef resultBytes(totalBytes); + + // Error-correct and copy data blocks together into a stream of bytes + for (int j = 0; j < dataBlocksCount; j++) { + Ref dataBlock(dataBlocks[j]); + ArrayRef codewordBytes = dataBlock->getCodewords(); + int numDataCodewords = dataBlock->getNumDataCodewords(); + correctErrors(codewordBytes, numDataCodewords); + for (int i = 0; i < numDataCodewords; i++) { + // De-interlace data blocks. + resultBytes[i * dataBlocksCount + j] = codewordBytes[i]; + } + } + // Decode the contents of that stream of bytes + DecodedBitStreamParser decodedBSParser; + return Ref (decodedBSParser.decode(resultBytes)); +} +} +} diff --git a/symbian/QZXing/source/zxing/datamatrix/decoder/DecodedBitStreamParserDM.h b/symbian/QZXing/source/zxing/datamatrix/decoder/DecodedBitStreamParser.h similarity index 97% rename from symbian/QZXing/source/zxing/datamatrix/decoder/DecodedBitStreamParserDM.h rename to symbian/QZXing/source/zxing/datamatrix/decoder/DecodedBitStreamParser.h index 20414c084..2a1b5f164 100644 --- a/symbian/QZXing/source/zxing/datamatrix/decoder/DecodedBitStreamParserDM.h +++ b/symbian/QZXing/source/zxing/datamatrix/decoder/DecodedBitStreamParser.h @@ -1,104 +1,104 @@ -#ifndef __DECODED_BIT_STREAM_PARSER_DM_H__ -#define __DECODED_BIT_STREAM_PARSER_DM_H__ - -/* - * DecodedBitStreamParser.h - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - - -namespace zxing { -namespace datamatrix { - -class DecodedBitStreamParser { -private: - static const int PAD_ENCODE = 0; // Not really an encoding - static const int ASCII_ENCODE = 1; - static const int C40_ENCODE = 2; - static const int TEXT_ENCODE = 3; - static const int ANSIX12_ENCODE = 4; - static const int EDIFACT_ENCODE = 5; - static const int BASE256_ENCODE = 6; - - /** - * See ISO 16022:2006, Annex C Table C.1 - * The C40 Basic Character Set (*'s used for placeholders for the shift values) - */ - static const char C40_BASIC_SET_CHARS[]; - - static const char C40_SHIFT2_SET_CHARS[]; - /** - * See ISO 16022:2006, Annex C Table C.2 - * The Text Basic Character Set (*'s used for placeholders for the shift values) - */ - static const char TEXT_BASIC_SET_CHARS[]; - - static const char TEXT_SHIFT3_SET_CHARS[]; - /** - * See ISO 16022:2006, 5.2.3 and Annex C, Table C.2 - */ - int decodeAsciiSegment(Ref bits, std::ostringstream &result, std::ostringstream &resultTrailer); - /** - * See ISO 16022:2006, 5.2.5 and Annex C, Table C.1 - */ - void decodeC40Segment(Ref bits, std::ostringstream &result); - /** - * See ISO 16022:2006, 5.2.6 and Annex C, Table C.2 - */ - void decodeTextSegment(Ref bits, std::ostringstream &result); - /** - * See ISO 16022:2006, 5.2.7 - */ - void decodeAnsiX12Segment(Ref bits, std::ostringstream &result); - /** - * See ISO 16022:2006, 5.2.8 and Annex C Table C.3 - */ - void decodeEdifactSegment(Ref bits, std::ostringstream &result); - /** - * See ISO 16022:2006, 5.2.9 and Annex B, B.2 - */ - void decodeBase256Segment(Ref bits, std::ostringstream &result, std::vector byteSegments); - - void parseTwoBytes(int firstByte, int secondByte, int*& result); - /** - * See ISO 16022:2006, Annex B, B.2 - */ - unsigned char unrandomize255State(int randomizedBase256Codeword, - int base256CodewordPosition) { - int pseudoRandomNumber = ((149 * base256CodewordPosition) % 255) + 1; - int tempVariable = randomizedBase256Codeword - pseudoRandomNumber; - return (unsigned char) (tempVariable >= 0 ? tempVariable : (tempVariable + 256)); - }; - void append(std::ostream &ost, const unsigned char *bufIn, size_t nIn, const char *src); - -public: - DecodedBitStreamParser() { }; - Ref decode(ArrayRef bytes); -}; - -} -} - -#endif // __DECODED_BIT_STREAM_PARSER_DM_H__ +#ifndef __DECODED_BIT_STREAM_PARSER_DM_H__ +#define __DECODED_BIT_STREAM_PARSER_DM_H__ + +/* + * DecodedBitStreamParser.h + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + + +namespace zxing { +namespace datamatrix { + +class DecodedBitStreamParser { +private: + static const int PAD_ENCODE = 0; // Not really an encoding + static const int ASCII_ENCODE = 1; + static const int C40_ENCODE = 2; + static const int TEXT_ENCODE = 3; + static const int ANSIX12_ENCODE = 4; + static const int EDIFACT_ENCODE = 5; + static const int BASE256_ENCODE = 6; + + /** + * See ISO 16022:2006, Annex C Table C.1 + * The C40 Basic Character Set (*'s used for placeholders for the shift values) + */ + static const char C40_BASIC_SET_CHARS[]; + + static const char C40_SHIFT2_SET_CHARS[]; + /** + * See ISO 16022:2006, Annex C Table C.2 + * The Text Basic Character Set (*'s used for placeholders for the shift values) + */ + static const char TEXT_BASIC_SET_CHARS[]; + + static const char TEXT_SHIFT3_SET_CHARS[]; + /** + * See ISO 16022:2006, 5.2.3 and Annex C, Table C.2 + */ + int decodeAsciiSegment(Ref bits, std::ostringstream &result, std::ostringstream &resultTrailer); + /** + * See ISO 16022:2006, 5.2.5 and Annex C, Table C.1 + */ + void decodeC40Segment(Ref bits, std::ostringstream &result); + /** + * See ISO 16022:2006, 5.2.6 and Annex C, Table C.2 + */ + void decodeTextSegment(Ref bits, std::ostringstream &result); + /** + * See ISO 16022:2006, 5.2.7 + */ + void decodeAnsiX12Segment(Ref bits, std::ostringstream &result); + /** + * See ISO 16022:2006, 5.2.8 and Annex C Table C.3 + */ + void decodeEdifactSegment(Ref bits, std::ostringstream &result); + /** + * See ISO 16022:2006, 5.2.9 and Annex B, B.2 + */ + void decodeBase256Segment(Ref bits, std::ostringstream &result, std::vector byteSegments); + + void parseTwoBytes(int firstByte, int secondByte, int*& result); + /** + * See ISO 16022:2006, Annex B, B.2 + */ + unsigned char unrandomize255State(int randomizedBase256Codeword, + int base256CodewordPosition) { + int pseudoRandomNumber = ((149 * base256CodewordPosition) % 255) + 1; + int tempVariable = randomizedBase256Codeword - pseudoRandomNumber; + return (unsigned char) (tempVariable >= 0 ? tempVariable : (tempVariable + 256)); + }; + void append(std::ostream &ost, const unsigned char *bufIn, size_t nIn, const char *src); + +public: + DecodedBitStreamParser() { }; + Ref decode(ArrayRef bytes); +}; + +} +} + +#endif // __DECODED_BIT_STREAM_PARSER_DM_H__ diff --git a/symbian/QZXing/source/zxing/datamatrix/decoder/DecoderDM.h b/symbian/QZXing/source/zxing/datamatrix/decoder/Decoder.h similarity index 96% rename from symbian/QZXing/source/zxing/datamatrix/decoder/DecoderDM.h rename to symbian/QZXing/source/zxing/datamatrix/decoder/Decoder.h index 65fdf740c..3569d6be4 100644 --- a/symbian/QZXing/source/zxing/datamatrix/decoder/DecoderDM.h +++ b/symbian/QZXing/source/zxing/datamatrix/decoder/Decoder.h @@ -1,50 +1,49 @@ -#ifndef __DECODER_DM_H__ -#define __DECODER_DM_H__ - -/* - * Decoder.h - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - - -namespace zxing { -namespace datamatrix { - -class Decoder { -private: - ReedSolomonDecoder rsDecoder_; - - void correctErrors(ArrayRef bytes, int numDataCodewords); - -public: - Decoder(); - - Ref decode(Ref bits); -}; - -} -} - -#endif // __DECODER_DM_H__ +#ifndef __DECODER_DM_H__ +#define __DECODER_DM_H__ + +/* + * Decoder.h + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + + +namespace zxing { +namespace datamatrix { + +class Decoder { +private: + ReedSolomonDecoder rsDecoder_; + + void correctErrors(ArrayRef bytes, int numDataCodewords); + +public: + Decoder(); + + Ref decode(Ref bits); +}; + +} +} + +#endif // __DECODER_DM_H__ diff --git a/symbian/QZXing/source/zxing/datamatrix/detector/CornerPoint.h b/symbian/QZXing/source/zxing/datamatrix/detector/CornerPoint.h index cbf2a7ef6..8977eae32 100644 --- a/symbian/QZXing/source/zxing/datamatrix/detector/CornerPoint.h +++ b/symbian/QZXing/source/zxing/datamatrix/detector/CornerPoint.h @@ -1,43 +1,43 @@ -#ifndef __CORNER_FINDER_H__ -#define __CORNER_FINDER_H__ - -/* - * CornerPoint.h - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - namespace datamatrix { - - class CornerPoint : public ResultPoint { - private: - int counter_; - - public: - CornerPoint(float posX, float posY); - int getCount() const; - void incrementCount(); - bool equals(Ref other) const; - }; - } -} - -#endif // __CORNER_FINDER_H__ +#ifndef __CORNER_FINDER_H__ +#define __CORNER_FINDER_H__ + +/* + * CornerPoint.h + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + namespace datamatrix { + + class CornerPoint : public ResultPoint { + private: + int counter_; + + public: + CornerPoint(float posX, float posY); + int getCount() const; + void incrementCount(); + bool equals(Ref other) const; + }; + } +} + +#endif // __CORNER_FINDER_H__ diff --git a/symbian/QZXing/source/zxing/datamatrix/detector/CornerPoint.cpp b/symbian/QZXing/source/zxing/datamatrix/detector/DataMatrixCornerPoint.cpp similarity index 96% rename from symbian/QZXing/source/zxing/datamatrix/detector/CornerPoint.cpp rename to symbian/QZXing/source/zxing/datamatrix/detector/DataMatrixCornerPoint.cpp index b04f28237..101d78f20 100644 --- a/symbian/QZXing/source/zxing/datamatrix/detector/CornerPoint.cpp +++ b/symbian/QZXing/source/zxing/datamatrix/detector/DataMatrixCornerPoint.cpp @@ -1,46 +1,46 @@ -/* - * CornerPoint.cpp - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - - -namespace zxing { - namespace datamatrix { - - using namespace std; - - CornerPoint::CornerPoint(float posX, float posY) : - ResultPoint(posX,posY), counter_(0) { - } - - int CornerPoint::getCount() const { - return counter_; - } - - void CornerPoint::incrementCount() { - counter_++; - } - - bool CornerPoint::equals(Ref other) const { - return posX_ == other->getX() && posY_ == other->getY(); - } - - } -} +/* + * CornerPoint.cpp + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + + +namespace zxing { + namespace datamatrix { + + using namespace std; + + CornerPoint::CornerPoint(float posX, float posY) : + ResultPoint(posX,posY), counter_(0) { + } + + int CornerPoint::getCount() const { + return counter_; + } + + void CornerPoint::incrementCount() { + counter_++; + } + + bool CornerPoint::equals(Ref other) const { + return posX_ == other->getX() && posY_ == other->getY(); + } + + } +} diff --git a/symbian/QZXing/source/zxing/datamatrix/detector/DetectorDM.cpp b/symbian/QZXing/source/zxing/datamatrix/detector/DataMatrixDetector.cpp similarity index 96% rename from symbian/QZXing/source/zxing/datamatrix/detector/DetectorDM.cpp rename to symbian/QZXing/source/zxing/datamatrix/detector/DataMatrixDetector.cpp index e25c47a25..5e9b75e0f 100644 --- a/symbian/QZXing/source/zxing/datamatrix/detector/DetectorDM.cpp +++ b/symbian/QZXing/source/zxing/datamatrix/detector/DataMatrixDetector.cpp @@ -1,434 +1,434 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Detector.cpp - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace zxing { -namespace datamatrix { - -using namespace std; - -ResultPointsAndTransitions::ResultPointsAndTransitions() { - Ref ref(new ResultPoint(0, 0)); - from_ = ref; - to_ = ref; - transitions_ = 0; -} - -ResultPointsAndTransitions::ResultPointsAndTransitions(Ref from, Ref to, - int transitions) - : to_(to), from_(from), transitions_(transitions) { -} - -Ref ResultPointsAndTransitions::getFrom() { - return from_; -} - -Ref ResultPointsAndTransitions::getTo() { - return to_; -} - -int ResultPointsAndTransitions::getTransitions() { - return transitions_; -} - -Detector::Detector(Ref image) - : image_(image) { -} - -Ref Detector::getImage() { - return image_; -} - -Ref Detector::detect() { - Ref rectangleDetector_(new WhiteRectangleDetector(image_)); - std::vector > ResultPoints = rectangleDetector_->detect(); - Ref pointA = ResultPoints[0]; - Ref pointB = ResultPoints[1]; - Ref pointC = ResultPoints[2]; - Ref pointD = ResultPoints[3]; - - // Point A and D are across the diagonal from one another, - // as are B and C. Figure out which are the solid black lines - // by counting transitions - std::vector > transitions(4); - transitions[0].reset(transitionsBetween(pointA, pointB)); - transitions[1].reset(transitionsBetween(pointA, pointC)); - transitions[2].reset(transitionsBetween(pointB, pointD)); - transitions[3].reset(transitionsBetween(pointC, pointD)); - insertionSort(transitions); - - // Sort by number of transitions. First two will be the two solid sides; last two - // will be the two alternating black/white sides - Ref lSideOne(transitions[0]); - Ref lSideTwo(transitions[1]); - - // Figure out which point is their intersection by tallying up the number of times we see the - // endpoints in the four endpoints. One will show up twice. - Ref maybeTopLeft; - Ref bottomLeft; - Ref maybeBottomRight; - if (lSideOne->getFrom()->equals(lSideOne->getTo())) { - bottomLeft = lSideOne->getFrom(); - maybeTopLeft = lSideTwo->getFrom(); - maybeBottomRight = lSideTwo->getTo(); - } else if (lSideOne->getFrom()->equals(lSideTwo->getFrom())) { - bottomLeft = lSideOne->getFrom(); - maybeTopLeft = lSideOne->getTo(); - maybeBottomRight = lSideTwo->getTo(); - } else if (lSideOne->getFrom()->equals(lSideTwo->getTo())) { - bottomLeft = lSideOne->getFrom(); - maybeTopLeft = lSideOne->getTo(); - maybeBottomRight = lSideTwo->getFrom(); - } else if (lSideOne->getTo()->equals(lSideTwo->getFrom())) { - bottomLeft = lSideOne->getTo(); - maybeTopLeft = lSideOne->getFrom(); - maybeBottomRight = lSideTwo->getTo(); - } else if (lSideOne->getTo()->equals(lSideTwo->getTo())) { - bottomLeft = lSideOne->getTo(); - maybeTopLeft = lSideOne->getFrom(); - maybeBottomRight = lSideTwo->getFrom(); - } else { - bottomLeft = lSideTwo->getFrom(); - maybeTopLeft = lSideOne->getTo(); - maybeBottomRight = lSideOne->getFrom(); - } - - // Bottom left is correct but top left and bottom right might be switched - std::vector > corners(3); - corners[0].reset(maybeTopLeft); - corners[1].reset(bottomLeft); - corners[2].reset(maybeBottomRight); - - // Use the dot product trick to sort them out - ResultPoint::orderBestPatterns(corners); - - // Now we know which is which: - Ref bottomRight(corners[0]); - bottomLeft = corners[1]; - Ref topLeft(corners[2]); - - // Which point didn't we find in relation to the "L" sides? that's the top right corner - Ref topRight; - if (!(pointA->equals(bottomRight) || pointA->equals(bottomLeft) || pointA->equals(topLeft))) { - topRight = pointA; - } else if (!(pointB->equals(bottomRight) || pointB->equals(bottomLeft) - || pointB->equals(topLeft))) { - topRight = pointB; - } else if (!(pointC->equals(bottomRight) || pointC->equals(bottomLeft) - || pointC->equals(topLeft))) { - topRight = pointC; - } else { - topRight = pointD; - } - - // Next determine the dimension by tracing along the top or right side and counting black/white - // transitions. Since we start inside a black module, we should see a number of transitions - // equal to 1 less than the code dimension. Well, actually 2 less, because we are going to - // end on a black module: - - // The top right point is actually the corner of a module, which is one of the two black modules - // adjacent to the white module at the top right. Tracing to that corner from either the top left - // or bottom right should work here. - - int dimensionTop = transitionsBetween(topLeft, topRight)->getTransitions(); - int dimensionRight = transitionsBetween(bottomRight, topRight)->getTransitions(); - - //dimensionTop++; - if ((dimensionTop & 0x01) == 1) { - // it can't be odd, so, round... up? - dimensionTop++; - } - dimensionTop += 2; - - //dimensionRight++; - if ((dimensionRight & 0x01) == 1) { - // it can't be odd, so, round... up? - dimensionRight++; - } - dimensionRight += 2; - - Ref bits; - Ref transform; - Ref correctedTopRight; - - - // Rectanguar symbols are 6x16, 6x28, 10x24, 10x32, 14x32, or 14x44. If one dimension is more - // than twice the other, it's certainly rectangular, but to cut a bit more slack we accept it as - // rectangular if the bigger side is at least 7/4 times the other: - if (4 * dimensionTop >= 7 * dimensionRight || 4 * dimensionRight >= 7 * dimensionTop) { - // The matrix is rectangular - correctedTopRight = correctTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight, - dimensionTop, dimensionRight); - if (correctedTopRight == NULL) { - correctedTopRight = topRight; - } - - dimensionTop = transitionsBetween(topLeft, correctedTopRight)->getTransitions(); - dimensionRight = transitionsBetween(bottomRight, correctedTopRight)->getTransitions(); - - if ((dimensionTop & 0x01) == 1) { - // it can't be odd, so, round... up? - dimensionTop++; - } - - if ((dimensionRight & 0x01) == 1) { - // it can't be odd, so, round... up? - dimensionRight++; - } - - transform = createTransform(topLeft, correctedTopRight, bottomLeft, bottomRight, dimensionTop, - dimensionRight); - bits = sampleGrid(image_, dimensionTop, dimensionRight, transform); - - } else { - // The matrix is square - int dimension = min(dimensionRight, dimensionTop); - - // correct top right point to match the white module - correctedTopRight = correctTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension); - if (correctedTopRight == NULL) { - correctedTopRight = topRight; - } - - // Redetermine the dimension using the corrected top right point - int dimensionCorrected = max(transitionsBetween(topLeft, correctedTopRight)->getTransitions(), - transitionsBetween(bottomRight, correctedTopRight)->getTransitions()); - dimensionCorrected++; - if ((dimensionCorrected & 0x01) == 1) { - dimensionCorrected++; - } - - transform = createTransform(topLeft, correctedTopRight, bottomLeft, bottomRight, - dimensionCorrected, dimensionCorrected); - bits = sampleGrid(image_, dimensionCorrected, dimensionCorrected, transform); - } - - std::vector > points(4); - points[0].reset(topLeft); - points[1].reset(bottomLeft); - points[2].reset(correctedTopRight); - points[3].reset(bottomRight); - Ref detectorResult(new DetectorResult(bits, points, transform)); - return detectorResult; -} - -/** - * Calculates the position of the white top right module using the output of the rectangle detector - * for a rectangular matrix - */ -Ref Detector::correctTopRightRectangular(Ref bottomLeft, - Ref bottomRight, Ref topLeft, Ref topRight, - int dimensionTop, int dimensionRight) { - - float corr = distance(bottomLeft, bottomRight) / (float) dimensionTop; - int norm = distance(topLeft, topRight); - float cos = (topRight->getX() - topLeft->getX()) / norm; - float sin = (topRight->getY() - topLeft->getY()) / norm; - - Ref c1( - new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin)); - - corr = distance(bottomLeft, topLeft) / (float) dimensionRight; - norm = distance(bottomRight, topRight); - cos = (topRight->getX() - bottomRight->getX()) / norm; - sin = (topRight->getY() - bottomRight->getY()) / norm; - - Ref c2( - new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin)); - - if (!isValid(c1)) { - if (isValid(c2)) { - return c2; - } - return Ref(NULL); - } - if (!isValid(c2)) { - return c1; - } - - int l1 = abs(dimensionTop - transitionsBetween(topLeft, c1)->getTransitions()) - + abs(dimensionRight - transitionsBetween(bottomRight, c1)->getTransitions()); - int l2 = abs(dimensionTop - transitionsBetween(topLeft, c2)->getTransitions()) - + abs(dimensionRight - transitionsBetween(bottomRight, c2)->getTransitions()); - - return l1 <= l2 ? c1 : c2; -} - -/** - * Calculates the position of the white top right module using the output of the rectangle detector - * for a square matrix - */ -Ref Detector::correctTopRight(Ref bottomLeft, - Ref bottomRight, Ref topLeft, Ref topRight, - int dimension) { - - float corr = distance(bottomLeft, bottomRight) / (float) dimension; - int norm = distance(topLeft, topRight); - float cos = (topRight->getX() - topLeft->getX()) / norm; - float sin = (topRight->getY() - topLeft->getY()) / norm; - - Ref c1( - new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin)); - - corr = distance(bottomLeft, bottomRight) / (float) dimension; - norm = distance(bottomRight, topRight); - cos = (topRight->getX() - bottomRight->getX()) / norm; - sin = (topRight->getY() - bottomRight->getY()) / norm; - - Ref c2( - new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin)); - - if (!isValid(c1)) { - if (isValid(c2)) { - return c2; - } - return Ref(NULL); - } - if (!isValid(c2)) { - return c1; - } - - int l1 = abs( - transitionsBetween(topLeft, c1)->getTransitions() - - transitionsBetween(bottomRight, c1)->getTransitions()); - int l2 = abs( - transitionsBetween(topLeft, c2)->getTransitions() - - transitionsBetween(bottomRight, c2)->getTransitions()); - - return l1 <= l2 ? c1 : c2; -} - -bool Detector::isValid(Ref p) { - return p->getX() >= 0 && p->getX() < image_->getWidth() && p->getY() > 0 - && p->getY() < image_->getHeight(); -} - -// L2 distance -int Detector::distance(Ref a, Ref b) { - return round( - (float) sqrt( - (double) (a->getX() - b->getX()) * (a->getX() - b->getX()) - + (a->getY() - b->getY()) * (a->getY() - b->getY()))); -} - -Ref Detector::transitionsBetween(Ref from, - Ref to) { - // See QR Code Detector, sizeOfBlackWhiteBlackRun() - int fromX = (int) from->getX(); - int fromY = (int) from->getY(); - int toX = (int) to->getX(); - int toY = (int) to->getY(); - bool steep = abs(toY - fromY) > abs(toX - fromX); - if (steep) { - int temp = fromX; - fromX = fromY; - fromY = temp; - temp = toX; - toX = toY; - toY = temp; - } - - int dx = abs(toX - fromX); - int dy = abs(toY - fromY); - int error = -dx >> 1; - int ystep = fromY < toY ? 1 : -1; - int xstep = fromX < toX ? 1 : -1; - int transitions = 0; - bool inBlack = image_->get(steep ? fromY : fromX, steep ? fromX : fromY); - for (int x = fromX, y = fromY; x != toX; x += xstep) { - bool isBlack = image_->get(steep ? y : x, steep ? x : y); - if (isBlack != inBlack) { - transitions++; - inBlack = isBlack; - } - error += dy; - if (error > 0) { - if (y == toY) { - break; - } - y += ystep; - error -= dx; - } - } - Ref result(new ResultPointsAndTransitions(from, to, transitions)); - return result; -} - -Ref Detector::createTransform(Ref topLeft, - Ref topRight, Ref bottomLeft, Ref bottomRight, - int dimensionX, int dimensionY) { - - Ref transform( - PerspectiveTransform::quadrilateralToQuadrilateral( - 0.5f, - 0.5f, - dimensionX - 0.5f, - 0.5f, - dimensionX - 0.5f, - dimensionY - 0.5f, - 0.5f, - dimensionY - 0.5f, - topLeft->getX(), - topLeft->getY(), - topRight->getX(), - topRight->getY(), - bottomRight->getX(), - bottomRight->getY(), - bottomLeft->getX(), - bottomLeft->getY())); - return transform; -} - -Ref Detector::sampleGrid(Ref image, int dimensionX, int dimensionY, - Ref transform) { - GridSampler &sampler = GridSampler::getInstance(); - return sampler.sampleGrid(image, dimensionX, dimensionY, transform); -} - -void Detector::insertionSort(std::vector > &vector) { - int max = vector.size(); - bool swapped = true; - Ref value; - Ref valueB; - do { - swapped = false; - for (int i = 1; i < max; i++) { - value = vector[i - 1]; - if (compare(value, (valueB = vector[i])) > 0){ - swapped = true; - vector[i - 1].reset(valueB); - vector[i].reset(value); - } - } - } while (swapped); -} - -int Detector::compare(Ref a, Ref b) { - return a->getTransitions() - b->getTransitions(); -} -} -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Detector.cpp + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +namespace zxing { +namespace datamatrix { + +using namespace std; + +ResultPointsAndTransitions::ResultPointsAndTransitions() { + Ref ref(new ResultPoint(0, 0)); + from_ = ref; + to_ = ref; + transitions_ = 0; +} + +ResultPointsAndTransitions::ResultPointsAndTransitions(Ref from, Ref to, + int transitions) + : to_(to), from_(from), transitions_(transitions) { +} + +Ref ResultPointsAndTransitions::getFrom() { + return from_; +} + +Ref ResultPointsAndTransitions::getTo() { + return to_; +} + +int ResultPointsAndTransitions::getTransitions() { + return transitions_; +} + +Detector::Detector(Ref image) + : image_(image) { +} + +Ref Detector::getImage() { + return image_; +} + +Ref Detector::detect() { + Ref rectangleDetector_(new WhiteRectangleDetector(image_)); + std::vector > ResultPoints = rectangleDetector_->detect(); + Ref pointA = ResultPoints[0]; + Ref pointB = ResultPoints[1]; + Ref pointC = ResultPoints[2]; + Ref pointD = ResultPoints[3]; + + // Point A and D are across the diagonal from one another, + // as are B and C. Figure out which are the solid black lines + // by counting transitions + std::vector > transitions(4); + transitions[0].reset(transitionsBetween(pointA, pointB)); + transitions[1].reset(transitionsBetween(pointA, pointC)); + transitions[2].reset(transitionsBetween(pointB, pointD)); + transitions[3].reset(transitionsBetween(pointC, pointD)); + insertionSort(transitions); + + // Sort by number of transitions. First two will be the two solid sides; last two + // will be the two alternating black/white sides + Ref lSideOne(transitions[0]); + Ref lSideTwo(transitions[1]); + + // Figure out which point is their intersection by tallying up the number of times we see the + // endpoints in the four endpoints. One will show up twice. + Ref maybeTopLeft; + Ref bottomLeft; + Ref maybeBottomRight; + if (lSideOne->getFrom()->equals(lSideOne->getTo())) { + bottomLeft = lSideOne->getFrom(); + maybeTopLeft = lSideTwo->getFrom(); + maybeBottomRight = lSideTwo->getTo(); + } else if (lSideOne->getFrom()->equals(lSideTwo->getFrom())) { + bottomLeft = lSideOne->getFrom(); + maybeTopLeft = lSideOne->getTo(); + maybeBottomRight = lSideTwo->getTo(); + } else if (lSideOne->getFrom()->equals(lSideTwo->getTo())) { + bottomLeft = lSideOne->getFrom(); + maybeTopLeft = lSideOne->getTo(); + maybeBottomRight = lSideTwo->getFrom(); + } else if (lSideOne->getTo()->equals(lSideTwo->getFrom())) { + bottomLeft = lSideOne->getTo(); + maybeTopLeft = lSideOne->getFrom(); + maybeBottomRight = lSideTwo->getTo(); + } else if (lSideOne->getTo()->equals(lSideTwo->getTo())) { + bottomLeft = lSideOne->getTo(); + maybeTopLeft = lSideOne->getFrom(); + maybeBottomRight = lSideTwo->getFrom(); + } else { + bottomLeft = lSideTwo->getFrom(); + maybeTopLeft = lSideOne->getTo(); + maybeBottomRight = lSideOne->getFrom(); + } + + // Bottom left is correct but top left and bottom right might be switched + std::vector > corners(3); + corners[0].reset(maybeTopLeft); + corners[1].reset(bottomLeft); + corners[2].reset(maybeBottomRight); + + // Use the dot product trick to sort them out + ResultPoint::orderBestPatterns(corners); + + // Now we know which is which: + Ref bottomRight(corners[0]); + bottomLeft = corners[1]; + Ref topLeft(corners[2]); + + // Which point didn't we find in relation to the "L" sides? that's the top right corner + Ref topRight; + if (!(pointA->equals(bottomRight) || pointA->equals(bottomLeft) || pointA->equals(topLeft))) { + topRight = pointA; + } else if (!(pointB->equals(bottomRight) || pointB->equals(bottomLeft) + || pointB->equals(topLeft))) { + topRight = pointB; + } else if (!(pointC->equals(bottomRight) || pointC->equals(bottomLeft) + || pointC->equals(topLeft))) { + topRight = pointC; + } else { + topRight = pointD; + } + + // Next determine the dimension by tracing along the top or right side and counting black/white + // transitions. Since we start inside a black module, we should see a number of transitions + // equal to 1 less than the code dimension. Well, actually 2 less, because we are going to + // end on a black module: + + // The top right point is actually the corner of a module, which is one of the two black modules + // adjacent to the white module at the top right. Tracing to that corner from either the top left + // or bottom right should work here. + + int dimensionTop = transitionsBetween(topLeft, topRight)->getTransitions(); + int dimensionRight = transitionsBetween(bottomRight, topRight)->getTransitions(); + + //dimensionTop++; + if ((dimensionTop & 0x01) == 1) { + // it can't be odd, so, round... up? + dimensionTop++; + } + dimensionTop += 2; + + //dimensionRight++; + if ((dimensionRight & 0x01) == 1) { + // it can't be odd, so, round... up? + dimensionRight++; + } + dimensionRight += 2; + + Ref bits; + Ref transform; + Ref correctedTopRight; + + + // Rectanguar symbols are 6x16, 6x28, 10x24, 10x32, 14x32, or 14x44. If one dimension is more + // than twice the other, it's certainly rectangular, but to cut a bit more slack we accept it as + // rectangular if the bigger side is at least 7/4 times the other: + if (4 * dimensionTop >= 7 * dimensionRight || 4 * dimensionRight >= 7 * dimensionTop) { + // The matrix is rectangular + correctedTopRight = correctTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight, + dimensionTop, dimensionRight); + if (correctedTopRight == NULL) { + correctedTopRight = topRight; + } + + dimensionTop = transitionsBetween(topLeft, correctedTopRight)->getTransitions(); + dimensionRight = transitionsBetween(bottomRight, correctedTopRight)->getTransitions(); + + if ((dimensionTop & 0x01) == 1) { + // it can't be odd, so, round... up? + dimensionTop++; + } + + if ((dimensionRight & 0x01) == 1) { + // it can't be odd, so, round... up? + dimensionRight++; + } + + transform = createTransform(topLeft, correctedTopRight, bottomLeft, bottomRight, dimensionTop, + dimensionRight); + bits = sampleGrid(image_, dimensionTop, dimensionRight, transform); + + } else { + // The matrix is square + int dimension = min(dimensionRight, dimensionTop); + + // correct top right point to match the white module + correctedTopRight = correctTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension); + if (correctedTopRight == NULL) { + correctedTopRight = topRight; + } + + // Redetermine the dimension using the corrected top right point + int dimensionCorrected = max(transitionsBetween(topLeft, correctedTopRight)->getTransitions(), + transitionsBetween(bottomRight, correctedTopRight)->getTransitions()); + dimensionCorrected++; + if ((dimensionCorrected & 0x01) == 1) { + dimensionCorrected++; + } + + transform = createTransform(topLeft, correctedTopRight, bottomLeft, bottomRight, + dimensionCorrected, dimensionCorrected); + bits = sampleGrid(image_, dimensionCorrected, dimensionCorrected, transform); + } + + std::vector > points(4); + points[0].reset(topLeft); + points[1].reset(bottomLeft); + points[2].reset(correctedTopRight); + points[3].reset(bottomRight); + Ref detectorResult(new DetectorResult(bits, points)); + return detectorResult; +} + +/** + * Calculates the position of the white top right module using the output of the rectangle detector + * for a rectangular matrix + */ +Ref Detector::correctTopRightRectangular(Ref bottomLeft, + Ref bottomRight, Ref topLeft, Ref topRight, + int dimensionTop, int dimensionRight) { + + float corr = distance(bottomLeft, bottomRight) / (float) dimensionTop; + int norm = distance(topLeft, topRight); + float cos = (topRight->getX() - topLeft->getX()) / norm; + float sin = (topRight->getY() - topLeft->getY()) / norm; + + Ref c1( + new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin)); + + corr = distance(bottomLeft, topLeft) / (float) dimensionRight; + norm = distance(bottomRight, topRight); + cos = (topRight->getX() - bottomRight->getX()) / norm; + sin = (topRight->getY() - bottomRight->getY()) / norm; + + Ref c2( + new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin)); + + if (!isValid(c1)) { + if (isValid(c2)) { + return c2; + } + return Ref(NULL); + } + if (!isValid(c2)) { + return c1; + } + + int l1 = abs(dimensionTop - transitionsBetween(topLeft, c1)->getTransitions()) + + abs(dimensionRight - transitionsBetween(bottomRight, c1)->getTransitions()); + int l2 = abs(dimensionTop - transitionsBetween(topLeft, c2)->getTransitions()) + + abs(dimensionRight - transitionsBetween(bottomRight, c2)->getTransitions()); + + return l1 <= l2 ? c1 : c2; +} + +/** + * Calculates the position of the white top right module using the output of the rectangle detector + * for a square matrix + */ +Ref Detector::correctTopRight(Ref bottomLeft, + Ref bottomRight, Ref topLeft, Ref topRight, + int dimension) { + + float corr = distance(bottomLeft, bottomRight) / (float) dimension; + int norm = distance(topLeft, topRight); + float cos = (topRight->getX() - topLeft->getX()) / norm; + float sin = (topRight->getY() - topLeft->getY()) / norm; + + Ref c1( + new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin)); + + corr = distance(bottomLeft, bottomRight) / (float) dimension; + norm = distance(bottomRight, topRight); + cos = (topRight->getX() - bottomRight->getX()) / norm; + sin = (topRight->getY() - bottomRight->getY()) / norm; + + Ref c2( + new ResultPoint(topRight->getX() + corr * cos, topRight->getY() + corr * sin)); + + if (!isValid(c1)) { + if (isValid(c2)) { + return c2; + } + return Ref(NULL); + } + if (!isValid(c2)) { + return c1; + } + + int l1 = abs( + transitionsBetween(topLeft, c1)->getTransitions() + - transitionsBetween(bottomRight, c1)->getTransitions()); + int l2 = abs( + transitionsBetween(topLeft, c2)->getTransitions() + - transitionsBetween(bottomRight, c2)->getTransitions()); + + return l1 <= l2 ? c1 : c2; +} + +bool Detector::isValid(Ref p) { + return p->getX() >= 0 && p->getX() < image_->getWidth() && p->getY() > 0 + && p->getY() < image_->getHeight(); +} + +// L2 distance +int Detector::distance(Ref a, Ref b) { + return round( + (float) sqrt( + (double) (a->getX() - b->getX()) * (a->getX() - b->getX()) + + (a->getY() - b->getY()) * (a->getY() - b->getY()))); +} + +Ref Detector::transitionsBetween(Ref from, + Ref to) { + // See QR Code Detector, sizeOfBlackWhiteBlackRun() + int fromX = (int) from->getX(); + int fromY = (int) from->getY(); + int toX = (int) to->getX(); + int toY = (int) to->getY(); + bool steep = abs(toY - fromY) > abs(toX - fromX); + if (steep) { + int temp = fromX; + fromX = fromY; + fromY = temp; + temp = toX; + toX = toY; + toY = temp; + } + + int dx = abs(toX - fromX); + int dy = abs(toY - fromY); + int error = -dx >> 1; + int ystep = fromY < toY ? 1 : -1; + int xstep = fromX < toX ? 1 : -1; + int transitions = 0; + bool inBlack = image_->get(steep ? fromY : fromX, steep ? fromX : fromY); + for (int x = fromX, y = fromY; x != toX; x += xstep) { + bool isBlack = image_->get(steep ? y : x, steep ? x : y); + if (isBlack != inBlack) { + transitions++; + inBlack = isBlack; + } + error += dy; + if (error > 0) { + if (y == toY) { + break; + } + y += ystep; + error -= dx; + } + } + Ref result(new ResultPointsAndTransitions(from, to, transitions)); + return result; +} + +Ref Detector::createTransform(Ref topLeft, + Ref topRight, Ref bottomLeft, Ref bottomRight, + int dimensionX, int dimensionY) { + + Ref transform( + PerspectiveTransform::quadrilateralToQuadrilateral( + 0.5f, + 0.5f, + dimensionX - 0.5f, + 0.5f, + dimensionX - 0.5f, + dimensionY - 0.5f, + 0.5f, + dimensionY - 0.5f, + topLeft->getX(), + topLeft->getY(), + topRight->getX(), + topRight->getY(), + bottomRight->getX(), + bottomRight->getY(), + bottomLeft->getX(), + bottomLeft->getY())); + return transform; +} + +Ref Detector::sampleGrid(Ref image, int dimensionX, int dimensionY, + Ref transform) { + GridSampler &sampler = GridSampler::getInstance(); + return sampler.sampleGrid(image, dimensionX, dimensionY, transform); +} + +void Detector::insertionSort(std::vector > &vector) { + int max = vector.size(); + bool swapped = true; + Ref value; + Ref valueB; + do { + swapped = false; + for (int i = 1; i < max; i++) { + value = vector[i - 1]; + if (compare(value, (valueB = vector[i])) > 0){ + swapped = true; + vector[i - 1].reset(valueB); + vector[i].reset(value); + } + } + } while (swapped); +} + +int Detector::compare(Ref a, Ref b) { + return a->getTransitions() - b->getTransitions(); +} +} +} diff --git a/symbian/QZXing/source/zxing/datamatrix/detector/DetectorException.cpp b/symbian/QZXing/source/zxing/datamatrix/detector/DataMatrixDetectorException.cpp similarity index 100% rename from symbian/QZXing/source/zxing/datamatrix/detector/DetectorException.cpp rename to symbian/QZXing/source/zxing/datamatrix/detector/DataMatrixDetectorException.cpp diff --git a/symbian/QZXing/source/zxing/datamatrix/detector/MonochromeRectangleDetectorDM.cpp b/symbian/QZXing/source/zxing/datamatrix/detector/DataMatrixMonochromeRectangleDetector.cpp similarity index 96% rename from symbian/QZXing/source/zxing/datamatrix/detector/MonochromeRectangleDetectorDM.cpp rename to symbian/QZXing/source/zxing/datamatrix/detector/DataMatrixMonochromeRectangleDetector.cpp index df8c1e4fa..67ed5726c 100644 --- a/symbian/QZXing/source/zxing/datamatrix/detector/MonochromeRectangleDetectorDM.cpp +++ b/symbian/QZXing/source/zxing/datamatrix/detector/DataMatrixMonochromeRectangleDetector.cpp @@ -1,172 +1,172 @@ -/* - * MonochromeRectangleDetector.cpp - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -namespace datamatrix { - -std::vector > MonochromeRectangleDetector::detect() { - int height = image_->getHeight(); - int width = image_->getWidth(); - int halfHeight = height >> 1; - int halfWidth = width >> 1; - int deltaY = max(1, height / (MAX_MODULES << 3)); - int deltaX = max(1, width / (MAX_MODULES << 3)); - - int top = 0; - int bottom = height; - int left = 0; - int right = width; - Ref pointA(findCornerFromCenter(halfWidth, 0, left, right, - halfHeight, -deltaY, top, bottom, halfWidth >> 1)); - top = (int) pointA->getY() - 1; - Ref pointB(findCornerFromCenter(halfWidth, -deltaX, left, right, - halfHeight, 0, top, bottom, halfHeight >> 1)); - left = (int) pointB->getX() - 1; - Ref pointC(findCornerFromCenter(halfWidth, deltaX, left, right, - halfHeight, 0, top, bottom, halfHeight >> 1)); - right = (int) pointC->getX() + 1; - Ref pointD(findCornerFromCenter(halfWidth, 0, left, right, - halfHeight, deltaY, top, bottom, halfWidth >> 1)); - bottom = (int) pointD->getY() + 1; - - // Go try to find point A again with better information -- might have been off at first. - pointA.reset(findCornerFromCenter(halfWidth, 0, left, right, - halfHeight, -deltaY, top, bottom, halfWidth >> 2)); - std::vector > corners(4); - - corners[0].reset(pointA); - corners[1].reset(pointB); - corners[2].reset(pointC); - corners[3].reset(pointD); - return corners; - } - -Ref MonochromeRectangleDetector::findCornerFromCenter(int centerX, int deltaX, int left, int right, - int centerY, int deltaY, int top, int bottom, int maxWhiteRun) { - Ref lastRange(NULL); - for (int y = centerY, x = centerX; - y < bottom && y >= top && x < right && x >= left; - y += deltaY, x += deltaX) { - Ref range(NULL); - if (deltaX == 0) { - // horizontal slices, up and down - range = blackWhiteRange(y, maxWhiteRun, left, right, true); - } else { - // vertical slices, left and right - range = blackWhiteRange(x, maxWhiteRun, top, bottom, false); - } - if (range == NULL) { - if (lastRange == NULL) { - throw ReaderException("Couldn't find corners (lastRange = NULL) "); - } else { - // lastRange was found - if (deltaX == 0) { - int lastY = y - deltaY; - if (lastRange->start < centerX) { - if (lastRange->end > centerX) { - // straddle, choose one or the other based on direction - Ref result(new CornerPoint(deltaY > 0 ? lastRange->start : lastRange->end, lastY)); - return result; - } - Ref result(new CornerPoint(lastRange->start, lastY)); - return result; - } else { - Ref result(new CornerPoint(lastRange->end, lastY)); - return result; - } - } else { - int lastX = x - deltaX; - if (lastRange->start < centerY) { - if (lastRange->end > centerY) { - Ref result(new CornerPoint(lastX, deltaX < 0 ? lastRange->start : lastRange->end)); - return result; - } - Ref result(new CornerPoint(lastX, lastRange->start)); - return result; - } else { - Ref result(new CornerPoint(lastX, lastRange->end)); - return result; - } - } - } - } - lastRange = range; - } - throw ReaderException("Couldn't find corners"); - } - -Ref MonochromeRectangleDetector::blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, - bool horizontal) { - - int center = (minDim + maxDim) >> 1; - - // Scan left/up first - int start = center; - while (start >= minDim) { - if (horizontal ? image_->get(start, fixedDimension) : image_->get(fixedDimension, start)) { - start--; - } else { - int whiteRunStart = start; - do { - start--; - } while (start >= minDim && !(horizontal ? image_->get(start, fixedDimension) : - image_->get(fixedDimension, start))); - int whiteRunSize = whiteRunStart - start; - if (start < minDim || whiteRunSize > maxWhiteRun) { - start = whiteRunStart; - break; - } - } - } - start++; - - // Then try right/down - int end = center; - while (end < maxDim) { - if (horizontal ? image_->get(end, fixedDimension) : image_->get(fixedDimension, end)) { - end++; - } else { - int whiteRunStart = end; - do { - end++; - } while (end < maxDim && !(horizontal ? image_->get(end, fixedDimension) : - image_->get(fixedDimension, end))); - int whiteRunSize = end - whiteRunStart; - if (end >= maxDim || whiteRunSize > maxWhiteRun) { - end = whiteRunStart; - break; - } - } - } - end--; - Ref result(NULL); - if (end > start) { - result = new TwoInts; - result->start = start; - result->end = end; - } - return result; - } -} -} +/* + * MonochromeRectangleDetector.cpp + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { +namespace datamatrix { + +std::vector > MonochromeRectangleDetector::detect() { + int height = image_->getHeight(); + int width = image_->getWidth(); + int halfHeight = height >> 1; + int halfWidth = width >> 1; + int deltaY = max(1, height / (MAX_MODULES << 3)); + int deltaX = max(1, width / (MAX_MODULES << 3)); + + int top = 0; + int bottom = height; + int left = 0; + int right = width; + Ref pointA(findCornerFromCenter(halfWidth, 0, left, right, + halfHeight, -deltaY, top, bottom, halfWidth >> 1)); + top = (int) pointA->getY() - 1; + Ref pointB(findCornerFromCenter(halfWidth, -deltaX, left, right, + halfHeight, 0, top, bottom, halfHeight >> 1)); + left = (int) pointB->getX() - 1; + Ref pointC(findCornerFromCenter(halfWidth, deltaX, left, right, + halfHeight, 0, top, bottom, halfHeight >> 1)); + right = (int) pointC->getX() + 1; + Ref pointD(findCornerFromCenter(halfWidth, 0, left, right, + halfHeight, deltaY, top, bottom, halfWidth >> 1)); + bottom = (int) pointD->getY() + 1; + + // Go try to find point A again with better information -- might have been off at first. + pointA.reset(findCornerFromCenter(halfWidth, 0, left, right, + halfHeight, -deltaY, top, bottom, halfWidth >> 2)); + std::vector > corners(4); + + corners[0].reset(pointA); + corners[1].reset(pointB); + corners[2].reset(pointC); + corners[3].reset(pointD); + return corners; + } + +Ref MonochromeRectangleDetector::findCornerFromCenter(int centerX, int deltaX, int left, int right, + int centerY, int deltaY, int top, int bottom, int maxWhiteRun) { + Ref lastRange(NULL); + for (int y = centerY, x = centerX; + y < bottom && y >= top && x < right && x >= left; + y += deltaY, x += deltaX) { + Ref range(NULL); + if (deltaX == 0) { + // horizontal slices, up and down + range = blackWhiteRange(y, maxWhiteRun, left, right, true); + } else { + // vertical slices, left and right + range = blackWhiteRange(x, maxWhiteRun, top, bottom, false); + } + if (range == NULL) { + if (lastRange == NULL) { + throw ReaderException("Couldn't find corners (lastRange = NULL) "); + } else { + // lastRange was found + if (deltaX == 0) { + int lastY = y - deltaY; + if (lastRange->start < centerX) { + if (lastRange->end > centerX) { + // straddle, choose one or the other based on direction + Ref result(new CornerPoint(deltaY > 0 ? lastRange->start : lastRange->end, lastY)); + return result; + } + Ref result(new CornerPoint(lastRange->start, lastY)); + return result; + } else { + Ref result(new CornerPoint(lastRange->end, lastY)); + return result; + } + } else { + int lastX = x - deltaX; + if (lastRange->start < centerY) { + if (lastRange->end > centerY) { + Ref result(new CornerPoint(lastX, deltaX < 0 ? lastRange->start : lastRange->end)); + return result; + } + Ref result(new CornerPoint(lastX, lastRange->start)); + return result; + } else { + Ref result(new CornerPoint(lastX, lastRange->end)); + return result; + } + } + } + } + lastRange = range; + } + throw ReaderException("Couldn't find corners"); + } + +Ref MonochromeRectangleDetector::blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, + bool horizontal) { + + int center = (minDim + maxDim) >> 1; + + // Scan left/up first + int start = center; + while (start >= minDim) { + if (horizontal ? image_->get(start, fixedDimension) : image_->get(fixedDimension, start)) { + start--; + } else { + int whiteRunStart = start; + do { + start--; + } while (start >= minDim && !(horizontal ? image_->get(start, fixedDimension) : + image_->get(fixedDimension, start))); + int whiteRunSize = whiteRunStart - start; + if (start < minDim || whiteRunSize > maxWhiteRun) { + start = whiteRunStart; + break; + } + } + } + start++; + + // Then try right/down + int end = center; + while (end < maxDim) { + if (horizontal ? image_->get(end, fixedDimension) : image_->get(fixedDimension, end)) { + end++; + } else { + int whiteRunStart = end; + do { + end++; + } while (end < maxDim && !(horizontal ? image_->get(end, fixedDimension) : + image_->get(fixedDimension, end))); + int whiteRunSize = end - whiteRunStart; + if (end >= maxDim || whiteRunSize > maxWhiteRun) { + end = whiteRunStart; + break; + } + } + } + end--; + Ref result(NULL); + if (end > start) { + result = new TwoInts; + result->start = start; + result->end = end; + } + return result; + } +} +} diff --git a/symbian/QZXing/source/zxing/datamatrix/detector/DetectorDM.h b/symbian/QZXing/source/zxing/datamatrix/detector/Detector.h similarity index 94% rename from symbian/QZXing/source/zxing/datamatrix/detector/DetectorDM.h rename to symbian/QZXing/source/zxing/datamatrix/detector/Detector.h index c71bbac68..23208930e 100644 --- a/symbian/QZXing/source/zxing/datamatrix/detector/DetectorDM.h +++ b/symbian/QZXing/source/zxing/datamatrix/detector/Detector.h @@ -1,94 +1,94 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __DETECTOR_DM_H__ -#define __DETECTOR_DM_H__ - -/* - * Detector.h - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace zxing { -namespace datamatrix { - -class ResultPointsAndTransitions: public Counted { - private: - Ref to_; - Ref from_; - int transitions_; - - public: - ResultPointsAndTransitions(); - ResultPointsAndTransitions(Ref from, Ref to, int transitions); - Ref getFrom(); - Ref getTo(); - int getTransitions(); -}; - -class Detector: public Counted { - private: - Ref image_; - - protected: - Ref sampleGrid(Ref image, int dimensionX, int dimensionY, - Ref transform); - - void insertionSort(std::vector >& vector); - - Ref correctTopRightRectangular(Ref bottomLeft, - Ref bottomRight, Ref topLeft, Ref topRight, - int dimensionTop, int dimensionRight); - Ref correctTopRight(Ref bottomLeft, Ref bottomRight, - Ref topLeft, Ref topRight, int dimension); - bool isValid(Ref p); - int distance(Ref a, Ref b); - Ref transitionsBetween(Ref from, Ref to); - int min(int a, int b) { - return a > b ? b : a; - } - /** - * Ends up being a bit faster than round(). This merely rounds its - * argument to the nearest int, where x.5 rounds up. - */ - int round(float d) { - return (int) (d + 0.5f); - } - - public: - Ref getImage(); - Detector(Ref image); - - virtual Ref createTransform(Ref topLeft, - Ref topRight, Ref bottomLeft, Ref bottomRight, - int dimensionX, int dimensionY); - - Ref detect(); - - private: - int compare(Ref a, Ref b); -}; - -} -} - -#endif // __DETECTOR_DM_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __DETECTOR_H__ +#define __DETECTOR_H__ + +/* + * Detector.h + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +namespace zxing { +namespace datamatrix { + +class ResultPointsAndTransitions: public Counted { + private: + Ref to_; + Ref from_; + int transitions_; + + public: + ResultPointsAndTransitions(); + ResultPointsAndTransitions(Ref from, Ref to, int transitions); + Ref getFrom(); + Ref getTo(); + int getTransitions(); +}; + +class Detector: public Counted { + private: + Ref image_; + + protected: + Ref sampleGrid(Ref image, int dimensionX, int dimensionY, + Ref transform); + + void insertionSort(std::vector >& vector); + + Ref correctTopRightRectangular(Ref bottomLeft, + Ref bottomRight, Ref topLeft, Ref topRight, + int dimensionTop, int dimensionRight); + Ref correctTopRight(Ref bottomLeft, Ref bottomRight, + Ref topLeft, Ref topRight, int dimension); + bool isValid(Ref p); + int distance(Ref a, Ref b); + Ref transitionsBetween(Ref from, Ref to); + int min(int a, int b) { + return a > b ? b : a; + } + /** + * Ends up being a bit faster than round(). This merely rounds its + * argument to the nearest int, where x.5 rounds up. + */ + int round(float d) { + return (int) (d + 0.5f); + } + + public: + Ref getImage(); + Detector(Ref image); + + virtual Ref createTransform(Ref topLeft, + Ref topRight, Ref bottomLeft, Ref bottomRight, + int dimensionX, int dimensionY); + + Ref detect(); + + private: + int compare(Ref a, Ref b); +}; + +} +} + +#endif // __DETECTOR_H__ diff --git a/symbian/QZXing/source/zxing/datamatrix/detector/DetectorException.h b/symbian/QZXing/source/zxing/datamatrix/detector/DetectorException.h index d2c45aaf0..8002ac9d1 100644 --- a/symbian/QZXing/source/zxing/datamatrix/detector/DetectorException.h +++ b/symbian/QZXing/source/zxing/datamatrix/detector/DetectorException.h @@ -5,8 +5,8 @@ * Author: luiz */ -#ifndef DETECTOREXCEPTION_DM_H_ -#define DETECTOREXCEPTION_DM_H_ +#ifndef DETECTOREXCEPTION_H_ +#define DETECTOREXCEPTION_H_ #include @@ -20,4 +20,4 @@ class DetectorException : public Exception { }; } /* namespace nexxera */ } /* namespace zxing */ -#endif /* DETECTOREXCEPTION_DM_H_ */ +#endif /* DETECTOREXCEPTION_H_ */ diff --git a/symbian/QZXing/source/zxing/datamatrix/detector/MonochromeRectangleDetectorDM.h b/symbian/QZXing/source/zxing/datamatrix/detector/MonochromeRectangleDetector.h similarity index 95% rename from symbian/QZXing/source/zxing/datamatrix/detector/MonochromeRectangleDetectorDM.h rename to symbian/QZXing/source/zxing/datamatrix/detector/MonochromeRectangleDetector.h index ccf3af9df..43efb4675 100644 --- a/symbian/QZXing/source/zxing/datamatrix/detector/MonochromeRectangleDetectorDM.h +++ b/symbian/QZXing/source/zxing/datamatrix/detector/MonochromeRectangleDetector.h @@ -1,61 +1,61 @@ -#ifndef __MONOCHROMERECTANGLEDETECTOR_H__ -#define __MONOCHROMERECTANGLEDETECTOR_H__ - -/* - * MonochromeRectangleDetector.h - * zxing - * - * Created by Luiz Silva on 09/02/2010. - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace zxing { -namespace datamatrix { - -struct TwoInts: public Counted { - int start; - int end; -}; - -class MonochromeRectangleDetector : public Counted { -private: - static const int MAX_MODULES = 32; - Ref image_; - -public: - MonochromeRectangleDetector(Ref image) : image_(image) { } - - std::vector > detect(); - -private: - Ref findCornerFromCenter(int centerX, int deltaX, int left, int right, - int centerY, int deltaY, int top, int bottom, int maxWhiteRun); - - Ref blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, - bool horizontal); - - int max(int a, float b) { return (float) a > b ? a : (int) b;} -}; -} -} - -#endif // __MONOCHROMERECTANGLEDETECTOR_H__ +#ifndef __MONOCHROMERECTANGLEDETECTOR_H__ +#define __MONOCHROMERECTANGLEDETECTOR_H__ + +/* + * MonochromeRectangleDetector.h + * zxing + * + * Created by Luiz Silva on 09/02/2010. + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +namespace zxing { +namespace datamatrix { + +struct TwoInts: public Counted { + int start; + int end; +}; + +class MonochromeRectangleDetector : public Counted { +private: + static const int MAX_MODULES = 32; + Ref image_; + +public: + MonochromeRectangleDetector(Ref image) : image_(image) { }; + + std::vector > detect(); + +private: + Ref findCornerFromCenter(int centerX, int deltaX, int left, int right, + int centerY, int deltaY, int top, int bottom, int maxWhiteRun); + + Ref blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, + bool horizontal); + + int max(int a, float b) { return (float) a > b ? a : (int) b;}; +}; +} +} + +#endif // __MONOCHROMERECTANGLEDETECTOR_H__ diff --git a/symbian/QZXing/source/zxing/multi/ByQuadrantReader.cpp b/symbian/QZXing/source/zxing/multi/ByQuadrantReader.cpp index 427278907..c031eefaf 100644 --- a/symbian/QZXing/source/zxing/multi/ByQuadrantReader.cpp +++ b/symbian/QZXing/source/zxing/multi/ByQuadrantReader.cpp @@ -1,71 +1,71 @@ -/* - * Copyright 2011 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { -namespace multi { - -ByQuadrantReader::ByQuadrantReader(Reader& delegate) : delegate_(delegate) {} - -ByQuadrantReader::~ByQuadrantReader(){} - -Ref ByQuadrantReader::decode(Ref image){ - return decode(image, DecodeHints::DEFAULT_HINT); -} - -Ref ByQuadrantReader::decode(Ref image, DecodeHints hints){ - int width = image->getWidth(); - int height = image->getHeight(); - int halfWidth = width / 2; - int halfHeight = height / 2; - Ref topLeft = image->crop(0, 0, halfWidth, halfHeight); - try { - return delegate_.decode(topLeft, hints); - } catch (ReaderException re) { - // continue - } - - Ref topRight = image->crop(halfWidth, 0, halfWidth, halfHeight); - try { - return delegate_.decode(topRight, hints); - } catch (ReaderException re) { - // continue - } - - Ref bottomLeft = image->crop(0, halfHeight, halfWidth, halfHeight); - try { - return delegate_.decode(bottomLeft, hints); - } catch (ReaderException re) { - // continue - } - - Ref bottomRight = image->crop(halfWidth, halfHeight, halfWidth, halfHeight); - try { - return delegate_.decode(bottomRight, hints); - } catch (ReaderException re) { - // continue - } - - int quarterWidth = halfWidth / 2; - int quarterHeight = halfHeight / 2; - Ref center = image->crop(quarterWidth, quarterHeight, halfWidth, halfHeight); - return delegate_.decode(center, hints); -} - -} // End zxing::multi namespace -} // End zxing namespace +/* + * Copyright 2011 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { +namespace multi { + +ByQuadrantReader::ByQuadrantReader(Reader& delegate) : delegate_(delegate) {} + +ByQuadrantReader::~ByQuadrantReader(){} + +Ref ByQuadrantReader::decode(Ref image){ + return decode(image, DecodeHints::DEFAULT_HINT); +} + +Ref ByQuadrantReader::decode(Ref image, DecodeHints hints){ + int width = image->getWidth(); + int height = image->getHeight(); + int halfWidth = width / 2; + int halfHeight = height / 2; + Ref topLeft = image->crop(0, 0, halfWidth, halfHeight); + try { + return delegate_.decode(topLeft, hints); + } catch (ReaderException& re) { + // continue + } + + Ref topRight = image->crop(halfWidth, 0, halfWidth, halfHeight); + try { + return delegate_.decode(topRight, hints); + } catch (ReaderException& re) { + // continue + } + + Ref bottomLeft = image->crop(0, halfHeight, halfWidth, halfHeight); + try { + return delegate_.decode(bottomLeft, hints); + } catch (ReaderException& re) { + // continue + } + + Ref bottomRight = image->crop(halfWidth, halfHeight, halfWidth, halfHeight); + try { + return delegate_.decode(bottomRight, hints); + } catch (ReaderException& re) { + // continue + } + + int quarterWidth = halfWidth / 2; + int quarterHeight = halfHeight / 2; + Ref center = image->crop(quarterWidth, quarterHeight, halfWidth, halfHeight); + return delegate_.decode(center, hints); +} + +} // End zxing::multi namespace +} // End zxing namespace diff --git a/symbian/QZXing/source/zxing/multi/ByQuadrantReader.h b/symbian/QZXing/source/zxing/multi/ByQuadrantReader.h index 18dcc33ab..0853a0235 100644 --- a/symbian/QZXing/source/zxing/multi/ByQuadrantReader.h +++ b/symbian/QZXing/source/zxing/multi/ByQuadrantReader.h @@ -1,40 +1,40 @@ -#ifndef __BY_QUADRANT_READER_H__ -#define __BY_QUADRANT_READER_H__ - -/* - * Copyright 2011 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { -namespace multi { -class ByQuadrantReader : public Reader { - private: - Reader& delegate_; - - public: - ByQuadrantReader(Reader& delegate); - virtual ~ByQuadrantReader(); - virtual Ref decode(Ref image); - virtual Ref decode(Ref image, DecodeHints hints); -}; -} // End zxing::multi namespace -} // End zxing namespace - -#endif // __BY_QUADRANT_READER_H__ +#ifndef __BY_QUADRANT_READER_H__ +#define __BY_QUADRANT_READER_H__ + +/* + * Copyright 2011 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { +namespace multi { +class ByQuadrantReader : public Reader { + private: + Reader& delegate_; + + public: + ByQuadrantReader(Reader& delegate); + virtual ~ByQuadrantReader(); + virtual Ref decode(Ref image); + virtual Ref decode(Ref image, DecodeHints hints); +}; +} // End zxing::multi namespace +} // End zxing namespace + +#endif // __BY_QUADRANT_READER_H__ diff --git a/symbian/QZXing/source/zxing/multi/GenericMultipleBarcodeReader.cpp b/symbian/QZXing/source/zxing/multi/GenericMultipleBarcodeReader.cpp index adad94d04..b72385235 100644 --- a/symbian/QZXing/source/zxing/multi/GenericMultipleBarcodeReader.cpp +++ b/symbian/QZXing/source/zxing/multi/GenericMultipleBarcodeReader.cpp @@ -1,128 +1,128 @@ -/* - * Copyright 2011 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -namespace multi { -GenericMultipleBarcodeReader::GenericMultipleBarcodeReader(Reader& delegate) : - delegate_(delegate) -{ -} - -GenericMultipleBarcodeReader::~GenericMultipleBarcodeReader(){} - -std::vector > GenericMultipleBarcodeReader::decodeMultiple( - Ref image, DecodeHints hints) -{ - std::vector > results; - doDecodeMultiple(image, hints, results, 0, 0); - if (results.empty()){ - throw ReaderException("No code detected"); - } - return results; -} - -void GenericMultipleBarcodeReader::doDecodeMultiple(Ref image, - DecodeHints hints, std::vector >& results, int xOffset, int yOffset) -{ - Ref result; - try { - result = delegate_.decode(image, hints); - } catch (ReaderException re) { - return; - } - bool alreadyFound = false; - for (unsigned int i = 0; i < results.size(); i++) { - Ref existingResult = results[i]; - if (existingResult->getText()->getText() == result->getText()->getText()) { - alreadyFound = true; - break; - } - } - if (alreadyFound) { - return; - } - - results.push_back(translateResultPoints(result, xOffset, yOffset)); - const std::vector > resultPoints = result->getResultPoints(); - if (resultPoints.empty()) { - return; - } - - int width = image->getWidth(); - int height = image->getHeight(); - float minX = width; - float minY = height; - float maxX = 0.0f; - float maxY = 0.0f; - for (unsigned int i = 0; i < resultPoints.size(); i++) { - Ref point = resultPoints[i]; - float x = point->getX(); - float y = point->getY(); - if (x < minX) { - minX = x; - } - if (y < minY) { - minY = y; - } - if (x > maxX) { - maxX = x; - } - if (y > maxY) { - maxY = y; - } - } - - // Decode left of barcode - if (minX > MIN_DIMENSION_TO_RECUR) { - doDecodeMultiple(image->crop(0, 0, (int) minX, height), - hints, results, xOffset, yOffset); - } - // Decode above barcode - if (minY > MIN_DIMENSION_TO_RECUR) { - doDecodeMultiple(image->crop(0, 0, width, (int) minY), - hints, results, xOffset, yOffset); - } - // Decode right of barcode - if (maxX < width - MIN_DIMENSION_TO_RECUR) { - doDecodeMultiple(image->crop((int) maxX, 0, width - (int) maxX, height), - hints, results, xOffset + (int) maxX, yOffset); - } - // Decode below barcode - if (maxY < height - MIN_DIMENSION_TO_RECUR) { - doDecodeMultiple(image->crop(0, (int) maxY, width, height - (int) maxY), - hints, results, xOffset, yOffset + (int) maxY); - } -} - -Ref GenericMultipleBarcodeReader::translateResultPoints(Ref result, int xOffset, int yOffset){ - const std::vector > oldResultPoints = result->getResultPoints(); - if (oldResultPoints.empty()) { - return result; - } - std::vector > newResultPoints; - for (unsigned int i = 0; i < oldResultPoints.size(); i++) { - Ref oldPoint = oldResultPoints[i]; - newResultPoints.push_back(Ref(new ResultPoint(oldPoint->getX() + xOffset, oldPoint->getY() + yOffset))); - } - return Ref(new Result(result->getText(), result->getRawBytes(), newResultPoints, result->getBarcodeFormat())); -} - -} // End zxing::multi namespace -} // End zxing namespace +/* + * Copyright 2011 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { +namespace multi { +GenericMultipleBarcodeReader::GenericMultipleBarcodeReader(Reader& delegate) : + delegate_(delegate) +{ +} + +GenericMultipleBarcodeReader::~GenericMultipleBarcodeReader(){} + +std::vector > GenericMultipleBarcodeReader::decodeMultiple( + Ref image, DecodeHints hints) +{ + std::vector > results; + doDecodeMultiple(image, hints, results, 0, 0); + if (results.empty()){ + throw ReaderException("No code detected"); + } + return results; +} + +void GenericMultipleBarcodeReader::doDecodeMultiple(Ref image, + DecodeHints hints, std::vector >& results, int xOffset, int yOffset) +{ + Ref result; + try { + result = delegate_.decode(image, hints); + } catch (ReaderException& re) { + return; + } + bool alreadyFound = false; + for (unsigned int i = 0; i < results.size(); i++) { + Ref existingResult = results[i]; + if (existingResult->getText()->getText() == result->getText()->getText()) { + alreadyFound = true; + break; + } + } + if (alreadyFound) { + return; + } + + results.push_back(translateResultPoints(result, xOffset, yOffset)); + const std::vector > resultPoints = result->getResultPoints(); + if (resultPoints.empty()) { + return; + } + + int width = image->getWidth(); + int height = image->getHeight(); + float minX = width; + float minY = height; + float maxX = 0.0f; + float maxY = 0.0f; + for (unsigned int i = 0; i < resultPoints.size(); i++) { + Ref point = resultPoints[i]; + float x = point->getX(); + float y = point->getY(); + if (x < minX) { + minX = x; + } + if (y < minY) { + minY = y; + } + if (x > maxX) { + maxX = x; + } + if (y > maxY) { + maxY = y; + } + } + + // Decode left of barcode + if (minX > MIN_DIMENSION_TO_RECUR) { + doDecodeMultiple(image->crop(0, 0, (int) minX, height), + hints, results, xOffset, yOffset); + } + // Decode above barcode + if (minY > MIN_DIMENSION_TO_RECUR) { + doDecodeMultiple(image->crop(0, 0, width, (int) minY), + hints, results, xOffset, yOffset); + } + // Decode right of barcode + if (maxX < width - MIN_DIMENSION_TO_RECUR) { + doDecodeMultiple(image->crop((int) maxX, 0, width - (int) maxX, height), + hints, results, xOffset + (int) maxX, yOffset); + } + // Decode below barcode + if (maxY < height - MIN_DIMENSION_TO_RECUR) { + doDecodeMultiple(image->crop(0, (int) maxY, width, height - (int) maxY), + hints, results, xOffset, yOffset + (int) maxY); + } +} + +Ref GenericMultipleBarcodeReader::translateResultPoints(Ref result, int xOffset, int yOffset){ + const std::vector > oldResultPoints = result->getResultPoints(); + if (oldResultPoints.empty()) { + return result; + } + std::vector > newResultPoints; + for (unsigned int i = 0; i < oldResultPoints.size(); i++) { + Ref oldPoint = oldResultPoints[i]; + newResultPoints.push_back(Ref(new ResultPoint(oldPoint->getX() + xOffset, oldPoint->getY() + yOffset))); + } + return Ref(new Result(result->getText(), result->getRawBytes(), newResultPoints, result->getBarcodeFormat())); +} + +} // End zxing::multi namespace +} // End zxing namespace diff --git a/symbian/QZXing/source/zxing/multi/GenericMultipleBarcodeReader.h b/symbian/QZXing/source/zxing/multi/GenericMultipleBarcodeReader.h index 87d46b335..10defcb54 100644 --- a/symbian/QZXing/source/zxing/multi/GenericMultipleBarcodeReader.h +++ b/symbian/QZXing/source/zxing/multi/GenericMultipleBarcodeReader.h @@ -1,47 +1,47 @@ -#ifndef __GENERIC_MULTIPLE_BARCODE_READER_H__ -#define __GENERIC_MULTIPLE_BARCODE_READER_H__ - -/* - * Copyright 2011 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { -namespace multi { -class GenericMultipleBarcodeReader : public MultipleBarcodeReader { - private: - static Ref translateResultPoints(Ref result, - int xOffset, - int yOffset); - void doDecodeMultiple(Ref image, - DecodeHints hints, - std::vector >& results, - int xOffset, - int yOffset); - Reader& delegate_; - static const int MIN_DIMENSION_TO_RECUR = 100; - - public: - GenericMultipleBarcodeReader(Reader& delegate); - virtual ~GenericMultipleBarcodeReader(); - virtual std::vector > decodeMultiple(Ref image, - DecodeHints hints); -}; -} // End zxing::multi namespace -} // End zxing namespace - -#endif // __GENERIC_MULTIPLE_BARCODE_READER_H__ +#ifndef __GENERIC_MULTIPLE_BARCODE_READER_H__ +#define __GENERIC_MULTIPLE_BARCODE_READER_H__ + +/* + * Copyright 2011 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { +namespace multi { +class GenericMultipleBarcodeReader : public MultipleBarcodeReader { + private: + static Ref translateResultPoints(Ref result, + int xOffset, + int yOffset); + void doDecodeMultiple(Ref image, + DecodeHints hints, + std::vector >& results, + int xOffset, + int yOffset); + Reader& delegate_; + static const int MIN_DIMENSION_TO_RECUR = 100; + + public: + GenericMultipleBarcodeReader(Reader& delegate); + virtual ~GenericMultipleBarcodeReader(); + virtual std::vector > decodeMultiple(Ref image, + DecodeHints hints); +}; +} // End zxing::multi namespace +} // End zxing namespace + +#endif // __GENERIC_MULTIPLE_BARCODE_READER_H__ diff --git a/symbian/QZXing/source/zxing/multi/MultipleBarcodeReader.cpp b/symbian/QZXing/source/zxing/multi/MultipleBarcodeReader.cpp index 67e187e1b..8b99f929b 100644 --- a/symbian/QZXing/source/zxing/multi/MultipleBarcodeReader.cpp +++ b/symbian/QZXing/source/zxing/multi/MultipleBarcodeReader.cpp @@ -1,29 +1,29 @@ -/* - * Copyright 2011 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { -namespace multi { - -MultipleBarcodeReader::~MultipleBarcodeReader() { } - -std::vector > MultipleBarcodeReader::decodeMultiple(Ref image) { - return decodeMultiple(image, DecodeHints::DEFAULT_HINT); -} - -} // End zxing::multi namespace -} // End zxing namespace +/* + * Copyright 2011 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { +namespace multi { + +MultipleBarcodeReader::~MultipleBarcodeReader() { } + +std::vector > MultipleBarcodeReader::decodeMultiple(Ref image) { + return decodeMultiple(image, DecodeHints::DEFAULT_HINT); +} + +} // End zxing::multi namespace +} // End zxing namespace diff --git a/symbian/QZXing/source/zxing/multi/MultipleBarcodeReader.h b/symbian/QZXing/source/zxing/multi/MultipleBarcodeReader.h index 61242971d..4f54c67ee 100644 --- a/symbian/QZXing/source/zxing/multi/MultipleBarcodeReader.h +++ b/symbian/QZXing/source/zxing/multi/MultipleBarcodeReader.h @@ -1,39 +1,39 @@ -#ifndef __MULTIPLE_BARCODE_READER_H__ -#define __MULTIPLE_BARCODE_READER_H__ - -/* - * Copyright 2011 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace zxing { -namespace multi { -class MultipleBarcodeReader : public Counted { - protected: - MultipleBarcodeReader() {} - public: - virtual std::vector > decodeMultiple(Ref image); - virtual std::vector > decodeMultiple(Ref image, DecodeHints hints) = 0; - virtual ~MultipleBarcodeReader(); -}; -} // End zxing::multi namespace -} // End zxing namespace - -#endif // __MULTIPLE_BARCODE_READER_H__ +#ifndef __MULTIPLE_BARCODE_READER_H__ +#define __MULTIPLE_BARCODE_READER_H__ + +/* + * Copyright 2011 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +namespace zxing { +namespace multi { +class MultipleBarcodeReader : public Counted { + protected: + MultipleBarcodeReader() {} + public: + virtual std::vector > decodeMultiple(Ref image); + virtual std::vector > decodeMultiple(Ref image, DecodeHints hints) = 0; + virtual ~MultipleBarcodeReader(); +}; +} // End zxing::multi namespace +} // End zxing namespace + +#endif // __MULTIPLE_BARCODE_READER_H__ diff --git a/symbian/QZXing/source/zxing/multi/qrcode/QRCodeMultiReader.cpp b/symbian/QZXing/source/zxing/multi/qrcode/QRCodeMultiReader.cpp index d60f5e069..06d151fb5 100644 --- a/symbian/QZXing/source/zxing/multi/qrcode/QRCodeMultiReader.cpp +++ b/symbian/QZXing/source/zxing/multi/qrcode/QRCodeMultiReader.cpp @@ -1,57 +1,57 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Copyright 2011 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { -namespace multi { -QRCodeMultiReader::QRCodeMultiReader(){} - -QRCodeMultiReader::~QRCodeMultiReader(){} - -std::vector > QRCodeMultiReader::decodeMultiple(Ref image, - DecodeHints hints) -{ - std::vector > results; - MultiDetector detector(image->getBlackMatrix()); - - std::vector > detectorResult = detector.detectMulti(hints); - for (unsigned int i = 0; i < detectorResult.size(); i++) { - try { - Ref decoderResult = getDecoder().decode(detectorResult[i]->getBits()); - std::vector > points = detectorResult[i]->getPoints(); - Ref result = Ref(new Result(decoderResult->getText(), - decoderResult->getRawBytes(), - points, BarcodeFormat_QR_CODE)); - // result->putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult->getByteSegments()); - // result->putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult->getECLevel().toString()); - results.push_back(result); - } catch (ReaderException re) { - // ignore and continue - } - } - if (results.empty()){ - throw ReaderException("No code detected"); - } - return results; -} - -} // End zxing::multi namespace -} // End zxing namespace +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Copyright 2011 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { +namespace multi { +QRCodeMultiReader::QRCodeMultiReader(){} + +QRCodeMultiReader::~QRCodeMultiReader(){} + +std::vector > QRCodeMultiReader::decodeMultiple(Ref image, + DecodeHints hints) +{ + std::vector > results; + MultiDetector detector(image->getBlackMatrix()); + + std::vector > detectorResult = detector.detectMulti(hints); + for (unsigned int i = 0; i < detectorResult.size(); i++) { + try { + Ref decoderResult = getDecoder().decode(detectorResult[i]->getBits()); + std::vector > points = detectorResult[i]->getPoints(); + Ref result = Ref(new Result(decoderResult->getText(), + decoderResult->getRawBytes(), + points, BarcodeFormat_QR_CODE)); + // result->putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult->getByteSegments()); + // result->putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult->getECLevel().toString()); + results.push_back(result); + } catch (ReaderException& re) { + // ignore and continue + } + } + if (results.empty()){ + throw ReaderException("No code detected"); + } + return results; +} + +} // End zxing::multi namespace +} // End zxing namespace diff --git a/symbian/QZXing/source/zxing/multi/qrcode/QRCodeMultiReader.h b/symbian/QZXing/source/zxing/multi/qrcode/QRCodeMultiReader.h index e32be8ce1..050bc1b7d 100644 --- a/symbian/QZXing/source/zxing/multi/qrcode/QRCodeMultiReader.h +++ b/symbian/QZXing/source/zxing/multi/qrcode/QRCodeMultiReader.h @@ -1,34 +1,34 @@ -#ifndef __QRCODE_MULTI_READER_H__ -#define __QRCODE_MULTI_READER_H__ - -/* - * Copyright 2011 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { -namespace multi { -class QRCodeMultiReader: public zxing::qrcode::QRCodeReader, public MultipleBarcodeReader { - public: - QRCodeMultiReader(); - virtual ~QRCodeMultiReader(); - virtual std::vector > decodeMultiple(Ref image, DecodeHints hints); -}; -} // End zxing::multi namespace -} // End zxing namespace - -#endif // __QRCODE_MULTI_READER_H__ +#ifndef __QRCODE_MULTI_READER_H__ +#define __QRCODE_MULTI_READER_H__ + +/* + * Copyright 2011 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { +namespace multi { +class QRCodeMultiReader: public zxing::qrcode::QRCodeReader, public MultipleBarcodeReader { + public: + QRCodeMultiReader(); + virtual ~QRCodeMultiReader(); + virtual std::vector > decodeMultiple(Ref image, DecodeHints hints); +}; +} // End zxing::multi namespace +} // End zxing namespace + +#endif // __QRCODE_MULTI_READER_H__ diff --git a/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiDetector.cpp b/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiDetector.cpp index 53f64a24c..481a10632 100644 --- a/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiDetector.cpp +++ b/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiDetector.cpp @@ -1,46 +1,46 @@ -/* - * Copyright 2011 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -namespace multi { -using namespace zxing::qrcode; - -MultiDetector::MultiDetector(Ref image) : Detector(image) {} - -MultiDetector::~MultiDetector(){} - -std::vector > MultiDetector::detectMulti(DecodeHints hints){ - Ref image = getImage(); - MultiFinderPatternFinder finder = MultiFinderPatternFinder(image, hints.getResultPointCallback()); - std::vector > info = finder.findMulti(hints); - std::vector > result; - for(unsigned int i = 0; i < info.size(); i++){ - try{ - result.push_back(processFinderPatternInfo(info[i])); - } catch (ReaderException e){ - // ignore - } - } - - return result; -} - -} // End zxing::multi namespace -} // End zxing namespace +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { +namespace multi { +using namespace zxing::qrcode; + +MultiDetector::MultiDetector(Ref image) : Detector(image) {} + +MultiDetector::~MultiDetector(){} + +std::vector > MultiDetector::detectMulti(DecodeHints hints){ + Ref image = getImage(); + MultiFinderPatternFinder finder = MultiFinderPatternFinder(image, hints.getResultPointCallback()); + std::vector > info = finder.findMulti(hints); + std::vector > result; + for(unsigned int i = 0; i < info.size(); i++){ + try{ + result.push_back(processFinderPatternInfo(info[i])); + } catch (ReaderException& e){ + // ignore + } + } + + return result; +} + +} // End zxing::multi namespace +} // End zxing namespace diff --git a/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiDetector.h b/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiDetector.h index 338d5d9c0..618a1e798 100644 --- a/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiDetector.h +++ b/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiDetector.h @@ -1,35 +1,35 @@ -#ifndef __MULTI_DETECTOR_H__ -#define __MULTI_DETECTOR_H__ - -/* - * Copyright 2011 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -namespace multi { -class MultiDetector : public zxing::qrcode::Detector { - public: - MultiDetector(Ref image); - virtual ~MultiDetector(); - virtual std::vector > detectMulti(DecodeHints hints); -}; -} // End zxing::multi namespace -} // End zxing namespace - -#endif // __MULTI_DETECTOR_H__ +#ifndef __MULTI_DETECTOR_H__ +#define __MULTI_DETECTOR_H__ + +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { +namespace multi { +class MultiDetector : public zxing::qrcode::Detector { + public: + MultiDetector(Ref image); + virtual ~MultiDetector(); + virtual std::vector > detectMulti(DecodeHints hints); +}; +} // End zxing::multi namespace +} // End zxing namespace + +#endif // __MULTI_DETECTOR_H__ diff --git a/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiFinderPatternFinder.cpp b/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiFinderPatternFinder.cpp index c7694f256..43bc693db 100644 --- a/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiFinderPatternFinder.cpp +++ b/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiFinderPatternFinder.cpp @@ -1,225 +1,230 @@ -/* - * Copyright 2011 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace zxing{ -namespace multi { -using namespace zxing::qrcode; - -bool compareModuleSize(Ref a, Ref b){ - float value = a->getEstimatedModuleSize() - b->getEstimatedModuleSize(); - return value < 0.0; -} - - -MultiFinderPatternFinder::MultiFinderPatternFinder(Ref image, - Ref resultPointCallback) : - FinderPatternFinder(image, resultPointCallback) -{ -} - -MultiFinderPatternFinder::~MultiFinderPatternFinder(){} - -std::vector > MultiFinderPatternFinder::findMulti(DecodeHints const& hints){ - bool tryHarder = hints.getTryHarder(); - Ref image = image_; // Protected member - int maxI = image->getHeight(); - int maxJ = image->getWidth(); - // We are looking for black/white/black/white/black modules in - // 1:1:3:1:1 ratio; this tracks the number of such modules seen so far - - // Let's assume that the maximum version QR Code we support takes up 1/4 the height of the - // image, and then account for the center being 3 modules in size. This gives the smallest - // number of pixels the center could be, so skip this often. When trying harder, look for all - // QR versions regardless of how dense they are. - int iSkip = (int) (maxI / (MAX_MODULES * 4.0f) * 3); - if (iSkip < MIN_SKIP || tryHarder) { - iSkip = MIN_SKIP; - } - - int stateCount[5]; - for (int i = iSkip - 1; i < maxI; i += iSkip) { - // Get a row of black/white values - stateCount[0] = 0; - stateCount[1] = 0; - stateCount[2] = 0; - stateCount[3] = 0; - stateCount[4] = 0; - int currentState = 0; - for (int j = 0; j < maxJ; j++) { - if (image->get(j, i)) { - // Black pixel - if ((currentState & 1) == 1) { // Counting white pixels - currentState++; - } - stateCount[currentState]++; - } else { // White pixel - if ((currentState & 1) == 0) { // Counting black pixels - if (currentState == 4) { // A winner? - if (foundPatternCross(stateCount)) { // Yes - bool confirmed = handlePossibleCenter(stateCount, i, j); - if (!confirmed) { - do { // Advance to next black pixel - j++; - } while (j < maxJ && !image->get(j, i)); - j--; // back up to that last white pixel - } - // Clear state to start looking again - currentState = 0; - stateCount[0] = 0; - stateCount[1] = 0; - stateCount[2] = 0; - stateCount[3] = 0; - stateCount[4] = 0; - } else { // No, shift counts back by two - stateCount[0] = stateCount[2]; - stateCount[1] = stateCount[3]; - stateCount[2] = stateCount[4]; - stateCount[3] = 1; - stateCount[4] = 0; - currentState = 3; - } - } else { - stateCount[++currentState]++; - } - } else { // Counting white pixels - stateCount[currentState]++; - } - } - } // for j=... - - if (foundPatternCross(stateCount)) { - handlePossibleCenter(stateCount, i, maxJ); - } // end if foundPatternCross - } // for i=iSkip-1 ... - std::vector > > patternInfo = selectBestPatterns(); - std::vector > result; - for (unsigned int i = 0; i < patternInfo.size(); i++) { - std::vector > pattern = patternInfo[i]; - FinderPatternFinder::orderBestPatterns(pattern); - result.push_back(Ref(new FinderPatternInfo(pattern))); - } - return result; -} - -std::vector > > MultiFinderPatternFinder::selectBestPatterns(){ - std::vector > possibleCenters = possibleCenters_; - - int size = possibleCenters.size(); - - if (size < 3) { - // Couldn't find enough finder patterns - throw ReaderException("No code detected"); - } - - std::vector > > results; - - /* - * Begin HE modifications to safely detect multiple codes of equal size - */ - if (size == 3) { - results.push_back(possibleCenters_); - return results; - } - - // Sort by estimated module size to speed up the upcoming checks - //TODO do a sort based on module size - std::sort(possibleCenters.begin(), possibleCenters.end(), compareModuleSize); - - /* - * Now lets start: build a list of tuples of three finder locations that - * - feature similar module sizes - * - are placed in a distance so the estimated module count is within the QR specification - * - have similar distance between upper left/right and left top/bottom finder patterns - * - form a triangle with 90° angle (checked by comparing top right/bottom left distance - * with pythagoras) - * - * Note: we allow each point to be used for more than one code region: this might seem - * counterintuitive at first, but the performance penalty is not that big. At this point, - * we cannot make a good quality decision whether the three finders actually represent - * a QR code, or are just by chance layouted so it looks like there might be a QR code there. - * So, if the layout seems right, lets have the decoder try to decode. - */ - - for (int i1 = 0; i1 < (size - 2); i1++) { - Ref p1 = possibleCenters[i1]; - for (int i2 = i1 + 1; i2 < (size - 1); i2++) { - Ref p2 = possibleCenters[i2]; - // Compare the expected module sizes; if they are really off, skip - float vModSize12 = (p1->getEstimatedModuleSize() - p2->getEstimatedModuleSize()) / std::min(p1->getEstimatedModuleSize(), p2->getEstimatedModuleSize()); - float vModSize12A = abs(p1->getEstimatedModuleSize() - p2->getEstimatedModuleSize()); - if (vModSize12A > DIFF_MODSIZE_CUTOFF && vModSize12 >= DIFF_MODSIZE_CUTOFF_PERCENT) { - // break, since elements are ordered by the module size deviation there cannot be - // any more interesting elements for the given p1. - break; - } - for (int i3 = i2 + 1; i3 < size; i3++) { - Ref p3 = possibleCenters[i3]; - // Compare the expected module sizes; if they are really off, skip - float vModSize23 = (p2->getEstimatedModuleSize() - p3->getEstimatedModuleSize()) / std::min(p2->getEstimatedModuleSize(), p3->getEstimatedModuleSize()); - float vModSize23A = abs(p2->getEstimatedModuleSize() - p3->getEstimatedModuleSize()); - if (vModSize23A > DIFF_MODSIZE_CUTOFF && vModSize23 >= DIFF_MODSIZE_CUTOFF_PERCENT) { - // break, since elements are ordered by the module size deviation there cannot be - // any more interesting elements for the given p1. - break; - } - std::vector > test; - test.push_back(p1); - test.push_back(p2); - test.push_back(p3); - FinderPatternFinder::orderBestPatterns(test); - // Calculate the distances: a = topleft-bottomleft, b=topleft-topright, c = diagonal - Ref info = Ref(new FinderPatternInfo(test)); - float dA = FinderPatternFinder::distance(info->getTopLeft(), info->getBottomLeft()); - float dC = FinderPatternFinder::distance(info->getTopRight(), info->getBottomLeft()); - float dB = FinderPatternFinder::distance(info->getTopLeft(), info->getTopRight()); - // Check the sizes - float estimatedModuleCount = (dA + dB) / (p1->getEstimatedModuleSize() * 2.0f); - if (estimatedModuleCount > MAX_MODULE_COUNT_PER_EDGE || estimatedModuleCount < MIN_MODULE_COUNT_PER_EDGE) { - continue; - } - // Calculate the difference of the edge lengths in percent - float vABBC = abs((dA - dB) / std::min(dA, dB)); - if (vABBC >= 0.1f) { - continue; - } - // Calculate the diagonal length by assuming a 90° angle at topleft - float dCpy = (float) sqrt(dA * dA + dB * dB); - // Compare to the real distance in % - float vPyC = abs((dC - dCpy) / std::min(dC, dCpy)); - if (vPyC >= 0.1f) { - continue; - } - // All tests passed! - results.push_back(test); - } // end iterate p3 - } // end iterate p2 - } // end iterate p1 - if (results.empty()){ - // Nothing found! - throw ReaderException("No code detected"); - } - return results; -} - -} // End zxing::multi namespace -} // End zxing namespace +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +namespace zxing{ +namespace multi { +using namespace zxing::qrcode; + +const float MultiFinderPatternFinder::MAX_MODULE_COUNT_PER_EDGE = 180; +const float MultiFinderPatternFinder::MIN_MODULE_COUNT_PER_EDGE = 9; +const float MultiFinderPatternFinder::DIFF_MODSIZE_CUTOFF_PERCENT = 0.05f; +const float MultiFinderPatternFinder::DIFF_MODSIZE_CUTOFF = 0.5f; + +bool compareModuleSize(Ref a, Ref b){ + float value = a->getEstimatedModuleSize() - b->getEstimatedModuleSize(); + return value < 0.0; +} + + +MultiFinderPatternFinder::MultiFinderPatternFinder(Ref image, + Ref resultPointCallback) : + FinderPatternFinder(image, resultPointCallback) +{ +} + +MultiFinderPatternFinder::~MultiFinderPatternFinder(){} + +std::vector > MultiFinderPatternFinder::findMulti(DecodeHints const& hints){ + bool tryHarder = hints.getTryHarder(); + Ref image = image_; // Protected member + int maxI = image->getHeight(); + int maxJ = image->getWidth(); + // We are looking for black/white/black/white/black modules in + // 1:1:3:1:1 ratio; this tracks the number of such modules seen so far + + // Let's assume that the maximum version QR Code we support takes up 1/4 the height of the + // image, and then account for the center being 3 modules in size. This gives the smallest + // number of pixels the center could be, so skip this often. When trying harder, look for all + // QR versions regardless of how dense they are. + int iSkip = (int) (maxI / (MAX_MODULES * 4.0f) * 3); + if (iSkip < MIN_SKIP || tryHarder) { + iSkip = MIN_SKIP; + } + + int stateCount[5]; + for (int i = iSkip - 1; i < maxI; i += iSkip) { + // Get a row of black/white values + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + stateCount[3] = 0; + stateCount[4] = 0; + int currentState = 0; + for (int j = 0; j < maxJ; j++) { + if (image->get(j, i)) { + // Black pixel + if ((currentState & 1) == 1) { // Counting white pixels + currentState++; + } + stateCount[currentState]++; + } else { // White pixel + if ((currentState & 1) == 0) { // Counting black pixels + if (currentState == 4) { // A winner? + if (foundPatternCross(stateCount)) { // Yes + bool confirmed = handlePossibleCenter(stateCount, i, j); + if (!confirmed) { + do { // Advance to next black pixel + j++; + } while (j < maxJ && !image->get(j, i)); + j--; // back up to that last white pixel + } + // Clear state to start looking again + currentState = 0; + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + stateCount[3] = 0; + stateCount[4] = 0; + } else { // No, shift counts back by two + stateCount[0] = stateCount[2]; + stateCount[1] = stateCount[3]; + stateCount[2] = stateCount[4]; + stateCount[3] = 1; + stateCount[4] = 0; + currentState = 3; + } + } else { + stateCount[++currentState]++; + } + } else { // Counting white pixels + stateCount[currentState]++; + } + } + } // for j=... + + if (foundPatternCross(stateCount)) { + handlePossibleCenter(stateCount, i, maxJ); + } // end if foundPatternCross + } // for i=iSkip-1 ... + std::vector > > patternInfo = selectBestPatterns(); + std::vector > result; + for (unsigned int i = 0; i < patternInfo.size(); i++) { + std::vector > pattern = patternInfo[i]; + FinderPatternFinder::orderBestPatterns(pattern); + result.push_back(Ref(new FinderPatternInfo(pattern))); + } + return result; +} + +std::vector > > MultiFinderPatternFinder::selectBestPatterns(){ + std::vector > possibleCenters = possibleCenters_; + + int size = possibleCenters.size(); + + if (size < 3) { + // Couldn't find enough finder patterns + throw ReaderException("No code detected"); + } + + std::vector > > results; + + /* + * Begin HE modifications to safely detect multiple codes of equal size + */ + if (size == 3) { + results.push_back(possibleCenters_); + return results; + } + + // Sort by estimated module size to speed up the upcoming checks + //TODO do a sort based on module size + std::sort(possibleCenters.begin(), possibleCenters.end(), compareModuleSize); + + /* + * Now lets start: build a list of tuples of three finder locations that + * - feature similar module sizes + * - are placed in a distance so the estimated module count is within the QR specification + * - have similar distance between upper left/right and left top/bottom finder patterns + * - form a triangle with 90° angle (checked by comparing top right/bottom left distance + * with pythagoras) + * + * Note: we allow each point to be used for more than one code region: this might seem + * counterintuitive at first, but the performance penalty is not that big. At this point, + * we cannot make a good quality decision whether the three finders actually represent + * a QR code, or are just by chance layouted so it looks like there might be a QR code there. + * So, if the layout seems right, lets have the decoder try to decode. + */ + + for (int i1 = 0; i1 < (size - 2); i1++) { + Ref p1 = possibleCenters[i1]; + for (int i2 = i1 + 1; i2 < (size - 1); i2++) { + Ref p2 = possibleCenters[i2]; + // Compare the expected module sizes; if they are really off, skip + float vModSize12 = (p1->getEstimatedModuleSize() - p2->getEstimatedModuleSize()) / std::min(p1->getEstimatedModuleSize(), p2->getEstimatedModuleSize()); + float vModSize12A = abs(p1->getEstimatedModuleSize() - p2->getEstimatedModuleSize()); + if (vModSize12A > DIFF_MODSIZE_CUTOFF && vModSize12 >= DIFF_MODSIZE_CUTOFF_PERCENT) { + // break, since elements are ordered by the module size deviation there cannot be + // any more interesting elements for the given p1. + break; + } + for (int i3 = i2 + 1; i3 < size; i3++) { + Ref p3 = possibleCenters[i3]; + // Compare the expected module sizes; if they are really off, skip + float vModSize23 = (p2->getEstimatedModuleSize() - p3->getEstimatedModuleSize()) / std::min(p2->getEstimatedModuleSize(), p3->getEstimatedModuleSize()); + float vModSize23A = abs(p2->getEstimatedModuleSize() - p3->getEstimatedModuleSize()); + if (vModSize23A > DIFF_MODSIZE_CUTOFF && vModSize23 >= DIFF_MODSIZE_CUTOFF_PERCENT) { + // break, since elements are ordered by the module size deviation there cannot be + // any more interesting elements for the given p1. + break; + } + std::vector > test; + test.push_back(p1); + test.push_back(p2); + test.push_back(p3); + FinderPatternFinder::orderBestPatterns(test); + // Calculate the distances: a = topleft-bottomleft, b=topleft-topright, c = diagonal + Ref info = Ref(new FinderPatternInfo(test)); + float dA = FinderPatternFinder::distance(info->getTopLeft(), info->getBottomLeft()); + float dC = FinderPatternFinder::distance(info->getTopRight(), info->getBottomLeft()); + float dB = FinderPatternFinder::distance(info->getTopLeft(), info->getTopRight()); + // Check the sizes + float estimatedModuleCount = (dA + dB) / (p1->getEstimatedModuleSize() * 2.0f); + if (estimatedModuleCount > MAX_MODULE_COUNT_PER_EDGE || estimatedModuleCount < MIN_MODULE_COUNT_PER_EDGE) { + continue; + } + // Calculate the difference of the edge lengths in percent + float vABBC = abs((dA - dB) / std::min(dA, dB)); + if (vABBC >= 0.1f) { + continue; + } + // Calculate the diagonal length by assuming a 90° angle at topleft + float dCpy = (float) sqrt(dA * dA + dB * dB); + // Compare to the real distance in % + float vPyC = abs((dC - dCpy) / std::min(dC, dCpy)); + if (vPyC >= 0.1f) { + continue; + } + // All tests passed! + results.push_back(test); + } // end iterate p3 + } // end iterate p2 + } // end iterate p1 + if (results.empty()){ + // Nothing found! + throw ReaderException("No code detected"); + } + return results; +} + +} // End zxing::multi namespace +} // End zxing namespace diff --git a/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiFinderPatternFinder.h b/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiFinderPatternFinder.h index b6db8107d..2aeb3f624 100644 --- a/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiFinderPatternFinder.h +++ b/symbian/QZXing/source/zxing/multi/qrcode/detector/MultiFinderPatternFinder.h @@ -1,45 +1,45 @@ -#ifndef __MULTI_FINDER_PATTERN_FINDER_H__ -#define __MULTI_FINDER_PATTERN_FINDER_H__ - -/* - * Copyright 2011 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -namespace multi { -class MultiFinderPatternFinder : zxing::qrcode::FinderPatternFinder { - private: - std::vector > > selectBestPatterns(); - - static const float MAX_MODULE_COUNT_PER_EDGE = 180; - static const float MIN_MODULE_COUNT_PER_EDGE = 9; - static const float DIFF_MODSIZE_CUTOFF_PERCENT = 0.05f; - static const float DIFF_MODSIZE_CUTOFF = 0.5f; - - public: - MultiFinderPatternFinder(Ref image, Ref resultPointCallback); - virtual ~MultiFinderPatternFinder(); - virtual std::vector > findMulti(DecodeHints const& hints); - - -}; -} -} - -#endif // __MULTI_FINDER_PATTERN_FINDER_H__ +#ifndef __MULTI_FINDER_PATTERN_FINDER_H__ +#define __MULTI_FINDER_PATTERN_FINDER_H__ + +/* + * Copyright 2011 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { +namespace multi { +class MultiFinderPatternFinder : zxing::qrcode::FinderPatternFinder { + private: + std::vector > > selectBestPatterns(); + + static const float MAX_MODULE_COUNT_PER_EDGE; + static const float MIN_MODULE_COUNT_PER_EDGE; + static const float DIFF_MODSIZE_CUTOFF_PERCENT; + static const float DIFF_MODSIZE_CUTOFF; + + public: + MultiFinderPatternFinder(Ref image, Ref resultPointCallback); + virtual ~MultiFinderPatternFinder(); + virtual std::vector > findMulti(DecodeHints const& hints); + + +}; +} +} + +#endif // __MULTI_FINDER_PATTERN_FINDER_H__ diff --git a/symbian/QZXing/source/zxing/oned/Code128Reader.cpp b/symbian/QZXing/source/zxing/oned/Code128Reader.cpp index 14cda9bde..171f0e977 100644 --- a/symbian/QZXing/source/zxing/oned/Code128Reader.cpp +++ b/symbian/QZXing/source/zxing/oned/Code128Reader.cpp @@ -1,502 +1,490 @@ -/* - * Code128Reader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Code128Reader.h" -#include -#include -#include -#include -#include -#include - -namespace zxing { - namespace oned { - - const int CODE_PATTERNS_LENGTH = 107; - const int countersLength = 6; - static const int CODE_PATTERNS[CODE_PATTERNS_LENGTH][countersLength] = { - {2, 1, 2, 2, 2, 2}, /* 0 */ - {2, 2, 2, 1, 2, 2}, - {2, 2, 2, 2, 2, 1}, - {1, 2, 1, 2, 2, 3}, - {1, 2, 1, 3, 2, 2}, - {1, 3, 1, 2, 2, 2}, /* 5 */ - {1, 2, 2, 2, 1, 3}, - {1, 2, 2, 3, 1, 2}, - {1, 3, 2, 2, 1, 2}, - {2, 2, 1, 2, 1, 3}, - {2, 2, 1, 3, 1, 2}, /* 10 */ - {2, 3, 1, 2, 1, 2}, - {1, 1, 2, 2, 3, 2}, - {1, 2, 2, 1, 3, 2}, - {1, 2, 2, 2, 3, 1}, - {1, 1, 3, 2, 2, 2}, /* 15 */ - {1, 2, 3, 1, 2, 2}, - {1, 2, 3, 2, 2, 1}, - {2, 2, 3, 2, 1, 1}, - {2, 2, 1, 1, 3, 2}, - {2, 2, 1, 2, 3, 1}, /* 20 */ - {2, 1, 3, 2, 1, 2}, - {2, 2, 3, 1, 1, 2}, - {3, 1, 2, 1, 3, 1}, - {3, 1, 1, 2, 2, 2}, - {3, 2, 1, 1, 2, 2}, /* 25 */ - {3, 2, 1, 2, 2, 1}, - {3, 1, 2, 2, 1, 2}, - {3, 2, 2, 1, 1, 2}, - {3, 2, 2, 2, 1, 1}, - {2, 1, 2, 1, 2, 3}, /* 30 */ - {2, 1, 2, 3, 2, 1}, - {2, 3, 2, 1, 2, 1}, - {1, 1, 1, 3, 2, 3}, - {1, 3, 1, 1, 2, 3}, - {1, 3, 1, 3, 2, 1}, /* 35 */ - {1, 1, 2, 3, 1, 3}, - {1, 3, 2, 1, 1, 3}, - {1, 3, 2, 3, 1, 1}, - {2, 1, 1, 3, 1, 3}, - {2, 3, 1, 1, 1, 3}, /* 40 */ - {2, 3, 1, 3, 1, 1}, - {1, 1, 2, 1, 3, 3}, - {1, 1, 2, 3, 3, 1}, - {1, 3, 2, 1, 3, 1}, - {1, 1, 3, 1, 2, 3}, /* 45 */ - {1, 1, 3, 3, 2, 1}, - {1, 3, 3, 1, 2, 1}, - {3, 1, 3, 1, 2, 1}, - {2, 1, 1, 3, 3, 1}, - {2, 3, 1, 1, 3, 1}, /* 50 */ - {2, 1, 3, 1, 1, 3}, - {2, 1, 3, 3, 1, 1}, - {2, 1, 3, 1, 3, 1}, - {3, 1, 1, 1, 2, 3}, - {3, 1, 1, 3, 2, 1}, /* 55 */ - {3, 3, 1, 1, 2, 1}, - {3, 1, 2, 1, 1, 3}, - {3, 1, 2, 3, 1, 1}, - {3, 3, 2, 1, 1, 1}, - {3, 1, 4, 1, 1, 1}, /* 60 */ - {2, 2, 1, 4, 1, 1}, - {4, 3, 1, 1, 1, 1}, - {1, 1, 1, 2, 2, 4}, - {1, 1, 1, 4, 2, 2}, - {1, 2, 1, 1, 2, 4}, /* 65 */ - {1, 2, 1, 4, 2, 1}, - {1, 4, 1, 1, 2, 2}, - {1, 4, 1, 2, 2, 1}, - {1, 1, 2, 2, 1, 4}, - {1, 1, 2, 4, 1, 2}, /* 70 */ - {1, 2, 2, 1, 1, 4}, - {1, 2, 2, 4, 1, 1}, - {1, 4, 2, 1, 1, 2}, - {1, 4, 2, 2, 1, 1}, - {2, 4, 1, 2, 1, 1}, /* 75 */ - {2, 2, 1, 1, 1, 4}, - {4, 1, 3, 1, 1, 1}, - {2, 4, 1, 1, 1, 2}, - {1, 3, 4, 1, 1, 1}, - {1, 1, 1, 2, 4, 2}, /* 80 */ - {1, 2, 1, 1, 4, 2}, - {1, 2, 1, 2, 4, 1}, - {1, 1, 4, 2, 1, 2}, - {1, 2, 4, 1, 1, 2}, - {1, 2, 4, 2, 1, 1}, /* 85 */ - {4, 1, 1, 2, 1, 2}, - {4, 2, 1, 1, 1, 2}, - {4, 2, 1, 2, 1, 1}, - {2, 1, 2, 1, 4, 1}, - {2, 1, 4, 1, 2, 1}, /* 90 */ - {4, 1, 2, 1, 2, 1}, - {1, 1, 1, 1, 4, 3}, - {1, 1, 1, 3, 4, 1}, - {1, 3, 1, 1, 4, 1}, - {1, 1, 4, 1, 1, 3}, /* 95 */ - {1, 1, 4, 3, 1, 1}, - {4, 1, 1, 1, 1, 3}, - {4, 1, 1, 3, 1, 1}, - {1, 1, 3, 1, 4, 1}, - {1, 1, 4, 1, 3, 1}, /* 100 */ - {3, 1, 1, 1, 4, 1}, - {4, 1, 1, 1, 3, 1}, - {2, 1, 1, 4, 1, 2}, - {2, 1, 1, 2, 1, 4}, - {2, 1, 1, 2, 3, 2}, /* 105 */ - {2, 3, 3, 1, 1, 1} - }; - - - Code128Reader::Code128Reader(){ - } - - int* Code128Reader::findStartPattern(Ref row){ - int width = row->getSize(); - int rowOffset = 0; - while (rowOffset < width) { - if (row->get(rowOffset)) { - break; - } - rowOffset++; - } - - int counterPosition = 0; - int counters[countersLength] = {0,0,0,0,0,0}; - int patternStart = rowOffset; - bool isWhite = false; - int patternLength = sizeof(counters) / sizeof(int); - - for (int i = rowOffset; i < width; i++) { - bool pixel = row->get(i); - if (pixel ^ isWhite) { - counters[counterPosition]++; - } else { - if (counterPosition == patternLength - 1) { - unsigned int bestVariance = MAX_AVG_VARIANCE; - int bestMatch = -1; - for (int startCode = CODE_START_A; startCode <= CODE_START_C; startCode++) { - unsigned int variance = patternMatchVariance(counters, sizeof(counters) / sizeof(int), - CODE_PATTERNS[startCode], MAX_INDIVIDUAL_VARIANCE); - if (variance < bestVariance) { - bestVariance = variance; - bestMatch = startCode; - } - } - if (bestMatch >= 0) { - // Look for whitespace before start pattern, >= 50% of width of start pattern - long maxResult = 0; -#ifndef NOFMAXL - maxResult = fmaxl(0, patternStart - (i - patternStart) / 2); -#else - maxResult = fmax(0, patternStart - (i - patternStart) / 2); -#endif - if (row->isRange(maxResult, patternStart, - false)) { - int* resultValue = new int[3]; - resultValue[0] = patternStart; - resultValue[1] = i; - resultValue[2] = bestMatch; - return resultValue; - } - } - patternStart += counters[0] + counters[1]; - for (int y = 2; y < patternLength; y++) { - counters[y - 2] = counters[y]; - } - counters[patternLength - 2] = 0; - counters[patternLength - 1] = 0; - counterPosition--; - } else { - counterPosition++; - } - counters[counterPosition] = 1; - isWhite = !isWhite; - } - } - throw ReaderException(""); - } - - int Code128Reader::decodeCode(Ref row, int counters[], int countersCount, - int rowOffset) { - if (!recordPattern(row, rowOffset, counters, countersCount)) { - throw ReaderException(""); - } - unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept - int bestMatch = -1; - for (int d = 0; d < CODE_PATTERNS_LENGTH; d++) { - int pattern[countersLength]; - - for(int ind = 0; ind< countersLength; ind++){ - pattern[ind] = CODE_PATTERNS[d][ind]; - } -// memcpy(pattern, CODE_PATTERNS[d], countersLength); - unsigned int variance = patternMatchVariance(counters, countersCount, pattern, - MAX_INDIVIDUAL_VARIANCE); - if (variance < bestVariance) { - bestVariance = variance; - bestMatch = d; - } - } - // TODO We're overlooking the fact that the STOP pattern has 7 values, not 6. - if (bestMatch >= 0) { - return bestMatch; - } else { - throw ReaderException(""); - } - } - - Ref Code128Reader::decodeRow(int rowNumber, Ref row) { - int* startPatternInfo = NULL; - try { - startPatternInfo = findStartPattern(row); - int startCode = startPatternInfo[2]; - int codeSet; - switch (startCode) { - case CODE_START_A: - codeSet = CODE_CODE_A; - break; - case CODE_START_B: - codeSet = CODE_CODE_B; - break; - case CODE_START_C: - codeSet = CODE_CODE_C; - break; - default: - throw ReaderException(""); - } - - bool done = false; - bool isNextShifted = false; - - std::string tmpResultString; - std::stringstream tmpResultSStr; // used if its Code 128C - - int lastStart = startPatternInfo[0]; - int nextStart = startPatternInfo[1]; - int counters[countersLength] = {0,0,0,0,0,0}; - - int lastCode = 0; - int code = 0; - int checksumTotal = startCode; - int multiplier = 0; - bool lastCharacterWasPrintable = true; - - while (!done) { - bool unshift = isNextShifted; - isNextShifted = false; - - // Save off last code - lastCode = code; - - // Decode another code from image - try { - code = decodeCode(row, counters, sizeof(counters)/sizeof(int), nextStart); - } catch (ReaderException const& re) { - throw re; - } - - // Remember whether the last code was printable or not (excluding CODE_STOP) - if (code != CODE_STOP) { - lastCharacterWasPrintable = true; - } - - // Add to checksum computation (if not CODE_STOP of course) - if (code != CODE_STOP) { - multiplier++; - checksumTotal += multiplier * code; - } - - // Advance to where the next code will to start - lastStart = nextStart; - int _countersLength = sizeof(counters) / sizeof(int); - for (int i = 0; i < _countersLength; i++) { - nextStart += counters[i]; - } - - // Take care of illegal start codes - switch (code) { - case CODE_START_A: - case CODE_START_B: - case CODE_START_C: - throw ReaderException(""); - } - - switch (codeSet) { - - case CODE_CODE_A: - if (code < 64) { - tmpResultString.append(1, (char) (' ' + code)); - } else if (code < 96) { - tmpResultString.append(1, (char) (code - 64)); - } else { - // Don't let CODE_STOP, which always appears, affect whether whether we think the - // last code was printable or not. - if (code != CODE_STOP) { - lastCharacterWasPrintable = false; - } - switch (code) { - case CODE_FNC_1: - case CODE_FNC_2: - case CODE_FNC_3: - case CODE_FNC_4_A: - // do nothing? - break; - case CODE_SHIFT: - isNextShifted = true; - codeSet = CODE_CODE_B; - break; - case CODE_CODE_B: - codeSet = CODE_CODE_B; - break; - case CODE_CODE_C: - codeSet = CODE_CODE_C; - break; - case CODE_STOP: - done = true; - break; - } - } - break; - case CODE_CODE_B: - if (code < 96) { - tmpResultString.append(1, (char) (' ' + code)); - } else { - if (code != CODE_STOP) { - lastCharacterWasPrintable = false; - } - switch (code) { - case CODE_FNC_1: - case CODE_FNC_2: - case CODE_FNC_3: - case CODE_FNC_4_B: - // do nothing? - break; - case CODE_SHIFT: - isNextShifted = true; - codeSet = CODE_CODE_C; - break; - case CODE_CODE_A: - codeSet = CODE_CODE_A; - break; - case CODE_CODE_C: - codeSet = CODE_CODE_C; - break; - case CODE_STOP: - done = true; - break; - } - } - break; - case CODE_CODE_C: - tmpResultSStr.str(std::string()); - // the code read in this case is the number encoded directly - if (code < 100) { - if (code < 10) { - tmpResultSStr << '0'; - } - tmpResultSStr << code; - tmpResultString.append(tmpResultSStr.str()); - } else { - if (code != CODE_STOP) { - lastCharacterWasPrintable = false; - } - switch (code) { - case CODE_FNC_1: - // do nothing? - break; - case CODE_CODE_A: - codeSet = CODE_CODE_A; - break; - case CODE_CODE_B: - codeSet = CODE_CODE_B; - break; - case CODE_STOP: - done = true; - break; - } - } - break; - } - - // Unshift back to another code set if we were shifted - if (unshift) { - switch (codeSet) { - case CODE_CODE_A: - codeSet = CODE_CODE_C; - break; - case CODE_CODE_B: - codeSet = CODE_CODE_A; - break; - case CODE_CODE_C: - codeSet = CODE_CODE_B; - break; - } - } - - } - - // Check for ample whitespace following pattern, but, to do this we first need to remember that - // we fudged decoding CODE_STOP since it actually has 7 bars, not 6. There is a black bar left - // to read off. Would be slightly better to properly read. Here we just skip it: - int width = row->getSize(); - while (nextStart < width && row->get(nextStart)) { - nextStart++; - } - long minResult = 0; -#ifndef NOFMAXL - minResult = fminl(width, nextStart + (nextStart - lastStart)/ 2); -#else - minResult = fmin(width, nextStart + (nextStart - lastStart)/ 2); -#endif - if (!row->isRange(nextStart, minResult, false)) { - throw ReaderException(""); - } - - // Pull out from sum the value of the penultimate check code - checksumTotal -= multiplier * lastCode; - // lastCode is the checksum then: - if (checksumTotal % 103 != lastCode) { - throw ReaderException(""); - } - - // Need to pull out the check digits from string - int resultLength = tmpResultString.length(); - // Only bother if the result had at least one character, and if the checksum digit happened to - // be a printable character. If it was just interpreted as a control code, nothing to remove. - if (resultLength > 0 && lastCharacterWasPrintable) { - if (codeSet == CODE_CODE_C) { - tmpResultString.erase(resultLength - 2, resultLength); - } else { - tmpResultString.erase(resultLength - 1, resultLength); - } - } - - Ref resultString(new String(tmpResultString)); - if (tmpResultString.length() == 0) { - // Almost surely a false positive - throw ReaderException(""); - } - - float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f; - float right = (float) (nextStart + lastStart) / 2.0f; - - std::vector< Ref > resultPoints(2); - Ref resultPoint1(new OneDResultPoint(left, (float) rowNumber)); - Ref resultPoint2(new OneDResultPoint(right, (float) rowNumber)); - resultPoints[0] = resultPoint1; - resultPoints[1] = resultPoint2; - - delete [] startPatternInfo; - ArrayRef resultBytes(1); - return Ref(new Result(resultString, resultBytes, resultPoints, - BarcodeFormat_CODE_128)); - } catch (ReaderException const& re) { - delete [] startPatternInfo; - return Ref(); - } - } - - void Code128Reader::append(char* s, char c){ - int len = strlen(s); - s[len] = c; - s[len + 1] = '\0'; - } - - Code128Reader::~Code128Reader(){ - } - } -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Code128Reader.h" +#include +#include +#include +#include +#include +#include + +namespace zxing { + namespace oned { + + const int CODE_PATTERNS_LENGTH = 107; + const int countersLength = 6; + static const int CODE_PATTERNS[CODE_PATTERNS_LENGTH][countersLength] = { + {2, 1, 2, 2, 2, 2}, /* 0 */ + {2, 2, 2, 1, 2, 2}, + {2, 2, 2, 2, 2, 1}, + {1, 2, 1, 2, 2, 3}, + {1, 2, 1, 3, 2, 2}, + {1, 3, 1, 2, 2, 2}, /* 5 */ + {1, 2, 2, 2, 1, 3}, + {1, 2, 2, 3, 1, 2}, + {1, 3, 2, 2, 1, 2}, + {2, 2, 1, 2, 1, 3}, + {2, 2, 1, 3, 1, 2}, /* 10 */ + {2, 3, 1, 2, 1, 2}, + {1, 1, 2, 2, 3, 2}, + {1, 2, 2, 1, 3, 2}, + {1, 2, 2, 2, 3, 1}, + {1, 1, 3, 2, 2, 2}, /* 15 */ + {1, 2, 3, 1, 2, 2}, + {1, 2, 3, 2, 2, 1}, + {2, 2, 3, 2, 1, 1}, + {2, 2, 1, 1, 3, 2}, + {2, 2, 1, 2, 3, 1}, /* 20 */ + {2, 1, 3, 2, 1, 2}, + {2, 2, 3, 1, 1, 2}, + {3, 1, 2, 1, 3, 1}, + {3, 1, 1, 2, 2, 2}, + {3, 2, 1, 1, 2, 2}, /* 25 */ + {3, 2, 1, 2, 2, 1}, + {3, 1, 2, 2, 1, 2}, + {3, 2, 2, 1, 1, 2}, + {3, 2, 2, 2, 1, 1}, + {2, 1, 2, 1, 2, 3}, /* 30 */ + {2, 1, 2, 3, 2, 1}, + {2, 3, 2, 1, 2, 1}, + {1, 1, 1, 3, 2, 3}, + {1, 3, 1, 1, 2, 3}, + {1, 3, 1, 3, 2, 1}, /* 35 */ + {1, 1, 2, 3, 1, 3}, + {1, 3, 2, 1, 1, 3}, + {1, 3, 2, 3, 1, 1}, + {2, 1, 1, 3, 1, 3}, + {2, 3, 1, 1, 1, 3}, /* 40 */ + {2, 3, 1, 3, 1, 1}, + {1, 1, 2, 1, 3, 3}, + {1, 1, 2, 3, 3, 1}, + {1, 3, 2, 1, 3, 1}, + {1, 1, 3, 1, 2, 3}, /* 45 */ + {1, 1, 3, 3, 2, 1}, + {1, 3, 3, 1, 2, 1}, + {3, 1, 3, 1, 2, 1}, + {2, 1, 1, 3, 3, 1}, + {2, 3, 1, 1, 3, 1}, /* 50 */ + {2, 1, 3, 1, 1, 3}, + {2, 1, 3, 3, 1, 1}, + {2, 1, 3, 1, 3, 1}, + {3, 1, 1, 1, 2, 3}, + {3, 1, 1, 3, 2, 1}, /* 55 */ + {3, 3, 1, 1, 2, 1}, + {3, 1, 2, 1, 1, 3}, + {3, 1, 2, 3, 1, 1}, + {3, 3, 2, 1, 1, 1}, + {3, 1, 4, 1, 1, 1}, /* 60 */ + {2, 2, 1, 4, 1, 1}, + {4, 3, 1, 1, 1, 1}, + {1, 1, 1, 2, 2, 4}, + {1, 1, 1, 4, 2, 2}, + {1, 2, 1, 1, 2, 4}, /* 65 */ + {1, 2, 1, 4, 2, 1}, + {1, 4, 1, 1, 2, 2}, + {1, 4, 1, 2, 2, 1}, + {1, 1, 2, 2, 1, 4}, + {1, 1, 2, 4, 1, 2}, /* 70 */ + {1, 2, 2, 1, 1, 4}, + {1, 2, 2, 4, 1, 1}, + {1, 4, 2, 1, 1, 2}, + {1, 4, 2, 2, 1, 1}, + {2, 4, 1, 2, 1, 1}, /* 75 */ + {2, 2, 1, 1, 1, 4}, + {4, 1, 3, 1, 1, 1}, + {2, 4, 1, 1, 1, 2}, + {1, 3, 4, 1, 1, 1}, + {1, 1, 1, 2, 4, 2}, /* 80 */ + {1, 2, 1, 1, 4, 2}, + {1, 2, 1, 2, 4, 1}, + {1, 1, 4, 2, 1, 2}, + {1, 2, 4, 1, 1, 2}, + {1, 2, 4, 2, 1, 1}, /* 85 */ + {4, 1, 1, 2, 1, 2}, + {4, 2, 1, 1, 1, 2}, + {4, 2, 1, 2, 1, 1}, + {2, 1, 2, 1, 4, 1}, + {2, 1, 4, 1, 2, 1}, /* 90 */ + {4, 1, 2, 1, 2, 1}, + {1, 1, 1, 1, 4, 3}, + {1, 1, 1, 3, 4, 1}, + {1, 3, 1, 1, 4, 1}, + {1, 1, 4, 1, 1, 3}, /* 95 */ + {1, 1, 4, 3, 1, 1}, + {4, 1, 1, 1, 1, 3}, + {4, 1, 1, 3, 1, 1}, + {1, 1, 3, 1, 4, 1}, + {1, 1, 4, 1, 3, 1}, /* 100 */ + {3, 1, 1, 1, 4, 1}, + {4, 1, 1, 1, 3, 1}, + {2, 1, 1, 4, 1, 2}, + {2, 1, 1, 2, 1, 4}, + {2, 1, 1, 2, 3, 2}, /* 105 */ + {2, 3, 3, 1, 1, 1} + }; + + + Code128Reader::Code128Reader(){ + } + + int* Code128Reader::findStartPattern(Ref row){ + int width = row->getSize(); + int rowOffset = 0; + while (rowOffset < width) { + if (row->get(rowOffset)) { + break; + } + rowOffset++; + } + + int counterPosition = 0; + int counters[countersLength] = {0,0,0,0,0,0}; + int patternStart = rowOffset; + bool isWhite = false; + int patternLength = sizeof(counters) / sizeof(int); + + for (int i = rowOffset; i < width; i++) { + bool pixel = row->get(i); + if (pixel ^ isWhite) { + counters[counterPosition]++; + } else { + if (counterPosition == patternLength - 1) { + unsigned int bestVariance = MAX_AVG_VARIANCE; + int bestMatch = -1; + for (int startCode = CODE_START_A; startCode <= CODE_START_C; startCode++) { + unsigned int variance = patternMatchVariance(counters, sizeof(counters) / sizeof(int), + CODE_PATTERNS[startCode], MAX_INDIVIDUAL_VARIANCE); + if (variance < bestVariance) { + bestVariance = variance; + bestMatch = startCode; + } + } + if (bestMatch >= 0) { + // Look for whitespace before start pattern, >= 50% of width of start pattern + if (row->isRange(std::max(0, patternStart - (i - patternStart) / 2), patternStart, + false)) { + int* resultValue = new int[3]; + resultValue[0] = patternStart; + resultValue[1] = i; + resultValue[2] = bestMatch; + return resultValue; + } + } + patternStart += counters[0] + counters[1]; + for (int y = 2; y < patternLength; y++) { + counters[y - 2] = counters[y]; + } + counters[patternLength - 2] = 0; + counters[patternLength - 1] = 0; + counterPosition--; + } else { + counterPosition++; + } + counters[counterPosition] = 1; + isWhite = !isWhite; + } + } + throw ReaderException(""); + } + + int Code128Reader::decodeCode(Ref row, int counters[], int countersCount, + int rowOffset) { + if (!recordPattern(row, rowOffset, counters, countersCount)) { + throw ReaderException(""); + } + unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept + int bestMatch = -1; + for (int d = 0; d < CODE_PATTERNS_LENGTH; d++) { + int pattern[countersLength]; + + for(int ind = 0; ind< countersLength; ind++){ + pattern[ind] = CODE_PATTERNS[d][ind]; + } +// memcpy(pattern, CODE_PATTERNS[d], countersLength); + unsigned int variance = patternMatchVariance(counters, countersCount, pattern, + MAX_INDIVIDUAL_VARIANCE); + if (variance < bestVariance) { + bestVariance = variance; + bestMatch = d; + } + } + // TODO We're overlooking the fact that the STOP pattern has 7 values, not 6. + if (bestMatch >= 0) { + return bestMatch; + } else { + throw ReaderException(""); + } + } + + Ref Code128Reader::decodeRow(int rowNumber, Ref row) { + int* startPatternInfo = NULL; + try { + startPatternInfo = findStartPattern(row); + int startCode = startPatternInfo[2]; + int codeSet; + switch (startCode) { + case CODE_START_A: + codeSet = CODE_CODE_A; + break; + case CODE_START_B: + codeSet = CODE_CODE_B; + break; + case CODE_START_C: + codeSet = CODE_CODE_C; + break; + default: + throw ReaderException(""); + } + + bool done = false; + bool isNextShifted = false; + + std::string tmpResultString; + std::stringstream tmpResultSStr; // used if its Code 128C + + int lastStart = startPatternInfo[0]; + int nextStart = startPatternInfo[1]; + int counters[countersLength] = {0,0,0,0,0,0}; + + int lastCode = 0; + int code = 0; + int checksumTotal = startCode; + int multiplier = 0; + bool lastCharacterWasPrintable = true; + + while (!done) { + bool unshift = isNextShifted; + isNextShifted = false; + + // Save off last code + lastCode = code; + + // Decode another code from image + try { + code = decodeCode(row, counters, sizeof(counters)/sizeof(int), nextStart); + } catch (ReaderException const& re) { + throw re; + } + + // Remember whether the last code was printable or not (excluding CODE_STOP) + if (code != CODE_STOP) { + lastCharacterWasPrintable = true; + } + + // Add to checksum computation (if not CODE_STOP of course) + if (code != CODE_STOP) { + multiplier++; + checksumTotal += multiplier * code; + } + + // Advance to where the next code will to start + lastStart = nextStart; + int _countersLength = sizeof(counters) / sizeof(int); + for (int i = 0; i < _countersLength; i++) { + nextStart += counters[i]; + } + + // Take care of illegal start codes + switch (code) { + case CODE_START_A: + case CODE_START_B: + case CODE_START_C: + throw ReaderException(""); + } + + switch (codeSet) { + + case CODE_CODE_A: + if (code < 64) { + tmpResultString.append(1, (char) (' ' + code)); + } else if (code < 96) { + tmpResultString.append(1, (char) (code - 64)); + } else { + // Don't let CODE_STOP, which always appears, affect whether whether we think the + // last code was printable or not. + if (code != CODE_STOP) { + lastCharacterWasPrintable = false; + } + switch (code) { + case CODE_FNC_1: + case CODE_FNC_2: + case CODE_FNC_3: + case CODE_FNC_4_A: + // do nothing? + break; + case CODE_SHIFT: + isNextShifted = true; + codeSet = CODE_CODE_B; + break; + case CODE_CODE_B: + codeSet = CODE_CODE_B; + break; + case CODE_CODE_C: + codeSet = CODE_CODE_C; + break; + case CODE_STOP: + done = true; + break; + } + } + break; + case CODE_CODE_B: + if (code < 96) { + tmpResultString.append(1, (char) (' ' + code)); + } else { + if (code != CODE_STOP) { + lastCharacterWasPrintable = false; + } + switch (code) { + case CODE_FNC_1: + case CODE_FNC_2: + case CODE_FNC_3: + case CODE_FNC_4_B: + // do nothing? + break; + case CODE_SHIFT: + isNextShifted = true; + codeSet = CODE_CODE_C; + break; + case CODE_CODE_A: + codeSet = CODE_CODE_A; + break; + case CODE_CODE_C: + codeSet = CODE_CODE_C; + break; + case CODE_STOP: + done = true; + break; + } + } + break; + case CODE_CODE_C: + tmpResultSStr.str(std::string()); + // the code read in this case is the number encoded directly + if (code < 100) { + if (code < 10) { + tmpResultSStr << '0'; + } + tmpResultSStr << code; + tmpResultString.append(tmpResultSStr.str()); + } else { + if (code != CODE_STOP) { + lastCharacterWasPrintable = false; + } + switch (code) { + case CODE_FNC_1: + // do nothing? + break; + case CODE_CODE_A: + codeSet = CODE_CODE_A; + break; + case CODE_CODE_B: + codeSet = CODE_CODE_B; + break; + case CODE_STOP: + done = true; + break; + } + } + break; + } + + // Unshift back to another code set if we were shifted + if (unshift) { + switch (codeSet) { + case CODE_CODE_A: + codeSet = CODE_CODE_C; + break; + case CODE_CODE_B: + codeSet = CODE_CODE_A; + break; + case CODE_CODE_C: + codeSet = CODE_CODE_B; + break; + } + } + + } + + // Check for ample whitespace following pattern, but, to do this we first need to remember that + // we fudged decoding CODE_STOP since it actually has 7 bars, not 6. There is a black bar left + // to read off. Would be slightly better to properly read. Here we just skip it: + int width = row->getSize(); + while (nextStart < width && row->get(nextStart)) { + nextStart++; + } + if (!row->isRange(nextStart, + std::min(width, nextStart + (nextStart - lastStart) / 2), + false)) { + throw ReaderException(""); + } + + // Pull out from sum the value of the penultimate check code + checksumTotal -= multiplier * lastCode; + // lastCode is the checksum then: + if (checksumTotal % 103 != lastCode) { + throw ReaderException(""); + } + + // Need to pull out the check digits from string + int resultLength = tmpResultString.length(); + // Only bother if the result had at least one character, and if the checksum digit happened to + // be a printable character. If it was just interpreted as a control code, nothing to remove. + if (resultLength > 0 && lastCharacterWasPrintable) { + if (codeSet == CODE_CODE_C) { + tmpResultString.erase(resultLength - 2, resultLength); + } else { + tmpResultString.erase(resultLength - 1, resultLength); + } + } + + Ref resultString(new String(tmpResultString)); + if (tmpResultString.length() == 0) { + // Almost surely a false positive + throw ReaderException(""); + } + + float left = (float) (startPatternInfo[1] + startPatternInfo[0]) / 2.0f; + float right = (float) (nextStart + lastStart) / 2.0f; + + std::vector< Ref > resultPoints(2); + Ref resultPoint1(new OneDResultPoint(left, (float) rowNumber)); + Ref resultPoint2(new OneDResultPoint(right, (float) rowNumber)); + resultPoints[0] = resultPoint1; + resultPoints[1] = resultPoint2; + + delete [] startPatternInfo; + ArrayRef resultBytes(1); + return Ref(new Result(resultString, resultBytes, resultPoints, + BarcodeFormat_CODE_128)); + } catch (ReaderException const& re) { + delete [] startPatternInfo; + return Ref(); + } + } + + void Code128Reader::append(char* s, char c){ + int len = strlen(s); + s[len] = c; + s[len + 1] = '\0'; + } + + Code128Reader::~Code128Reader(){ + } + } +} diff --git a/symbian/QZXing/source/zxing/oned/Code128Reader.h b/symbian/QZXing/source/zxing/oned/Code128Reader.h index b0bf5d103..625971793 100644 --- a/symbian/QZXing/source/zxing/oned/Code128Reader.h +++ b/symbian/QZXing/source/zxing/oned/Code128Reader.h @@ -1,64 +1,60 @@ -#ifndef __CODE_128_READER_H__ -#define __CODE_128_READER_H__ -/* - * Code128Reader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { - namespace oned { - class Code128Reader : public OneDReader { - - private: - //static const unsigned int MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.25f); - enum {MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.25f)}; - //static const int MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.7f); - enum {MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.7f)}; - static const int CODE_SHIFT = 98; - - static const int CODE_CODE_C = 99; - static const int CODE_CODE_B = 100; - static const int CODE_CODE_A = 101; - - static const int CODE_FNC_1 = 102; - static const int CODE_FNC_2 = 97; - static const int CODE_FNC_3 = 96; - static const int CODE_FNC_4_A = 101; - static const int CODE_FNC_4_B = 100; - - static const int CODE_START_A = 103; - static const int CODE_START_B = 104; - static const int CODE_START_C = 105; - static const int CODE_STOP = 106; - - static int* findStartPattern(Ref row); - static int decodeCode(Ref row, int counters[], int countersCount, int rowOffset); - - void append(char* s, char c); - public: - Ref decodeRow(int rowNumber, Ref row); - Code128Reader(); - ~Code128Reader(); - }; - } -} - -#endif +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __CODE_128_READER_H__ +#define __CODE_128_READER_H__ +/* + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { + namespace oned { + class Code128Reader : public OneDReader { + + private: + enum {MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 250/1000)}; + enum {MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 700/1000)}; + static const int CODE_SHIFT = 98; + + static const int CODE_CODE_C = 99; + static const int CODE_CODE_B = 100; + static const int CODE_CODE_A = 101; + + static const int CODE_FNC_1 = 102; + static const int CODE_FNC_2 = 97; + static const int CODE_FNC_3 = 96; + static const int CODE_FNC_4_A = 101; + static const int CODE_FNC_4_B = 100; + + static const int CODE_START_A = 103; + static const int CODE_START_B = 104; + static const int CODE_START_C = 105; + static const int CODE_STOP = 106; + + static int* findStartPattern(Ref row); + static int decodeCode(Ref row, int counters[], int countersCount, int rowOffset); + + void append(char* s, char c); + public: + Ref decodeRow(int rowNumber, Ref row); + Code128Reader(); + ~Code128Reader(); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/oned/Code39Reader.cpp b/symbian/QZXing/source/zxing/oned/Code39Reader.cpp index 237848e47..b55dda1a9 100644 --- a/symbian/QZXing/source/zxing/oned/Code39Reader.cpp +++ b/symbian/QZXing/source/zxing/oned/Code39Reader.cpp @@ -1,358 +1,348 @@ -/* - * Code39Reader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Code39Reader.h" -#include -#include -#include -#include -#include - -namespace zxing { -namespace oned { - - static const char* ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%"; - - - /** - * These represent the encodings of characters, as patterns of wide and narrow - * bars. - * The 9 least-significant bits of each int correspond to the pattern of wide - * and narrow, with 1s representing "wide" and 0s representing narrow. - */ - const int CHARACTER_ENCODINGS_LEN = 44; - static int CHARACTER_ENCODINGS[CHARACTER_ENCODINGS_LEN] = { - 0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124, 0x064, // 0-9 - 0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C, 0x04C, 0x01C, // A-J - 0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007, 0x106, 0x046, 0x016, // K-T - 0x181, 0x0C1, 0x1C0, 0x091, 0x190, 0x0D0, 0x085, 0x184, 0x0C4, 0x094, // U-* - 0x0A8, 0x0A2, 0x08A, 0x02A // $-% - }; - - static int ASTERISK_ENCODING = 0x094; - static const char* ALPHABET_STRING = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%"; - - - /** - * Creates a reader that assumes all encoded data is data, and does not treat - * the final character as a check digit. It will not decoded "extended - * Code 39" sequences. - */ - Code39Reader::Code39Reader() : alphabet_string(ALPHABET_STRING), - usingCheckDigit(false), - extendedMode(false) { - } - - /** - * Creates a reader that can be configured to check the last character as a - * check digit. It will not decoded "extended Code 39" sequences. - * - * @param usingCheckDigit if true, treat the last data character as a check - * digit, not data, and verify that the checksum passes. - */ - Code39Reader::Code39Reader(bool usingCheckDigit_) : - alphabet_string(ALPHABET_STRING), - usingCheckDigit(usingCheckDigit_), - extendedMode(false) { - } - - - Code39Reader::Code39Reader(bool usingCheckDigit_, bool extendedMode_) : - alphabet_string(ALPHABET_STRING), - usingCheckDigit(usingCheckDigit_), - extendedMode(extendedMode_) { - } - - Ref Code39Reader::decodeRow(int rowNumber, Ref row) { - int* start = NULL; - try { - start = findAsteriskPattern(row); - int nextStart = start[1]; - int end = row->getSize(); - - // Read off white space - while (nextStart < end && !row->get(nextStart)) { - nextStart++; - } - - std::string tmpResultString; - - const int countersLen = 9; - int counters[countersLen]; - for (int i = 0; i < countersLen; i++) { - counters[i] = 0; - } - char decodedChar; - int lastStart; - do { - if (!recordPattern(row, nextStart, counters, countersLen)) { - throw ReaderException(""); - } - int pattern = toNarrowWidePattern(counters, countersLen); - if (pattern < 0) { - throw ReaderException("pattern < 0"); - } - decodedChar = patternToChar(pattern); - tmpResultString.append(1, decodedChar); - lastStart = nextStart; - for (int i = 0; i < countersLen; i++) { - nextStart += counters[i]; - } - // Read off white space - while (nextStart < end && !row->get(nextStart)) { - nextStart++; - } - } while (decodedChar != '*'); - tmpResultString.erase(tmpResultString.length()-1, 1);// remove asterisk - - // Look for whitespace after pattern: - int lastPatternSize = 0; - for (int i = 0; i < countersLen; i++) { - lastPatternSize += counters[i]; - } - int whiteSpaceAfterEnd = nextStart - lastStart - lastPatternSize; - // If 50% of last pattern size, following last pattern, is not whitespace, - // fail (but if it's whitespace to the very end of the image, that's OK) - if (nextStart != end && whiteSpaceAfterEnd / 2 < lastPatternSize) { - throw ReaderException("too short end white space"); - } - - if (usingCheckDigit) { - int max = tmpResultString.length() - 1; - unsigned int total = 0; - for (int i = 0; i < max; i++) { - total += alphabet_string.find_first_of(tmpResultString[i], 0); - } - if (total % 43 != alphabet_string.find_first_of(tmpResultString[max], 0)) { - throw ReaderException(""); - } - tmpResultString.erase(max, 1); - } - - Ref resultString(new String(tmpResultString)); - if (extendedMode) { - resultString = decodeExtended(tmpResultString); - } - - if (tmpResultString.length() == 0) { - // Almost surely a false positive - throw ReaderException(""); - } - - float left = (float) (start[1] + start[0]) / 2.0f; - float right = (float) (nextStart + lastStart) / 2.0f; - - std::vector< Ref > resultPoints(2); - Ref resultPoint1( - new OneDResultPoint(left, (float) rowNumber)); - Ref resultPoint2( - new OneDResultPoint(right, (float) rowNumber)); - resultPoints[0] = resultPoint1; - resultPoints[1] = resultPoint2; - - ArrayRef resultBytes(1); - - Ref res(new Result( - resultString, resultBytes, resultPoints, BarcodeFormat_CODE_39)); - - delete [] start; - return res; - } catch (ReaderException const& re) { - delete [] start; - return Ref(); - } - } - - int* Code39Reader::findAsteriskPattern(Ref row){ - int width = row->getSize(); - int rowOffset = 0; - while (rowOffset < width) { - if (row->get(rowOffset)) { - break; - } - rowOffset++; - } - - int counterPosition = 0; - const int countersLen = 9; - int counters[countersLen]; - for (int i = 0; i < countersLen; i++) { - counters[i] = 0; - } - int patternStart = rowOffset; - bool isWhite = false; - int patternLength = countersLen; - - for (int i = rowOffset; i < width; i++) { - bool pixel = row->get(i); - if (pixel ^ isWhite) { - counters[counterPosition]++; - } else { - if (counterPosition == patternLength - 1) { - if (toNarrowWidePattern(counters, countersLen) == ASTERISK_ENCODING) { - // Look for whitespace before start pattern, >= 50% of width of - // start pattern. - long double longPatternOffset = 0; -#ifndef NOFMAXL - longPatternOffset = fmaxl(0, patternStart - (i - patternStart) / 2); -#else - longPatternOffset = fmax(0, patternStart - (i - patternStart) / 2); -#endif - - - if (row->isRange(longPatternOffset, patternStart, false)) { - int* resultValue = new int[2]; - resultValue[0] = patternStart; - resultValue[1] = i; - return resultValue; - } - } - patternStart += counters[0] + counters[1]; - for (int y = 2; y < patternLength; y++) { - counters[y - 2] = counters[y]; - } - counters[patternLength - 2] = 0; - counters[patternLength - 1] = 0; - counterPosition--; - } else { - counterPosition++; - } - counters[counterPosition] = 1; - isWhite = !isWhite; - } - } - throw ReaderException(""); - } - - // For efficiency, returns -1 on failure. Not throwing here saved as many as - // 700 exceptions per image when using some of our blackbox images. - int Code39Reader::toNarrowWidePattern(int counters[], int countersLen){ - int numCounters = countersLen; - int maxNarrowCounter = 0; - int wideCounters; - do { - int minCounter = INT_MAX; - for (int i = 0; i < numCounters; i++) { - int counter = counters[i]; - if (counter < minCounter && counter > maxNarrowCounter) { - minCounter = counter; - } - } - maxNarrowCounter = minCounter; - wideCounters = 0; - int totalWideCountersWidth = 0; - int pattern = 0; - for (int i = 0; i < numCounters; i++) { - int counter = counters[i]; - if (counters[i] > maxNarrowCounter) { - pattern |= 1 << (numCounters - 1 - i); - wideCounters++; - totalWideCountersWidth += counter; - } - } - if (wideCounters == 3) { - // Found 3 wide counters, but are they close enough in width? - // We can perform a cheap, conservative check to see if any individual - // counter is more than 1.5 times the average: - for (int i = 0; i < numCounters && wideCounters > 0; i++) { - int counter = counters[i]; - if (counters[i] > maxNarrowCounter) { - wideCounters--; - // totalWideCountersWidth = 3 * average, so this checks if - // counter >= 3/2 * average. - if ((counter << 1) >= totalWideCountersWidth) { - return -1; - } - } - } - return pattern; - } - } while (wideCounters > 3); - return -1; - } - - char Code39Reader::patternToChar(int pattern){ - for (int i = 0; i < CHARACTER_ENCODINGS_LEN; i++) { - if (CHARACTER_ENCODINGS[i] == pattern) { - return ALPHABET[i]; - } - } - throw ReaderException(""); - } - - Ref Code39Reader::decodeExtended(std::string encoded){ - int length = encoded.length(); - std::string tmpDecoded; - for (int i = 0; i < length; i++) { - char c = encoded[i]; - if (c == '+' || c == '$' || c == '%' || c == '/') { - char next = encoded[i + 1]; - char decodedChar = '\0'; - switch (c) { - case '+': - // +A to +Z map to a to z - if (next >= 'A' && next <= 'Z') { - decodedChar = (char) (next + 32); - } else { - throw ReaderException(""); - } - break; - case '$': - // $A to $Z map to control codes SH to SB - if (next >= 'A' && next <= 'Z') { - decodedChar = (char) (next - 64); - } else { - throw ReaderException(""); - } - break; - case '%': - // %A to %E map to control codes ESC to US - if (next >= 'A' && next <= 'E') { - decodedChar = (char) (next - 38); - } else if (next >= 'F' && next <= 'W') { - decodedChar = (char) (next - 11); - } else { - throw ReaderException(""); - } - break; - case '/': - // /A to /O map to ! to , and /Z maps to : - if (next >= 'A' && next <= 'O') { - decodedChar = (char) (next - 32); - } else if (next == 'Z') { - decodedChar = ':'; - } else { - throw ReaderException(""); - } - break; - } - tmpDecoded.append(1, decodedChar); - // bump up i again since we read two characters - i++; - } else { - tmpDecoded.append(1, c); - } - } - Ref decoded(new String(tmpDecoded)); - return decoded; - } -} // namespace oned -} // namespace zxing - +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Code39Reader.h" +#include +#include +#include +#include +#include + +namespace zxing { +namespace oned { + + static const char* ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%"; + + + /** + * These represent the encodings of characters, as patterns of wide and narrow + * bars. + * The 9 least-significant bits of each int correspond to the pattern of wide + * and narrow, with 1s representing "wide" and 0s representing narrow. + */ + const int CHARACTER_ENCODINGS_LEN = 44; + static int CHARACTER_ENCODINGS[CHARACTER_ENCODINGS_LEN] = { + 0x034, 0x121, 0x061, 0x160, 0x031, 0x130, 0x070, 0x025, 0x124, 0x064, // 0-9 + 0x109, 0x049, 0x148, 0x019, 0x118, 0x058, 0x00D, 0x10C, 0x04C, 0x01C, // A-J + 0x103, 0x043, 0x142, 0x013, 0x112, 0x052, 0x007, 0x106, 0x046, 0x016, // K-T + 0x181, 0x0C1, 0x1C0, 0x091, 0x190, 0x0D0, 0x085, 0x184, 0x0C4, 0x094, // U-* + 0x0A8, 0x0A2, 0x08A, 0x02A // $-% + }; + + static int ASTERISK_ENCODING = 0x094; + static const char* ALPHABET_STRING = + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. *$/+%"; + + + /** + * Creates a reader that assumes all encoded data is data, and does not treat + * the final character as a check digit. It will not decoded "extended + * Code 39" sequences. + */ + Code39Reader::Code39Reader() : alphabet_string(ALPHABET_STRING), + usingCheckDigit(false), + extendedMode(false) { + } + + /** + * Creates a reader that can be configured to check the last character as a + * check digit. It will not decoded "extended Code 39" sequences. + * + * @param usingCheckDigit if true, treat the last data character as a check + * digit, not data, and verify that the checksum passes. + */ + Code39Reader::Code39Reader(bool usingCheckDigit_) : + alphabet_string(ALPHABET_STRING), + usingCheckDigit(usingCheckDigit_), + extendedMode(false) { + } + + + Code39Reader::Code39Reader(bool usingCheckDigit_, bool extendedMode_) : + alphabet_string(ALPHABET_STRING), + usingCheckDigit(usingCheckDigit_), + extendedMode(extendedMode_) { + } + + Ref Code39Reader::decodeRow(int rowNumber, Ref row) { + int* start = NULL; + try { + start = findAsteriskPattern(row); + int nextStart = start[1]; + int end = row->getSize(); + + // Read off white space + while (nextStart < end && !row->get(nextStart)) { + nextStart++; + } + + std::string tmpResultString; + + const int countersLen = 9; + int counters[countersLen]; + for (int i = 0; i < countersLen; i++) { + counters[i] = 0; + } + char decodedChar; + int lastStart; + do { + if (!recordPattern(row, nextStart, counters, countersLen)) { + throw ReaderException(""); + } + int pattern = toNarrowWidePattern(counters, countersLen); + if (pattern < 0) { + throw ReaderException("pattern < 0"); + } + decodedChar = patternToChar(pattern); + tmpResultString.append(1, decodedChar); + lastStart = nextStart; + for (int i = 0; i < countersLen; i++) { + nextStart += counters[i]; + } + // Read off white space + while (nextStart < end && !row->get(nextStart)) { + nextStart++; + } + } while (decodedChar != '*'); + tmpResultString.erase(tmpResultString.length()-1, 1);// remove asterisk + + // Look for whitespace after pattern: + int lastPatternSize = 0; + for (int i = 0; i < countersLen; i++) { + lastPatternSize += counters[i]; + } + int whiteSpaceAfterEnd = nextStart - lastStart - lastPatternSize; + // If 50% of last pattern size, following last pattern, is not whitespace, + // fail (but if it's whitespace to the very end of the image, that's OK) + if (nextStart != end && whiteSpaceAfterEnd / 2 < lastPatternSize) { + throw ReaderException("too short end white space"); + } + + if (usingCheckDigit) { + int max = tmpResultString.length() - 1; + unsigned int total = 0; + for (int i = 0; i < max; i++) { + total += alphabet_string.find_first_of(tmpResultString[i], 0); + } + if (total % 43 != alphabet_string.find_first_of(tmpResultString[max], 0)) { + throw ReaderException(""); + } + tmpResultString.erase(max, 1); + } + + Ref resultString(new String(tmpResultString)); + if (extendedMode) { + resultString = decodeExtended(tmpResultString); + } + + if (tmpResultString.length() == 0) { + // Almost surely a false positive + throw ReaderException(""); + } + + float left = (float) (start[1] + start[0]) / 2.0f; + float right = (float) (nextStart + lastStart) / 2.0f; + + std::vector< Ref > resultPoints(2); + Ref resultPoint1( + new OneDResultPoint(left, (float) rowNumber)); + Ref resultPoint2( + new OneDResultPoint(right, (float) rowNumber)); + resultPoints[0] = resultPoint1; + resultPoints[1] = resultPoint2; + + ArrayRef resultBytes(1); + + Ref res(new Result( + resultString, resultBytes, resultPoints, BarcodeFormat_CODE_39)); + + delete [] start; + return res; + } catch (ReaderException const& re) { + delete [] start; + return Ref(); + } + } + + int* Code39Reader::findAsteriskPattern(Ref row){ + int width = row->getSize(); + int rowOffset = 0; + while (rowOffset < width) { + if (row->get(rowOffset)) { + break; + } + rowOffset++; + } + + int counterPosition = 0; + const int countersLen = 9; + int counters[countersLen]; + for (int i = 0; i < countersLen; i++) { + counters[i] = 0; + } + int patternStart = rowOffset; + bool isWhite = false; + int patternLength = countersLen; + + for (int i = rowOffset; i < width; i++) { + bool pixel = row->get(i); + if (pixel ^ isWhite) { + counters[counterPosition]++; + } else { + if (counterPosition == patternLength - 1) { + if (toNarrowWidePattern(counters, countersLen) == ASTERISK_ENCODING) { + // Look for whitespace before start pattern, >= 50% of width of + // start pattern. + if (row->isRange(std::max(0, patternStart - ((i - patternStart) >> 1)), patternStart, false)) { + int* resultValue = new int[2]; + resultValue[0] = patternStart; + resultValue[1] = i; + return resultValue; + } + } + patternStart += counters[0] + counters[1]; + for (int y = 2; y < patternLength; y++) { + counters[y - 2] = counters[y]; + } + counters[patternLength - 2] = 0; + counters[patternLength - 1] = 0; + counterPosition--; + } else { + counterPosition++; + } + counters[counterPosition] = 1; + isWhite = !isWhite; + } + } + throw ReaderException(""); + } + + // For efficiency, returns -1 on failure. Not throwing here saved as many as + // 700 exceptions per image when using some of our blackbox images. + int Code39Reader::toNarrowWidePattern(int counters[], int countersLen){ + int numCounters = countersLen; + int maxNarrowCounter = 0; + int wideCounters; + do { + int minCounter = INT_MAX; + for (int i = 0; i < numCounters; i++) { + int counter = counters[i]; + if (counter < minCounter && counter > maxNarrowCounter) { + minCounter = counter; + } + } + maxNarrowCounter = minCounter; + wideCounters = 0; + int totalWideCountersWidth = 0; + int pattern = 0; + for (int i = 0; i < numCounters; i++) { + int counter = counters[i]; + if (counters[i] > maxNarrowCounter) { + pattern |= 1 << (numCounters - 1 - i); + wideCounters++; + totalWideCountersWidth += counter; + } + } + if (wideCounters == 3) { + // Found 3 wide counters, but are they close enough in width? + // We can perform a cheap, conservative check to see if any individual + // counter is more than 1.5 times the average: + for (int i = 0; i < numCounters && wideCounters > 0; i++) { + int counter = counters[i]; + if (counters[i] > maxNarrowCounter) { + wideCounters--; + // totalWideCountersWidth = 3 * average, so this checks if + // counter >= 3/2 * average. + if ((counter << 1) >= totalWideCountersWidth) { + return -1; + } + } + } + return pattern; + } + } while (wideCounters > 3); + return -1; + } + + char Code39Reader::patternToChar(int pattern){ + for (int i = 0; i < CHARACTER_ENCODINGS_LEN; i++) { + if (CHARACTER_ENCODINGS[i] == pattern) { + return ALPHABET[i]; + } + } + throw ReaderException(""); + } + + Ref Code39Reader::decodeExtended(std::string encoded){ + int length = encoded.length(); + std::string tmpDecoded; + for (int i = 0; i < length; i++) { + char c = encoded[i]; + if (c == '+' || c == '$' || c == '%' || c == '/') { + char next = encoded[i + 1]; + char decodedChar = '\0'; + switch (c) { + case '+': + // +A to +Z map to a to z + if (next >= 'A' && next <= 'Z') { + decodedChar = (char) (next + 32); + } else { + throw ReaderException(""); + } + break; + case '$': + // $A to $Z map to control codes SH to SB + if (next >= 'A' && next <= 'Z') { + decodedChar = (char) (next - 64); + } else { + throw ReaderException(""); + } + break; + case '%': + // %A to %E map to control codes ESC to US + if (next >= 'A' && next <= 'E') { + decodedChar = (char) (next - 38); + } else if (next >= 'F' && next <= 'W') { + decodedChar = (char) (next - 11); + } else { + throw ReaderException(""); + } + break; + case '/': + // /A to /O map to ! to , and /Z maps to : + if (next >= 'A' && next <= 'O') { + decodedChar = (char) (next - 32); + } else if (next == 'Z') { + decodedChar = ':'; + } else { + throw ReaderException(""); + } + break; + } + tmpDecoded.append(1, decodedChar); + // bump up i again since we read two characters + i++; + } else { + tmpDecoded.append(1, c); + } + } + Ref decoded(new String(tmpDecoded)); + return decoded; + } +} // namespace oned +} // namespace zxing + diff --git a/symbian/QZXing/source/zxing/oned/Code39Reader.h b/symbian/QZXing/source/zxing/oned/Code39Reader.h index b306008e0..cc6913717 100644 --- a/symbian/QZXing/source/zxing/oned/Code39Reader.h +++ b/symbian/QZXing/source/zxing/oned/Code39Reader.h @@ -1,58 +1,58 @@ -#ifndef __CODE_39_READER_H__ -#define __CODE_39_READER_H__ -/* - * Code39Reader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { - namespace oned { - - /** - *

Decodes Code 39 barcodes. This does not support "Full ASCII Code 39" yet.

- * Ported form Java (author Sean Owen) - * @author Lukasz Warchol - */ - class Code39Reader : public OneDReader { - - private: - std::string alphabet_string; - - bool usingCheckDigit; - bool extendedMode; - - static int* findAsteriskPattern(Ref row); //throws ReaderException - static int toNarrowWidePattern(int counters[], int countersLen); - static char patternToChar(int pattern); //throws ReaderException - static Ref decodeExtended(std::string encoded); //throws ReaderException - - void append(char* s, char c); - public: - Code39Reader(); - Code39Reader(bool usingCheckDigit_); - Code39Reader(bool usingCheckDigit_, bool extendedMode_); - - Ref decodeRow(int rowNumber, Ref row); - }; - } -} - -#endif +#ifndef __CODE_39_READER_H__ +#define __CODE_39_READER_H__ +/* + * Code39Reader.h + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { + namespace oned { + + /** + *

Decodes Code 39 barcodes. This does not support "Full ASCII Code 39" yet.

+ * Ported form Java (author Sean Owen) + * @author Lukasz Warchol + */ + class Code39Reader : public OneDReader { + + private: + std::string alphabet_string; + + bool usingCheckDigit; + bool extendedMode; + + static int* findAsteriskPattern(Ref row); //throws ReaderException + static int toNarrowWidePattern(int counters[], int countersLen); + static char patternToChar(int pattern); //throws ReaderException + static Ref decodeExtended(std::string encoded); //throws ReaderException + + void append(char* s, char c); + public: + Code39Reader(); + Code39Reader(bool usingCheckDigit_); + Code39Reader(bool usingCheckDigit_, bool extendedMode_); + + Ref decodeRow(int rowNumber, Ref row); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/oned/EAN13Reader.cpp b/symbian/QZXing/source/zxing/oned/EAN13Reader.cpp index c541ec649..0e1be9a91 100644 --- a/symbian/QZXing/source/zxing/oned/EAN13Reader.cpp +++ b/symbian/QZXing/source/zxing/oned/EAN13Reader.cpp @@ -1,95 +1,99 @@ -/* - * EAN13Reader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "EAN13Reader.h" -#include - -namespace zxing { - namespace oned { - - static const int FIRST_DIGIT_ENCODINGS[10] = { - 0x00, 0x0B, 0x0D, 0xE, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A - }; - - EAN13Reader::EAN13Reader() { } - - int EAN13Reader::decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, - std::string& resultString) { - const int countersLen = 4; - int counters[countersLen] = { 0, 0, 0, 0 }; - - int end = row->getSize(); - int rowOffset = startGuardEnd; - int lgPatternFound = 0; - - for (int x = 0; x < 6 && rowOffset < end; x++) { - int bestMatch = decodeDigit(row, counters, countersLen, rowOffset, - UPC_EAN_PATTERNS_L_AND_G_PATTERNS); - if (bestMatch < 0) { - return -1; - } - resultString.append(1, (char) ('0' + bestMatch % 10)); - for (int i = 0; i < countersLen; i++) { - rowOffset += counters[i]; - } - if (bestMatch >= 10) { - lgPatternFound |= 1 << (5 - x); - } - } - - if (!determineFirstDigit(resultString, lgPatternFound)) { - return -1; - } - - int middleRangeStart; - int middleRangeEnd; - if (findGuardPattern(row, rowOffset, true, (int*)getMIDDLE_PATTERN(), - getMIDDLE_PATTERN_LEN(), &middleRangeStart, &middleRangeEnd)) { - rowOffset = middleRangeEnd; - for (int x = 0; x < 6 && rowOffset < end; x++) { - int bestMatch = decodeDigit(row, counters, countersLen, rowOffset, - UPC_EAN_PATTERNS_L_PATTERNS); - if (bestMatch < 0) { - return -1; - } - resultString.append(1, (char) ('0' + bestMatch)); - for (int i = 0; i < countersLen; i++) { - rowOffset += counters[i]; - } - } - return rowOffset; - } - return -1; - } - - bool EAN13Reader::determineFirstDigit(std::string& resultString, int lgPatternFound) { - for (int d = 0; d < 10; d++) { - if (lgPatternFound == FIRST_DIGIT_ENCODINGS[d]) { - resultString.insert((size_t)0, (size_t)1, (char) ('0' + d)); - return true; - } - } - return false; - } - - BarcodeFormat EAN13Reader::getBarcodeFormat(){ - return BarcodeFormat_EAN_13; - } - } -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "EAN13Reader.h" +#include +#include + +namespace zxing { +namespace oned { + +static const int FIRST_DIGIT_ENCODINGS[10] = { + 0x00, 0x0B, 0x0D, 0xE, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A +}; + +EAN13Reader::EAN13Reader() { } + +int EAN13Reader::decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, + std::string& resultString) { + (void)startGuardBegin; + const int countersLen = 4; + int counters[countersLen] = { 0, 0, 0, 0 }; + + int end = row->getSize(); + int rowOffset = startGuardEnd; + int lgPatternFound = 0; + + for (int x = 0; x < 6 && rowOffset < end; x++) { + int bestMatch = decodeDigit(row, counters, countersLen, rowOffset, + UPC_EAN_PATTERNS_L_AND_G_PATTERNS); + if (bestMatch < 0) { + return -1; + } + resultString.append(1, (char) ('0' + bestMatch % 10)); + for (int i = 0; i < countersLen; i++) { + rowOffset += counters[i]; + } + if (bestMatch >= 10) { + lgPatternFound |= 1 << (5 - x); + } + } + + if (!determineFirstDigit(resultString, lgPatternFound)) { + return -1; + } + + int middleRangeStart; + int middleRangeEnd; + if (findGuardPattern(row, rowOffset, true, (int*)getMIDDLE_PATTERN(), + getMIDDLE_PATTERN_LEN(), &middleRangeStart, &middleRangeEnd)) { + rowOffset = middleRangeEnd; + for (int x = 0; x < 6 && rowOffset < end; x++) { + int bestMatch = decodeDigit(row, counters, countersLen, rowOffset, + UPC_EAN_PATTERNS_L_PATTERNS); + if (bestMatch < 0) { + return -1; + } + resultString.append(1, (char) ('0' + bestMatch)); + for (int i = 0; i < countersLen; i++) { + rowOffset += counters[i]; + } + } + return rowOffset; + } + return -1; +} + +bool EAN13Reader::determineFirstDigit(std::string& resultString, int lgPatternFound) { + for (int d = 0; d < 10; d++) { + if (lgPatternFound == FIRST_DIGIT_ENCODINGS[d]) { +#if defined(Q_OS_SYMBIAN) + resultString.insert((char*)0, 1, (char) ('0' + d)); +#else + resultString.insert(/*(char*)*/0, 1, (char) ('0' + d)); +#endif + return true; + } + } + return false; +} + +BarcodeFormat EAN13Reader::getBarcodeFormat(){ + return BarcodeFormat_EAN_13; +} +} +} diff --git a/symbian/QZXing/source/zxing/oned/EAN13Reader.h b/symbian/QZXing/source/zxing/oned/EAN13Reader.h index 4ba4e0b71..e53320cd1 100644 --- a/symbian/QZXing/source/zxing/oned/EAN13Reader.h +++ b/symbian/QZXing/source/zxing/oned/EAN13Reader.h @@ -1,44 +1,44 @@ -#ifndef __EAN_13_READER_H__ -#define __EAN_13_READER_H__ - -/* - * EAN13Reader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - namespace oned { - class EAN13Reader : public UPCEANReader { - - private: - static bool determineFirstDigit(std::string& resultString, int lgPatternFound); - - public: - EAN13Reader(); - - int decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, - std::string& resultString); - - BarcodeFormat getBarcodeFormat(); - }; - } -} - -#endif +#ifndef __EAN_13_READER_H__ +#define __EAN_13_READER_H__ + +/* + * EAN13Reader.h + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + namespace oned { + class EAN13Reader : public UPCEANReader { + + private: + static bool determineFirstDigit(std::string& resultString, int lgPatternFound); + + public: + EAN13Reader(); + + int decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, + std::string& resultString); + + BarcodeFormat getBarcodeFormat(); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/oned/EAN8Reader.cpp b/symbian/QZXing/source/zxing/oned/EAN8Reader.cpp index 05ff5cb10..95aa7f6bd 100644 --- a/symbian/QZXing/source/zxing/oned/EAN8Reader.cpp +++ b/symbian/QZXing/source/zxing/oned/EAN8Reader.cpp @@ -1,73 +1,72 @@ -/* - * EAN8Reader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "EAN8Reader.h" -#include - -namespace zxing { - namespace oned { - - EAN8Reader::EAN8Reader(){ } - - int EAN8Reader::decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, - std::string& resultString){ - const int countersLen = 4; - int counters[countersLen] = { 0, 0, 0, 0 }; - - int end = row->getSize(); - int rowOffset = startGuardEnd; - - for (int x = 0; x < 4 && rowOffset < end; x++) { - int bestMatch = decodeDigit(row, counters, countersLen, rowOffset, - UPC_EAN_PATTERNS_L_PATTERNS); - if (bestMatch < 0) { - return -1; - } - resultString.append(1, (char) ('0' + bestMatch)); - for (int i = 0; i < countersLen; i++) { - rowOffset += counters[i]; - } - } - - int middleRangeStart; - int middleRangeEnd; - if (findGuardPattern(row, rowOffset, true, (int*)getMIDDLE_PATTERN(), - getMIDDLE_PATTERN_LEN(), &middleRangeStart, &middleRangeEnd)) { - rowOffset = middleRangeEnd; - for (int x = 0; x < 4 && rowOffset < end; x++) { - int bestMatch = decodeDigit(row, counters, countersLen, rowOffset, - UPC_EAN_PATTERNS_L_PATTERNS); - if (bestMatch < 0) { - return -1; - } - resultString.append(1, (char) ('0' + bestMatch)); - for (int i = 0; i < countersLen; i++) { - rowOffset += counters[i]; - } - } - return rowOffset; - } - return -1; - } - - BarcodeFormat EAN8Reader::getBarcodeFormat(){ - return BarcodeFormat_EAN_8; - } - } -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "EAN8Reader.h" +#include + +namespace zxing { + namespace oned { + + EAN8Reader::EAN8Reader(){ } + + int EAN8Reader::decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, + std::string& resultString){ + (void)startGuardBegin; + const int countersLen = 4; + int counters[countersLen] = { 0, 0, 0, 0 }; + + int end = row->getSize(); + int rowOffset = startGuardEnd; + + for (int x = 0; x < 4 && rowOffset < end; x++) { + int bestMatch = decodeDigit(row, counters, countersLen, rowOffset, + UPC_EAN_PATTERNS_L_PATTERNS); + if (bestMatch < 0) { + return -1; + } + resultString.append(1, (char) ('0' + bestMatch)); + for (int i = 0; i < countersLen; i++) { + rowOffset += counters[i]; + } + } + + int middleRangeStart; + int middleRangeEnd; + if (findGuardPattern(row, rowOffset, true, (int*)getMIDDLE_PATTERN(), + getMIDDLE_PATTERN_LEN(), &middleRangeStart, &middleRangeEnd)) { + rowOffset = middleRangeEnd; + for (int x = 0; x < 4 && rowOffset < end; x++) { + int bestMatch = decodeDigit(row, counters, countersLen, rowOffset, + UPC_EAN_PATTERNS_L_PATTERNS); + if (bestMatch < 0) { + return -1; + } + resultString.append(1, (char) ('0' + bestMatch)); + for (int i = 0; i < countersLen; i++) { + rowOffset += counters[i]; + } + } + return rowOffset; + } + return -1; + } + + BarcodeFormat EAN8Reader::getBarcodeFormat(){ + return BarcodeFormat_EAN_8; + } + } +} diff --git a/symbian/QZXing/source/zxing/oned/EAN8Reader.h b/symbian/QZXing/source/zxing/oned/EAN8Reader.h index 4db52fba8..478a73d8f 100644 --- a/symbian/QZXing/source/zxing/oned/EAN8Reader.h +++ b/symbian/QZXing/source/zxing/oned/EAN8Reader.h @@ -1,41 +1,41 @@ -#ifndef __EAN_8_READER_H__ -#define __EAN_8_READER_H__ - -/* - * EAN8Reader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - namespace oned { - class EAN8Reader : public UPCEANReader { - - public: - EAN8Reader(); - - int decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, - std::string& resultString); - - BarcodeFormat getBarcodeFormat(); - }; - } -} - -#endif +#ifndef __EAN_8_READER_H__ +#define __EAN_8_READER_H__ + +/* + * EAN8Reader.h + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + namespace oned { + class EAN8Reader : public UPCEANReader { + + public: + EAN8Reader(); + + int decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, + std::string& resultString); + + BarcodeFormat getBarcodeFormat(); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/oned/ITFReader.cpp b/symbian/QZXing/source/zxing/oned/ITFReader.cpp index e37bad7f2..0b92550c1 100644 --- a/symbian/QZXing/source/zxing/oned/ITFReader.cpp +++ b/symbian/QZXing/source/zxing/oned/ITFReader.cpp @@ -1,367 +1,367 @@ -/* - * ITFReader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ITFReader.h" -#include -#include -#include -#include - -namespace zxing { - namespace oned { - - static const int W = 3; // Pixel width of a wide line - static const int N = 1; // Pixed width of a narrow line - - const int DEFAULT_ALLOWED_LENGTHS_LEN = 10; - const int DEFAULT_ALLOWED_LENGTHS[DEFAULT_ALLOWED_LENGTHS_LEN] = { 44, 24, 20, 18, 16, 14, 12, 10, 8, 6 }; - - /** - * Start/end guard pattern. - * - * Note: The end pattern is reversed because the row is reversed before - * searching for the END_PATTERN - */ - static const int START_PATTERN_LEN = 4; - static const int START_PATTERN[START_PATTERN_LEN] = {N, N, N, N}; - - static const int END_PATTERN_REVERSED_LEN = 3; - static const int END_PATTERN_REVERSED[END_PATTERN_REVERSED_LEN] = {N, N, W}; - - /** - * Patterns of Wide / Narrow lines to indicate each digit - */ - static const int PATTERNS_LEN = 10; - static const int PATTERNS[PATTERNS_LEN][5] = { - {N, N, W, W, N}, // 0 - {W, N, N, N, W}, // 1 - {N, W, N, N, W}, // 2 - {W, W, N, N, N}, // 3 - {N, N, W, N, W}, // 4 - {W, N, W, N, N}, // 5 - {N, W, W, N, N}, // 6 - {N, N, N, W, W}, // 7 - {W, N, N, W, N}, // 8 - {N, W, N, W, N} // 9 - }; - - - ITFReader::ITFReader() : narrowLineWidth(-1) { - } - - - Ref ITFReader::decodeRow(int rowNumber, Ref row) { - int* startRange = 0; - int* endRange = 0; - try { - // Find out where the Middle section (payload) starts & ends - startRange = decodeStart(row); - endRange = decodeEnd(row); - - std::string tmpResult; - decodeMiddle(row, startRange[1], endRange[0], tmpResult); - - // To avoid false positives with 2D barcodes (and other patterns), make - // an assumption that the decoded string must be a known length - int length = tmpResult.length(); - bool lengthOK = false; - for (int i = 0; i < DEFAULT_ALLOWED_LENGTHS_LEN; i++) { - if (length == DEFAULT_ALLOWED_LENGTHS[i]) { - lengthOK = true; - break; - } - } - if (!lengthOK) { - throw ReaderException("not enough characters count"); - } - - Ref resultString(new String(tmpResult)); - - std::vector< Ref > resultPoints(2); - Ref resultPoint1(new OneDResultPoint(startRange[1], (float) rowNumber)); - Ref resultPoint2(new OneDResultPoint(endRange[0], (float) rowNumber)); - resultPoints[0] = resultPoint1; - resultPoints[1] = resultPoint2; - - delete [] startRange; - delete [] endRange; - ArrayRef resultBytes(1); - return Ref(new Result(resultString, resultBytes, resultPoints, BarcodeFormat_ITF)); - } catch (ReaderException const& re) { - delete [] startRange; - delete [] endRange; - return Ref(); - } - } - - /** - * @param row row of black/white values to search - * @param payloadStart offset of start pattern - * @param resultString {@link StringBuffer} to append decoded chars to - * @throws ReaderException if decoding could not complete successfully - */ - void ITFReader::decodeMiddle(Ref row, int payloadStart, int payloadEnd, - std::string& resultString) { - // Digits are interleaved in pairs - 5 black lines for one digit, and the - // 5 - // interleaved white lines for the second digit. - // Therefore, need to scan 10 lines and then - // split these into two arrays - int counterDigitPairLen = 10; - int counterDigitPair[counterDigitPairLen]; - for (int i=0; i row) { - int endStart = skipWhiteSpace(row); - int* startPattern = 0; - try { - startPattern = findGuardPattern(row, endStart, START_PATTERN, START_PATTERN_LEN); - - // Determine the width of a narrow line in pixels. We can do this by - // getting the width of the start pattern and dividing by 4 because its - // made up of 4 narrow lines. - narrowLineWidth = (startPattern[1] - startPattern[0]) >> 2; - validateQuietZone(row, startPattern[0]); - return startPattern; - } catch (ReaderException const& re) { - delete [] startPattern; - throw re; - } - } - - /** - * Identify where the end of the middle / payload section ends. - * - * @param row row of black/white values to search - * @return Array, containing index of start of 'end block' and end of 'end - * block' - * @throws ReaderException - */ - - int* ITFReader::decodeEnd(Ref row) { - // For convenience, reverse the row and then - // search from 'the start' for the end block - row->reverse(); - int* endPattern = 0; - try { - int endStart = skipWhiteSpace(row); - endPattern = findGuardPattern(row, endStart, END_PATTERN_REVERSED, END_PATTERN_REVERSED_LEN); - - // The start & end patterns must be pre/post fixed by a quiet zone. This - // zone must be at least 10 times the width of a narrow line. - // ref: http://www.barcode-1.net/i25code.html - validateQuietZone(row, endPattern[0]); - - // Now recalculate the indices of where the 'endblock' starts & stops to - // accommodate - // the reversed nature of the search - int temp = endPattern[0]; - endPattern[0] = row->getSize() - endPattern[1]; - endPattern[1] = row->getSize() - temp; - - row->reverse(); - return endPattern; - } catch (ReaderException const& re) { - delete [] endPattern; - row->reverse(); - throw re; - } - } - - /** - * The start & end patterns must be pre/post fixed by a quiet zone. This - * zone must be at least 10 times the width of a narrow line. Scan back until - * we either get to the start of the barcode or match the necessary number of - * quiet zone pixels. - * - * Note: Its assumed the row is reversed when using this method to find - * quiet zone after the end pattern. - * - * ref: http://www.barcode-1.net/i25code.html - * - * @param row bit array representing the scanned barcode. - * @param startPattern index into row of the start or end pattern. - * @throws ReaderException if the quiet zone cannot be found, a ReaderException is thrown. - */ - void ITFReader::validateQuietZone(Ref row, int startPattern) { -//#pragma mark needs some corrections -// int quietCount = narrowLineWidth * 10; // expect to find this many pixels of quiet zone -// -// for (int i = startPattern - 1; quietCount > 0 && i >= 0; i--) { -// if (row->get(i)) { -// break; -// } -// quietCount--; -// } -// if (quietCount != 0) { -// // Unable to find the necessary number of quiet zone pixels. -// throw ReaderException("Unable to find the necessary number of quiet zone pixels"); -// } - } - - /** - * Skip all whitespace until we get to the first black line. - * - * @param row row of black/white values to search - * @return index of the first black line. - * @throws ReaderException Throws exception if no black lines are found in the row - */ - int ITFReader::skipWhiteSpace(Ref row) { - int width = row->getSize(); - int endStart = 0; - while (endStart < width) { - if (row->get(endStart)) { - break; - } - endStart++; - } - if (endStart == width) { - throw ReaderException(""); - } - return endStart; - } - - /** - * @param row row of black/white values to search - * @param rowOffset position to start search - * @param pattern pattern of counts of number of black and white pixels that are - * being searched for as a pattern - * @return start/end horizontal offset of guard pattern, as an array of two - * ints - * @throws ReaderException if pattern is not found - */ - int* ITFReader::findGuardPattern(Ref row, int rowOffset, const int pattern[], - int patternLen) { - // TODO: This is very similar to implementation in UPCEANReader. Consider if they can be - // merged to a single method. - int patternLength = patternLen; - int counters[patternLength]; - for (int i=0; igetSize(); - bool isWhite = false; - - int counterPosition = 0; - int patternStart = rowOffset; - for (int x = rowOffset; x < width; x++) { - bool pixel = row->get(x); - if (pixel ^ isWhite) { - counters[counterPosition]++; - } else { - if (counterPosition == patternLength - 1) { - if (patternMatchVariance(counters, patternLength, pattern, - MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) { - int* resultValue = new int[2]; - resultValue[0] = patternStart; - resultValue[1] = x; - return resultValue; - } - patternStart += counters[0] + counters[1]; - for (int y = 2; y < patternLength; y++) { - counters[y - 2] = counters[y]; - } - counters[patternLength - 2] = 0; - counters[patternLength - 1] = 0; - counterPosition--; - } else { - counterPosition++; - } - counters[counterPosition] = 1; - isWhite = !isWhite; - } - } - throw ReaderException(""); - } - - /** - * Attempts to decode a sequence of ITF black/white lines into single - * digit. - * - * @param counters the counts of runs of observed black/white/black/... values - * @return The decoded digit - * @throws ReaderException if digit cannot be decoded - */ - int ITFReader::decodeDigit(int counters[], int countersLen){ - unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept - int bestMatch = -1; - int max = PATTERNS_LEN; - for (int i = 0; i < max; i++) { - int pattern[countersLen]; - for(int ind = 0; ind= 0) { - return bestMatch; - } else { - throw ReaderException("digit didint found"); - } - } - - ITFReader::~ITFReader(){ - } - } -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ITFReader.h" +#include +#include +#include +#include + +namespace zxing { + namespace oned { + + static const int W = 3; // Pixel width of a wide line + static const int N = 1; // Pixed width of a narrow line + + const int DEFAULT_ALLOWED_LENGTHS_LEN = 10; + const int DEFAULT_ALLOWED_LENGTHS[DEFAULT_ALLOWED_LENGTHS_LEN] = { 44, 24, 20, 18, 16, 14, 12, 10, 8, 6 }; + + /** + * Start/end guard pattern. + * + * Note: The end pattern is reversed because the row is reversed before + * searching for the END_PATTERN + */ + static const int START_PATTERN_LEN = 4; + static const int START_PATTERN[START_PATTERN_LEN] = {N, N, N, N}; + + static const int END_PATTERN_REVERSED_LEN = 3; + static const int END_PATTERN_REVERSED[END_PATTERN_REVERSED_LEN] = {N, N, W}; + + /** + * Patterns of Wide / Narrow lines to indicate each digit + */ + static const int PATTERNS_LEN = 10; + static const int PATTERNS[PATTERNS_LEN][5] = { + {N, N, W, W, N}, // 0 + {W, N, N, N, W}, // 1 + {N, W, N, N, W}, // 2 + {W, W, N, N, N}, // 3 + {N, N, W, N, W}, // 4 + {W, N, W, N, N}, // 5 + {N, W, W, N, N}, // 6 + {N, N, N, W, W}, // 7 + {W, N, N, W, N}, // 8 + {N, W, N, W, N} // 9 + }; + + + ITFReader::ITFReader() : narrowLineWidth(-1) { + } + + + Ref ITFReader::decodeRow(int rowNumber, Ref row) { + int* startRange = 0; + int* endRange = 0; + try { + // Find out where the Middle section (payload) starts & ends + startRange = decodeStart(row); + endRange = decodeEnd(row); + + std::string tmpResult; + decodeMiddle(row, startRange[1], endRange[0], tmpResult); + + // To avoid false positives with 2D barcodes (and other patterns), make + // an assumption that the decoded string must be a known length + int length = tmpResult.length(); + bool lengthOK = false; + for (int i = 0; i < DEFAULT_ALLOWED_LENGTHS_LEN; i++) { + if (length == DEFAULT_ALLOWED_LENGTHS[i]) { + lengthOK = true; + break; + } + } + if (!lengthOK) { + throw ReaderException("not enough characters count"); + } + + Ref resultString(new String(tmpResult)); + + std::vector< Ref > resultPoints(2); + Ref resultPoint1(new OneDResultPoint(startRange[1], (float) rowNumber)); + Ref resultPoint2(new OneDResultPoint(endRange[0], (float) rowNumber)); + resultPoints[0] = resultPoint1; + resultPoints[1] = resultPoint2; + + delete [] startRange; + delete [] endRange; + ArrayRef resultBytes(1); + return Ref(new Result(resultString, resultBytes, resultPoints, BarcodeFormat_ITF)); + } catch (ReaderException const& re) { + delete [] startRange; + delete [] endRange; + return Ref(); + } + } + + /** + * @param row row of black/white values to search + * @param payloadStart offset of start pattern + * @param resultString {@link StringBuffer} to append decoded chars to + * @throws ReaderException if decoding could not complete successfully + */ + void ITFReader::decodeMiddle(Ref row, int payloadStart, int payloadEnd, + std::string& resultString) { + // Digits are interleaved in pairs - 5 black lines for one digit, and the + // 5 + // interleaved white lines for the second digit. + // Therefore, need to scan 10 lines and then + // split these into two arrays + int counterDigitPairLen = 10; + int counterDigitPair[counterDigitPairLen]; + for (int i=0; i row) { + int endStart = skipWhiteSpace(row); + int* startPattern = 0; + try { + startPattern = findGuardPattern(row, endStart, START_PATTERN, START_PATTERN_LEN); + + // Determine the width of a narrow line in pixels. We can do this by + // getting the width of the start pattern and dividing by 4 because its + // made up of 4 narrow lines. + narrowLineWidth = (startPattern[1] - startPattern[0]) >> 2; + validateQuietZone(row, startPattern[0]); + return startPattern; + } catch (ReaderException const& re) { + delete [] startPattern; + throw re; + } + } + + /** + * Identify where the end of the middle / payload section ends. + * + * @param row row of black/white values to search + * @return Array, containing index of start of 'end block' and end of 'end + * block' + * @throws ReaderException + */ + + int* ITFReader::decodeEnd(Ref row) { + // For convenience, reverse the row and then + // search from 'the start' for the end block + row->reverse(); + int* endPattern = 0; + try { + int endStart = skipWhiteSpace(row); + endPattern = findGuardPattern(row, endStart, END_PATTERN_REVERSED, END_PATTERN_REVERSED_LEN); + + // The start & end patterns must be pre/post fixed by a quiet zone. This + // zone must be at least 10 times the width of a narrow line. + // ref: http://www.barcode-1.net/i25code.html + validateQuietZone(row, endPattern[0]); + + // Now recalculate the indices of where the 'endblock' starts & stops to + // accommodate + // the reversed nature of the search + int temp = endPattern[0]; + endPattern[0] = row->getSize() - endPattern[1]; + endPattern[1] = row->getSize() - temp; + + row->reverse(); + return endPattern; + } catch (ReaderException const& re) { + delete [] endPattern; + row->reverse(); + throw re; + } + } + + /** + * The start & end patterns must be pre/post fixed by a quiet zone. This + * zone must be at least 10 times the width of a narrow line. Scan back until + * we either get to the start of the barcode or match the necessary number of + * quiet zone pixels. + * + * Note: Its assumed the row is reversed when using this method to find + * quiet zone after the end pattern. + * + * ref: http://www.barcode-1.net/i25code.html + * + * @param row bit array representing the scanned barcode. + * @param startPattern index into row of the start or end pattern. + * @throws ReaderException if the quiet zone cannot be found, a ReaderException is thrown. + */ + void ITFReader::validateQuietZone(Ref row, int startPattern) { + (void)row; + (void)startPattern; +//#pragma mark needs some corrections +// int quietCount = narrowLineWidth * 10; // expect to find this many pixels of quiet zone +// +// for (int i = startPattern - 1; quietCount > 0 && i >= 0; i--) { +// if (row->get(i)) { +// break; +// } +// quietCount--; +// } +// if (quietCount != 0) { +// // Unable to find the necessary number of quiet zone pixels. +// throw ReaderException("Unable to find the necessary number of quiet zone pixels"); +// } + } + + /** + * Skip all whitespace until we get to the first black line. + * + * @param row row of black/white values to search + * @return index of the first black line. + * @throws ReaderException Throws exception if no black lines are found in the row + */ + int ITFReader::skipWhiteSpace(Ref row) { + int width = row->getSize(); + int endStart = 0; + while (endStart < width) { + if (row->get(endStart)) { + break; + } + endStart++; + } + if (endStart == width) { + throw ReaderException(""); + } + return endStart; + } + + /** + * @param row row of black/white values to search + * @param rowOffset position to start search + * @param pattern pattern of counts of number of black and white pixels that are + * being searched for as a pattern + * @return start/end horizontal offset of guard pattern, as an array of two + * ints + * @throws ReaderException if pattern is not found + */ + int* ITFReader::findGuardPattern(Ref row, int rowOffset, const int pattern[], + int patternLen) { + // TODO: This is very similar to implementation in UPCEANReader. Consider if they can be + // merged to a single method. + int patternLength = patternLen; + int counters[patternLength]; + for (int i=0; igetSize(); + bool isWhite = false; + + int counterPosition = 0; + int patternStart = rowOffset; + for (int x = rowOffset; x < width; x++) { + bool pixel = row->get(x); + if (pixel ^ isWhite) { + counters[counterPosition]++; + } else { + if (counterPosition == patternLength - 1) { + if (patternMatchVariance(counters, patternLength, pattern, + MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) { + int* resultValue = new int[2]; + resultValue[0] = patternStart; + resultValue[1] = x; + return resultValue; + } + patternStart += counters[0] + counters[1]; + for (int y = 2; y < patternLength; y++) { + counters[y - 2] = counters[y]; + } + counters[patternLength - 2] = 0; + counters[patternLength - 1] = 0; + counterPosition--; + } else { + counterPosition++; + } + counters[counterPosition] = 1; + isWhite = !isWhite; + } + } + throw ReaderException(""); + } + + /** + * Attempts to decode a sequence of ITF black/white lines into single + * digit. + * + * @param counters the counts of runs of observed black/white/black/... values + * @return The decoded digit + * @throws ReaderException if digit cannot be decoded + */ + int ITFReader::decodeDigit(int counters[], int countersLen){ + unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept + int bestMatch = -1; + int max = PATTERNS_LEN; + for (int i = 0; i < max; i++) { + int pattern[countersLen]; + for(int ind = 0; ind= 0) { + return bestMatch; + } else { + throw ReaderException("digit didint found"); + } + } + + ITFReader::~ITFReader(){ + } + } +} diff --git a/symbian/QZXing/source/zxing/oned/ITFReader.h b/symbian/QZXing/source/zxing/oned/ITFReader.h index 81ebd0bf6..ccba0c552 100644 --- a/symbian/QZXing/source/zxing/oned/ITFReader.h +++ b/symbian/QZXing/source/zxing/oned/ITFReader.h @@ -1,57 +1,53 @@ -#ifndef __ITF_READER_H__ -#define __ITF_READER_H__ - -/* - * ITFReader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { - namespace oned { - class ITFReader : public OneDReader { - - private: - //static const unsigned int MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f); - enum {MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f)}; - //static const int MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.8f); - enum {MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.8f)}; - // Stores the actual narrow line width of the image being decoded. - int narrowLineWidth; - - int* decodeStart(Ref row); //throws ReaderException - int* decodeEnd(Ref row); //throws ReaderException - static void decodeMiddle(Ref row, int payloadStart, int payloadEnd, std::string& resultString); //throws ReaderException - void validateQuietZone(Ref row, int startPattern); //throws ReaderException - static int skipWhiteSpace(Ref row); //throws ReaderException - - static int* findGuardPattern(Ref row, int rowOffset, const int pattern[], int patternLen); //throws ReaderException - static int decodeDigit(int counters[], int countersLen); //throws ReaderException - - void append(char* s, char c); - public: - Ref decodeRow(int rowNumber, Ref row); ///throws ReaderException - ITFReader(); - ~ITFReader(); - }; - } -} - -#endif +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __ITF_READER_H__ +#define __ITF_READER_H__ + +/* + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { + namespace oned { + class ITFReader : public OneDReader { + + private: + enum {MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 420/1000)}; + enum {MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 800/1000)}; + // Stores the actual narrow line width of the image being decoded. + int narrowLineWidth; + + int* decodeStart(Ref row); //throws ReaderException + int* decodeEnd(Ref row); //throws ReaderException + static void decodeMiddle(Ref row, int payloadStart, int payloadEnd, std::string& resultString); //throws ReaderException + void validateQuietZone(Ref row, int startPattern); //throws ReaderException + static int skipWhiteSpace(Ref row); //throws ReaderException + + static int* findGuardPattern(Ref row, int rowOffset, const int pattern[], int patternLen); //throws ReaderException + static int decodeDigit(int counters[], int countersLen); //throws ReaderException + + void append(char* s, char c); + public: + Ref decodeRow(int rowNumber, Ref row); ///throws ReaderException + ITFReader(); + ~ITFReader(); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/oned/MultiFormatOneDReader.cpp b/symbian/QZXing/source/zxing/oned/MultiFormatOneDReader.cpp index 01792061a..8560a8766 100644 --- a/symbian/QZXing/source/zxing/oned/MultiFormatOneDReader.cpp +++ b/symbian/QZXing/source/zxing/oned/MultiFormatOneDReader.cpp @@ -1,66 +1,66 @@ -/* - * MultiFormatOneDReader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "MultiFormatOneDReader.h" - -#include -#include -#include -#include -#include - -namespace zxing { - namespace oned { - MultiFormatOneDReader::MultiFormatOneDReader(DecodeHints hints) : readers() { - if (hints.containsFormat(BarcodeFormat_EAN_13) || - hints.containsFormat(BarcodeFormat_EAN_8) || - hints.containsFormat(BarcodeFormat_UPC_A) || - hints.containsFormat(BarcodeFormat_UPC_E)) { - readers.push_back(Ref(new MultiFormatUPCEANReader(hints))); - } - if (hints.containsFormat(BarcodeFormat_CODE_39)) { - readers.push_back(Ref(new Code39Reader())); - } - if (hints.containsFormat(BarcodeFormat_CODE_128)) { - readers.push_back(Ref(new Code128Reader())); - } - if (hints.containsFormat(BarcodeFormat_ITF)) { - readers.push_back(Ref(new ITFReader())); - } - if (readers.size() == 0) { - readers.push_back(Ref(new MultiFormatUPCEANReader(hints))); - readers.push_back(Ref(new Code39Reader())); - readers.push_back(Ref(new Code128Reader())); - readers.push_back(Ref(new ITFReader())); - } - } - - Ref MultiFormatOneDReader::decodeRow(int rowNumber, Ref row) { - int size = readers.size(); - for (int i = 0; i < size; i++) { - OneDReader* reader = readers[i]; - Ref result = reader->decodeRow(rowNumber, row); - if (!result.empty()) { - return result; - } - } - return Ref(); - } - } -} +/* + * MultiFormatOneDReader.cpp + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "MultiFormatOneDReader.h" + +#include +#include +#include +#include +#include + +namespace zxing { + namespace oned { + MultiFormatOneDReader::MultiFormatOneDReader(DecodeHints hints) : readers() { + if (hints.containsFormat(BarcodeFormat_EAN_13) || + hints.containsFormat(BarcodeFormat_EAN_8) || + hints.containsFormat(BarcodeFormat_UPC_A) || + hints.containsFormat(BarcodeFormat_UPC_E)) { + readers.push_back(Ref(new MultiFormatUPCEANReader(hints))); + } + if (hints.containsFormat(BarcodeFormat_CODE_39)) { + readers.push_back(Ref(new Code39Reader())); + } + if (hints.containsFormat(BarcodeFormat_CODE_128)) { + readers.push_back(Ref(new Code128Reader())); + } + if (hints.containsFormat(BarcodeFormat_ITF)) { + readers.push_back(Ref(new ITFReader())); + } + if (readers.size() == 0) { + readers.push_back(Ref(new MultiFormatUPCEANReader(hints))); + readers.push_back(Ref(new Code39Reader())); + readers.push_back(Ref(new Code128Reader())); + readers.push_back(Ref(new ITFReader())); + } + } + + Ref MultiFormatOneDReader::decodeRow(int rowNumber, Ref row) { + int size = readers.size(); + for (int i = 0; i < size; i++) { + OneDReader* reader = readers[i]; + Ref result = reader->decodeRow(rowNumber, row); + if (!result.empty()) { + return result; + } + } + return Ref(); + } + } +} diff --git a/symbian/QZXing/source/zxing/oned/MultiFormatOneDReader.h b/symbian/QZXing/source/zxing/oned/MultiFormatOneDReader.h index c939f6619..4e8d6b287 100644 --- a/symbian/QZXing/source/zxing/oned/MultiFormatOneDReader.h +++ b/symbian/QZXing/source/zxing/oned/MultiFormatOneDReader.h @@ -1,38 +1,38 @@ -#ifndef __MULTI_FORMAT_ONED_READER_H__ -#define __MULTI_FORMAT_ONED_READER_H__ -/* - * MultiFormatOneDReader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - namespace oned { - class MultiFormatOneDReader : public OneDReader { - - private: - std::vector > readers; - public: - MultiFormatOneDReader(DecodeHints hints); - - Ref decodeRow(int rowNumber, Ref row); - }; - } -} - -#endif +#ifndef __MULTI_FORMAT_ONED_READER_H__ +#define __MULTI_FORMAT_ONED_READER_H__ +/* + * MultiFormatOneDReader.h + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + namespace oned { + class MultiFormatOneDReader : public OneDReader { + + private: + std::vector > readers; + public: + MultiFormatOneDReader(DecodeHints hints); + + Ref decodeRow(int rowNumber, Ref row); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/oned/MultiFormatUPCEANReader.cpp b/symbian/QZXing/source/zxing/oned/MultiFormatUPCEANReader.cpp index a5582f026..de420244a 100644 --- a/symbian/QZXing/source/zxing/oned/MultiFormatUPCEANReader.cpp +++ b/symbian/QZXing/source/zxing/oned/MultiFormatUPCEANReader.cpp @@ -1,87 +1,87 @@ -/* - * MultiFormatUPCEANReader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "MultiFormatUPCEANReader.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace zxing { - namespace oned { - - MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers() { - if (hints.containsFormat(BarcodeFormat_EAN_13)) { - readers.push_back(Ref(new EAN13Reader())); - } else if (hints.containsFormat(BarcodeFormat_UPC_A)) { - readers.push_back(Ref(new UPCAReader())); - } - if (hints.containsFormat(BarcodeFormat_EAN_8)) { - readers.push_back(Ref(new EAN8Reader())); - } - if (hints.containsFormat(BarcodeFormat_UPC_E)) { - readers.push_back(Ref(new UPCEReader())); - } - if (readers.size() == 0) { - readers.push_back(Ref(new EAN13Reader())); - // UPC-A is covered by EAN-13 - readers.push_back(Ref(new EAN8Reader())); - readers.push_back(Ref(new UPCEReader())); - } - } - - Ref MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref row) { - // Compute this location once and reuse it on multiple implementations - int size = readers.size(); - for (int i = 0; i < size; i++) { - Ref reader = readers[i]; - Ref result = reader->decodeRow(rowNumber, row); - if (result.empty()) { - continue; - } - - // Special case: a 12-digit code encoded in UPC-A is identical to a "0" - // followed by those 12 digits encoded as EAN-13. Each will recognize such a code, - // UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0". - // Individually these are correct and their readers will both read such a code - // and correctly call it EAN-13, or UPC-A, respectively. - // - // In this case, if we've been looking for both types, we'd like to call it - // a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read - // UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A - // result if appropriate. - if (result->getBarcodeFormat() == BarcodeFormat_EAN_13) { - const std::string& text = (result->getText())->getText(); - if (text[0] == '0') { - Ref resultString(new String(text.substr(1))); - Ref res(new Result(resultString, result->getRawBytes(), - result->getResultPoints(), BarcodeFormat_UPC_A)); - return res; - } - } - return result; - } - return Ref(); - } - } -} +/* + * MultiFormatUPCEANReader.cpp + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "MultiFormatUPCEANReader.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace zxing { + namespace oned { + + MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers() { + if (hints.containsFormat(BarcodeFormat_EAN_13)) { + readers.push_back(Ref(new EAN13Reader())); + } else if (hints.containsFormat(BarcodeFormat_UPC_A)) { + readers.push_back(Ref(new UPCAReader())); + } + if (hints.containsFormat(BarcodeFormat_EAN_8)) { + readers.push_back(Ref(new EAN8Reader())); + } + if (hints.containsFormat(BarcodeFormat_UPC_E)) { + readers.push_back(Ref(new UPCEReader())); + } + if (readers.size() == 0) { + readers.push_back(Ref(new EAN13Reader())); + // UPC-A is covered by EAN-13 + readers.push_back(Ref(new EAN8Reader())); + readers.push_back(Ref(new UPCEReader())); + } + } + + Ref MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref row) { + // Compute this location once and reuse it on multiple implementations + int size = readers.size(); + for (int i = 0; i < size; i++) { + Ref reader = readers[i]; + Ref result = reader->decodeRow(rowNumber, row); + if (result.empty()) { + continue; + } + + // Special case: a 12-digit code encoded in UPC-A is identical to a "0" + // followed by those 12 digits encoded as EAN-13. Each will recognize such a code, + // UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0". + // Individually these are correct and their readers will both read such a code + // and correctly call it EAN-13, or UPC-A, respectively. + // + // In this case, if we've been looking for both types, we'd like to call it + // a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read + // UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A + // result if appropriate. + if (result->getBarcodeFormat() == BarcodeFormat_EAN_13) { + const std::string& text = (result->getText())->getText(); + if (text[0] == '0') { + Ref resultString(new String(text.substr(1))); + Ref res(new Result(resultString, result->getRawBytes(), + result->getResultPoints(), BarcodeFormat_UPC_A)); + return res; + } + } + return result; + } + return Ref(); + } + } +} diff --git a/symbian/QZXing/source/zxing/oned/MultiFormatUPCEANReader.h b/symbian/QZXing/source/zxing/oned/MultiFormatUPCEANReader.h index 30e5c4df7..8e89ff428 100644 --- a/symbian/QZXing/source/zxing/oned/MultiFormatUPCEANReader.h +++ b/symbian/QZXing/source/zxing/oned/MultiFormatUPCEANReader.h @@ -1,38 +1,38 @@ -#ifndef __MULTI_FORMAT_UPC_EAN_READER_H__ -#define __MULTI_FORMAT_UPC_EAN_READER_H__ -/* - * MultiFormatUPCEANReader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - namespace oned { - class MultiFormatUPCEANReader : public OneDReader { - - private: - std::vector > readers; - public: - MultiFormatUPCEANReader(DecodeHints hints); - - Ref decodeRow(int rowNumber, Ref row); - }; - } -} - -#endif +#ifndef __MULTI_FORMAT_UPC_EAN_READER_H__ +#define __MULTI_FORMAT_UPC_EAN_READER_H__ +/* + * MultiFormatUPCEANReader.h + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + namespace oned { + class MultiFormatUPCEANReader : public OneDReader { + + private: + std::vector > readers; + public: + MultiFormatUPCEANReader(DecodeHints hints); + + Ref decodeRow(int rowNumber, Ref row); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/oned/OneDReader.cpp b/symbian/QZXing/source/zxing/oned/OneDReader.cpp index 8ef7a23ac..dbe73f477 100644 --- a/symbian/QZXing/source/zxing/oned/OneDReader.cpp +++ b/symbian/QZXing/source/zxing/oned/OneDReader.cpp @@ -1,207 +1,207 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * OneDReader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "OneDReader.h" -#include -#include -#include -#include - -namespace zxing { - namespace oned { - using namespace std; - - OneDReader::OneDReader() { - } - - Ref OneDReader::decode(Ref image, DecodeHints hints) { - Ref result = doDecode(image, hints); - if (result.empty() && hints.getTryHarder() && image->isRotateSupported()) { - Ref rotatedImage(image->rotateCounterClockwise()); - result = doDecode(rotatedImage, hints); - if (!result.empty()) { - /* - // Record that we found it rotated 90 degrees CCW / 270 degrees CW - Hashtable metadata = result.getResultMetadata(); - int orientation = 270; - if (metadata != null && metadata.containsKey(ResultMetadataType.ORIENTATION)) { - // But if we found it reversed in doDecode(), add in that result here: - orientation = (orientation + - ((Integer) metadata.get(ResultMetadataType.ORIENTATION)).intValue()) % 360; - } - result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(orientation)); - */ - // Update result points - std::vector >& points (result->getResultPoints()); - int height = rotatedImage->getHeight(); - for (size_t i = 0; i < points.size(); i++) { - points[i].reset(new OneDResultPoint(height - points[i]->getY() - 1, points[i]->getX())); - } - } - } - if (result.empty()) { - throw ReaderException(""); - } - return result; - } - - Ref OneDReader::doDecode(Ref image, DecodeHints hints) { - int width = image->getWidth(); - int height = image->getHeight(); - Ref row(new BitArray(width)); - int middle = height >> 1; - bool tryHarder = hints.getTryHarder(); - int rowStep = (int)fmax(1, height >> (tryHarder ? 8 : 5)); - int maxLines; - if (tryHarder) { - maxLines = height; // Look at the whole image, not just the center - } else { - maxLines = 15; // 15 rows spaced 1/32 apart is roughly the middle half of the image - } - - for (int x = 0; x < maxLines; x++) { - // Scanning from the middle out. Determine which row we're looking at next: - int rowStepsAboveOrBelow = (x + 1) >> 1; - bool isAbove = (x & 0x01) == 0; // i.e. is x even? - int rowNumber = middle + rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow); - if (rowNumber < 0 || rowNumber >= height) { - // Oops, if we run off the top or bottom, stop - break; - } - - // Estimate black point for this row and load it: - try { - row = image->getBlackRow(rowNumber, row); - } catch (ReaderException const& re) { - continue; - } catch (IllegalArgumentException const& re) { - continue; - } - - // While we have the image data in a BitArray, it's fairly cheap to reverse it in place to - // handle decoding upside down barcodes. - for (int attempt = 0; attempt < 2; attempt++) { - if (attempt == 1) { - row->reverse(); // reverse the row and continue - } - - // Look for a barcode - Ref result = decodeRow(rowNumber, row); - // We found our barcode - if (!result.empty()) { - if (attempt == 1) { - // But it was upside down, so note that - // result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(180)); - // And remember to flip the result points horizontally. - std::vector > points(result->getResultPoints()); - // if there's exactly two points (which there should be), flip the x coordinate - // if there's not exactly 2, I don't know what do do with it - if (points.size() == 2) { - Ref pointZero(new OneDResultPoint(width - points[0]->getX() - 1, - points[0]->getY())); - points[0] = pointZero; - - Ref pointOne(new OneDResultPoint(width - points[1]->getX() - 1, - points[1]->getY())); - points[1] = pointOne; - - result.reset(new Result(result->getText(), result->getRawBytes(), points, - result->getBarcodeFormat())); - } - } - return result; - } - } - } - return Ref(); - } - - unsigned int OneDReader::patternMatchVariance(int counters[], int countersSize, - const int pattern[], int maxIndividualVariance) { - int numCounters = countersSize; - unsigned int total = 0; - unsigned int patternLength = 0; - for (int i = 0; i < numCounters; i++) { - total += counters[i]; - patternLength += pattern[i]; - } - if (total < patternLength) { - // If we don't even have one pixel per unit of bar width, assume this is too small - // to reliably match, so fail: - return INT_MAX; - } - // We're going to fake floating-point math in integers. We just need to use more bits. - // Scale up patternLength so that intermediate values below like scaledCounter will have - // more "significant digits" - unsigned int unitBarWidth = (total << INTEGER_MATH_SHIFT) / patternLength; - maxIndividualVariance = (maxIndividualVariance * unitBarWidth) >> INTEGER_MATH_SHIFT; - - unsigned int totalVariance = 0; - for (int x = 0; x < numCounters; x++) { - int counter = counters[x] << INTEGER_MATH_SHIFT; - int scaledPattern = pattern[x] * unitBarWidth; - int variance = counter > scaledPattern ? counter - scaledPattern : scaledPattern - counter; - if (variance > maxIndividualVariance) { - return INT_MAX; - } - totalVariance += variance; - } - return totalVariance / total; - } - - bool OneDReader::recordPattern(Ref row, int start, int counters[], int countersCount) { - int numCounters = countersCount;//sizeof(counters) / sizeof(int); - for (int i = 0; i < numCounters; i++) { - counters[i] = 0; - } - int end = row->getSize(); - if (start >= end) { - return false; - } - bool isWhite = !row->get(start); - int counterPosition = 0; - int i = start; - while (i < end) { - bool pixel = row->get(i); - if (pixel ^ isWhite) { // that is, exactly one is true - counters[counterPosition]++; - } else { - counterPosition++; - if (counterPosition == numCounters) { - break; - } else { - counters[counterPosition] = 1; - isWhite ^= true; // isWhite = !isWhite; - } - } - i++; - } - // If we read fully the last section of pixels and filled up our counters -- or filled - // the last counter but ran off the side of the image, OK. Otherwise, a problem. - if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) { - return false; - } - return true; - } - - OneDReader::~OneDReader() { - } - } -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * OneDReader.cpp + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "OneDReader.h" +#include +#include +#include +#include + +namespace zxing { + namespace oned { + using namespace std; + + OneDReader::OneDReader() { + } + + Ref OneDReader::decode(Ref image, DecodeHints hints) { + Ref result = doDecode(image, hints); + if (result.empty() && hints.getTryHarder() && image->isRotateSupported()) { + Ref rotatedImage(image->rotateCounterClockwise()); + result = doDecode(rotatedImage, hints); + if (!result.empty()) { + /* + // Record that we found it rotated 90 degrees CCW / 270 degrees CW + Hashtable metadata = result.getResultMetadata(); + int orientation = 270; + if (metadata != null && metadata.containsKey(ResultMetadataType.ORIENTATION)) { + // But if we found it reversed in doDecode(), add in that result here: + orientation = (orientation + + ((Integer) metadata.get(ResultMetadataType.ORIENTATION)).intValue()) % 360; + } + result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(orientation)); + */ + // Update result points + std::vector >& points (result->getResultPoints()); + int height = rotatedImage->getHeight(); + for (size_t i = 0; i < points.size(); i++) { + points[i].reset(new OneDResultPoint(height - points[i]->getY() - 1, points[i]->getX())); + } + } + } + if (result.empty()) { + throw ReaderException(""); + } + return result; + } + + Ref OneDReader::doDecode(Ref image, DecodeHints hints) { + int width = image->getWidth(); + int height = image->getHeight(); + Ref row(new BitArray(width)); + int middle = height >> 1; + bool tryHarder = hints.getTryHarder(); + int rowStep = (int)fmax(1, height >> (tryHarder ? 8 : 5)); + int maxLines; + if (tryHarder) { + maxLines = height; // Look at the whole image, not just the center + } else { + maxLines = 15; // 15 rows spaced 1/32 apart is roughly the middle half of the image + } + + for (int x = 0; x < maxLines; x++) { + // Scanning from the middle out. Determine which row we're looking at next: + int rowStepsAboveOrBelow = (x + 1) >> 1; + bool isAbove = (x & 0x01) == 0; // i.e. is x even? + int rowNumber = middle + rowStep * (isAbove ? rowStepsAboveOrBelow : -rowStepsAboveOrBelow); + if (rowNumber < 0 || rowNumber >= height) { + // Oops, if we run off the top or bottom, stop + break; + } + + // Estimate black point for this row and load it: + try { + row = image->getBlackRow(rowNumber, row); + } catch (ReaderException const& re) { + continue; + } catch (IllegalArgumentException const& re) { + continue; + } + + // While we have the image data in a BitArray, it's fairly cheap to reverse it in place to + // handle decoding upside down barcodes. + for (int attempt = 0; attempt < 2; attempt++) { + if (attempt == 1) { + row->reverse(); // reverse the row and continue + } + + // Look for a barcode + Ref result = decodeRow(rowNumber, row); + // We found our barcode + if (!result.empty()) { + if (attempt == 1) { + // But it was upside down, so note that + // result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(180)); + // And remember to flip the result points horizontally. + std::vector > points(result->getResultPoints()); + // if there's exactly two points (which there should be), flip the x coordinate + // if there's not exactly 2, I don't know what do do with it + if (points.size() == 2) { + Ref pointZero(new OneDResultPoint(width - points[0]->getX() - 1, + points[0]->getY())); + points[0] = pointZero; + + Ref pointOne(new OneDResultPoint(width - points[1]->getX() - 1, + points[1]->getY())); + points[1] = pointOne; + + result.reset(new Result(result->getText(), result->getRawBytes(), points, + result->getBarcodeFormat())); + } + } + return result; + } + } + } + return Ref(); + } + + unsigned int OneDReader::patternMatchVariance(int counters[], int countersSize, + const int pattern[], int maxIndividualVariance) { + int numCounters = countersSize; + unsigned int total = 0; + unsigned int patternLength = 0; + for (int i = 0; i < numCounters; i++) { + total += counters[i]; + patternLength += pattern[i]; + } + if (total < patternLength) { + // If we don't even have one pixel per unit of bar width, assume this is too small + // to reliably match, so fail: + return INT_MAX; + } + // We're going to fake floating-point math in integers. We just need to use more bits. + // Scale up patternLength so that intermediate values below like scaledCounter will have + // more "significant digits" + unsigned int unitBarWidth = (total << INTEGER_MATH_SHIFT) / patternLength; + maxIndividualVariance = (maxIndividualVariance * unitBarWidth) >> INTEGER_MATH_SHIFT; + + unsigned int totalVariance = 0; + for (int x = 0; x < numCounters; x++) { + int counter = counters[x] << INTEGER_MATH_SHIFT; + int scaledPattern = pattern[x] * unitBarWidth; + int variance = counter > scaledPattern ? counter - scaledPattern : scaledPattern - counter; + if (variance > maxIndividualVariance) { + return INT_MAX; + } + totalVariance += variance; + } + return totalVariance / total; + } + + bool OneDReader::recordPattern(Ref row, int start, int counters[], int countersCount) { + int numCounters = countersCount;//sizeof(counters) / sizeof(int); + for (int i = 0; i < numCounters; i++) { + counters[i] = 0; + } + int end = row->getSize(); + if (start >= end) { + return false; + } + bool isWhite = !row->get(start); + int counterPosition = 0; + int i = start; + while (i < end) { + bool pixel = row->get(i); + if (pixel ^ isWhite) { // that is, exactly one is true + counters[counterPosition]++; + } else { + counterPosition++; + if (counterPosition == numCounters) { + break; + } else { + counters[counterPosition] = 1; + isWhite ^= true; // isWhite = !isWhite; + } + } + i++; + } + // If we read fully the last section of pixels and filled up our counters -- or filled + // the last counter but ran off the side of the image, OK. Otherwise, a problem. + if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) { + return false; + } + return true; + } + + OneDReader::~OneDReader() { + } + } +} diff --git a/symbian/QZXing/source/zxing/oned/OneDReader.h b/symbian/QZXing/source/zxing/oned/OneDReader.h index fdd1d023a..a93de0780 100644 --- a/symbian/QZXing/source/zxing/oned/OneDReader.h +++ b/symbian/QZXing/source/zxing/oned/OneDReader.h @@ -1,50 +1,50 @@ -#ifndef __ONED_READER_H__ -#define __ONED_READER_H__ - -/* - * OneDReader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - namespace oned { - class OneDReader : public Reader { - private: - static const int INTEGER_MATH_SHIFT = 8; - - Ref doDecode(Ref image, DecodeHints hints); - public: - static const int PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << INTEGER_MATH_SHIFT; - - OneDReader(); - virtual Ref decode(Ref image, DecodeHints hints); - - // Implementations must not throw any exceptions. If a barcode is not found on this row, - // a empty ref should be returned e.g. return Ref(); - virtual Ref decodeRow(int rowNumber, Ref row) = 0; - - static unsigned int patternMatchVariance(int counters[], int countersSize, - const int pattern[], int maxIndividualVariance); - static bool recordPattern(Ref row, int start, int counters[], int countersCount); - virtual ~OneDReader(); - }; - } -} - -#endif +#ifndef __ONED_READER_H__ +#define __ONED_READER_H__ + +/* + * OneDReader.h + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + namespace oned { + class OneDReader : public Reader { + private: + static const int INTEGER_MATH_SHIFT = 8; + + Ref doDecode(Ref image, DecodeHints hints); + public: + static const int PATTERN_MATCH_RESULT_SCALE_FACTOR = 1 << INTEGER_MATH_SHIFT; + + OneDReader(); + virtual Ref decode(Ref image, DecodeHints hints); + + // Implementations must not throw any exceptions. If a barcode is not found on this row, + // a empty ref should be returned e.g. return Ref(); + virtual Ref decodeRow(int rowNumber, Ref row) = 0; + + static unsigned int patternMatchVariance(int counters[], int countersSize, + const int pattern[], int maxIndividualVariance); + static bool recordPattern(Ref row, int start, int counters[], int countersCount); + virtual ~OneDReader(); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/oned/OneDResultPoint.cpp b/symbian/QZXing/source/zxing/oned/OneDResultPoint.cpp index bdf7d7926..bbd350455 100644 --- a/symbian/QZXing/source/zxing/oned/OneDResultPoint.cpp +++ b/symbian/QZXing/source/zxing/oned/OneDResultPoint.cpp @@ -1,28 +1,28 @@ -/* - * OneDResultPoint.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "OneDResultPoint.h" - -namespace zxing { - namespace oned { - - OneDResultPoint::OneDResultPoint(float posX, float posY) : ResultPoint(posX,posY) { - } - } -} +/* + * OneDResultPoint.cpp + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "OneDResultPoint.h" + +namespace zxing { + namespace oned { + + OneDResultPoint::OneDResultPoint(float posX, float posY) : ResultPoint(posX,posY) { + } + } +} diff --git a/symbian/QZXing/source/zxing/oned/OneDResultPoint.h b/symbian/QZXing/source/zxing/oned/OneDResultPoint.h index 825a04e08..04c7a8532 100644 --- a/symbian/QZXing/source/zxing/oned/OneDResultPoint.h +++ b/symbian/QZXing/source/zxing/oned/OneDResultPoint.h @@ -1,35 +1,35 @@ -#ifndef __ONED_RESULT_POINT_H__ -#define __ONED_RESULT_POINT_H__ -/* - * OneDResultPoint.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include - -namespace zxing { - namespace oned { - - class OneDResultPoint : public ResultPoint { - - public: - OneDResultPoint(float posX, float posY); - }; - } -} - -#endif +#ifndef __ONED_RESULT_POINT_H__ +#define __ONED_RESULT_POINT_H__ +/* + * OneDResultPoint.h + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include + +namespace zxing { + namespace oned { + + class OneDResultPoint : public ResultPoint { + + public: + OneDResultPoint(float posX, float posY); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/oned/UPCAReader.cpp b/symbian/QZXing/source/zxing/oned/UPCAReader.cpp index 1eb2b6f39..d7ae0cde8 100644 --- a/symbian/QZXing/source/zxing/oned/UPCAReader.cpp +++ b/symbian/QZXing/source/zxing/oned/UPCAReader.cpp @@ -1,65 +1,65 @@ -/* - * UPCAReader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "UPCAReader.h" -#include - -namespace zxing { - namespace oned { - UPCAReader::UPCAReader() : ean13Reader() { - } - - Ref UPCAReader::decodeRow(int rowNumber, Ref row) { - return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row)); - } - - Ref UPCAReader::decodeRow(int rowNumber, Ref row, int startGuardBegin, - int startGuardEnd) { - return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardBegin, - startGuardEnd)); - } - - Ref UPCAReader::decode(Ref image, DecodeHints hints) { - return maybeReturnResult(ean13Reader.decode(image, hints)); - } - - int UPCAReader::decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, - std::string& resultString) { - return ean13Reader.decodeMiddle(row, startGuardBegin, startGuardEnd, resultString); - } - - Ref UPCAReader::maybeReturnResult(Ref result) { - if (result.empty()) { - return result; - } - const std::string& text = (result->getText())->getText(); - if (text[0] == '0') { - Ref resultString(new String(text.substr(1))); - Ref res(new Result(resultString, result->getRawBytes(), result->getResultPoints(), - BarcodeFormat_UPC_A)); - return res; - } - return Ref(); - } - - BarcodeFormat UPCAReader::getBarcodeFormat(){ - return BarcodeFormat_UPC_A; - } - } -} +/* + * UPCAReader.cpp + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UPCAReader.h" +#include + +namespace zxing { + namespace oned { + UPCAReader::UPCAReader() : ean13Reader() { + } + + Ref UPCAReader::decodeRow(int rowNumber, Ref row) { + return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row)); + } + + Ref UPCAReader::decodeRow(int rowNumber, Ref row, int startGuardBegin, + int startGuardEnd) { + return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardBegin, + startGuardEnd)); + } + + Ref UPCAReader::decode(Ref image, DecodeHints hints) { + return maybeReturnResult(ean13Reader.decode(image, hints)); + } + + int UPCAReader::decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, + std::string& resultString) { + return ean13Reader.decodeMiddle(row, startGuardBegin, startGuardEnd, resultString); + } + + Ref UPCAReader::maybeReturnResult(Ref result) { + if (result.empty()) { + return result; + } + const std::string& text = (result->getText())->getText(); + if (text[0] == '0') { + Ref resultString(new String(text.substr(1))); + Ref res(new Result(resultString, result->getRawBytes(), result->getResultPoints(), + BarcodeFormat_UPC_A)); + return res; + } + return Ref(); + } + + BarcodeFormat UPCAReader::getBarcodeFormat(){ + return BarcodeFormat_UPC_A; + } + } +} diff --git a/symbian/QZXing/source/zxing/oned/UPCAReader.h b/symbian/QZXing/source/zxing/oned/UPCAReader.h index 7c61cf113..e4c2a17ba 100644 --- a/symbian/QZXing/source/zxing/oned/UPCAReader.h +++ b/symbian/QZXing/source/zxing/oned/UPCAReader.h @@ -1,49 +1,49 @@ -#ifndef __UPCA_READER_H__ -#define __UPCA_READER_H__ -/* - * UPCAReader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - namespace oned { - class UPCAReader : public UPCEANReader { - - private: - EAN13Reader ean13Reader; - static Ref maybeReturnResult(Ref result); - - public: - UPCAReader(); - - int decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, - std::string& resultString); - - Ref decodeRow(int rowNumber, Ref row); - Ref decodeRow(int rowNumber, Ref row, int startGuardBegin, - int startGuardEnd); - Ref decode(Ref image, DecodeHints hints); - - BarcodeFormat getBarcodeFormat(); - }; - } -} - -#endif +#ifndef __UPCA_READER_H__ +#define __UPCA_READER_H__ +/* + * UPCAReader.h + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + namespace oned { + class UPCAReader : public UPCEANReader { + + private: + EAN13Reader ean13Reader; + static Ref maybeReturnResult(Ref result); + + public: + UPCAReader(); + + int decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, + std::string& resultString); + + Ref decodeRow(int rowNumber, Ref row); + Ref decodeRow(int rowNumber, Ref row, int startGuardBegin, + int startGuardEnd); + Ref decode(Ref image, DecodeHints hints); + + BarcodeFormat getBarcodeFormat(); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/oned/UPCEANReader.cpp b/symbian/QZXing/source/zxing/oned/UPCEANReader.cpp index 962d71ae7..49cf332ea 100644 --- a/symbian/QZXing/source/zxing/oned/UPCEANReader.cpp +++ b/symbian/QZXing/source/zxing/oned/UPCEANReader.cpp @@ -1,311 +1,311 @@ -/* - * UPCEANReader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "UPCEANReader.h" -#include -#include - -namespace zxing { - namespace oned { - - /** - * Start/end guard pattern. - */ - static const int START_END_PATTERN[3] = {1, 1, 1}; - - /** - * Pattern marking the middle of a UPC/EAN pattern, separating the two halves. - */ - static const int MIDDLE_PATTERN_LEN = 5; - static const int MIDDLE_PATTERN[MIDDLE_PATTERN_LEN] = {1, 1, 1, 1, 1}; - - /** - * "Odd", or "L" patterns used to encode UPC/EAN digits. - */ - const int L_PATTERNS_LEN = 10; - const int L_PATTERNS_SUB_LEN = 4; - const int L_PATTERNS[L_PATTERNS_LEN][L_PATTERNS_SUB_LEN] = { - {3, 2, 1, 1}, // 0 - {2, 2, 2, 1}, // 1 - {2, 1, 2, 2}, // 2 - {1, 4, 1, 1}, // 3 - {1, 1, 3, 2}, // 4 - {1, 2, 3, 1}, // 5 - {1, 1, 1, 4}, // 6 - {1, 3, 1, 2}, // 7 - {1, 2, 1, 3}, // 8 - {3, 1, 1, 2} // 9 - }; - - /** - * As above but also including the "even", or "G" patterns used to encode UPC/EAN digits. - */ - const int L_AND_G_PATTERNS_LEN = 20; - const int L_AND_G_PATTERNS_SUB_LEN = 4; - const int L_AND_G_PATTERNS[L_AND_G_PATTERNS_LEN][L_AND_G_PATTERNS_SUB_LEN] = { - {3, 2, 1, 1}, // 0 - {2, 2, 2, 1}, // 1 - {2, 1, 2, 2}, // 2 - {1, 4, 1, 1}, // 3 - {1, 1, 3, 2}, // 4 - {1, 2, 3, 1}, // 5 - {1, 1, 1, 4}, // 6 - {1, 3, 1, 2}, // 7 - {1, 2, 1, 3}, // 8 - {3, 1, 1, 2}, // 9 - {1, 1, 2, 3}, // 10 reversed 0 - {1, 2, 2, 2}, // 11 reversed 1 - {2, 2, 1, 2}, // 12 reversed 2 - {1, 1, 4, 1}, // 13 reversed 3 - {2, 3, 1, 1}, // 14 reversed 4 - {1, 3, 2, 1}, // 15 reversed 5 - {4, 1, 1, 1}, // 16 reversed 6 - {2, 1, 3, 1}, // 17 reversed 7 - {3, 1, 2, 1}, // 18 reversed 8 - {2, 1, 1, 3} // 19 reversed 9 - }; - - - int UPCEANReader::getMIDDLE_PATTERN_LEN() { - return MIDDLE_PATTERN_LEN; - } - - const int* UPCEANReader::getMIDDLE_PATTERN() { - return MIDDLE_PATTERN; - } - - UPCEANReader::UPCEANReader() { - } - - - Ref UPCEANReader::decodeRow(int rowNumber, Ref row) { - int rangeStart; - int rangeEnd; - if (findStartGuardPattern(row, &rangeStart, &rangeEnd)) { - try { - return decodeRow(rowNumber, row, rangeStart, rangeEnd); - } catch (ReaderException const& re) { - } - } - return Ref(); - } - - Ref UPCEANReader::decodeRow(int rowNumber, Ref row, int startGuardBegin, - int startGuardEnd) { - std::string tmpResultString; - std::string& tmpResultStringRef = tmpResultString; - int endStart = decodeMiddle(row, startGuardBegin, startGuardEnd, tmpResultStringRef); - if (endStart < 0) { - return Ref(); - } - - int endGuardBegin; - int endGuardEnd; - if (!decodeEnd(row, endStart, &endGuardBegin, &endGuardEnd)) { - return Ref(); - } - - // Make sure there is a quiet zone at least as big as the end pattern after the barcode. - // The spec might want more whitespace, but in practice this is the maximum we can count on. - size_t quietEnd = endGuardEnd + (endGuardEnd - endGuardBegin); - if (quietEnd >= row->getSize() || !row->isRange(endGuardEnd, quietEnd, false)) { - return Ref(); - } - - if (!checkChecksum(tmpResultString)) { - return Ref(); - } - - Ref resultString(new String(tmpResultString)); - float left = (float) (startGuardBegin + startGuardEnd) / 2.0f; - float right = (float) (endGuardBegin + endGuardEnd) / 2.0f; - - std::vector< Ref > resultPoints(2); - Ref resultPoint1(new OneDResultPoint(left, (float) rowNumber)); - Ref resultPoint2(new OneDResultPoint(right, (float) rowNumber)); - resultPoints[0] = resultPoint1; - resultPoints[1] = resultPoint2; - - ArrayRef resultBytes(1); - return Ref(new Result(resultString, resultBytes, resultPoints, getBarcodeFormat())); - } - - bool UPCEANReader::findStartGuardPattern(Ref row, int* rangeStart, int* rangeEnd) { - int nextStart = 0; - while (findGuardPattern(row, nextStart, false, START_END_PATTERN, - sizeof(START_END_PATTERN) / sizeof(int), rangeStart, rangeEnd)) { - int start = *rangeStart; - nextStart = *rangeEnd; - // Make sure there is a quiet zone at least as big as the start pattern before the barcode. - // If this check would run off the left edge of the image, do not accept this barcode, - // as it is very likely to be a false positive. - int quietStart = start - (nextStart - start); - if (quietStart >= 0 && row->isRange(quietStart, start, false)) { - return true; - } - } - return false; - } - - bool UPCEANReader::findGuardPattern(Ref row, int rowOffset, bool whiteFirst, - const int pattern[], int patternLen, int* start, int* end) { - int patternLength = patternLen; - int counters[patternLength]; - int countersCount = sizeof(counters) / sizeof(int); - for (int i = 0; i < countersCount; i++) { - counters[i] = 0; - } - int width = row->getSize(); - bool isWhite = false; - while (rowOffset < width) { - isWhite = !row->get(rowOffset); - if (whiteFirst == isWhite) { - break; - } - rowOffset++; - } - - int counterPosition = 0; - int patternStart = rowOffset; - for (int x = rowOffset; x < width; x++) { - bool pixel = row->get(x); - if (pixel ^ isWhite) { - counters[counterPosition]++; - } else { - if (counterPosition == patternLength - 1) { - if (patternMatchVariance(counters, countersCount, pattern, - MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) { - *start = patternStart; - *end = x; - return true; - } - patternStart += counters[0] + counters[1]; - for (int y = 2; y < patternLength; y++) { - counters[y - 2] = counters[y]; - } - counters[patternLength - 2] = 0; - counters[patternLength - 1] = 0; - counterPosition--; - } else { - counterPosition++; - } - counters[counterPosition] = 1; - isWhite = !isWhite; - } - } - return false; - } - - bool UPCEANReader::decodeEnd(Ref row, int endStart, int* endGuardBegin, - int* endGuardEnd) { - return findGuardPattern(row, endStart, false, START_END_PATTERN, - sizeof(START_END_PATTERN) / sizeof(int), endGuardBegin, endGuardEnd); - } - - int UPCEANReader::decodeDigit(Ref row, int counters[], int countersLen, int rowOffset, - UPC_EAN_PATTERNS patternType) { - if (!recordPattern(row, rowOffset, counters, countersLen)) { - return -1; - } - unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept - int bestMatch = -1; - - int max = 0; - switch (patternType) { - case UPC_EAN_PATTERNS_L_PATTERNS: - max = L_PATTERNS_LEN; - for (int i = 0; i < max; i++) { - int pattern[countersLen]; - for(int j = 0; j< countersLen; j++){ - pattern[j] = L_PATTERNS[i][j]; - } - - unsigned int variance = patternMatchVariance(counters, countersLen, pattern, - MAX_INDIVIDUAL_VARIANCE); - if (variance < bestVariance) { - bestVariance = variance; - bestMatch = i; - } - } - break; - case UPC_EAN_PATTERNS_L_AND_G_PATTERNS: - max = L_AND_G_PATTERNS_LEN; - for (int i = 0; i < max; i++) { - int pattern[countersLen]; - for(int j = 0; j< countersLen; j++){ - pattern[j] = L_AND_G_PATTERNS[i][j]; - } - - unsigned int variance = patternMatchVariance(counters, countersLen, pattern, - MAX_INDIVIDUAL_VARIANCE); - if (variance < bestVariance) { - bestVariance = variance; - bestMatch = i; - } - } - break; - default: - break; - } - return bestMatch; - } - - /** - * @return {@link #checkStandardUPCEANChecksum(String)} - */ - bool UPCEANReader::checkChecksum(std::string s) { - return checkStandardUPCEANChecksum(s); - } - - /** - * Computes the UPC/EAN checksum on a string of digits, and reports - * whether the checksum is correct or not. - * - * @param s string of digits to check - * @return true iff string of digits passes the UPC/EAN checksum algorithm - */ - bool UPCEANReader::checkStandardUPCEANChecksum(std::string s) { - int length = s.length(); - if (length == 0) { - return false; - } - - int sum = 0; - for (int i = length - 2; i >= 0; i -= 2) { - int digit = (int) s[i] - (int) '0'; - if (digit < 0 || digit > 9) { - return false; - } - sum += digit; - } - sum *= 3; - for (int i = length - 1; i >= 0; i -= 2) { - int digit = (int) s[i] - (int) '0'; - if (digit < 0 || digit > 9) { - return false; - } - sum += digit; - } - return sum % 10 == 0; - } - - UPCEANReader::~UPCEANReader() { - } - } -} +/* + * UPCEANReader.cpp + * ZXing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UPCEANReader.h" +#include +#include + +namespace zxing { + namespace oned { + + /** + * Start/end guard pattern. + */ + static const int START_END_PATTERN[3] = {1, 1, 1}; + + /** + * Pattern marking the middle of a UPC/EAN pattern, separating the two halves. + */ + static const int MIDDLE_PATTERN_LEN = 5; + static const int MIDDLE_PATTERN[MIDDLE_PATTERN_LEN] = {1, 1, 1, 1, 1}; + + /** + * "Odd", or "L" patterns used to encode UPC/EAN digits. + */ + const int L_PATTERNS_LEN = 10; + const int L_PATTERNS_SUB_LEN = 4; + const int L_PATTERNS[L_PATTERNS_LEN][L_PATTERNS_SUB_LEN] = { + {3, 2, 1, 1}, // 0 + {2, 2, 2, 1}, // 1 + {2, 1, 2, 2}, // 2 + {1, 4, 1, 1}, // 3 + {1, 1, 3, 2}, // 4 + {1, 2, 3, 1}, // 5 + {1, 1, 1, 4}, // 6 + {1, 3, 1, 2}, // 7 + {1, 2, 1, 3}, // 8 + {3, 1, 1, 2} // 9 + }; + + /** + * As above but also including the "even", or "G" patterns used to encode UPC/EAN digits. + */ + const int L_AND_G_PATTERNS_LEN = 20; + const int L_AND_G_PATTERNS_SUB_LEN = 4; + const int L_AND_G_PATTERNS[L_AND_G_PATTERNS_LEN][L_AND_G_PATTERNS_SUB_LEN] = { + {3, 2, 1, 1}, // 0 + {2, 2, 2, 1}, // 1 + {2, 1, 2, 2}, // 2 + {1, 4, 1, 1}, // 3 + {1, 1, 3, 2}, // 4 + {1, 2, 3, 1}, // 5 + {1, 1, 1, 4}, // 6 + {1, 3, 1, 2}, // 7 + {1, 2, 1, 3}, // 8 + {3, 1, 1, 2}, // 9 + {1, 1, 2, 3}, // 10 reversed 0 + {1, 2, 2, 2}, // 11 reversed 1 + {2, 2, 1, 2}, // 12 reversed 2 + {1, 1, 4, 1}, // 13 reversed 3 + {2, 3, 1, 1}, // 14 reversed 4 + {1, 3, 2, 1}, // 15 reversed 5 + {4, 1, 1, 1}, // 16 reversed 6 + {2, 1, 3, 1}, // 17 reversed 7 + {3, 1, 2, 1}, // 18 reversed 8 + {2, 1, 1, 3} // 19 reversed 9 + }; + + + int UPCEANReader::getMIDDLE_PATTERN_LEN() { + return MIDDLE_PATTERN_LEN; + } + + const int* UPCEANReader::getMIDDLE_PATTERN() { + return MIDDLE_PATTERN; + } + + UPCEANReader::UPCEANReader() { + } + + + Ref UPCEANReader::decodeRow(int rowNumber, Ref row) { + int rangeStart; + int rangeEnd; + if (findStartGuardPattern(row, &rangeStart, &rangeEnd)) { + try { + return decodeRow(rowNumber, row, rangeStart, rangeEnd); + } catch (ReaderException const& re) { + } + } + return Ref(); + } + + Ref UPCEANReader::decodeRow(int rowNumber, Ref row, int startGuardBegin, + int startGuardEnd) { + std::string tmpResultString; + std::string& tmpResultStringRef = tmpResultString; + int endStart = decodeMiddle(row, startGuardBegin, startGuardEnd, tmpResultStringRef); + if (endStart < 0) { + return Ref(); + } + + int endGuardBegin; + int endGuardEnd; + if (!decodeEnd(row, endStart, &endGuardBegin, &endGuardEnd)) { + return Ref(); + } + + // Make sure there is a quiet zone at least as big as the end pattern after the barcode. + // The spec might want more whitespace, but in practice this is the maximum we can count on. + size_t quietEnd = endGuardEnd + (endGuardEnd - endGuardBegin); + if (quietEnd >= row->getSize() || !row->isRange(endGuardEnd, quietEnd, false)) { + return Ref(); + } + + if (!checkChecksum(tmpResultString)) { + return Ref(); + } + + Ref resultString(new String(tmpResultString)); + float left = (float) (startGuardBegin + startGuardEnd) / 2.0f; + float right = (float) (endGuardBegin + endGuardEnd) / 2.0f; + + std::vector< Ref > resultPoints(2); + Ref resultPoint1(new OneDResultPoint(left, (float) rowNumber)); + Ref resultPoint2(new OneDResultPoint(right, (float) rowNumber)); + resultPoints[0] = resultPoint1; + resultPoints[1] = resultPoint2; + + ArrayRef resultBytes(1); + return Ref(new Result(resultString, resultBytes, resultPoints, getBarcodeFormat())); + } + + bool UPCEANReader::findStartGuardPattern(Ref row, int* rangeStart, int* rangeEnd) { + int nextStart = 0; + while (findGuardPattern(row, nextStart, false, START_END_PATTERN, + sizeof(START_END_PATTERN) / sizeof(int), rangeStart, rangeEnd)) { + int start = *rangeStart; + nextStart = *rangeEnd; + // Make sure there is a quiet zone at least as big as the start pattern before the barcode. + // If this check would run off the left edge of the image, do not accept this barcode, + // as it is very likely to be a false positive. + int quietStart = start - (nextStart - start); + if (quietStart >= 0 && row->isRange(quietStart, start, false)) { + return true; + } + } + return false; + } + + bool UPCEANReader::findGuardPattern(Ref row, int rowOffset, bool whiteFirst, + const int pattern[], int patternLen, int* start, int* end) { + int patternLength = patternLen; + int counters[patternLength]; + int countersCount = sizeof(counters) / sizeof(int); + for (int i = 0; i < countersCount; i++) { + counters[i] = 0; + } + int width = row->getSize(); + bool isWhite = false; + while (rowOffset < width) { + isWhite = !row->get(rowOffset); + if (whiteFirst == isWhite) { + break; + } + rowOffset++; + } + + int counterPosition = 0; + int patternStart = rowOffset; + for (int x = rowOffset; x < width; x++) { + bool pixel = row->get(x); + if (pixel ^ isWhite) { + counters[counterPosition]++; + } else { + if (counterPosition == patternLength - 1) { + if (patternMatchVariance(counters, countersCount, pattern, + MAX_INDIVIDUAL_VARIANCE) < MAX_AVG_VARIANCE) { + *start = patternStart; + *end = x; + return true; + } + patternStart += counters[0] + counters[1]; + for (int y = 2; y < patternLength; y++) { + counters[y - 2] = counters[y]; + } + counters[patternLength - 2] = 0; + counters[patternLength - 1] = 0; + counterPosition--; + } else { + counterPosition++; + } + counters[counterPosition] = 1; + isWhite = !isWhite; + } + } + return false; + } + + bool UPCEANReader::decodeEnd(Ref row, int endStart, int* endGuardBegin, + int* endGuardEnd) { + return findGuardPattern(row, endStart, false, START_END_PATTERN, + sizeof(START_END_PATTERN) / sizeof(int), endGuardBegin, endGuardEnd); + } + + int UPCEANReader::decodeDigit(Ref row, int counters[], int countersLen, int rowOffset, + UPC_EAN_PATTERNS patternType) { + if (!recordPattern(row, rowOffset, counters, countersLen)) { + return -1; + } + unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept + int bestMatch = -1; + + int max = 0; + switch (patternType) { + case UPC_EAN_PATTERNS_L_PATTERNS: + max = L_PATTERNS_LEN; + for (int i = 0; i < max; i++) { + int pattern[countersLen]; + for(int j = 0; j< countersLen; j++){ + pattern[j] = L_PATTERNS[i][j]; + } + + unsigned int variance = patternMatchVariance(counters, countersLen, pattern, + MAX_INDIVIDUAL_VARIANCE); + if (variance < bestVariance) { + bestVariance = variance; + bestMatch = i; + } + } + break; + case UPC_EAN_PATTERNS_L_AND_G_PATTERNS: + max = L_AND_G_PATTERNS_LEN; + for (int i = 0; i < max; i++) { + int pattern[countersLen]; + for(int j = 0; j< countersLen; j++){ + pattern[j] = L_AND_G_PATTERNS[i][j]; + } + + unsigned int variance = patternMatchVariance(counters, countersLen, pattern, + MAX_INDIVIDUAL_VARIANCE); + if (variance < bestVariance) { + bestVariance = variance; + bestMatch = i; + } + } + break; + default: + break; + } + return bestMatch; + } + + /** + * @return {@link #checkStandardUPCEANChecksum(String)} + */ + bool UPCEANReader::checkChecksum(std::string s) { + return checkStandardUPCEANChecksum(s); + } + + /** + * Computes the UPC/EAN checksum on a string of digits, and reports + * whether the checksum is correct or not. + * + * @param s string of digits to check + * @return true iff string of digits passes the UPC/EAN checksum algorithm + */ + bool UPCEANReader::checkStandardUPCEANChecksum(std::string s) { + int length = s.length(); + if (length == 0) { + return false; + } + + int sum = 0; + for (int i = length - 2; i >= 0; i -= 2) { + int digit = (int) s[i] - (int) '0'; + if (digit < 0 || digit > 9) { + return false; + } + sum += digit; + } + sum *= 3; + for (int i = length - 1; i >= 0; i -= 2) { + int digit = (int) s[i] - (int) '0'; + if (digit < 0 || digit > 9) { + return false; + } + sum += digit; + } + return sum % 10 == 0; + } + + UPCEANReader::~UPCEANReader() { + } + } +} diff --git a/symbian/QZXing/source/zxing/oned/UPCEANReader.h b/symbian/QZXing/source/zxing/oned/UPCEANReader.h index a9e1f9b4b..7de40348b 100644 --- a/symbian/QZXing/source/zxing/oned/UPCEANReader.h +++ b/symbian/QZXing/source/zxing/oned/UPCEANReader.h @@ -1,79 +1,75 @@ -#ifndef __UPC_EAN_READER_H__ -#define __UPC_EAN_READER_H__ - -/* - * UPCEANReader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -typedef enum UPC_EAN_PATTERNS { - UPC_EAN_PATTERNS_L_PATTERNS = 0, - UPC_EAN_PATTERNS_L_AND_G_PATTERNS -} UPC_EAN_PATTERNS; - -namespace zxing { - namespace oned { - class UPCEANReader : public OneDReader { - - private: - //static const unsigned int MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f); - enum {MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f)}; - //static const int MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.7f); - enum {MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.7f)}; - - static bool findStartGuardPattern(Ref row, int* rangeStart, int* rangeEnd); - - virtual bool decodeEnd(Ref row, int endStart, int* endGuardBegin, int* endGuardEnd); - - static bool checkStandardUPCEANChecksum(std::string s); - protected: - static bool findGuardPattern(Ref row, int rowOffset, bool whiteFirst, - const int pattern[], int patternLen, int* start, int* end); - - virtual int getMIDDLE_PATTERN_LEN(); - virtual const int* getMIDDLE_PATTERN(); - - public: - UPCEANReader(); - - // Returns < 0 on failure, >= 0 on success. - virtual int decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, - std::string& resultString) = 0; - - Ref decodeRow(int rowNumber, Ref row); - - // TODO(dswitkin): Should this be virtual so that UPCAReader can override it? - Ref decodeRow(int rowNumber, Ref row, int startGuardBegin, - int startGuardEnd); - - // Returns < 0 on failure, >= 0 on success. - static int decodeDigit(Ref row, int counters[], int countersLen, int rowOffset, - UPC_EAN_PATTERNS patternType); - - virtual bool checkChecksum(std::string s); - - virtual BarcodeFormat getBarcodeFormat() = 0; - virtual ~UPCEANReader(); - }; - } -} - -#endif +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __UPC_EAN_READER_H__ +#define __UPC_EAN_READER_H__ + +/* + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +typedef enum UPC_EAN_PATTERNS { + UPC_EAN_PATTERNS_L_PATTERNS = 0, + UPC_EAN_PATTERNS_L_AND_G_PATTERNS +} UPC_EAN_PATTERNS; + +namespace zxing { + namespace oned { + class UPCEANReader : public OneDReader { + + private: + enum {MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 420/1000)}; + enum {MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 700/1000)}; + + static bool findStartGuardPattern(Ref row, int* rangeStart, int* rangeEnd); + + virtual bool decodeEnd(Ref row, int endStart, int* endGuardBegin, int* endGuardEnd); + + static bool checkStandardUPCEANChecksum(std::string s); + protected: + static bool findGuardPattern(Ref row, int rowOffset, bool whiteFirst, + const int pattern[], int patternLen, int* start, int* end); + + virtual int getMIDDLE_PATTERN_LEN(); + virtual const int* getMIDDLE_PATTERN(); + + public: + UPCEANReader(); + + // Returns < 0 on failure, >= 0 on success. + virtual int decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, + std::string& resultString) = 0; + + Ref decodeRow(int rowNumber, Ref row); + + // TODO(dswitkin): Should this be virtual so that UPCAReader can override it? + Ref decodeRow(int rowNumber, Ref row, int startGuardBegin, + int startGuardEnd); + + // Returns < 0 on failure, >= 0 on success. + static int decodeDigit(Ref row, int counters[], int countersLen, int rowOffset, + UPC_EAN_PATTERNS patternType); + + virtual bool checkChecksum(std::string s); + + virtual BarcodeFormat getBarcodeFormat() = 0; + virtual ~UPCEANReader(); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/oned/UPCEReader.cpp b/symbian/QZXing/source/zxing/oned/UPCEReader.cpp index ee656a593..d9e98fb3f 100644 --- a/symbian/QZXing/source/zxing/oned/UPCEReader.cpp +++ b/symbian/QZXing/source/zxing/oned/UPCEReader.cpp @@ -1,143 +1,147 @@ -/* - * UPCEReader.cpp - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "UPCEReader.h" -#include - -namespace zxing { - namespace oned { - - /** - * The pattern that marks the middle, and end, of a UPC-E pattern. - * There is no "second half" to a UPC-E barcode. - */ - static const int MIDDLE_END_PATTERN[6] = {1, 1, 1, 1, 1, 1}; - - /** - * See {@link #L_AND_G_PATTERNS}; these values similarly represent patterns of - * even-odd parity encodings of digits that imply both the number system (0 or 1) - * used, and the check digit. - */ - static const int NUMSYS_AND_CHECK_DIGIT_PATTERNS[2][10] = { - {0x38, 0x34, 0x32, 0x31, 0x2C, 0x26, 0x23, 0x2A, 0x29, 0x25}, - {0x07, 0x0B, 0x0D, 0x0E, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A} - }; - - UPCEReader::UPCEReader() { - } - - int UPCEReader::decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, - std::string& resultString) { - const int countersLen = 4; - int counters[countersLen] = { 0, 0, 0, 0 }; - - int end = row->getSize(); - int rowOffset = startGuardEnd; - int lgPatternFound = 0; - - for (int x = 0; x < 6 && rowOffset < end; x++) { - int bestMatch = decodeDigit(row, counters, countersLen, rowOffset, - UPC_EAN_PATTERNS_L_AND_G_PATTERNS); - if (bestMatch < 0) { - return -1; - } - resultString.append(1, (char) ('0' + bestMatch % 10)); - for (int i = 0; i < countersLen; i++) { - rowOffset += counters[i]; - } - if (bestMatch >= 10) { - lgPatternFound |= 1 << (5 - x); - } - } - - if (!determineNumSysAndCheckDigit(resultString, lgPatternFound)) { - return -1; - } - return rowOffset; - } - - bool UPCEReader::decodeEnd(Ref row, int endStart, int* endGuardBegin, - int* endGuardEnd) { - return findGuardPattern(row, endStart, true, MIDDLE_END_PATTERN, - sizeof(MIDDLE_END_PATTERN) / sizeof(int), endGuardBegin, endGuardEnd); - } - - bool UPCEReader::checkChecksum(std::string s){ - return UPCEANReader::checkChecksum(convertUPCEtoUPCA(s)); - } - - - bool UPCEReader::determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound) { - for (int numSys = 0; numSys <= 1; numSys++) { - for (int d = 0; d < 10; d++) { - if (lgPatternFound == NUMSYS_AND_CHECK_DIGIT_PATTERNS[numSys][d]) { - resultString.insert((size_t)0, (size_t)1, (char) ('0' + numSys)); - resultString.append((size_t)1, (char) ('0' + d)); - return true; - } - } - } - return false; - } - - /** - * Expands a UPC-E value back into its full, equivalent UPC-A code value. - * - * @param upce UPC-E code as string of digits - * @return equivalent UPC-A code as string of digits - */ - std::string UPCEReader::convertUPCEtoUPCA(std::string upce) { - std::string result; - result.append(1, upce[0]); - char lastChar = upce[6]; - switch (lastChar) { - case '0': - case '1': - case '2': - result.append(upce.substr(1,2)); - result.append(1, lastChar); - result.append("0000"); - result.append(upce.substr(3,3)); - break; - case '3': - result.append(upce.substr(1,3)); - result.append("00000"); - result.append(upce.substr(4,2)); - break; - case '4': - result.append(upce.substr(1,4)); - result.append("00000"); - result.append(1, upce[5]); - break; - default: - result.append(upce.substr(1,5)); - result.append("0000"); - result.append(1, lastChar); - break; - } - result.append(1, upce[7]); - return result; - } - - - BarcodeFormat UPCEReader::getBarcodeFormat() { - return BarcodeFormat_UPC_E; - } - } -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UPCEReader.h" +#include +#include + +namespace zxing { + namespace oned { + + /** + * The pattern that marks the middle, and end, of a UPC-E pattern. + * There is no "second half" to a UPC-E barcode. + */ + static const int MIDDLE_END_PATTERN[6] = {1, 1, 1, 1, 1, 1}; + + /** + * See {@link #L_AND_G_PATTERNS}; these values similarly represent patterns of + * even-odd parity encodings of digits that imply both the number system (0 or 1) + * used, and the check digit. + */ + static const int NUMSYS_AND_CHECK_DIGIT_PATTERNS[2][10] = { + {0x38, 0x34, 0x32, 0x31, 0x2C, 0x26, 0x23, 0x2A, 0x29, 0x25}, + {0x07, 0x0B, 0x0D, 0x0E, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A} + }; + + UPCEReader::UPCEReader() { + } + + int UPCEReader::decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, + std::string& resultString) { + (void)startGuardBegin; + const int countersLen = 4; + int counters[countersLen] = { 0, 0, 0, 0 }; + + int end = row->getSize(); + int rowOffset = startGuardEnd; + int lgPatternFound = 0; + + for (int x = 0; x < 6 && rowOffset < end; x++) { + int bestMatch = decodeDigit(row, counters, countersLen, rowOffset, + UPC_EAN_PATTERNS_L_AND_G_PATTERNS); + if (bestMatch < 0) { + return -1; + } + resultString.append(1, (char) ('0' + bestMatch % 10)); + for (int i = 0; i < countersLen; i++) { + rowOffset += counters[i]; + } + if (bestMatch >= 10) { + lgPatternFound |= 1 << (5 - x); + } + } + + if (!determineNumSysAndCheckDigit(resultString, lgPatternFound)) { + return -1; + } + return rowOffset; + } + + bool UPCEReader::decodeEnd(Ref row, int endStart, int* endGuardBegin, + int* endGuardEnd) { + return findGuardPattern(row, endStart, true, MIDDLE_END_PATTERN, + sizeof(MIDDLE_END_PATTERN) / sizeof(int), endGuardBegin, endGuardEnd); + } + + bool UPCEReader::checkChecksum(std::string s){ + return UPCEANReader::checkChecksum(convertUPCEtoUPCA(s)); + } + + + bool UPCEReader::determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound) { + for (int numSys = 0; numSys <= 1; numSys++) { + for (int d = 0; d < 10; d++) { + if (lgPatternFound == NUMSYS_AND_CHECK_DIGIT_PATTERNS[numSys][d]) { +#if defined(Q_OS_SYMBIAN) + resultString.insert((char*)0, 1, (char) ((int)'0' + numSys)); +#else + resultString.insert(/*(char*)*/0, 1, (char) ((int)'0' + numSys)); +#endif + resultString.append(1, (char) ('0' + d)); + return true; + } + } + } + return false; + } + + /** + * Expands a UPC-E value back into its full, equivalent UPC-A code value. + * + * @param upce UPC-E code as string of digits + * @return equivalent UPC-A code as string of digits + */ + std::string UPCEReader::convertUPCEtoUPCA(std::string upce) { + std::string result; + result.append(1, upce[0]); + char lastChar = upce[6]; + switch (lastChar) { + case '0': + case '1': + case '2': + result.append(upce.substr(1,2)); + result.append(1, lastChar); + result.append("0000"); + result.append(upce.substr(3,3)); + break; + case '3': + result.append(upce.substr(1,3)); + result.append("00000"); + result.append(upce.substr(4,2)); + break; + case '4': + result.append(upce.substr(1,4)); + result.append("00000"); + result.append(1, upce[5]); + break; + default: + result.append(upce.substr(1,5)); + result.append("0000"); + result.append(1, lastChar); + break; + } + result.append(1, upce[7]); + return result; + } + + + BarcodeFormat UPCEReader::getBarcodeFormat() { + return BarcodeFormat_UPC_E; + } + } +} diff --git a/symbian/QZXing/source/zxing/oned/UPCEReader.h b/symbian/QZXing/source/zxing/oned/UPCEReader.h index 0f4c61fb0..e46ac64da 100644 --- a/symbian/QZXing/source/zxing/oned/UPCEReader.h +++ b/symbian/QZXing/source/zxing/oned/UPCEReader.h @@ -1,47 +1,44 @@ -#ifndef __UPC_E_READER_H__ -#define __UPC_E_READER_H__ - -/* - * UPCEReader.h - * ZXing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - namespace oned { - class UPCEReader : public UPCEANReader { - - private: - static bool determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound); - protected: - bool decodeEnd(Ref row, int endStart, int* endGuardBegin, int* endGuardEnd); - bool checkChecksum(std::string s); - public: - UPCEReader(); - - int decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, - std::string& resultString); - static std::string convertUPCEtoUPCA(std::string upce); - - BarcodeFormat getBarcodeFormat(); - }; - } -} - -#endif +#ifndef __UPC_E_READER_H__ +#define __UPC_E_READER_H__ + +/* + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + namespace oned { + class UPCEReader : public UPCEANReader { + + private: + static bool determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound); + protected: + bool decodeEnd(Ref row, int endStart, int* endGuardBegin, int* endGuardEnd); + bool checkChecksum(std::string s); + public: + UPCEReader(); + + int decodeMiddle(Ref row, int startGuardBegin, int startGuardEnd, + std::string& resultString); + static std::string convertUPCEtoUPCA(std::string upce); + + BarcodeFormat getBarcodeFormat(); + }; + } +} + +#endif diff --git a/symbian/QZXing/source/zxing/qrcode/ErrorCorrectionLevel.h b/symbian/QZXing/source/zxing/qrcode/ErrorCorrectionLevel.h index ad8d64e21..28bce61b0 100644 --- a/symbian/QZXing/source/zxing/qrcode/ErrorCorrectionLevel.h +++ b/symbian/QZXing/source/zxing/qrcode/ErrorCorrectionLevel.h @@ -1,52 +1,52 @@ -#ifndef __ERROR_CORRECTION_LEVEL_H__ -#define __ERROR_CORRECTION_LEVEL_H__ - -/* - * ErrorCorrectionLevel.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { -namespace qrcode { - -class ErrorCorrectionLevel { -private: - int ordinal_; - int bits_; - std::string name_; - ErrorCorrectionLevel(int inOrdinal, int bits, char const* name); - static ErrorCorrectionLevel *FOR_BITS[]; - static int N_LEVELS; -public: - static ErrorCorrectionLevel L; - static ErrorCorrectionLevel M; - static ErrorCorrectionLevel Q; - static ErrorCorrectionLevel H; - - int ordinal() const; - int bits() const; - std::string const& name() const; - operator std::string const& () const; - - static ErrorCorrectionLevel& forBits(int bits); -}; -} -} - -#endif // __ERROR_CORRECTION_LEVEL_H__ +#ifndef __ERROR_CORRECTION_LEVEL_H__ +#define __ERROR_CORRECTION_LEVEL_H__ + +/* + * ErrorCorrectionLevel.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { +namespace qrcode { + +class ErrorCorrectionLevel { +private: + int ordinal_; + int bits_; + std::string name_; + ErrorCorrectionLevel(int inOrdinal, int bits, char const* name); + static ErrorCorrectionLevel *FOR_BITS[]; + static int N_LEVELS; +public: + static ErrorCorrectionLevel L; + static ErrorCorrectionLevel M; + static ErrorCorrectionLevel Q; + static ErrorCorrectionLevel H; + + int ordinal() const; + int bits() const; + std::string const& name() const; + operator std::string const& () const; + + static ErrorCorrectionLevel& forBits(int bits); +}; +} +} + +#endif // __ERROR_CORRECTION_LEVEL_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/FormatInformation.h b/symbian/QZXing/source/zxing/qrcode/FormatInformation.h index 5a07bbbca..ed856036b 100644 --- a/symbian/QZXing/source/zxing/qrcode/FormatInformation.h +++ b/symbian/QZXing/source/zxing/qrcode/FormatInformation.h @@ -1,54 +1,54 @@ -#ifndef __FORMAT_INFORMATION_H__ -#define __FORMAT_INFORMATION_H__ - -/* - * FormatInformation.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { -namespace qrcode { - -class FormatInformation : public Counted { -private: - static int FORMAT_INFO_MASK_QR; - static int FORMAT_INFO_DECODE_LOOKUP[][2]; - static int N_FORMAT_INFO_DECODE_LOOKUPS; - static int BITS_SET_IN_HALF_BYTE[]; - - ErrorCorrectionLevel &errorCorrectionLevel_; - unsigned char dataMask_; - - FormatInformation(int formatInfo); - -public: - static int numBitsDiffering(unsigned int a, unsigned int b); - static Ref decodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2); - static Ref doDecodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2); - ErrorCorrectionLevel &getErrorCorrectionLevel(); - unsigned char getDataMask(); - friend bool operator==(const FormatInformation &a, const FormatInformation &b); - friend std::ostream& operator<<(std::ostream& out, const FormatInformation& fi); -}; -} -} - -#endif // __FORMAT_INFORMATION_H__ +#ifndef __FORMAT_INFORMATION_H__ +#define __FORMAT_INFORMATION_H__ + +/* + * FormatInformation.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { +namespace qrcode { + +class FormatInformation : public Counted { +private: + static int FORMAT_INFO_MASK_QR; + static int FORMAT_INFO_DECODE_LOOKUP[][2]; + static int N_FORMAT_INFO_DECODE_LOOKUPS; + static int BITS_SET_IN_HALF_BYTE[]; + + ErrorCorrectionLevel &errorCorrectionLevel_; + unsigned char dataMask_; + + FormatInformation(int formatInfo); + +public: + static int numBitsDiffering(unsigned int a, unsigned int b); + static Ref decodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2); + static Ref doDecodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2); + ErrorCorrectionLevel &getErrorCorrectionLevel(); + unsigned char getDataMask(); + friend bool operator==(const FormatInformation &a, const FormatInformation &b); + friend std::ostream& operator<<(std::ostream& out, const FormatInformation& fi); +}; +} +} + +#endif // __FORMAT_INFORMATION_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/QRCodeReader.cpp b/symbian/QZXing/source/zxing/qrcode/QRCodeReader.cpp index 969633a89..227be4753 100644 --- a/symbian/QZXing/source/zxing/qrcode/QRCodeReader.cpp +++ b/symbian/QZXing/source/zxing/qrcode/QRCodeReader.cpp @@ -1,86 +1,86 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * QRCodeReader.cpp - * zxing - * - * Created by Christian Brunschen on 20/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include - -namespace zxing { - namespace qrcode { - - using namespace std; - - QRCodeReader::QRCodeReader() :decoder_() { - } - //TODO: see if any of the other files in the qrcode tree need tryHarder - Ref QRCodeReader::decode(Ref image, DecodeHints hints) { -#ifdef DEBUG - cout << "decoding image " << image.object_ << ":\n" << flush; -#endif - - Detector detector(image->getBlackMatrix()); - - -#ifdef DEBUG - cout << "(1) created detector " << &detector << "\n" << flush; -#endif - - Ref detectorResult(detector.detect(hints)); -#ifdef DEBUG - cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush; -#endif - - std::vector > points(detectorResult->getPoints()); - - -#ifdef DEBUG - cout << "(3) extracted points " << &points << "\n" << flush; - cout << "found " << points->size() << " points:\n"; - for (size_t i = 0; i < points->size(); i++) { - cout << " " << points[i]->getX() << "," << points[i]->getY() << "\n"; - } - cout << "bits:\n"; - cout << *(detectorResult->getBits()) << "\n"; -#endif - - Ref decoderResult(decoder_.decode(detectorResult->getBits())); -#ifdef DEBUG - cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush; -#endif - - Ref result( - new Result(decoderResult->getText(), decoderResult->getRawBytes(), points, BarcodeFormat_QR_CODE)); -#ifdef DEBUG - cout << "(5) created result " << result.object_ << ", returning\n" << flush; -#endif - - return result; - } - - QRCodeReader::~QRCodeReader() { - } - - Decoder& QRCodeReader::getDecoder() { - return decoder_; - } - } -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * QRCodeReader.cpp + * zxing + * + * Created by Christian Brunschen on 20/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include + +namespace zxing { + namespace qrcode { + + using namespace std; + + QRCodeReader::QRCodeReader() :decoder_() { + } + //TODO: see if any of the other files in the qrcode tree need tryHarder + Ref QRCodeReader::decode(Ref image, DecodeHints hints) { +#ifdef DEBUG + cout << "decoding image " << image.object_ << ":\n" << flush; +#endif + + Detector detector(image->getBlackMatrix()); + + +#ifdef DEBUG + cout << "(1) created detector " << &detector << "\n" << flush; +#endif + + Ref detectorResult(detector.detect(hints)); +#ifdef DEBUG + cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush; +#endif + + std::vector > points(detectorResult->getPoints()); + + +#ifdef DEBUG + cout << "(3) extracted points " << &points << "\n" << flush; + cout << "found " << points.size() << " points:\n"; + for (size_t i = 0; i < points.size(); i++) { + cout << " " << points[i]->getX() << "," << points[i]->getY() << "\n"; + } + cout << "bits:\n"; + cout << *(detectorResult->getBits()) << "\n"; +#endif + + Ref decoderResult(decoder_.decode(detectorResult->getBits())); +#ifdef DEBUG + cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush; +#endif + + Ref result( + new Result(decoderResult->getText(), decoderResult->getRawBytes(), points, BarcodeFormat_QR_CODE)); +#ifdef DEBUG + cout << "(5) created result " << result.object_ << ", returning\n" << flush; +#endif + + return result; + } + + QRCodeReader::~QRCodeReader() { + } + + Decoder& QRCodeReader::getDecoder() { + return decoder_; + } + } +} diff --git a/symbian/QZXing/source/zxing/qrcode/QRCodeReader.h b/symbian/QZXing/source/zxing/qrcode/QRCodeReader.h index b245be65e..991cc186c 100644 --- a/symbian/QZXing/source/zxing/qrcode/QRCodeReader.h +++ b/symbian/QZXing/source/zxing/qrcode/QRCodeReader.h @@ -1,47 +1,47 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __QR_CODE_READER_H__ -#define __QR_CODE_READER_H__ - -/* - * QRCodeReader.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -namespace zxing { - namespace qrcode { - - class QRCodeReader : public Reader { - private: - Decoder decoder_; - - protected: - Decoder& getDecoder(); - - public: - QRCodeReader(); - virtual Ref decode(Ref image, DecodeHints hints); - virtual ~QRCodeReader(); - - }; - } -} - -#endif // __QR_CODE_READER_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __QR_CODE_READER_H__ +#define __QR_CODE_READER_H__ + +/* + * QRCodeReader.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +namespace zxing { + namespace qrcode { + + class QRCodeReader : public Reader { + private: + Decoder decoder_; + + protected: + Decoder& getDecoder(); + + public: + QRCodeReader(); + virtual Ref decode(Ref image, DecodeHints hints); + virtual ~QRCodeReader(); + + }; + } +} + +#endif // __QR_CODE_READER_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/ErrorCorrectionLevel.cpp b/symbian/QZXing/source/zxing/qrcode/QRErrorCorrectionLevel.cpp similarity index 96% rename from symbian/QZXing/source/zxing/qrcode/ErrorCorrectionLevel.cpp rename to symbian/QZXing/source/zxing/qrcode/QRErrorCorrectionLevel.cpp index 16659a131..46eed14a9 100644 --- a/symbian/QZXing/source/zxing/qrcode/ErrorCorrectionLevel.cpp +++ b/symbian/QZXing/source/zxing/qrcode/QRErrorCorrectionLevel.cpp @@ -1,65 +1,65 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * ErrorCorrectionLevel.cpp - * zxing - * - * Created by Christian Brunschen on 15/05/2008. - * Copyright 2008-2011 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -using std::string; - -namespace zxing { -namespace qrcode { - -ErrorCorrectionLevel::ErrorCorrectionLevel(int inOrdinal, - int bits, - char const* name) : - ordinal_(inOrdinal), bits_(bits), name_(name) {} - -int ErrorCorrectionLevel::ordinal() const { - return ordinal_; -} - -int ErrorCorrectionLevel::bits() const { - return bits_; -} - -string const& ErrorCorrectionLevel::name() const { - return name_; -} - -ErrorCorrectionLevel::operator string const& () const { - return name_; -} - -ErrorCorrectionLevel& ErrorCorrectionLevel::forBits(int bits) { - if (bits < 0 || bits >= N_LEVELS) { - throw ReaderException("Ellegal error correction level bits"); - } - return *FOR_BITS[bits]; -} - - ErrorCorrectionLevel ErrorCorrectionLevel::L(0, 0x01, "L"); - ErrorCorrectionLevel ErrorCorrectionLevel::M(1, 0x00, "M"); - ErrorCorrectionLevel ErrorCorrectionLevel::Q(2, 0x03, "Q"); - ErrorCorrectionLevel ErrorCorrectionLevel::H(3, 0x02, "H"); -ErrorCorrectionLevel *ErrorCorrectionLevel::FOR_BITS[] = { &M, &L, &H, &Q }; -int ErrorCorrectionLevel::N_LEVELS = 4; - -} -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * ErrorCorrectionLevel.cpp + * zxing + * + * Created by Christian Brunschen on 15/05/2008. + * Copyright 2008-2011 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +using std::string; + +namespace zxing { +namespace qrcode { + +ErrorCorrectionLevel::ErrorCorrectionLevel(int inOrdinal, + int bits, + char const* name) : + ordinal_(inOrdinal), bits_(bits), name_(name) {} + +int ErrorCorrectionLevel::ordinal() const { + return ordinal_; +} + +int ErrorCorrectionLevel::bits() const { + return bits_; +} + +string const& ErrorCorrectionLevel::name() const { + return name_; +} + +ErrorCorrectionLevel::operator string const& () const { + return name_; +} + +ErrorCorrectionLevel& ErrorCorrectionLevel::forBits(int bits) { + if (bits < 0 || bits >= N_LEVELS) { + throw ReaderException("Ellegal error correction level bits"); + } + return *FOR_BITS[bits]; +} + + ErrorCorrectionLevel ErrorCorrectionLevel::L(0, 0x01, "L"); + ErrorCorrectionLevel ErrorCorrectionLevel::M(1, 0x00, "M"); + ErrorCorrectionLevel ErrorCorrectionLevel::Q(2, 0x03, "Q"); + ErrorCorrectionLevel ErrorCorrectionLevel::H(3, 0x02, "H"); +ErrorCorrectionLevel *ErrorCorrectionLevel::FOR_BITS[] = { &M, &L, &H, &Q }; +int ErrorCorrectionLevel::N_LEVELS = 4; + +} +} diff --git a/symbian/QZXing/source/zxing/qrcode/FormatInformation.cpp b/symbian/QZXing/source/zxing/qrcode/QRFormatInformation.cpp similarity index 97% rename from symbian/QZXing/source/zxing/qrcode/FormatInformation.cpp rename to symbian/QZXing/source/zxing/qrcode/QRFormatInformation.cpp index 6f04de890..7ae0d80c2 100644 --- a/symbian/QZXing/source/zxing/qrcode/FormatInformation.cpp +++ b/symbian/QZXing/source/zxing/qrcode/QRFormatInformation.cpp @@ -1,118 +1,118 @@ -/* - * FormatInformation.cpp - * zxing - * - * Created by Christian Brunschen on 18/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { -namespace qrcode { - -using namespace std; - -int FormatInformation::FORMAT_INFO_MASK_QR = 0x5412; -int FormatInformation::FORMAT_INFO_DECODE_LOOKUP[][2] = { { 0x5412, 0x00 }, { 0x5125, 0x01 }, { 0x5E7C, 0x02 }, { - 0x5B4B, 0x03 }, { 0x45F9, 0x04 }, { 0x40CE, 0x05 }, { 0x4F97, 0x06 }, { 0x4AA0, 0x07 }, { 0x77C4, 0x08 }, { - 0x72F3, 0x09 }, { 0x7DAA, 0x0A }, { 0x789D, 0x0B }, { 0x662F, 0x0C }, { 0x6318, 0x0D }, { 0x6C41, 0x0E }, { - 0x6976, 0x0F }, { 0x1689, 0x10 }, { 0x13BE, 0x11 }, { 0x1CE7, 0x12 }, { 0x19D0, 0x13 }, { 0x0762, 0x14 }, { - 0x0255, 0x15 }, { 0x0D0C, 0x16 }, { 0x083B, 0x17 }, { 0x355F, 0x18 }, { 0x3068, 0x19 }, { 0x3F31, 0x1A }, { - 0x3A06, 0x1B }, { 0x24B4, 0x1C }, { 0x2183, 0x1D }, { 0x2EDA, 0x1E }, { 0x2BED, 0x1F }, -}; -int FormatInformation::N_FORMAT_INFO_DECODE_LOOKUPS = 32; - -int FormatInformation::BITS_SET_IN_HALF_BYTE[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; - -FormatInformation::FormatInformation(int formatInfo) : - errorCorrectionLevel_(ErrorCorrectionLevel::forBits((formatInfo >> 3) & 0x03)), dataMask_( - (unsigned char)(formatInfo & 0x07)) { -} - -ErrorCorrectionLevel& FormatInformation::getErrorCorrectionLevel() { - return errorCorrectionLevel_; -} - -unsigned char FormatInformation::getDataMask() { - return dataMask_; -} - -int FormatInformation::numBitsDiffering(unsigned int a, unsigned int b) { - a ^= b; - return BITS_SET_IN_HALF_BYTE[a & 0x0F] + BITS_SET_IN_HALF_BYTE[(a >> 4 & 0x0F)] + BITS_SET_IN_HALF_BYTE[(a >> 8 - & 0x0F)] + BITS_SET_IN_HALF_BYTE[(a >> 12 & 0x0F)] + BITS_SET_IN_HALF_BYTE[(a >> 16 & 0x0F)] - + BITS_SET_IN_HALF_BYTE[(a >> 20 & 0x0F)] + BITS_SET_IN_HALF_BYTE[(a >> 24 & 0x0F)] - + BITS_SET_IN_HALF_BYTE[(a >> 28 & 0x0F)]; -} - -Ref FormatInformation::decodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2) { - Ref result(doDecodeFormatInformation(maskedFormatInfo1, maskedFormatInfo2)); - if (result != 0) { - return result; - } - // Should return null, but, some QR codes apparently - // do not mask this info. Try again by actually masking the pattern - // first - return doDecodeFormatInformation(maskedFormatInfo1 ^ FORMAT_INFO_MASK_QR, - maskedFormatInfo2 ^ FORMAT_INFO_MASK_QR); -} -Ref FormatInformation::doDecodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2) { - // Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing - int bestDifference = numeric_limits::max(); - int bestFormatInfo = 0; - for (int i = 0; i < N_FORMAT_INFO_DECODE_LOOKUPS; i++) { - int* decodeInfo = FORMAT_INFO_DECODE_LOOKUP[i]; - int targetInfo = decodeInfo[0]; - if (targetInfo == maskedFormatInfo1 || targetInfo == maskedFormatInfo2) { - // Found an exact match - Ref result(new FormatInformation(decodeInfo[1])); - return result; - } - int bitsDifference = numBitsDiffering(maskedFormatInfo1, targetInfo); - if (bitsDifference < bestDifference) { - bestFormatInfo = decodeInfo[1]; - bestDifference = bitsDifference; - } - if (maskedFormatInfo1 != maskedFormatInfo2) { - // also try the other option - bitsDifference = numBitsDiffering(maskedFormatInfo2, targetInfo); - if (bitsDifference < bestDifference) { - bestFormatInfo = decodeInfo[1]; - bestDifference = bitsDifference; - } - } - } - if (bestDifference <= 3) { - Ref result(new FormatInformation(bestFormatInfo)); - return result; - } - Ref result; - return result; -} - -bool operator==(const FormatInformation &a, const FormatInformation &b) { - return &(a.errorCorrectionLevel_) == &(b.errorCorrectionLevel_) && a.dataMask_ == b.dataMask_; -} - -ostream& operator<<(ostream& out, const FormatInformation& fi) { - const FormatInformation *fip = &fi; - out << "FormatInformation @ " << fip; - return out; -} - -} -} +/* + * FormatInformation.cpp + * zxing + * + * Created by Christian Brunschen on 18/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { +namespace qrcode { + +using namespace std; + +int FormatInformation::FORMAT_INFO_MASK_QR = 0x5412; +int FormatInformation::FORMAT_INFO_DECODE_LOOKUP[][2] = { { 0x5412, 0x00 }, { 0x5125, 0x01 }, { 0x5E7C, 0x02 }, { + 0x5B4B, 0x03 }, { 0x45F9, 0x04 }, { 0x40CE, 0x05 }, { 0x4F97, 0x06 }, { 0x4AA0, 0x07 }, { 0x77C4, 0x08 }, { + 0x72F3, 0x09 }, { 0x7DAA, 0x0A }, { 0x789D, 0x0B }, { 0x662F, 0x0C }, { 0x6318, 0x0D }, { 0x6C41, 0x0E }, { + 0x6976, 0x0F }, { 0x1689, 0x10 }, { 0x13BE, 0x11 }, { 0x1CE7, 0x12 }, { 0x19D0, 0x13 }, { 0x0762, 0x14 }, { + 0x0255, 0x15 }, { 0x0D0C, 0x16 }, { 0x083B, 0x17 }, { 0x355F, 0x18 }, { 0x3068, 0x19 }, { 0x3F31, 0x1A }, { + 0x3A06, 0x1B }, { 0x24B4, 0x1C }, { 0x2183, 0x1D }, { 0x2EDA, 0x1E }, { 0x2BED, 0x1F }, +}; +int FormatInformation::N_FORMAT_INFO_DECODE_LOOKUPS = 32; + +int FormatInformation::BITS_SET_IN_HALF_BYTE[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; + +FormatInformation::FormatInformation(int formatInfo) : + errorCorrectionLevel_(ErrorCorrectionLevel::forBits((formatInfo >> 3) & 0x03)), dataMask_( + (unsigned char)(formatInfo & 0x07)) { +} + +ErrorCorrectionLevel& FormatInformation::getErrorCorrectionLevel() { + return errorCorrectionLevel_; +} + +unsigned char FormatInformation::getDataMask() { + return dataMask_; +} + +int FormatInformation::numBitsDiffering(unsigned int a, unsigned int b) { + a ^= b; + return BITS_SET_IN_HALF_BYTE[a & 0x0F] + BITS_SET_IN_HALF_BYTE[(a >> 4 & 0x0F)] + BITS_SET_IN_HALF_BYTE[(a >> 8 + & 0x0F)] + BITS_SET_IN_HALF_BYTE[(a >> 12 & 0x0F)] + BITS_SET_IN_HALF_BYTE[(a >> 16 & 0x0F)] + + BITS_SET_IN_HALF_BYTE[(a >> 20 & 0x0F)] + BITS_SET_IN_HALF_BYTE[(a >> 24 & 0x0F)] + + BITS_SET_IN_HALF_BYTE[(a >> 28 & 0x0F)]; +} + +Ref FormatInformation::decodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2) { + Ref result(doDecodeFormatInformation(maskedFormatInfo1, maskedFormatInfo2)); + if (result != 0) { + return result; + } + // Should return null, but, some QR codes apparently + // do not mask this info. Try again by actually masking the pattern + // first + return doDecodeFormatInformation(maskedFormatInfo1 ^ FORMAT_INFO_MASK_QR, + maskedFormatInfo2 ^ FORMAT_INFO_MASK_QR); +} +Ref FormatInformation::doDecodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2) { + // Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing + int bestDifference = numeric_limits::max(); + int bestFormatInfo = 0; + for (int i = 0; i < N_FORMAT_INFO_DECODE_LOOKUPS; i++) { + int* decodeInfo = FORMAT_INFO_DECODE_LOOKUP[i]; + int targetInfo = decodeInfo[0]; + if (targetInfo == maskedFormatInfo1 || targetInfo == maskedFormatInfo2) { + // Found an exact match + Ref result(new FormatInformation(decodeInfo[1])); + return result; + } + int bitsDifference = numBitsDiffering(maskedFormatInfo1, targetInfo); + if (bitsDifference < bestDifference) { + bestFormatInfo = decodeInfo[1]; + bestDifference = bitsDifference; + } + if (maskedFormatInfo1 != maskedFormatInfo2) { + // also try the other option + bitsDifference = numBitsDiffering(maskedFormatInfo2, targetInfo); + if (bitsDifference < bestDifference) { + bestFormatInfo = decodeInfo[1]; + bestDifference = bitsDifference; + } + } + } + if (bestDifference <= 3) { + Ref result(new FormatInformation(bestFormatInfo)); + return result; + } + Ref result; + return result; +} + +bool operator==(const FormatInformation &a, const FormatInformation &b) { + return &(a.errorCorrectionLevel_) == &(b.errorCorrectionLevel_) && a.dataMask_ == b.dataMask_; +} + +ostream& operator<<(ostream& out, const FormatInformation& fi) { + const FormatInformation *fip = &fi; + out << "FormatInformation @ " << fip; + return out; +} + +} +} diff --git a/symbian/QZXing/source/zxing/qrcode/Version.cpp b/symbian/QZXing/source/zxing/qrcode/QRVersion.cpp similarity index 98% rename from symbian/QZXing/source/zxing/qrcode/Version.cpp rename to symbian/QZXing/source/zxing/qrcode/QRVersion.cpp index 339f79fda..37b186b82 100644 --- a/symbian/QZXing/source/zxing/qrcode/Version.cpp +++ b/symbian/QZXing/source/zxing/qrcode/QRVersion.cpp @@ -1,557 +1,557 @@ -/* - * Version.cpp - * zxing - * - * Created by Christian Brunschen on 14/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace zxing { -namespace qrcode { -using namespace std; - -ECB::ECB(int count, int dataCodewords) : - count_(count), dataCodewords_(dataCodewords) { -} - -int ECB::getCount() { - return count_; -} - -int ECB::getDataCodewords() { - return dataCodewords_; -} - -ECBlocks::ECBlocks(int ecCodewords, ECB *ecBlocks) : - ecCodewords_(ecCodewords), ecBlocks_(1, ecBlocks) { -} - -ECBlocks::ECBlocks(int ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2) : - ecCodewords_(ecCodewords), ecBlocks_(1, ecBlocks1) { - ecBlocks_.push_back(ecBlocks2); -} - -int ECBlocks::getECCodewords() { - return ecCodewords_; -} - -std::vector& ECBlocks::getECBlocks() { - return ecBlocks_; -} - -ECBlocks::~ECBlocks() { - for (size_t i = 0; i < ecBlocks_.size(); i++) { - delete ecBlocks_[i]; - } -} - -unsigned int Version::VERSION_DECODE_INFO[] = { 0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, 0x0C762, 0x0D847, 0x0E60D, - 0x0F928, 0x10B78, 0x1145D, 0x12A17, 0x13532, 0x149A6, 0x15683, 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, - 0x1B08E, 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, 0x209D5, 0x216F0, 0x228BA, 0x2379F, 0x24B0B, 0x2542E, 0x26A64, - 0x27541, 0x28C69 - }; -int Version::N_VERSION_DECODE_INFOS = 34; -vector > Version::VERSIONS; -static int N_VERSIONS = Version::buildVersions(); - -int Version::getVersionNumber() { - return versionNumber_; -} - -vector &Version::getAlignmentPatternCenters() { - return alignmentPatternCenters_; -} - -int Version::getTotalCodewords() { - return totalCodewords_; -} - -int Version::getDimensionForVersion() { - return 17 + 4 * versionNumber_; -} - -ECBlocks& Version::getECBlocksForLevel(ErrorCorrectionLevel &ecLevel) { - return *ecBlocks_[ecLevel.ordinal()]; -} - -Version *Version::getProvisionalVersionForDimension(int dimension) { - if (dimension % 4 != 1) { - throw ReaderException("Dimension must be 1 mod 4"); - } - return Version::getVersionForNumber((dimension - 17) >> 2); -} - -Version *Version::getVersionForNumber(int versionNumber) { - if (versionNumber < 1 || versionNumber > N_VERSIONS) { - throw ReaderException("versionNumber must be between 1 and 40"); - } - - return VERSIONS[versionNumber - 1]; -} - -Version::Version(int versionNumber, vector *alignmentPatternCenters, ECBlocks *ecBlocks1, ECBlocks *ecBlocks2, - ECBlocks *ecBlocks3, ECBlocks *ecBlocks4) : - versionNumber_(versionNumber), alignmentPatternCenters_(*alignmentPatternCenters), ecBlocks_(4), totalCodewords_(0) { - ecBlocks_[0] = ecBlocks1; - ecBlocks_[1] = ecBlocks2; - ecBlocks_[2] = ecBlocks3; - ecBlocks_[3] = ecBlocks4; - - int total = 0; - int ecCodewords = ecBlocks1->getECCodewords(); - vector &ecbArray = ecBlocks1->getECBlocks(); - for (size_t i = 0; i < ecbArray.size(); i++) { - ECB *ecBlock = ecbArray[i]; - total += ecBlock->getCount() * (ecBlock->getDataCodewords() + ecCodewords); - } - totalCodewords_ = total; -} - -Version::~Version() { - delete &alignmentPatternCenters_; - for (size_t i = 0; i < ecBlocks_.size(); i++) { - delete ecBlocks_[i]; - } -} - -Version *Version::decodeVersionInformation(unsigned int versionBits) { - int bestDifference = numeric_limits::max(); - size_t bestVersion = 0; - for (int i = 0; i < N_VERSION_DECODE_INFOS; i++) { - unsigned targetVersion = VERSION_DECODE_INFO[i]; - // Do the version info bits match exactly? done. - if (targetVersion == versionBits) { - return getVersionForNumber(i + 7); - } - // Otherwise see if this is the closest to a real version info bit - // string we have seen so far - int bitsDifference = FormatInformation::numBitsDiffering(versionBits, targetVersion); - if (bitsDifference < bestDifference) { - bestVersion = i + 7; - bestDifference = bitsDifference; - } - } - // We can tolerate up to 3 bits of error since no two version info codewords will - // differ in less than 4 bits. - if (bestDifference <= 3) { - return getVersionForNumber(bestVersion); - } - // If we didn't find a close enough match, fail - return 0; -} - -Ref Version::buildFunctionPattern() { - int dimension = getDimensionForVersion(); - Ref functionPattern(new BitMatrix(dimension)); - - - // Top left finder pattern + separator + format - functionPattern->setRegion(0, 0, 9, 9); - // Top right finder pattern + separator + format - functionPattern->setRegion(dimension - 8, 0, 8, 9); - // Bottom left finder pattern + separator + format - functionPattern->setRegion(0, dimension - 8, 9, 8); - - - // Alignment patterns - size_t max = alignmentPatternCenters_.size(); - for (size_t x = 0; x < max; x++) { - int i = alignmentPatternCenters_[x] - 2; - for (size_t y = 0; y < max; y++) { - if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) { - // No alignment patterns near the three finder patterns - continue; - } - functionPattern->setRegion(alignmentPatternCenters_[y] - 2, i, 5, 5); - } - } - - // Vertical timing pattern - functionPattern->setRegion(6, 9, 1, dimension - 17); - // Horizontal timing pattern - functionPattern->setRegion(9, 6, dimension - 17, 1); - - if (versionNumber_ > 6) { - // Version info, top right - functionPattern->setRegion(dimension - 11, 0, 3, 6); - // Version info, bottom left - functionPattern->setRegion(0, dimension - 11, 6, 3); - } - - - //#ifdef DEBUG - // cout << "version " << versionNumber_ << " built function pattern:\n"; - // cout << *functionPattern; - //#endif - - return functionPattern; -} - -static vector *intArray(size_t n...) { - va_list ap; - va_start(ap, n); - vector *result = new vector(n); - for (size_t i = 0; i < n; i++) { - (*result)[i] = va_arg(ap, int); - } - va_end(ap); - return result; -} - -int Version::buildVersions() { - VERSIONS.push_back(Ref(new Version(1, intArray(0), - new ECBlocks(7, new ECB(1, 19)), - new ECBlocks(10, new ECB(1, 16)), - new ECBlocks(13, new ECB(1, 13)), - new ECBlocks(17, new ECB(1, 9))))); - VERSIONS.push_back(Ref(new Version(2, intArray(2, 6, 18), - new ECBlocks(10, new ECB(1, 34)), - new ECBlocks(16, new ECB(1, 28)), - new ECBlocks(22, new ECB(1, 22)), - new ECBlocks(28, new ECB(1, 16))))); - VERSIONS.push_back(Ref(new Version(3, intArray(2, 6, 22), - new ECBlocks(15, new ECB(1, 55)), - new ECBlocks(26, new ECB(1, 44)), - new ECBlocks(18, new ECB(2, 17)), - new ECBlocks(22, new ECB(2, 13))))); - VERSIONS.push_back(Ref(new Version(4, intArray(2, 6, 26), - new ECBlocks(20, new ECB(1, 80)), - new ECBlocks(18, new ECB(2, 32)), - new ECBlocks(26, new ECB(2, 24)), - new ECBlocks(16, new ECB(4, 9))))); - VERSIONS.push_back(Ref(new Version(5, intArray(2, 6, 30), - new ECBlocks(26, new ECB(1, 108)), - new ECBlocks(24, new ECB(2, 43)), - new ECBlocks(18, new ECB(2, 15), - new ECB(2, 16)), - new ECBlocks(22, new ECB(2, 11), - new ECB(2, 12))))); - VERSIONS.push_back(Ref(new Version(6, intArray(2, 6, 34), - new ECBlocks(18, new ECB(2, 68)), - new ECBlocks(16, new ECB(4, 27)), - new ECBlocks(24, new ECB(4, 19)), - new ECBlocks(28, new ECB(4, 15))))); - VERSIONS.push_back(Ref(new Version(7, intArray(3, 6, 22, 38), - new ECBlocks(20, new ECB(2, 78)), - new ECBlocks(18, new ECB(4, 31)), - new ECBlocks(18, new ECB(2, 14), - new ECB(4, 15)), - new ECBlocks(26, new ECB(4, 13), - new ECB(1, 14))))); - VERSIONS.push_back(Ref(new Version(8, intArray(3, 6, 24, 42), - new ECBlocks(24, new ECB(2, 97)), - new ECBlocks(22, new ECB(2, 38), - new ECB(2, 39)), - new ECBlocks(22, new ECB(4, 18), - new ECB(2, 19)), - new ECBlocks(26, new ECB(4, 14), - new ECB(2, 15))))); - VERSIONS.push_back(Ref(new Version(9, intArray(3, 6, 26, 46), - new ECBlocks(30, new ECB(2, 116)), - new ECBlocks(22, new ECB(3, 36), - new ECB(2, 37)), - new ECBlocks(20, new ECB(4, 16), - new ECB(4, 17)), - new ECBlocks(24, new ECB(4, 12), - new ECB(4, 13))))); - VERSIONS.push_back(Ref(new Version(10, intArray(3, 6, 28, 50), - new ECBlocks(18, new ECB(2, 68), - new ECB(2, 69)), - new ECBlocks(26, new ECB(4, 43), - new ECB(1, 44)), - new ECBlocks(24, new ECB(6, 19), - new ECB(2, 20)), - new ECBlocks(28, new ECB(6, 15), - new ECB(2, 16))))); - VERSIONS.push_back(Ref(new Version(11, intArray(3, 6, 30, 54), - new ECBlocks(20, new ECB(4, 81)), - new ECBlocks(30, new ECB(1, 50), - new ECB(4, 51)), - new ECBlocks(28, new ECB(4, 22), - new ECB(4, 23)), - new ECBlocks(24, new ECB(3, 12), - new ECB(8, 13))))); - VERSIONS.push_back(Ref(new Version(12, intArray(3, 6, 32, 58), - new ECBlocks(24, new ECB(2, 92), - new ECB(2, 93)), - new ECBlocks(22, new ECB(6, 36), - new ECB(2, 37)), - new ECBlocks(26, new ECB(4, 20), - new ECB(6, 21)), - new ECBlocks(28, new ECB(7, 14), - new ECB(4, 15))))); - VERSIONS.push_back(Ref(new Version(13, intArray(3, 6, 34, 62), - new ECBlocks(26, new ECB(4, 107)), - new ECBlocks(22, new ECB(8, 37), - new ECB(1, 38)), - new ECBlocks(24, new ECB(8, 20), - new ECB(4, 21)), - new ECBlocks(22, new ECB(12, 11), - new ECB(4, 12))))); - VERSIONS.push_back(Ref(new Version(14, intArray(4, 6, 26, 46, 66), - new ECBlocks(30, new ECB(3, 115), - new ECB(1, 116)), - new ECBlocks(24, new ECB(4, 40), - new ECB(5, 41)), - new ECBlocks(20, new ECB(11, 16), - new ECB(5, 17)), - new ECBlocks(24, new ECB(11, 12), - new ECB(5, 13))))); - VERSIONS.push_back(Ref(new Version(15, intArray(4, 6, 26, 48, 70), - new ECBlocks(22, new ECB(5, 87), - new ECB(1, 88)), - new ECBlocks(24, new ECB(5, 41), - new ECB(5, 42)), - new ECBlocks(30, new ECB(5, 24), - new ECB(7, 25)), - new ECBlocks(24, new ECB(11, 12), - new ECB(7, 13))))); - VERSIONS.push_back(Ref(new Version(16, intArray(4, 6, 26, 50, 74), - new ECBlocks(24, new ECB(5, 98), - new ECB(1, 99)), - new ECBlocks(28, new ECB(7, 45), - new ECB(3, 46)), - new ECBlocks(24, new ECB(15, 19), - new ECB(2, 20)), - new ECBlocks(30, new ECB(3, 15), - new ECB(13, 16))))); - VERSIONS.push_back(Ref(new Version(17, intArray(4, 6, 30, 54, 78), - new ECBlocks(28, new ECB(1, 107), - new ECB(5, 108)), - new ECBlocks(28, new ECB(10, 46), - new ECB(1, 47)), - new ECBlocks(28, new ECB(1, 22), - new ECB(15, 23)), - new ECBlocks(28, new ECB(2, 14), - new ECB(17, 15))))); - VERSIONS.push_back(Ref(new Version(18, intArray(4, 6, 30, 56, 82), - new ECBlocks(30, new ECB(5, 120), - new ECB(1, 121)), - new ECBlocks(26, new ECB(9, 43), - new ECB(4, 44)), - new ECBlocks(28, new ECB(17, 22), - new ECB(1, 23)), - new ECBlocks(28, new ECB(2, 14), - new ECB(19, 15))))); - VERSIONS.push_back(Ref(new Version(19, intArray(4, 6, 30, 58, 86), - new ECBlocks(28, new ECB(3, 113), - new ECB(4, 114)), - new ECBlocks(26, new ECB(3, 44), - new ECB(11, 45)), - new ECBlocks(26, new ECB(17, 21), - new ECB(4, 22)), - new ECBlocks(26, new ECB(9, 13), - new ECB(16, 14))))); - VERSIONS.push_back(Ref(new Version(20, intArray(4, 6, 34, 62, 90), - new ECBlocks(28, new ECB(3, 107), - new ECB(5, 108)), - new ECBlocks(26, new ECB(3, 41), - new ECB(13, 42)), - new ECBlocks(30, new ECB(15, 24), - new ECB(5, 25)), - new ECBlocks(28, new ECB(15, 15), - new ECB(10, 16))))); - VERSIONS.push_back(Ref(new Version(21, intArray(5, 6, 28, 50, 72, 94), - new ECBlocks(28, new ECB(4, 116), - new ECB(4, 117)), - new ECBlocks(26, new ECB(17, 42)), - new ECBlocks(28, new ECB(17, 22), - new ECB(6, 23)), - new ECBlocks(30, new ECB(19, 16), - new ECB(6, 17))))); - VERSIONS.push_back(Ref(new Version(22, intArray(5, 6, 26, 50, 74, 98), - new ECBlocks(28, new ECB(2, 111), - new ECB(7, 112)), - new ECBlocks(28, new ECB(17, 46)), - new ECBlocks(30, new ECB(7, 24), - new ECB(16, 25)), - new ECBlocks(24, new ECB(34, 13))))); - VERSIONS.push_back(Ref(new Version(23, intArray(5, 6, 30, 54, 78, 102), - new ECBlocks(30, new ECB(4, 121), - new ECB(5, 122)), - new ECBlocks(28, new ECB(4, 47), - new ECB(14, 48)), - new ECBlocks(30, new ECB(11, 24), - new ECB(14, 25)), - new ECBlocks(30, new ECB(16, 15), - new ECB(14, 16))))); - VERSIONS.push_back(Ref(new Version(24, intArray(5, 6, 28, 54, 80, 106), - new ECBlocks(30, new ECB(6, 117), - new ECB(4, 118)), - new ECBlocks(28, new ECB(6, 45), - new ECB(14, 46)), - new ECBlocks(30, new ECB(11, 24), - new ECB(16, 25)), - new ECBlocks(30, new ECB(30, 16), - new ECB(2, 17))))); - VERSIONS.push_back(Ref(new Version(25, intArray(5, 6, 32, 58, 84, 110), - new ECBlocks(26, new ECB(8, 106), - new ECB(4, 107)), - new ECBlocks(28, new ECB(8, 47), - new ECB(13, 48)), - new ECBlocks(30, new ECB(7, 24), - new ECB(22, 25)), - new ECBlocks(30, new ECB(22, 15), - new ECB(13, 16))))); - VERSIONS.push_back(Ref(new Version(26, intArray(5, 6, 30, 58, 86, 114), - new ECBlocks(28, new ECB(10, 114), - new ECB(2, 115)), - new ECBlocks(28, new ECB(19, 46), - new ECB(4, 47)), - new ECBlocks(28, new ECB(28, 22), - new ECB(6, 23)), - new ECBlocks(30, new ECB(33, 16), - new ECB(4, 17))))); - VERSIONS.push_back(Ref(new Version(27, intArray(5, 6, 34, 62, 90, 118), - new ECBlocks(30, new ECB(8, 122), - new ECB(4, 123)), - new ECBlocks(28, new ECB(22, 45), - new ECB(3, 46)), - new ECBlocks(30, new ECB(8, 23), - new ECB(26, 24)), - new ECBlocks(30, new ECB(12, 15), - new ECB(28, 16))))); - VERSIONS.push_back(Ref(new Version(28, intArray(6, 6, 26, 50, 74, 98, 122), - new ECBlocks(30, new ECB(3, 117), - new ECB(10, 118)), - new ECBlocks(28, new ECB(3, 45), - new ECB(23, 46)), - new ECBlocks(30, new ECB(4, 24), - new ECB(31, 25)), - new ECBlocks(30, new ECB(11, 15), - new ECB(31, 16))))); - VERSIONS.push_back(Ref(new Version(29, intArray(6, 6, 30, 54, 78, 102, 126), - new ECBlocks(30, new ECB(7, 116), - new ECB(7, 117)), - new ECBlocks(28, new ECB(21, 45), - new ECB(7, 46)), - new ECBlocks(30, new ECB(1, 23), - new ECB(37, 24)), - new ECBlocks(30, new ECB(19, 15), - new ECB(26, 16))))); - VERSIONS.push_back(Ref(new Version(30, intArray(6, 6, 26, 52, 78, 104, 130), - new ECBlocks(30, new ECB(5, 115), - new ECB(10, 116)), - new ECBlocks(28, new ECB(19, 47), - new ECB(10, 48)), - new ECBlocks(30, new ECB(15, 24), - new ECB(25, 25)), - new ECBlocks(30, new ECB(23, 15), - new ECB(25, 16))))); - VERSIONS.push_back(Ref(new Version(31, intArray(6, 6, 30, 56, 82, 108, 134), - new ECBlocks(30, new ECB(13, 115), - new ECB(3, 116)), - new ECBlocks(28, new ECB(2, 46), - new ECB(29, 47)), - new ECBlocks(30, new ECB(42, 24), - new ECB(1, 25)), - new ECBlocks(30, new ECB(23, 15), - new ECB(28, 16))))); - VERSIONS.push_back(Ref(new Version(32, intArray(6, 6, 34, 60, 86, 112, 138), - new ECBlocks(30, new ECB(17, 115)), - new ECBlocks(28, new ECB(10, 46), - new ECB(23, 47)), - new ECBlocks(30, new ECB(10, 24), - new ECB(35, 25)), - new ECBlocks(30, new ECB(19, 15), - new ECB(35, 16))))); - VERSIONS.push_back(Ref(new Version(33, intArray(6, 6, 30, 58, 86, 114, 142), - new ECBlocks(30, new ECB(17, 115), - new ECB(1, 116)), - new ECBlocks(28, new ECB(14, 46), - new ECB(21, 47)), - new ECBlocks(30, new ECB(29, 24), - new ECB(19, 25)), - new ECBlocks(30, new ECB(11, 15), - new ECB(46, 16))))); - VERSIONS.push_back(Ref(new Version(34, intArray(6, 6, 34, 62, 90, 118, 146), - new ECBlocks(30, new ECB(13, 115), - new ECB(6, 116)), - new ECBlocks(28, new ECB(14, 46), - new ECB(23, 47)), - new ECBlocks(30, new ECB(44, 24), - new ECB(7, 25)), - new ECBlocks(30, new ECB(59, 16), - new ECB(1, 17))))); - VERSIONS.push_back(Ref(new Version(35, intArray(7, 6, 30, 54, 78, - 102, 126, 150), - new ECBlocks(30, new ECB(12, 121), - new ECB(7, 122)), - new ECBlocks(28, new ECB(12, 47), - new ECB(26, 48)), - new ECBlocks(30, new ECB(39, 24), - new ECB(14, 25)), - new ECBlocks(30, new ECB(22, 15), - new ECB(41, 16))))); - VERSIONS.push_back(Ref(new Version(36, intArray(7, 6, 24, 50, 76, - 102, 128, 154), - new ECBlocks(30, new ECB(6, 121), - new ECB(14, 122)), - new ECBlocks(28, new ECB(6, 47), - new ECB(34, 48)), - new ECBlocks(30, new ECB(46, 24), - new ECB(10, 25)), - new ECBlocks(30, new ECB(2, 15), - new ECB(64, 16))))); - VERSIONS.push_back(Ref(new Version(37, intArray(7, 6, 28, 54, 80, - 106, 132, 158), - new ECBlocks(30, new ECB(17, 122), - new ECB(4, 123)), - new ECBlocks(28, new ECB(29, 46), - new ECB(14, 47)), - new ECBlocks(30, new ECB(49, 24), - new ECB(10, 25)), - new ECBlocks(30, new ECB(24, 15), - new ECB(46, 16))))); - VERSIONS.push_back(Ref(new Version(38, intArray(7, 6, 32, 58, 84, - 110, 136, 162), - new ECBlocks(30, new ECB(4, 122), - new ECB(18, 123)), - new ECBlocks(28, new ECB(13, 46), - new ECB(32, 47)), - new ECBlocks(30, new ECB(48, 24), - new ECB(14, 25)), - new ECBlocks(30, new ECB(42, 15), - new ECB(32, 16))))); - VERSIONS.push_back(Ref(new Version(39, intArray(7, 6, 26, 54, 82, - 110, 138, 166), - new ECBlocks(30, new ECB(20, 117), - new ECB(4, 118)), - new ECBlocks(28, new ECB(40, 47), - new ECB(7, 48)), - new ECBlocks(30, new ECB(43, 24), - new ECB(22, 25)), - new ECBlocks(30, new ECB(10, 15), - new ECB(67, 16))))); - VERSIONS.push_back(Ref(new Version(40, intArray(7, 6, 30, 58, 86, - 114, 142, 170), - new ECBlocks(30, new ECB(19, 118), - new ECB(6, 119)), - new ECBlocks(28, new ECB(18, 47), - new ECB(31, 48)), - new ECBlocks(30, new ECB(34, 24), - new ECB(34, 25)), - new ECBlocks(30, new ECB(20, 15), - new ECB(61, 16))))); - return VERSIONS.size(); -} -} -} +/* + * Version.cpp + * zxing + * + * Created by Christian Brunschen on 14/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +namespace zxing { +namespace qrcode { +using namespace std; + +ECB::ECB(int count, int dataCodewords) : + count_(count), dataCodewords_(dataCodewords) { +} + +int ECB::getCount() { + return count_; +} + +int ECB::getDataCodewords() { + return dataCodewords_; +} + +ECBlocks::ECBlocks(int ecCodewords, ECB *ecBlocks) : + ecCodewords_(ecCodewords), ecBlocks_(1, ecBlocks) { +} + +ECBlocks::ECBlocks(int ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2) : + ecCodewords_(ecCodewords), ecBlocks_(1, ecBlocks1) { + ecBlocks_.push_back(ecBlocks2); +} + +int ECBlocks::getECCodewords() { + return ecCodewords_; +} + +std::vector& ECBlocks::getECBlocks() { + return ecBlocks_; +} + +ECBlocks::~ECBlocks() { + for (size_t i = 0; i < ecBlocks_.size(); i++) { + delete ecBlocks_[i]; + } +} + +unsigned int Version::VERSION_DECODE_INFO[] = { 0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, 0x0C762, 0x0D847, 0x0E60D, + 0x0F928, 0x10B78, 0x1145D, 0x12A17, 0x13532, 0x149A6, 0x15683, 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, + 0x1B08E, 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, 0x209D5, 0x216F0, 0x228BA, 0x2379F, 0x24B0B, 0x2542E, 0x26A64, + 0x27541, 0x28C69 + }; +int Version::N_VERSION_DECODE_INFOS = 34; +vector > Version::VERSIONS; +static int N_VERSIONS = Version::buildVersions(); + +int Version::getVersionNumber() { + return versionNumber_; +} + +vector &Version::getAlignmentPatternCenters() { + return alignmentPatternCenters_; +} + +int Version::getTotalCodewords() { + return totalCodewords_; +} + +int Version::getDimensionForVersion() { + return 17 + 4 * versionNumber_; +} + +ECBlocks& Version::getECBlocksForLevel(ErrorCorrectionLevel &ecLevel) { + return *ecBlocks_[ecLevel.ordinal()]; +} + +Version *Version::getProvisionalVersionForDimension(int dimension) { + if (dimension % 4 != 1) { + throw ReaderException("Dimension must be 1 mod 4"); + } + return Version::getVersionForNumber((dimension - 17) >> 2); +} + +Version *Version::getVersionForNumber(int versionNumber) { + if (versionNumber < 1 || versionNumber > N_VERSIONS) { + throw ReaderException("versionNumber must be between 1 and 40"); + } + + return VERSIONS[versionNumber - 1]; +} + +Version::Version(int versionNumber, vector *alignmentPatternCenters, ECBlocks *ecBlocks1, ECBlocks *ecBlocks2, + ECBlocks *ecBlocks3, ECBlocks *ecBlocks4) : + versionNumber_(versionNumber), alignmentPatternCenters_(*alignmentPatternCenters), ecBlocks_(4), totalCodewords_(0) { + ecBlocks_[0] = ecBlocks1; + ecBlocks_[1] = ecBlocks2; + ecBlocks_[2] = ecBlocks3; + ecBlocks_[3] = ecBlocks4; + + int total = 0; + int ecCodewords = ecBlocks1->getECCodewords(); + vector &ecbArray = ecBlocks1->getECBlocks(); + for (size_t i = 0; i < ecbArray.size(); i++) { + ECB *ecBlock = ecbArray[i]; + total += ecBlock->getCount() * (ecBlock->getDataCodewords() + ecCodewords); + } + totalCodewords_ = total; +} + +Version::~Version() { + delete &alignmentPatternCenters_; + for (size_t i = 0; i < ecBlocks_.size(); i++) { + delete ecBlocks_[i]; + } +} + +Version *Version::decodeVersionInformation(unsigned int versionBits) { + int bestDifference = numeric_limits::max(); + size_t bestVersion = 0; + for (int i = 0; i < N_VERSION_DECODE_INFOS; i++) { + unsigned targetVersion = VERSION_DECODE_INFO[i]; + // Do the version info bits match exactly? done. + if (targetVersion == versionBits) { + return getVersionForNumber(i + 7); + } + // Otherwise see if this is the closest to a real version info bit + // string we have seen so far + int bitsDifference = FormatInformation::numBitsDiffering(versionBits, targetVersion); + if (bitsDifference < bestDifference) { + bestVersion = i + 7; + bestDifference = bitsDifference; + } + } + // We can tolerate up to 3 bits of error since no two version info codewords will + // differ in less than 4 bits. + if (bestDifference <= 3) { + return getVersionForNumber(bestVersion); + } + // If we didn't find a close enough match, fail + return 0; +} + +Ref Version::buildFunctionPattern() { + int dimension = getDimensionForVersion(); + Ref functionPattern(new BitMatrix(dimension)); + + + // Top left finder pattern + separator + format + functionPattern->setRegion(0, 0, 9, 9); + // Top right finder pattern + separator + format + functionPattern->setRegion(dimension - 8, 0, 8, 9); + // Bottom left finder pattern + separator + format + functionPattern->setRegion(0, dimension - 8, 9, 8); + + + // Alignment patterns + size_t max = alignmentPatternCenters_.size(); + for (size_t x = 0; x < max; x++) { + int i = alignmentPatternCenters_[x] - 2; + for (size_t y = 0; y < max; y++) { + if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) { + // No alignment patterns near the three finder patterns + continue; + } + functionPattern->setRegion(alignmentPatternCenters_[y] - 2, i, 5, 5); + } + } + + // Vertical timing pattern + functionPattern->setRegion(6, 9, 1, dimension - 17); + // Horizontal timing pattern + functionPattern->setRegion(9, 6, dimension - 17, 1); + + if (versionNumber_ > 6) { + // Version info, top right + functionPattern->setRegion(dimension - 11, 0, 3, 6); + // Version info, bottom left + functionPattern->setRegion(0, dimension - 11, 6, 3); + } + + + //#ifdef DEBUG + // cout << "version " << versionNumber_ << " built function pattern:\n"; + // cout << *functionPattern; + //#endif + + return functionPattern; +} + +static vector *intArray(size_t n...) { + va_list ap; + va_start(ap, n); + vector *result = new vector(n); + for (size_t i = 0; i < n; i++) { + (*result)[i] = va_arg(ap, int); + } + va_end(ap); + return result; +} + +int Version::buildVersions() { + VERSIONS.push_back(Ref(new Version(1, intArray(0), + new ECBlocks(7, new ECB(1, 19)), + new ECBlocks(10, new ECB(1, 16)), + new ECBlocks(13, new ECB(1, 13)), + new ECBlocks(17, new ECB(1, 9))))); + VERSIONS.push_back(Ref(new Version(2, intArray(2, 6, 18), + new ECBlocks(10, new ECB(1, 34)), + new ECBlocks(16, new ECB(1, 28)), + new ECBlocks(22, new ECB(1, 22)), + new ECBlocks(28, new ECB(1, 16))))); + VERSIONS.push_back(Ref(new Version(3, intArray(2, 6, 22), + new ECBlocks(15, new ECB(1, 55)), + new ECBlocks(26, new ECB(1, 44)), + new ECBlocks(18, new ECB(2, 17)), + new ECBlocks(22, new ECB(2, 13))))); + VERSIONS.push_back(Ref(new Version(4, intArray(2, 6, 26), + new ECBlocks(20, new ECB(1, 80)), + new ECBlocks(18, new ECB(2, 32)), + new ECBlocks(26, new ECB(2, 24)), + new ECBlocks(16, new ECB(4, 9))))); + VERSIONS.push_back(Ref(new Version(5, intArray(2, 6, 30), + new ECBlocks(26, new ECB(1, 108)), + new ECBlocks(24, new ECB(2, 43)), + new ECBlocks(18, new ECB(2, 15), + new ECB(2, 16)), + new ECBlocks(22, new ECB(2, 11), + new ECB(2, 12))))); + VERSIONS.push_back(Ref(new Version(6, intArray(2, 6, 34), + new ECBlocks(18, new ECB(2, 68)), + new ECBlocks(16, new ECB(4, 27)), + new ECBlocks(24, new ECB(4, 19)), + new ECBlocks(28, new ECB(4, 15))))); + VERSIONS.push_back(Ref(new Version(7, intArray(3, 6, 22, 38), + new ECBlocks(20, new ECB(2, 78)), + new ECBlocks(18, new ECB(4, 31)), + new ECBlocks(18, new ECB(2, 14), + new ECB(4, 15)), + new ECBlocks(26, new ECB(4, 13), + new ECB(1, 14))))); + VERSIONS.push_back(Ref(new Version(8, intArray(3, 6, 24, 42), + new ECBlocks(24, new ECB(2, 97)), + new ECBlocks(22, new ECB(2, 38), + new ECB(2, 39)), + new ECBlocks(22, new ECB(4, 18), + new ECB(2, 19)), + new ECBlocks(26, new ECB(4, 14), + new ECB(2, 15))))); + VERSIONS.push_back(Ref(new Version(9, intArray(3, 6, 26, 46), + new ECBlocks(30, new ECB(2, 116)), + new ECBlocks(22, new ECB(3, 36), + new ECB(2, 37)), + new ECBlocks(20, new ECB(4, 16), + new ECB(4, 17)), + new ECBlocks(24, new ECB(4, 12), + new ECB(4, 13))))); + VERSIONS.push_back(Ref(new Version(10, intArray(3, 6, 28, 50), + new ECBlocks(18, new ECB(2, 68), + new ECB(2, 69)), + new ECBlocks(26, new ECB(4, 43), + new ECB(1, 44)), + new ECBlocks(24, new ECB(6, 19), + new ECB(2, 20)), + new ECBlocks(28, new ECB(6, 15), + new ECB(2, 16))))); + VERSIONS.push_back(Ref(new Version(11, intArray(3, 6, 30, 54), + new ECBlocks(20, new ECB(4, 81)), + new ECBlocks(30, new ECB(1, 50), + new ECB(4, 51)), + new ECBlocks(28, new ECB(4, 22), + new ECB(4, 23)), + new ECBlocks(24, new ECB(3, 12), + new ECB(8, 13))))); + VERSIONS.push_back(Ref(new Version(12, intArray(3, 6, 32, 58), + new ECBlocks(24, new ECB(2, 92), + new ECB(2, 93)), + new ECBlocks(22, new ECB(6, 36), + new ECB(2, 37)), + new ECBlocks(26, new ECB(4, 20), + new ECB(6, 21)), + new ECBlocks(28, new ECB(7, 14), + new ECB(4, 15))))); + VERSIONS.push_back(Ref(new Version(13, intArray(3, 6, 34, 62), + new ECBlocks(26, new ECB(4, 107)), + new ECBlocks(22, new ECB(8, 37), + new ECB(1, 38)), + new ECBlocks(24, new ECB(8, 20), + new ECB(4, 21)), + new ECBlocks(22, new ECB(12, 11), + new ECB(4, 12))))); + VERSIONS.push_back(Ref(new Version(14, intArray(4, 6, 26, 46, 66), + new ECBlocks(30, new ECB(3, 115), + new ECB(1, 116)), + new ECBlocks(24, new ECB(4, 40), + new ECB(5, 41)), + new ECBlocks(20, new ECB(11, 16), + new ECB(5, 17)), + new ECBlocks(24, new ECB(11, 12), + new ECB(5, 13))))); + VERSIONS.push_back(Ref(new Version(15, intArray(4, 6, 26, 48, 70), + new ECBlocks(22, new ECB(5, 87), + new ECB(1, 88)), + new ECBlocks(24, new ECB(5, 41), + new ECB(5, 42)), + new ECBlocks(30, new ECB(5, 24), + new ECB(7, 25)), + new ECBlocks(24, new ECB(11, 12), + new ECB(7, 13))))); + VERSIONS.push_back(Ref(new Version(16, intArray(4, 6, 26, 50, 74), + new ECBlocks(24, new ECB(5, 98), + new ECB(1, 99)), + new ECBlocks(28, new ECB(7, 45), + new ECB(3, 46)), + new ECBlocks(24, new ECB(15, 19), + new ECB(2, 20)), + new ECBlocks(30, new ECB(3, 15), + new ECB(13, 16))))); + VERSIONS.push_back(Ref(new Version(17, intArray(4, 6, 30, 54, 78), + new ECBlocks(28, new ECB(1, 107), + new ECB(5, 108)), + new ECBlocks(28, new ECB(10, 46), + new ECB(1, 47)), + new ECBlocks(28, new ECB(1, 22), + new ECB(15, 23)), + new ECBlocks(28, new ECB(2, 14), + new ECB(17, 15))))); + VERSIONS.push_back(Ref(new Version(18, intArray(4, 6, 30, 56, 82), + new ECBlocks(30, new ECB(5, 120), + new ECB(1, 121)), + new ECBlocks(26, new ECB(9, 43), + new ECB(4, 44)), + new ECBlocks(28, new ECB(17, 22), + new ECB(1, 23)), + new ECBlocks(28, new ECB(2, 14), + new ECB(19, 15))))); + VERSIONS.push_back(Ref(new Version(19, intArray(4, 6, 30, 58, 86), + new ECBlocks(28, new ECB(3, 113), + new ECB(4, 114)), + new ECBlocks(26, new ECB(3, 44), + new ECB(11, 45)), + new ECBlocks(26, new ECB(17, 21), + new ECB(4, 22)), + new ECBlocks(26, new ECB(9, 13), + new ECB(16, 14))))); + VERSIONS.push_back(Ref(new Version(20, intArray(4, 6, 34, 62, 90), + new ECBlocks(28, new ECB(3, 107), + new ECB(5, 108)), + new ECBlocks(26, new ECB(3, 41), + new ECB(13, 42)), + new ECBlocks(30, new ECB(15, 24), + new ECB(5, 25)), + new ECBlocks(28, new ECB(15, 15), + new ECB(10, 16))))); + VERSIONS.push_back(Ref(new Version(21, intArray(5, 6, 28, 50, 72, 94), + new ECBlocks(28, new ECB(4, 116), + new ECB(4, 117)), + new ECBlocks(26, new ECB(17, 42)), + new ECBlocks(28, new ECB(17, 22), + new ECB(6, 23)), + new ECBlocks(30, new ECB(19, 16), + new ECB(6, 17))))); + VERSIONS.push_back(Ref(new Version(22, intArray(5, 6, 26, 50, 74, 98), + new ECBlocks(28, new ECB(2, 111), + new ECB(7, 112)), + new ECBlocks(28, new ECB(17, 46)), + new ECBlocks(30, new ECB(7, 24), + new ECB(16, 25)), + new ECBlocks(24, new ECB(34, 13))))); + VERSIONS.push_back(Ref(new Version(23, intArray(5, 6, 30, 54, 78, 102), + new ECBlocks(30, new ECB(4, 121), + new ECB(5, 122)), + new ECBlocks(28, new ECB(4, 47), + new ECB(14, 48)), + new ECBlocks(30, new ECB(11, 24), + new ECB(14, 25)), + new ECBlocks(30, new ECB(16, 15), + new ECB(14, 16))))); + VERSIONS.push_back(Ref(new Version(24, intArray(5, 6, 28, 54, 80, 106), + new ECBlocks(30, new ECB(6, 117), + new ECB(4, 118)), + new ECBlocks(28, new ECB(6, 45), + new ECB(14, 46)), + new ECBlocks(30, new ECB(11, 24), + new ECB(16, 25)), + new ECBlocks(30, new ECB(30, 16), + new ECB(2, 17))))); + VERSIONS.push_back(Ref(new Version(25, intArray(5, 6, 32, 58, 84, 110), + new ECBlocks(26, new ECB(8, 106), + new ECB(4, 107)), + new ECBlocks(28, new ECB(8, 47), + new ECB(13, 48)), + new ECBlocks(30, new ECB(7, 24), + new ECB(22, 25)), + new ECBlocks(30, new ECB(22, 15), + new ECB(13, 16))))); + VERSIONS.push_back(Ref(new Version(26, intArray(5, 6, 30, 58, 86, 114), + new ECBlocks(28, new ECB(10, 114), + new ECB(2, 115)), + new ECBlocks(28, new ECB(19, 46), + new ECB(4, 47)), + new ECBlocks(28, new ECB(28, 22), + new ECB(6, 23)), + new ECBlocks(30, new ECB(33, 16), + new ECB(4, 17))))); + VERSIONS.push_back(Ref(new Version(27, intArray(5, 6, 34, 62, 90, 118), + new ECBlocks(30, new ECB(8, 122), + new ECB(4, 123)), + new ECBlocks(28, new ECB(22, 45), + new ECB(3, 46)), + new ECBlocks(30, new ECB(8, 23), + new ECB(26, 24)), + new ECBlocks(30, new ECB(12, 15), + new ECB(28, 16))))); + VERSIONS.push_back(Ref(new Version(28, intArray(6, 6, 26, 50, 74, 98, 122), + new ECBlocks(30, new ECB(3, 117), + new ECB(10, 118)), + new ECBlocks(28, new ECB(3, 45), + new ECB(23, 46)), + new ECBlocks(30, new ECB(4, 24), + new ECB(31, 25)), + new ECBlocks(30, new ECB(11, 15), + new ECB(31, 16))))); + VERSIONS.push_back(Ref(new Version(29, intArray(6, 6, 30, 54, 78, 102, 126), + new ECBlocks(30, new ECB(7, 116), + new ECB(7, 117)), + new ECBlocks(28, new ECB(21, 45), + new ECB(7, 46)), + new ECBlocks(30, new ECB(1, 23), + new ECB(37, 24)), + new ECBlocks(30, new ECB(19, 15), + new ECB(26, 16))))); + VERSIONS.push_back(Ref(new Version(30, intArray(6, 6, 26, 52, 78, 104, 130), + new ECBlocks(30, new ECB(5, 115), + new ECB(10, 116)), + new ECBlocks(28, new ECB(19, 47), + new ECB(10, 48)), + new ECBlocks(30, new ECB(15, 24), + new ECB(25, 25)), + new ECBlocks(30, new ECB(23, 15), + new ECB(25, 16))))); + VERSIONS.push_back(Ref(new Version(31, intArray(6, 6, 30, 56, 82, 108, 134), + new ECBlocks(30, new ECB(13, 115), + new ECB(3, 116)), + new ECBlocks(28, new ECB(2, 46), + new ECB(29, 47)), + new ECBlocks(30, new ECB(42, 24), + new ECB(1, 25)), + new ECBlocks(30, new ECB(23, 15), + new ECB(28, 16))))); + VERSIONS.push_back(Ref(new Version(32, intArray(6, 6, 34, 60, 86, 112, 138), + new ECBlocks(30, new ECB(17, 115)), + new ECBlocks(28, new ECB(10, 46), + new ECB(23, 47)), + new ECBlocks(30, new ECB(10, 24), + new ECB(35, 25)), + new ECBlocks(30, new ECB(19, 15), + new ECB(35, 16))))); + VERSIONS.push_back(Ref(new Version(33, intArray(6, 6, 30, 58, 86, 114, 142), + new ECBlocks(30, new ECB(17, 115), + new ECB(1, 116)), + new ECBlocks(28, new ECB(14, 46), + new ECB(21, 47)), + new ECBlocks(30, new ECB(29, 24), + new ECB(19, 25)), + new ECBlocks(30, new ECB(11, 15), + new ECB(46, 16))))); + VERSIONS.push_back(Ref(new Version(34, intArray(6, 6, 34, 62, 90, 118, 146), + new ECBlocks(30, new ECB(13, 115), + new ECB(6, 116)), + new ECBlocks(28, new ECB(14, 46), + new ECB(23, 47)), + new ECBlocks(30, new ECB(44, 24), + new ECB(7, 25)), + new ECBlocks(30, new ECB(59, 16), + new ECB(1, 17))))); + VERSIONS.push_back(Ref(new Version(35, intArray(7, 6, 30, 54, 78, + 102, 126, 150), + new ECBlocks(30, new ECB(12, 121), + new ECB(7, 122)), + new ECBlocks(28, new ECB(12, 47), + new ECB(26, 48)), + new ECBlocks(30, new ECB(39, 24), + new ECB(14, 25)), + new ECBlocks(30, new ECB(22, 15), + new ECB(41, 16))))); + VERSIONS.push_back(Ref(new Version(36, intArray(7, 6, 24, 50, 76, + 102, 128, 154), + new ECBlocks(30, new ECB(6, 121), + new ECB(14, 122)), + new ECBlocks(28, new ECB(6, 47), + new ECB(34, 48)), + new ECBlocks(30, new ECB(46, 24), + new ECB(10, 25)), + new ECBlocks(30, new ECB(2, 15), + new ECB(64, 16))))); + VERSIONS.push_back(Ref(new Version(37, intArray(7, 6, 28, 54, 80, + 106, 132, 158), + new ECBlocks(30, new ECB(17, 122), + new ECB(4, 123)), + new ECBlocks(28, new ECB(29, 46), + new ECB(14, 47)), + new ECBlocks(30, new ECB(49, 24), + new ECB(10, 25)), + new ECBlocks(30, new ECB(24, 15), + new ECB(46, 16))))); + VERSIONS.push_back(Ref(new Version(38, intArray(7, 6, 32, 58, 84, + 110, 136, 162), + new ECBlocks(30, new ECB(4, 122), + new ECB(18, 123)), + new ECBlocks(28, new ECB(13, 46), + new ECB(32, 47)), + new ECBlocks(30, new ECB(48, 24), + new ECB(14, 25)), + new ECBlocks(30, new ECB(42, 15), + new ECB(32, 16))))); + VERSIONS.push_back(Ref(new Version(39, intArray(7, 6, 26, 54, 82, + 110, 138, 166), + new ECBlocks(30, new ECB(20, 117), + new ECB(4, 118)), + new ECBlocks(28, new ECB(40, 47), + new ECB(7, 48)), + new ECBlocks(30, new ECB(43, 24), + new ECB(22, 25)), + new ECBlocks(30, new ECB(10, 15), + new ECB(67, 16))))); + VERSIONS.push_back(Ref(new Version(40, intArray(7, 6, 30, 58, 86, + 114, 142, 170), + new ECBlocks(30, new ECB(19, 118), + new ECB(6, 119)), + new ECBlocks(28, new ECB(18, 47), + new ECB(31, 48)), + new ECBlocks(30, new ECB(34, 24), + new ECB(34, 25)), + new ECBlocks(30, new ECB(20, 15), + new ECB(61, 16))))); + return VERSIONS.size(); +} +} +} diff --git a/symbian/QZXing/source/zxing/qrcode/Version.h b/symbian/QZXing/source/zxing/qrcode/Version.h index c111cdddd..3fa8e82ce 100644 --- a/symbian/QZXing/source/zxing/qrcode/Version.h +++ b/symbian/QZXing/source/zxing/qrcode/Version.h @@ -1,85 +1,85 @@ -#ifndef __VERSION_H__ -#define __VERSION_H__ - -/* - * Version.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace zxing { -namespace qrcode { - -class ECB { -private: - int count_; - int dataCodewords_; -public: - ECB(int count, int dataCodewords); - int getCount(); - int getDataCodewords(); -}; - -class ECBlocks { -private: - int ecCodewords_; - std::vector ecBlocks_; -public: - ECBlocks(int ecCodewords, ECB *ecBlocks); - ECBlocks(int ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2); - int getECCodewords(); - std::vector& getECBlocks(); - ~ECBlocks(); -}; - -class Version : public Counted { - -private: - int versionNumber_; - std::vector &alignmentPatternCenters_; - std::vector ecBlocks_; - int totalCodewords_; - Version(int versionNumber, std::vector *alignmentPatternCenters, ECBlocks *ecBlocks1, ECBlocks *ecBlocks2, - ECBlocks *ecBlocks3, ECBlocks *ecBlocks4); - -public: - static unsigned int VERSION_DECODE_INFO[]; - static int N_VERSION_DECODE_INFOS; - static std::vector > VERSIONS; - - ~Version(); - int getVersionNumber(); - std::vector &getAlignmentPatternCenters(); - int getTotalCodewords(); - int getDimensionForVersion(); - ECBlocks &getECBlocksForLevel(ErrorCorrectionLevel &ecLevel); - static Version *getProvisionalVersionForDimension(int dimension); - static Version *getVersionForNumber(int versionNumber); - static Version *decodeVersionInformation(unsigned int versionBits); - Ref buildFunctionPattern(); - static int buildVersions(); -}; -} -} - -#endif // __VERSION_H__ +#ifndef __VERSION_H__ +#define __VERSION_H__ + +/* + * Version.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +namespace zxing { +namespace qrcode { + +class ECB { +private: + int count_; + int dataCodewords_; +public: + ECB(int count, int dataCodewords); + int getCount(); + int getDataCodewords(); +}; + +class ECBlocks { +private: + int ecCodewords_; + std::vector ecBlocks_; +public: + ECBlocks(int ecCodewords, ECB *ecBlocks); + ECBlocks(int ecCodewords, ECB *ecBlocks1, ECB *ecBlocks2); + int getECCodewords(); + std::vector& getECBlocks(); + ~ECBlocks(); +}; + +class Version : public Counted { + +private: + int versionNumber_; + std::vector &alignmentPatternCenters_; + std::vector ecBlocks_; + int totalCodewords_; + Version(int versionNumber, std::vector *alignmentPatternCenters, ECBlocks *ecBlocks1, ECBlocks *ecBlocks2, + ECBlocks *ecBlocks3, ECBlocks *ecBlocks4); + +public: + static unsigned int VERSION_DECODE_INFO[]; + static int N_VERSION_DECODE_INFOS; + static std::vector > VERSIONS; + + ~Version(); + int getVersionNumber(); + std::vector &getAlignmentPatternCenters(); + int getTotalCodewords(); + int getDimensionForVersion(); + ECBlocks &getECBlocksForLevel(ErrorCorrectionLevel &ecLevel); + static Version *getProvisionalVersionForDimension(int dimension); + static Version *getVersionForNumber(int versionNumber); + static Version *decodeVersionInformation(unsigned int versionBits); + Ref buildFunctionPattern(); + static int buildVersions(); +}; +} +} + +#endif // __VERSION_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/BitMatrixParser.h b/symbian/QZXing/source/zxing/qrcode/decoder/BitMatrixParser.h index 50d170ab4..8813dced0 100644 --- a/symbian/QZXing/source/zxing/qrcode/decoder/BitMatrixParser.h +++ b/symbian/QZXing/source/zxing/qrcode/decoder/BitMatrixParser.h @@ -1,56 +1,56 @@ -#ifndef __BIT_MATRIX_PARSER_H__ -#define __BIT_MATRIX_PARSER_H__ - -/* - * BitMatrixParser.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace zxing { -namespace qrcode { - -class BitMatrixParser : public Counted { -private: - Ref bitMatrix_; - Version *parsedVersion_; - Ref parsedFormatInfo_; - - int copyBit(size_t x, size_t y, int versionBits); - -public: - BitMatrixParser(Ref bitMatrix); - Ref readFormatInformation(); - Version *readVersion(); - ArrayRef readCodewords(); - -private: - BitMatrixParser(const BitMatrixParser&); - BitMatrixParser& operator =(const BitMatrixParser&); - -}; - -} -} - -#endif // __BIT_MATRIX_PARSER_H__ +#ifndef __BIT_MATRIX_PARSER_H__ +#define __BIT_MATRIX_PARSER_H__ + +/* + * BitMatrixParser.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +namespace zxing { +namespace qrcode { + +class BitMatrixParser : public Counted { +private: + Ref bitMatrix_; + Version *parsedVersion_; + Ref parsedFormatInfo_; + + int copyBit(size_t x, size_t y, int versionBits); + +public: + BitMatrixParser(Ref bitMatrix); + Ref readFormatInformation(); + Version *readVersion(); + ArrayRef readCodewords(); + +private: + BitMatrixParser(const BitMatrixParser&); + BitMatrixParser& operator =(const BitMatrixParser&); + +}; + +} +} + +#endif // __BIT_MATRIX_PARSER_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/DataBlock.h b/symbian/QZXing/source/zxing/qrcode/decoder/DataBlock.h index 6c8b462a2..3f0c6cffb 100644 --- a/symbian/QZXing/source/zxing/qrcode/decoder/DataBlock.h +++ b/symbian/QZXing/source/zxing/qrcode/decoder/DataBlock.h @@ -1,50 +1,50 @@ -#ifndef __DATA_BLOCK_H__ -#define __DATA_BLOCK_H__ - -/* - * DataBlock.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -namespace zxing { -namespace qrcode { - -class DataBlock : public Counted { -private: - int numDataCodewords_; - ArrayRef codewords_; - - DataBlock(int numDataCodewords, ArrayRef codewords); - -public: - static std::vector > - getDataBlocks(ArrayRef rawCodewords, Version *version, ErrorCorrectionLevel &ecLevel); - - int getNumDataCodewords(); - ArrayRef getCodewords(); -}; - -} -} - -#endif // __DATA_BLOCK_H__ +#ifndef __DATA_BLOCK_H__ +#define __DATA_BLOCK_H__ + +/* + * DataBlock.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +namespace zxing { +namespace qrcode { + +class DataBlock : public Counted { +private: + int numDataCodewords_; + ArrayRef codewords_; + + DataBlock(int numDataCodewords, ArrayRef codewords); + +public: + static std::vector > + getDataBlocks(ArrayRef rawCodewords, Version *version, ErrorCorrectionLevel &ecLevel); + + int getNumDataCodewords(); + ArrayRef getCodewords(); +}; + +} +} + +#endif // __DATA_BLOCK_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/DataMask.h b/symbian/QZXing/source/zxing/qrcode/decoder/DataMask.h index fa3088b19..06750f043 100644 --- a/symbian/QZXing/source/zxing/qrcode/decoder/DataMask.h +++ b/symbian/QZXing/source/zxing/qrcode/decoder/DataMask.h @@ -1,50 +1,50 @@ -#ifndef __DATA_MASK_H__ -#define __DATA_MASK_H__ - -/* - * DataMask.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include - -namespace zxing { -namespace qrcode { - -class DataMask : public Counted { -private: - static std::vector > DATA_MASKS; - -protected: - -public: - static int buildDataMasks(); - DataMask(); - virtual ~DataMask(); - void unmaskBitMatrix(BitMatrix& matrix, size_t dimension); - virtual bool isMasked(size_t x, size_t y) = 0; - static DataMask& forReference(int reference); -}; - -} -} - -#endif // __DATA_MASK_H__ +#ifndef __DATA_MASK_H__ +#define __DATA_MASK_H__ + +/* + * DataMask.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include + +namespace zxing { +namespace qrcode { + +class DataMask : public Counted { +private: + static std::vector > DATA_MASKS; + +protected: + +public: + static int buildDataMasks(); + DataMask(); + virtual ~DataMask(); + void unmaskBitMatrix(BitMatrix& matrix, size_t dimension); + virtual bool isMasked(size_t x, size_t y) = 0; + static DataMask& forReference(int reference); +}; + +} +} + +#endif // __DATA_MASK_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/DecodedBitStreamParser.cpp b/symbian/QZXing/source/zxing/qrcode/decoder/DecodedBitStreamParser.cpp deleted file mode 100644 index 37e413a48..000000000 --- a/symbian/QZXing/source/zxing/qrcode/decoder/DecodedBitStreamParser.cpp +++ /dev/null @@ -1,402 +0,0 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * DecodedBitStreamParser.cpp - * zxing - * - * Created by Christian Brunschen on 20/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#ifndef NO_ICONV -#include -#endif - -// Required for compatibility. TODO: test on Symbian -#ifdef ZXING_ICONV_CONST -#undef ICONV_CONST -#define ICONV_CONST const -#endif - -#ifndef ICONV_CONST -#define ICONV_CONST /**/ -#endif - -using namespace std; -using namespace zxing; -using namespace zxing::qrcode; -using namespace zxing::common; - -const char DecodedBitStreamParser::ALPHANUMERIC_CHARS[] = -{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', - 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', - 'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':' -}; - -namespace {int GB2312_SUBSET = 1;} - -void DecodedBitStreamParser::append(std::string &result, - string const& in, - const char *src) { - append(result, (unsigned char const*)in.c_str(), in.length(), src); -} - -void DecodedBitStreamParser::append(std::string &result, - const unsigned char *bufIn, - size_t nIn, - const char *src) { -#ifndef NO_ICONV - if (nIn == 0) { - return; - } - - iconv_t cd = iconv_open(StringUtils::UTF8, src); - if (cd == (iconv_t)-1) { - result.append((const char *)bufIn, nIn); - return; - } - - const int maxOut = 4 * nIn + 1; - unsigned char* bufOut = new unsigned char[maxOut]; - - ICONV_CONST char *fromPtr = (ICONV_CONST char *)bufIn; - size_t nFrom = nIn; - char *toPtr = (char *)bufOut; - size_t nTo = maxOut; - - while (nFrom > 0) { - size_t oneway = iconv(cd, (const char**)&fromPtr, &nFrom, &toPtr, &nTo); - if (oneway == (size_t)(-1)) { - iconv_close(cd); - delete[] bufOut; - throw ReaderException("error converting characters"); - } - } - iconv_close(cd); - - int nResult = maxOut - nTo; - bufOut[nResult] = '\0'; - result.append((const char *)bufOut); - delete[] bufOut; -#else - result.append((const char *)bufIn, nIn); -#endif -} - -void DecodedBitStreamParser::decodeHanziSegment(Ref bits_, - string& result, - int count) { - BitSource& bits (*bits_); - // Don't crash trying to read more bits than we have available. - if (count * 13 > bits.available()) { - throw FormatException(); - } - - // Each character will require 2 bytes. Read the characters as 2-byte pairs - // and decode as GB2312 afterwards - size_t nBytes = 2 * count; - unsigned char* buffer = new unsigned char[nBytes]; - int offset = 0; - while (count > 0) { - // Each 13 bits encodes a 2-byte character - int twoBytes = bits.readBits(13); - int assembledTwoBytes = ((twoBytes / 0x060) << 8) | (twoBytes % 0x060); - if (assembledTwoBytes < 0x003BF) { - // In the 0xA1A1 to 0xAAFE range - assembledTwoBytes += 0x0A1A1; - } else { - // In the 0xB0A1 to 0xFAFE range - assembledTwoBytes += 0x0A6A1; - } - buffer[offset] = (unsigned char) ((assembledTwoBytes >> 8) & 0xFF); - buffer[offset + 1] = (unsigned char) (assembledTwoBytes & 0xFF); - offset += 2; - count--; - } - - try { - append(result, buffer, nBytes, StringUtils::GB2312); - } catch (ReaderException const& re) { - delete [] buffer; - throw FormatException(); - } - - delete [] buffer; - } - -void DecodedBitStreamParser::decodeKanjiSegment(Ref bits, std::string &result, int count) { - // Each character will require 2 bytes. Read the characters as 2-byte pairs - // and decode as Shift_JIS afterwards - size_t nBytes = 2 * count; - unsigned char* buffer = new unsigned char[nBytes]; - int offset = 0; - while (count > 0) { - // Each 13 bits encodes a 2-byte character - - int twoBytes = bits->readBits(13); - int assembledTwoBytes = ((twoBytes / 0x0C0) << 8) | (twoBytes % 0x0C0); - if (assembledTwoBytes < 0x01F00) { - // In the 0x8140 to 0x9FFC range - assembledTwoBytes += 0x08140; - } else { - // In the 0xE040 to 0xEBBF range - assembledTwoBytes += 0x0C140; - } - buffer[offset] = (unsigned char)(assembledTwoBytes >> 8); - buffer[offset + 1] = (unsigned char)assembledTwoBytes; - offset += 2; - count--; - } - - append(result, buffer, nBytes, StringUtils::SHIFT_JIS); - delete[] buffer; -} - -void DecodedBitStreamParser::decodeByteSegment(Ref bits_, - string& result, - int count, - CharacterSetECI* currentCharacterSetECI, - ArrayRef< ArrayRef >& byteSegments, - Hashtable const& hints) { - int nBytes = count; - BitSource& bits (*bits_); - // Don't crash trying to read more bits than we have available. - if (count << 3 > bits.available()) { - throw FormatException(); - } - - ArrayRef bytes_ (count); - unsigned char* readBytes = &(*bytes_)[0]; - for (int i = 0; i < count; i++) { - readBytes[i] = (unsigned char) bits.readBits(8); - } - string encoding; - if (currentCharacterSetECI == 0) { - // The spec isn't clear on this mode; see - // section 6.4.5: t does not say which encoding to assuming - // upon decoding. I have seen ISO-8859-1 used as well as - // Shift_JIS -- without anything like an ECI designator to - // give a hint. - encoding = StringUtils::guessEncoding(readBytes, count, hints); - } else { - encoding = currentCharacterSetECI->getEncodingName(); - } - try { - append(result, readBytes, nBytes, encoding.c_str()); - } catch (ReaderException const& re) { - throw FormatException(); - } - byteSegments->values().push_back(bytes_); -} - -void DecodedBitStreamParser::decodeNumericSegment(Ref bits, std::string &result, int count) { - int nBytes = count; - unsigned char* bytes = new unsigned char[nBytes]; - int i = 0; - // Read three digits at a time - while (count >= 3) { - // Each 10 bits encodes three digits - if (bits->available() < 10) { - throw ReaderException("format exception"); - } - int threeDigitsBits = bits->readBits(10); - if (threeDigitsBits >= 1000) { - ostringstream s; - s << "Illegal value for 3-digit unit: " << threeDigitsBits; - delete[] bytes; - throw ReaderException(s.str().c_str()); - } - bytes[i++] = ALPHANUMERIC_CHARS[threeDigitsBits / 100]; - bytes[i++] = ALPHANUMERIC_CHARS[(threeDigitsBits / 10) % 10]; - bytes[i++] = ALPHANUMERIC_CHARS[threeDigitsBits % 10]; - count -= 3; - } - if (count == 2) { - if (bits->available() < 7) { - throw ReaderException("format exception"); - } - // Two digits left over to read, encoded in 7 bits - int twoDigitsBits = bits->readBits(7); - if (twoDigitsBits >= 100) { - ostringstream s; - s << "Illegal value for 2-digit unit: " << twoDigitsBits; - delete[] bytes; - throw ReaderException(s.str().c_str()); - } - bytes[i++] = ALPHANUMERIC_CHARS[twoDigitsBits / 10]; - bytes[i++] = ALPHANUMERIC_CHARS[twoDigitsBits % 10]; - } else if (count == 1) { - if (bits->available() < 4) { - throw ReaderException("format exception"); - } - // One digit left over to read - int digitBits = bits->readBits(4); - if (digitBits >= 10) { - ostringstream s; - s << "Illegal value for digit unit: " << digitBits; - delete[] bytes; - throw ReaderException(s.str().c_str()); - } - bytes[i++] = ALPHANUMERIC_CHARS[digitBits]; - } - append(result, bytes, nBytes, StringUtils::ASCII); - delete[] bytes; -} - -char DecodedBitStreamParser::toAlphaNumericChar(size_t value) { - if (value >= sizeof(DecodedBitStreamParser::ALPHANUMERIC_CHARS)) { - throw FormatException(); - } - return ALPHANUMERIC_CHARS[value]; -} - -void DecodedBitStreamParser::decodeAlphanumericSegment(Ref bits_, - string& result, - int count, - bool fc1InEffect) { - BitSource& bits (*bits_); - ostringstream bytes; - // Read two characters at a time - while (count > 1) { - int nextTwoCharsBits = bits.readBits(11); - bytes << toAlphaNumericChar(nextTwoCharsBits / 45); - bytes << toAlphaNumericChar(nextTwoCharsBits % 45); - count -= 2; - } - if (count == 1) { - // special case: one character left - bytes << toAlphaNumericChar(bits.readBits(6)); - } - // See section 6.4.8.1, 6.4.8.2 - string s = bytes.str(); - if (fc1InEffect) { - // We need to massage the result a bit if in an FNC1 mode: - ostringstream r; - for (size_t i = 0; i < s.length(); i++) { - if (s[i] != '%') { - r << s[i]; - } else { - if (i < s.length() - 1 && s[i + 1] == '%') { - // %% is rendered as % - r << s[i++]; - } else { - // In alpha mode, % should be converted to FNC1 separator 0x1D - r << (char)0x1D; - } - } - } - s = r.str(); - } - append(result, s, StringUtils::ASCII); -} - -namespace { - int parseECIValue(BitSource bits) { - int firstByte = bits.readBits(8); - if ((firstByte & 0x80) == 0) { - // just one byte - return firstByte & 0x7F; - } - if ((firstByte & 0xC0) == 0x80) { - // two bytes - int secondByte = bits.readBits(8); - return ((firstByte & 0x3F) << 8) | secondByte; - } - if ((firstByte & 0xE0) == 0xC0) { - // three bytes - int secondThirdBytes = bits.readBits(16); - return ((firstByte & 0x1F) << 16) | secondThirdBytes; - } - throw IllegalArgumentException("Bad ECI bits starting with byte " + firstByte); - } -} - -Ref -DecodedBitStreamParser::decode(ArrayRef bytes, - Version* version, - ErrorCorrectionLevel const& ecLevel, - Hashtable const& hints) { - Ref bits_ (new BitSource(bytes)); - BitSource& bits (*bits_); - string result; - CharacterSetECI* currentCharacterSetECI = 0; - bool fc1InEffect = false; - ArrayRef< ArrayRef > byteSegments (size_t(0)); - Mode* mode = 0; - do { - // While still another segment to read... - if (bits.available() < 4) { - // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here - mode = &Mode::TERMINATOR; - } else { - try { - mode = &Mode::forBits(bits.readBits(4)); // mode is encoded by 4 bits - } catch (IllegalArgumentException const& iae) { - throw iae; - // throw FormatException.getFormatInstance(); - } - } - if (mode != &Mode::TERMINATOR) { - if ((mode == &Mode::FNC1_FIRST_POSITION) || (mode == &Mode::FNC1_SECOND_POSITION)) { - // We do little with FNC1 except alter the parsed result a bit according to the spec - fc1InEffect = true; - } else if (mode == &Mode::STRUCTURED_APPEND) { - // not really supported; all we do is ignore it - // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue - bits.readBits(16); - } else if (mode == &Mode::ECI) { - // Count doesn't apply to ECI - int value = parseECIValue(bits); - currentCharacterSetECI = CharacterSetECI::getCharacterSetECIByValue(value); - if (currentCharacterSetECI == 0) { - throw FormatException(); - } - } else { - // First handle Hanzi mode which does not start with character count - if (mode == &Mode::HANZI) { - //chinese mode contains a sub set indicator right after mode indicator - int subset = bits.readBits(4); - int countHanzi = bits.readBits(mode->getCharacterCountBits(version)); - if (subset == GB2312_SUBSET) { - decodeHanziSegment(bits_, result, countHanzi); - } - } else { - // "Normal" QR code modes: - // How many characters will follow, encoded in this mode? - int count = bits.readBits(mode->getCharacterCountBits(version)); - if (mode == &Mode::NUMERIC) { - decodeNumericSegment(bits_, result, count); - } else if (mode == &Mode::ALPHANUMERIC) { - decodeAlphanumericSegment(bits_, result, count, fc1InEffect); - } else if (mode == &Mode::BYTE) { - decodeByteSegment(bits_, result, count, currentCharacterSetECI, byteSegments, hints); - } else if (mode == &Mode::KANJI) { - decodeKanjiSegment(bits_, result, count); - } else { - throw FormatException(); - } - } - } - } - } while (mode != &Mode::TERMINATOR); - - return Ref(new DecoderResult(bytes, Ref(new String(result)), byteSegments, (string)ecLevel)); -} - diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/DecodedBitStreamParser.h b/symbian/QZXing/source/zxing/qrcode/decoder/DecodedBitStreamParser.h index 086c31c96..11702145e 100644 --- a/symbian/QZXing/source/zxing/qrcode/decoder/DecodedBitStreamParser.h +++ b/symbian/QZXing/source/zxing/qrcode/decoder/DecodedBitStreamParser.h @@ -1,72 +1,72 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- - -#ifndef __DECODED_BIT_STREAM_PARSER_H__ -#define __DECODED_BIT_STREAM_PARSER_H__ - -/* - * DecodedBitStreamParser.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace zxing { -namespace qrcode { - -class DecodedBitStreamParser { -public: - typedef std::map Hashtable; - -private: - static char const ALPHANUMERIC_CHARS[]; - static char toAlphaNumericChar(size_t value); - - static void decodeHanziSegment(Ref bits, std::string &result, int count); - static void decodeKanjiSegment(Ref bits, std::string &result, int count); - static void decodeByteSegment(Ref bits, std::string &result, int count); - static void decodeByteSegment(Ref bits_, - std::string& result, - int count, - zxing::common::CharacterSetECI* currentCharacterSetECI, - ArrayRef< ArrayRef >& byteSegments, - Hashtable const& hints); - static void decodeAlphanumericSegment(Ref bits, std::string &result, int count, bool fc1InEffect); - static void decodeNumericSegment(Ref bits, std::string &result, int count); - - static void append(std::string &ost, const unsigned char *bufIn, size_t nIn, const char *src); - static void append(std::string &ost, std::string const& in, const char *src); - -public: - static Ref decode(ArrayRef bytes, - Version *version, - ErrorCorrectionLevel const& ecLevel, - Hashtable const& hints); -}; - -} -} - -#endif // __DECODED_BIT_STREAM_PARSER_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- + +#ifndef __DECODED_BIT_STREAM_PARSER_H__ +#define __DECODED_BIT_STREAM_PARSER_H__ + +/* + * DecodedBitStreamParser.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace zxing { +namespace qrcode { + +class DecodedBitStreamParser { +public: + typedef std::map Hashtable; + +private: + static char const ALPHANUMERIC_CHARS[]; + static char toAlphaNumericChar(size_t value); + + static void decodeHanziSegment(Ref bits, std::string &result, int count); + static void decodeKanjiSegment(Ref bits, std::string &result, int count); + static void decodeByteSegment(Ref bits, std::string &result, int count); + static void decodeByteSegment(Ref bits_, + std::string& result, + int count, + zxing::common::CharacterSetECI* currentCharacterSetECI, + ArrayRef< ArrayRef >& byteSegments, + Hashtable const& hints); + static void decodeAlphanumericSegment(Ref bits, std::string &result, int count, bool fc1InEffect); + static void decodeNumericSegment(Ref bits, std::string &result, int count); + + static void append(std::string &ost, const unsigned char *bufIn, size_t nIn, const char *src); + static void append(std::string &ost, std::string const& in, const char *src); + +public: + static Ref decode(ArrayRef bytes, + Version *version, + ErrorCorrectionLevel const& ecLevel, + Hashtable const& hints); +}; + +} +} + +#endif // __DECODED_BIT_STREAM_PARSER_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/Decoder.h b/symbian/QZXing/source/zxing/qrcode/decoder/Decoder.h index 3b63c98b9..c6312e0cd 100644 --- a/symbian/QZXing/source/zxing/qrcode/decoder/Decoder.h +++ b/symbian/QZXing/source/zxing/qrcode/decoder/Decoder.h @@ -1,47 +1,46 @@ -#ifndef __DECODER_H__ -#define __DECODER_H__ - -/* - * Decoder.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace zxing { -namespace qrcode { - -class Decoder { -private: - ReedSolomonDecoder rsDecoder_; - - void correctErrors(ArrayRef bytes, int numDataCodewords); - -public: - Decoder(); - Ref decode(Ref bits); -}; - -} -} - -#endif // __DECODER_H__ +#ifndef __DECODER_H__ +#define __DECODER_H__ + +/* + * Decoder.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +namespace zxing { +namespace qrcode { + +class Decoder { +private: + ReedSolomonDecoder rsDecoder_; + + void correctErrors(ArrayRef bytes, int numDataCodewords); + +public: + Decoder(); + Ref decode(Ref bits); +}; + +} +} + +#endif // __DECODER_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/Mode.h b/symbian/QZXing/source/zxing/qrcode/decoder/Mode.h index e75a10b7a..424f9d2fd 100644 --- a/symbian/QZXing/source/zxing/qrcode/decoder/Mode.h +++ b/symbian/QZXing/source/zxing/qrcode/decoder/Mode.h @@ -1,58 +1,58 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __MODE_H__ -#define __MODE_H__ - -/* - * Mode.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { -namespace qrcode { - -class Mode { -private: - int characterCountBitsForVersions0To9_; - int characterCountBitsForVersions10To26_; - int characterCountBitsForVersions27AndHigher_; - int bits_; - std::string name_; - - Mode(int cbv0_9, int cbv10_26, int cbv27, int bits, char const* name); - -public: - static Mode TERMINATOR; - static Mode NUMERIC; - static Mode ALPHANUMERIC; - static Mode STRUCTURED_APPEND; - static Mode BYTE; - static Mode ECI; - static Mode KANJI; - static Mode FNC1_FIRST_POSITION; - static Mode FNC1_SECOND_POSITION; - static Mode HANZI; - - static Mode& forBits(int bits); - int getCharacterCountBits(Version *version); -}; -} -} - -#endif // __MODE_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __MODE_H__ +#define __MODE_H__ + +/* + * Mode.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { +namespace qrcode { + +class Mode { +private: + int characterCountBitsForVersions0To9_; + int characterCountBitsForVersions10To26_; + int characterCountBitsForVersions27AndHigher_; + int bits_; + std::string name_; + + Mode(int cbv0_9, int cbv10_26, int cbv27, int bits, char const* name); + +public: + static Mode TERMINATOR; + static Mode NUMERIC; + static Mode ALPHANUMERIC; + static Mode STRUCTURED_APPEND; + static Mode BYTE; + static Mode ECI; + static Mode KANJI; + static Mode FNC1_FIRST_POSITION; + static Mode FNC1_SECOND_POSITION; + static Mode HANZI; + + static Mode& forBits(int bits); + int getCharacterCountBits(Version *version); +}; +} +} + +#endif // __MODE_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/BitMatrixParser.cpp b/symbian/QZXing/source/zxing/qrcode/decoder/QRBitMatrixParser.cpp similarity index 96% rename from symbian/QZXing/source/zxing/qrcode/decoder/BitMatrixParser.cpp rename to symbian/QZXing/source/zxing/qrcode/decoder/QRBitMatrixParser.cpp index 8554a1cd3..07324b1ce 100644 --- a/symbian/QZXing/source/zxing/qrcode/decoder/BitMatrixParser.cpp +++ b/symbian/QZXing/source/zxing/qrcode/decoder/QRBitMatrixParser.cpp @@ -1,186 +1,186 @@ -/* - * BitMatrixParser.cpp - * zxing - * - * Created by Christian Brunschen on 20/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - - -namespace zxing { -namespace qrcode { - -int BitMatrixParser::copyBit(size_t x, size_t y, int versionBits) { - return bitMatrix_->get(x, y) ? (versionBits << 1) | 0x1 : versionBits << 1; -} - -BitMatrixParser::BitMatrixParser(Ref bitMatrix) : - bitMatrix_(bitMatrix), parsedVersion_(0), parsedFormatInfo_() { - size_t dimension = bitMatrix->getDimension(); - if ((dimension < 21) || (dimension & 0x03) != 1) { - throw ReaderException("Dimension must be 1 mod 4 and >= 21"); - } -} - -Ref BitMatrixParser::readFormatInformation() { - if (parsedFormatInfo_ != 0) { - return parsedFormatInfo_; - } - - // Read top-left format info bits - int formatInfoBits1 = 0; - for (int i = 0; i < 6; i++) { - formatInfoBits1 = copyBit(i, 8, formatInfoBits1); - } - // .. and skip a bit in the timing pattern ... - formatInfoBits1 = copyBit(7, 8, formatInfoBits1); - formatInfoBits1 = copyBit(8, 8, formatInfoBits1); - formatInfoBits1 = copyBit(8, 7, formatInfoBits1); - // .. and skip a bit in the timing pattern ... - for (int j = 5; j >= 0; j--) { - formatInfoBits1 = copyBit(8, j, formatInfoBits1); - } - - // Read the top-right/bottom-left pattern - int dimension = bitMatrix_->getDimension(); - int formatInfoBits2 = 0; - int jMin = dimension - 7; - for (int j = dimension - 1; j >= jMin; j--) { - formatInfoBits2 = copyBit(8, j, formatInfoBits2); - } - for (int i = dimension - 8; i < dimension; i++) { - formatInfoBits2 = copyBit(i, 8, formatInfoBits2); - } - - parsedFormatInfo_ = FormatInformation::decodeFormatInformation(formatInfoBits1,formatInfoBits2); - if (parsedFormatInfo_ != 0) { - return parsedFormatInfo_; - } - throw ReaderException("Could not decode format information"); -} - -Version *BitMatrixParser::readVersion() { - if (parsedVersion_ != 0) { - return parsedVersion_; - } - - int dimension = bitMatrix_->getDimension(); - - int provisionalVersion = (dimension - 17) >> 2; - if (provisionalVersion <= 6) { - return Version::getVersionForNumber(provisionalVersion); - } - - // Read top-right version info: 3 wide by 6 tall - int versionBits = 0; - for (int y = 5; y >= 0; y--) { - int xMin = dimension - 11; - for (int x = dimension - 9; x >= xMin; x--) { - versionBits = copyBit(x, y, versionBits); - } - } - - parsedVersion_ = Version::decodeVersionInformation(versionBits); - if (parsedVersion_ != 0 && parsedVersion_->getDimensionForVersion() == dimension) { - return parsedVersion_; - } - - // Hmm, failed. Try bottom left: 6 wide by 3 tall - versionBits = 0; - for (int x = 5; x >= 0; x--) { - int yMin = dimension - 11; - for (int y = dimension - 9; y >= yMin; y--) { - versionBits = copyBit(x, y, versionBits); - } - } - - parsedVersion_ = Version::decodeVersionInformation(versionBits); - if (parsedVersion_ != 0 && parsedVersion_->getDimensionForVersion() == dimension) { - return parsedVersion_; - } - throw ReaderException("Could not decode version"); -} - -ArrayRef BitMatrixParser::readCodewords() { - Ref formatInfo = readFormatInformation(); - Version *version = readVersion(); - - - // cerr << *bitMatrix_ << endl; - // cerr << bitMatrix_->getDimension() << endl; - - // Get the data mask for the format used in this QR Code. This will exclude - // some bits from reading as we wind through the bit matrix. - DataMask &dataMask = DataMask::forReference((int)formatInfo->getDataMask()); - // cout << (int)formatInfo->getDataMask() << endl; - int dimension = bitMatrix_->getDimension(); - dataMask.unmaskBitMatrix(*bitMatrix_, dimension); - - - // cerr << *bitMatrix_ << endl; - // cerr << version->getTotalCodewords() << endl; - - Ref functionPattern = version->buildFunctionPattern(); - - - // cout << *functionPattern << endl; - - bool readingUp = true; - ArrayRef result(version->getTotalCodewords()); - int resultOffset = 0; - int currentByte = 0; - int bitsRead = 0; - // Read columns in pairs, from right to left - for (int x = dimension - 1; x > 0; x -= 2) { - if (x == 6) { - // Skip whole column with vertical alignment pattern; - // saves time and makes the other code proceed more cleanly - x--; - } - // Read alternatingly from bottom to top then top to bottom - for (int counter = 0; counter < dimension; counter++) { - int y = readingUp ? dimension - 1 - counter : counter; - for (int col = 0; col < 2; col++) { - // Ignore bits covered by the function pattern - if (!functionPattern->get(x - col, y)) { - // Read a bit - bitsRead++; - currentByte <<= 1; - if (bitMatrix_->get(x - col, y)) { - currentByte |= 1; - } - // If we've made a whole byte, save it off - if (bitsRead == 8) { - result[resultOffset++] = (unsigned char)currentByte; - bitsRead = 0; - currentByte = 0; - } - } - } - } - readingUp = !readingUp; // switch directions - } - - if (resultOffset != version->getTotalCodewords()) { - throw ReaderException("Did not read all codewords"); - } - return result; -} - -} -} +/* + * BitMatrixParser.cpp + * zxing + * + * Created by Christian Brunschen on 20/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + + +namespace zxing { +namespace qrcode { + +int BitMatrixParser::copyBit(size_t x, size_t y, int versionBits) { + return bitMatrix_->get(x, y) ? (versionBits << 1) | 0x1 : versionBits << 1; +} + +BitMatrixParser::BitMatrixParser(Ref bitMatrix) : + bitMatrix_(bitMatrix), parsedVersion_(0), parsedFormatInfo_() { + size_t dimension = bitMatrix->getDimension(); + if ((dimension < 21) || (dimension & 0x03) != 1) { + throw ReaderException("Dimension must be 1 mod 4 and >= 21"); + } +} + +Ref BitMatrixParser::readFormatInformation() { + if (parsedFormatInfo_ != 0) { + return parsedFormatInfo_; + } + + // Read top-left format info bits + int formatInfoBits1 = 0; + for (int i = 0; i < 6; i++) { + formatInfoBits1 = copyBit(i, 8, formatInfoBits1); + } + // .. and skip a bit in the timing pattern ... + formatInfoBits1 = copyBit(7, 8, formatInfoBits1); + formatInfoBits1 = copyBit(8, 8, formatInfoBits1); + formatInfoBits1 = copyBit(8, 7, formatInfoBits1); + // .. and skip a bit in the timing pattern ... + for (int j = 5; j >= 0; j--) { + formatInfoBits1 = copyBit(8, j, formatInfoBits1); + } + + // Read the top-right/bottom-left pattern + int dimension = bitMatrix_->getDimension(); + int formatInfoBits2 = 0; + int jMin = dimension - 7; + for (int j = dimension - 1; j >= jMin; j--) { + formatInfoBits2 = copyBit(8, j, formatInfoBits2); + } + for (int i = dimension - 8; i < dimension; i++) { + formatInfoBits2 = copyBit(i, 8, formatInfoBits2); + } + + parsedFormatInfo_ = FormatInformation::decodeFormatInformation(formatInfoBits1,formatInfoBits2); + if (parsedFormatInfo_ != 0) { + return parsedFormatInfo_; + } + throw ReaderException("Could not decode format information"); +} + +Version *BitMatrixParser::readVersion() { + if (parsedVersion_ != 0) { + return parsedVersion_; + } + + int dimension = bitMatrix_->getDimension(); + + int provisionalVersion = (dimension - 17) >> 2; + if (provisionalVersion <= 6) { + return Version::getVersionForNumber(provisionalVersion); + } + + // Read top-right version info: 3 wide by 6 tall + int versionBits = 0; + for (int y = 5; y >= 0; y--) { + int xMin = dimension - 11; + for (int x = dimension - 9; x >= xMin; x--) { + versionBits = copyBit(x, y, versionBits); + } + } + + parsedVersion_ = Version::decodeVersionInformation(versionBits); + if (parsedVersion_ != 0 && parsedVersion_->getDimensionForVersion() == dimension) { + return parsedVersion_; + } + + // Hmm, failed. Try bottom left: 6 wide by 3 tall + versionBits = 0; + for (int x = 5; x >= 0; x--) { + int yMin = dimension - 11; + for (int y = dimension - 9; y >= yMin; y--) { + versionBits = copyBit(x, y, versionBits); + } + } + + parsedVersion_ = Version::decodeVersionInformation(versionBits); + if (parsedVersion_ != 0 && parsedVersion_->getDimensionForVersion() == dimension) { + return parsedVersion_; + } + throw ReaderException("Could not decode version"); +} + +ArrayRef BitMatrixParser::readCodewords() { + Ref formatInfo = readFormatInformation(); + Version *version = readVersion(); + + + // cerr << *bitMatrix_ << endl; + // cerr << bitMatrix_->getDimension() << endl; + + // Get the data mask for the format used in this QR Code. This will exclude + // some bits from reading as we wind through the bit matrix. + DataMask &dataMask = DataMask::forReference((int)formatInfo->getDataMask()); + // cout << (int)formatInfo->getDataMask() << endl; + int dimension = bitMatrix_->getDimension(); + dataMask.unmaskBitMatrix(*bitMatrix_, dimension); + + + // cerr << *bitMatrix_ << endl; + // cerr << version->getTotalCodewords() << endl; + + Ref functionPattern = version->buildFunctionPattern(); + + + // cout << *functionPattern << endl; + + bool readingUp = true; + ArrayRef result(version->getTotalCodewords()); + int resultOffset = 0; + int currentByte = 0; + int bitsRead = 0; + // Read columns in pairs, from right to left + for (int x = dimension - 1; x > 0; x -= 2) { + if (x == 6) { + // Skip whole column with vertical alignment pattern; + // saves time and makes the other code proceed more cleanly + x--; + } + // Read alternatingly from bottom to top then top to bottom + for (int counter = 0; counter < dimension; counter++) { + int y = readingUp ? dimension - 1 - counter : counter; + for (int col = 0; col < 2; col++) { + // Ignore bits covered by the function pattern + if (!functionPattern->get(x - col, y)) { + // Read a bit + bitsRead++; + currentByte <<= 1; + if (bitMatrix_->get(x - col, y)) { + currentByte |= 1; + } + // If we've made a whole byte, save it off + if (bitsRead == 8) { + result[resultOffset++] = (unsigned char)currentByte; + bitsRead = 0; + currentByte = 0; + } + } + } + } + readingUp = !readingUp; // switch directions + } + + if (resultOffset != version->getTotalCodewords()) { + throw ReaderException("Did not read all codewords"); + } + return result; +} + +} +} diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/DataBlock.cpp b/symbian/QZXing/source/zxing/qrcode/decoder/QRDataBlock.cpp similarity index 97% rename from symbian/QZXing/source/zxing/qrcode/decoder/DataBlock.cpp rename to symbian/QZXing/source/zxing/qrcode/decoder/QRDataBlock.cpp index 1ea6602d7..0ac80313c 100644 --- a/symbian/QZXing/source/zxing/qrcode/decoder/DataBlock.cpp +++ b/symbian/QZXing/source/zxing/qrcode/decoder/QRDataBlock.cpp @@ -1,118 +1,118 @@ -/* - * DataBlock.cpp - * zxing - * - * Created by Christian Brunschen on 19/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { -namespace qrcode { - -using namespace std; - -DataBlock::DataBlock(int numDataCodewords, ArrayRef codewords) : - numDataCodewords_(numDataCodewords), codewords_(codewords) { -} - -int DataBlock::getNumDataCodewords() { - return numDataCodewords_; -} - -ArrayRef DataBlock::getCodewords() { - return codewords_; -} - - -std::vector > DataBlock::getDataBlocks(ArrayRef rawCodewords, Version *version, - ErrorCorrectionLevel &ecLevel) { - - - // Figure out the number and size of data blocks used by this version and - // error correction level - ECBlocks &ecBlocks = version->getECBlocksForLevel(ecLevel); - - - // First count the total number of data blocks - int totalBlocks = 0; - vector ecBlockArray = ecBlocks.getECBlocks(); - for (size_t i = 0; i < ecBlockArray.size(); i++) { - totalBlocks += ecBlockArray[i]->getCount(); - } - - // Now establish DataBlocks of the appropriate size and number of data codewords - std::vector > result(totalBlocks); - int numResultBlocks = 0; - for (size_t j = 0; j < ecBlockArray.size(); j++) { - ECB *ecBlock = ecBlockArray[j]; - for (int i = 0; i < ecBlock->getCount(); i++) { - int numDataCodewords = ecBlock->getDataCodewords(); - int numBlockCodewords = ecBlocks.getECCodewords() + numDataCodewords; - ArrayRef buffer(numBlockCodewords); - Ref blockRef(new DataBlock(numDataCodewords, buffer)); - result[numResultBlocks++] = blockRef; - } - } - - // All blocks have the same amount of data, except that the last n - // (where n may be 0) have 1 more byte. Figure out where these start. - int shorterBlocksTotalCodewords = result[0]->codewords_.size(); - int longerBlocksStartAt = result.size() - 1; - while (longerBlocksStartAt >= 0) { - int numCodewords = result[longerBlocksStartAt]->codewords_.size(); - if (numCodewords == shorterBlocksTotalCodewords) { - break; - } - if (numCodewords != shorterBlocksTotalCodewords + 1) { - throw IllegalArgumentException("Data block sizes differ by more than 1"); - } - longerBlocksStartAt--; - } - longerBlocksStartAt++; - - int shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.getECCodewords(); - // The last elements of result may be 1 element longer; - // first fill out as many elements as all of them have - int rawCodewordsOffset = 0; - for (int i = 0; i < shorterBlocksNumDataCodewords; i++) { - for (int j = 0; j < numResultBlocks; j++) { - result[j]->codewords_[i] = rawCodewords[rawCodewordsOffset++]; - } - } - // Fill out the last data block in the longer ones - for (int j = longerBlocksStartAt; j < numResultBlocks; j++) { - result[j]->codewords_[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++]; - } - // Now add in error correction blocks - int max = result[0]->codewords_.size(); - for (int i = shorterBlocksNumDataCodewords; i < max; i++) { - for (int j = 0; j < numResultBlocks; j++) { - int iOffset = j < longerBlocksStartAt ? i : i + 1; - result[j]->codewords_[iOffset] = rawCodewords[rawCodewordsOffset++]; - } - } - - if ((size_t)rawCodewordsOffset != rawCodewords.size()) { - throw IllegalArgumentException("rawCodewordsOffset != rawCodewords.length"); - } - - return result; -} - -} -} +/* + * DataBlock.cpp + * zxing + * + * Created by Christian Brunschen on 19/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { +namespace qrcode { + +using namespace std; + +DataBlock::DataBlock(int numDataCodewords, ArrayRef codewords) : + numDataCodewords_(numDataCodewords), codewords_(codewords) { +} + +int DataBlock::getNumDataCodewords() { + return numDataCodewords_; +} + +ArrayRef DataBlock::getCodewords() { + return codewords_; +} + + +std::vector > DataBlock::getDataBlocks(ArrayRef rawCodewords, Version *version, + ErrorCorrectionLevel &ecLevel) { + + + // Figure out the number and size of data blocks used by this version and + // error correction level + ECBlocks &ecBlocks = version->getECBlocksForLevel(ecLevel); + + + // First count the total number of data blocks + int totalBlocks = 0; + vector ecBlockArray = ecBlocks.getECBlocks(); + for (size_t i = 0; i < ecBlockArray.size(); i++) { + totalBlocks += ecBlockArray[i]->getCount(); + } + + // Now establish DataBlocks of the appropriate size and number of data codewords + std::vector > result(totalBlocks); + int numResultBlocks = 0; + for (size_t j = 0; j < ecBlockArray.size(); j++) { + ECB *ecBlock = ecBlockArray[j]; + for (int i = 0; i < ecBlock->getCount(); i++) { + int numDataCodewords = ecBlock->getDataCodewords(); + int numBlockCodewords = ecBlocks.getECCodewords() + numDataCodewords; + ArrayRef buffer(numBlockCodewords); + Ref blockRef(new DataBlock(numDataCodewords, buffer)); + result[numResultBlocks++] = blockRef; + } + } + + // All blocks have the same amount of data, except that the last n + // (where n may be 0) have 1 more byte. Figure out where these start. + int shorterBlocksTotalCodewords = result[0]->codewords_.size(); + int longerBlocksStartAt = result.size() - 1; + while (longerBlocksStartAt >= 0) { + int numCodewords = result[longerBlocksStartAt]->codewords_.size(); + if (numCodewords == shorterBlocksTotalCodewords) { + break; + } + if (numCodewords != shorterBlocksTotalCodewords + 1) { + throw IllegalArgumentException("Data block sizes differ by more than 1"); + } + longerBlocksStartAt--; + } + longerBlocksStartAt++; + + int shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.getECCodewords(); + // The last elements of result may be 1 element longer; + // first fill out as many elements as all of them have + int rawCodewordsOffset = 0; + for (int i = 0; i < shorterBlocksNumDataCodewords; i++) { + for (int j = 0; j < numResultBlocks; j++) { + result[j]->codewords_[i] = rawCodewords[rawCodewordsOffset++]; + } + } + // Fill out the last data block in the longer ones + for (int j = longerBlocksStartAt; j < numResultBlocks; j++) { + result[j]->codewords_[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++]; + } + // Now add in error correction blocks + int max = result[0]->codewords_.size(); + for (int i = shorterBlocksNumDataCodewords; i < max; i++) { + for (int j = 0; j < numResultBlocks; j++) { + int iOffset = j < longerBlocksStartAt ? i : i + 1; + result[j]->codewords_[iOffset] = rawCodewords[rawCodewordsOffset++]; + } + } + + if ((size_t)rawCodewordsOffset != rawCodewords.size()) { + throw IllegalArgumentException("rawCodewordsOffset != rawCodewords.length"); + } + + return result; +} + +} +} diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/DataMask.cpp b/symbian/QZXing/source/zxing/qrcode/decoder/QRDataMask.cpp similarity index 94% rename from symbian/QZXing/source/zxing/qrcode/decoder/DataMask.cpp rename to symbian/QZXing/source/zxing/qrcode/decoder/QRDataMask.cpp index 9b293b13c..090cd7133 100644 --- a/symbian/QZXing/source/zxing/qrcode/decoder/DataMask.cpp +++ b/symbian/QZXing/source/zxing/qrcode/decoder/QRDataMask.cpp @@ -1,159 +1,159 @@ -/* - * DataMask.cpp - * zxing - * - * Created by Christian Brunschen on 19/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include - -namespace zxing { -namespace qrcode { - -using namespace std; - -DataMask::DataMask() { -} - -DataMask::~DataMask() { -} - -vector > DataMask::DATA_MASKS; -static int N_DATA_MASKS = DataMask::buildDataMasks(); - -DataMask &DataMask::forReference(int reference) { - if (reference < 0 || reference > 7) { - throw IllegalArgumentException("reference must be between 0 and 7"); - } - return *DATA_MASKS[reference]; -} - -void DataMask::unmaskBitMatrix(BitMatrix& bits, size_t dimension) { - for (size_t y = 0; y < dimension; y++) { - for (size_t x = 0; x < dimension; x++) { - // TODO: check why the coordinates have to be swapped - if (isMasked(y, x)) { - bits.flip(x, y); - } - } - } -} - -/** - * 000: mask bits for which (x + y) mod 2 == 0 - */ -class DataMask000 : public DataMask { -public: - bool isMasked(size_t x, size_t y) { - // return ((x + y) & 0x01) == 0; - return ((x + y) % 2) == 0; - } -}; - -/** - * 001: mask bits for which x mod 2 == 0 - */ -class DataMask001 : public DataMask { -public: - bool isMasked(size_t x, size_t y) { - // return (x & 0x01) == 0; - return (x % 2) == 0; - } -}; - -/** - * 010: mask bits for which y mod 3 == 0 - */ -class DataMask010 : public DataMask { -public: - bool isMasked(size_t x, size_t y) { - return y % 3 == 0; - } -}; - -/** - * 011: mask bits for which (x + y) mod 3 == 0 - */ -class DataMask011 : public DataMask { -public: - bool isMasked(size_t x, size_t y) { - return (x + y) % 3 == 0; - } -}; - -/** - * 100: mask bits for which (x/2 + y/3) mod 2 == 0 - */ -class DataMask100 : public DataMask { -public: - bool isMasked(size_t x, size_t y) { - // return (((x >> 1) + (y / 3)) & 0x01) == 0; - return (((x >> 1) + (y / 3)) % 2) == 0; - } -}; - -/** - * 101: mask bits for which xy mod 2 + xy mod 3 == 0 - */ -class DataMask101 : public DataMask { -public: - bool isMasked(size_t x, size_t y) { - size_t temp = x * y; - // return (temp & 0x01) + (temp % 3) == 0; - return (temp % 2) + (temp % 3) == 0; - - } -}; - -/** - * 110: mask bits for which (xy mod 2 + xy mod 3) mod 2 == 0 - */ -class DataMask110 : public DataMask { -public: - bool isMasked(size_t x, size_t y) { - size_t temp = x * y; - // return (((temp & 0x01) + (temp % 3)) & 0x01) == 0; - return (((temp % 2) + (temp % 3)) % 2) == 0; - } -}; - -/** - * 111: mask bits for which ((x+y)mod 2 + xy mod 3) mod 2 == 0 - */ -class DataMask111 : public DataMask { -public: - bool isMasked(size_t x, size_t y) { - // return ((((x + y) & 0x01) + ((x * y) % 3)) & 0x01) == 0; - return ((((x + y) % 2) + ((x * y) % 3)) % 2) == 0; - } -}; - -int DataMask::buildDataMasks() { - DATA_MASKS.push_back(Ref (new DataMask000())); - DATA_MASKS.push_back(Ref (new DataMask001())); - DATA_MASKS.push_back(Ref (new DataMask010())); - DATA_MASKS.push_back(Ref (new DataMask011())); - DATA_MASKS.push_back(Ref (new DataMask100())); - DATA_MASKS.push_back(Ref (new DataMask101())); - DATA_MASKS.push_back(Ref (new DataMask110())); - DATA_MASKS.push_back(Ref (new DataMask111())); - return DATA_MASKS.size(); -} - -} -} +/* + * DataMask.cpp + * zxing + * + * Created by Christian Brunschen on 19/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +namespace zxing { +namespace qrcode { + +using namespace std; + +DataMask::DataMask() { +} + +DataMask::~DataMask() { +} + +vector > DataMask::DATA_MASKS; +static int N_DATA_MASKS = DataMask::buildDataMasks(); + +DataMask &DataMask::forReference(int reference) { + if (reference < 0 || reference > 7) { + throw IllegalArgumentException("reference must be between 0 and 7"); + } + return *DATA_MASKS[reference]; +} + +void DataMask::unmaskBitMatrix(BitMatrix& bits, size_t dimension) { + for (size_t y = 0; y < dimension; y++) { + for (size_t x = 0; x < dimension; x++) { + // TODO: check why the coordinates have to be swapped + if (isMasked(y, x)) { + bits.flip(x, y); + } + } + } +} + +/** + * 000: mask bits for which (x + y) mod 2 == 0 + */ +class DataMask000 : public DataMask { +public: + bool isMasked(size_t x, size_t y) { + // return ((x + y) & 0x01) == 0; + return ((x + y) % 2) == 0; + } +}; + +/** + * 001: mask bits for which x mod 2 == 0 + */ +class DataMask001 : public DataMask { +public: + bool isMasked(size_t x, size_t) { + // return (x & 0x01) == 0; + return (x % 2) == 0; + } +}; + +/** + * 010: mask bits for which y mod 3 == 0 + */ +class DataMask010 : public DataMask { +public: + bool isMasked(size_t, size_t y) { + return y % 3 == 0; + } +}; + +/** + * 011: mask bits for which (x + y) mod 3 == 0 + */ +class DataMask011 : public DataMask { +public: + bool isMasked(size_t x, size_t y) { + return (x + y) % 3 == 0; + } +}; + +/** + * 100: mask bits for which (x/2 + y/3) mod 2 == 0 + */ +class DataMask100 : public DataMask { +public: + bool isMasked(size_t x, size_t y) { + // return (((x >> 1) + (y / 3)) & 0x01) == 0; + return (((x >> 1) + (y / 3)) % 2) == 0; + } +}; + +/** + * 101: mask bits for which xy mod 2 + xy mod 3 == 0 + */ +class DataMask101 : public DataMask { +public: + bool isMasked(size_t x, size_t y) { + size_t temp = x * y; + // return (temp & 0x01) + (temp % 3) == 0; + return (temp % 2) + (temp % 3) == 0; + + } +}; + +/** + * 110: mask bits for which (xy mod 2 + xy mod 3) mod 2 == 0 + */ +class DataMask110 : public DataMask { +public: + bool isMasked(size_t x, size_t y) { + size_t temp = x * y; + // return (((temp & 0x01) + (temp % 3)) & 0x01) == 0; + return (((temp % 2) + (temp % 3)) % 2) == 0; + } +}; + +/** + * 111: mask bits for which ((x+y)mod 2 + xy mod 3) mod 2 == 0 + */ +class DataMask111 : public DataMask { +public: + bool isMasked(size_t x, size_t y) { + // return ((((x + y) & 0x01) + ((x * y) % 3)) & 0x01) == 0; + return ((((x + y) % 2) + ((x * y) % 3)) % 2) == 0; + } +}; + +int DataMask::buildDataMasks() { + DATA_MASKS.push_back(Ref (new DataMask000())); + DATA_MASKS.push_back(Ref (new DataMask001())); + DATA_MASKS.push_back(Ref (new DataMask010())); + DATA_MASKS.push_back(Ref (new DataMask011())); + DATA_MASKS.push_back(Ref (new DataMask100())); + DATA_MASKS.push_back(Ref (new DataMask101())); + DATA_MASKS.push_back(Ref (new DataMask110())); + DATA_MASKS.push_back(Ref (new DataMask111())); + return DATA_MASKS.size(); +} + +} +} diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/QRDecodedBitStreamParser.cpp b/symbian/QZXing/source/zxing/qrcode/decoder/QRDecodedBitStreamParser.cpp new file mode 100644 index 000000000..3b119ffce --- /dev/null +++ b/symbian/QZXing/source/zxing/qrcode/decoder/QRDecodedBitStreamParser.cpp @@ -0,0 +1,416 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * DecodedBitStreamParser.cpp + * zxing + * + * Created by Christian Brunschen on 20/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include + +#ifndef NO_ICONV +#include +#endif + +// Required for compatibility. TODO: test on Symbian +#ifdef ZXING_ICONV_CONST +#undef ICONV_CONST +#define ICONV_CONST const +#endif + +#ifndef ICONV_CONST +#define ICONV_CONST /**/ +#endif + +using namespace std; +using namespace zxing; +using namespace zxing::qrcode; +using namespace zxing::common; + +const char DecodedBitStreamParser::ALPHANUMERIC_CHARS[] = +{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', + 'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':' +}; + +namespace {int GB2312_SUBSET = 1;} + +void DecodedBitStreamParser::append(std::string &result, + string const& in, + const char *src) { + append(result, (unsigned char const*)in.c_str(), in.length(), src); +} + +void DecodedBitStreamParser::append(std::string &result, + const unsigned char *bufIn, + size_t nIn, + const char *src) { +#ifndef NO_ICONV + if (nIn == 0) { + return; + } + + iconv_t cd = iconv_open(StringUtils::UTF8, src); + if (cd == (iconv_t)-1) { + result.append((const char *)bufIn, nIn); + return; + } + + const int maxOut = 4 * nIn + 1; + unsigned char* bufOut = new unsigned char[maxOut]; + + /*ICONV_CONST*/ char *fromPtr = (/*ICONV_CONST*/ char *)bufIn; + size_t nFrom = nIn; + char *toPtr = (char *)bufOut; + size_t nTo = maxOut; + + while (nFrom > 0) { +#if defined(Q_OS_SYMBIAN) + size_t oneway = iconv(cd, (const char**)&fromPtr, &nFrom, &toPtr, &nTo); // for Symbian and Mingw +#else + size_t oneway = iconv(cd, (char**)&fromPtr, &nFrom, &toPtr, &nTo); // for Harmattan +#endif + + if (oneway == (size_t)(-1)) { + iconv_close(cd); + delete[] bufOut; + throw ReaderException("error converting characters"); + } + } + iconv_close(cd); + + int nResult = maxOut - nTo; + bufOut[nResult] = '\0'; + result.append((const char *)bufOut); + delete[] bufOut; +#else + result.append((const char *)bufIn, nIn); +#endif +} + +void DecodedBitStreamParser::decodeHanziSegment(Ref bits_, + string& result, + int count) { + BitSource& bits (*bits_); + // Don't crash trying to read more bits than we have available. + if (count * 13 > bits.available()) { + throw FormatException(); + } + + // Each character will require 2 bytes. Read the characters as 2-byte pairs + // and decode as GB2312 afterwards + size_t nBytes = 2 * count; + unsigned char* buffer = new unsigned char[nBytes]; + int offset = 0; + while (count > 0) { + // Each 13 bits encodes a 2-byte character + int twoBytes = bits.readBits(13); + int assembledTwoBytes = ((twoBytes / 0x060) << 8) | (twoBytes % 0x060); + if (assembledTwoBytes < 0x003BF) { + // In the 0xA1A1 to 0xAAFE range + assembledTwoBytes += 0x0A1A1; + } else { + // In the 0xB0A1 to 0xFAFE range + assembledTwoBytes += 0x0A6A1; + } + buffer[offset] = (unsigned char) ((assembledTwoBytes >> 8) & 0xFF); + buffer[offset + 1] = (unsigned char) (assembledTwoBytes & 0xFF); + offset += 2; + count--; + } + + try { + append(result, buffer, nBytes, StringUtils::GB2312); + } catch (ReaderException const& re) { + delete [] buffer; + throw FormatException(); + } + + delete [] buffer; +} + +void DecodedBitStreamParser::decodeKanjiSegment(Ref bits, std::string &result, int count) { + // Each character will require 2 bytes. Read the characters as 2-byte pairs + // and decode as Shift_JIS afterwards + size_t nBytes = 2 * count; + unsigned char* buffer = new unsigned char[nBytes]; + int offset = 0; + while (count > 0) { + // Each 13 bits encodes a 2-byte character + + int twoBytes = bits->readBits(13); + int assembledTwoBytes = ((twoBytes / 0x0C0) << 8) | (twoBytes % 0x0C0); + if (assembledTwoBytes < 0x01F00) { + // In the 0x8140 to 0x9FFC range + assembledTwoBytes += 0x08140; + } else { + // In the 0xE040 to 0xEBBF range + assembledTwoBytes += 0x0C140; + } + buffer[offset] = (unsigned char)(assembledTwoBytes >> 8); + buffer[offset + 1] = (unsigned char)assembledTwoBytes; + offset += 2; + count--; + } + + append(result, buffer, nBytes, StringUtils::SHIFT_JIS); + delete[] buffer; +} + +void DecodedBitStreamParser::decodeByteSegment(Ref bits_, + string& result, + int count, + CharacterSetECI* currentCharacterSetECI, + ArrayRef< ArrayRef >& byteSegments, + Hashtable const& hints) { + int nBytes = count; + BitSource& bits (*bits_); + // Don't crash trying to read more bits than we have available. + if (count << 3 > bits.available()) { + throw FormatException(); + } + + ArrayRef bytes_ (count); + unsigned char* readBytes = &(*bytes_)[0]; + for (int i = 0; i < count; i++) { + readBytes[i] = (unsigned char) bits.readBits(8); + } + string encoding; + if (currentCharacterSetECI == 0) { + // The spec isn't clear on this mode; see + // section 6.4.5: t does not say which encoding to assuming + // upon decoding. I have seen ISO-8859-1 used as well as + // Shift_JIS -- without anything like an ECI designator to + // give a hint. + encoding = StringUtils::guessEncoding(readBytes, count, hints); + } else { + encoding = currentCharacterSetECI->name(); + } + try { + append(result, readBytes, nBytes, encoding.c_str()); + } catch (ReaderException const& re) { + throw FormatException(); + } + byteSegments->values().push_back(bytes_); +} + +void DecodedBitStreamParser::decodeNumericSegment(Ref bits, std::string &result, int count) { + int nBytes = count; + unsigned char* bytes = new unsigned char[nBytes]; + int i = 0; + // Read three digits at a time + while (count >= 3) { + // Each 10 bits encodes three digits + if (bits->available() < 10) { + throw ReaderException("format exception"); + } + int threeDigitsBits = bits->readBits(10); + if (threeDigitsBits >= 1000) { + ostringstream s; + s << "Illegal value for 3-digit unit: " << threeDigitsBits; + delete[] bytes; + throw ReaderException(s.str().c_str()); + } + bytes[i++] = ALPHANUMERIC_CHARS[threeDigitsBits / 100]; + bytes[i++] = ALPHANUMERIC_CHARS[(threeDigitsBits / 10) % 10]; + bytes[i++] = ALPHANUMERIC_CHARS[threeDigitsBits % 10]; + count -= 3; + } + if (count == 2) { + if (bits->available() < 7) { + throw ReaderException("format exception"); + } + // Two digits left over to read, encoded in 7 bits + int twoDigitsBits = bits->readBits(7); + if (twoDigitsBits >= 100) { + ostringstream s; + s << "Illegal value for 2-digit unit: " << twoDigitsBits; + delete[] bytes; + throw ReaderException(s.str().c_str()); + } + bytes[i++] = ALPHANUMERIC_CHARS[twoDigitsBits / 10]; + bytes[i++] = ALPHANUMERIC_CHARS[twoDigitsBits % 10]; + } else if (count == 1) { + if (bits->available() < 4) { + throw ReaderException("format exception"); + } + // One digit left over to read + int digitBits = bits->readBits(4); + if (digitBits >= 10) { + ostringstream s; + s << "Illegal value for digit unit: " << digitBits; + delete[] bytes; + throw ReaderException(s.str().c_str()); + } + bytes[i++] = ALPHANUMERIC_CHARS[digitBits]; + } + append(result, bytes, nBytes, StringUtils::ASCII); + delete[] bytes; +} + +char DecodedBitStreamParser::toAlphaNumericChar(size_t value) { + if (value >= sizeof(DecodedBitStreamParser::ALPHANUMERIC_CHARS)) { + throw FormatException(); + } + return ALPHANUMERIC_CHARS[value]; +} + +void DecodedBitStreamParser::decodeAlphanumericSegment(Ref bits_, + string& result, + int count, + bool fc1InEffect) { + BitSource& bits (*bits_); + ostringstream bytes; + // Read two characters at a time + while (count > 1) { + if (bits.available() < 11) { + throw FormatException(); + } + int nextTwoCharsBits = bits.readBits(11); + bytes << toAlphaNumericChar(nextTwoCharsBits / 45); + bytes << toAlphaNumericChar(nextTwoCharsBits % 45); + count -= 2; + } + if (count == 1) { + // special case: one character left + if (bits.available() < 6) { + throw FormatException(); + } + bytes << toAlphaNumericChar(bits.readBits(6)); + } + // See section 6.4.8.1, 6.4.8.2 + string s = bytes.str(); + if (fc1InEffect) { + // We need to massage the result a bit if in an FNC1 mode: + ostringstream r; + for (size_t i = 0; i < s.length(); i++) { + if (s[i] != '%') { + r << s[i]; + } else { + if (i < s.length() - 1 && s[i + 1] == '%') { + // %% is rendered as % + r << s[i++]; + } else { + // In alpha mode, % should be converted to FNC1 separator 0x1D + r << (char)0x1D; + } + } + } + s = r.str(); + } + append(result, s, StringUtils::ASCII); +} + +namespace { +int parseECIValue(BitSource bits) { + int firstByte = bits.readBits(8); + if ((firstByte & 0x80) == 0) { + // just one byte + return firstByte & 0x7F; + } + if ((firstByte & 0xC0) == 0x80) { + // two bytes + int secondByte = bits.readBits(8); + return ((firstByte & 0x3F) << 8) | secondByte; + } + if ((firstByte & 0xE0) == 0xC0) { + // three bytes + int secondThirdBytes = bits.readBits(16); + return ((firstByte & 0x1F) << 16) | secondThirdBytes; + } + throw FormatException(); +} +} + +Ref +DecodedBitStreamParser::decode(ArrayRef bytes, + Version* version, + ErrorCorrectionLevel const& ecLevel, + Hashtable const& hints) { + Ref bits_ (new BitSource(bytes)); + BitSource& bits (*bits_); + string result; + CharacterSetECI* currentCharacterSetECI = 0; + bool fc1InEffect = false; + ArrayRef< ArrayRef > byteSegments (size_t(0)); + Mode* mode = 0; + do { + // While still another segment to read... + if (bits.available() < 4) { + // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here + mode = &Mode::TERMINATOR; + } else { + try { + mode = &Mode::forBits(bits.readBits(4)); // mode is encoded by 4 bits + } catch (IllegalArgumentException const& iae) { + throw iae; + // throw FormatException.getFormatInstance(); + } + } + if (mode != &Mode::TERMINATOR) { + if ((mode == &Mode::FNC1_FIRST_POSITION) || (mode == &Mode::FNC1_SECOND_POSITION)) { + // We do little with FNC1 except alter the parsed result a bit according to the spec + fc1InEffect = true; + } else if (mode == &Mode::STRUCTURED_APPEND) { + // not really supported; all we do is ignore it + // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue + bits.readBits(16); + } else if (mode == &Mode::ECI) { + // Count doesn't apply to ECI + int value = parseECIValue(bits); + currentCharacterSetECI = CharacterSetECI::getCharacterSetECIByValue(value); + if (currentCharacterSetECI == 0) { + throw FormatException(); + } + } else { + // First handle Hanzi mode which does not start with character count + if (mode == &Mode::HANZI) { + //chinese mode contains a sub set indicator right after mode indicator + int subset = bits.readBits(4); + int countHanzi = bits.readBits(mode->getCharacterCountBits(version)); + if (subset == GB2312_SUBSET) { + decodeHanziSegment(bits_, result, countHanzi); + } + } else { + // "Normal" QR code modes: + // How many characters will follow, encoded in this mode? + int count = bits.readBits(mode->getCharacterCountBits(version)); + if (mode == &Mode::NUMERIC) { + decodeNumericSegment(bits_, result, count); + } else if (mode == &Mode::ALPHANUMERIC) { + decodeAlphanumericSegment(bits_, result, count, fc1InEffect); + } else if (mode == &Mode::BYTE) { + decodeByteSegment(bits_, result, count, currentCharacterSetECI, byteSegments, hints); + } else if (mode == &Mode::KANJI) { + decodeKanjiSegment(bits_, result, count); + } else { + throw FormatException(); + } + } + } + } + } while (mode != &Mode::TERMINATOR); + + return Ref(new DecoderResult(bytes, Ref(new String(result)), byteSegments, (string)ecLevel)); +} + diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/Decoder.cpp b/symbian/QZXing/source/zxing/qrcode/decoder/QRDecoder.cpp similarity index 95% rename from symbian/QZXing/source/zxing/qrcode/decoder/Decoder.cpp rename to symbian/QZXing/source/zxing/qrcode/decoder/QRDecoder.cpp index 7b86e652d..0f1e338f5 100644 --- a/symbian/QZXing/source/zxing/qrcode/decoder/Decoder.cpp +++ b/symbian/QZXing/source/zxing/qrcode/decoder/QRDecoder.cpp @@ -1,102 +1,102 @@ -/* - * Decoder.cpp - * zxing - * - * Created by Christian Brunschen on 20/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace zxing { -namespace qrcode { - -using namespace std; - -Decoder::Decoder() : - rsDecoder_(GF256::QR_CODE_FIELD) { -} - -void Decoder::correctErrors(ArrayRef codewordBytes, int numDataCodewords) { - int numCodewords = codewordBytes->size(); - ArrayRef codewordInts(numCodewords); - for (int i = 0; i < numCodewords; i++) { - codewordInts[i] = codewordBytes[i] & 0xff; - } - int numECCodewords = numCodewords - numDataCodewords; - - try { - rsDecoder_.decode(codewordInts, numECCodewords); - } catch (ReedSolomonException const& ex) { - ReaderException rex(ex.what()); - throw rex; - } - - for (int i = 0; i < numDataCodewords; i++) { - codewordBytes[i] = (unsigned char)codewordInts[i]; - } -} - -Ref Decoder::decode(Ref bits) { - // Construct a parser and read version, error-correction level - BitMatrixParser parser(bits); - - Version *version = parser.readVersion(); - ErrorCorrectionLevel &ecLevel = parser.readFormatInformation()->getErrorCorrectionLevel(); - - - // Read codewords - ArrayRef codewords(parser.readCodewords()); - - - // Separate into data blocks - std::vector > dataBlocks(DataBlock::getDataBlocks(codewords, version, ecLevel)); - - - // Count total number of data bytes - int totalBytes = 0; - for (size_t i = 0; i < dataBlocks.size(); i++) { - totalBytes += dataBlocks[i]->getNumDataCodewords(); - } - ArrayRef resultBytes(totalBytes); - int resultOffset = 0; - - - // Error-correct and copy data blocks together into a stream of bytes - for (size_t j = 0; j < dataBlocks.size(); j++) { - Ref dataBlock(dataBlocks[j]); - ArrayRef codewordBytes = dataBlock->getCodewords(); - int numDataCodewords = dataBlock->getNumDataCodewords(); - correctErrors(codewordBytes, numDataCodewords); - for (int i = 0; i < numDataCodewords; i++) { - resultBytes[resultOffset++] = codewordBytes[i]; - } - } - - return DecodedBitStreamParser::decode(resultBytes, - version, - ecLevel, - DecodedBitStreamParser::Hashtable()); -} - -} -} +/* + * Decoder.cpp + * zxing + * + * Created by Christian Brunschen on 20/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace zxing { +namespace qrcode { + +using namespace std; + +Decoder::Decoder() : + rsDecoder_(GenericGF::QR_CODE_FIELD_256) { +} + +void Decoder::correctErrors(ArrayRef codewordBytes, int numDataCodewords) { + int numCodewords = codewordBytes->size(); + ArrayRef codewordInts(numCodewords); + for (int i = 0; i < numCodewords; i++) { + codewordInts[i] = codewordBytes[i] & 0xff; + } + int numECCodewords = numCodewords - numDataCodewords; + + try { + rsDecoder_.decode(codewordInts, numECCodewords); + } catch (ReedSolomonException const& ex) { + ReaderException rex(ex.what()); + throw rex; + } + + for (int i = 0; i < numDataCodewords; i++) { + codewordBytes[i] = (unsigned char)codewordInts[i]; + } +} + +Ref Decoder::decode(Ref bits) { + // Construct a parser and read version, error-correction level + BitMatrixParser parser(bits); + + Version *version = parser.readVersion(); + ErrorCorrectionLevel &ecLevel = parser.readFormatInformation()->getErrorCorrectionLevel(); + + + // Read codewords + ArrayRef codewords(parser.readCodewords()); + + + // Separate into data blocks + std::vector > dataBlocks(DataBlock::getDataBlocks(codewords, version, ecLevel)); + + + // Count total number of data bytes + int totalBytes = 0; + for (size_t i = 0; i < dataBlocks.size(); i++) { + totalBytes += dataBlocks[i]->getNumDataCodewords(); + } + ArrayRef resultBytes(totalBytes); + int resultOffset = 0; + + + // Error-correct and copy data blocks together into a stream of bytes + for (size_t j = 0; j < dataBlocks.size(); j++) { + Ref dataBlock(dataBlocks[j]); + ArrayRef codewordBytes = dataBlock->getCodewords(); + int numDataCodewords = dataBlock->getNumDataCodewords(); + correctErrors(codewordBytes, numDataCodewords); + for (int i = 0; i < numDataCodewords; i++) { + resultBytes[resultOffset++] = codewordBytes[i]; + } + } + + return DecodedBitStreamParser::decode(resultBytes, + version, + ecLevel, + DecodedBitStreamParser::Hashtable()); +} + +} +} diff --git a/symbian/QZXing/source/zxing/qrcode/decoder/Mode.cpp b/symbian/QZXing/source/zxing/qrcode/decoder/QRMode.cpp similarity index 97% rename from symbian/QZXing/source/zxing/qrcode/decoder/Mode.cpp rename to symbian/QZXing/source/zxing/qrcode/decoder/QRMode.cpp index 67b2f27cd..ce55de3fe 100644 --- a/symbian/QZXing/source/zxing/qrcode/decoder/Mode.cpp +++ b/symbian/QZXing/source/zxing/qrcode/decoder/QRMode.cpp @@ -1,86 +1,86 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * Mode.cpp - * zxing - * - * Created by Christian Brunschen on 19/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include - -using zxing::qrcode::Mode; -using std::ostringstream; - -Mode Mode::TERMINATOR(0, 0, 0, 0x00, "TERMINATOR"); -Mode Mode::NUMERIC(10, 12, 14, 0x01, "NUMERIC"); -Mode Mode::ALPHANUMERIC(9, 11, 13, 0x02, "ALPHANUMERIC"); -Mode Mode::STRUCTURED_APPEND(0, 0, 0, 0x03, "STRUCTURED_APPEND"); -Mode Mode::BYTE(8, 16, 16, 0x04, "BYTE"); -Mode Mode::ECI(0, 0, 0, 0x07, "ECI"); -Mode Mode::KANJI(8, 10, 12, 0x08, "KANJI"); -Mode Mode::FNC1_FIRST_POSITION(0, 0, 0, 0x05, "FNC1_FIRST_POSITION"); -Mode Mode::FNC1_SECOND_POSITION(0, 0, 0, 0x09, "FNC1_SECOND_POSITION"); -Mode Mode::HANZI(8, 10, 12, 0x0D, "HANZI"); - -Mode::Mode(int cbv0_9, int cbv10_26, int cbv27, int bits, char const* name) : - characterCountBitsForVersions0To9_(cbv0_9), characterCountBitsForVersions10To26_(cbv10_26), - characterCountBitsForVersions27AndHigher_(cbv27), bits_(bits), name_(name) { -} - -Mode& Mode::forBits(int bits) { - switch (bits) { - case 0x0: - return TERMINATOR; - case 0x1: - return NUMERIC; - case 0x2: - return ALPHANUMERIC; - case 0x3: - return STRUCTURED_APPEND; - case 0x4: - return BYTE; - case 0x5: - return FNC1_FIRST_POSITION; - case 0x7: - return ECI; - case 0x8: - return KANJI; - case 0x9: - return FNC1_SECOND_POSITION; - case 0xD: - // 0xD is defined in GBT 18284-2000, may not be supported in foreign country - return HANZI; - default: - ostringstream s; - s << "Illegal mode bits: " << bits; - throw ReaderException(s.str().c_str()); - } -} - -int Mode::getCharacterCountBits(Version *version) { - int number = version->getVersionNumber(); - if (number <= 9) { - return characterCountBitsForVersions0To9_; - } else if (number <= 26) { - return characterCountBitsForVersions10To26_; - } else { - return characterCountBitsForVersions27AndHigher_; - } -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * Mode.cpp + * zxing + * + * Created by Christian Brunschen on 19/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +using zxing::qrcode::Mode; +using std::ostringstream; + +Mode Mode::TERMINATOR(0, 0, 0, 0x00, "TERMINATOR"); +Mode Mode::NUMERIC(10, 12, 14, 0x01, "NUMERIC"); +Mode Mode::ALPHANUMERIC(9, 11, 13, 0x02, "ALPHANUMERIC"); +Mode Mode::STRUCTURED_APPEND(0, 0, 0, 0x03, "STRUCTURED_APPEND"); +Mode Mode::BYTE(8, 16, 16, 0x04, "BYTE"); +Mode Mode::ECI(0, 0, 0, 0x07, "ECI"); +Mode Mode::KANJI(8, 10, 12, 0x08, "KANJI"); +Mode Mode::FNC1_FIRST_POSITION(0, 0, 0, 0x05, "FNC1_FIRST_POSITION"); +Mode Mode::FNC1_SECOND_POSITION(0, 0, 0, 0x09, "FNC1_SECOND_POSITION"); +Mode Mode::HANZI(8, 10, 12, 0x0D, "HANZI"); + +Mode::Mode(int cbv0_9, int cbv10_26, int cbv27, int bits, char const* name) : + characterCountBitsForVersions0To9_(cbv0_9), characterCountBitsForVersions10To26_(cbv10_26), + characterCountBitsForVersions27AndHigher_(cbv27), bits_(bits), name_(name) { +} + +Mode& Mode::forBits(int bits) { + switch (bits) { + case 0x0: + return TERMINATOR; + case 0x1: + return NUMERIC; + case 0x2: + return ALPHANUMERIC; + case 0x3: + return STRUCTURED_APPEND; + case 0x4: + return BYTE; + case 0x5: + return FNC1_FIRST_POSITION; + case 0x7: + return ECI; + case 0x8: + return KANJI; + case 0x9: + return FNC1_SECOND_POSITION; + case 0xD: + // 0xD is defined in GBT 18284-2000, may not be supported in foreign country + return HANZI; + default: + ostringstream s; + s << "Illegal mode bits: " << bits; + throw ReaderException(s.str().c_str()); + } +} + +int Mode::getCharacterCountBits(Version *version) { + int number = version->getVersionNumber(); + if (number <= 9) { + return characterCountBitsForVersions0To9_; + } else if (number <= 26) { + return characterCountBitsForVersions10To26_; + } else { + return characterCountBitsForVersions27AndHigher_; + } +} diff --git a/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPattern.h b/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPattern.h index f95b92abe..8767a5990 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPattern.h +++ b/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPattern.h @@ -1,45 +1,45 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- - -#ifndef __ALIGNMENT_PATTERN_H__ -#define __ALIGNMENT_PATTERN_H__ - -/* - * AlignmentPattern.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - namespace qrcode { - - class AlignmentPattern : public ResultPoint { - private: - float estimatedModuleSize_; - - public: - AlignmentPattern(float posX, float posY, float estimatedModuleSize); - bool aboutEquals(float moduleSize, float i, float j) const; - Ref combineEstimate(float i, float j, - float newModuleSize) const; - }; - - } -} - -#endif // __ALIGNMENT_PATTERN_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- + +#ifndef __ALIGNMENT_PATTERN_H__ +#define __ALIGNMENT_PATTERN_H__ + +/* + * AlignmentPattern.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + namespace qrcode { + + class AlignmentPattern : public ResultPoint { + private: + float estimatedModuleSize_; + + public: + AlignmentPattern(float posX, float posY, float estimatedModuleSize); + bool aboutEquals(float moduleSize, float i, float j) const; + Ref combineEstimate(float i, float j, + float newModuleSize) const; + }; + + } +} + +#endif // __ALIGNMENT_PATTERN_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPatternFinder.h b/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPatternFinder.h index dbc7b0ae0..e5e1f42d8 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPatternFinder.h +++ b/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPatternFinder.h @@ -1,68 +1,68 @@ -#ifndef __ALIGNMENT_PATTERN_FINDER_H__ -#define __ALIGNMENT_PATTERN_FINDER_H__ - -/* - * AlignmentPatternFinder.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "AlignmentPattern.h" -#include -#include -#include -#include - -namespace zxing { -namespace qrcode { - -class AlignmentPatternFinder : public Counted { -private: - static int CENTER_QUORUM; - static int MIN_SKIP; - static int MAX_MODULES; - - Ref image_; - std::vector *possibleCenters_; - size_t startX_; - size_t startY_; - size_t width_; - size_t height_; - float moduleSize_; - - static float centerFromEnd(std::vector &stateCount, int end); - bool foundPatternCross(std::vector &stateCount); - - float crossCheckVertical(size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal); - - Ref handlePossibleCenter(std::vector &stateCount, size_t i, size_t j); - -public: - AlignmentPatternFinder(Ref image, size_t startX, size_t startY, size_t width, size_t height, - float moduleSize, Refconst& callback); - ~AlignmentPatternFinder(); - Ref find(); - -private: - AlignmentPatternFinder(const AlignmentPatternFinder&); - AlignmentPatternFinder& operator =(const AlignmentPatternFinder&); - - Ref callback_; -}; -} -} - -#endif // __ALIGNMENT_PATTERN_FINDER_H__ +#ifndef __ALIGNMENT_PATTERN_FINDER_H__ +#define __ALIGNMENT_PATTERN_FINDER_H__ + +/* + * AlignmentPatternFinder.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AlignmentPattern.h" +#include +#include +#include +#include + +namespace zxing { +namespace qrcode { + +class AlignmentPatternFinder : public Counted { +private: + static int CENTER_QUORUM; + static int MIN_SKIP; + static int MAX_MODULES; + + Ref image_; + std::vector *possibleCenters_; + size_t startX_; + size_t startY_; + size_t width_; + size_t height_; + float moduleSize_; + + static float centerFromEnd(std::vector &stateCount, int end); + bool foundPatternCross(std::vector &stateCount); + + float crossCheckVertical(size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal); + + Ref handlePossibleCenter(std::vector &stateCount, size_t i, size_t j); + +public: + AlignmentPatternFinder(Ref image, size_t startX, size_t startY, size_t width, size_t height, + float moduleSize, Refconst& callback); + ~AlignmentPatternFinder(); + Ref find(); + +private: + AlignmentPatternFinder(const AlignmentPatternFinder&); + AlignmentPatternFinder& operator =(const AlignmentPatternFinder&); + + Ref callback_; +}; +} +} + +#endif // __ALIGNMENT_PATTERN_FINDER_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/detector/FinderPattern.h b/symbian/QZXing/source/zxing/qrcode/detector/FinderPattern.h index e23ba5dc0..0e4f35e0c 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/FinderPattern.h +++ b/symbian/QZXing/source/zxing/qrcode/detector/FinderPattern.h @@ -1,47 +1,47 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -#ifndef __FINDER_PATTERN_H__ -#define __FINDER_PATTERN_H__ - -/* - * FinderPattern.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -namespace zxing { - namespace qrcode { - - class FinderPattern : public ResultPoint { - private: - float estimatedModuleSize_; - int count_; - - public: - FinderPattern(float posX, float posY, float estimatedModuleSize); - FinderPattern(float posX, float posY, float estimatedModuleSize, int count); - int getCount() const; - float getEstimatedModuleSize() const; - void incrementCount(); - bool aboutEquals(float moduleSize, float i, float j) const; - Ref combineEstimate(float i, float j, float newModuleSize) const; - }; - } -} - -#endif // __FINDER_PATTERN_H__ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +#ifndef __FINDER_PATTERN_H__ +#define __FINDER_PATTERN_H__ + +/* + * FinderPattern.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace zxing { + namespace qrcode { + + class FinderPattern : public ResultPoint { + private: + float estimatedModuleSize_; + int count_; + + public: + FinderPattern(float posX, float posY, float estimatedModuleSize); + FinderPattern(float posX, float posY, float estimatedModuleSize, int count); + int getCount() const; + float getEstimatedModuleSize() const; + void incrementCount(); + bool aboutEquals(float moduleSize, float i, float j) const; + Ref combineEstimate(float i, float j, float newModuleSize) const; + }; + } +} + +#endif // __FINDER_PATTERN_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternFinder.h b/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternFinder.h index 1d85f9b65..07e78c0ba 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternFinder.h +++ b/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternFinder.h @@ -1,71 +1,71 @@ -#ifndef __FINDER_PATTERN_FINDER_H__ -#define __FINDER_PATTERN_FINDER_H__ - -/* - * FinderPatternFinder.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include - -namespace zxing { - -class DecodeHints; - -namespace qrcode { - -class FinderPatternFinder { -private: - static int CENTER_QUORUM; - -protected: - static int MIN_SKIP; - static int MAX_MODULES; - - Ref image_; - std::vector > possibleCenters_; - bool hasSkipped_; - - Ref callback_; - - /** stateCount must be int[5] */ - static float centerFromEnd(int* stateCount, int end); - static bool foundPatternCross(int* stateCount); - - float crossCheckVertical(size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal); - float crossCheckHorizontal(size_t startJ, size_t centerI, int maxCount, int originalStateCountTotal); - - /** stateCount must be int[5] */ - bool handlePossibleCenter(int* stateCount, size_t i, size_t j); - int findRowSkip(); - bool haveMultiplyConfirmedCenters(); - std::vector > selectBestPatterns(); - static std::vector > orderBestPatterns(std::vector > patterns); -public: - static float distance(Ref p1, Ref p2); - FinderPatternFinder(Ref image, Refconst&); - Ref find(DecodeHints const& hints); -}; -} -} - -#endif // __FINDER_PATTERN_FINDER_H__ +#ifndef __FINDER_PATTERN_FINDER_H__ +#define __FINDER_PATTERN_FINDER_H__ + +/* + * FinderPatternFinder.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +namespace zxing { + +class DecodeHints; + +namespace qrcode { + +class FinderPatternFinder { +private: + static int CENTER_QUORUM; + +protected: + static int MIN_SKIP; + static int MAX_MODULES; + + Ref image_; + std::vector > possibleCenters_; + bool hasSkipped_; + + Ref callback_; + + /** stateCount must be int[5] */ + static float centerFromEnd(int* stateCount, int end); + static bool foundPatternCross(int* stateCount); + + float crossCheckVertical(size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal); + float crossCheckHorizontal(size_t startJ, size_t centerI, int maxCount, int originalStateCountTotal); + + /** stateCount must be int[5] */ + bool handlePossibleCenter(int* stateCount, size_t i, size_t j); + int findRowSkip(); + bool haveMultiplyConfirmedCenters(); + std::vector > selectBestPatterns(); + static std::vector > orderBestPatterns(std::vector > patterns); +public: + static float distance(Ref p1, Ref p2); + FinderPatternFinder(Ref image, Refconst&); + Ref find(DecodeHints const& hints); +}; +} +} + +#endif // __FINDER_PATTERN_FINDER_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternInfo.h b/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternInfo.h index 6d132540c..1c9dbbe0b 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternInfo.h +++ b/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternInfo.h @@ -1,47 +1,47 @@ -#ifndef __FINDER_PATTERN_INFO_H__ -#define __FINDER_PATTERN_INFO_H__ - -/* - * FinderPatternInfo.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -namespace zxing { -namespace qrcode { - -class FinderPatternInfo : public Counted { -private: - Ref bottomLeft_; - Ref topLeft_; - Ref topRight_; - -public: - FinderPatternInfo(std::vector > patternCenters); - - Ref getBottomLeft(); - Ref getTopLeft(); - Ref getTopRight(); -}; -} -} - -#endif // __FINDER_PATTERN_INFO_H__ +#ifndef __FINDER_PATTERN_INFO_H__ +#define __FINDER_PATTERN_INFO_H__ + +/* + * FinderPatternInfo.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +namespace zxing { +namespace qrcode { + +class FinderPatternInfo : public Counted { +private: + Ref bottomLeft_; + Ref topLeft_; + Ref topRight_; + +public: + FinderPatternInfo(std::vector > patternCenters); + + Ref getBottomLeft(); + Ref getTopLeft(); + Ref getTopRight(); +}; +} +} + +#endif // __FINDER_PATTERN_INFO_H__ diff --git a/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPattern.cpp b/symbian/QZXing/source/zxing/qrcode/detector/QRAlignmentPattern.cpp similarity index 97% rename from symbian/QZXing/source/zxing/qrcode/detector/AlignmentPattern.cpp rename to symbian/QZXing/source/zxing/qrcode/detector/QRAlignmentPattern.cpp index d8744939e..0675f9354 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPattern.cpp +++ b/symbian/QZXing/source/zxing/qrcode/detector/QRAlignmentPattern.cpp @@ -1,51 +1,51 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * AlignmentPattern.cpp - * zxing - * - * Created by Christian Brunschen on 13/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { -namespace qrcode { - -using namespace std; - -AlignmentPattern::AlignmentPattern(float posX, float posY, float estimatedModuleSize) : - ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize) { -} - -bool AlignmentPattern::aboutEquals(float moduleSize, float i, float j) const { - if (abs(i - getY()) <= moduleSize && abs(j - getX()) <= moduleSize) { - float moduleSizeDiff = abs(moduleSize - estimatedModuleSize_); - return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize_; - } - return false; -} - -Ref AlignmentPattern::combineEstimate(float i, float j, float newModuleSize) const { - float combinedX = (getX() + j) / 2.0f; - float combinedY = (getY() + i) / 2.0f; - float combinedModuleSize = (estimatedModuleSize_ + newModuleSize) / 2.0f; - Ref result - (new AlignmentPattern(combinedX, combinedY, combinedModuleSize)); - return result; -} - -} -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * AlignmentPattern.cpp + * zxing + * + * Created by Christian Brunschen on 13/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { +namespace qrcode { + +using namespace std; + +AlignmentPattern::AlignmentPattern(float posX, float posY, float estimatedModuleSize) : + ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize) { +} + +bool AlignmentPattern::aboutEquals(float moduleSize, float i, float j) const { + if (abs(i - getY()) <= moduleSize && abs(j - getX()) <= moduleSize) { + float moduleSizeDiff = abs(moduleSize - estimatedModuleSize_); + return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize_; + } + return false; +} + +Ref AlignmentPattern::combineEstimate(float i, float j, float newModuleSize) const { + float combinedX = (getX() + j) / 2.0f; + float combinedY = (getY() + i) / 2.0f; + float combinedModuleSize = (estimatedModuleSize_ + newModuleSize) / 2.0f; + Ref result + (new AlignmentPattern(combinedX, combinedY, combinedModuleSize)); + return result; +} + +} +} diff --git a/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPatternFinder.cpp b/symbian/QZXing/source/zxing/qrcode/detector/QRAlignmentPatternFinder.cpp similarity index 97% rename from symbian/QZXing/source/zxing/qrcode/detector/AlignmentPatternFinder.cpp rename to symbian/QZXing/source/zxing/qrcode/detector/QRAlignmentPatternFinder.cpp index 8aecb2f95..ef821976c 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/AlignmentPatternFinder.cpp +++ b/symbian/QZXing/source/zxing/qrcode/detector/QRAlignmentPatternFinder.cpp @@ -1,209 +1,209 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * AlignmentPatternFinder.cpp - * zxing - * - * Created by Christian Brunschen on 14/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "AlignmentPatternFinder.h" -#include -#include -#include -#include -#include - -namespace zxing { -namespace qrcode { - -using namespace std; - -float AlignmentPatternFinder::centerFromEnd(vector &stateCount, int end) { - return (float)(end - stateCount[2]) - stateCount[1] / 2.0f; -} - -bool AlignmentPatternFinder::foundPatternCross(vector &stateCount) { - float maxVariance = moduleSize_ / 2.0f; - for (size_t i = 0; i < 3; i++) { - if (abs(moduleSize_ - stateCount[i]) >= maxVariance) { - return false; - } - } - return true; -} - -float AlignmentPatternFinder::crossCheckVertical(size_t startI, size_t centerJ, int maxCount, - int originalStateCountTotal) { - int maxI = image_->getHeight(); - vector stateCount(3, 0); - - - // Start counting up from center - int i = startI; - while (i >= 0 && image_->get(centerJ, i) && stateCount[1] <= maxCount) { - stateCount[1]++; - i--; - } - // If already too many modules in this state or ran off the edge: - if (i < 0 || stateCount[1] > maxCount) { - return NAN; - } - while (i >= 0 && !image_->get(centerJ, i) && stateCount[0] <= maxCount) { - stateCount[0]++; - i--; - } - if (stateCount[0] > maxCount) { - return NAN; - } - - // Now also count down from center - i = startI + 1; - while (i < maxI && image_->get(centerJ, i) && stateCount[1] <= maxCount) { - stateCount[1]++; - i++; - } - if (i == maxI || stateCount[1] > maxCount) { - return NAN; - } - while (i < maxI && !image_->get(centerJ, i) && stateCount[2] <= maxCount) { - stateCount[2]++; - i++; - } - if (stateCount[2] > maxCount) { - return NAN; - } - - int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; - if (5 * abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) { - return NAN; - } - - return foundPatternCross(stateCount) ? centerFromEnd(stateCount, i) : NAN; -} - -Ref AlignmentPatternFinder::handlePossibleCenter(vector &stateCount, size_t i, size_t j) { - int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; - float centerJ = centerFromEnd(stateCount, j); - float centerI = crossCheckVertical(i, (int)centerJ, 2 * stateCount[1], stateCountTotal); - if (!isnan(centerI)) { - float estimatedModuleSize = (float)(stateCount[0] + stateCount[1] + stateCount[2]) / 3.0f; - int max = possibleCenters_->size(); - for (int index = 0; index < max; index++) { - Ref center((*possibleCenters_)[index]); - // Look for about the same center and module size: - if (center->aboutEquals(estimatedModuleSize, centerI, centerJ)) { - return center->combineEstimate(centerI, centerJ, estimatedModuleSize); - } - } - AlignmentPattern *tmp = new AlignmentPattern(centerJ, centerI, estimatedModuleSize); - // Hadn't found this before; save it - tmp->retain(); - possibleCenters_->push_back(tmp); - if (callback_ != 0) { - callback_->foundPossibleResultPoint(*tmp); - } - } - Ref result; - return result; -} - -AlignmentPatternFinder::AlignmentPatternFinder(Ref image, size_t startX, size_t startY, size_t width, - size_t height, float moduleSize, - Refconst& callback) : - image_(image), possibleCenters_(new vector ()), startX_(startX), startY_(startY), - width_(width), height_(height), moduleSize_(moduleSize), callback_(callback) { -} - -AlignmentPatternFinder::~AlignmentPatternFinder() { - for (size_t i = 0; i < possibleCenters_->size(); i++) { - (*possibleCenters_)[i]->release(); - (*possibleCenters_)[i] = 0; - } - delete possibleCenters_; -} - -Ref AlignmentPatternFinder::find() { - size_t maxJ = startX_ + width_; - size_t middleI = startY_ + (height_ >> 1); - // Ref luminanceRow(new BitArray(width_)); - // We are looking for black/white/black modules in 1:1:1 ratio; - // this tracks the number of black/white/black modules seen so far - vector stateCount(3, 0); - for (size_t iGen = 0; iGen < height_; iGen++) { - // Search from middle outwards - size_t i = middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1)); - // image_->getBlackRow(i, luminanceRow, startX_, width_); - stateCount[0] = 0; - stateCount[1] = 0; - stateCount[2] = 0; - size_t j = startX_; - // Burn off leading white pixels before anything else; if we start in the middle of - // a white run, it doesn't make sense to count its length, since we don't know if the - // white run continued to the left of the start point - while (j < maxJ && !image_->get(j, i)) { - j++; - } - int currentState = 0; - while (j < maxJ) { - if (image_->get(j, i)) { - // Black pixel - if (currentState == 1) { // Counting black pixels - stateCount[currentState]++; - } else { // Counting white pixels - if (currentState == 2) { // A winner? - if (foundPatternCross(stateCount)) { // Yes - Ref confirmed(handlePossibleCenter(stateCount, i, j)); - if (confirmed != 0) { - return confirmed; - } - } - stateCount[0] = stateCount[2]; - stateCount[1] = 1; - stateCount[2] = 0; - currentState = 1; - } else { - stateCount[++currentState]++; - } - } - } else { // White pixel - if (currentState == 1) { // Counting black pixels - currentState++; - } - stateCount[currentState]++; - } - j++; - } - if (foundPatternCross(stateCount)) { - Ref confirmed(handlePossibleCenter(stateCount, i, maxJ)); - if (confirmed != 0) { - return confirmed; - } - } - - } - - // Hmm, nothing we saw was observed and confirmed twice. If we had - // any guess at all, return it. - if (possibleCenters_->size() > 0) { - Ref center((*possibleCenters_)[0]); - return center; - } - - throw zxing::ReaderException("Could not find alignment pattern"); -} - -} -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * AlignmentPatternFinder.cpp + * zxing + * + * Created by Christian Brunschen on 14/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AlignmentPatternFinder.h" +#include +#include +#include +#include +#include + +namespace zxing { +namespace qrcode { + +using namespace std; + +float AlignmentPatternFinder::centerFromEnd(vector &stateCount, int end) { + return (float)(end - stateCount[2]) - stateCount[1] / 2.0f; +} + +bool AlignmentPatternFinder::foundPatternCross(vector &stateCount) { + float maxVariance = moduleSize_ / 2.0f; + for (size_t i = 0; i < 3; i++) { + if (abs(moduleSize_ - stateCount[i]) >= maxVariance) { + return false; + } + } + return true; +} + +float AlignmentPatternFinder::crossCheckVertical(size_t startI, size_t centerJ, int maxCount, + int originalStateCountTotal) { + int maxI = image_->getHeight(); + vector stateCount(3, 0); + + + // Start counting up from center + int i = startI; + while (i >= 0 && image_->get(centerJ, i) && stateCount[1] <= maxCount) { + stateCount[1]++; + i--; + } + // If already too many modules in this state or ran off the edge: + if (i < 0 || stateCount[1] > maxCount) { + return NAN; + } + while (i >= 0 && !image_->get(centerJ, i) && stateCount[0] <= maxCount) { + stateCount[0]++; + i--; + } + if (stateCount[0] > maxCount) { + return NAN; + } + + // Now also count down from center + i = startI + 1; + while (i < maxI && image_->get(centerJ, i) && stateCount[1] <= maxCount) { + stateCount[1]++; + i++; + } + if (i == maxI || stateCount[1] > maxCount) { + return NAN; + } + while (i < maxI && !image_->get(centerJ, i) && stateCount[2] <= maxCount) { + stateCount[2]++; + i++; + } + if (stateCount[2] > maxCount) { + return NAN; + } + + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; + if (5 * abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) { + return NAN; + } + + return foundPatternCross(stateCount) ? centerFromEnd(stateCount, i) : NAN; +} + +Ref AlignmentPatternFinder::handlePossibleCenter(vector &stateCount, size_t i, size_t j) { + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; + float centerJ = centerFromEnd(stateCount, j); + float centerI = crossCheckVertical(i, (int)centerJ, 2 * stateCount[1], stateCountTotal); + if (!isnan(centerI)) { + float estimatedModuleSize = (float)(stateCount[0] + stateCount[1] + stateCount[2]) / 3.0f; + int max = possibleCenters_->size(); + for (int index = 0; index < max; index++) { + Ref center((*possibleCenters_)[index]); + // Look for about the same center and module size: + if (center->aboutEquals(estimatedModuleSize, centerI, centerJ)) { + return center->combineEstimate(centerI, centerJ, estimatedModuleSize); + } + } + AlignmentPattern *tmp = new AlignmentPattern(centerJ, centerI, estimatedModuleSize); + // Hadn't found this before; save it + tmp->retain(); + possibleCenters_->push_back(tmp); + if (callback_ != 0) { + callback_->foundPossibleResultPoint(*tmp); + } + } + Ref result; + return result; +} + +AlignmentPatternFinder::AlignmentPatternFinder(Ref image, size_t startX, size_t startY, size_t width, + size_t height, float moduleSize, + Refconst& callback) : + image_(image), possibleCenters_(new vector ()), startX_(startX), startY_(startY), + width_(width), height_(height), moduleSize_(moduleSize), callback_(callback) { +} + +AlignmentPatternFinder::~AlignmentPatternFinder() { + for (size_t i = 0; i < possibleCenters_->size(); i++) { + (*possibleCenters_)[i]->release(); + (*possibleCenters_)[i] = 0; + } + delete possibleCenters_; +} + +Ref AlignmentPatternFinder::find() { + size_t maxJ = startX_ + width_; + size_t middleI = startY_ + (height_ >> 1); + // Ref luminanceRow(new BitArray(width_)); + // We are looking for black/white/black modules in 1:1:1 ratio; + // this tracks the number of black/white/black modules seen so far + vector stateCount(3, 0); + for (size_t iGen = 0; iGen < height_; iGen++) { + // Search from middle outwards + size_t i = middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1)); + // image_->getBlackRow(i, luminanceRow, startX_, width_); + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + size_t j = startX_; + // Burn off leading white pixels before anything else; if we start in the middle of + // a white run, it doesn't make sense to count its length, since we don't know if the + // white run continued to the left of the start point + while (j < maxJ && !image_->get(j, i)) { + j++; + } + int currentState = 0; + while (j < maxJ) { + if (image_->get(j, i)) { + // Black pixel + if (currentState == 1) { // Counting black pixels + stateCount[currentState]++; + } else { // Counting white pixels + if (currentState == 2) { // A winner? + if (foundPatternCross(stateCount)) { // Yes + Ref confirmed(handlePossibleCenter(stateCount, i, j)); + if (confirmed != 0) { + return confirmed; + } + } + stateCount[0] = stateCount[2]; + stateCount[1] = 1; + stateCount[2] = 0; + currentState = 1; + } else { + stateCount[++currentState]++; + } + } + } else { // White pixel + if (currentState == 1) { // Counting black pixels + currentState++; + } + stateCount[currentState]++; + } + j++; + } + if (foundPatternCross(stateCount)) { + Ref confirmed(handlePossibleCenter(stateCount, i, maxJ)); + if (confirmed != 0) { + return confirmed; + } + } + + } + + // Hmm, nothing we saw was observed and confirmed twice. If we had + // any guess at all, return it. + if (possibleCenters_->size() > 0) { + Ref center((*possibleCenters_)[0]); + return center; + } + + throw zxing::ReaderException("Could not find alignment pattern"); +} + +} +} diff --git a/symbian/QZXing/source/zxing/qrcode/detector/Detector.cpp b/symbian/QZXing/source/zxing/qrcode/detector/QRDetector.cpp similarity index 96% rename from symbian/QZXing/source/zxing/qrcode/detector/Detector.cpp rename to symbian/QZXing/source/zxing/qrcode/detector/QRDetector.cpp index 952010a28..4a30fce81 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/Detector.cpp +++ b/symbian/QZXing/source/zxing/qrcode/detector/QRDetector.cpp @@ -106,7 +106,7 @@ Ref Detector::processFinderPatternInfo(Ref in points[3].reset(alignmentPattern); } - Ref result(new DetectorResult(bits, points, transform)); + Ref result(new DetectorResult(bits, points)); return result; } diff --git a/symbian/QZXing/source/zxing/qrcode/detector/QREdgeDetector.cpp b/symbian/QZXing/source/zxing/qrcode/detector/QREdgeDetector.cpp index b2162ef50..211f5daf0 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/QREdgeDetector.cpp +++ b/symbian/QZXing/source/zxing/qrcode/detector/QREdgeDetector.cpp @@ -1,7 +1,5 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* - * QREdgeDetector.cpp - * zxing - * * Created by Ralf Kistner on 7/12/2009. * Copyright 2008 ZXing authors All rights reserved. * @@ -61,6 +59,7 @@ Ref QREdgeDetector::createTransform(Ref topLe Point QREdgeDetector::findCorner(const BitMatrix& image, Point topLeft, Point topRight, Point bottomLeft, int dimension) { + (void)dimension; Point bottomRight = guessLastPattern(topLeft, topRight, bottomLeft); Line bottomEst = findPatternEdge(image, bottomLeft, topLeft, bottomRight, false); diff --git a/symbian/QZXing/source/zxing/qrcode/detector/QREdgeDetector.h b/symbian/QZXing/source/zxing/qrcode/detector/QREdgeDetector.h index 898a6df59..026545ffa 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/QREdgeDetector.h +++ b/symbian/QZXing/source/zxing/qrcode/detector/QREdgeDetector.h @@ -1,48 +1,48 @@ #ifndef __QREDGEDETECTOR_H__ #define __QREDGEDETECTOR_H__ -/* - * QREdgeDetector.h - * zxing - * - * Copyright 2010 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * QREdgeDetector.h + * zxing + * + * Copyright 2010 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ - -#include -#include - -namespace zxing { -namespace qrcode { - -class QREdgeDetector : public Detector { -public: - QREdgeDetector(Ref image); - - virtual Ref createTransform(Ref topLeft, Ref topRight, Ref < - ResultPoint > bottomLeft, Ref alignmentPattern, int dimension); - -private: - Point findCorner(const BitMatrix& image, Point topLeft, Point topRight, Point bottomLeft, int dimension); - Line findPatternEdge(const BitMatrix& image, Point pattern, Point opposite, Point direction, bool invert); - - Point endOfReverseBlackWhiteBlackRun(const BitMatrix& image, Point from, Point to); - - Ref get1CornerTransform(Point topLeft, Point topRight, Point bottomLeft, Point corner, int dimension); -}; - -} + + +#include +#include + +namespace zxing { +namespace qrcode { + +class QREdgeDetector : public Detector { +public: + QREdgeDetector(Ref image); + + virtual Ref createTransform(Ref topLeft, Ref topRight, Ref < + ResultPoint > bottomLeft, Ref alignmentPattern, int dimension); + +private: + Point findCorner(const BitMatrix& image, Point topLeft, Point topRight, Point bottomLeft, int dimension); + Line findPatternEdge(const BitMatrix& image, Point pattern, Point opposite, Point direction, bool invert); + + Point endOfReverseBlackWhiteBlackRun(const BitMatrix& image, Point from, Point to); + + Ref get1CornerTransform(Point topLeft, Point topRight, Point bottomLeft, Point corner, int dimension); +}; + +} } #endif // QREDGEDETECTOR_H_ diff --git a/symbian/QZXing/source/zxing/qrcode/detector/FinderPattern.cpp b/symbian/QZXing/source/zxing/qrcode/detector/QRFinderPattern.cpp similarity index 97% rename from symbian/QZXing/source/zxing/qrcode/detector/FinderPattern.cpp rename to symbian/QZXing/source/zxing/qrcode/detector/QRFinderPattern.cpp index 32c64da7f..89eee2338 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/FinderPattern.cpp +++ b/symbian/QZXing/source/zxing/qrcode/detector/QRFinderPattern.cpp @@ -1,71 +1,71 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * FinderPattern.cpp - * zxing - * - * Created by Christian Brunschen on 13/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { - namespace qrcode { - - using namespace std; - - FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize) : - ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(1) { - } - - FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize, int count) : - ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(count) { - } - - int FinderPattern::getCount() const { - return count_; - } - - float FinderPattern::getEstimatedModuleSize() const { - return estimatedModuleSize_; - } - - void FinderPattern::incrementCount() { - count_++; - } - -/* - bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const { - return abs(i - posY_) <= moduleSize && abs(j - posX_) <= moduleSize && (abs(moduleSize - estimatedModuleSize_) - <= 1.0f || abs(moduleSize - estimatedModuleSize_) / estimatedModuleSize_ <= 0.1f); - } -*/ - bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const { - if (abs(i - getY()) <= moduleSize && abs(j - getX()) <= moduleSize) { - float moduleSizeDiff = abs(moduleSize - estimatedModuleSize_); - return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize_; - } - return false; - } - - Ref FinderPattern::combineEstimate(float i, float j, float newModuleSize) const { - int combinedCount = count_ + 1; - float combinedX = (count_ * getX() + j) / combinedCount; - float combinedY = (count_ * getY() + i) / combinedCount; - float combinedModuleSize = (count_ * getEstimatedModuleSize() + newModuleSize) / combinedCount; - return Ref(new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount)); - } - } -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * FinderPattern.cpp + * zxing + * + * Created by Christian Brunschen on 13/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { + namespace qrcode { + + using namespace std; + + FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize) : + ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(1) { + } + + FinderPattern::FinderPattern(float posX, float posY, float estimatedModuleSize, int count) : + ResultPoint(posX,posY), estimatedModuleSize_(estimatedModuleSize), count_(count) { + } + + int FinderPattern::getCount() const { + return count_; + } + + float FinderPattern::getEstimatedModuleSize() const { + return estimatedModuleSize_; + } + + void FinderPattern::incrementCount() { + count_++; + } + +/* + bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const { + return abs(i - posY_) <= moduleSize && abs(j - posX_) <= moduleSize && (abs(moduleSize - estimatedModuleSize_) + <= 1.0f || abs(moduleSize - estimatedModuleSize_) / estimatedModuleSize_ <= 0.1f); + } +*/ + bool FinderPattern::aboutEquals(float moduleSize, float i, float j) const { + if (abs(i - getY()) <= moduleSize && abs(j - getX()) <= moduleSize) { + float moduleSizeDiff = abs(moduleSize - estimatedModuleSize_); + return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize_; + } + return false; + } + + Ref FinderPattern::combineEstimate(float i, float j, float newModuleSize) const { + int combinedCount = count_ + 1; + float combinedX = (count_ * getX() + j) / combinedCount; + float combinedY = (count_ * getY() + i) / combinedCount; + float combinedModuleSize = (count_ * getEstimatedModuleSize() + newModuleSize) / combinedCount; + return Ref(new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount)); + } + } +} diff --git a/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternFinder.cpp b/symbian/QZXing/source/zxing/qrcode/detector/QRFinderPatternFinder.cpp similarity index 97% rename from symbian/QZXing/source/zxing/qrcode/detector/FinderPatternFinder.cpp rename to symbian/QZXing/source/zxing/qrcode/detector/QRFinderPatternFinder.cpp index 35ce976b5..c14e0fdd6 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternFinder.cpp +++ b/symbian/QZXing/source/zxing/qrcode/detector/QRFinderPatternFinder.cpp @@ -1,541 +1,541 @@ -// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- -/* - * FinderPatternFinder.cpp - * zxing - * - * Created by Christian Brunschen on 13/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include - -namespace zxing { -namespace qrcode { - -using namespace std; - -class FurthestFromAverageComparator { -private: - const float averageModuleSize_; -public: - FurthestFromAverageComparator(float averageModuleSize) : - averageModuleSize_(averageModuleSize) { - } - bool operator()(Ref a, Ref b) { - float dA = abs(a->getEstimatedModuleSize() - averageModuleSize_); - float dB = abs(b->getEstimatedModuleSize() - averageModuleSize_); - return dA > dB; - } -}; - -class CenterComparator { - const float averageModuleSize_; -public: - CenterComparator(float averageModuleSize) : - averageModuleSize_(averageModuleSize) { - } - bool operator()(Ref a, Ref b) { - // N.B.: we want the result in descending order ... - if (a->getCount() != b->getCount()) { - return a->getCount() > b->getCount(); - } else { - float dA = abs(a->getEstimatedModuleSize() - averageModuleSize_); - float dB = abs(b->getEstimatedModuleSize() - averageModuleSize_); - return dA < dB; - } - } -}; - -int FinderPatternFinder::CENTER_QUORUM = 2; -int FinderPatternFinder::MIN_SKIP = 3; -int FinderPatternFinder::MAX_MODULES = 57; - -float FinderPatternFinder::centerFromEnd(int* stateCount, int end) { - return (float)(end - stateCount[4] - stateCount[3]) - stateCount[2] / 2.0f; -} - -bool FinderPatternFinder::foundPatternCross(int* stateCount) { - int totalModuleSize = 0; - for (int i = 0; i < 5; i++) { - if (stateCount[i] == 0) { - return false; - } - totalModuleSize += stateCount[i]; - } - if (totalModuleSize < 7) { - return false; - } - float moduleSize = (float)totalModuleSize / 7.0f; - float maxVariance = moduleSize / 2.0f; - // Allow less than 50% variance from 1-1-3-1-1 proportions - return abs(moduleSize - stateCount[0]) < maxVariance && abs(moduleSize - stateCount[1]) < maxVariance && abs(3.0f - * moduleSize - stateCount[2]) < 3.0f * maxVariance && abs(moduleSize - stateCount[3]) < maxVariance && abs( - moduleSize - stateCount[4]) < maxVariance; -} - -float FinderPatternFinder::crossCheckVertical(size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal) { - - int maxI = image_->getHeight(); - int stateCount[5]; - for (int i = 0; i < 5; i++) - stateCount[i] = 0; - - - // Start counting up from center - int i = startI; - while (i >= 0 && image_->get(centerJ, i)) { - stateCount[2]++; - i--; - } - if (i < 0) { - return NAN; - } - while (i >= 0 && !image_->get(centerJ, i) && stateCount[1] <= maxCount) { - stateCount[1]++; - i--; - } - // If already too many modules in this state or ran off the edge: - if (i < 0 || stateCount[1] > maxCount) { - return NAN; - } - while (i >= 0 && image_->get(centerJ, i) && stateCount[0] <= maxCount) { - stateCount[0]++; - i--; - } - if (stateCount[0] > maxCount) { - return NAN; - } - - // Now also count down from center - i = startI + 1; - while (i < maxI && image_->get(centerJ, i)) { - stateCount[2]++; - i++; - } - if (i == maxI) { - return NAN; - } - while (i < maxI && !image_->get(centerJ, i) && stateCount[3] < maxCount) { - stateCount[3]++; - i++; - } - if (i == maxI || stateCount[3] >= maxCount) { - return NAN; - } - while (i < maxI && image_->get(centerJ, i) && stateCount[4] < maxCount) { - stateCount[4]++; - i++; - } - if (stateCount[4] >= maxCount) { - return NAN; - } - - // If we found a finder-pattern-like section, but its size is more than 40% different than - // the original, assume it's a false positive - int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; - if (5 * abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) { - return NAN; - } - - return foundPatternCross(stateCount) ? centerFromEnd(stateCount, i) : NAN; -} - -float FinderPatternFinder::crossCheckHorizontal(size_t startJ, size_t centerI, int maxCount, - int originalStateCountTotal) { - - int maxJ = image_->getWidth(); - int stateCount[5]; - for (int i = 0; i < 5; i++) - stateCount[i] = 0; - - int j = startJ; - while (j >= 0 && image_->get(j, centerI)) { - stateCount[2]++; - j--; - } - if (j < 0) { - return NAN; - } - while (j >= 0 && !image_->get(j, centerI) && stateCount[1] <= maxCount) { - stateCount[1]++; - j--; - } - if (j < 0 || stateCount[1] > maxCount) { - return NAN; - } - while (j >= 0 && image_->get(j, centerI) && stateCount[0] <= maxCount) { - stateCount[0]++; - j--; - } - if (stateCount[0] > maxCount) { - return NAN; - } - - j = startJ + 1; - while (j < maxJ && image_->get(j, centerI)) { - stateCount[2]++; - j++; - } - if (j == maxJ) { - return NAN; - } - while (j < maxJ && !image_->get(j, centerI) && stateCount[3] < maxCount) { - stateCount[3]++; - j++; - } - if (j == maxJ || stateCount[3] >= maxCount) { - return NAN; - } - while (j < maxJ && image_->get(j, centerI) && stateCount[4] < maxCount) { - stateCount[4]++; - j++; - } - if (stateCount[4] >= maxCount) { - return NAN; - } - - // If we found a finder-pattern-like section, but its size is significantly different than - // the original, assume it's a false positive - int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; - if (5 * abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) { - return NAN; - } - - return foundPatternCross(stateCount) ? centerFromEnd(stateCount, j) : NAN; -} - -bool FinderPatternFinder::handlePossibleCenter(int* stateCount, size_t i, size_t j) { - int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; - float centerJ = centerFromEnd(stateCount, j); - float centerI = crossCheckVertical(i, (size_t)centerJ, stateCount[2], stateCountTotal); - if (!isnan(centerI)) { - // Re-cross check - centerJ = crossCheckHorizontal((size_t)centerJ, (size_t)centerI, stateCount[2], stateCountTotal); - if (!isnan(centerJ)) { - float estimatedModuleSize = (float)stateCountTotal / 7.0f; - bool found = false; - size_t max = possibleCenters_.size(); - for (size_t index = 0; index < max; index++) { - Ref center = possibleCenters_[index]; - // Look for about the same center and module size: - if (center->aboutEquals(estimatedModuleSize, centerI, centerJ)) { - possibleCenters_[index] = center->combineEstimate(centerI, centerJ, estimatedModuleSize); - found = true; - break; - } - } - if (!found) { - Ref newPattern(new FinderPattern(centerJ, centerI, estimatedModuleSize)); - possibleCenters_.push_back(newPattern); - if (callback_ != 0) { - callback_->foundPossibleResultPoint(*newPattern); - } - } - return true; - } - } - return false; -} - -int FinderPatternFinder::findRowSkip() { - size_t max = possibleCenters_.size(); - if (max <= 1) { - return 0; - } - Ref firstConfirmedCenter; - for (size_t i = 0; i < max; i++) { - Ref center = possibleCenters_[i]; - if (center->getCount() >= CENTER_QUORUM) { - if (firstConfirmedCenter == 0) { - firstConfirmedCenter = center; - } else { - // We have two confirmed centers - // How far down can we skip before resuming looking for the next - // pattern? In the worst case, only the difference between the - // difference in the x / y coordinates of the two centers. - // This is the case where you find top left first. Draw it out. - hasSkipped_ = true; - return (int)(abs(firstConfirmedCenter->getX() - center->getX()) - abs(firstConfirmedCenter->getY() - - center->getY()))/2; - } - } - } - return 0; -} - -bool FinderPatternFinder::haveMultiplyConfirmedCenters() { - int confirmedCount = 0; - float totalModuleSize = 0.0f; - size_t max = possibleCenters_.size(); - for (size_t i = 0; i < max; i++) { - Ref pattern = possibleCenters_[i]; - if (pattern->getCount() >= CENTER_QUORUM) { - confirmedCount++; - totalModuleSize += pattern->getEstimatedModuleSize(); - } - } - if (confirmedCount < 3) { - return false; - } - // OK, we have at least 3 confirmed centers, but, it's possible that one is a "false positive" - // and that we need to keep looking. We detect this by asking if the estimated module sizes - // vary too much. We arbitrarily say that when the total deviation from average exceeds - // 5% of the total module size estimates, it's too much. - float average = totalModuleSize / max; - float totalDeviation = 0.0f; - for (size_t i = 0; i < max; i++) { - Ref pattern = possibleCenters_[i]; - totalDeviation += abs(pattern->getEstimatedModuleSize() - average); - } - return totalDeviation <= 0.05f * totalModuleSize; -} - -vector > FinderPatternFinder::selectBestPatterns() { - size_t startSize = possibleCenters_.size(); - - if (startSize < 3) { - // Couldn't find enough finder patterns - throw zxing::ReaderException("Could not find three finder patterns"); - } - - // Filter outlier possibilities whose module size is too different - if (startSize > 3) { - // But we can only afford to do so if we have at least 4 possibilities to choose from - float totalModuleSize = 0.0f; - float square = 0.0f; - for (size_t i = 0; i < startSize; i++) { - float size = possibleCenters_[i]->getEstimatedModuleSize(); - totalModuleSize += size; - square += size * size; - } - float average = totalModuleSize / (float) startSize; - float stdDev = (float)sqrt(square / startSize - average * average); - - sort(possibleCenters_.begin(), possibleCenters_.end(), FurthestFromAverageComparator(average)); - - float limit = max(0.2f * average, stdDev); - - for (size_t i = 0; i < possibleCenters_.size() && possibleCenters_.size() > 3; i++) { - if (abs(possibleCenters_[i]->getEstimatedModuleSize() - average) > limit) { - possibleCenters_.erase(possibleCenters_.begin()+i); - i--; - } - } - } - - if (possibleCenters_.size() > 3) { - // Throw away all but those first size candidate points we found. - float totalModuleSize = 0.0f; - for (size_t i = 0; i < possibleCenters_.size(); i++) { - float size = possibleCenters_[i]->getEstimatedModuleSize(); - totalModuleSize += size; - } - float average = totalModuleSize / (float) possibleCenters_.size(); - sort(possibleCenters_.begin(), possibleCenters_.end(), CenterComparator(average)); - } - - if (possibleCenters_.size() > 3) { - possibleCenters_.erase(possibleCenters_.begin()+3,possibleCenters_.end()); - } - - vector > result(3); - result[0] = possibleCenters_[0]; - result[1] = possibleCenters_[1]; - result[2] = possibleCenters_[2]; - return result; -} - -vector > FinderPatternFinder::orderBestPatterns(vector > patterns) { - // Find distances between pattern centers - float abDistance = distance(patterns[0], patterns[1]); - float bcDistance = distance(patterns[1], patterns[2]); - float acDistance = distance(patterns[0], patterns[2]); - - Ref topLeft; - Ref topRight; - Ref bottomLeft; - // Assume one closest to other two is top left; - // topRight and bottomLeft will just be guesses below at first - if (bcDistance >= abDistance && bcDistance >= acDistance) { - topLeft = patterns[0]; - topRight = patterns[1]; - bottomLeft = patterns[2]; - } else if (acDistance >= bcDistance && acDistance >= abDistance) { - topLeft = patterns[1]; - topRight = patterns[0]; - bottomLeft = patterns[2]; - } else { - topLeft = patterns[2]; - topRight = patterns[0]; - bottomLeft = patterns[1]; - } - - // Use cross product to figure out which of other1/2 is the bottom left - // pattern. The vector "top-left -> bottom-left" x "top-left -> top-right" - // should yield a vector with positive z component - if ((bottomLeft->getY() - topLeft->getY()) * (topRight->getX() - topLeft->getX()) < (bottomLeft->getX() - - topLeft->getX()) * (topRight->getY() - topLeft->getY())) { - Ref temp = topRight; - topRight = bottomLeft; - bottomLeft = temp; - } - - vector > results(3); - results[0] = bottomLeft; - results[1] = topLeft; - results[2] = topRight; - return results; -} - -float FinderPatternFinder::distance(Ref p1, Ref p2) { - float dx = p1->getX() - p2->getX(); - float dy = p1->getY() - p2->getY(); - return (float)sqrt(dx * dx + dy * dy); -} - -FinderPatternFinder::FinderPatternFinder(Ref image, - Refconst& callback) : - image_(image), possibleCenters_(), hasSkipped_(false), callback_(callback) { -} - -Ref FinderPatternFinder::find(DecodeHints const& hints) { - bool tryHarder = hints.getTryHarder(); - - size_t maxI = image_->getHeight(); - size_t maxJ = image_->getWidth(); - - - // We are looking for black/white/black/white/black modules in - // 1:1:3:1:1 ratio; this tracks the number of such modules seen so far - - // As this is used often, we use an integer array instead of vector - int stateCount[5]; - bool done = false; - - - // Let's assume that the maximum version QR Code we support takes up 1/4 - // the height of the image, and then account for the center being 3 - // modules in size. This gives the smallest number of pixels the center - // could be, so skip this often. When trying harder, look for all - // QR versions regardless of how dense they are. - int iSkip = (3 * maxI) / (4 * MAX_MODULES); - if (iSkip < MIN_SKIP || tryHarder) { - iSkip = MIN_SKIP; - } - - // This is slightly faster than using the Ref. Efficiency is important here - BitMatrix& matrix = *image_; - - for (size_t i = iSkip - 1; i < maxI && !done; i += iSkip) { - // Get a row of black/white values - - stateCount[0] = 0; - stateCount[1] = 0; - stateCount[2] = 0; - stateCount[3] = 0; - stateCount[4] = 0; - int currentState = 0; - for (size_t j = 0; j < maxJ; j++) { - if (matrix.get(j, i)) { - // Black pixel - if ((currentState & 1) == 1) { // Counting white pixels - currentState++; - } - stateCount[currentState]++; - } else { // White pixel - if ((currentState & 1) == 0) { // Counting black pixels - if (currentState == 4) { // A winner? - if (foundPatternCross(stateCount)) { // Yes - bool confirmed = handlePossibleCenter(stateCount, i, j); - if (confirmed) { - // Start examining every other line. Checking each line turned out to be too - // expensive and didn't improve performance. - iSkip = 2; - if (hasSkipped_) { - done = haveMultiplyConfirmedCenters(); - } else { - int rowSkip = findRowSkip(); - if (rowSkip > stateCount[2]) { - // Skip rows between row of lower confirmed center - // and top of presumed third confirmed center - // but back up a bit to get a full chance of detecting - // it, entire width of center of finder pattern - - // Skip by rowSkip, but back off by stateCount[2] (size - // of last center of pattern we saw) to be conservative, - // and also back off by iSkip which is about to be - // re-added - i += rowSkip - stateCount[2] - iSkip; - j = maxJ - 1; - } - } - } else { - stateCount[0] = stateCount[2]; - stateCount[1] = stateCount[3]; - stateCount[2] = stateCount[4]; - stateCount[3] = 1; - stateCount[4] = 0; - currentState = 3; - continue; - } - // Clear state to start looking again - currentState = 0; - stateCount[0] = 0; - stateCount[1] = 0; - stateCount[2] = 0; - stateCount[3] = 0; - stateCount[4] = 0; - } else { // No, shift counts back by two - stateCount[0] = stateCount[2]; - stateCount[1] = stateCount[3]; - stateCount[2] = stateCount[4]; - stateCount[3] = 1; - stateCount[4] = 0; - currentState = 3; - } - } else { - stateCount[++currentState]++; - } - } else { // Counting white pixels - stateCount[currentState]++; - } - } - } - if (foundPatternCross(stateCount)) { - bool confirmed = handlePossibleCenter(stateCount, i, maxJ); - if (confirmed) { - iSkip = stateCount[0]; - if (hasSkipped_) { - // Found a third one - done = haveMultiplyConfirmedCenters(); - } - } - } - } - - vector > patternInfo = selectBestPatterns(); - patternInfo = orderBestPatterns(patternInfo); - - Ref result(new FinderPatternInfo(patternInfo)); - return result; -} -} -} +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- +/* + * FinderPatternFinder.cpp + * zxing + * + * Created by Christian Brunschen on 13/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +namespace zxing { +namespace qrcode { + +using namespace std; + +class FurthestFromAverageComparator { +private: + const float averageModuleSize_; +public: + FurthestFromAverageComparator(float averageModuleSize) : + averageModuleSize_(averageModuleSize) { + } + bool operator()(Ref a, Ref b) { + float dA = abs(a->getEstimatedModuleSize() - averageModuleSize_); + float dB = abs(b->getEstimatedModuleSize() - averageModuleSize_); + return dA > dB; + } +}; + +class CenterComparator { + const float averageModuleSize_; +public: + CenterComparator(float averageModuleSize) : + averageModuleSize_(averageModuleSize) { + } + bool operator()(Ref a, Ref b) { + // N.B.: we want the result in descending order ... + if (a->getCount() != b->getCount()) { + return a->getCount() > b->getCount(); + } else { + float dA = abs(a->getEstimatedModuleSize() - averageModuleSize_); + float dB = abs(b->getEstimatedModuleSize() - averageModuleSize_); + return dA < dB; + } + } +}; + +int FinderPatternFinder::CENTER_QUORUM = 2; +int FinderPatternFinder::MIN_SKIP = 3; +int FinderPatternFinder::MAX_MODULES = 57; + +float FinderPatternFinder::centerFromEnd(int* stateCount, int end) { + return (float)(end - stateCount[4] - stateCount[3]) - stateCount[2] / 2.0f; +} + +bool FinderPatternFinder::foundPatternCross(int* stateCount) { + int totalModuleSize = 0; + for (int i = 0; i < 5; i++) { + if (stateCount[i] == 0) { + return false; + } + totalModuleSize += stateCount[i]; + } + if (totalModuleSize < 7) { + return false; + } + float moduleSize = (float)totalModuleSize / 7.0f; + float maxVariance = moduleSize / 2.0f; + // Allow less than 50% variance from 1-1-3-1-1 proportions + return abs(moduleSize - stateCount[0]) < maxVariance && abs(moduleSize - stateCount[1]) < maxVariance && abs(3.0f + * moduleSize - stateCount[2]) < 3.0f * maxVariance && abs(moduleSize - stateCount[3]) < maxVariance && abs( + moduleSize - stateCount[4]) < maxVariance; +} + +float FinderPatternFinder::crossCheckVertical(size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal) { + + int maxI = image_->getHeight(); + int stateCount[5]; + for (int i = 0; i < 5; i++) + stateCount[i] = 0; + + + // Start counting up from center + int i = startI; + while (i >= 0 && image_->get(centerJ, i)) { + stateCount[2]++; + i--; + } + if (i < 0) { + return NAN; + } + while (i >= 0 && !image_->get(centerJ, i) && stateCount[1] <= maxCount) { + stateCount[1]++; + i--; + } + // If already too many modules in this state or ran off the edge: + if (i < 0 || stateCount[1] > maxCount) { + return NAN; + } + while (i >= 0 && image_->get(centerJ, i) && stateCount[0] <= maxCount) { + stateCount[0]++; + i--; + } + if (stateCount[0] > maxCount) { + return NAN; + } + + // Now also count down from center + i = startI + 1; + while (i < maxI && image_->get(centerJ, i)) { + stateCount[2]++; + i++; + } + if (i == maxI) { + return NAN; + } + while (i < maxI && !image_->get(centerJ, i) && stateCount[3] < maxCount) { + stateCount[3]++; + i++; + } + if (i == maxI || stateCount[3] >= maxCount) { + return NAN; + } + while (i < maxI && image_->get(centerJ, i) && stateCount[4] < maxCount) { + stateCount[4]++; + i++; + } + if (stateCount[4] >= maxCount) { + return NAN; + } + + // If we found a finder-pattern-like section, but its size is more than 40% different than + // the original, assume it's a false positive + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; + if (5 * abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) { + return NAN; + } + + return foundPatternCross(stateCount) ? centerFromEnd(stateCount, i) : NAN; +} + +float FinderPatternFinder::crossCheckHorizontal(size_t startJ, size_t centerI, int maxCount, + int originalStateCountTotal) { + + int maxJ = image_->getWidth(); + int stateCount[5]; + for (int i = 0; i < 5; i++) + stateCount[i] = 0; + + int j = startJ; + while (j >= 0 && image_->get(j, centerI)) { + stateCount[2]++; + j--; + } + if (j < 0) { + return NAN; + } + while (j >= 0 && !image_->get(j, centerI) && stateCount[1] <= maxCount) { + stateCount[1]++; + j--; + } + if (j < 0 || stateCount[1] > maxCount) { + return NAN; + } + while (j >= 0 && image_->get(j, centerI) && stateCount[0] <= maxCount) { + stateCount[0]++; + j--; + } + if (stateCount[0] > maxCount) { + return NAN; + } + + j = startJ + 1; + while (j < maxJ && image_->get(j, centerI)) { + stateCount[2]++; + j++; + } + if (j == maxJ) { + return NAN; + } + while (j < maxJ && !image_->get(j, centerI) && stateCount[3] < maxCount) { + stateCount[3]++; + j++; + } + if (j == maxJ || stateCount[3] >= maxCount) { + return NAN; + } + while (j < maxJ && image_->get(j, centerI) && stateCount[4] < maxCount) { + stateCount[4]++; + j++; + } + if (stateCount[4] >= maxCount) { + return NAN; + } + + // If we found a finder-pattern-like section, but its size is significantly different than + // the original, assume it's a false positive + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; + if (5 * abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) { + return NAN; + } + + return foundPatternCross(stateCount) ? centerFromEnd(stateCount, j) : NAN; +} + +bool FinderPatternFinder::handlePossibleCenter(int* stateCount, size_t i, size_t j) { + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; + float centerJ = centerFromEnd(stateCount, j); + float centerI = crossCheckVertical(i, (size_t)centerJ, stateCount[2], stateCountTotal); + if (!isnan(centerI)) { + // Re-cross check + centerJ = crossCheckHorizontal((size_t)centerJ, (size_t)centerI, stateCount[2], stateCountTotal); + if (!isnan(centerJ)) { + float estimatedModuleSize = (float)stateCountTotal / 7.0f; + bool found = false; + size_t max = possibleCenters_.size(); + for (size_t index = 0; index < max; index++) { + Ref center = possibleCenters_[index]; + // Look for about the same center and module size: + if (center->aboutEquals(estimatedModuleSize, centerI, centerJ)) { + possibleCenters_[index] = center->combineEstimate(centerI, centerJ, estimatedModuleSize); + found = true; + break; + } + } + if (!found) { + Ref newPattern(new FinderPattern(centerJ, centerI, estimatedModuleSize)); + possibleCenters_.push_back(newPattern); + if (callback_ != 0) { + callback_->foundPossibleResultPoint(*newPattern); + } + } + return true; + } + } + return false; +} + +int FinderPatternFinder::findRowSkip() { + size_t max = possibleCenters_.size(); + if (max <= 1) { + return 0; + } + Ref firstConfirmedCenter; + for (size_t i = 0; i < max; i++) { + Ref center = possibleCenters_[i]; + if (center->getCount() >= CENTER_QUORUM) { + if (firstConfirmedCenter == 0) { + firstConfirmedCenter = center; + } else { + // We have two confirmed centers + // How far down can we skip before resuming looking for the next + // pattern? In the worst case, only the difference between the + // difference in the x / y coordinates of the two centers. + // This is the case where you find top left first. Draw it out. + hasSkipped_ = true; + return (int)(abs(firstConfirmedCenter->getX() - center->getX()) - abs(firstConfirmedCenter->getY() + - center->getY()))/2; + } + } + } + return 0; +} + +bool FinderPatternFinder::haveMultiplyConfirmedCenters() { + int confirmedCount = 0; + float totalModuleSize = 0.0f; + size_t max = possibleCenters_.size(); + for (size_t i = 0; i < max; i++) { + Ref pattern = possibleCenters_[i]; + if (pattern->getCount() >= CENTER_QUORUM) { + confirmedCount++; + totalModuleSize += pattern->getEstimatedModuleSize(); + } + } + if (confirmedCount < 3) { + return false; + } + // OK, we have at least 3 confirmed centers, but, it's possible that one is a "false positive" + // and that we need to keep looking. We detect this by asking if the estimated module sizes + // vary too much. We arbitrarily say that when the total deviation from average exceeds + // 5% of the total module size estimates, it's too much. + float average = totalModuleSize / max; + float totalDeviation = 0.0f; + for (size_t i = 0; i < max; i++) { + Ref pattern = possibleCenters_[i]; + totalDeviation += abs(pattern->getEstimatedModuleSize() - average); + } + return totalDeviation <= 0.05f * totalModuleSize; +} + +vector > FinderPatternFinder::selectBestPatterns() { + size_t startSize = possibleCenters_.size(); + + if (startSize < 3) { + // Couldn't find enough finder patterns + throw zxing::ReaderException("Could not find three finder patterns"); + } + + // Filter outlier possibilities whose module size is too different + if (startSize > 3) { + // But we can only afford to do so if we have at least 4 possibilities to choose from + float totalModuleSize = 0.0f; + float square = 0.0f; + for (size_t i = 0; i < startSize; i++) { + float size = possibleCenters_[i]->getEstimatedModuleSize(); + totalModuleSize += size; + square += size * size; + } + float average = totalModuleSize / (float) startSize; + float stdDev = (float)sqrt(square / startSize - average * average); + + sort(possibleCenters_.begin(), possibleCenters_.end(), FurthestFromAverageComparator(average)); + + float limit = max(0.2f * average, stdDev); + + for (size_t i = 0; i < possibleCenters_.size() && possibleCenters_.size() > 3; i++) { + if (abs(possibleCenters_[i]->getEstimatedModuleSize() - average) > limit) { + possibleCenters_.erase(possibleCenters_.begin()+i); + i--; + } + } + } + + if (possibleCenters_.size() > 3) { + // Throw away all but those first size candidate points we found. + float totalModuleSize = 0.0f; + for (size_t i = 0; i < possibleCenters_.size(); i++) { + float size = possibleCenters_[i]->getEstimatedModuleSize(); + totalModuleSize += size; + } + float average = totalModuleSize / (float) possibleCenters_.size(); + sort(possibleCenters_.begin(), possibleCenters_.end(), CenterComparator(average)); + } + + if (possibleCenters_.size() > 3) { + possibleCenters_.erase(possibleCenters_.begin()+3,possibleCenters_.end()); + } + + vector > result(3); + result[0] = possibleCenters_[0]; + result[1] = possibleCenters_[1]; + result[2] = possibleCenters_[2]; + return result; +} + +vector > FinderPatternFinder::orderBestPatterns(vector > patterns) { + // Find distances between pattern centers + float abDistance = distance(patterns[0], patterns[1]); + float bcDistance = distance(patterns[1], patterns[2]); + float acDistance = distance(patterns[0], patterns[2]); + + Ref topLeft; + Ref topRight; + Ref bottomLeft; + // Assume one closest to other two is top left; + // topRight and bottomLeft will just be guesses below at first + if (bcDistance >= abDistance && bcDistance >= acDistance) { + topLeft = patterns[0]; + topRight = patterns[1]; + bottomLeft = patterns[2]; + } else if (acDistance >= bcDistance && acDistance >= abDistance) { + topLeft = patterns[1]; + topRight = patterns[0]; + bottomLeft = patterns[2]; + } else { + topLeft = patterns[2]; + topRight = patterns[0]; + bottomLeft = patterns[1]; + } + + // Use cross product to figure out which of other1/2 is the bottom left + // pattern. The vector "top-left -> bottom-left" x "top-left -> top-right" + // should yield a vector with positive z component + if ((bottomLeft->getY() - topLeft->getY()) * (topRight->getX() - topLeft->getX()) < (bottomLeft->getX() + - topLeft->getX()) * (topRight->getY() - topLeft->getY())) { + Ref temp = topRight; + topRight = bottomLeft; + bottomLeft = temp; + } + + vector > results(3); + results[0] = bottomLeft; + results[1] = topLeft; + results[2] = topRight; + return results; +} + +float FinderPatternFinder::distance(Ref p1, Ref p2) { + float dx = p1->getX() - p2->getX(); + float dy = p1->getY() - p2->getY(); + return (float)sqrt(dx * dx + dy * dy); +} + +FinderPatternFinder::FinderPatternFinder(Ref image, + Refconst& callback) : + image_(image), possibleCenters_(), hasSkipped_(false), callback_(callback) { +} + +Ref FinderPatternFinder::find(DecodeHints const& hints) { + bool tryHarder = hints.getTryHarder(); + + size_t maxI = image_->getHeight(); + size_t maxJ = image_->getWidth(); + + + // We are looking for black/white/black/white/black modules in + // 1:1:3:1:1 ratio; this tracks the number of such modules seen so far + + // As this is used often, we use an integer array instead of vector + int stateCount[5]; + bool done = false; + + + // Let's assume that the maximum version QR Code we support takes up 1/4 + // the height of the image, and then account for the center being 3 + // modules in size. This gives the smallest number of pixels the center + // could be, so skip this often. When trying harder, look for all + // QR versions regardless of how dense they are. + int iSkip = (3 * maxI) / (4 * MAX_MODULES); + if (iSkip < MIN_SKIP || tryHarder) { + iSkip = MIN_SKIP; + } + + // This is slightly faster than using the Ref. Efficiency is important here + BitMatrix& matrix = *image_; + + for (size_t i = iSkip - 1; i < maxI && !done; i += iSkip) { + // Get a row of black/white values + + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + stateCount[3] = 0; + stateCount[4] = 0; + int currentState = 0; + for (size_t j = 0; j < maxJ; j++) { + if (matrix.get(j, i)) { + // Black pixel + if ((currentState & 1) == 1) { // Counting white pixels + currentState++; + } + stateCount[currentState]++; + } else { // White pixel + if ((currentState & 1) == 0) { // Counting black pixels + if (currentState == 4) { // A winner? + if (foundPatternCross(stateCount)) { // Yes + bool confirmed = handlePossibleCenter(stateCount, i, j); + if (confirmed) { + // Start examining every other line. Checking each line turned out to be too + // expensive and didn't improve performance. + iSkip = 2; + if (hasSkipped_) { + done = haveMultiplyConfirmedCenters(); + } else { + int rowSkip = findRowSkip(); + if (rowSkip > stateCount[2]) { + // Skip rows between row of lower confirmed center + // and top of presumed third confirmed center + // but back up a bit to get a full chance of detecting + // it, entire width of center of finder pattern + + // Skip by rowSkip, but back off by stateCount[2] (size + // of last center of pattern we saw) to be conservative, + // and also back off by iSkip which is about to be + // re-added + i += rowSkip - stateCount[2] - iSkip; + j = maxJ - 1; + } + } + } else { + stateCount[0] = stateCount[2]; + stateCount[1] = stateCount[3]; + stateCount[2] = stateCount[4]; + stateCount[3] = 1; + stateCount[4] = 0; + currentState = 3; + continue; + } + // Clear state to start looking again + currentState = 0; + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + stateCount[3] = 0; + stateCount[4] = 0; + } else { // No, shift counts back by two + stateCount[0] = stateCount[2]; + stateCount[1] = stateCount[3]; + stateCount[2] = stateCount[4]; + stateCount[3] = 1; + stateCount[4] = 0; + currentState = 3; + } + } else { + stateCount[++currentState]++; + } + } else { // Counting white pixels + stateCount[currentState]++; + } + } + } + if (foundPatternCross(stateCount)) { + bool confirmed = handlePossibleCenter(stateCount, i, maxJ); + if (confirmed) { + iSkip = stateCount[0]; + if (hasSkipped_) { + // Found a third one + done = haveMultiplyConfirmedCenters(); + } + } + } + } + + vector > patternInfo = selectBestPatterns(); + patternInfo = orderBestPatterns(patternInfo); + + Ref result(new FinderPatternInfo(patternInfo)); + return result; +} +} +} diff --git a/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternInfo.cpp b/symbian/QZXing/source/zxing/qrcode/detector/QRFinderPatternInfo.cpp similarity index 96% rename from symbian/QZXing/source/zxing/qrcode/detector/FinderPatternInfo.cpp rename to symbian/QZXing/source/zxing/qrcode/detector/QRFinderPatternInfo.cpp index 088a0e760..36ce6d411 100644 --- a/symbian/QZXing/source/zxing/qrcode/detector/FinderPatternInfo.cpp +++ b/symbian/QZXing/source/zxing/qrcode/detector/QRFinderPatternInfo.cpp @@ -1,41 +1,41 @@ -/* - * FinderPatternInfo.cpp - * zxing - * - * Created by Christian Brunschen on 13/05/2008. - * Copyright 2008 ZXing authors All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -namespace zxing { -namespace qrcode { - -FinderPatternInfo::FinderPatternInfo(std::vector > patternCenters) : - bottomLeft_(patternCenters[0]), topLeft_(patternCenters[1]), topRight_(patternCenters[2]) { -} - -Ref FinderPatternInfo::getBottomLeft() { - return bottomLeft_; -} -Ref FinderPatternInfo::getTopLeft() { - return topLeft_; -} -Ref FinderPatternInfo::getTopRight() { - return topRight_; -} - -} -} +/* + * FinderPatternInfo.cpp + * zxing + * + * Created by Christian Brunschen on 13/05/2008. + * Copyright 2008 ZXing authors All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace zxing { +namespace qrcode { + +FinderPatternInfo::FinderPatternInfo(std::vector > patternCenters) : + bottomLeft_(patternCenters[0]), topLeft_(patternCenters[1]), topRight_(patternCenters[2]) { +} + +Ref FinderPatternInfo::getBottomLeft() { + return bottomLeft_; +} +Ref FinderPatternInfo::getTopLeft() { + return topLeft_; +} +Ref FinderPatternInfo::getTopRight() { + return topRight_; +} + +} +} diff --git a/symbian/QZXing_tutorial.txt b/symbian/QZXing_tutorial.txt index 4bb02c848..8fcb480aa 100644 --- a/symbian/QZXing_tutorial.txt +++ b/symbian/QZXing_tutorial.txt @@ -1,56 +1,47 @@ This is a wrapper library of the C++ part of ZXing library. == Getting started == -This library is mented to be very simple and will provide as simple as possible the decoding operations. Thus my main purpose is not to support -extreme operations and complex techniques that ZXing library does support. Of course, the original ZXing code is still here for everyone interested -in using something beyond the already implemented (those of you willing to make more operations available, their code is always welcomed to be merged). +This library is mented to be very simple and will provide as simple as possible the decoding operations. Thus my main purpose is not to support extreme +operations and complex techniques that ZXing library does support. Of course, the original ZXing code is still here for everyone interested in using +something beyond the already implemented (those of you willing to make more operations available, their code is always welcomed to be merged). Supported barcode types: -* Qr Code -* DataMatrix -* UPC_E -* UPC_A -* EAN_8 -* EAN_13 -* CODE_128 -* CODE_39 -* ITF -The only dependency of this project is the supported functions of the compiler. For instance all G++ based compilers are ok but on the other hand, -MSVC doesn't support them that is why at least for now only Mingw compiler is supported for Desktop targets along with Symbian versions. + * Qr Code + * Data Matrix (V1.1) + * Aztec Code (V1.2) + * UPC_E + * UPC_A + * EAN_8 + * EAN_13 + * CODE_128 + * CODE_39 + * ITF + +The only dependency of this project is the supported functions of the compiler. For instance all G++ based compilers are ok but on the other hand, MSVC doesn't support them that is why at least for now only Mingw compiler is supported for Desktop targets along with Symbian versions. So, if you have a Qt project and your target is to decode a barcode contained in a QImage then this is how is done... == Prerequisites == -First you need to download the correct binary version of the library according to your needs. In the Symbian versions there are 2 versions of binaries -of each. The '''selfsigned''' and the '''signed'''. The selfsigned contains the appropriate Capabilities that makes your program selfsignable -(-lQZXing_selfsigned). But if you are planning to use additional Capabilities in your project other than those compling to selfsigning then you need -to select the singed version (-lQZXing). Be careful on that because if your application uses more capabilities than the library has, your application -will keep crashing. +First you need to download the correct binary version of the library according to your needs. In the Symbian versions there are 2 versions of binaries of each. The selfsigned and the signed. The selfsigned contains the appropriate Capabilities that makes your program selfsignable (-lQZXing_selfsigned). But if you are planning to use additional Capabilities in your project other than those compling to selfsigning then you need to select the singed version (-lQZXing). Be careful on that because if your application uses more capabilities than the library has, your application will keep crashing. Now that it is decided if you need selfsigned or signed version, next step is to select the Deploying target and Qt version. -* symbian\QZXing\binary\Qt_4.6.3_Symbian: Use this if targeting for Qt versions lower than 4.7. This version -doesn't have dependency to the Qt Declarative. Also it contains a binary specially for S60 FP1 (selfsigned) which doesn't contain the ''Location'' -Capability (in the S60 FP1 Location capability is not selfsigned). + * [https://projects.developer.nokia.com/QZXing/downloads/1 Qt_4.6.3_Symbian^1]: Use this if targeting for Qt versions lower than 4.7. This version doesn't have dependency to the Qt Declarative. Also it contains a binary specially for S60 FP1 (selfsigned) which doesn't contain the Location Capability (in the S60 FP1 Location capability is not selfsigned). -* symbian\QZXing\binary\Qt_4.7.3_Symbian: This is the full featured version since it supports QML. + * [https://projects.developer.nokia.com/QZXing/downloads/2 "'Qt_4.7.3_Symbian"]: This is the full featured version since it supports QML. -* symbian\QZXing\binary\Harmattan-Maemo5: This is when targeting for Maemo platform. - -* symbian\QZXing\binary\Qt_4.7.4_Desktop_Mingw: If targeting for Desktop applications Mingw is the only compiler supported at the moment. + * [https://projects.developer.nokia.com/QZXing/downloads/3 Qt_4.7.4_Desktop_Mingw]: If targeting for Desktop applications Mingw is the only compiler supported at the moment. Having selected one of the above 3, you download it. == Including the library == - === Symbian Target === -In the downloaded package there are 3 folders (include, InstallToDevice, release). Those 3 folders you need to copy them to the EPOC32 root folder -of the Symbian SDK you are planing to use. For instance, by default QtSDK is installed under the path ''C:\QtSDK''. If we need to use Symbian^3 -and Qt 4.7.4 we copy the 3 folders and paste them to the following path: ''C:\QtSDK\Symbian\SDKs\Symbian3Qt474\epoc32''. This will merge the folders -and will add the library files needed for compiling and linking. +In the downloaded package there are 3 folders (include, InstallToDevice, release). Those 3 folders you need to copy them to the EPOC32 root folder of the Symbian SDK you are planing to use. For instance, by default QtSDK is installed under the path C:\QtSDK. If we need to use Symbian^3 and Qt 4.7.4 we copy the 3 folders and paste them to the following path: C:\QtSDK\Symbian\SDKs\Symbian3Qt474\epoc32. This will merge the folders and will add the library files needed for compiling and linking.^ Then in the .pro file of your project the following lines have to be added: + + symbian{ LIBS += -lqzxing customrules.pkg_prerules = \ @@ -60,64 +51,68 @@ symbian{ DEPLOYMENT += customrules } -Pay attention to this line: - "@\"$$(EPOCROOT)Epoc32/InstallToDevice/QZXing_selfsigned.sis\",(0xE618743C)"\ -This is where you will define if you want the selfsigned or the signed version. If signed version needed you have to write: - "@\"$$(EPOCROOT)Epoc32/InstallToDevice/QZXing.sis\",(0xE618743C)"\ +Pay attention to this line: ` "@\"$$(EPOCROOT)Epoc32/InstallToDevice/QZXing_selfsigned.sis\",(0xE618743C)"\` This is where you will define if you want the selfsigned or the signed version. If signed version needed you have to write: ` "@\"$$(EPOCROOT)Epoc32/InstallToDevice/QZXing_usinged.sis\",(0xE618743C)"\` === Desktop Target === Copy the contents of the package Qt_4.7.4_Desktop_Mingw to a folder in your project. Then add in the .pro file + + win32{ INCLUDEPATH += "absolute path of the folder where the files where placed" LIBS += -L"absolute path of the folder where the files where placed" \ -lqzxing } - == In the code == -Where the library needs to be used you have to include the header file: #include . -Now a QZXing object can be created. It is recommended (but not obligatory) to use one instance of it and decode any number of barcodes you decide. -The class supports 3 methods: +Where the library needs to be used you have to include the header file: `#include `. Now a QZXing object can be created. It is recommended (but not obligatory) to use one instance of it and decode any number of barcodes you decide. The class supports 3 methods: + + * setDecoder(DecoderFormat): DecoderFormat is an enumeration regarding the types of barcodes the decoder will try to identify to each decoding. By default all the types are enabled but hence that it is extra processing. If you want to identify specific barcode types you can disable the other. This will result to faster processing. Conjunctions of more than one types of barcodes are supported using logical OR over the enumeration. For example if we need to support both Qt Codes and EAN 13 we need to call the following: -* ''setDecoder(DecoderFormat)'': DecoderFormat is an enumeration regarding the types of barcodes the decoder will try to identify to each decoding. - By default all the types are enabled but hence that it is extra processing. If you want to identify specific barcode types you can disable the - other. This will result to faster processing. Conjunctions of more than one types of barcodes are supported using logical OR over the enumeration. - For example if we need to support both Qt Codes and EAN 13 we need to call the following: - QZXing decoder; decoder.setDecoder( DecoderFormat_QR_CODE | DecoderFormat_EAN_13 ); + This enable/disable operation of the decoders can be done any time needed. -* ''registerQMLTypes()'': If you are planning to use the library in the QML then in the main function you need to call this static function. -It will register the QZXing library and make it visible to QML. After that, in the qml file you are planning to use the library you need to write -at the top: import QZXing 1.0 + * registerQMLTypes(): If you are planning to use the library in the QML then in the main function you need to call this static function. It will register the QZXing library and make it visible to QML. After that, in the qml file you are planning to use the library you need to write at the top: -* ''decodeImage(QImage)'': the method that initiates the decoding. It is made as a slot for convenience. It is blocking function thus if you need your -application to continue without freezing, you can call it to an other thread. Finally return the result of the decoding. If an error occurred it will -return an empty string "". +import QZXing 1.2 -* ''decodingStarted()'': signal emitted when decoding starts -* ''decodingFinished(bool succeeded)'': signal emitted when decoding finishes reporting the success with the boolean. -* ''tagFound(QString tag)'': emitted upon successful decoding of a barcode. + + * decodeImage(QImage): the method that initiates the decoding. It is made as a slot for convenience. It is blocking function thus if you need your application to continue without freezing, you can call it to an other thread. Finally return the result of the decoding. If an error occurred it will return an empty string \"\". + * decodeImageQML(QObject*): the method that has to be called from QML to decode an Image Element. By calling this function the decoder will search the whole picture to find something to decode. As argument is used the Image QML element that holds the image that we want to decode. If is needed to decode only a specific part of the image use decodeSubImageQML. Introduced in version V1.2 + * decodeSubImageQML(QObject*, double, double, double, double): the method that has to be called from QML to decode only a portion of an Image Element. First argument is the Image QML element. The rest are as follows: offsetX, offsetY, width, height. + * offsetX, offsetY: define the starting point in the image where the portion that needs to be decoded starts. + * width, height: the size of the portion that will be decoded. Introduced in version V1.2 + + * decodingStarted(): signal emitted when decoding starts + * decodingFinished(bool succeeded): signal emitted when decoding finishes reporting the success with the boolean. + * tagFound(QString tag): emitted upon successful decoding of a barcode. == Examples == The repository contains 2 examples. -* QQrDecoder: uses Qt Mobility 1.1.3 with QCamera , VideoFinder and QWidgets. It has minor issues that i hope will get fixed at some point: -# No automatic focus thus the user needs to press a button to initiate focusing, capturing and eventually decoding. -# A few were unable to use it because it constantly throughs various erros such as "General Camera error". + * QQrDecoder: uses Qt Mobility 1.1.3 with QCamera , VideoFinder and QWidgets. This is the same project previously hosted in [https://projects.developer.nokia.com/QQrDecoder this project page] and [http://www.developer.nokia.com/Community/Wiki/Qr_Decoder_in_Qt this wiki article] (the project page from now gets deprecated since the project will be hosted here from now on). It has known issues that i hope will get fixed at some point: -* QMLBarcodeDecoder: Needs Qt Mobility 1.2 and Qt 4.7.4 because Camera qml component got supported from that version and on. Hope it will solve the -problems we had in the QQrDecoder. BUT it is not tested because i have no Symbian^3 device and Remote Device Access has problems regarding the -camera use. So the code in there is an estimation who the project should look. I hope it works without any change. +# No automatic focus thus the user needs to press a button to initiate focusing, capturing and eventually decoding. # A few were unable to use it because it constantly throughs various erros such as "General Camera error". + + * QMLBarcodeDecoder: Needs Qt Mobility 1.2 and Qt 4.7.4 because Camera qml component got supported from that version and on. Hope it will solve the problems we had in the QQrDecoder. And for the closing here is a small pretty QML code contained in the above project showing how it is used: + + Camera{ id:camera - onImageCaptured: decoder.decodeImage(preview) + onImageCaptured:{ + imageToDecode.source = preview + decoder.decodeImageQML(imageToDecode); + } +} + +Image{ + id:imageToDecode } QZXing{ @@ -130,9 +125,7 @@ QZXing{ onDecodingFinished: console.log("Decoding finished " + (succeeded==true ? "successfully" : "unsuccessfully") ) } -== The End == -If anyone needs anything feel free to ask in the project's forum. - +== The end == Also your feedback is very important :) PS: this project is hosted here as well throughout its development process: https://projects.developer.nokia.com/QZXing. On major changes i update it