Skip to content
This repository
Browse code

No commit message

  • Loading branch information...
commit 879e2018a937841b25b2cfc7e1f83de2a8719608 1 parent fd5f109
authored November 07, 2006
6  qrencode.c
@@ -549,7 +549,7 @@ static int QRenc_estimateVersion(QRenc_DataStream *stream)
549 549
 	do {
550 550
 		prev = new;
551 551
 		bits = QRenc_estimateBitStreamSize(stream, prev);
552  
-		new = QRspec_getMinimumVersion((bits + 7) / 8);
  552
+		new = QRspec_getMinimumVersion((bits + 7) / 8, stream->level);
553 553
 		if (new == -1) {
554 554
 			return -1;
555 555
 		}
@@ -650,7 +650,7 @@ static int QRenc_convertData(QRenc_DataStream *stream)
650 650
 
651 651
 	for(;;) {
652 652
 		bits = QRenc_createBitStream(stream);
653  
-		ver = QRspec_getMinimumVersion((bits + 7) / 8);
  653
+		ver = QRspec_getMinimumVersion((bits + 7) / 8, stream->level);
654 654
 		if(ver < 0) {
655 655
 			return -1;
656 656
 		} else if(ver > QRenc_getVersion(stream)) {
@@ -677,7 +677,7 @@ static BitStream *QRenc_createPaddingBit(QRenc_DataStream *stream)
677 677
 	if(stream->version <= 0)
678 678
 		return NULL;
679 679
 
680  
-	maxwords = qrspecCapacity[stream->version].words;
  680
+	maxwords = QRspec_getMaximumCodeLength(stream->version, stream->level);
681 681
 	maxbits = maxwords * 8;
682 682
 	
683 683
 	list = stream->head;
2  qrencode.h
@@ -53,7 +53,7 @@ typedef struct _QRenc_DataStream QRenc_DataStream;
53 53
  * Level of error correction.
54 54
  */
55 55
 typedef enum {
56  
-	QR_EC_LEVEL_L,
  56
+	QR_EC_LEVEL_L = 0,
57 57
 	QR_EC_LEVEL_M,
58 58
 	QR_EC_LEVEL_Q,
59 59
 	QR_EC_LEVEL_H
98  qrspec.c
@@ -39,60 +39,62 @@
39 39
  *****************************************************************************/
40 40
 
41 41
 QRspec_Capacity qrspecCapacity[QRSPEC_VERSION_MAX + 1] = {
42  
-	{  0,    0,    0,    0,    0,    0},
43  
-	{ 21,   26,    7,   10,   13,   17}, // 1
44  
-	{ 25,   44,   10,   16,   22,   28},
45  
-	{ 29,   70,   15,   26,   36,   44},
46  
-	{ 33,  100,   20,   36,   52,   64},
47  
-	{ 37,  134,   26,   48,   72,   88}, // 5
48  
-	{ 41,  172,   36,   64,   96,  112},
49  
-	{ 45,  196,   40,   72,  108,  130},
50  
-	{ 49,  242,   48,   88,  132,  156},
51  
-	{ 53,  292,   60,  110,  160,  192},
52  
-	{ 57,  346,   72,  130,  192,  224}, //10
53  
-	{ 61,  404,   80,  150,  224,  264},
54  
-	{ 65,  466,   96,  176,  260,  308},
55  
-	{ 69,  532,  104,  198,  288,  352},
56  
-	{ 73,  581,  120,  216,  320,  384},
57  
-	{ 77,  655,  132,  240,  360,  432}, //15
58  
-	{ 81,  733,  144,  280,  408,  480},
59  
-	{ 85,  815,  168,  308,  448,  532},
60  
-	{ 89,  901,  180,  338,  504,  588},
61  
-	{ 93,  991,  196,  364,  546,  650},
62  
-	{ 97, 1085,  224,  416,  600,  700}, //20
63  
-	{101, 1156,  224,  442,  644,  750},
64  
-	{105, 1258,  252,  476,  690,  816},
65  
-	{109, 1364,  280,  504,  750,  900},
66  
-	{113, 1474,  300,  560,  810,  960},
67  
-	{117, 1588,  312,  588,  870, 1050}, //25
68  
-	{121, 1706,  336,  644,  952, 1110},
69  
-	{125, 1828,  360,  700, 1020, 1200},
70  
-	{129, 1921,  390,  728, 1050, 1260},
71  
-	{133, 2051,  420,  784, 1140, 1350},
72  
-	{137, 2185,  450,  812, 1200, 1440}, //30
73  
-	{141, 2323,  480,  868, 1290, 1530},
74  
-	{145, 2465,  510,  924, 1350, 1620},
75  
-	{149, 2611,  540,  980, 1440, 1710},
76  
-	{153, 2761,  570, 1036, 1530, 1800},
77  
-	{157, 2876,  570, 1064, 1590, 1890}, //35
78  
-	{161, 3034,  600, 1120, 1680, 1980},
79  
-	{165, 3196,  630, 1204, 1770, 2100},
80  
-	{169, 3362,  660, 1260, 1860, 2220},
81  
-	{173, 3532,  720, 1316, 1950, 2310},
82  
-	{177, 3706,  750, 1372, 2040, 2430} //40
  42
+	{  0,    0, {   0,    0,    0,    0}},
  43
+	{ 21,   26, {   7,   10,   13,   17}}, // 1
  44
+	{ 25,   44, {  10,   16,   22,   28}},
  45
+	{ 29,   70, {  15,   26,   36,   44}},
  46
+	{ 33,  100, {  20,   36,   52,   64}},
  47
+	{ 37,  134, {  26,   48,   72,   88}}, // 5
  48
+	{ 41,  172, {  36,   64,   96,  112}},
  49
+	{ 45,  196, {  40,   72,  108,  130}},
  50
+	{ 49,  242, {  48,   88,  132,  156}},
  51
+	{ 53,  292, {  60,  110,  160,  192}},
  52
+	{ 57,  346, {  72,  130,  192,  224}}, //10
  53
+	{ 61,  404, {  80,  150,  224,  264}},
  54
+	{ 65,  466, {  96,  176,  260,  308}},
  55
+	{ 69,  532, { 104,  198,  288,  352}},
  56
+	{ 73,  581, { 120,  216,  320,  384}},
  57
+	{ 77,  655, { 132,  240,  360,  432}}, //15
  58
+	{ 81,  733, { 144,  280,  408,  480}},
  59
+	{ 85,  815, { 168,  308,  448,  532}},
  60
+	{ 89,  901, { 180,  338,  504,  588}},
  61
+	{ 93,  991, { 196,  364,  546,  650}},
  62
+	{ 97, 1085, { 224,  416,  600,  700}}, //20
  63
+	{101, 1156, { 224,  442,  644,  750}},
  64
+	{105, 1258, { 252,  476,  690,  816}},
  65
+	{109, 1364, { 280,  504,  750,  900}},
  66
+	{113, 1474, { 300,  560,  810,  960}},
  67
+	{117, 1588, { 312,  588,  870, 1050}}, //25
  68
+	{121, 1706, { 336,  644,  952, 1110}},
  69
+	{125, 1828, { 360,  700, 1020, 1200}},
  70
+	{129, 1921, { 390,  728, 1050, 1260}},
  71
+	{133, 2051, { 420,  784, 1140, 1350}},
  72
+	{137, 2185, { 450,  812, 1200, 1440}}, //30
  73
+	{141, 2323, { 480,  868, 1290, 1530}},
  74
+	{145, 2465, { 510,  924, 1350, 1620}},
  75
+	{149, 2611, { 540,  980, 1440, 1710}},
  76
+	{153, 2761, { 570, 1036, 1530, 1800}},
  77
+	{157, 2876, { 570, 1064, 1590, 1890}}, //35
  78
+	{161, 3034, { 600, 1120, 1680, 1980}},
  79
+	{165, 3196, { 630, 1204, 1770, 2100}},
  80
+	{169, 3362, { 660, 1260, 1860, 2220}},
  81
+	{173, 3532, { 720, 1316, 1950, 2310}},
  82
+	{177, 3706, { 750, 1372, 2040, 2430}} //40
83 83
 };
84 84
 
85  
-/**
86  
- * Return a version number that satisfies the input code length.
87  
- * @param size input code length (byte)
88  
- * @return version number
89  
- */
90  
-int QRspec_getMinimumVersion(int size)
  85
+int QRspec_getMaximumCodeLength(int version, QRenc_ErrorCorrectionLevel level)
  86
+{
  87
+	return qrspecCapacity[version].words - qrspecCapacity[version].ec[level];
  88
+}
  89
+
  90
+int QRspec_getMinimumVersion(int size, QRenc_ErrorCorrectionLevel level)
91 91
 {
92 92
 	int i;
  93
+	int words;
93 94
 
94 95
 	for(i=1; i<= QRSPEC_VERSION_MAX; i++) {
95  
-		if(qrspecCapacity[i].words >= size) return i;
  96
+		words  = qrspecCapacity[i].words; - qrspecCapacity[i].ec[level];
  97
+		if(words >= size) return i;
96 98
 	}
97 99
 
98 100
 	return -1;
15  qrspec.h
@@ -36,20 +36,25 @@
36 36
 typedef struct {
37 37
 	int length; //< Edge length of the symbol
38 38
 	int words;   //< Data capacity (bytes)
39  
-	int rsL;
40  
-	int rsM;
41  
-	int rsH;
42  
-	int rsQ;
  39
+	int ec[4];
43 40
 } QRspec_Capacity;
44 41
 
45 42
 extern QRspec_Capacity qrspecCapacity[];
46 43
 
47 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 QRspec_getMaximumCodeLength(int version, QRenc_ErrorCorrectionLevel level);
  51
+
  52
+/**
48 53
  * Return a version number that satisfies the input code length.
49 54
  * @param size input code length (byte)
50 55
  * @return version number
51 56
  */
52  
-extern int QRspec_getMinimumVersion(int size);
  57
+extern int QRspec_getMinimumVersion(int size, QRenc_ErrorCorrectionLevel level);
53 58
 
54 59
 /******************************************************************************
55 60
  * Length indicator
7  tests/test_datastream.c
@@ -101,8 +101,9 @@ void test_encodeNumericPadded(void)
101 101
 	QRenc_appendData(stream, QR_MODE_NUM, 8, (unsigned char *)num);
102 102
 	bstream = QRenc_getBitStream(stream);
103 103
 	flag = strncmp(correct, bstream->data, 48);
104  
-	if(strlen(bstream->data) != 208)
105  
-		flag++;
  104
+	printf("%s\n", bstream->data);
  105
+	if(strlen(bstream->data) != 19 * 8)
  106
+		flag |= 0x80;
106 107
 	testEnd(flag);
107 108
 
108 109
 	QRenc_freeData(stream);
@@ -159,7 +160,7 @@ int main(int argc, char **argv)
159 160
 	test_encodeNumeric();
160 161
 	test_encodeNumeric2();
161 162
 	test_encode8();
162  
-	test_encode82();
  163
+//	test_encode82();
163 164
 	test_encodeAn();
164 165
 	test_encodeAn2();
165 166
 	test_encodeKanji();

0 notes on commit 879e201

Please sign in to comment.
Something went wrong with that request. Please try again.