Permalink
Browse files

No commit message

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

0 comments on commit 879e201

Please sign in to comment.