Permalink
Browse files

No commit message

  • Loading branch information...
fukuchi
fukuchi committed Nov 11, 2006
1 parent 47f4315 commit 63e799f745f1e03d0715a18c756316cdf03c8f96
Showing with 69 additions and 2 deletions.
  1. +37 −0 qrspec.c
  2. +13 −1 qrspec.h
  3. +19 −1 tests/test_qrspec.c
View
@@ -365,6 +365,39 @@ unsigned int QRspec_getVersionPattern(int version)
return versionPattern[version -7];
}
+/******************************************************************************
+ * Format information
+ *****************************************************************************/
+
+/* See Table 22 (pp.45) and Appendix C (pp. 65) of JIS X0510:2004 */
+static unsigned int levelIndicator[4] = {1, 0, 3, 2};
+
+unsigned int QRspec_getFormatInfo(int mask, QRenc_ErrorCorrectionLevel level)
+{
+ unsigned int data, ecc, b, code;
+ int i, c;
+
+ data = (levelIndicator[level] << 13) | (mask << 10);
+ ecc = data;
+ b = 1 << 14;
+ for(i=0; b != 0; i++) {
+ if(ecc & b) break;
+ b = b >> 1;
+ }
+ c = 4 - i;
+ code = 0x537 << c ; //10100110111
+ b = 1 << (10 + c);
+ for(i=0; i<c; i++) {
+ if(b & ecc) {
+ ecc ^= code;
+ }
+ code = code >> 1;
+ b = b >> 1;
+ }
+
+ return (data | ecc) ^ 0x5412;
+}
+
/******************************************************************************
* Frame
*****************************************************************************/
@@ -539,3 +572,7 @@ unsigned char *QRspec_newFrame(int version)
return frame;
}
+
+void QRspec_fillFormatInfo(unsigned char *frame, int version, int mask)
+{
+}
View
@@ -126,10 +126,22 @@ extern void QRspec_freeAlignment(QRspec_Alignment *al);
* Return BCH encoded version information pattern that is used for the symbol
* of version 7 or greater. Use lower 18 bits.
* @param version
- * @return BCH coded version information pattern
+ * @return BCH encoded version information pattern
*/
extern unsigned int QRspec_getVersionPattern(int version);
+/******************************************************************************
+ * Format information
+ *****************************************************************************/
+
+/**
+ * Return BCH encoded format information pattern.
+ * @param mask
+ * @param level
+ * @return BCH encoded format information pattern
+ */
+extern unsigned int QRspec_getFormatInfo(int mask, QRenc_ErrorCorrectionLevel level);
+
/******************************************************************************
* Frame
*****************************************************************************/
View
@@ -230,14 +230,32 @@ void print_newFrame(void)
free(frame);
}
+void test_format(void)
+{
+ unsigned int format;
+
+ testStart("Format info test (mask 101, LEVEL M)");
+ format = QRspec_getFormatInfo(5, QR_EC_LEVEL_M);
+ testEndExp(format == 0x40ce);
+
+ testStart("Format info test (mask 011, LEVEL H)");
+ format = QRspec_getFormatInfo(3, QR_EC_LEVEL_H);
+ testEndExp(format == 0x19d0);
+
+ testStart("Format info test (mask 000, LEVEL L)");
+ format = QRspec_getFormatInfo(0, QR_EC_LEVEL_L);
+ testEndExp(format == 0x77c4);
+}
+
int main(int argc, char **argv)
{
test_eccTable();
test_eccTable2();
// print_eccTable();
test_alignment1();
test_verpat();
- print_newFrame();
+// print_newFrame();
+ test_format();
report();

0 comments on commit 63e799f

Please sign in to comment.