/*
* qrencode - QR Code encoder
*
* Input data chunk class
* Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
//#include "config.h"
#include "qrencode.h"
#include "qrspec.h"
#include "bitstream.h"
#include "qrinput.h"
/******************************************************************************
* Entry of input data
*****************************************************************************/
static QRinput_List *QRinput_List_newEntry(QRencodeMode mode, int size, const unsigned char *data)
{
QRinput_List *entry;
if(QRinput_check(mode, size, data)) {
errno = EINVAL;
return NULL;
}
entry = (QRinput_List *)malloc(sizeof(QRinput_List));
if(entry == NULL) return NULL;
entry->mode = mode;
entry->size = size;
entry->data = (unsigned char *)malloc(size);
if(entry->data == NULL) {
free(entry);
return NULL;
}
memcpy(entry->data, data, size);
entry->bstream = NULL;
entry->next = NULL;
return entry;
}
static void QRinput_List_freeEntry(QRinput_List *entry)
{
if(entry != NULL) {
free(entry->data);
BitStream_free(entry->bstream);
free(entry);
}
}
static QRinput_List *QRinput_List_dup(QRinput_List *entry)
{
QRinput_List *n;
n = (QRinput_List *)malloc(sizeof(QRinput_List));
if(n == NULL) return NULL;
n->mode = entry->mode;
n->size = entry->size;
n->data = (unsigned char *)malloc(n->size);
if(n->data == NULL) {
free(n);
return NULL;
}
memcpy(n->data, entry->data, entry->size);
n->bstream = NULL;
n->next = NULL;
return n;
}
/******************************************************************************
* Input Data
*****************************************************************************/
QRinput *QRinput_new(void)
{
return QRinput_new2(0, QR_ECLEVEL_L);
}
QRinput *QRinput_new2(int version, QRecLevel level)
{
QRinput *input;
if(version < 0 || version > QRSPEC_VERSION_MAX || level > QR_ECLEVEL_H) {
errno = EINVAL;
return NULL;
}
input = (QRinput *)malloc(sizeof(QRinput));
if(input == NULL) return NULL;
input->head = NULL;
input->tail = NULL;
input->version = version;
input->level = level;
return input;
}
int QRinput_getVersion(QRinput *input)
{
return input->version;
}
int QRinput_setVersion(QRinput *input, int version)
{
if(version < 0 || version > QRSPEC_VERSION_MAX) {
errno = EINVAL;
return -1;
}
input->version = version;
return 0;
}
QRecLevel QRinput_getErrorCorrectionLevel(QRinput *input)
{
return input->level;
}
int QRinput_setErrorCorrectionLevel(QRinput *input, QRecLevel level)
{
if(level > QR_ECLEVEL_H) {
errno = EINVAL;
return -1;
}
input->level = level;
return 0;
}
static void QRinput_appendEntry(QRinput *input, QRinput_List *entry)
{
if(input->tail == NULL) {
input->head = entry;
input->tail = entry;
} else {
input->tail->next = entry;
input->tail = entry;
}
entry->next = NULL;
}
int QRinput_append(QRinput *input, QRencodeMode mode, int size, const unsigned char *data)
{
QRinput_List *entry;
entry = QRinput_List_newEntry(mode, size, data);
if(entry == NULL) {
return -1;
}
QRinput_appendEntry(input, entry);
return 0;
}
/**
* Insert a structured-append header to the head of the input data.
* @param input input data.
* @param size number of structured symbols.
* @param index index number of the symbol. (1 <= index <= size)
* @param parity parity among input data. (NOTE: each symbol of a set of structured symbols has the same parity data)
* @retval 0 success.
* @retval -1 error occurred and errno is set to indeicate the error. See Execptions for the details.
* @throw EINVAL invalid parameter.
* @throw ENOMEM unable to allocate memory.
*/
//__STATIC
static int QRinput_insertStructuredAppendHeader(QRinput *input, int size, int index, unsigned char parity)
{
QRinput_List *entry;
unsigned char buf[3];
if(size > MAX_STRUCTURED_SYMBOLS) {
errno = EINVAL;
return -1;
}
if(index <= 0 || index > MAX_STRUCTURED_SYMBOLS) {
errno = EINVAL;
return -1;
}
buf[0] = (unsigned char)size;
buf[1] = (unsigned char)index;
buf[2] = parity;
entry = QRinput_List_newEntry(QR_MODE_STRUCTURE, 3, buf);
if(entry == NULL) {
return -1;
}
entry->next = input->head;
input->head = entry;
return 0;
}
void QRinput_free(QRinput *input)
{
QRinput_List *list, *next;
if(input != NULL) {
list = input->head;
while(list != NULL) {
next = list->next;
QRinput_List_freeEntry(list);
list = next;
}
free(input);
}
}
static unsigned char QRinput_calcParity(QRinput *input)
{
unsigned char parity = 0;
QRinput_List *list;
int i;
list = input->head;
while(list != NULL) {
if(list->mode != QR_MODE_STRUCTURE) {
for(i=list->size-1; i>=0; i--) {
parity ^= list->data[i];
}
}
list = list->next;
}
return parity;
}
QRinput *QRinput_dup(QRinput *input)
{
QRinput *n;
QRinput_List *list, *e;
n = QRinput_new2(input->version, input->level);
if(n == NULL) return NULL;
list = input->head;
while(list != NULL) {
e = QRinput_List_dup(list);
if(e == NULL) {
QRinput_free(n);
return NULL;
}
QRinput_appendEntry(n, e);
list = list->next;
}
return n;
}
/******************************************************************************
* Numeric data
*****************************************************************************/
/**
* Check the input data.
* @param size
* @param data
* @return result
*/
static int QRinput_checkModeNum(int size, const char *data)
{
int i;
for(i=0; i<size; i++) {
if(data[i] < '0' || data[i] > '9')
return -1;
}
return 0;
}
/**
* Estimates the length of the encoded bit stream of numeric data.
* @param size
* @return number of bits
*/
int QRinput_estimateBitsModeNum(int size)
{
int w;
int bits;
w = size / 3;
bits = w * 10;
switch(size - w * 3) {
case 1:
bits += 4;
break;
case 2:
bits += 7;
break;
default:
break;
}
return bits;
}
/**
* Convert the number data to a bit stream.
* @param entry
* @retval 0 success
* @retval -1 an error occurred and errno is set to indeicate the error.
* See Execptions for the details.
* @throw ENOMEM unable to allocate memory.
*/
static int QRinput_encodeModeNum(QRinput_List *entry, int version)
{
int words, i, ret;
unsigned int val;
words = entry->size / 3;
entry->bstream = BitStream_new();
if(entry->bstream == NULL) return -1;
val = 0x1;
ret = BitStream_appendNum(entry->bstream, 4, val);
if(ret < 0) goto ABORT;
val = entry->size;
ret = BitStream_appendNum(entry->bstream, QRspec_lengthIndicator(QR_MODE_NUM, version), val);
if(ret < 0) goto ABORT;
for(i=0; i<words; i++) {
val = (entry->data[i*3 ] - '0') * 100;
val += (entry->data[i*3+1] - '0') * 10;
val += (entry->data[i*3+2] - '0');
ret = BitStream_appendNum(entry->bstream, 10, val);
if(ret < 0) goto ABORT;
}
if(entry->size - words * 3 == 1) {
val = entry->data[words*3] - '0';
ret = BitStream_appendNum(entry->bstream, 4, val);
if(ret < 0) goto ABORT;
} else if(entry->size - words * 3 == 2) {
val = (entry->data[words*3 ] - '0') * 10;
val += (entry->data[words*3+1] - '0');
BitStream_appendNum(entry->bstream, 7, val);
if(ret < 0) goto ABORT;
}
ret
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
IOS 二维码扫描 ZBar和Zxing (993个子文件)
0056cfed19bc1f4c26303e4c32fd4038257858 3KB
007099157c2b028ab089728024df39fd161fa0 51B
01250b5d966ec0264206833862792233c5848e 556B
019f57489f30614c2772e6e18963ed9c8c28c0 2KB
01ec1214bec4e5f7dd05b6bbed89840cb622dc 773B
01fd3729b7cd47982932945c0303cabd0047fc 2KB
0211f3c0ababd16570842092bbbb78e3f11afc 545B
023ea6fe0c570cf0f60b420fa5bfcaed36f52a 661B
02ac9d1765116dab1434cb73273181cb3d0456 268B
02adbb447dd6437257d76a92dcbb78fcc50865 658B
02d7da33c92c2d9e834257f2255b2d1e3160f7 1KB
0321bb4751f710ea265357c457be28cd18130f 1KB
03739e9af524b15b51b733e6fd960ef41d2b72 1KB
047410129fcd63d210501097826b8b9838c512 2KB
04f3c17b7291fe61da96d39bd940f08653b520 5KB
053f815ed7ad9f191645ac21d25cbfcf46ab4f 1KB
0557980b69869914f3c2d66c7292be51968e83 731B
05ba21de3392fe2db46edbd47f1f0919bb285f 41KB
0681d0deeaa2cfbeffa620ea31a3cc279fd0da 291B
068f8633a16bb088c90e9b96903c0d9316c276 932B
072f7dcb0921127776256bf4dc8f51fa145430 3KB
073af65274d3286a4c84d67fbd5aa287464962 563B
07899f9e4b64f4186a41c7c7e84955a8175698 686B
07a2667679fbd03f4d0d459318857c0fbd7688 3KB
07e7c44478cd30a1e297395de2f25c8a7bb52a 18KB
080324303ecc98eb02cf72305ce87466760e2e 155B
08c0ed2b3c2f6b341c1db94b304b8be0894ba4 791B
098fd072fc6ba265f38685ba135cb9cf840229 3KB
0a643d50c8cc21eb418b0ff20f86c4b2703a6a 21KB
0a77cff63d3410c38ed8e5599e975d574bd03a 582B
0b961ea9c54acd153cbe9873a415d0d09d61d0 183B
0bf063bff4f60b078fa9fd5a09922d20db0984 1KB
0c66738ef9513022052bba1f6907d4a008b2c0 5KB
0d3a8f6aea5083cd9971c92ec7020f1f622192 2KB
0d79cade8704dfec30a23181dfb07d4404a2b4 576B
0dc8a28b95b48854b801d4db2e2576afcb5859 3KB
0e5ed2e015cb0eac619f4a3fc7cab8aac0c309 1KB
0ebee6a113a11c3bdf862f271714c53f4e39dc 138B
0f2631c82734a304acda0db186d16d6a342cee 482B
0f2ecf38cef366fe0b0f51dd5e4f6cd3599d8f 270B
11afb8d99d4e34780bc2a2bf42ee6d50abf9a5 160B
11c1094fb111ff49192b820775e55f0af35c67 2KB
11cdddd9813be40ed3fd03d86ccdc3cf849199 1007B
12d7294f16afdb13b5a42022cc08098b9808c0 743B
132540c77b995138b9eb1556aa3b2233ea9fe5 654B
14530f0138001da42188daf99d75a192089458 684B
15ac5c8dc8a3d40f22ee55d2ef5573e490c37f 4KB
15b5d7c529446489c88ef4b4f35b7c0ddee26e 1KB
16ab2936b032c111030353a259bd2846b25ce2 2KB
17041a0f88bac03227123e1e32e8d1c222cf7f 628B
1745c41f7d0d1ada000a19980d04a9d89716d7 737B
18bb702eb0c3a707db1ef20533d43cdc7b8e26 298B
18e98e6fd354bd2d980a599caf478bd60487d6 1KB
198343f48249700b6cdcc79e5f209d1bc72fdc 1KB
19acfe336b55f6067b56e38947b784787ed95a 494B
1a405ae0e22345889c34b387519eaacfb9f090 1KB
1b0479331e875c0f496252600bc13c27e544cb 865B
1b3d4126b8e12f207bac99107f89bf9f59f60e 492B
1bba8adb7e9605d393ae55cfed80d52999b0a9 673B
1dc4a411ed3f613b7ac0e72eb0d5a736ef6dea 506B
1ddccedce7273865470b2a66c80ca2fbafb45b 598B
1e17bd80ad10addf70a5feda5cea426cff99b1 658B
1eb7ab40282f23828218416cd290f958eb780f 679B
1f014af4346a3ea1bd4bd8d554ed6507a7b77a 1KB
1f7fa802effe48601631a5dd7bba5e71008570 676B
1fce6d7b75c904a9f6f458c67043901e5c7055 777B
1fdce52af2905da54f7bce9a2f73ebef50e0df 840B
20c0d96b5be1216c0dbe27d6308fc7d0d0a82f 1KB
20c3996c597ddd0e935e1fd28fc25c7a07afbb 3KB
213737118b416bf1b7adf22f5bf5117285d7bc 1KB
2197127b7e857ab6f4a98d573374464cffd9c0 2KB
2205bcb1f92131437dfa2330dd391865ffe8f2 803B
22160da86766793cb1cb510cd184f78aa0666c 2KB
227ab6272fae670e13d86a80aa2a73f255b1aa 633B
22ee8798a9415f9a64b6325bd33f0af78830f2 2KB
23aa1e7b25cb3c1573c826c5390979b43558f9 4KB
23fd4b8a1b04ffef861dc4cb2c15380e583e88 2KB
25b539bbc1a0d84383de17fcba58e4e0dffaee 3KB
25ec19f3a9ba6af611b77d7769869b462bea4f 2KB
2608a5972642c7b7a13b987f21e2502a5af3ea 3KB
282255b76c4069654f17cbce417eb129797b22 735B
28753c89f0dca9d75e5fccd47664617b98e7e3 5KB
2916d4274d5f9eaef4e6184a1234465686c085 152B
29356e2caa5d7ed149355e36ea651096cc3703 28KB
295a3397b777c8ff258951ed64bbbae2c6c9bc 58B
2a77343e4e9e68a8c56e414c23d6e32e658da7 1KB
2af461710b20e146798efa63d729dd4ecc25d1 3KB
2afa2da5f1beaf911928d4dc752341e1dbbc89 523B
2b33ddc51799549dc7503bd11804b06d6a502b 614B
2bf213e42def8690f5ea5f792e90151f3ae7c1 2KB
2c0553a99b2909818aadd118cbc213de09fe91 49B
2c2a2d78e504751dc3e4b09a213cded7eef07b 941B
2c434d30da7ca34ee520b61dc16e2a559202ba 311B
2c99d96a4fc06a3c4728a519302c78eb090440 957B
2cb6e3560de0b8ba6cf6570c1e41e9d8d9b506 53KB
2df3bd6ed5653a5d5a165deabf2e7bf6658a25 5KB
2f6f23fcfdcdef0e939e6213ecb3cbaed4d802 3KB
2f91787e1ae7d53cd9acbc311ff3b1a8b40ff0 628B
3042332236026cb090691289cfc2a8ec78d08f 560B
3088b19edb6e135d3f8d0da43e38ad7fa0ae51 690B
共 993 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
麦子红
- 粉丝: 1
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页