├── README.md ├── example ├── qml1test │ ├── Apple.png │ ├── deployment.pri │ ├── main.cpp │ ├── main.qml │ ├── qml.qrc │ └── qml1test.pro ├── qml2test │ ├── AliasText.qml │ ├── deployment.pri │ ├── main.cpp │ ├── main.qml │ ├── qml.qrc │ └── qml2test.pro └── widgetstest │ ├── main.cpp │ ├── widgetstest.pro │ └── xxx.png ├── include ├── dduiqrwidgets.h ├── qrencode │ ├── 3rd │ │ ├── bitstream.h │ │ ├── config.h │ │ ├── mask.h │ │ ├── mmask.h │ │ ├── mqrspec.h │ │ ├── qrencode.h │ │ ├── qrencode_inner.h │ │ ├── qrinput.h │ │ ├── qrspec.h │ │ ├── rscode.h │ │ └── split.h │ ├── qrencode.pri │ └── qrencode │ │ └── 3rd │ │ ├── bitstream.c │ │ ├── bitstream.h │ │ ├── config.h │ │ ├── mask.c │ │ ├── mask.h │ │ ├── mmask.c │ │ ├── mmask.h │ │ ├── mqrspec.c │ │ ├── mqrspec.h │ │ ├── qrencode.c │ │ ├── qrencode.h │ │ ├── qrencode_inner.h │ │ ├── qrinput.c │ │ ├── qrinput.h │ │ ├── qrspec.c │ │ ├── qrspec.h │ │ ├── rscode.c │ │ ├── rscode.h │ │ ├── split.c │ │ └── split.h └── widgets_global.h ├── qml1 ├── dduiqrencode.cpp ├── dduiqrencode.h ├── dduiqrencode_plugin.cpp ├── dduiqrencode_plugin.h ├── qml1.pro └── qmldir ├── qml2 ├── qml2.pro ├── qmldir ├── qrddencode.cpp ├── qrddencode.h ├── qtquickqrencode_plugin.cpp ├── qtquickqrencode_plugin.h ├── quickitemgrabber.cpp └── quickitemgrabber.h ├── qrencode ├── .DS_Store ├── 3rd │ ├── bitstream.c │ ├── bitstream.h │ ├── config.h │ ├── mask.c │ ├── mask.h │ ├── mmask.c │ ├── mmask.h │ ├── mqrspec.c │ ├── mqrspec.h │ ├── qrencode.c │ ├── qrencode.h │ ├── qrencode_inner.h │ ├── qrinput.c │ ├── qrinput.h │ ├── qrspec.c │ ├── qrspec.h │ ├── rscode.c │ ├── rscode.h │ ├── split.c │ └── split.h ├── qrencode.pri └── qrencode │ └── 3rd │ ├── bitstream.c │ ├── bitstream.h │ ├── config.h │ ├── mask.c │ ├── mask.h │ ├── mmask.c │ ├── mmask.h │ ├── mqrspec.c │ ├── mqrspec.h │ ├── qrencode.c │ ├── qrencode.h │ ├── qrencode_inner.h │ ├── qrinput.c │ ├── qrinput.h │ ├── qrspec.c │ ├── qrspec.h │ ├── rscode.c │ ├── rscode.h │ ├── split.c │ └── split.h ├── qtquickqrencode.pro └── widgets ├── dduiqrwidgets.cpp ├── dduiqrwidgets.h ├── widgets.pro └── widgets_global.h /README.md: -------------------------------------------------------------------------------- 1 | ## [2018-04-11update]QRCode Powered Support QWidgets And QML(qml1 and qml2) Module 2 | Designing cool, interactive interfaces. DuoDuoZhijiao came up with a much better answer for QtQuick1QREncode: `QWidgets QML`, 3 | a Widget And a declarative language perfect for designing UIs (and much more). 4 | Here's a sample of how QtQuick1QREncode Plugin For QML looks like: 5 | 6 | ![Add Logo](http://7qn7mv.com1.z0.glb.clouddn.com/_ddui111.png) 7 | 8 | ![No Logo](http://7qn7mv.com1.z0.glb.clouddn.com/_ddui22.png) 9 | 10 | ## Attention Please 11 | 12 | * You should install those plugin to Qt SDK path like :make install or Use qtcreator's install command 13 | 14 | ``` 15 | //QML2 code 16 | import QtQuick 2.3 17 | import com.duoduo.component 1.0 18 | QtQuick2QREncode{ 19 | id:qr 20 | width: 128 21 | height: 128 22 | qrSize: Qt.size(width,width) 23 | anchors.centerIn: parent 24 | qrData:"duoduozhijiao" //encode contents 25 | qrForeground: "#29aee1" //encode color 26 | qrBackground: "white" 27 | qrMargin: 2 28 | qrMode: QtQuick1QREncode.MODE_8 //encode model 29 | qrLevel: QtQuick1QREncode.LEVEL_Q // encode level 30 | qrLogo: "qrc:/256.png" //or local path or qrc path but not network url 31 | onQrSaveFileChanged: { 32 | console.log("We get save file path is :"+qrfilepath) 33 | } 34 | } 35 | ``` 36 | 37 | ``` 38 | //qml1 Code: 39 | import QtQuick 1.0 //notice here 40 | import com.ddui.qmlcomponents 1.0 41 | 42 | Item { 43 | width: 256 44 | height: width 45 | visible: true 46 | QtQuick1QREncode{ 47 | id:qr 48 | anchors.fill: parent 49 | qrSize: Qt.size(width,width) 50 | qrData:"www.heilqt.com" //encode contents 51 | qrForeground: "#29aee1" //encode color 52 | qrBackground: "white" 53 | qrMargin: 4 54 | qrMode: QtQuick1QREncode.MODE_8 //encode model 55 | qrLevel: QtQuick1QREncode.LEVEL_Q // encode level 56 | qrLogo: "qrc:/Apple.png" //or local path or qrc path but not network url 57 | onQrSaveFileChanged: { 58 | console.log("We get save file path is :"+qrfilepath) 59 | } 60 | onQrSizeChanged:{ 61 | console.log("Size get save file path is :"+qrsize.width) 62 | } 63 | } 64 | onWidthChanged: { 65 | if(width>height){ 66 | qr.setQrSize(Qt.size(height,height)) 67 | }else{ 68 | qr.setQrSize(Qt.size(width,width)) 69 | } 70 | } 71 | } 72 | ``` 73 | 74 | ``` 75 | //this is a widgets Code 76 | #include 77 | #include "dduiqrwidgets.h" 78 | 79 | int main(int argc, char *argv[]) 80 | { 81 | QApplication app(argc, argv); 82 | DDuiQRWidgets w; 83 | w.resize(400,100); 84 | w.show(); 85 | w.setQrSaveFile("xxx.png"); 86 | return app.exec(); 87 | } 88 | ``` 89 | 90 | This project aims at bringing the power of QtQuick1QREncode to qml designer UI and widgets. 91 | 92 | 93 | # Summary 94 | * [How to build](#how-to-build) 95 | * [How to use with QtQuick1QREncode](#how-to-use-with-qml-plugins) 96 | * [How to extend](#how-to-extend) 97 | * [Todo](#todo) 98 | 99 | ## How to Build 100 | #### Add the source code to your local machine on Mac Windows Linux. 101 | #### Make Sure Setting your env for Qt SDK 102 | #### Use Command 103 | Git clone it. 104 | Build it 105 | 106 | ``` 107 | make clean(mingw32-make clean) 108 | qmake 109 | make (mingw32-make mingw) | nmake(vc) 110 | sudo make install (*unix) 111 | ``` 112 | ## Use QtCreator 113 | You may use qtcreator to build it. 114 | 115 | 116 | ## How to use with QtQuick1QREncode 117 | Note that for the following, you need to have `Qt SDK` for Qt4.7 or later installed. 118 | 119 | #### QtQuick1QREncode 120 | You can use QtQuick1QREncode to encode your QtQuick1QREncode UI. 121 | 122 | #### Implemented QML Extension USE C++ (QQmlExtensionPlugin)(Qt4.x or later) 123 | Implemented a QML Extension module that: 124 | - Refer to [http://doc.qt.io/qt-5/qqmlextensionplugin.html](http://doc.qt.io/qt-5/qqmlextensionplugin.html). 125 | 126 | #### Implemented properties 127 | - qrData (QtQuick1QREncode data show) 128 | - qrLogo (QtQuick1QREncode middle logo) 129 | - qrSize (QtQuick1QREncode size) 130 | - qrMode (mode ) 131 | - qrLevel (level ) 132 | - qrCasesen (casesen upper) 133 | - qrMargin (margin) 134 | - qrPercent (percent) 135 | - qrForeground (qrForeground) 136 | - qrBackground (qrBackground) 137 | 138 | #### Implemented signals 139 | - Above all signals 140 | 141 | #### Implemented slots and functions 142 | - all Above slots 143 | - setQrSaveFile(const QString& filePath) //can sava current QtQuick1QREncode to file 144 | 145 | 146 | #### Implemented QWidget Extension USE C++ (Qt5.x or later) 147 | Implemented a QWidget Extension module that: 148 | - Refer to how to build share libary 149 | 150 | #### Implemented properties 151 | - qrData (QtQuick1QREncode data show) 152 | - qrLogo (QtQuick1QREncode middle logo) 153 | - qrSize (QtQuick1QREncode size) 154 | - qrMode (mode ) 155 | - qrLevel (level ) 156 | - qrCasesen (casesen upper) 157 | - qrMargin (margin) 158 | - qrPercent (percent) 159 | - qrForeground (qrForeground) 160 | - qrBackground (qrBackground) 161 | 162 | #### Implemented signals 163 | - Above all signals 164 | 165 | #### Implemented slots and functions 166 | - all Above slots 167 | - setQrSaveFile(const QString& filePath) //can sava current QtQuick1QREncode to file 168 | 169 | 170 | #### modified 171 | - qrSize is set update size and repaint 172 | 173 | ## FeedBack 174 | 175 | Contact information 176 | 177 | - Email(373955953#qq.com, Change#to@) 178 | - QQ: 39559539234 179 | - QQ Group:312125701 180 | - github: [寒山-居士](https://github.com/toby20130333) 181 | 182 | 183 | ## Thanks 184 | 185 | [https://github.com/penk/terrarium-app](https://github.com/penk/terrarium-app) 186 | 187 | ## About Author 188 | 189 | ``` 190 | var duoduozhijiao = { 191 | nickName : "寒山-居士", 192 | site : "http://www.heilqt.com", 193 | blog : "http://blog.heilqt.com" 194 | } 195 | ``` 196 | -------------------------------------------------------------------------------- /example/qml1test/Apple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toby20130333/qtquickqrencode/ea8be185f426ce00da07929b80206e001250d4f5/example/qml1test/Apple.png -------------------------------------------------------------------------------- /example/qml1test/deployment.pri: -------------------------------------------------------------------------------- 1 | unix:!android { 2 | isEmpty(target.path) { 3 | qnx { 4 | target.path = /tmp/$${TARGET}/bin 5 | } else { 6 | target.path = /opt/$${TARGET}/bin 7 | } 8 | export(target.path) 9 | } 10 | INSTALLS += target 11 | } 12 | 13 | export(INSTALLS) 14 | -------------------------------------------------------------------------------- /example/qml1test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication app(argc, argv); 7 | QDeclarativeView *view = new QDeclarativeView; 8 | view->setResizeMode(QDeclarativeView::SizeRootObjectToView); 9 | view->setSource(QUrl("qrc:/main.qml")); 10 | view->show(); 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /example/qml1test/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 1.0 2 | import com.ddui.qmlcomponents 1.0 3 | 4 | Item { 5 | width: 256 6 | height: width 7 | visible: true 8 | QtQuick1QREncode{ 9 | id:qr 10 | anchors.fill: parent 11 | qrSize: Qt.size(width,width) 12 | qrData:"www.heilqt.com" //encode contents 13 | qrForeground: "#29aee1" //encode color 14 | qrBackground: "white" 15 | qrMargin: 4 16 | qrMode: QtQuick1QREncode.MODE_8 //encode model 17 | qrLevel: QtQuick1QREncode.LEVEL_Q // encode level 18 | qrLogo: "qrc:/Apple.png" //or local path or qrc path but not network url 19 | onQrSaveFileChanged: { 20 | console.log("We get save file path is :"+qrfilepath) 21 | } 22 | onQrSizeChanged:{ 23 | console.log("Size get save file path is :"+qrsize.width) 24 | } 25 | } 26 | onWidthChanged: { 27 | if(width>height){ 28 | qr.setQrSize(Qt.size(height,height)) 29 | }else{ 30 | qr.setQrSize(Qt.size(width,width)) 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /example/qml1test/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | Apple.png 5 | 6 | 7 | -------------------------------------------------------------------------------- /example/qml1test/qml1test.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | #QT += qml quick 4 | QT += declarative 5 | CONFIG += c++11 6 | 7 | INCLUDEPATH +=$$PWD 8 | 9 | SOURCES += $$PWD/main.cpp 10 | 11 | RESOURCES += $$PWD/qml.qrc 12 | DESTDIR = . 13 | # Additional import path used to resolve QML modules in Qt Creator's code model 14 | QML_IMPORT_PATH = 15 | 16 | # Default rules for deployment. 17 | #include(deployment.pri) 18 | -------------------------------------------------------------------------------- /example/qml2test/AliasText.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.0 2 | 3 | Item { 4 | property alias myaliasTxt: myTxt.text 5 | function setText(str){ 6 | myaliasTxt = str; 7 | } 8 | Text { 9 | id: myTxt 10 | anchors.fill: parent 11 | horizontalAlignment: Text.AlignHCenter 12 | verticalAlignment: Text.AlignVCenter 13 | font.pixelSize: 20 14 | color: "white" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/qml2test/deployment.pri: -------------------------------------------------------------------------------- 1 | unix:!android { 2 | isEmpty(target.path) { 3 | qnx { 4 | target.path = /tmp/$${TARGET}/bin 5 | } else { 6 | target.path = /opt/$${TARGET}/bin 7 | } 8 | export(target.path) 9 | } 10 | INSTALLS += target 11 | } 12 | 13 | export(INSTALLS) 14 | -------------------------------------------------------------------------------- /example/qml2test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QGuiApplication app(argc, argv); 7 | 8 | QQmlApplicationEngine engine; 9 | engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); 10 | 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /example/qml2test/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.3 2 | import QtQuick.Window 2.2 3 | import com.duoduo.components 1.0 4 | 5 | Window { 6 | visible: true 7 | width: 228 8 | height: 228 9 | QtQuick2QREncode{ 10 | id:qr 11 | anchors.fill: parent 12 | qrSize: Qt.size(width,width) 13 | anchors.centerIn: parent 14 | qrData:"www.heilqt.com" //encode contents 15 | qrForeground: "#29aee1" //encode color 16 | qrBackground: "#dddddd" 17 | qrMargin: 10 18 | qrMode: QtQuick2QREncode.MODE_8 //encode model 19 | qrLevel: QtQuick2QREncode.LEVEL_Q // encode level 20 | qrLogo: "qrc:/256.png" //or local path or qrc path but not network url 21 | onQrSaveFileChanged: { 22 | console.log("We get save file path is :"+qrfilepath) 23 | } 24 | onHeightChanged: { 25 | getSize(); 26 | } 27 | onWidthChanged: { 28 | getSize(); 29 | } 30 | } 31 | function getSize(){ 32 | var w = Math.min(width,height); 33 | console.log("---------------w"+w); 34 | qr.qrSize = Qt.size(w,w); 35 | } 36 | 37 | //以下是测试text别名的使用 38 | Component.onCompleted: { 39 | tt.setText("欢迎二维码生成器...."); 40 | } 41 | AliasText{ 42 | id:tt 43 | anchors.centerIn: parent 44 | width: parent.width 45 | height: 30 46 | } 47 | MouseArea{ 48 | id:saveMa 49 | anchors.fill: parent 50 | onClicked: { 51 | qr.setQrSaveFile("xxx.png"); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /example/qml2test/qml.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | main.qml 4 | AliasText.qml 5 | 6 | 7 | -------------------------------------------------------------------------------- /example/qml2test/qml2test.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = app 2 | 3 | QT += qml quick 4 | CONFIG += c++11 5 | 6 | INCLUDEPATH += $$PWD 7 | SOURCES += $$PWD/main.cpp 8 | 9 | RESOURCES += $$PWD/qml.qrc 10 | 11 | # Additional import path used to resolve QML modules in Qt Creator's code model 12 | QML_IMPORT_PATH = 13 | DESTDIR = . 14 | # Default rules for deployment. 15 | #include(deployment.pri) 16 | -------------------------------------------------------------------------------- /example/widgetstest/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dduiqrwidgets.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication app(argc, argv); 7 | DDuiQRWidgets w; 8 | w.resize(400,400); 9 | w.show(); 10 | w.setQrSaveFile("xxx.png"); 11 | return app.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /example/widgetstest/widgetstest.pro: -------------------------------------------------------------------------------- 1 | QT += gui core widgets 2 | 3 | TARGET = widgetsqrencode 4 | 5 | INCLUDEPATH += $$PWD 6 | 7 | SOURCES += \ 8 | $$PWD/main.cpp 9 | 10 | LIBS += -L$$PWD/../../lib/ -ldduiqrwidgets 11 | DESTDIR = . 12 | INCLUDEPATH += $$PWD/../../include/ 13 | DEPENDPATH += $$PWD/../../lib/dduiqrwidgets 14 | -------------------------------------------------------------------------------- /example/widgetstest/xxx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toby20130333/qtquickqrencode/ea8be185f426ce00da07929b80206e001250d4f5/example/widgetstest/xxx.png -------------------------------------------------------------------------------- /include/dduiqrwidgets.h: -------------------------------------------------------------------------------- 1 | #ifndef DDUIQRWIDGETS_H 2 | #define DDUIQRWIDGETS_H 3 | 4 | #include "widgets_global.h" 5 | #include 6 | #include "qrencode/3rd/qrencode.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | class WIDGETSSHARED_EXPORT DDuiQRWidgets : 14 | public QWidget 15 | { 16 | Q_OBJECT 17 | Q_DISABLE_COPY(DDuiQRWidgets) 18 | Q_ENUMS(QR_MODE) 19 | Q_ENUMS(QR_LEVEL) 20 | Q_PROPERTY(QString qrData READ qrDDData WRITE setQrData NOTIFY qrDataChanged) 21 | Q_PROPERTY(QString qrLogo READ qrDDLogo WRITE setQrLogo NOTIFY qrLogoChanged) 22 | Q_PROPERTY(QSize qrSize READ qrDDSize WRITE setQrSize NOTIFY qrSizeChanged) 23 | Q_PROPERTY(QR_MODE qrMode READ qrDDMode WRITE setQrMode NOTIFY qrModeChanged) 24 | Q_PROPERTY(QR_LEVEL qrLevel READ qrDDLevel WRITE setQrLevel NOTIFY qrLevelChanged) 25 | Q_PROPERTY(bool qrCasesen READ qrDDCasesen WRITE setQrCasesen NOTIFY qrCasesenChanged) 26 | Q_PROPERTY(int qrMargin READ qrDDMargin WRITE setQrMargin NOTIFY qrMarginChanged) 27 | Q_PROPERTY(qreal qrPercent READ qrDDPercent WRITE setQrPercent NOTIFY qrPercentChanged) 28 | Q_PROPERTY(QColor qrForeground READ qrDDForeground WRITE setQrForeground NOTIFY qrForegroundChanged) 29 | Q_PROPERTY(QColor qrBackground READ qrDDBackground WRITE setQrBackground NOTIFY qrBackgroundChanged) 30 | public: 31 | DDuiQRWidgets(QWidget *parent = 0); 32 | ~DDuiQRWidgets(); 33 | 34 | /// 35 | /// \brief The QR_MODE enum 36 | /// 设置二维码的编码模式 37 | enum QR_MODE { 38 | MODE_NUL = QR_MODE_NUL, 39 | MODE_NUM = QR_MODE_NUM, 40 | MODE_AN = QR_MODE_AN, 41 | MODE_8 = QR_MODE_8, 42 | MODE_KANJI = QR_MODE_KANJI, 43 | MODE_STRUCTURE = QR_MODE_STRUCTURE, 44 | MODE_ECI = QR_MODE_ECI, 45 | MODE_FNC1FIRST = QR_MODE_FNC1FIRST, 46 | MODE_FNC1SECOND = QR_MODE_FNC1SECOND 47 | }; 48 | /// 49 | /// \brief The QR_LEVEL enum 50 | /// 设置二维码编码的识别质量的级别 51 | /// 52 | enum QR_LEVEL { 53 | LEVEL_L = QR_ECLEVEL_L, 54 | LEVEL_M = QR_ECLEVEL_M, 55 | LEVEL_Q = QR_ECLEVEL_Q, 56 | LEVEL_H = QR_ECLEVEL_H 57 | }; 58 | 59 | QString qrDDData(); 60 | QString qrDDLogo(); 61 | QSize qrDDSize(); 62 | QR_MODE qrDDMode(); 63 | QR_LEVEL qrDDLevel(); 64 | bool qrDDCasesen(); 65 | int qrDDMargin(); 66 | qreal qrDDPercent(); 67 | QColor qrDDForeground(); 68 | QColor qrDDBackground(); 69 | 70 | //设置需要编码的数据 71 | Q_INVOKABLE void setQrData(const QString& data); 72 | // 设置二维码的logo 73 | Q_INVOKABLE void setQrLogo(const QString& logo); 74 | Q_INVOKABLE void setQrSize(QSize mode); 75 | Q_INVOKABLE void setQrMode(QR_MODE mode); 76 | Q_INVOKABLE void setQrLevel(QR_LEVEL level); 77 | Q_INVOKABLE void setQrCasesen(bool casesen); 78 | Q_INVOKABLE void setQrMargin(int margin); 79 | Q_INVOKABLE void setQrPercent(qreal percent); 80 | Q_INVOKABLE void setQrForeground(QColor forgb); 81 | Q_INVOKABLE void setQrBackground(QColor backgb); 82 | Q_INVOKABLE void setQrSaveFile(const QString& filepath); 83 | 84 | signals: 85 | void qrDataChanged(const QString& qrdata); 86 | void qrLogoChanged(const QString& qrlogo); 87 | void qrSizeChanged(const QSize& qrsize); 88 | void qrModeChanged(QR_MODE qrmodel); 89 | void qrLevelChanged(QR_LEVEL qrlevel); 90 | void qrCasesenChanged(bool qrcasesen); 91 | void qrMarginChanged(int qrmargin); 92 | void qrPercentChanged(qreal qrpercent); 93 | void qrForegroundChanged(const QColor& qrfg); 94 | void qrBackgroundChanged(const QColor& qrbg); 95 | void qrSaveFileChanged(const QString& qrfilepath); 96 | 97 | private: 98 | QString qrData; 99 | QString qrLogo; 100 | QSize qrSize; 101 | QR_MODE qrMode; 102 | QR_LEVEL qrLevel; 103 | bool qrCasesen; 104 | int qrMargin; 105 | qreal qrPercent; 106 | QColor qrForeground; 107 | QColor qrBackground; 108 | QString qrFilePath; 109 | QString icon; 110 | QByteArray text; 111 | void saveCurViewToFile(); 112 | void saveItemToFile(); 113 | private slots: 114 | void grabChanged(); 115 | protected: 116 | void paintEvent(QPaintEvent *e); 117 | void resizeEvent(QResizeEvent *e); 118 | }; 119 | 120 | #endif // DDUIQRWIDGETS_H 121 | -------------------------------------------------------------------------------- /include/qrencode/3rd/bitstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Binary sequence class. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __BITSTREAM_H__ 23 | #define __BITSTREAM_H__ 24 | 25 | typedef struct { 26 | int length; 27 | unsigned char *data; 28 | } BitStream; 29 | 30 | extern BitStream *BitStream_new(void); 31 | extern int BitStream_append(BitStream *bstream, BitStream *arg); 32 | extern int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num); 33 | extern int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data); 34 | #define BitStream_size(__bstream__) (__bstream__->length) 35 | extern unsigned char *BitStream_toByte(BitStream *bstream); 36 | extern void BitStream_free(BitStream *bstream); 37 | 38 | #endif /* __BITSTREAM_H__ */ 39 | -------------------------------------------------------------------------------- /include/qrencode/3rd/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | // #define HAVE_DLFCN_H 1 6 | 7 | /* Define if you have the iconv() function and it works. */ 8 | /* #undef HAVE_ICONV */ 9 | 10 | /* Define to 1 if you have the header file. */ 11 | // #define HAVE_INTTYPES_H 1 12 | 13 | /* Define to 1 if using pthread is enabled. */ 14 | #define HAVE_LIBPTHREAD 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | // #define HAVE_MEMORY_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | // #define HAVE_STDINT_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | // #define HAVE_STDLIB_H 1 24 | 25 | /* Define to 1 if you have the `strdup' function. */ 26 | // #define HAVE_STRDUP 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | // #define HAVE_STRINGS_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | // #define HAVE_STRING_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | // #define HAVE_SYS_STAT_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | // #define HAVE_SYS_TYPES_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | // #define HAVE_UNISTD_H 1 42 | 43 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 44 | */ 45 | // #define LT_OBJDIR ".libs/" 46 | 47 | /* Major version number */ 48 | #define MAJOR_VERSION 3 49 | 50 | /* Micro version number */ 51 | #define MICRO_VERSION 3 52 | 53 | /* Minor version number */ 54 | #define MINOR_VERSION 4 55 | 56 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */ 57 | /* #undef NO_MINUS_C_MINUS_O */ 58 | 59 | /* Name of package */ 60 | // #define PACKAGE "qrencode" 61 | 62 | /* Define to the address where bug reports for this package should be sent. */ 63 | // #define PACKAGE_BUGREPORT "" 64 | 65 | /* Define to the full name of this package. */ 66 | // #define PACKAGE_NAME "" 67 | 68 | /* Define to the full name and version of this package. */ 69 | // #define PACKAGE_STRING "" 70 | 71 | /* Define to the one symbol short name of this package. */ 72 | // #define PACKAGE_TARNAME "" 73 | 74 | /* Define to the home page for this package. */ 75 | // #define PACKAGE_URL "" 76 | 77 | /* Define to the version of this package. */ 78 | // #define PACKAGE_VERSION "" 79 | 80 | /* Define to 1 if you have the ANSI C header files. */ 81 | // #define STDC_HEADERS 1 82 | 83 | /* Version number of package */ 84 | #define VERSION "3.4.3" 85 | 86 | /* Define to empty if `const' does not conform to ANSI C. */ 87 | /* #undef const */ 88 | 89 | /* Define to `__inline__' or `__inline' if that's what the C compiler 90 | calls it, or to nothing if 'inline' is not supported under any name. */ 91 | #ifndef __cplusplus 92 | /* #undef inline */ 93 | #endif 94 | 95 | /* Define to 'static' if no test programs will be compiled. */ 96 | #define __STATIC static 97 | /* #undef WITH_TESTS */ 98 | 99 | -------------------------------------------------------------------------------- /include/qrencode/3rd/mask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Masking. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MASK_H__ 23 | #define __MASK_H__ 24 | 25 | extern unsigned char *Mask_makeMask(int width, unsigned char *frame, int mask, QRecLevel level); 26 | extern unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level); 27 | 28 | #ifdef WITH_TESTS 29 | extern int Mask_calcN2(int width, unsigned char *frame); 30 | extern int Mask_calcN1N3(int length, int *runLength); 31 | extern int Mask_calcRunLength(int width, unsigned char *frame, int dir, int *runLength); 32 | extern int Mask_evaluateSymbol(int width, unsigned char *frame); 33 | extern int Mask_writeFormatInformation(int width, unsigned char *frame, int mask, QRecLevel level); 34 | extern unsigned char *Mask_makeMaskedFrame(int width, unsigned char *frame, int mask); 35 | #endif 36 | 37 | #endif /* __MASK_H__ */ 38 | -------------------------------------------------------------------------------- /include/qrencode/3rd/mmask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Masking for Micro QR Code. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MMASK_H__ 23 | #define __MMASK_H__ 24 | 25 | extern unsigned char *MMask_makeMask(int version, unsigned char *frame, int mask, QRecLevel level); 26 | extern unsigned char *MMask_mask(int version, unsigned char *frame, QRecLevel level); 27 | 28 | #ifdef WITH_TESTS 29 | extern int MMask_evaluateSymbol(int width, unsigned char *frame); 30 | extern void MMask_writeFormatInformation(int version, int width, unsigned char *frame, int mask, QRecLevel level); 31 | extern unsigned char *MMask_makeMaskedFrame(int width, unsigned char *frame, int mask); 32 | #endif 33 | 34 | #endif /* __MMASK_H__ */ 35 | -------------------------------------------------------------------------------- /include/qrencode/3rd/mqrspec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Micro QR Code specification in convenient format. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MQRSPEC_H__ 23 | #define __MQRSPEC_H__ 24 | 25 | #include "qrencode.h" 26 | 27 | /****************************************************************************** 28 | * Version and capacity 29 | *****************************************************************************/ 30 | 31 | /** 32 | * Maximum width of a symbol 33 | */ 34 | #define MQRSPEC_WIDTH_MAX 17 35 | 36 | /** 37 | * Return maximum data code length (bits) for the version. 38 | * @param version 39 | * @param level 40 | * @return maximum size (bits) 41 | */ 42 | extern int MQRspec_getDataLengthBit(int version, QRecLevel level); 43 | 44 | /** 45 | * Return maximum data code length (bytes) for the version. 46 | * @param version 47 | * @param level 48 | * @return maximum size (bytes) 49 | */ 50 | extern int MQRspec_getDataLength(int version, QRecLevel level); 51 | 52 | /** 53 | * Return maximum error correction code length (bytes) for the version. 54 | * @param version 55 | * @param level 56 | * @return ECC size (bytes) 57 | */ 58 | extern int MQRspec_getECCLength(int version, QRecLevel level); 59 | 60 | /** 61 | * Return a version number that satisfies the input code length. 62 | * @param size input code length (byte) 63 | * @param level 64 | * @return version number 65 | */ 66 | extern int MQRspec_getMinimumVersion(int size, QRecLevel level); 67 | 68 | /** 69 | * Return the width of the symbol for the version. 70 | * @param version 71 | * @return width 72 | */ 73 | extern int MQRspec_getWidth(int version); 74 | 75 | /** 76 | * Return the numer of remainder bits. 77 | * @param version 78 | * @return number of remainder bits 79 | */ 80 | extern int MQRspec_getRemainder(int version); 81 | 82 | /****************************************************************************** 83 | * Length indicator 84 | *****************************************************************************/ 85 | 86 | /** 87 | * Return the size of lenght indicator for the mode and version. 88 | * @param mode 89 | * @param version 90 | * @return the size of the appropriate length indicator (bits). 91 | */ 92 | extern int MQRspec_lengthIndicator(QRencodeMode mode, int version); 93 | 94 | /** 95 | * Return the maximum length for the mode and version. 96 | * @param mode 97 | * @param version 98 | * @return the maximum length (bytes) 99 | */ 100 | extern int MQRspec_maximumWords(QRencodeMode mode, int version); 101 | 102 | /****************************************************************************** 103 | * Version information pattern 104 | *****************************************************************************/ 105 | 106 | /** 107 | * Return BCH encoded version information pattern that is used for the symbol 108 | * of version 7 or greater. Use lower 18 bits. 109 | * @param version 110 | * @return BCH encoded version information pattern 111 | */ 112 | extern unsigned int MQRspec_getVersionPattern(int version); 113 | 114 | /****************************************************************************** 115 | * Format information 116 | *****************************************************************************/ 117 | 118 | /** 119 | * Return BCH encoded format information pattern. 120 | * @param mask 121 | * @param version 122 | * @param level 123 | * @return BCH encoded format information pattern 124 | */ 125 | extern unsigned int MQRspec_getFormatInfo(int mask, int version, QRecLevel level); 126 | 127 | /****************************************************************************** 128 | * Frame 129 | *****************************************************************************/ 130 | 131 | /** 132 | * Return a copy of initialized frame. 133 | * When the same version is requested twice or more, a copy of cached frame 134 | * is returned. 135 | * @param version 136 | * @return Array of unsigned char. You can free it by free(). 137 | */ 138 | extern unsigned char *MQRspec_newFrame(int version); 139 | 140 | /** 141 | * Clear the frame cache. Typically for debug. 142 | */ 143 | extern void MQRspec_clearCache(void); 144 | 145 | /****************************************************************************** 146 | * Mode indicator 147 | *****************************************************************************/ 148 | 149 | /** 150 | * Mode indicator. See Table 2 in Appendix 1 of JIS X0510:2004, pp.107. 151 | */ 152 | #define MQRSPEC_MODEID_NUM 0 153 | #define MQRSPEC_MODEID_AN 1 154 | #define MQRSPEC_MODEID_8 2 155 | #define MQRSPEC_MODEID_KANJI 3 156 | 157 | #endif /* __MQRSPEC_H__ */ 158 | -------------------------------------------------------------------------------- /include/qrencode/3rd/qrencode_inner.h: -------------------------------------------------------------------------------- 1 | /** 2 | * qrencode - QR Code encoder 3 | * 4 | * Header for test use 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRENCODE_INNER_H__ 23 | #define __QRENCODE_INNER_H__ 24 | 25 | /** 26 | * This header file includes definitions for test use. 27 | */ 28 | 29 | /****************************************************************************** 30 | * Raw code 31 | *****************************************************************************/ 32 | 33 | typedef struct { 34 | int dataLength; 35 | unsigned char *data; 36 | int eccLength; 37 | unsigned char *ecc; 38 | } RSblock; 39 | 40 | typedef struct { 41 | int version; 42 | int dataLength; 43 | int eccLength; 44 | unsigned char *datacode; 45 | unsigned char *ecccode; 46 | int b1; 47 | int blocks; 48 | RSblock *rsblock; 49 | int count; 50 | } QRRawCode; 51 | 52 | extern QRRawCode *QRraw_new(QRinput *input); 53 | extern unsigned char QRraw_getCode(QRRawCode *raw); 54 | extern void QRraw_free(QRRawCode *raw); 55 | 56 | /****************************************************************************** 57 | * Raw code for Micro QR Code 58 | *****************************************************************************/ 59 | 60 | typedef struct { 61 | int version; 62 | int dataLength; 63 | int eccLength; 64 | unsigned char *datacode; 65 | unsigned char *ecccode; 66 | RSblock *rsblock; 67 | int oddbits; 68 | int count; 69 | } MQRRawCode; 70 | 71 | extern MQRRawCode *MQRraw_new(QRinput *input); 72 | extern unsigned char MQRraw_getCode(MQRRawCode *raw); 73 | extern void MQRraw_free(MQRRawCode *raw); 74 | 75 | /****************************************************************************** 76 | * Frame filling 77 | *****************************************************************************/ 78 | extern unsigned char *FrameFiller_test(int version); 79 | extern unsigned char *FrameFiller_testMQR(int version); 80 | 81 | /****************************************************************************** 82 | * QR-code encoding 83 | *****************************************************************************/ 84 | extern QRcode *QRcode_encodeMask(QRinput *input, int mask); 85 | extern QRcode *QRcode_encodeMaskMQR(QRinput *input, int mask); 86 | extern QRcode *QRcode_new(int version, int width, unsigned char *data); 87 | 88 | #endif /* __QRENCODE_INNER_H__ */ 89 | -------------------------------------------------------------------------------- /include/qrencode/3rd/qrinput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Input data chunk class 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRINPUT_H__ 23 | #define __QRINPUT_H__ 24 | 25 | #include "qrencode.h" 26 | #include "bitstream.h" 27 | 28 | int QRinput_isSplittableMode(QRencodeMode mode); 29 | 30 | /****************************************************************************** 31 | * Entry of input data 32 | *****************************************************************************/ 33 | typedef struct _QRinput_List QRinput_List; 34 | 35 | struct _QRinput_List { 36 | QRencodeMode mode; 37 | int size; ///< Size of data chunk (byte). 38 | unsigned char *data; ///< Data chunk. 39 | BitStream *bstream; 40 | QRinput_List *next; 41 | }; 42 | 43 | /****************************************************************************** 44 | * Input Data 45 | *****************************************************************************/ 46 | struct _QRinput { 47 | int version; 48 | QRecLevel level; 49 | QRinput_List *head; 50 | QRinput_List *tail; 51 | int mqr; 52 | int fnc1; 53 | unsigned char appid; 54 | }; 55 | 56 | /****************************************************************************** 57 | * Structured append input data 58 | *****************************************************************************/ 59 | typedef struct _QRinput_InputList QRinput_InputList; 60 | 61 | struct _QRinput_InputList { 62 | QRinput *input; 63 | QRinput_InputList *next; 64 | }; 65 | 66 | struct _QRinput_Struct { 67 | int size; ///< number of structured symbols 68 | int parity; 69 | QRinput_InputList *head; 70 | QRinput_InputList *tail; 71 | }; 72 | 73 | /** 74 | * Pack all bit streams padding bits into a byte array. 75 | * @param input input data. 76 | * @return padded merged byte stream 77 | */ 78 | extern unsigned char *QRinput_getByteStream(QRinput *input); 79 | 80 | 81 | extern int QRinput_estimateBitsModeNum(int size); 82 | extern int QRinput_estimateBitsModeAn(int size); 83 | extern int QRinput_estimateBitsMode8(int size); 84 | extern int QRinput_estimateBitsModeKanji(int size); 85 | 86 | extern QRinput *QRinput_dup(QRinput *input); 87 | 88 | extern const signed char QRinput_anTable[128]; 89 | 90 | /** 91 | * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19). 92 | * @param __c__ character 93 | * @return value 94 | */ 95 | #define QRinput_lookAnTable(__c__) \ 96 | ((__c__ & 0x80)?-1:QRinput_anTable[(int)__c__]) 97 | 98 | /** 99 | * Length of a standard mode indicator in bits. 100 | */ 101 | 102 | #define MODE_INDICATOR_SIZE 4 103 | 104 | /** 105 | * Length of a segment of structured-append header. 106 | */ 107 | #define STRUCTURE_HEADER_SIZE 20 108 | 109 | /** 110 | * Maximum number of symbols in a set of structured-appended symbols. 111 | */ 112 | #define MAX_STRUCTURED_SYMBOLS 16 113 | 114 | #ifdef WITH_TESTS 115 | extern BitStream *QRinput_mergeBitStream(QRinput *input); 116 | extern BitStream *QRinput_getBitStream(QRinput *input); 117 | extern int QRinput_estimateBitStreamSize(QRinput *input, int version); 118 | extern int QRinput_splitEntry(QRinput_List *entry, int bytes); 119 | extern int QRinput_lengthOfCode(QRencodeMode mode, int version, int bits); 120 | extern int QRinput_insertStructuredAppendHeader(QRinput *input, int size, int index, unsigned char parity); 121 | #endif 122 | 123 | #endif /* __QRINPUT_H__ */ 124 | -------------------------------------------------------------------------------- /include/qrencode/3rd/qrspec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * QR Code specification in convenient format. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRSPEC_H__ 23 | #define __QRSPEC_H__ 24 | 25 | #include "qrencode.h" 26 | 27 | /****************************************************************************** 28 | * Version and capacity 29 | *****************************************************************************/ 30 | 31 | /** 32 | * Maximum width of a symbol 33 | */ 34 | #define QRSPEC_WIDTH_MAX 177 35 | 36 | /** 37 | * Return maximum data code length (bytes) for the version. 38 | * @param version 39 | * @param level 40 | * @return maximum size (bytes) 41 | */ 42 | extern int QRspec_getDataLength(int version, QRecLevel level); 43 | 44 | /** 45 | * Return maximum error correction code length (bytes) for the version. 46 | * @param version 47 | * @param level 48 | * @return ECC size (bytes) 49 | */ 50 | extern int QRspec_getECCLength(int version, QRecLevel level); 51 | 52 | /** 53 | * Return a version number that satisfies the input code length. 54 | * @param size input code length (byte) 55 | * @param level 56 | * @return version number 57 | */ 58 | extern int QRspec_getMinimumVersion(int size, QRecLevel level); 59 | 60 | /** 61 | * Return the width of the symbol for the version. 62 | * @param version 63 | * @return width 64 | */ 65 | extern int QRspec_getWidth(int version); 66 | 67 | /** 68 | * Return the numer of remainder bits. 69 | * @param version 70 | * @return number of remainder bits 71 | */ 72 | extern int QRspec_getRemainder(int version); 73 | 74 | /****************************************************************************** 75 | * Length indicator 76 | *****************************************************************************/ 77 | 78 | /** 79 | * Return the size of lenght indicator for the mode and version. 80 | * @param mode 81 | * @param version 82 | * @return the size of the appropriate length indicator (bits). 83 | */ 84 | extern int QRspec_lengthIndicator(QRencodeMode mode, int version); 85 | 86 | /** 87 | * Return the maximum length for the mode and version. 88 | * @param mode 89 | * @param version 90 | * @return the maximum length (bytes) 91 | */ 92 | extern int QRspec_maximumWords(QRencodeMode mode, int version); 93 | 94 | /****************************************************************************** 95 | * Error correction code 96 | *****************************************************************************/ 97 | 98 | /** 99 | * Return an array of ECC specification. 100 | * @param version 101 | * @param level 102 | * @param spec an array of ECC specification contains as following: 103 | * {# of type1 blocks, # of data code, # of ecc code, 104 | * # of type2 blocks, # of data code} 105 | */ 106 | void QRspec_getEccSpec(int version, QRecLevel level, int spec[5]); 107 | 108 | #define QRspec_rsBlockNum(__spec__) (__spec__[0] + __spec__[3]) 109 | #define QRspec_rsBlockNum1(__spec__) (__spec__[0]) 110 | #define QRspec_rsDataCodes1(__spec__) (__spec__[1]) 111 | #define QRspec_rsEccCodes1(__spec__) (__spec__[2]) 112 | #define QRspec_rsBlockNum2(__spec__) (__spec__[3]) 113 | #define QRspec_rsDataCodes2(__spec__) (__spec__[4]) 114 | #define QRspec_rsEccCodes2(__spec__) (__spec__[2]) 115 | 116 | #define QRspec_rsDataLength(__spec__) \ 117 | ((QRspec_rsBlockNum1(__spec__) * QRspec_rsDataCodes1(__spec__)) + \ 118 | (QRspec_rsBlockNum2(__spec__) * QRspec_rsDataCodes2(__spec__))) 119 | #define QRspec_rsEccLength(__spec__) \ 120 | (QRspec_rsBlockNum(__spec__) * QRspec_rsEccCodes1(__spec__)) 121 | 122 | /****************************************************************************** 123 | * Version information pattern 124 | *****************************************************************************/ 125 | 126 | /** 127 | * Return BCH encoded version information pattern that is used for the symbol 128 | * of version 7 or greater. Use lower 18 bits. 129 | * @param version 130 | * @return BCH encoded version information pattern 131 | */ 132 | extern unsigned int QRspec_getVersionPattern(int version); 133 | 134 | /****************************************************************************** 135 | * Format information 136 | *****************************************************************************/ 137 | 138 | /** 139 | * Return BCH encoded format information pattern. 140 | * @param mask 141 | * @param level 142 | * @return BCH encoded format information pattern 143 | */ 144 | extern unsigned int QRspec_getFormatInfo(int mask, QRecLevel level); 145 | 146 | /****************************************************************************** 147 | * Frame 148 | *****************************************************************************/ 149 | 150 | /** 151 | * Return a copy of initialized frame. 152 | * When the same version is requested twice or more, a copy of cached frame 153 | * is returned. 154 | * @param version 155 | * @return Array of unsigned char. You can free it by free(). 156 | */ 157 | extern unsigned char *QRspec_newFrame(int version); 158 | 159 | /** 160 | * Clear the frame cache. Typically for debug. 161 | */ 162 | extern void QRspec_clearCache(void); 163 | 164 | /****************************************************************************** 165 | * Mode indicator 166 | *****************************************************************************/ 167 | 168 | /** 169 | * Mode indicator. See Table 2 of JIS X0510:2004, pp.16. 170 | */ 171 | #define QRSPEC_MODEID_ECI 7 172 | #define QRSPEC_MODEID_NUM 1 173 | #define QRSPEC_MODEID_AN 2 174 | #define QRSPEC_MODEID_8 4 175 | #define QRSPEC_MODEID_KANJI 8 176 | #define QRSPEC_MODEID_FNC1FIRST 5 177 | #define QRSPEC_MODEID_FNC1SECOND 9 178 | #define QRSPEC_MODEID_STRUCTURE 3 179 | #define QRSPEC_MODEID_TERMINATOR 0 180 | 181 | #endif /* __QRSPEC_H__ */ 182 | -------------------------------------------------------------------------------- /include/qrencode/3rd/rscode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Reed solomon encoder. This code is taken from Phil Karn's libfec then 5 | * editted and packed into a pair of .c and .h files. 6 | * 7 | * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q 8 | * (libfec is released under the GNU Lesser General Public License.) 9 | * 10 | * Copyright (C) 2006-2011 Kentaro Fukuchi 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2.1 of the License, or any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef __RSCODE_H__ 28 | #define __RSCODE_H__ 29 | 30 | /* 31 | * General purpose RS codec, 8-bit symbols. 32 | */ 33 | 34 | typedef struct _RS RS; 35 | 36 | extern RS *init_rs(int symsize, int gfpoly, int fcr, int prim, int nroots, int pad); 37 | extern void encode_rs_char(RS *rs, const unsigned char *data, unsigned char *parity); 38 | extern void free_rs_char(RS *rs); 39 | extern void free_rs_cache(void); 40 | 41 | #endif /* __RSCODE_H__ */ 42 | -------------------------------------------------------------------------------- /include/qrencode/3rd/split.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Input data splitter. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * The following data / specifications are taken from 8 | * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) 9 | * or 10 | * "Automatic identification and data capture techniques -- 11 | * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) 12 | * 13 | * This library is free software; you can redistribute it and/or 14 | * modify it under the terms of the GNU Lesser General Public 15 | * License as published by the Free Software Foundation; either 16 | * version 2.1 of the License, or any later version. 17 | * 18 | * This library is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | * Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public 24 | * License along with this library; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef __SPLIT_H__ 29 | #define __SPLIT_H__ 30 | 31 | #include "qrencode.h" 32 | 33 | /** 34 | * Split the input string (null terminated) into QRinput. 35 | * @param string input string 36 | * @param hint give QR_MODE_KANJI if the input string contains Kanji character encoded in Shift-JIS. If not, give QR_MODE_8. 37 | * @param casesensitive 0 for case-insensitive encoding (all alphabet characters are replaced to UPPER-CASE CHARACTERS. 38 | * @retval 0 success. 39 | * @retval -1 an error occurred. errno is set to indicate the error. See 40 | * Exceptions for the details. 41 | * @throw EINVAL invalid input object. 42 | * @throw ENOMEM unable to allocate memory for input objects. 43 | */ 44 | extern int Split_splitStringToQRinput(const char *string, QRinput *input, 45 | QRencodeMode hint, int casesensitive); 46 | 47 | #endif /* __SPLIT_H__ */ 48 | -------------------------------------------------------------------------------- /include/qrencode/qrencode.pri: -------------------------------------------------------------------------------- 1 | 2 | INCLUDEPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/qrencode/3rd/bitstream.h \ 6 | $$PWD/qrencode/3rd/config.h \ 7 | $$PWD/qrencode/3rd/mask.h \ 8 | $$PWD/qrencode/3rd/mmask.h \ 9 | $$PWD/qrencode/3rd/mqrspec.h \ 10 | $$PWD/qrencode/3rd/qrencode.h \ 11 | $$PWD/qrencode/3rd/qrencode_inner.h \ 12 | $$PWD/qrencode/3rd/qrinput.h \ 13 | $$PWD/qrencode/3rd/qrspec.h \ 14 | $$PWD/qrencode/3rd/rscode.h \ 15 | $$PWD/qrencode/3rd/split.h 16 | 17 | SOURCES += \ 18 | $$PWD/qrencode/3rd/bitstream.c \ 19 | $$PWD/qrencode/3rd/mask.c \ 20 | $$PWD/qrencode/3rd/mmask.c \ 21 | $$PWD/qrencode/3rd/mqrspec.c \ 22 | $$PWD/qrencode/3rd/qrencode.c \ 23 | $$PWD/qrencode/3rd/qrinput.c \ 24 | $$PWD/qrencode/3rd/qrspec.c \ 25 | $$PWD/qrencode/3rd/rscode.c \ 26 | $$PWD/qrencode/3rd/split.c 27 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/bitstream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Binary sequence class. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "config.h" 23 | #include 24 | #include 25 | #include 26 | 27 | #include "bitstream.h" 28 | 29 | BitStream *BitStream_new(void) 30 | { 31 | BitStream *bstream; 32 | 33 | bstream = (BitStream *)malloc(sizeof(BitStream)); 34 | if(bstream == NULL) return NULL; 35 | 36 | bstream->length = 0; 37 | bstream->data = NULL; 38 | 39 | return bstream; 40 | } 41 | 42 | static int BitStream_allocate(BitStream *bstream, int length) 43 | { 44 | unsigned char *data; 45 | 46 | if(bstream == NULL) { 47 | return -1; 48 | } 49 | 50 | data = (unsigned char *)malloc(length); 51 | if(data == NULL) { 52 | return -1; 53 | } 54 | 55 | if(bstream->data) { 56 | free(bstream->data); 57 | } 58 | bstream->length = length; 59 | bstream->data = data; 60 | 61 | return 0; 62 | } 63 | 64 | static BitStream *BitStream_newFromNum(int bits, unsigned int num) 65 | { 66 | unsigned int mask; 67 | int i; 68 | unsigned char *p; 69 | BitStream *bstream; 70 | 71 | bstream = BitStream_new(); 72 | if(bstream == NULL) return NULL; 73 | 74 | if(BitStream_allocate(bstream, bits)) { 75 | BitStream_free(bstream); 76 | return NULL; 77 | } 78 | 79 | p = bstream->data; 80 | mask = 1 << (bits - 1); 81 | for(i=0; i> 1; 89 | } 90 | 91 | return bstream; 92 | } 93 | 94 | static BitStream *BitStream_newFromBytes(int size, unsigned char *data) 95 | { 96 | unsigned char mask; 97 | int i, j; 98 | unsigned char *p; 99 | BitStream *bstream; 100 | 101 | bstream = BitStream_new(); 102 | if(bstream == NULL) return NULL; 103 | 104 | if(BitStream_allocate(bstream, size * 8)) { 105 | BitStream_free(bstream); 106 | return NULL; 107 | } 108 | 109 | p = bstream->data; 110 | for(i=0; i> 1; 120 | } 121 | } 122 | 123 | return bstream; 124 | } 125 | 126 | int BitStream_append(BitStream *bstream, BitStream *arg) 127 | { 128 | unsigned char *data; 129 | 130 | if(arg == NULL) { 131 | return -1; 132 | } 133 | if(arg->length == 0) { 134 | return 0; 135 | } 136 | if(bstream->length == 0) { 137 | if(BitStream_allocate(bstream, arg->length)) { 138 | return -1; 139 | } 140 | memcpy(bstream->data, arg->data, arg->length); 141 | return 0; 142 | } 143 | 144 | data = (unsigned char *)malloc(bstream->length + arg->length); 145 | if(data == NULL) { 146 | return -1; 147 | } 148 | memcpy(data, bstream->data, bstream->length); 149 | memcpy(data + bstream->length, arg->data, arg->length); 150 | 151 | free(bstream->data); 152 | bstream->length += arg->length; 153 | bstream->data = data; 154 | 155 | return 0; 156 | } 157 | 158 | int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num) 159 | { 160 | BitStream *b; 161 | int ret; 162 | 163 | if(bits == 0) return 0; 164 | 165 | b = BitStream_newFromNum(bits, num); 166 | if(b == NULL) return -1; 167 | 168 | ret = BitStream_append(bstream, b); 169 | BitStream_free(b); 170 | 171 | return ret; 172 | } 173 | 174 | int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data) 175 | { 176 | BitStream *b; 177 | int ret; 178 | 179 | if(size == 0) return 0; 180 | 181 | b = BitStream_newFromBytes(size, data); 182 | if(b == NULL) return -1; 183 | 184 | ret = BitStream_append(bstream, b); 185 | BitStream_free(b); 186 | 187 | return ret; 188 | } 189 | 190 | unsigned char *BitStream_toByte(BitStream *bstream) 191 | { 192 | int i, j, size, bytes; 193 | unsigned char *data, v; 194 | unsigned char *p; 195 | 196 | size = BitStream_size(bstream); 197 | if(size == 0) { 198 | return NULL; 199 | } 200 | data = (unsigned char *)malloc((size + 7) / 8); 201 | if(data == NULL) { 202 | return NULL; 203 | } 204 | 205 | bytes = size / 8; 206 | 207 | p = bstream->data; 208 | for(i=0; idata); 234 | free(bstream); 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/bitstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Binary sequence class. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __BITSTREAM_H__ 23 | #define __BITSTREAM_H__ 24 | 25 | typedef struct { 26 | int length; 27 | unsigned char *data; 28 | } BitStream; 29 | 30 | extern BitStream *BitStream_new(void); 31 | extern int BitStream_append(BitStream *bstream, BitStream *arg); 32 | extern int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num); 33 | extern int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data); 34 | #define BitStream_size(__bstream__) (__bstream__->length) 35 | extern unsigned char *BitStream_toByte(BitStream *bstream); 36 | extern void BitStream_free(BitStream *bstream); 37 | 38 | #endif /* __BITSTREAM_H__ */ 39 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | // #define HAVE_DLFCN_H 1 6 | 7 | /* Define if you have the iconv() function and it works. */ 8 | /* #undef HAVE_ICONV */ 9 | 10 | /* Define to 1 if you have the header file. */ 11 | // #define HAVE_INTTYPES_H 1 12 | 13 | /* Define to 1 if using pthread is enabled. */ 14 | #ifndef WIN32 15 | #define HAVE_LIBPTHREAD 1 16 | #endif 17 | /* Define to 1 if you have the header file. */ 18 | // #define HAVE_MEMORY_H 1 19 | 20 | /* Define to 1 if you have the header file. */ 21 | // #define HAVE_STDINT_H 1 22 | 23 | /* Define to 1 if you have the header file. */ 24 | // #define HAVE_STDLIB_H 1 25 | 26 | /* Define to 1 if you have the `strdup' function. */ 27 | // #define HAVE_STRDUP 1 28 | 29 | /* Define to 1 if you have the header file. */ 30 | // #define HAVE_STRINGS_H 1 31 | 32 | /* Define to 1 if you have the header file. */ 33 | // #define HAVE_STRING_H 1 34 | 35 | /* Define to 1 if you have the header file. */ 36 | // #define HAVE_SYS_STAT_H 1 37 | 38 | /* Define to 1 if you have the header file. */ 39 | // #define HAVE_SYS_TYPES_H 1 40 | 41 | /* Define to 1 if you have the header file. */ 42 | // #define HAVE_UNISTD_H 1 43 | 44 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 45 | */ 46 | // #define LT_OBJDIR ".libs/" 47 | 48 | /* Major version number */ 49 | #define MAJOR_VERSION 3 50 | 51 | /* Micro version number */ 52 | #define MICRO_VERSION 3 53 | 54 | /* Minor version number */ 55 | #define MINOR_VERSION 4 56 | 57 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */ 58 | /* #undef NO_MINUS_C_MINUS_O */ 59 | 60 | /* Name of package */ 61 | // #define PACKAGE "qrencode" 62 | 63 | /* Define to the address where bug reports for this package should be sent. */ 64 | // #define PACKAGE_BUGREPORT "" 65 | 66 | /* Define to the full name of this package. */ 67 | // #define PACKAGE_NAME "" 68 | 69 | /* Define to the full name and version of this package. */ 70 | // #define PACKAGE_STRING "" 71 | 72 | /* Define to the one symbol short name of this package. */ 73 | // #define PACKAGE_TARNAME "" 74 | 75 | /* Define to the home page for this package. */ 76 | // #define PACKAGE_URL "" 77 | 78 | /* Define to the version of this package. */ 79 | // #define PACKAGE_VERSION "" 80 | 81 | /* Define to 1 if you have the ANSI C header files. */ 82 | // #define STDC_HEADERS 1 83 | 84 | /* Version number of package */ 85 | #define VERSION "3.4.3" 86 | 87 | /* Define to empty if `const' does not conform to ANSI C. */ 88 | /* #undef const */ 89 | 90 | /* Define to `__inline__' or `__inline' if that's what the C compiler 91 | calls it, or to nothing if 'inline' is not supported under any name. */ 92 | #ifndef __cplusplus 93 | /* #undef inline */ 94 | #endif 95 | 96 | /* Define to 'static' if no test programs will be compiled. */ 97 | #define __STATIC static 98 | /* #undef WITH_TESTS */ 99 | 100 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/mask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Masking. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MASK_H__ 23 | #define __MASK_H__ 24 | 25 | extern unsigned char *Mask_makeMask(int width, unsigned char *frame, int mask, QRecLevel level); 26 | extern unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level); 27 | 28 | #ifdef WITH_TESTS 29 | extern int Mask_calcN2(int width, unsigned char *frame); 30 | extern int Mask_calcN1N3(int length, int *runLength); 31 | extern int Mask_calcRunLength(int width, unsigned char *frame, int dir, int *runLength); 32 | extern int Mask_evaluateSymbol(int width, unsigned char *frame); 33 | extern int Mask_writeFormatInformation(int width, unsigned char *frame, int mask, QRecLevel level); 34 | extern unsigned char *Mask_makeMaskedFrame(int width, unsigned char *frame, int mask); 35 | #endif 36 | 37 | #endif /* __MASK_H__ */ 38 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/mmask.c: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Masking for Micro QR Code. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "config.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "qrencode.h" 29 | #include "mqrspec.h" 30 | #include "mmask.h" 31 | 32 | 33 | __STATIC void MMask_writeFormatInformation(int version, int width, unsigned char *frame, int mask, QRecLevel level) 34 | { 35 | unsigned int format; 36 | unsigned char v; 37 | int i; 38 | 39 | format = MQRspec_getFormatInfo(mask, version, level); 40 | 41 | for(i=0; i<8; i++) { 42 | v = 0x84 | (format & 1); 43 | frame[width * (i + 1) + 8] = v; 44 | format = format >> 1; 45 | } 46 | for(i=0; i<7; i++) { 47 | v = 0x84 | (format & 1); 48 | frame[width * 8 + 7 - i] = v; 49 | format = format >> 1; 50 | } 51 | } 52 | 53 | #define MASKMAKER(__exp__) \ 54 | int x, y;\ 55 | \ 56 | for(y=0; y= maskNum) { 113 | errno = EINVAL; 114 | return NULL; 115 | } 116 | 117 | width = MQRspec_getWidth(version); 118 | masked = (unsigned char *)malloc(width * width); 119 | if(masked == NULL) return NULL; 120 | 121 | maskMakers[mask](width, frame, masked); 122 | MMask_writeFormatInformation(version, width, masked, mask, level); 123 | 124 | return masked; 125 | } 126 | 127 | __STATIC int MMask_evaluateSymbol(int width, unsigned char *frame) 128 | { 129 | int x, y; 130 | unsigned char *p; 131 | int sum1 = 0, sum2 = 0; 132 | 133 | p = frame + width * (width - 1); 134 | for(x=1; x maxScore) { 167 | maxScore = score; 168 | free(bestMask); 169 | bestMask = mask; 170 | mask = (unsigned char *)malloc(width * width); 171 | if(mask == NULL) break; 172 | } 173 | } 174 | free(mask); 175 | return bestMask; 176 | } 177 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/mmask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Masking for Micro QR Code. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MMASK_H__ 23 | #define __MMASK_H__ 24 | 25 | extern unsigned char *MMask_makeMask(int version, unsigned char *frame, int mask, QRecLevel level); 26 | extern unsigned char *MMask_mask(int version, unsigned char *frame, QRecLevel level); 27 | 28 | #ifdef WITH_TESTS 29 | extern int MMask_evaluateSymbol(int width, unsigned char *frame); 30 | extern void MMask_writeFormatInformation(int version, int width, unsigned char *frame, int mask, QRecLevel level); 31 | extern unsigned char *MMask_makeMaskedFrame(int width, unsigned char *frame, int mask); 32 | #endif 33 | 34 | #endif /* __MMASK_H__ */ 35 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/mqrspec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Micro QR Code specification in convenient format. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MQRSPEC_H__ 23 | #define __MQRSPEC_H__ 24 | 25 | #include "qrencode.h" 26 | 27 | /****************************************************************************** 28 | * Version and capacity 29 | *****************************************************************************/ 30 | 31 | /** 32 | * Maximum width of a symbol 33 | */ 34 | #define MQRSPEC_WIDTH_MAX 17 35 | 36 | /** 37 | * Return maximum data code length (bits) for the version. 38 | * @param version 39 | * @param level 40 | * @return maximum size (bits) 41 | */ 42 | extern int MQRspec_getDataLengthBit(int version, QRecLevel level); 43 | 44 | /** 45 | * Return maximum data code length (bytes) for the version. 46 | * @param version 47 | * @param level 48 | * @return maximum size (bytes) 49 | */ 50 | extern int MQRspec_getDataLength(int version, QRecLevel level); 51 | 52 | /** 53 | * Return maximum error correction code length (bytes) for the version. 54 | * @param version 55 | * @param level 56 | * @return ECC size (bytes) 57 | */ 58 | extern int MQRspec_getECCLength(int version, QRecLevel level); 59 | 60 | /** 61 | * Return a version number that satisfies the input code length. 62 | * @param size input code length (byte) 63 | * @param level 64 | * @return version number 65 | */ 66 | extern int MQRspec_getMinimumVersion(int size, QRecLevel level); 67 | 68 | /** 69 | * Return the width of the symbol for the version. 70 | * @param version 71 | * @return width 72 | */ 73 | extern int MQRspec_getWidth(int version); 74 | 75 | /** 76 | * Return the numer of remainder bits. 77 | * @param version 78 | * @return number of remainder bits 79 | */ 80 | extern int MQRspec_getRemainder(int version); 81 | 82 | /****************************************************************************** 83 | * Length indicator 84 | *****************************************************************************/ 85 | 86 | /** 87 | * Return the size of lenght indicator for the mode and version. 88 | * @param mode 89 | * @param version 90 | * @return the size of the appropriate length indicator (bits). 91 | */ 92 | extern int MQRspec_lengthIndicator(QRencodeMode mode, int version); 93 | 94 | /** 95 | * Return the maximum length for the mode and version. 96 | * @param mode 97 | * @param version 98 | * @return the maximum length (bytes) 99 | */ 100 | extern int MQRspec_maximumWords(QRencodeMode mode, int version); 101 | 102 | /****************************************************************************** 103 | * Version information pattern 104 | *****************************************************************************/ 105 | 106 | /** 107 | * Return BCH encoded version information pattern that is used for the symbol 108 | * of version 7 or greater. Use lower 18 bits. 109 | * @param version 110 | * @return BCH encoded version information pattern 111 | */ 112 | extern unsigned int MQRspec_getVersionPattern(int version); 113 | 114 | /****************************************************************************** 115 | * Format information 116 | *****************************************************************************/ 117 | 118 | /** 119 | * Return BCH encoded format information pattern. 120 | * @param mask 121 | * @param version 122 | * @param level 123 | * @return BCH encoded format information pattern 124 | */ 125 | extern unsigned int MQRspec_getFormatInfo(int mask, int version, QRecLevel level); 126 | 127 | /****************************************************************************** 128 | * Frame 129 | *****************************************************************************/ 130 | 131 | /** 132 | * Return a copy of initialized frame. 133 | * When the same version is requested twice or more, a copy of cached frame 134 | * is returned. 135 | * @param version 136 | * @return Array of unsigned char. You can free it by free(). 137 | */ 138 | extern unsigned char *MQRspec_newFrame(int version); 139 | 140 | /** 141 | * Clear the frame cache. Typically for debug. 142 | */ 143 | extern void MQRspec_clearCache(void); 144 | 145 | /****************************************************************************** 146 | * Mode indicator 147 | *****************************************************************************/ 148 | 149 | /** 150 | * Mode indicator. See Table 2 in Appendix 1 of JIS X0510:2004, pp.107. 151 | */ 152 | #define MQRSPEC_MODEID_NUM 0 153 | #define MQRSPEC_MODEID_AN 1 154 | #define MQRSPEC_MODEID_8 2 155 | #define MQRSPEC_MODEID_KANJI 3 156 | 157 | #endif /* __MQRSPEC_H__ */ 158 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/qrencode_inner.h: -------------------------------------------------------------------------------- 1 | /** 2 | * qrencode - QR Code encoder 3 | * 4 | * Header for test use 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRENCODE_INNER_H__ 23 | #define __QRENCODE_INNER_H__ 24 | 25 | /** 26 | * This header file includes definitions for test use. 27 | */ 28 | 29 | /****************************************************************************** 30 | * Raw code 31 | *****************************************************************************/ 32 | 33 | typedef struct { 34 | int dataLength; 35 | unsigned char *data; 36 | int eccLength; 37 | unsigned char *ecc; 38 | } RSblock; 39 | 40 | typedef struct { 41 | int version; 42 | int dataLength; 43 | int eccLength; 44 | unsigned char *datacode; 45 | unsigned char *ecccode; 46 | int b1; 47 | int blocks; 48 | RSblock *rsblock; 49 | int count; 50 | } QRRawCode; 51 | 52 | extern QRRawCode *QRraw_new(QRinput *input); 53 | extern unsigned char QRraw_getCode(QRRawCode *raw); 54 | extern void QRraw_free(QRRawCode *raw); 55 | 56 | /****************************************************************************** 57 | * Raw code for Micro QR Code 58 | *****************************************************************************/ 59 | 60 | typedef struct { 61 | int version; 62 | int dataLength; 63 | int eccLength; 64 | unsigned char *datacode; 65 | unsigned char *ecccode; 66 | RSblock *rsblock; 67 | int oddbits; 68 | int count; 69 | } MQRRawCode; 70 | 71 | extern MQRRawCode *MQRraw_new(QRinput *input); 72 | extern unsigned char MQRraw_getCode(MQRRawCode *raw); 73 | extern void MQRraw_free(MQRRawCode *raw); 74 | 75 | /****************************************************************************** 76 | * Frame filling 77 | *****************************************************************************/ 78 | extern unsigned char *FrameFiller_test(int version); 79 | extern unsigned char *FrameFiller_testMQR(int version); 80 | 81 | /****************************************************************************** 82 | * QR-code encoding 83 | *****************************************************************************/ 84 | extern QRcode *QRcode_encodeMask(QRinput *input, int mask); 85 | extern QRcode *QRcode_encodeMaskMQR(QRinput *input, int mask); 86 | extern QRcode *QRcode_new(int version, int width, unsigned char *data); 87 | 88 | #endif /* __QRENCODE_INNER_H__ */ 89 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/qrinput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Input data chunk class 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRINPUT_H__ 23 | #define __QRINPUT_H__ 24 | 25 | #include "qrencode.h" 26 | #include "bitstream.h" 27 | 28 | int QRinput_isSplittableMode(QRencodeMode mode); 29 | 30 | /****************************************************************************** 31 | * Entry of input data 32 | *****************************************************************************/ 33 | typedef struct _QRinput_List QRinput_List; 34 | 35 | struct _QRinput_List { 36 | QRencodeMode mode; 37 | int size; ///< Size of data chunk (byte). 38 | unsigned char *data; ///< Data chunk. 39 | BitStream *bstream; 40 | QRinput_List *next; 41 | }; 42 | 43 | /****************************************************************************** 44 | * Input Data 45 | *****************************************************************************/ 46 | struct _QRinput { 47 | int version; 48 | QRecLevel level; 49 | QRinput_List *head; 50 | QRinput_List *tail; 51 | int mqr; 52 | int fnc1; 53 | unsigned char appid; 54 | }; 55 | 56 | /****************************************************************************** 57 | * Structured append input data 58 | *****************************************************************************/ 59 | typedef struct _QRinput_InputList QRinput_InputList; 60 | 61 | struct _QRinput_InputList { 62 | QRinput *input; 63 | QRinput_InputList *next; 64 | }; 65 | 66 | struct _QRinput_Struct { 67 | int size; ///< number of structured symbols 68 | int parity; 69 | QRinput_InputList *head; 70 | QRinput_InputList *tail; 71 | }; 72 | 73 | /** 74 | * Pack all bit streams padding bits into a byte array. 75 | * @param input input data. 76 | * @return padded merged byte stream 77 | */ 78 | extern unsigned char *QRinput_getByteStream(QRinput *input); 79 | 80 | 81 | extern int QRinput_estimateBitsModeNum(int size); 82 | extern int QRinput_estimateBitsModeAn(int size); 83 | extern int QRinput_estimateBitsMode8(int size); 84 | extern int QRinput_estimateBitsModeKanji(int size); 85 | 86 | extern QRinput *QRinput_dup(QRinput *input); 87 | 88 | extern const signed char QRinput_anTable[128]; 89 | 90 | /** 91 | * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19). 92 | * @param __c__ character 93 | * @return value 94 | */ 95 | #define QRinput_lookAnTable(__c__) \ 96 | ((__c__ & 0x80)?-1:QRinput_anTable[(int)__c__]) 97 | 98 | /** 99 | * Length of a standard mode indicator in bits. 100 | */ 101 | 102 | #define MODE_INDICATOR_SIZE 4 103 | 104 | /** 105 | * Length of a segment of structured-append header. 106 | */ 107 | #define STRUCTURE_HEADER_SIZE 20 108 | 109 | /** 110 | * Maximum number of symbols in a set of structured-appended symbols. 111 | */ 112 | #define MAX_STRUCTURED_SYMBOLS 16 113 | 114 | #ifdef WITH_TESTS 115 | extern BitStream *QRinput_mergeBitStream(QRinput *input); 116 | extern BitStream *QRinput_getBitStream(QRinput *input); 117 | extern int QRinput_estimateBitStreamSize(QRinput *input, int version); 118 | extern int QRinput_splitEntry(QRinput_List *entry, int bytes); 119 | extern int QRinput_lengthOfCode(QRencodeMode mode, int version, int bits); 120 | extern int QRinput_insertStructuredAppendHeader(QRinput *input, int size, int index, unsigned char parity); 121 | #endif 122 | 123 | #endif /* __QRINPUT_H__ */ 124 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/qrspec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * QR Code specification in convenient format. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRSPEC_H__ 23 | #define __QRSPEC_H__ 24 | 25 | #include "qrencode.h" 26 | 27 | /****************************************************************************** 28 | * Version and capacity 29 | *****************************************************************************/ 30 | 31 | /** 32 | * Maximum width of a symbol 33 | */ 34 | #define QRSPEC_WIDTH_MAX 177 35 | 36 | /** 37 | * Return maximum data code length (bytes) for the version. 38 | * @param version 39 | * @param level 40 | * @return maximum size (bytes) 41 | */ 42 | extern int QRspec_getDataLength(int version, QRecLevel level); 43 | 44 | /** 45 | * Return maximum error correction code length (bytes) for the version. 46 | * @param version 47 | * @param level 48 | * @return ECC size (bytes) 49 | */ 50 | extern int QRspec_getECCLength(int version, QRecLevel level); 51 | 52 | /** 53 | * Return a version number that satisfies the input code length. 54 | * @param size input code length (byte) 55 | * @param level 56 | * @return version number 57 | */ 58 | extern int QRspec_getMinimumVersion(int size, QRecLevel level); 59 | 60 | /** 61 | * Return the width of the symbol for the version. 62 | * @param version 63 | * @return width 64 | */ 65 | extern int QRspec_getWidth(int version); 66 | 67 | /** 68 | * Return the numer of remainder bits. 69 | * @param version 70 | * @return number of remainder bits 71 | */ 72 | extern int QRspec_getRemainder(int version); 73 | 74 | /****************************************************************************** 75 | * Length indicator 76 | *****************************************************************************/ 77 | 78 | /** 79 | * Return the size of lenght indicator for the mode and version. 80 | * @param mode 81 | * @param version 82 | * @return the size of the appropriate length indicator (bits). 83 | */ 84 | extern int QRspec_lengthIndicator(QRencodeMode mode, int version); 85 | 86 | /** 87 | * Return the maximum length for the mode and version. 88 | * @param mode 89 | * @param version 90 | * @return the maximum length (bytes) 91 | */ 92 | extern int QRspec_maximumWords(QRencodeMode mode, int version); 93 | 94 | /****************************************************************************** 95 | * Error correction code 96 | *****************************************************************************/ 97 | 98 | /** 99 | * Return an array of ECC specification. 100 | * @param version 101 | * @param level 102 | * @param spec an array of ECC specification contains as following: 103 | * {# of type1 blocks, # of data code, # of ecc code, 104 | * # of type2 blocks, # of data code} 105 | */ 106 | void QRspec_getEccSpec(int version, QRecLevel level, int spec[5]); 107 | 108 | #define QRspec_rsBlockNum(__spec__) (__spec__[0] + __spec__[3]) 109 | #define QRspec_rsBlockNum1(__spec__) (__spec__[0]) 110 | #define QRspec_rsDataCodes1(__spec__) (__spec__[1]) 111 | #define QRspec_rsEccCodes1(__spec__) (__spec__[2]) 112 | #define QRspec_rsBlockNum2(__spec__) (__spec__[3]) 113 | #define QRspec_rsDataCodes2(__spec__) (__spec__[4]) 114 | #define QRspec_rsEccCodes2(__spec__) (__spec__[2]) 115 | 116 | #define QRspec_rsDataLength(__spec__) \ 117 | ((QRspec_rsBlockNum1(__spec__) * QRspec_rsDataCodes1(__spec__)) + \ 118 | (QRspec_rsBlockNum2(__spec__) * QRspec_rsDataCodes2(__spec__))) 119 | #define QRspec_rsEccLength(__spec__) \ 120 | (QRspec_rsBlockNum(__spec__) * QRspec_rsEccCodes1(__spec__)) 121 | 122 | /****************************************************************************** 123 | * Version information pattern 124 | *****************************************************************************/ 125 | 126 | /** 127 | * Return BCH encoded version information pattern that is used for the symbol 128 | * of version 7 or greater. Use lower 18 bits. 129 | * @param version 130 | * @return BCH encoded version information pattern 131 | */ 132 | extern unsigned int QRspec_getVersionPattern(int version); 133 | 134 | /****************************************************************************** 135 | * Format information 136 | *****************************************************************************/ 137 | 138 | /** 139 | * Return BCH encoded format information pattern. 140 | * @param mask 141 | * @param level 142 | * @return BCH encoded format information pattern 143 | */ 144 | extern unsigned int QRspec_getFormatInfo(int mask, QRecLevel level); 145 | 146 | /****************************************************************************** 147 | * Frame 148 | *****************************************************************************/ 149 | 150 | /** 151 | * Return a copy of initialized frame. 152 | * When the same version is requested twice or more, a copy of cached frame 153 | * is returned. 154 | * @param version 155 | * @return Array of unsigned char. You can free it by free(). 156 | */ 157 | extern unsigned char *QRspec_newFrame(int version); 158 | 159 | /** 160 | * Clear the frame cache. Typically for debug. 161 | */ 162 | extern void QRspec_clearCache(void); 163 | 164 | /****************************************************************************** 165 | * Mode indicator 166 | *****************************************************************************/ 167 | 168 | /** 169 | * Mode indicator. See Table 2 of JIS X0510:2004, pp.16. 170 | */ 171 | #define QRSPEC_MODEID_ECI 7 172 | #define QRSPEC_MODEID_NUM 1 173 | #define QRSPEC_MODEID_AN 2 174 | #define QRSPEC_MODEID_8 4 175 | #define QRSPEC_MODEID_KANJI 8 176 | #define QRSPEC_MODEID_FNC1FIRST 5 177 | #define QRSPEC_MODEID_FNC1SECOND 9 178 | #define QRSPEC_MODEID_STRUCTURE 3 179 | #define QRSPEC_MODEID_TERMINATOR 0 180 | 181 | #endif /* __QRSPEC_H__ */ 182 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/rscode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Reed solomon encoder. This code is taken from Phil Karn's libfec then 5 | * editted and packed into a pair of .c and .h files. 6 | * 7 | * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q 8 | * (libfec is released under the GNU Lesser General Public License.) 9 | * 10 | * Copyright (C) 2006-2011 Kentaro Fukuchi 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2.1 of the License, or any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef __RSCODE_H__ 28 | #define __RSCODE_H__ 29 | 30 | /* 31 | * General purpose RS codec, 8-bit symbols. 32 | */ 33 | 34 | typedef struct _RS RS; 35 | 36 | extern RS *init_rs(int symsize, int gfpoly, int fcr, int prim, int nroots, int pad); 37 | extern void encode_rs_char(RS *rs, const unsigned char *data, unsigned char *parity); 38 | extern void free_rs_char(RS *rs); 39 | extern void free_rs_cache(void); 40 | 41 | #endif /* __RSCODE_H__ */ 42 | -------------------------------------------------------------------------------- /include/qrencode/qrencode/3rd/split.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Input data splitter. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * The following data / specifications are taken from 8 | * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) 9 | * or 10 | * "Automatic identification and data capture techniques -- 11 | * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) 12 | * 13 | * This library is free software; you can redistribute it and/or 14 | * modify it under the terms of the GNU Lesser General Public 15 | * License as published by the Free Software Foundation; either 16 | * version 2.1 of the License, or any later version. 17 | * 18 | * This library is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | * Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public 24 | * License along with this library; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef __SPLIT_H__ 29 | #define __SPLIT_H__ 30 | 31 | #include "qrencode.h" 32 | 33 | /** 34 | * Split the input string (null terminated) into QRinput. 35 | * @param string input string 36 | * @param hint give QR_MODE_KANJI if the input string contains Kanji character encoded in Shift-JIS. If not, give QR_MODE_8. 37 | * @param casesensitive 0 for case-insensitive encoding (all alphabet characters are replaced to UPPER-CASE CHARACTERS. 38 | * @retval 0 success. 39 | * @retval -1 an error occurred. errno is set to indicate the error. See 40 | * Exceptions for the details. 41 | * @throw EINVAL invalid input object. 42 | * @throw ENOMEM unable to allocate memory for input objects. 43 | */ 44 | extern int Split_splitStringToQRinput(const char *string, QRinput *input, 45 | QRencodeMode hint, int casesensitive); 46 | 47 | #endif /* __SPLIT_H__ */ 48 | -------------------------------------------------------------------------------- /include/widgets_global.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGETS_GLOBAL_H 2 | #define WIDGETS_GLOBAL_H 3 | 4 | #include 5 | 6 | #if defined(WIDGETS_LIBRARY) 7 | # define WIDGETSSHARED_EXPORT Q_DECL_EXPORT 8 | #else 9 | # define WIDGETSSHARED_EXPORT Q_DECL_IMPORT 10 | #endif 11 | 12 | #endif // WIDGETS_GLOBAL_H 13 | -------------------------------------------------------------------------------- /qml1/dduiqrencode.cpp: -------------------------------------------------------------------------------- 1 | #include "dduiqrencode.h" 2 | 3 | #include 4 | 5 | #define DDuiQREncode_WEBSITE "www.heilqt.com" 6 | 7 | DDuiQREncode::DDuiQREncode(QDeclarativeItem *parent): 8 | QDeclarativeItem(parent) 9 | { 10 | setFlag(ItemHasNoContents, false); 11 | qrMargin =5; 12 | qrSize = QSize(128,128); 13 | qrForeground = QColor("#0E4963"); 14 | qrBackground = QColor("white"); 15 | qrCasesen = true; 16 | qrMode = MODE_8; 17 | qrLevel = LEVEL_Q; 18 | qrPercent = 0.23; 19 | qrLogo=DDuiQREncode_WEBSITE; 20 | qrData = DDuiQREncode_WEBSITE; 21 | qrFilePath = ""; 22 | setSize(qrSize); 23 | } 24 | 25 | 26 | DDuiQREncode::~DDuiQREncode() 27 | { 28 | } 29 | 30 | void DDuiQREncode::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 31 | { 32 | QRcode *qrcode = QRcode_encodeString(qrData.toUtf8() , 7, (QRecLevel)qrLevel, (QRencodeMode)qrMode, qrCasesen ? 1 : 0); 33 | QRect rect(0,0,qrSize.width(),qrSize.height()); 34 | if(0 != qrcode) { 35 | unsigned char *point = qrcode->data; 36 | painter->setPen(Qt::NoPen); 37 | painter->setBrush(this->qrBackground); 38 | painter->drawRect(rect); 39 | double scale = (rect.width () - 2.0 * qrMargin) / qrcode->width; 40 | painter->setBrush(this->qrForeground); 41 | for (int y = 0; y < qrcode->width; y ++) { 42 | for (int x = 0; x < qrcode->width; x ++) { 43 | if (*point & 1) { 44 | QRectF r(qrMargin + x * scale, qrMargin + y * scale, scale, scale); 45 | painter->drawRects(&r, 1); 46 | } 47 | point ++; 48 | } 49 | } 50 | point = NULL; 51 | QRcode_free(qrcode); 52 | //if qr_logo is empty return 53 | 54 | painter->setBrush(QColor("#00ffffff")); 55 | double icon_width = (rect.width () - 2.0 * qrMargin) * qrPercent; 56 | double icon_height = icon_width; 57 | double wrap_x = (rect.width () - icon_width) / 2.0; 58 | double wrap_y = (rect.width () - icon_height) / 2.0; 59 | QRectF wrap(wrap_x - 5, wrap_y - 5, icon_width + 10, icon_height + 10); 60 | painter->drawRoundRect(wrap, 50, 50); 61 | if(qrLogo.isEmpty() || qrLogo == DDuiQREncode_WEBSITE){ 62 | painter->save(); 63 | QPen pen; 64 | pen.setColor(Qt::red); 65 | painter->setFont(QFont("微软雅黑",14)); 66 | painter->setPen(pen); 67 | painter->drawText(wrap,DDuiQREncode_WEBSITE); 68 | painter->restore(); 69 | }else{ 70 | if(qrLogo.startsWith("qrc")){ 71 | qrLogo = qrLogo.replace("qrc",""); 72 | } 73 | QPixmap image(qrLogo); 74 | QRectF target(wrap_x, wrap_y, icon_width, icon_height); 75 | QRectF source(0, 0, image.width (), image.height ()); 76 | painter->drawPixmap (target, image, source); 77 | } 78 | } 79 | } 80 | 81 | 82 | QString DDuiQREncode::qrDDData() 83 | { 84 | if(qrData==""){ 85 | return DDuiQREncode_WEBSITE; 86 | }else{ 87 | return qrData; 88 | } 89 | } 90 | /// 91 | /// \brief DDuiQREncode::qrDDLogo 92 | /// \return set qrcode logo 93 | /// 94 | QString DDuiQREncode::qrDDLogo() 95 | { 96 | if(qrLogo==""){ 97 | return ""; 98 | }else{ 99 | return qrLogo.replace("qrc",""); 100 | } 101 | } 102 | 103 | QSize DDuiQREncode::qrDDSize() 104 | { 105 | return qrSize; 106 | } 107 | 108 | DDuiQREncode::QR_MODE DDuiQREncode::qrDDMode() 109 | { 110 | return qrMode; 111 | } 112 | 113 | DDuiQREncode::QR_LEVEL DDuiQREncode::qrDDLevel() 114 | { 115 | return qrLevel; 116 | } 117 | 118 | bool DDuiQREncode::qrDDCasesen() 119 | { 120 | return qrCasesen; 121 | } 122 | 123 | int DDuiQREncode::qrDDMargin() 124 | { 125 | return qrMargin; 126 | } 127 | 128 | qreal DDuiQREncode::qrDDPercent() 129 | { 130 | return qrPercent; 131 | } 132 | 133 | QColor DDuiQREncode::qrDDForeground() 134 | { 135 | return qrForeground; 136 | } 137 | 138 | QColor DDuiQREncode::qrDDBackground() 139 | { 140 | return qrBackground; 141 | } 142 | 143 | void DDuiQREncode::setQrData(const QString &data) 144 | { 145 | if(qrData !=data){ 146 | qrData = data; 147 | emit qrDataChanged(qrData); 148 | } 149 | } 150 | 151 | void DDuiQREncode::setQrLogo(const QString &logo) 152 | { 153 | if(qrLogo != logo){ 154 | qrLogo = logo; 155 | emit qrLogoChanged(qrLogo); 156 | } 157 | } 158 | 159 | void DDuiQREncode::setQrSize(QSize size) 160 | { 161 | if(qrSize != size){ 162 | qrSize = size; 163 | emit qrSizeChanged(qrSize); 164 | update(); 165 | } 166 | } 167 | 168 | void DDuiQREncode::setQrMode(DDuiQREncode::QR_MODE mode) 169 | { 170 | if(qrMode != mode){ 171 | qrMode = mode; 172 | emit qrModeChanged(qrMode); 173 | } 174 | } 175 | 176 | void DDuiQREncode::setQrLevel(DDuiQREncode::QR_LEVEL level) 177 | { 178 | if(qrLevel != level){ 179 | qrLevel = level; 180 | emit qrLevelChanged(qrLevel); 181 | } 182 | } 183 | 184 | void DDuiQREncode::setQrCasesen(bool casesen) 185 | { 186 | if(qrCasesen != casesen){ 187 | qrCasesen = casesen; 188 | emit qrCasesenChanged(qrCasesen); 189 | } 190 | } 191 | 192 | void DDuiQREncode::setQrMargin(int margin) 193 | { 194 | if(qrMargin != margin){ 195 | qrMargin = margin; 196 | emit qrMarginChanged(qrMargin); 197 | } 198 | } 199 | 200 | void DDuiQREncode::setQrPercent(qreal percent) 201 | { 202 | if(qrPercent != percent){ 203 | qrPercent = percent; 204 | emit qrPercentChanged(qrPercent); 205 | } 206 | } 207 | 208 | void DDuiQREncode::setQrForeground(QColor forgb) 209 | { 210 | if(qrForeground != forgb){ 211 | qrForeground = forgb; 212 | emit qrForegroundChanged(qrForeground); 213 | } 214 | } 215 | 216 | void DDuiQREncode::setQrBackground(QColor backgb) 217 | { 218 | if(qrBackground != backgb){ 219 | qrBackground = backgb; 220 | emit qrBackgroundChanged(qrBackground); 221 | } 222 | } 223 | 224 | void DDuiQREncode::setQrSaveFile(const QString &filepath) 225 | { 226 | qrFilePath = filepath; 227 | if(!qrFilePath.isEmpty()){ 228 | saveItemToFile(); 229 | } 230 | } 231 | 232 | void DDuiQREncode::saveCurViewToFile() 233 | { 234 | //创建文件 235 | QString str = qrFilePath; 236 | if(!str.endsWith(".png")){ 237 | str.append(".png"); 238 | } 239 | QFile file(str); 240 | if (!file.open(QIODevice::WriteOnly)){ 241 | file.close(); 242 | return; 243 | } 244 | //流方式写入文件 245 | // QGraphicsWidget *window = this->window(); 246 | // if(window){ 247 | // QImage img = window->parentItem()-; 248 | // QByteArray ba; 249 | // QBuffer buffer(&ba); 250 | // buffer.open(QIODevice::WriteOnly); 251 | // img.save(&buffer, "png"); 252 | // file.write(ba); 253 | // } 254 | } 255 | 256 | void DDuiQREncode::saveItemToFile() 257 | { 258 | // if(m_grab == NULL){ 259 | // m_grab = new QuickItemGrabber(this); 260 | // connect(m_grab,SIGNAL(grabbed()),this,SLOT(grabChanged())); 261 | // } 262 | // m_grab->clear(); 263 | // m_grab->grab(this,QSize(this->width(),this->height())); 264 | } 265 | 266 | void DDuiQREncode::grabChanged() 267 | { 268 | // if(m_grab->save(qrFilePath)){ 269 | // emit qrSaveFileChanged(QCoreApplication::applicationDirPath()+"/"+qrFilePath); 270 | // } 271 | } 272 | 273 | -------------------------------------------------------------------------------- /qml1/dduiqrencode.h: -------------------------------------------------------------------------------- 1 | #ifndef DDUIQRENCODE_H 2 | #define DDUIQRENCODE_H 3 | 4 | #include 5 | #include 6 | #include "qrencode/3rd/qrencode.h" 7 | #include 8 | #include 9 | 10 | class DDuiQREncode : public QDeclarativeItem 11 | { 12 | Q_OBJECT 13 | Q_DISABLE_COPY(DDuiQREncode) 14 | Q_ENUMS(QR_MODE) 15 | Q_ENUMS(QR_LEVEL) 16 | 17 | Q_PROPERTY(QString qrData READ qrDDData WRITE setQrData NOTIFY qrDataChanged) 18 | Q_PROPERTY(QString qrLogo READ qrDDLogo WRITE setQrLogo NOTIFY qrLogoChanged) 19 | Q_PROPERTY(QSize qrSize READ qrDDSize WRITE setQrSize NOTIFY qrSizeChanged) 20 | Q_PROPERTY(QR_MODE qrMode READ qrDDMode WRITE setQrMode NOTIFY qrModeChanged) 21 | Q_PROPERTY(QR_LEVEL qrLevel READ qrDDLevel WRITE setQrLevel NOTIFY qrLevelChanged) 22 | Q_PROPERTY(bool qrCasesen READ qrDDCasesen WRITE setQrCasesen NOTIFY qrCasesenChanged) 23 | Q_PROPERTY(int qrMargin READ qrDDMargin WRITE setQrMargin NOTIFY qrMarginChanged) 24 | Q_PROPERTY(qreal qrPercent READ qrDDPercent WRITE setQrPercent NOTIFY qrPercentChanged) 25 | Q_PROPERTY(QColor qrForeground READ qrDDForeground WRITE setQrForeground NOTIFY qrForegroundChanged) 26 | Q_PROPERTY(QColor qrBackground READ qrDDBackground WRITE setQrBackground NOTIFY qrBackgroundChanged) 27 | public: 28 | DDuiQREncode(QDeclarativeItem *parent = 0); 29 | ~DDuiQREncode(); 30 | 31 | enum QR_MODE { 32 | MODE_NUL = QR_MODE_NUL, 33 | MODE_NUM = QR_MODE_NUM, 34 | MODE_AN = QR_MODE_AN, 35 | MODE_8 = QR_MODE_8, 36 | MODE_KANJI = QR_MODE_KANJI, 37 | MODE_STRUCTURE = QR_MODE_STRUCTURE, 38 | MODE_ECI = QR_MODE_ECI, 39 | MODE_FNC1FIRST = QR_MODE_FNC1FIRST, 40 | MODE_FNC1SECOND = QR_MODE_FNC1SECOND 41 | }; 42 | enum QR_LEVEL { 43 | LEVEL_L = QR_ECLEVEL_L, 44 | LEVEL_M = QR_ECLEVEL_M, 45 | LEVEL_Q = QR_ECLEVEL_Q, 46 | LEVEL_H = QR_ECLEVEL_H 47 | }; 48 | 49 | QString qrDDData(); 50 | QString qrDDLogo(); 51 | QSize qrDDSize(); 52 | QR_MODE qrDDMode(); 53 | QR_LEVEL qrDDLevel(); 54 | bool qrDDCasesen(); 55 | int qrDDMargin(); 56 | qreal qrDDPercent(); 57 | QColor qrDDForeground(); 58 | QColor qrDDBackground(); 59 | 60 | Q_INVOKABLE void setQrData(const QString& data); 61 | Q_INVOKABLE void setQrLogo(const QString& logo); 62 | Q_INVOKABLE void setQrSize(QSize mode); 63 | Q_INVOKABLE void setQrMode(QR_MODE mode); 64 | Q_INVOKABLE void setQrLevel(QR_LEVEL level); 65 | Q_INVOKABLE void setQrCasesen(bool casesen); 66 | Q_INVOKABLE void setQrMargin(int margin); 67 | Q_INVOKABLE void setQrPercent(qreal percent); 68 | Q_INVOKABLE void setQrForeground(QColor forgb); 69 | Q_INVOKABLE void setQrBackground(QColor backgb); 70 | Q_INVOKABLE void setQrSaveFile(const QString& filepath); 71 | 72 | signals: 73 | void qrDataChanged(const QString& qrdata); 74 | void qrLogoChanged(const QString& qrlogo); 75 | void qrSizeChanged(const QSize& qrsize); 76 | void qrModeChanged(QR_MODE qrmodel); 77 | void qrLevelChanged(QR_LEVEL qrlevel); 78 | void qrCasesenChanged(bool qrcasesen); 79 | void qrMarginChanged(int qrmargin); 80 | void qrPercentChanged(qreal qrpercent); 81 | void qrForegroundChanged(const QColor& qrfg); 82 | void qrBackgroundChanged(const QColor& qrbg); 83 | void qrSaveFileChanged(const QString& qrfilepath); 84 | 85 | private: 86 | QString qrData; 87 | QString qrLogo; 88 | QSize qrSize; 89 | QR_MODE qrMode; 90 | QR_LEVEL qrLevel; 91 | bool qrCasesen; 92 | int qrMargin; 93 | qreal qrPercent; 94 | QColor qrForeground; 95 | QColor qrBackground; 96 | QString qrFilePath; 97 | 98 | // QuickItemGrabber* m_grab; 99 | QString icon; 100 | QByteArray text; 101 | void saveCurViewToFile(); 102 | void saveItemToFile(); 103 | private slots: 104 | void grabChanged(); 105 | protected: 106 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); 107 | }; 108 | 109 | QML_DECLARE_TYPE(DDuiQREncode) 110 | 111 | #endif // DDUIQRENCODE_H 112 | -------------------------------------------------------------------------------- /qml1/dduiqrencode_plugin.cpp: -------------------------------------------------------------------------------- 1 | #include "dduiqrencode_plugin.h" 2 | #include "dduiqrencode.h" 3 | 4 | #include 5 | 6 | void DDuiQREncodePlugin::registerTypes(const char *uri) 7 | { 8 | // @uri com.ddui.qmlcomponents 9 | qmlRegisterType(uri, 1, 0, "QtQuick1QREncode"); 10 | } 11 | 12 | #if QT_VERSION < 0x050000 13 | Q_EXPORT_PLUGIN2(DDuiQREncode, DDuiQREncodePlugin) 14 | #endif 15 | -------------------------------------------------------------------------------- /qml1/dduiqrencode_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef DDUIQRENCODE_PLUGIN_H 2 | #define DDUIQRENCODE_PLUGIN_H 3 | 4 | #include 5 | 6 | class DDuiQREncodePlugin : public QDeclarativeExtensionPlugin 7 | { 8 | Q_OBJECT 9 | #if QT_VERSION >= 0x050000 10 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") 11 | #endif 12 | 13 | public: 14 | void registerTypes(const char *uri); 15 | }; 16 | 17 | #endif // DDUIQRENCODE_PLUGIN_H 18 | -------------------------------------------------------------------------------- /qml1/qml1.pro: -------------------------------------------------------------------------------- 1 | 2 | QT += declarative 3 | 4 | TEMPLATE = lib 5 | TARGET = QtQuick1QREncode 6 | 7 | CONFIG += qt plugin 8 | 9 | uri = com.ddui.qmlcomponents 10 | 11 | 12 | DESTDIR = $$PWD/../plugins/ 13 | MOC_DIR = $$PWD/../.moc 14 | OBJECTS_DIR = $$PWD/../.obj 15 | 16 | # Input 17 | INCLUDEPATH += $$PWD 18 | SOURCES += \ 19 | $$PWD/dduiqrencode_plugin.cpp \ 20 | $$PWD/dduiqrencode.cpp 21 | 22 | HEADERS += \ 23 | $$PWD/dduiqrencode_plugin.h \ 24 | $$PWD/dduiqrencode.h 25 | 26 | CONFIG += DD_USE_C 27 | 28 | DD_USE_C:{ 29 | include($$PWD/../qrencode/qrencode.pri) 30 | } 31 | DISTFILES = qmldir 32 | 33 | !equals(_PRO_FILE_PWD_, $$OUT_PWD) { 34 | copy_qmldir.target = $$OUT_PWD/qmldir 35 | copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir 36 | copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" 37 | QMAKE_EXTRA_TARGETS += copy_qmldir 38 | PRE_TARGETDEPS += $$copy_qmldir.target 39 | } 40 | 41 | qmldir.files = qmldir 42 | maemo5 | !isEmpty(MEEGO_VERSION_MAJOR) { 43 | installPath = /usr/lib/qt4/imports/$$replace(uri, \\., /) 44 | } else { 45 | installPath = $$[QT_INSTALL_IMPORTS]/$$replace(uri, \\., /) 46 | } 47 | qmldir.path = $$installPath 48 | target.path = $$installPath 49 | #install this plugin to qt sdk plugin path 50 | INSTALLS += target qmldir 51 | -------------------------------------------------------------------------------- /qml1/qmldir: -------------------------------------------------------------------------------- 1 | plugin QtQuick1QREncode 2 | -------------------------------------------------------------------------------- /qml2/qml2.pro: -------------------------------------------------------------------------------- 1 | 2 | QT += qml quick 3 | TEMPLATE = lib 4 | TARGET = QtQuick2QREncode 5 | 6 | CONFIG += qt plugin 7 | #TARGET = $$qtLibraryTarget($$TARGET) 8 | uri = com.duoduo.components 9 | CONFIG += DD_USE_C 10 | 11 | DESTDIR = $$PWD/../plugins/ 12 | MOC_DIR = $$PWD/../.moc 13 | OBJECTS_DIR = $$PWD/../.obj 14 | 15 | # Input 16 | INCLUDEPATH +=$$PWD 17 | SOURCES += \ 18 | $$PWD/qtquickqrencode_plugin.cpp \ 19 | $$PWD/qrddencode.cpp 20 | 21 | HEADERS += \ 22 | $$PWD/qtquickqrencode_plugin.h \ 23 | $$PWD/qrddencode.h 24 | 25 | greaterThan(QT_MAJOR_VERSION, 4){ 26 | SOURCES +=$$PWD/quickitemgrabber.cpp 27 | HEADERS +=$$PWD/quickitemgrabber.h 28 | } 29 | DD_USE_C:{ 30 | include($$PWD/../qrencode/qrencode.pri) 31 | } 32 | 33 | DISTFILES = qmldir 34 | 35 | !equals(_PRO_FILE_PWD_, $$OUT_PWD) { 36 | copy_qmldir.target = $$OUT_PWD/qmldir 37 | copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir 38 | copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" 39 | QMAKE_EXTRA_TARGETS += copy_qmldir 40 | PRE_TARGETDEPS += $$copy_qmldir.target 41 | } 42 | 43 | qmldir.files = qmldir 44 | installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) 45 | qmldir.path = $$installPath 46 | target.path = $$installPath 47 | INSTALLS += target qmldir 48 | 49 | -------------------------------------------------------------------------------- /qml2/qmldir: -------------------------------------------------------------------------------- 1 | module com.duoduo.components 2 | plugin QtQuick2QREncode 3 | 4 | -------------------------------------------------------------------------------- /qml2/qrddencode.cpp: -------------------------------------------------------------------------------- 1 | #include "qrddencode.h" 2 | #define QRENCODE_WEBSITE "www.heilqt.com" 3 | 4 | QREnCode::QREnCode(QQuickItem *parent): 5 | QQuickPaintedItem(parent) 6 | { 7 | #if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0)) 8 | #else 9 | m_grab = NULL; 10 | #endif 11 | qrMargin =5; 12 | qrSize = QSize(128,128); 13 | qrForeground = QColor("#0E4963"); 14 | qrBackground = QColor("white"); 15 | qrCasesen = true; 16 | qrMode = MODE_8; 17 | qrLevel = LEVEL_Q; 18 | qrPercent = 0.23; 19 | qrLogo=QRENCODE_WEBSITE; 20 | qrData = QRENCODE_WEBSITE; 21 | qrFilePath = ""; 22 | setSize(qrSize); 23 | } 24 | 25 | void QREnCode::paint(QPainter *painter) 26 | { 27 | QRcode *qrcode = QRcode_encodeString(qrData.toUtf8() , 7, (QRecLevel)qrLevel, (QRencodeMode)qrMode, qrCasesen ? 1 : 0); 28 | QRect rect(0,0,qrSize.width(),qrSize.height()); 29 | if(0 != qrcode) { 30 | unsigned char *point = qrcode->data; 31 | painter->setPen(Qt::NoPen); 32 | painter->setBrush(this->qrBackground); 33 | painter->drawRect(rect); 34 | int w = qMin(rect.width(),rect.height()); 35 | double scale = (w - 2.0 * qrMargin) / qrcode->width; 36 | painter->setBrush(this->qrForeground); 37 | for (int y = 0; y < qrcode->width; y ++) { 38 | for (int x = 0; x < qrcode->width; x ++) { 39 | if (*point & 1) { 40 | QRectF r(qrMargin + x * scale, qrMargin + y * scale, scale, scale); 41 | painter->drawRects(&r, 1); 42 | } 43 | point ++; 44 | } 45 | } 46 | point = NULL; 47 | QRcode_free(qrcode); 48 | //if qr_logo is empty return 49 | 50 | painter->setBrush(QColor("#00ffffff")); 51 | double icon_width = (w- 2.0 * qrMargin) * qrPercent; 52 | double icon_height = icon_width; 53 | double wrap_x = (w - icon_width) / 2.0; 54 | double wrap_y = (w- icon_height) / 2.0; 55 | QRectF wrap(wrap_x - 5, wrap_y - 5, icon_width + 10, icon_height + 10); 56 | painter->drawRoundRect(wrap, 50, 50); 57 | if(qrLogo.isEmpty() || qrLogo == QRENCODE_WEBSITE){ 58 | painter->drawText(wrap,QRENCODE_WEBSITE); 59 | }else{ 60 | QPixmap image(qrLogo); 61 | QRectF target(wrap_x, wrap_y, icon_width, icon_height); 62 | QRectF source(0, 0, image.width (), image.height ()); 63 | painter->drawPixmap (target, image, source); 64 | } 65 | } 66 | } 67 | 68 | QREnCode::~QREnCode() 69 | { 70 | } 71 | QString QREnCode::qrDDData() 72 | { 73 | if(qrData==""){ 74 | return QRENCODE_WEBSITE; 75 | }else{ 76 | return qrData; 77 | } 78 | } 79 | /// 80 | /// \brief QREnCode::qrDDLogo 81 | /// \return set qrcode logo 82 | /// 83 | QString QREnCode::qrDDLogo() 84 | { 85 | if(qrLogo==""){ 86 | return ""; 87 | }else{ 88 | return qrLogo.replace("qrc",""); 89 | } 90 | } 91 | 92 | QSize QREnCode::qrDDSize() 93 | { 94 | return qrSize; 95 | } 96 | 97 | QREnCode::QR_MODE QREnCode::qrDDMode() 98 | { 99 | return qrMode; 100 | } 101 | 102 | QREnCode::QR_LEVEL QREnCode::qrDDLevel() 103 | { 104 | return qrLevel; 105 | } 106 | 107 | bool QREnCode::qrDDCasesen() 108 | { 109 | return qrCasesen; 110 | } 111 | 112 | int QREnCode::qrDDMargin() 113 | { 114 | return qrMargin; 115 | } 116 | 117 | qreal QREnCode::qrDDPercent() 118 | { 119 | return qrPercent; 120 | } 121 | 122 | QColor QREnCode::qrDDForeground() 123 | { 124 | return qrForeground; 125 | } 126 | 127 | QColor QREnCode::qrDDBackground() 128 | { 129 | return qrBackground; 130 | } 131 | 132 | void QREnCode::setQrData(const QString &data) 133 | { 134 | if(qrData !=data){ 135 | qrData = data; 136 | emit qrDataChanged(qrData); 137 | } 138 | } 139 | 140 | void QREnCode::setQrLogo(const QString &logo) 141 | { 142 | if(qrLogo != logo){ 143 | qrLogo = logo; 144 | if(qrLogo.startsWith("qrc:")){ 145 | qrLogo = qrLogo.replace("qrc",""); 146 | }else if(qrLogo.startsWith("file://")){ 147 | qrLogo = qrLogo.replace("file://",""); 148 | } 149 | emit qrLogoChanged(qrLogo); 150 | } 151 | } 152 | 153 | void QREnCode::setQrSize(QSize size) 154 | { 155 | if(qrSize != size){ 156 | qrSize = size; 157 | emit qrSizeChanged(qrSize); 158 | update(); 159 | } 160 | } 161 | 162 | void QREnCode::setQrMode(QREnCode::QR_MODE mode) 163 | { 164 | if(qrMode != mode){ 165 | qrMode = mode; 166 | emit qrModeChanged(qrMode); 167 | } 168 | } 169 | 170 | void QREnCode::setQrLevel(QREnCode::QR_LEVEL level) 171 | { 172 | if(qrLevel != level){ 173 | qrLevel = level; 174 | emit qrLevelChanged(qrLevel); 175 | } 176 | } 177 | 178 | void QREnCode::setQrCasesen(bool casesen) 179 | { 180 | if(qrCasesen != casesen){ 181 | qrCasesen = casesen; 182 | emit qrCasesenChanged(qrCasesen); 183 | } 184 | } 185 | 186 | void QREnCode::setQrMargin(int margin) 187 | { 188 | if(qrMargin != margin){ 189 | qrMargin = margin; 190 | emit qrMarginChanged(qrMargin); 191 | } 192 | } 193 | 194 | void QREnCode::setQrPercent(qreal percent) 195 | { 196 | if(qrPercent != percent){ 197 | qrPercent = percent; 198 | emit qrPercentChanged(qrPercent); 199 | } 200 | } 201 | 202 | void QREnCode::setQrForeground(QColor forgb) 203 | { 204 | if(qrForeground != forgb){ 205 | qrForeground = forgb; 206 | emit qrForegroundChanged(qrForeground); 207 | } 208 | } 209 | 210 | void QREnCode::setQrBackground(QColor backgb) 211 | { 212 | if(qrBackground != backgb){ 213 | qrBackground = backgb; 214 | emit qrBackgroundChanged(qrBackground); 215 | } 216 | } 217 | 218 | void QREnCode::setQrSaveFile(const QString &filepath) 219 | { 220 | qrFilePath = filepath; 221 | if(!qrFilePath.isEmpty()){ 222 | saveItemToFile(); 223 | } 224 | } 225 | 226 | void QREnCode::saveCurViewToFile() 227 | { 228 | //创建文件 229 | QString str = qrFilePath; 230 | if(!str.endsWith(".png")){ 231 | str.append(".png"); 232 | } 233 | QFile file(str); 234 | if (!file.open(QIODevice::WriteOnly)){ 235 | file.close(); 236 | return; 237 | } 238 | //流方式写入文件 239 | QQuickWindow *window = this->window(); 240 | if(window){ 241 | QImage img = window->grabWindow(); 242 | QByteArray ba; 243 | QBuffer buffer(&ba); 244 | buffer.open(QIODevice::WriteOnly); 245 | img.save(&buffer, "png"); 246 | file.write(ba); 247 | } 248 | } 249 | 250 | /// 251 | /// \brief QREnCode::saveItemToFile 252 | /// 屏蔽5.4.0版本以下的 253 | /// 254 | void QREnCode::saveItemToFile() 255 | { 256 | #if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0)) 257 | emit errorMessage("Don't Support this function,Please Use Qt Version greate than 5.4.0"); 258 | #else 259 | // QuickItemGrabber* m_grab{nullptr}; 260 | if(m_grab == NULL){ 261 | m_grab = new QuickItemGrabber(this); 262 | connect(m_grab,SIGNAL(grabbed()),this,SLOT(grabChanged())); 263 | } 264 | m_grab->clear(); 265 | m_grab->grab(this,QSize(this->width(),this->height())); 266 | #endif 267 | } 268 | 269 | void QREnCode::grabChanged() 270 | { 271 | #if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0)) 272 | emit errorMessage("Don't Support this function,Please Use Qt Version greate than 5.4.0"); 273 | #else 274 | if(m_grab->save(qrFilePath)){ 275 | emit qrSaveFileChanged(QCoreApplication::applicationDirPath()+"/"+qrFilePath); 276 | } 277 | #endif 278 | } 279 | 280 | -------------------------------------------------------------------------------- /qml2/qrddencode.h: -------------------------------------------------------------------------------- 1 | #ifndef QRENCODE_H 2 | #define QRENCODE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "qrencode/3rd/qrencode.h" 14 | #include 15 | #include 16 | #include 17 | #include 18 | //#include 19 | #include "quickitemgrabber.h" 20 | 21 | class QREnCode : public QQuickPaintedItem 22 | { 23 | Q_OBJECT 24 | // Q_DISABLE_COPY(QREnCode) 25 | Q_ENUMS(QR_MODE) 26 | Q_ENUMS(QR_LEVEL) 27 | 28 | Q_PROPERTY(QString qrData READ qrDDData WRITE setQrData NOTIFY qrDataChanged) 29 | Q_PROPERTY(QString qrLogo READ qrDDLogo WRITE setQrLogo NOTIFY qrLogoChanged) 30 | Q_PROPERTY(QSize qrSize READ qrDDSize WRITE setQrSize NOTIFY qrSizeChanged) 31 | Q_PROPERTY(QR_MODE qrMode READ qrDDMode WRITE setQrMode NOTIFY qrModeChanged) 32 | Q_PROPERTY(QR_LEVEL qrLevel READ qrDDLevel WRITE setQrLevel NOTIFY qrLevelChanged) 33 | Q_PROPERTY(bool qrCasesen READ qrDDCasesen WRITE setQrCasesen NOTIFY qrCasesenChanged) 34 | Q_PROPERTY(int qrMargin READ qrDDMargin WRITE setQrMargin NOTIFY qrMarginChanged) 35 | Q_PROPERTY(qreal qrPercent READ qrDDPercent WRITE setQrPercent NOTIFY qrPercentChanged) 36 | Q_PROPERTY(QColor qrForeground READ qrDDForeground WRITE setQrForeground NOTIFY qrForegroundChanged) 37 | Q_PROPERTY(QColor qrBackground READ qrDDBackground WRITE setQrBackground NOTIFY qrBackgroundChanged) 38 | 39 | public: 40 | enum QR_MODE { 41 | MODE_NUL = QR_MODE_NUL, 42 | MODE_NUM = QR_MODE_NUM, 43 | MODE_AN = QR_MODE_AN, 44 | MODE_8 = QR_MODE_8, 45 | MODE_KANJI = QR_MODE_KANJI, 46 | MODE_STRUCTURE = QR_MODE_STRUCTURE, 47 | MODE_ECI = QR_MODE_ECI, 48 | MODE_FNC1FIRST = QR_MODE_FNC1FIRST, 49 | MODE_FNC1SECOND = QR_MODE_FNC1SECOND 50 | }; 51 | enum QR_LEVEL { 52 | LEVEL_L = QR_ECLEVEL_L, 53 | LEVEL_M = QR_ECLEVEL_M, 54 | LEVEL_Q = QR_ECLEVEL_Q, 55 | LEVEL_H = QR_ECLEVEL_H 56 | }; 57 | 58 | QREnCode(QQuickItem *parent = 0); 59 | void paint(QPainter* painter); 60 | ~QREnCode(); 61 | 62 | QString qrDDData(); 63 | QString qrDDLogo(); 64 | QSize qrDDSize(); 65 | QR_MODE qrDDMode(); 66 | QR_LEVEL qrDDLevel(); 67 | bool qrDDCasesen(); 68 | int qrDDMargin(); 69 | qreal qrDDPercent(); 70 | QColor qrDDForeground(); 71 | QColor qrDDBackground(); 72 | 73 | Q_INVOKABLE void setQrData(const QString& data); 74 | Q_INVOKABLE void setQrLogo(const QString& logo); 75 | Q_INVOKABLE void setQrSize(QSize mode); 76 | Q_INVOKABLE void setQrMode(QR_MODE mode); 77 | Q_INVOKABLE void setQrLevel(QR_LEVEL level); 78 | Q_INVOKABLE void setQrCasesen(bool casesen); 79 | Q_INVOKABLE void setQrMargin(int margin); 80 | Q_INVOKABLE void setQrPercent(qreal percent); 81 | Q_INVOKABLE void setQrForeground(QColor forgb); 82 | Q_INVOKABLE void setQrBackground(QColor backgb); 83 | Q_INVOKABLE void setQrSaveFile(const QString& filepath); 84 | 85 | signals: 86 | void qrDataChanged(const QString& qrdata); 87 | void qrLogoChanged(const QString& qrlogo); 88 | void qrSizeChanged(const QSize& qrsize); 89 | void qrModeChanged(QR_MODE qrmodel); 90 | void qrLevelChanged(QR_LEVEL qrlevel); 91 | void qrCasesenChanged(bool qrcasesen); 92 | void qrMarginChanged(int qrmargin); 93 | void qrPercentChanged(qreal qrpercent); 94 | void qrForegroundChanged(const QColor& qrfg); 95 | void qrBackgroundChanged(const QColor& qrbg); 96 | void qrSaveFileChanged(const QString& qrfilepath); 97 | 98 | void errorMessage(const QString& msg); 99 | private: 100 | QString qrData; 101 | QString qrLogo; 102 | QSize qrSize; 103 | QR_MODE qrMode; 104 | QR_LEVEL qrLevel; 105 | bool qrCasesen; 106 | int qrMargin; 107 | qreal qrPercent; 108 | QColor qrForeground; 109 | QColor qrBackground; 110 | QString qrFilePath; 111 | #if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0)) 112 | #else 113 | QuickItemGrabber* m_grab; 114 | #endif 115 | QString icon; 116 | QByteArray text; 117 | void saveCurViewToFile(); 118 | void saveItemToFile(); 119 | private slots: 120 | void grabChanged(); 121 | }; 122 | 123 | #endif // QRENCODE_H 124 | 125 | -------------------------------------------------------------------------------- /qml2/qtquickqrencode_plugin.cpp: -------------------------------------------------------------------------------- 1 | #include "qtquickqrencode_plugin.h" 2 | #include "qrddencode.h" 3 | 4 | #include 5 | 6 | void QtQuickQREncodePlugin::registerTypes(const char *uri) 7 | { 8 | // @uri com.duoduo.components 9 | qmlRegisterType(uri, 1, 0, "QtQuick2QREncode"); 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /qml2/qtquickqrencode_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef QTQUICKQRENCODE_PLUGIN_H 2 | #define QTQUICKQRENCODE_PLUGIN_H 3 | 4 | #include 5 | 6 | class QtQuickQREncodePlugin : public QQmlExtensionPlugin 7 | { 8 | Q_OBJECT 9 | Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") 10 | 11 | public: 12 | void registerTypes(const char *uri); 13 | }; 14 | 15 | #endif // QTQUICKQRENCODE_PLUGIN_H 16 | 17 | -------------------------------------------------------------------------------- /qml2/quickitemgrabber.cpp: -------------------------------------------------------------------------------- 1 | /** Author: Ben Lau (https://github.com/benlau) 2 | */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "quickitemgrabber.h" 8 | 9 | #if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0)) 10 | #include 11 | #include 12 | #include 13 | #include 14 | #else 15 | // Added since Qt 5.4 16 | #include 17 | #endif 18 | 19 | 20 | QuickItemGrabber::QuickItemGrabber(QObject *parent) : 21 | QObject(parent) 22 | { 23 | m_busy = false; 24 | m_ready = false; 25 | } 26 | 27 | bool QuickItemGrabber::busy() const 28 | { 29 | return m_busy; 30 | } 31 | 32 | bool QuickItemGrabber::grab(QQuickItem *target,QSize targetSize) 33 | { 34 | if (m_busy || 35 | target == 0 || 36 | !target->window() || 37 | !target->window()->isVisible() ) { 38 | return false; 39 | } 40 | m_ready = false; 41 | m_targetSize = targetSize; 42 | m_target = target; 43 | m_window = target->window(); 44 | 45 | if (m_targetSize.isEmpty()) { 46 | m_targetSize = QSize(m_target->width(),m_target->height()); 47 | } 48 | 49 | #if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0)) 50 | 51 | QQuickItemPrivate::get(m_target)->refFromEffectItem(false); 52 | 53 | m_target->window()->update(); 54 | 55 | connect(m_window.data(),SIGNAL(beforeSynchronizing()), 56 | this,SLOT(ready()),Qt::DirectConnection); 57 | 58 | connect(m_window.data(),SIGNAL(afterRendering()), 59 | this,SLOT(capture()),Qt::DirectConnection); 60 | #else 61 | 62 | result = target->grabToImage(m_targetSize); 63 | 64 | if (result.isNull()) { 65 | qDebug() << "Can't grab target item"; 66 | return false; 67 | } 68 | connect(result.data(),SIGNAL(ready()), 69 | this,SLOT(onGrabResultReady())); 70 | #endif 71 | 72 | setBusy(true); 73 | 74 | return true; 75 | } 76 | 77 | bool QuickItemGrabber::save(QString filename) 78 | { 79 | if (m_image.isNull()) { 80 | qWarning() << "QuickItemGrabber::save() - The image is null"; 81 | return false; 82 | } 83 | return m_image.save(filename); 84 | } 85 | 86 | void QuickItemGrabber::ready() 87 | { 88 | m_ready = true; 89 | } 90 | 91 | #if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)) 92 | void QuickItemGrabber::onGrabResultReady() 93 | { 94 | QImage image = result->image(); 95 | setImage(image); 96 | 97 | result.clear(); 98 | setBusy(false); 99 | emit grabbed(); 100 | } 101 | #endif 102 | 103 | QImage QuickItemGrabber::image() const 104 | { 105 | return m_image; 106 | } 107 | 108 | #if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0)) 109 | 110 | void QuickItemGrabber::capture() 111 | { 112 | if (!m_ready) { // It is not ready yet 113 | return; 114 | } 115 | 116 | if (m_target) { // Just in case the item is destroyed before rendering completed 117 | QOpenGLContext* context = QOpenGLContext::currentContext(); 118 | 119 | QQuickShaderEffectTexture *m_texture = new QQuickShaderEffectTexture(m_target); 120 | m_texture->setItem(QQuickItemPrivate::get(m_target)->itemNode()); 121 | 122 | // Set the source rectangle 123 | QSize sourceSize; 124 | sourceSize = QSize(m_target->width(),m_target->height()); 125 | m_texture->setRect(QRectF(0, sourceSize.height(), sourceSize.width(), -sourceSize.height())); 126 | 127 | QSize maxSize = maxTextureSize(); 128 | /* 129 | if (!maxSize.isValid()) { 130 | GLint param; 131 | 132 | QOpenGLFunctions glFuncs(context); 133 | glFuncs.glGetIntegerv(GL_MAX_TEXTURE_SIZE,¶m); 134 | 135 | maxSize = QSize(param,param); 136 | setMaxTextureSize(maxSize); 137 | } 138 | 139 | QSize textureSize = m_targetSize; 140 | if (maxSize.isValid() && 141 | (textureSize.width() > maxSize.width() || 142 | textureSize.height() > maxSize.height())) { 143 | FVRectToRect scaler; 144 | scaler.scaleToFit(textureSize,maxSize); 145 | // The required size is larger than max texture size. 146 | qDebug() << "Downgrade target image from" << textureSize << scaler.transformedRect().toRect().size(); 147 | textureSize = scaler.transformedRect().toRect().size(); 148 | } 149 | */ 150 | 151 | QSize expectedSize = textureSize(); 152 | 153 | QSGContext *sg = QSGRenderContext::from(context)->sceneGraphContext(); 154 | const QSize minSize = sg->minimumFBOSize(); 155 | m_texture->setSize(QSize(qMax(minSize.width(), expectedSize.width()), 156 | qMax(minSize.height(), expectedSize.height()))); 157 | m_texture->scheduleUpdate(); 158 | m_texture->updateTexture(); 159 | QImage image = m_texture->toImage(); 160 | setImage(image); 161 | 162 | delete m_texture; 163 | m_texture = 0; 164 | } 165 | 166 | disconnect(m_window.data(), SIGNAL(afterRendering()), this, SLOT(capture())); 167 | disconnect(m_window.data(), SIGNAL(beforeSynchronizing()), this, SLOT(ready())); 168 | 169 | setBusy(false); 170 | emit grabbed(); 171 | } 172 | #endif 173 | 174 | void QuickItemGrabber::setBusy(bool value) 175 | { 176 | if (m_busy != value) { 177 | m_busy = value; 178 | emit busyChanged(); 179 | } 180 | } 181 | 182 | void QuickItemGrabber::setImage(QImage value) 183 | { 184 | m_image = value; 185 | emit imageChanged(); 186 | } 187 | 188 | void QuickItemGrabber::clear() 189 | { 190 | setImage(QImage()); 191 | } 192 | 193 | -------------------------------------------------------------------------------- /qml2/quickitemgrabber.h: -------------------------------------------------------------------------------- 1 | /** Author: Ben Lau (https://github.com/benlau) 2 | */ 3 | #ifndef QUICKITEMGRABBER_H 4 | #define QUICKITEMGRABBER_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | /// QuickItemGrabber grabs QQuickItem into QImage 12 | 13 | class QuickItemGrabber : public QObject 14 | { 15 | Q_OBJECT 16 | /// "Busy" flag. It is TRUE if the grabber is running. It won't accept another request when busy. 17 | Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) 18 | 19 | /// The grabbed image 20 | Q_PROPERTY(QImage image READ image NOTIFY imageChanged) 21 | 22 | public: 23 | explicit QuickItemGrabber(QObject *parent = 0); 24 | 25 | bool busy() const; 26 | QImage image() const; 27 | 28 | /// Grab the target item and save to "image" property 29 | Q_INVOKABLE bool grab(QQuickItem* target,QSize targetSize = QSize()); 30 | 31 | /// Save the grabbed image into file. It is a blocked call. 32 | Q_INVOKABLE bool save(QString filename); 33 | 34 | /// Clear the captured image. 35 | Q_INVOKABLE void clear(); 36 | 37 | signals: 38 | void busyChanged(); 39 | void imageChanged(); 40 | void grabbed(); 41 | void maxTextureSizeChanged(); 42 | 43 | private: 44 | // Ready for capture 45 | Q_INVOKABLE void ready(); 46 | 47 | #if (QT_VERSION < QT_VERSION_CHECK(5, 4, 0)) 48 | Q_INVOKABLE void capture(); 49 | #else 50 | Q_INVOKABLE void onGrabResultReady(); 51 | QSharedPointer result; 52 | #endif 53 | 54 | void setBusy(bool value); 55 | void setImage(QImage value); 56 | 57 | bool m_busy; 58 | bool m_ready; 59 | QSize m_targetSize; 60 | QPointer m_target; 61 | QPointer m_window; 62 | QImage m_image; 63 | }; 64 | 65 | #endif // QUICKITEMGRABBER_H 66 | -------------------------------------------------------------------------------- /qrencode/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toby20130333/qtquickqrencode/ea8be185f426ce00da07929b80206e001250d4f5/qrencode/.DS_Store -------------------------------------------------------------------------------- /qrencode/3rd/bitstream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Binary sequence class. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "config.h" 23 | #include 24 | #include 25 | #include 26 | 27 | #include "bitstream.h" 28 | 29 | BitStream *BitStream_new(void) 30 | { 31 | BitStream *bstream; 32 | 33 | bstream = (BitStream *)malloc(sizeof(BitStream)); 34 | if(bstream == NULL) return NULL; 35 | 36 | bstream->length = 0; 37 | bstream->data = NULL; 38 | 39 | return bstream; 40 | } 41 | 42 | static int BitStream_allocate(BitStream *bstream, int length) 43 | { 44 | unsigned char *data; 45 | 46 | if(bstream == NULL) { 47 | return -1; 48 | } 49 | 50 | data = (unsigned char *)malloc(length); 51 | if(data == NULL) { 52 | return -1; 53 | } 54 | 55 | if(bstream->data) { 56 | free(bstream->data); 57 | } 58 | bstream->length = length; 59 | bstream->data = data; 60 | 61 | return 0; 62 | } 63 | 64 | static BitStream *BitStream_newFromNum(int bits, unsigned int num) 65 | { 66 | unsigned int mask; 67 | int i; 68 | unsigned char *p; 69 | BitStream *bstream; 70 | 71 | bstream = BitStream_new(); 72 | if(bstream == NULL) return NULL; 73 | 74 | if(BitStream_allocate(bstream, bits)) { 75 | BitStream_free(bstream); 76 | return NULL; 77 | } 78 | 79 | p = bstream->data; 80 | mask = 1 << (bits - 1); 81 | for(i=0; i> 1; 89 | } 90 | 91 | return bstream; 92 | } 93 | 94 | static BitStream *BitStream_newFromBytes(int size, unsigned char *data) 95 | { 96 | unsigned char mask; 97 | int i, j; 98 | unsigned char *p; 99 | BitStream *bstream; 100 | 101 | bstream = BitStream_new(); 102 | if(bstream == NULL) return NULL; 103 | 104 | if(BitStream_allocate(bstream, size * 8)) { 105 | BitStream_free(bstream); 106 | return NULL; 107 | } 108 | 109 | p = bstream->data; 110 | for(i=0; i> 1; 120 | } 121 | } 122 | 123 | return bstream; 124 | } 125 | 126 | int BitStream_append(BitStream *bstream, BitStream *arg) 127 | { 128 | unsigned char *data; 129 | 130 | if(arg == NULL) { 131 | return -1; 132 | } 133 | if(arg->length == 0) { 134 | return 0; 135 | } 136 | if(bstream->length == 0) { 137 | if(BitStream_allocate(bstream, arg->length)) { 138 | return -1; 139 | } 140 | memcpy(bstream->data, arg->data, arg->length); 141 | return 0; 142 | } 143 | 144 | data = (unsigned char *)malloc(bstream->length + arg->length); 145 | if(data == NULL) { 146 | return -1; 147 | } 148 | memcpy(data, bstream->data, bstream->length); 149 | memcpy(data + bstream->length, arg->data, arg->length); 150 | 151 | free(bstream->data); 152 | bstream->length += arg->length; 153 | bstream->data = data; 154 | 155 | return 0; 156 | } 157 | 158 | int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num) 159 | { 160 | BitStream *b; 161 | int ret; 162 | 163 | if(bits == 0) return 0; 164 | 165 | b = BitStream_newFromNum(bits, num); 166 | if(b == NULL) return -1; 167 | 168 | ret = BitStream_append(bstream, b); 169 | BitStream_free(b); 170 | 171 | return ret; 172 | } 173 | 174 | int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data) 175 | { 176 | BitStream *b; 177 | int ret; 178 | 179 | if(size == 0) return 0; 180 | 181 | b = BitStream_newFromBytes(size, data); 182 | if(b == NULL) return -1; 183 | 184 | ret = BitStream_append(bstream, b); 185 | BitStream_free(b); 186 | 187 | return ret; 188 | } 189 | 190 | unsigned char *BitStream_toByte(BitStream *bstream) 191 | { 192 | int i, j, size, bytes; 193 | unsigned char *data, v; 194 | unsigned char *p; 195 | 196 | size = BitStream_size(bstream); 197 | if(size == 0) { 198 | return NULL; 199 | } 200 | data = (unsigned char *)malloc((size + 7) / 8); 201 | if(data == NULL) { 202 | return NULL; 203 | } 204 | 205 | bytes = size / 8; 206 | 207 | p = bstream->data; 208 | for(i=0; idata); 234 | free(bstream); 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /qrencode/3rd/bitstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Binary sequence class. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __BITSTREAM_H__ 23 | #define __BITSTREAM_H__ 24 | 25 | typedef struct { 26 | int length; 27 | unsigned char *data; 28 | } BitStream; 29 | 30 | extern BitStream *BitStream_new(void); 31 | extern int BitStream_append(BitStream *bstream, BitStream *arg); 32 | extern int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num); 33 | extern int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data); 34 | #define BitStream_size(__bstream__) (__bstream__->length) 35 | extern unsigned char *BitStream_toByte(BitStream *bstream); 36 | extern void BitStream_free(BitStream *bstream); 37 | 38 | #endif /* __BITSTREAM_H__ */ 39 | -------------------------------------------------------------------------------- /qrencode/3rd/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | // #define HAVE_DLFCN_H 1 6 | 7 | /* Define if you have the iconv() function and it works. */ 8 | /* #undef HAVE_ICONV */ 9 | 10 | /* Define to 1 if you have the header file. */ 11 | // #define HAVE_INTTYPES_H 1 12 | 13 | /* Define to 1 if using pthread is enabled. */ 14 | #define HAVE_LIBPTHREAD 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | // #define HAVE_MEMORY_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | // #define HAVE_STDINT_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | // #define HAVE_STDLIB_H 1 24 | 25 | /* Define to 1 if you have the `strdup' function. */ 26 | // #define HAVE_STRDUP 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | // #define HAVE_STRINGS_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | // #define HAVE_STRING_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | // #define HAVE_SYS_STAT_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | // #define HAVE_SYS_TYPES_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | // #define HAVE_UNISTD_H 1 42 | 43 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 44 | */ 45 | // #define LT_OBJDIR ".libs/" 46 | 47 | /* Major version number */ 48 | #define MAJOR_VERSION 3 49 | 50 | /* Micro version number */ 51 | #define MICRO_VERSION 3 52 | 53 | /* Minor version number */ 54 | #define MINOR_VERSION 4 55 | 56 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */ 57 | /* #undef NO_MINUS_C_MINUS_O */ 58 | 59 | /* Name of package */ 60 | // #define PACKAGE "qrencode" 61 | 62 | /* Define to the address where bug reports for this package should be sent. */ 63 | // #define PACKAGE_BUGREPORT "" 64 | 65 | /* Define to the full name of this package. */ 66 | // #define PACKAGE_NAME "" 67 | 68 | /* Define to the full name and version of this package. */ 69 | // #define PACKAGE_STRING "" 70 | 71 | /* Define to the one symbol short name of this package. */ 72 | // #define PACKAGE_TARNAME "" 73 | 74 | /* Define to the home page for this package. */ 75 | // #define PACKAGE_URL "" 76 | 77 | /* Define to the version of this package. */ 78 | // #define PACKAGE_VERSION "" 79 | 80 | /* Define to 1 if you have the ANSI C header files. */ 81 | // #define STDC_HEADERS 1 82 | 83 | /* Version number of package */ 84 | #define VERSION "3.4.3" 85 | 86 | /* Define to empty if `const' does not conform to ANSI C. */ 87 | /* #undef const */ 88 | 89 | /* Define to `__inline__' or `__inline' if that's what the C compiler 90 | calls it, or to nothing if 'inline' is not supported under any name. */ 91 | #ifndef __cplusplus 92 | /* #undef inline */ 93 | #endif 94 | 95 | /* Define to 'static' if no test programs will be compiled. */ 96 | #define __STATIC static 97 | /* #undef WITH_TESTS */ 98 | 99 | -------------------------------------------------------------------------------- /qrencode/3rd/mask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Masking. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MASK_H__ 23 | #define __MASK_H__ 24 | 25 | extern unsigned char *Mask_makeMask(int width, unsigned char *frame, int mask, QRecLevel level); 26 | extern unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level); 27 | 28 | #ifdef WITH_TESTS 29 | extern int Mask_calcN2(int width, unsigned char *frame); 30 | extern int Mask_calcN1N3(int length, int *runLength); 31 | extern int Mask_calcRunLength(int width, unsigned char *frame, int dir, int *runLength); 32 | extern int Mask_evaluateSymbol(int width, unsigned char *frame); 33 | extern int Mask_writeFormatInformation(int width, unsigned char *frame, int mask, QRecLevel level); 34 | extern unsigned char *Mask_makeMaskedFrame(int width, unsigned char *frame, int mask); 35 | #endif 36 | 37 | #endif /* __MASK_H__ */ 38 | -------------------------------------------------------------------------------- /qrencode/3rd/mmask.c: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Masking for Micro QR Code. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "config.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "qrencode.h" 29 | #include "mqrspec.h" 30 | #include "mmask.h" 31 | 32 | 33 | __STATIC void MMask_writeFormatInformation(int version, int width, unsigned char *frame, int mask, QRecLevel level) 34 | { 35 | unsigned int format; 36 | unsigned char v; 37 | int i; 38 | 39 | format = MQRspec_getFormatInfo(mask, version, level); 40 | 41 | for(i=0; i<8; i++) { 42 | v = 0x84 | (format & 1); 43 | frame[width * (i + 1) + 8] = v; 44 | format = format >> 1; 45 | } 46 | for(i=0; i<7; i++) { 47 | v = 0x84 | (format & 1); 48 | frame[width * 8 + 7 - i] = v; 49 | format = format >> 1; 50 | } 51 | } 52 | 53 | #define MASKMAKER(__exp__) \ 54 | int x, y;\ 55 | \ 56 | for(y=0; y= maskNum) { 113 | errno = EINVAL; 114 | return NULL; 115 | } 116 | 117 | width = MQRspec_getWidth(version); 118 | masked = (unsigned char *)malloc(width * width); 119 | if(masked == NULL) return NULL; 120 | 121 | maskMakers[mask](width, frame, masked); 122 | MMask_writeFormatInformation(version, width, masked, mask, level); 123 | 124 | return masked; 125 | } 126 | 127 | __STATIC int MMask_evaluateSymbol(int width, unsigned char *frame) 128 | { 129 | int x, y; 130 | unsigned char *p; 131 | int sum1 = 0, sum2 = 0; 132 | 133 | p = frame + width * (width - 1); 134 | for(x=1; x maxScore) { 167 | maxScore = score; 168 | free(bestMask); 169 | bestMask = mask; 170 | mask = (unsigned char *)malloc(width * width); 171 | if(mask == NULL) break; 172 | } 173 | } 174 | free(mask); 175 | return bestMask; 176 | } 177 | -------------------------------------------------------------------------------- /qrencode/3rd/mmask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Masking for Micro QR Code. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MMASK_H__ 23 | #define __MMASK_H__ 24 | 25 | extern unsigned char *MMask_makeMask(int version, unsigned char *frame, int mask, QRecLevel level); 26 | extern unsigned char *MMask_mask(int version, unsigned char *frame, QRecLevel level); 27 | 28 | #ifdef WITH_TESTS 29 | extern int MMask_evaluateSymbol(int width, unsigned char *frame); 30 | extern void MMask_writeFormatInformation(int version, int width, unsigned char *frame, int mask, QRecLevel level); 31 | extern unsigned char *MMask_makeMaskedFrame(int width, unsigned char *frame, int mask); 32 | #endif 33 | 34 | #endif /* __MMASK_H__ */ 35 | -------------------------------------------------------------------------------- /qrencode/3rd/mqrspec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Micro QR Code specification in convenient format. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MQRSPEC_H__ 23 | #define __MQRSPEC_H__ 24 | 25 | #include "qrencode.h" 26 | 27 | /****************************************************************************** 28 | * Version and capacity 29 | *****************************************************************************/ 30 | 31 | /** 32 | * Maximum width of a symbol 33 | */ 34 | #define MQRSPEC_WIDTH_MAX 17 35 | 36 | /** 37 | * Return maximum data code length (bits) for the version. 38 | * @param version 39 | * @param level 40 | * @return maximum size (bits) 41 | */ 42 | extern int MQRspec_getDataLengthBit(int version, QRecLevel level); 43 | 44 | /** 45 | * Return maximum data code length (bytes) for the version. 46 | * @param version 47 | * @param level 48 | * @return maximum size (bytes) 49 | */ 50 | extern int MQRspec_getDataLength(int version, QRecLevel level); 51 | 52 | /** 53 | * Return maximum error correction code length (bytes) for the version. 54 | * @param version 55 | * @param level 56 | * @return ECC size (bytes) 57 | */ 58 | extern int MQRspec_getECCLength(int version, QRecLevel level); 59 | 60 | /** 61 | * Return a version number that satisfies the input code length. 62 | * @param size input code length (byte) 63 | * @param level 64 | * @return version number 65 | */ 66 | extern int MQRspec_getMinimumVersion(int size, QRecLevel level); 67 | 68 | /** 69 | * Return the width of the symbol for the version. 70 | * @param version 71 | * @return width 72 | */ 73 | extern int MQRspec_getWidth(int version); 74 | 75 | /** 76 | * Return the numer of remainder bits. 77 | * @param version 78 | * @return number of remainder bits 79 | */ 80 | extern int MQRspec_getRemainder(int version); 81 | 82 | /****************************************************************************** 83 | * Length indicator 84 | *****************************************************************************/ 85 | 86 | /** 87 | * Return the size of lenght indicator for the mode and version. 88 | * @param mode 89 | * @param version 90 | * @return the size of the appropriate length indicator (bits). 91 | */ 92 | extern int MQRspec_lengthIndicator(QRencodeMode mode, int version); 93 | 94 | /** 95 | * Return the maximum length for the mode and version. 96 | * @param mode 97 | * @param version 98 | * @return the maximum length (bytes) 99 | */ 100 | extern int MQRspec_maximumWords(QRencodeMode mode, int version); 101 | 102 | /****************************************************************************** 103 | * Version information pattern 104 | *****************************************************************************/ 105 | 106 | /** 107 | * Return BCH encoded version information pattern that is used for the symbol 108 | * of version 7 or greater. Use lower 18 bits. 109 | * @param version 110 | * @return BCH encoded version information pattern 111 | */ 112 | extern unsigned int MQRspec_getVersionPattern(int version); 113 | 114 | /****************************************************************************** 115 | * Format information 116 | *****************************************************************************/ 117 | 118 | /** 119 | * Return BCH encoded format information pattern. 120 | * @param mask 121 | * @param version 122 | * @param level 123 | * @return BCH encoded format information pattern 124 | */ 125 | extern unsigned int MQRspec_getFormatInfo(int mask, int version, QRecLevel level); 126 | 127 | /****************************************************************************** 128 | * Frame 129 | *****************************************************************************/ 130 | 131 | /** 132 | * Return a copy of initialized frame. 133 | * When the same version is requested twice or more, a copy of cached frame 134 | * is returned. 135 | * @param version 136 | * @return Array of unsigned char. You can free it by free(). 137 | */ 138 | extern unsigned char *MQRspec_newFrame(int version); 139 | 140 | /** 141 | * Clear the frame cache. Typically for debug. 142 | */ 143 | extern void MQRspec_clearCache(void); 144 | 145 | /****************************************************************************** 146 | * Mode indicator 147 | *****************************************************************************/ 148 | 149 | /** 150 | * Mode indicator. See Table 2 in Appendix 1 of JIS X0510:2004, pp.107. 151 | */ 152 | #define MQRSPEC_MODEID_NUM 0 153 | #define MQRSPEC_MODEID_AN 1 154 | #define MQRSPEC_MODEID_8 2 155 | #define MQRSPEC_MODEID_KANJI 3 156 | 157 | #endif /* __MQRSPEC_H__ */ 158 | -------------------------------------------------------------------------------- /qrencode/3rd/qrencode_inner.h: -------------------------------------------------------------------------------- 1 | /** 2 | * qrencode - QR Code encoder 3 | * 4 | * Header for test use 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRENCODE_INNER_H__ 23 | #define __QRENCODE_INNER_H__ 24 | 25 | /** 26 | * This header file includes definitions for test use. 27 | */ 28 | 29 | /****************************************************************************** 30 | * Raw code 31 | *****************************************************************************/ 32 | 33 | typedef struct { 34 | int dataLength; 35 | unsigned char *data; 36 | int eccLength; 37 | unsigned char *ecc; 38 | } RSblock; 39 | 40 | typedef struct { 41 | int version; 42 | int dataLength; 43 | int eccLength; 44 | unsigned char *datacode; 45 | unsigned char *ecccode; 46 | int b1; 47 | int blocks; 48 | RSblock *rsblock; 49 | int count; 50 | } QRRawCode; 51 | 52 | extern QRRawCode *QRraw_new(QRinput *input); 53 | extern unsigned char QRraw_getCode(QRRawCode *raw); 54 | extern void QRraw_free(QRRawCode *raw); 55 | 56 | /****************************************************************************** 57 | * Raw code for Micro QR Code 58 | *****************************************************************************/ 59 | 60 | typedef struct { 61 | int version; 62 | int dataLength; 63 | int eccLength; 64 | unsigned char *datacode; 65 | unsigned char *ecccode; 66 | RSblock *rsblock; 67 | int oddbits; 68 | int count; 69 | } MQRRawCode; 70 | 71 | extern MQRRawCode *MQRraw_new(QRinput *input); 72 | extern unsigned char MQRraw_getCode(MQRRawCode *raw); 73 | extern void MQRraw_free(MQRRawCode *raw); 74 | 75 | /****************************************************************************** 76 | * Frame filling 77 | *****************************************************************************/ 78 | extern unsigned char *FrameFiller_test(int version); 79 | extern unsigned char *FrameFiller_testMQR(int version); 80 | 81 | /****************************************************************************** 82 | * QR-code encoding 83 | *****************************************************************************/ 84 | extern QRcode *QRcode_encodeMask(QRinput *input, int mask); 85 | extern QRcode *QRcode_encodeMaskMQR(QRinput *input, int mask); 86 | extern QRcode *QRcode_new(int version, int width, unsigned char *data); 87 | 88 | #endif /* __QRENCODE_INNER_H__ */ 89 | -------------------------------------------------------------------------------- /qrencode/3rd/qrinput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Input data chunk class 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRINPUT_H__ 23 | #define __QRINPUT_H__ 24 | 25 | #include "qrencode.h" 26 | #include "bitstream.h" 27 | 28 | int QRinput_isSplittableMode(QRencodeMode mode); 29 | 30 | /****************************************************************************** 31 | * Entry of input data 32 | *****************************************************************************/ 33 | typedef struct _QRinput_List QRinput_List; 34 | 35 | struct _QRinput_List { 36 | QRencodeMode mode; 37 | int size; ///< Size of data chunk (byte). 38 | unsigned char *data; ///< Data chunk. 39 | BitStream *bstream; 40 | QRinput_List *next; 41 | }; 42 | 43 | /****************************************************************************** 44 | * Input Data 45 | *****************************************************************************/ 46 | struct _QRinput { 47 | int version; 48 | QRecLevel level; 49 | QRinput_List *head; 50 | QRinput_List *tail; 51 | int mqr; 52 | int fnc1; 53 | unsigned char appid; 54 | }; 55 | 56 | /****************************************************************************** 57 | * Structured append input data 58 | *****************************************************************************/ 59 | typedef struct _QRinput_InputList QRinput_InputList; 60 | 61 | struct _QRinput_InputList { 62 | QRinput *input; 63 | QRinput_InputList *next; 64 | }; 65 | 66 | struct _QRinput_Struct { 67 | int size; ///< number of structured symbols 68 | int parity; 69 | QRinput_InputList *head; 70 | QRinput_InputList *tail; 71 | }; 72 | 73 | /** 74 | * Pack all bit streams padding bits into a byte array. 75 | * @param input input data. 76 | * @return padded merged byte stream 77 | */ 78 | extern unsigned char *QRinput_getByteStream(QRinput *input); 79 | 80 | 81 | extern int QRinput_estimateBitsModeNum(int size); 82 | extern int QRinput_estimateBitsModeAn(int size); 83 | extern int QRinput_estimateBitsMode8(int size); 84 | extern int QRinput_estimateBitsModeKanji(int size); 85 | 86 | extern QRinput *QRinput_dup(QRinput *input); 87 | 88 | extern const signed char QRinput_anTable[128]; 89 | 90 | /** 91 | * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19). 92 | * @param __c__ character 93 | * @return value 94 | */ 95 | #define QRinput_lookAnTable(__c__) \ 96 | ((__c__ & 0x80)?-1:QRinput_anTable[(int)__c__]) 97 | 98 | /** 99 | * Length of a standard mode indicator in bits. 100 | */ 101 | 102 | #define MODE_INDICATOR_SIZE 4 103 | 104 | /** 105 | * Length of a segment of structured-append header. 106 | */ 107 | #define STRUCTURE_HEADER_SIZE 20 108 | 109 | /** 110 | * Maximum number of symbols in a set of structured-appended symbols. 111 | */ 112 | #define MAX_STRUCTURED_SYMBOLS 16 113 | 114 | #ifdef WITH_TESTS 115 | extern BitStream *QRinput_mergeBitStream(QRinput *input); 116 | extern BitStream *QRinput_getBitStream(QRinput *input); 117 | extern int QRinput_estimateBitStreamSize(QRinput *input, int version); 118 | extern int QRinput_splitEntry(QRinput_List *entry, int bytes); 119 | extern int QRinput_lengthOfCode(QRencodeMode mode, int version, int bits); 120 | extern int QRinput_insertStructuredAppendHeader(QRinput *input, int size, int index, unsigned char parity); 121 | #endif 122 | 123 | #endif /* __QRINPUT_H__ */ 124 | -------------------------------------------------------------------------------- /qrencode/3rd/qrspec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * QR Code specification in convenient format. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRSPEC_H__ 23 | #define __QRSPEC_H__ 24 | 25 | #include "qrencode.h" 26 | 27 | /****************************************************************************** 28 | * Version and capacity 29 | *****************************************************************************/ 30 | 31 | /** 32 | * Maximum width of a symbol 33 | */ 34 | #define QRSPEC_WIDTH_MAX 177 35 | 36 | /** 37 | * Return maximum data code length (bytes) for the version. 38 | * @param version 39 | * @param level 40 | * @return maximum size (bytes) 41 | */ 42 | extern int QRspec_getDataLength(int version, QRecLevel level); 43 | 44 | /** 45 | * Return maximum error correction code length (bytes) for the version. 46 | * @param version 47 | * @param level 48 | * @return ECC size (bytes) 49 | */ 50 | extern int QRspec_getECCLength(int version, QRecLevel level); 51 | 52 | /** 53 | * Return a version number that satisfies the input code length. 54 | * @param size input code length (byte) 55 | * @param level 56 | * @return version number 57 | */ 58 | extern int QRspec_getMinimumVersion(int size, QRecLevel level); 59 | 60 | /** 61 | * Return the width of the symbol for the version. 62 | * @param version 63 | * @return width 64 | */ 65 | extern int QRspec_getWidth(int version); 66 | 67 | /** 68 | * Return the numer of remainder bits. 69 | * @param version 70 | * @return number of remainder bits 71 | */ 72 | extern int QRspec_getRemainder(int version); 73 | 74 | /****************************************************************************** 75 | * Length indicator 76 | *****************************************************************************/ 77 | 78 | /** 79 | * Return the size of lenght indicator for the mode and version. 80 | * @param mode 81 | * @param version 82 | * @return the size of the appropriate length indicator (bits). 83 | */ 84 | extern int QRspec_lengthIndicator(QRencodeMode mode, int version); 85 | 86 | /** 87 | * Return the maximum length for the mode and version. 88 | * @param mode 89 | * @param version 90 | * @return the maximum length (bytes) 91 | */ 92 | extern int QRspec_maximumWords(QRencodeMode mode, int version); 93 | 94 | /****************************************************************************** 95 | * Error correction code 96 | *****************************************************************************/ 97 | 98 | /** 99 | * Return an array of ECC specification. 100 | * @param version 101 | * @param level 102 | * @param spec an array of ECC specification contains as following: 103 | * {# of type1 blocks, # of data code, # of ecc code, 104 | * # of type2 blocks, # of data code} 105 | */ 106 | void QRspec_getEccSpec(int version, QRecLevel level, int spec[5]); 107 | 108 | #define QRspec_rsBlockNum(__spec__) (__spec__[0] + __spec__[3]) 109 | #define QRspec_rsBlockNum1(__spec__) (__spec__[0]) 110 | #define QRspec_rsDataCodes1(__spec__) (__spec__[1]) 111 | #define QRspec_rsEccCodes1(__spec__) (__spec__[2]) 112 | #define QRspec_rsBlockNum2(__spec__) (__spec__[3]) 113 | #define QRspec_rsDataCodes2(__spec__) (__spec__[4]) 114 | #define QRspec_rsEccCodes2(__spec__) (__spec__[2]) 115 | 116 | #define QRspec_rsDataLength(__spec__) \ 117 | ((QRspec_rsBlockNum1(__spec__) * QRspec_rsDataCodes1(__spec__)) + \ 118 | (QRspec_rsBlockNum2(__spec__) * QRspec_rsDataCodes2(__spec__))) 119 | #define QRspec_rsEccLength(__spec__) \ 120 | (QRspec_rsBlockNum(__spec__) * QRspec_rsEccCodes1(__spec__)) 121 | 122 | /****************************************************************************** 123 | * Version information pattern 124 | *****************************************************************************/ 125 | 126 | /** 127 | * Return BCH encoded version information pattern that is used for the symbol 128 | * of version 7 or greater. Use lower 18 bits. 129 | * @param version 130 | * @return BCH encoded version information pattern 131 | */ 132 | extern unsigned int QRspec_getVersionPattern(int version); 133 | 134 | /****************************************************************************** 135 | * Format information 136 | *****************************************************************************/ 137 | 138 | /** 139 | * Return BCH encoded format information pattern. 140 | * @param mask 141 | * @param level 142 | * @return BCH encoded format information pattern 143 | */ 144 | extern unsigned int QRspec_getFormatInfo(int mask, QRecLevel level); 145 | 146 | /****************************************************************************** 147 | * Frame 148 | *****************************************************************************/ 149 | 150 | /** 151 | * Return a copy of initialized frame. 152 | * When the same version is requested twice or more, a copy of cached frame 153 | * is returned. 154 | * @param version 155 | * @return Array of unsigned char. You can free it by free(). 156 | */ 157 | extern unsigned char *QRspec_newFrame(int version); 158 | 159 | /** 160 | * Clear the frame cache. Typically for debug. 161 | */ 162 | extern void QRspec_clearCache(void); 163 | 164 | /****************************************************************************** 165 | * Mode indicator 166 | *****************************************************************************/ 167 | 168 | /** 169 | * Mode indicator. See Table 2 of JIS X0510:2004, pp.16. 170 | */ 171 | #define QRSPEC_MODEID_ECI 7 172 | #define QRSPEC_MODEID_NUM 1 173 | #define QRSPEC_MODEID_AN 2 174 | #define QRSPEC_MODEID_8 4 175 | #define QRSPEC_MODEID_KANJI 8 176 | #define QRSPEC_MODEID_FNC1FIRST 5 177 | #define QRSPEC_MODEID_FNC1SECOND 9 178 | #define QRSPEC_MODEID_STRUCTURE 3 179 | #define QRSPEC_MODEID_TERMINATOR 0 180 | 181 | #endif /* __QRSPEC_H__ */ 182 | -------------------------------------------------------------------------------- /qrencode/3rd/rscode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Reed solomon encoder. This code is taken from Phil Karn's libfec then 5 | * editted and packed into a pair of .c and .h files. 6 | * 7 | * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q 8 | * (libfec is released under the GNU Lesser General Public License.) 9 | * 10 | * Copyright (C) 2006-2011 Kentaro Fukuchi 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2.1 of the License, or any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef __RSCODE_H__ 28 | #define __RSCODE_H__ 29 | 30 | /* 31 | * General purpose RS codec, 8-bit symbols. 32 | */ 33 | 34 | typedef struct _RS RS; 35 | 36 | extern RS *init_rs(int symsize, int gfpoly, int fcr, int prim, int nroots, int pad); 37 | extern void encode_rs_char(RS *rs, const unsigned char *data, unsigned char *parity); 38 | extern void free_rs_char(RS *rs); 39 | extern void free_rs_cache(void); 40 | 41 | #endif /* __RSCODE_H__ */ 42 | -------------------------------------------------------------------------------- /qrencode/3rd/split.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Input data splitter. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * The following data / specifications are taken from 8 | * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) 9 | * or 10 | * "Automatic identification and data capture techniques -- 11 | * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) 12 | * 13 | * This library is free software; you can redistribute it and/or 14 | * modify it under the terms of the GNU Lesser General Public 15 | * License as published by the Free Software Foundation; either 16 | * version 2.1 of the License, or any later version. 17 | * 18 | * This library is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | * Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public 24 | * License along with this library; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef __SPLIT_H__ 29 | #define __SPLIT_H__ 30 | 31 | #include "qrencode.h" 32 | 33 | /** 34 | * Split the input string (null terminated) into QRinput. 35 | * @param string input string 36 | * @param hint give QR_MODE_KANJI if the input string contains Kanji character encoded in Shift-JIS. If not, give QR_MODE_8. 37 | * @param casesensitive 0 for case-insensitive encoding (all alphabet characters are replaced to UPPER-CASE CHARACTERS. 38 | * @retval 0 success. 39 | * @retval -1 an error occurred. errno is set to indicate the error. See 40 | * Exceptions for the details. 41 | * @throw EINVAL invalid input object. 42 | * @throw ENOMEM unable to allocate memory for input objects. 43 | */ 44 | extern int Split_splitStringToQRinput(const char *string, QRinput *input, 45 | QRencodeMode hint, int casesensitive); 46 | 47 | #endif /* __SPLIT_H__ */ 48 | -------------------------------------------------------------------------------- /qrencode/qrencode.pri: -------------------------------------------------------------------------------- 1 | 2 | INCLUDEPATH += $$PWD 3 | 4 | HEADERS += \ 5 | $$PWD/qrencode/3rd/bitstream.h \ 6 | $$PWD/qrencode/3rd/config.h \ 7 | $$PWD/qrencode/3rd/mask.h \ 8 | $$PWD/qrencode/3rd/mmask.h \ 9 | $$PWD/qrencode/3rd/mqrspec.h \ 10 | $$PWD/qrencode/3rd/qrencode.h \ 11 | $$PWD/qrencode/3rd/qrencode_inner.h \ 12 | $$PWD/qrencode/3rd/qrinput.h \ 13 | $$PWD/qrencode/3rd/qrspec.h \ 14 | $$PWD/qrencode/3rd/rscode.h \ 15 | $$PWD/qrencode/3rd/split.h 16 | 17 | SOURCES += \ 18 | $$PWD/qrencode/3rd/bitstream.c \ 19 | $$PWD/qrencode/3rd/mask.c \ 20 | $$PWD/qrencode/3rd/mmask.c \ 21 | $$PWD/qrencode/3rd/mqrspec.c \ 22 | $$PWD/qrencode/3rd/qrencode.c \ 23 | $$PWD/qrencode/3rd/qrinput.c \ 24 | $$PWD/qrencode/3rd/qrspec.c \ 25 | $$PWD/qrencode/3rd/rscode.c \ 26 | $$PWD/qrencode/3rd/split.c 27 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/bitstream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Binary sequence class. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "config.h" 23 | #include 24 | #include 25 | #include 26 | 27 | #include "bitstream.h" 28 | 29 | BitStream *BitStream_new(void) 30 | { 31 | BitStream *bstream; 32 | 33 | bstream = (BitStream *)malloc(sizeof(BitStream)); 34 | if(bstream == NULL) return NULL; 35 | 36 | bstream->length = 0; 37 | bstream->data = NULL; 38 | 39 | return bstream; 40 | } 41 | 42 | static int BitStream_allocate(BitStream *bstream, int length) 43 | { 44 | unsigned char *data; 45 | 46 | if(bstream == NULL) { 47 | return -1; 48 | } 49 | 50 | data = (unsigned char *)malloc(length); 51 | if(data == NULL) { 52 | return -1; 53 | } 54 | 55 | if(bstream->data) { 56 | free(bstream->data); 57 | } 58 | bstream->length = length; 59 | bstream->data = data; 60 | 61 | return 0; 62 | } 63 | 64 | static BitStream *BitStream_newFromNum(int bits, unsigned int num) 65 | { 66 | unsigned int mask; 67 | int i; 68 | unsigned char *p; 69 | BitStream *bstream; 70 | 71 | bstream = BitStream_new(); 72 | if(bstream == NULL) return NULL; 73 | 74 | if(BitStream_allocate(bstream, bits)) { 75 | BitStream_free(bstream); 76 | return NULL; 77 | } 78 | 79 | p = bstream->data; 80 | mask = 1 << (bits - 1); 81 | for(i=0; i> 1; 89 | } 90 | 91 | return bstream; 92 | } 93 | 94 | static BitStream *BitStream_newFromBytes(int size, unsigned char *data) 95 | { 96 | unsigned char mask; 97 | int i, j; 98 | unsigned char *p; 99 | BitStream *bstream; 100 | 101 | bstream = BitStream_new(); 102 | if(bstream == NULL) return NULL; 103 | 104 | if(BitStream_allocate(bstream, size * 8)) { 105 | BitStream_free(bstream); 106 | return NULL; 107 | } 108 | 109 | p = bstream->data; 110 | for(i=0; i> 1; 120 | } 121 | } 122 | 123 | return bstream; 124 | } 125 | 126 | int BitStream_append(BitStream *bstream, BitStream *arg) 127 | { 128 | unsigned char *data; 129 | 130 | if(arg == NULL) { 131 | return -1; 132 | } 133 | if(arg->length == 0) { 134 | return 0; 135 | } 136 | if(bstream->length == 0) { 137 | if(BitStream_allocate(bstream, arg->length)) { 138 | return -1; 139 | } 140 | memcpy(bstream->data, arg->data, arg->length); 141 | return 0; 142 | } 143 | 144 | data = (unsigned char *)malloc(bstream->length + arg->length); 145 | if(data == NULL) { 146 | return -1; 147 | } 148 | memcpy(data, bstream->data, bstream->length); 149 | memcpy(data + bstream->length, arg->data, arg->length); 150 | 151 | free(bstream->data); 152 | bstream->length += arg->length; 153 | bstream->data = data; 154 | 155 | return 0; 156 | } 157 | 158 | int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num) 159 | { 160 | BitStream *b; 161 | int ret; 162 | 163 | if(bits == 0) return 0; 164 | 165 | b = BitStream_newFromNum(bits, num); 166 | if(b == NULL) return -1; 167 | 168 | ret = BitStream_append(bstream, b); 169 | BitStream_free(b); 170 | 171 | return ret; 172 | } 173 | 174 | int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data) 175 | { 176 | BitStream *b; 177 | int ret; 178 | 179 | if(size == 0) return 0; 180 | 181 | b = BitStream_newFromBytes(size, data); 182 | if(b == NULL) return -1; 183 | 184 | ret = BitStream_append(bstream, b); 185 | BitStream_free(b); 186 | 187 | return ret; 188 | } 189 | 190 | unsigned char *BitStream_toByte(BitStream *bstream) 191 | { 192 | int i, j, size, bytes; 193 | unsigned char *data, v; 194 | unsigned char *p; 195 | 196 | size = BitStream_size(bstream); 197 | if(size == 0) { 198 | return NULL; 199 | } 200 | data = (unsigned char *)malloc((size + 7) / 8); 201 | if(data == NULL) { 202 | return NULL; 203 | } 204 | 205 | bytes = size / 8; 206 | 207 | p = bstream->data; 208 | for(i=0; idata); 234 | free(bstream); 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/bitstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Binary sequence class. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __BITSTREAM_H__ 23 | #define __BITSTREAM_H__ 24 | 25 | typedef struct { 26 | int length; 27 | unsigned char *data; 28 | } BitStream; 29 | 30 | extern BitStream *BitStream_new(void); 31 | extern int BitStream_append(BitStream *bstream, BitStream *arg); 32 | extern int BitStream_appendNum(BitStream *bstream, int bits, unsigned int num); 33 | extern int BitStream_appendBytes(BitStream *bstream, int size, unsigned char *data); 34 | #define BitStream_size(__bstream__) (__bstream__->length) 35 | extern unsigned char *BitStream_toByte(BitStream *bstream); 36 | extern void BitStream_free(BitStream *bstream); 37 | 38 | #endif /* __BITSTREAM_H__ */ 39 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | // #define HAVE_DLFCN_H 1 6 | 7 | /* Define if you have the iconv() function and it works. */ 8 | /* #undef HAVE_ICONV */ 9 | 10 | /* Define to 1 if you have the header file. */ 11 | // #define HAVE_INTTYPES_H 1 12 | 13 | /* Define to 1 if using pthread is enabled. */ 14 | #ifndef WIN32 15 | #define HAVE_LIBPTHREAD 1 16 | #endif 17 | /* Define to 1 if you have the header file. */ 18 | // #define HAVE_MEMORY_H 1 19 | 20 | /* Define to 1 if you have the header file. */ 21 | // #define HAVE_STDINT_H 1 22 | 23 | /* Define to 1 if you have the header file. */ 24 | // #define HAVE_STDLIB_H 1 25 | 26 | /* Define to 1 if you have the `strdup' function. */ 27 | // #define HAVE_STRDUP 1 28 | 29 | /* Define to 1 if you have the header file. */ 30 | // #define HAVE_STRINGS_H 1 31 | 32 | /* Define to 1 if you have the header file. */ 33 | // #define HAVE_STRING_H 1 34 | 35 | /* Define to 1 if you have the header file. */ 36 | // #define HAVE_SYS_STAT_H 1 37 | 38 | /* Define to 1 if you have the header file. */ 39 | // #define HAVE_SYS_TYPES_H 1 40 | 41 | /* Define to 1 if you have the header file. */ 42 | // #define HAVE_UNISTD_H 1 43 | 44 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 45 | */ 46 | // #define LT_OBJDIR ".libs/" 47 | 48 | /* Major version number */ 49 | #define MAJOR_VERSION 3 50 | 51 | /* Micro version number */ 52 | #define MICRO_VERSION 3 53 | 54 | /* Minor version number */ 55 | #define MINOR_VERSION 4 56 | 57 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */ 58 | /* #undef NO_MINUS_C_MINUS_O */ 59 | 60 | /* Name of package */ 61 | // #define PACKAGE "qrencode" 62 | 63 | /* Define to the address where bug reports for this package should be sent. */ 64 | // #define PACKAGE_BUGREPORT "" 65 | 66 | /* Define to the full name of this package. */ 67 | // #define PACKAGE_NAME "" 68 | 69 | /* Define to the full name and version of this package. */ 70 | // #define PACKAGE_STRING "" 71 | 72 | /* Define to the one symbol short name of this package. */ 73 | // #define PACKAGE_TARNAME "" 74 | 75 | /* Define to the home page for this package. */ 76 | // #define PACKAGE_URL "" 77 | 78 | /* Define to the version of this package. */ 79 | // #define PACKAGE_VERSION "" 80 | 81 | /* Define to 1 if you have the ANSI C header files. */ 82 | // #define STDC_HEADERS 1 83 | 84 | /* Version number of package */ 85 | #define VERSION "3.4.3" 86 | 87 | /* Define to empty if `const' does not conform to ANSI C. */ 88 | /* #undef const */ 89 | 90 | /* Define to `__inline__' or `__inline' if that's what the C compiler 91 | calls it, or to nothing if 'inline' is not supported under any name. */ 92 | #ifndef __cplusplus 93 | /* #undef inline */ 94 | #endif 95 | 96 | /* Define to 'static' if no test programs will be compiled. */ 97 | #define __STATIC static 98 | /* #undef WITH_TESTS */ 99 | 100 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/mask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Masking. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MASK_H__ 23 | #define __MASK_H__ 24 | 25 | extern unsigned char *Mask_makeMask(int width, unsigned char *frame, int mask, QRecLevel level); 26 | extern unsigned char *Mask_mask(int width, unsigned char *frame, QRecLevel level); 27 | 28 | #ifdef WITH_TESTS 29 | extern int Mask_calcN2(int width, unsigned char *frame); 30 | extern int Mask_calcN1N3(int length, int *runLength); 31 | extern int Mask_calcRunLength(int width, unsigned char *frame, int dir, int *runLength); 32 | extern int Mask_evaluateSymbol(int width, unsigned char *frame); 33 | extern int Mask_writeFormatInformation(int width, unsigned char *frame, int mask, QRecLevel level); 34 | extern unsigned char *Mask_makeMaskedFrame(int width, unsigned char *frame, int mask); 35 | #endif 36 | 37 | #endif /* __MASK_H__ */ 38 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/mmask.c: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Masking for Micro QR Code. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #include "config.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "qrencode.h" 29 | #include "mqrspec.h" 30 | #include "mmask.h" 31 | 32 | 33 | __STATIC void MMask_writeFormatInformation(int version, int width, unsigned char *frame, int mask, QRecLevel level) 34 | { 35 | unsigned int format; 36 | unsigned char v; 37 | int i; 38 | 39 | format = MQRspec_getFormatInfo(mask, version, level); 40 | 41 | for(i=0; i<8; i++) { 42 | v = 0x84 | (format & 1); 43 | frame[width * (i + 1) + 8] = v; 44 | format = format >> 1; 45 | } 46 | for(i=0; i<7; i++) { 47 | v = 0x84 | (format & 1); 48 | frame[width * 8 + 7 - i] = v; 49 | format = format >> 1; 50 | } 51 | } 52 | 53 | #define MASKMAKER(__exp__) \ 54 | int x, y;\ 55 | \ 56 | for(y=0; y= maskNum) { 113 | errno = EINVAL; 114 | return NULL; 115 | } 116 | 117 | width = MQRspec_getWidth(version); 118 | masked = (unsigned char *)malloc(width * width); 119 | if(masked == NULL) return NULL; 120 | 121 | maskMakers[mask](width, frame, masked); 122 | MMask_writeFormatInformation(version, width, masked, mask, level); 123 | 124 | return masked; 125 | } 126 | 127 | __STATIC int MMask_evaluateSymbol(int width, unsigned char *frame) 128 | { 129 | int x, y; 130 | unsigned char *p; 131 | int sum1 = 0, sum2 = 0; 132 | 133 | p = frame + width * (width - 1); 134 | for(x=1; x maxScore) { 167 | maxScore = score; 168 | free(bestMask); 169 | bestMask = mask; 170 | mask = (unsigned char *)malloc(width * width); 171 | if(mask == NULL) break; 172 | } 173 | } 174 | free(mask); 175 | return bestMask; 176 | } 177 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/mmask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Masking for Micro QR Code. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MMASK_H__ 23 | #define __MMASK_H__ 24 | 25 | extern unsigned char *MMask_makeMask(int version, unsigned char *frame, int mask, QRecLevel level); 26 | extern unsigned char *MMask_mask(int version, unsigned char *frame, QRecLevel level); 27 | 28 | #ifdef WITH_TESTS 29 | extern int MMask_evaluateSymbol(int width, unsigned char *frame); 30 | extern void MMask_writeFormatInformation(int version, int width, unsigned char *frame, int mask, QRecLevel level); 31 | extern unsigned char *MMask_makeMaskedFrame(int width, unsigned char *frame, int mask); 32 | #endif 33 | 34 | #endif /* __MMASK_H__ */ 35 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/mqrspec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Micro QR Code specification in convenient format. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __MQRSPEC_H__ 23 | #define __MQRSPEC_H__ 24 | 25 | #include "qrencode.h" 26 | 27 | /****************************************************************************** 28 | * Version and capacity 29 | *****************************************************************************/ 30 | 31 | /** 32 | * Maximum width of a symbol 33 | */ 34 | #define MQRSPEC_WIDTH_MAX 17 35 | 36 | /** 37 | * Return maximum data code length (bits) for the version. 38 | * @param version 39 | * @param level 40 | * @return maximum size (bits) 41 | */ 42 | extern int MQRspec_getDataLengthBit(int version, QRecLevel level); 43 | 44 | /** 45 | * Return maximum data code length (bytes) for the version. 46 | * @param version 47 | * @param level 48 | * @return maximum size (bytes) 49 | */ 50 | extern int MQRspec_getDataLength(int version, QRecLevel level); 51 | 52 | /** 53 | * Return maximum error correction code length (bytes) for the version. 54 | * @param version 55 | * @param level 56 | * @return ECC size (bytes) 57 | */ 58 | extern int MQRspec_getECCLength(int version, QRecLevel level); 59 | 60 | /** 61 | * Return a version number that satisfies the input code length. 62 | * @param size input code length (byte) 63 | * @param level 64 | * @return version number 65 | */ 66 | extern int MQRspec_getMinimumVersion(int size, QRecLevel level); 67 | 68 | /** 69 | * Return the width of the symbol for the version. 70 | * @param version 71 | * @return width 72 | */ 73 | extern int MQRspec_getWidth(int version); 74 | 75 | /** 76 | * Return the numer of remainder bits. 77 | * @param version 78 | * @return number of remainder bits 79 | */ 80 | extern int MQRspec_getRemainder(int version); 81 | 82 | /****************************************************************************** 83 | * Length indicator 84 | *****************************************************************************/ 85 | 86 | /** 87 | * Return the size of lenght indicator for the mode and version. 88 | * @param mode 89 | * @param version 90 | * @return the size of the appropriate length indicator (bits). 91 | */ 92 | extern int MQRspec_lengthIndicator(QRencodeMode mode, int version); 93 | 94 | /** 95 | * Return the maximum length for the mode and version. 96 | * @param mode 97 | * @param version 98 | * @return the maximum length (bytes) 99 | */ 100 | extern int MQRspec_maximumWords(QRencodeMode mode, int version); 101 | 102 | /****************************************************************************** 103 | * Version information pattern 104 | *****************************************************************************/ 105 | 106 | /** 107 | * Return BCH encoded version information pattern that is used for the symbol 108 | * of version 7 or greater. Use lower 18 bits. 109 | * @param version 110 | * @return BCH encoded version information pattern 111 | */ 112 | extern unsigned int MQRspec_getVersionPattern(int version); 113 | 114 | /****************************************************************************** 115 | * Format information 116 | *****************************************************************************/ 117 | 118 | /** 119 | * Return BCH encoded format information pattern. 120 | * @param mask 121 | * @param version 122 | * @param level 123 | * @return BCH encoded format information pattern 124 | */ 125 | extern unsigned int MQRspec_getFormatInfo(int mask, int version, QRecLevel level); 126 | 127 | /****************************************************************************** 128 | * Frame 129 | *****************************************************************************/ 130 | 131 | /** 132 | * Return a copy of initialized frame. 133 | * When the same version is requested twice or more, a copy of cached frame 134 | * is returned. 135 | * @param version 136 | * @return Array of unsigned char. You can free it by free(). 137 | */ 138 | extern unsigned char *MQRspec_newFrame(int version); 139 | 140 | /** 141 | * Clear the frame cache. Typically for debug. 142 | */ 143 | extern void MQRspec_clearCache(void); 144 | 145 | /****************************************************************************** 146 | * Mode indicator 147 | *****************************************************************************/ 148 | 149 | /** 150 | * Mode indicator. See Table 2 in Appendix 1 of JIS X0510:2004, pp.107. 151 | */ 152 | #define MQRSPEC_MODEID_NUM 0 153 | #define MQRSPEC_MODEID_AN 1 154 | #define MQRSPEC_MODEID_8 2 155 | #define MQRSPEC_MODEID_KANJI 3 156 | 157 | #endif /* __MQRSPEC_H__ */ 158 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/qrencode_inner.h: -------------------------------------------------------------------------------- 1 | /** 2 | * qrencode - QR Code encoder 3 | * 4 | * Header for test use 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRENCODE_INNER_H__ 23 | #define __QRENCODE_INNER_H__ 24 | 25 | /** 26 | * This header file includes definitions for test use. 27 | */ 28 | 29 | /****************************************************************************** 30 | * Raw code 31 | *****************************************************************************/ 32 | 33 | typedef struct { 34 | int dataLength; 35 | unsigned char *data; 36 | int eccLength; 37 | unsigned char *ecc; 38 | } RSblock; 39 | 40 | typedef struct { 41 | int version; 42 | int dataLength; 43 | int eccLength; 44 | unsigned char *datacode; 45 | unsigned char *ecccode; 46 | int b1; 47 | int blocks; 48 | RSblock *rsblock; 49 | int count; 50 | } QRRawCode; 51 | 52 | extern QRRawCode *QRraw_new(QRinput *input); 53 | extern unsigned char QRraw_getCode(QRRawCode *raw); 54 | extern void QRraw_free(QRRawCode *raw); 55 | 56 | /****************************************************************************** 57 | * Raw code for Micro QR Code 58 | *****************************************************************************/ 59 | 60 | typedef struct { 61 | int version; 62 | int dataLength; 63 | int eccLength; 64 | unsigned char *datacode; 65 | unsigned char *ecccode; 66 | RSblock *rsblock; 67 | int oddbits; 68 | int count; 69 | } MQRRawCode; 70 | 71 | extern MQRRawCode *MQRraw_new(QRinput *input); 72 | extern unsigned char MQRraw_getCode(MQRRawCode *raw); 73 | extern void MQRraw_free(MQRRawCode *raw); 74 | 75 | /****************************************************************************** 76 | * Frame filling 77 | *****************************************************************************/ 78 | extern unsigned char *FrameFiller_test(int version); 79 | extern unsigned char *FrameFiller_testMQR(int version); 80 | 81 | /****************************************************************************** 82 | * QR-code encoding 83 | *****************************************************************************/ 84 | extern QRcode *QRcode_encodeMask(QRinput *input, int mask); 85 | extern QRcode *QRcode_encodeMaskMQR(QRinput *input, int mask); 86 | extern QRcode *QRcode_new(int version, int width, unsigned char *data); 87 | 88 | #endif /* __QRENCODE_INNER_H__ */ 89 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/qrinput.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Input data chunk class 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRINPUT_H__ 23 | #define __QRINPUT_H__ 24 | 25 | #include "qrencode.h" 26 | #include "bitstream.h" 27 | 28 | int QRinput_isSplittableMode(QRencodeMode mode); 29 | 30 | /****************************************************************************** 31 | * Entry of input data 32 | *****************************************************************************/ 33 | typedef struct _QRinput_List QRinput_List; 34 | 35 | struct _QRinput_List { 36 | QRencodeMode mode; 37 | int size; ///< Size of data chunk (byte). 38 | unsigned char *data; ///< Data chunk. 39 | BitStream *bstream; 40 | QRinput_List *next; 41 | }; 42 | 43 | /****************************************************************************** 44 | * Input Data 45 | *****************************************************************************/ 46 | struct _QRinput { 47 | int version; 48 | QRecLevel level; 49 | QRinput_List *head; 50 | QRinput_List *tail; 51 | int mqr; 52 | int fnc1; 53 | unsigned char appid; 54 | }; 55 | 56 | /****************************************************************************** 57 | * Structured append input data 58 | *****************************************************************************/ 59 | typedef struct _QRinput_InputList QRinput_InputList; 60 | 61 | struct _QRinput_InputList { 62 | QRinput *input; 63 | QRinput_InputList *next; 64 | }; 65 | 66 | struct _QRinput_Struct { 67 | int size; ///< number of structured symbols 68 | int parity; 69 | QRinput_InputList *head; 70 | QRinput_InputList *tail; 71 | }; 72 | 73 | /** 74 | * Pack all bit streams padding bits into a byte array. 75 | * @param input input data. 76 | * @return padded merged byte stream 77 | */ 78 | extern unsigned char *QRinput_getByteStream(QRinput *input); 79 | 80 | 81 | extern int QRinput_estimateBitsModeNum(int size); 82 | extern int QRinput_estimateBitsModeAn(int size); 83 | extern int QRinput_estimateBitsMode8(int size); 84 | extern int QRinput_estimateBitsModeKanji(int size); 85 | 86 | extern QRinput *QRinput_dup(QRinput *input); 87 | 88 | extern const signed char QRinput_anTable[128]; 89 | 90 | /** 91 | * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19). 92 | * @param __c__ character 93 | * @return value 94 | */ 95 | #define QRinput_lookAnTable(__c__) \ 96 | ((__c__ & 0x80)?-1:QRinput_anTable[(int)__c__]) 97 | 98 | /** 99 | * Length of a standard mode indicator in bits. 100 | */ 101 | 102 | #define MODE_INDICATOR_SIZE 4 103 | 104 | /** 105 | * Length of a segment of structured-append header. 106 | */ 107 | #define STRUCTURE_HEADER_SIZE 20 108 | 109 | /** 110 | * Maximum number of symbols in a set of structured-appended symbols. 111 | */ 112 | #define MAX_STRUCTURED_SYMBOLS 16 113 | 114 | #ifdef WITH_TESTS 115 | extern BitStream *QRinput_mergeBitStream(QRinput *input); 116 | extern BitStream *QRinput_getBitStream(QRinput *input); 117 | extern int QRinput_estimateBitStreamSize(QRinput *input, int version); 118 | extern int QRinput_splitEntry(QRinput_List *entry, int bytes); 119 | extern int QRinput_lengthOfCode(QRencodeMode mode, int version, int bits); 120 | extern int QRinput_insertStructuredAppendHeader(QRinput *input, int size, int index, unsigned char parity); 121 | #endif 122 | 123 | #endif /* __QRINPUT_H__ */ 124 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/qrspec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * QR Code specification in convenient format. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | */ 21 | 22 | #ifndef __QRSPEC_H__ 23 | #define __QRSPEC_H__ 24 | 25 | #include "qrencode.h" 26 | 27 | /****************************************************************************** 28 | * Version and capacity 29 | *****************************************************************************/ 30 | 31 | /** 32 | * Maximum width of a symbol 33 | */ 34 | #define QRSPEC_WIDTH_MAX 177 35 | 36 | /** 37 | * Return maximum data code length (bytes) for the version. 38 | * @param version 39 | * @param level 40 | * @return maximum size (bytes) 41 | */ 42 | extern int QRspec_getDataLength(int version, QRecLevel level); 43 | 44 | /** 45 | * Return maximum error correction code length (bytes) for the version. 46 | * @param version 47 | * @param level 48 | * @return ECC size (bytes) 49 | */ 50 | extern int QRspec_getECCLength(int version, QRecLevel level); 51 | 52 | /** 53 | * Return a version number that satisfies the input code length. 54 | * @param size input code length (byte) 55 | * @param level 56 | * @return version number 57 | */ 58 | extern int QRspec_getMinimumVersion(int size, QRecLevel level); 59 | 60 | /** 61 | * Return the width of the symbol for the version. 62 | * @param version 63 | * @return width 64 | */ 65 | extern int QRspec_getWidth(int version); 66 | 67 | /** 68 | * Return the numer of remainder bits. 69 | * @param version 70 | * @return number of remainder bits 71 | */ 72 | extern int QRspec_getRemainder(int version); 73 | 74 | /****************************************************************************** 75 | * Length indicator 76 | *****************************************************************************/ 77 | 78 | /** 79 | * Return the size of lenght indicator for the mode and version. 80 | * @param mode 81 | * @param version 82 | * @return the size of the appropriate length indicator (bits). 83 | */ 84 | extern int QRspec_lengthIndicator(QRencodeMode mode, int version); 85 | 86 | /** 87 | * Return the maximum length for the mode and version. 88 | * @param mode 89 | * @param version 90 | * @return the maximum length (bytes) 91 | */ 92 | extern int QRspec_maximumWords(QRencodeMode mode, int version); 93 | 94 | /****************************************************************************** 95 | * Error correction code 96 | *****************************************************************************/ 97 | 98 | /** 99 | * Return an array of ECC specification. 100 | * @param version 101 | * @param level 102 | * @param spec an array of ECC specification contains as following: 103 | * {# of type1 blocks, # of data code, # of ecc code, 104 | * # of type2 blocks, # of data code} 105 | */ 106 | void QRspec_getEccSpec(int version, QRecLevel level, int spec[5]); 107 | 108 | #define QRspec_rsBlockNum(__spec__) (__spec__[0] + __spec__[3]) 109 | #define QRspec_rsBlockNum1(__spec__) (__spec__[0]) 110 | #define QRspec_rsDataCodes1(__spec__) (__spec__[1]) 111 | #define QRspec_rsEccCodes1(__spec__) (__spec__[2]) 112 | #define QRspec_rsBlockNum2(__spec__) (__spec__[3]) 113 | #define QRspec_rsDataCodes2(__spec__) (__spec__[4]) 114 | #define QRspec_rsEccCodes2(__spec__) (__spec__[2]) 115 | 116 | #define QRspec_rsDataLength(__spec__) \ 117 | ((QRspec_rsBlockNum1(__spec__) * QRspec_rsDataCodes1(__spec__)) + \ 118 | (QRspec_rsBlockNum2(__spec__) * QRspec_rsDataCodes2(__spec__))) 119 | #define QRspec_rsEccLength(__spec__) \ 120 | (QRspec_rsBlockNum(__spec__) * QRspec_rsEccCodes1(__spec__)) 121 | 122 | /****************************************************************************** 123 | * Version information pattern 124 | *****************************************************************************/ 125 | 126 | /** 127 | * Return BCH encoded version information pattern that is used for the symbol 128 | * of version 7 or greater. Use lower 18 bits. 129 | * @param version 130 | * @return BCH encoded version information pattern 131 | */ 132 | extern unsigned int QRspec_getVersionPattern(int version); 133 | 134 | /****************************************************************************** 135 | * Format information 136 | *****************************************************************************/ 137 | 138 | /** 139 | * Return BCH encoded format information pattern. 140 | * @param mask 141 | * @param level 142 | * @return BCH encoded format information pattern 143 | */ 144 | extern unsigned int QRspec_getFormatInfo(int mask, QRecLevel level); 145 | 146 | /****************************************************************************** 147 | * Frame 148 | *****************************************************************************/ 149 | 150 | /** 151 | * Return a copy of initialized frame. 152 | * When the same version is requested twice or more, a copy of cached frame 153 | * is returned. 154 | * @param version 155 | * @return Array of unsigned char. You can free it by free(). 156 | */ 157 | extern unsigned char *QRspec_newFrame(int version); 158 | 159 | /** 160 | * Clear the frame cache. Typically for debug. 161 | */ 162 | extern void QRspec_clearCache(void); 163 | 164 | /****************************************************************************** 165 | * Mode indicator 166 | *****************************************************************************/ 167 | 168 | /** 169 | * Mode indicator. See Table 2 of JIS X0510:2004, pp.16. 170 | */ 171 | #define QRSPEC_MODEID_ECI 7 172 | #define QRSPEC_MODEID_NUM 1 173 | #define QRSPEC_MODEID_AN 2 174 | #define QRSPEC_MODEID_8 4 175 | #define QRSPEC_MODEID_KANJI 8 176 | #define QRSPEC_MODEID_FNC1FIRST 5 177 | #define QRSPEC_MODEID_FNC1SECOND 9 178 | #define QRSPEC_MODEID_STRUCTURE 3 179 | #define QRSPEC_MODEID_TERMINATOR 0 180 | 181 | #endif /* __QRSPEC_H__ */ 182 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/rscode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Reed solomon encoder. This code is taken from Phil Karn's libfec then 5 | * editted and packed into a pair of .c and .h files. 6 | * 7 | * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q 8 | * (libfec is released under the GNU Lesser General Public License.) 9 | * 10 | * Copyright (C) 2006-2011 Kentaro Fukuchi 11 | * 12 | * This library is free software; you can redistribute it and/or 13 | * modify it under the terms of the GNU Lesser General Public 14 | * License as published by the Free Software Foundation; either 15 | * version 2.1 of the License, or any later version. 16 | * 17 | * This library is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | * Lesser General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU Lesser General Public 23 | * License along with this library; if not, write to the Free Software 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 25 | */ 26 | 27 | #ifndef __RSCODE_H__ 28 | #define __RSCODE_H__ 29 | 30 | /* 31 | * General purpose RS codec, 8-bit symbols. 32 | */ 33 | 34 | typedef struct _RS RS; 35 | 36 | extern RS *init_rs(int symsize, int gfpoly, int fcr, int prim, int nroots, int pad); 37 | extern void encode_rs_char(RS *rs, const unsigned char *data, unsigned char *parity); 38 | extern void free_rs_char(RS *rs); 39 | extern void free_rs_cache(void); 40 | 41 | #endif /* __RSCODE_H__ */ 42 | -------------------------------------------------------------------------------- /qrencode/qrencode/3rd/split.h: -------------------------------------------------------------------------------- 1 | /* 2 | * qrencode - QR Code encoder 3 | * 4 | * Input data splitter. 5 | * Copyright (C) 2006-2011 Kentaro Fukuchi 6 | * 7 | * The following data / specifications are taken from 8 | * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) 9 | * or 10 | * "Automatic identification and data capture techniques -- 11 | * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) 12 | * 13 | * This library is free software; you can redistribute it and/or 14 | * modify it under the terms of the GNU Lesser General Public 15 | * License as published by the Free Software Foundation; either 16 | * version 2.1 of the License, or any later version. 17 | * 18 | * This library is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 | * Lesser General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU Lesser General Public 24 | * License along with this library; if not, write to the Free Software 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 26 | */ 27 | 28 | #ifndef __SPLIT_H__ 29 | #define __SPLIT_H__ 30 | 31 | #include "qrencode.h" 32 | 33 | /** 34 | * Split the input string (null terminated) into QRinput. 35 | * @param string input string 36 | * @param hint give QR_MODE_KANJI if the input string contains Kanji character encoded in Shift-JIS. If not, give QR_MODE_8. 37 | * @param casesensitive 0 for case-insensitive encoding (all alphabet characters are replaced to UPPER-CASE CHARACTERS. 38 | * @retval 0 success. 39 | * @retval -1 an error occurred. errno is set to indicate the error. See 40 | * Exceptions for the details. 41 | * @throw EINVAL invalid input object. 42 | * @throw ENOMEM unable to allocate memory for input objects. 43 | */ 44 | extern int Split_splitStringToQRinput(const char *string, QRinput *input, 45 | QRencodeMode hint, int casesensitive); 46 | 47 | #endif /* __SPLIT_H__ */ 48 | -------------------------------------------------------------------------------- /qtquickqrencode.pro: -------------------------------------------------------------------------------- 1 | TEMPLATE = subdirs 2 | 3 | SUBDIRS += \ 4 | widgets \ 5 | example/widgetstest 6 | # Taken from Qt Creator project files 7 | defineTest(minQtVersion) { 8 | maj = $$1 9 | min = $$2 10 | patch = $$3 11 | isEqual(QT_MAJOR_VERSION, $$maj) { 12 | isEqual(QT_MINOR_VERSION, $$min) { 13 | isEqual(QT_PATCH_VERSION, $$patch) { 14 | return(true) 15 | } 16 | greaterThan(QT_PATCH_VERSION, $$patch) { 17 | return(true) 18 | } 19 | } 20 | greaterThan(QT_MINOR_VERSION, $$min) { 21 | return(true) 22 | } 23 | } 24 | greaterThan(QT_MAJOR_VERSION, $$maj) { 25 | return(true) 26 | } 27 | return(false) 28 | } 29 | #if qt version greaterthan 5.4.0 30 | message(------QT_VERSION--------$$QT_VERSION) 31 | minQtVersion(5,4,0):{ 32 | SUBDIRS += qml2\ 33 | example/qml2test 34 | message(------greaterThan--------) 35 | } 36 | #if qt version lessthan 5.4.0 37 | !minQtVersion(5,4,0):{ 38 | message(------lessthan--------) 39 | SUBDIRS += qml1\ 40 | example/qml1test 41 | } 42 | CONFIG += ordered 43 | -------------------------------------------------------------------------------- /widgets/dduiqrwidgets.h: -------------------------------------------------------------------------------- 1 | #ifndef DDUIQRWIDGETS_H 2 | #define DDUIQRWIDGETS_H 3 | 4 | #include "widgets_global.h" 5 | #include 6 | #include "qrencode/3rd/qrencode.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | class WIDGETSSHARED_EXPORT DDuiQRWidgets : 14 | public QWidget 15 | { 16 | Q_OBJECT 17 | Q_DISABLE_COPY(DDuiQRWidgets) 18 | Q_ENUMS(QR_MODE) 19 | Q_ENUMS(QR_LEVEL) 20 | Q_PROPERTY(QString qrData READ qrDDData WRITE setQrData NOTIFY qrDataChanged) 21 | Q_PROPERTY(QString qrLogo READ qrDDLogo WRITE setQrLogo NOTIFY qrLogoChanged) 22 | Q_PROPERTY(QSize qrSize READ qrDDSize WRITE setQrSize NOTIFY qrSizeChanged) 23 | Q_PROPERTY(QR_MODE qrMode READ qrDDMode WRITE setQrMode NOTIFY qrModeChanged) 24 | Q_PROPERTY(QR_LEVEL qrLevel READ qrDDLevel WRITE setQrLevel NOTIFY qrLevelChanged) 25 | Q_PROPERTY(bool qrCasesen READ qrDDCasesen WRITE setQrCasesen NOTIFY qrCasesenChanged) 26 | Q_PROPERTY(int qrMargin READ qrDDMargin WRITE setQrMargin NOTIFY qrMarginChanged) 27 | Q_PROPERTY(qreal qrPercent READ qrDDPercent WRITE setQrPercent NOTIFY qrPercentChanged) 28 | Q_PROPERTY(QColor qrForeground READ qrDDForeground WRITE setQrForeground NOTIFY qrForegroundChanged) 29 | Q_PROPERTY(QColor qrBackground READ qrDDBackground WRITE setQrBackground NOTIFY qrBackgroundChanged) 30 | public: 31 | DDuiQRWidgets(QWidget *parent = 0); 32 | ~DDuiQRWidgets(); 33 | 34 | /// 35 | /// \brief The QR_MODE enum 36 | /// 设置二维码的编码模式 37 | enum QR_MODE { 38 | MODE_NUL = QR_MODE_NUL, 39 | MODE_NUM = QR_MODE_NUM, 40 | MODE_AN = QR_MODE_AN, 41 | MODE_8 = QR_MODE_8, 42 | MODE_KANJI = QR_MODE_KANJI, 43 | MODE_STRUCTURE = QR_MODE_STRUCTURE, 44 | MODE_ECI = QR_MODE_ECI, 45 | MODE_FNC1FIRST = QR_MODE_FNC1FIRST, 46 | MODE_FNC1SECOND = QR_MODE_FNC1SECOND 47 | }; 48 | /// 49 | /// \brief The QR_LEVEL enum 50 | /// 设置二维码编码的识别质量的级别 51 | /// 52 | enum QR_LEVEL { 53 | LEVEL_L = QR_ECLEVEL_L, 54 | LEVEL_M = QR_ECLEVEL_M, 55 | LEVEL_Q = QR_ECLEVEL_Q, 56 | LEVEL_H = QR_ECLEVEL_H 57 | }; 58 | 59 | QString qrDDData(); 60 | QString qrDDLogo(); 61 | QSize qrDDSize(); 62 | QR_MODE qrDDMode(); 63 | QR_LEVEL qrDDLevel(); 64 | bool qrDDCasesen(); 65 | int qrDDMargin(); 66 | qreal qrDDPercent(); 67 | QColor qrDDForeground(); 68 | QColor qrDDBackground(); 69 | 70 | //设置需要编码的数据 71 | Q_INVOKABLE void setQrData(const QString& data); 72 | // 设置二维码的logo 73 | Q_INVOKABLE void setQrLogo(const QString& logo); 74 | Q_INVOKABLE void setQrSize(QSize mode); 75 | Q_INVOKABLE void setQrMode(QR_MODE mode); 76 | Q_INVOKABLE void setQrLevel(QR_LEVEL level); 77 | Q_INVOKABLE void setQrCasesen(bool casesen); 78 | Q_INVOKABLE void setQrMargin(int margin); 79 | Q_INVOKABLE void setQrPercent(qreal percent); 80 | Q_INVOKABLE void setQrForeground(QColor forgb); 81 | Q_INVOKABLE void setQrBackground(QColor backgb); 82 | Q_INVOKABLE void setQrSaveFile(const QString& filepath); 83 | 84 | signals: 85 | void qrDataChanged(const QString& qrdata); 86 | void qrLogoChanged(const QString& qrlogo); 87 | void qrSizeChanged(const QSize& qrsize); 88 | void qrModeChanged(QR_MODE qrmodel); 89 | void qrLevelChanged(QR_LEVEL qrlevel); 90 | void qrCasesenChanged(bool qrcasesen); 91 | void qrMarginChanged(int qrmargin); 92 | void qrPercentChanged(qreal qrpercent); 93 | void qrForegroundChanged(const QColor& qrfg); 94 | void qrBackgroundChanged(const QColor& qrbg); 95 | void qrSaveFileChanged(const QString& qrfilepath); 96 | 97 | private: 98 | QString qrData; 99 | QString qrLogo; 100 | QSize qrSize; 101 | QR_MODE qrMode; 102 | QR_LEVEL qrLevel; 103 | bool qrCasesen; 104 | int qrMargin; 105 | qreal qrPercent; 106 | QColor qrForeground; 107 | QColor qrBackground; 108 | QString qrFilePath; 109 | QString icon; 110 | QByteArray text; 111 | void saveCurViewToFile(); 112 | void saveItemToFile(); 113 | private slots: 114 | void grabChanged(); 115 | protected: 116 | void paintEvent(QPaintEvent *e); 117 | void resizeEvent(QResizeEvent *e); 118 | }; 119 | 120 | #endif // DDUIQRWIDGETS_H 121 | -------------------------------------------------------------------------------- /widgets/widgets.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2016-05-06T13:55:04 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += widgets 8 | 9 | TARGET = dduiqrwidgets 10 | TEMPLATE = lib 11 | 12 | DEFINES += WIDGETS_LIBRARY 13 | 14 | DESTDIR = $$PWD/../lib/ 15 | MOC_DIR = $$PWD/../.moc 16 | OBJECTS_DIR = $$PWD/../.obj 17 | 18 | INCLUDEPATH += $$PWD 19 | 20 | SOURCES += $$PWD/dduiqrwidgets.cpp 21 | 22 | HEADERS += $$PWD/dduiqrwidgets.h\ 23 | $$PWD/widgets_global.h 24 | 25 | CONFIG += DD_USE_C 26 | 27 | DD_USE_C:{ 28 | include($$PWD/../qrencode/qrencode.pri) 29 | } 30 | CHM.path = $$PWD/../include 31 | CHM.files +=$$PWD/*.h 32 | CHM.files +=$$PWD/../qrencode/ 33 | INSTALLS += CHM 34 | 35 | 36 | -------------------------------------------------------------------------------- /widgets/widgets_global.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGETS_GLOBAL_H 2 | #define WIDGETS_GLOBAL_H 3 | 4 | #include 5 | 6 | #if defined(WIDGETS_LIBRARY) 7 | # define WIDGETSSHARED_EXPORT Q_DECL_EXPORT 8 | #else 9 | # define WIDGETSSHARED_EXPORT Q_DECL_IMPORT 10 | #endif 11 | 12 | #endif // WIDGETS_GLOBAL_H 13 | --------------------------------------------------------------------------------