예제 #1
0
void print_eccTable(void)
{
	int i, j;
	int ecc;
	int data;
	int spec[5];

	for(i=1; i<=QRSPEC_VERSION_MAX; i++) {
		printf("Version %2d\n", i);
		for(j=0; j<4; j++) {
			QRspec_getEccSpec(i, (QRecLevel)j, spec);
			data = QRspec_rsBlockNum1(spec) * QRspec_rsDataCodes1(spec)
			     + QRspec_rsBlockNum2(spec) * QRspec_rsDataCodes2(spec);
			ecc  = QRspec_rsBlockNum1(spec) * QRspec_rsEccCodes1(spec)
			     + QRspec_rsBlockNum2(spec) * QRspec_rsEccCodes2(spec);
			printf("%3d\t", data);
			printf("%3d\t", ecc);
			printf("%2d\t", QRspec_rsBlockNum1(spec));
			printf("(%3d, %3d, %3d)\n",
				   QRspec_rsDataCodes1(spec) + QRspec_rsEccCodes1(spec),
				   QRspec_rsDataCodes1(spec),
				   QRspec_rsEccCodes1(spec));
			if(QRspec_rsBlockNum2(spec) > 0) {
				printf("\t%2d\t", QRspec_rsBlockNum2(spec));
				printf("(%3d, %3d, %3d)\n",
					   QRspec_rsDataCodes2(spec) + QRspec_rsEccCodes2(spec),
					   QRspec_rsDataCodes2(spec),
					   QRspec_rsEccCodes2(spec));
			}
		}
	}
}
예제 #2
0
void test_eccTable2(void)
{
	int i;
	int spec[5];

	const int correct[7][6] = {
		{ 8,  1, 0,  2, 60, 38},
		{ 8,  1, 1,  2, 61, 39},
		{24,  2, 0, 11, 54, 24},
		{24,  2, 1, 16, 55, 25},
		{32,  0, 0, 17, 145, 115},
		{40,  3, 0, 20, 45, 15},
		{40,  3, 1, 61, 46, 16},
	};

	testStart("Checking ECC table(2)");
	for(i=0; i<7; i++) {
		QRspec_getEccSpec(correct[i][0], (QRecLevel)correct[i][1], spec);
		if(correct[i][2] == 0) {
			assert_equal(QRspec_rsBlockNum1(spec), correct[i][3],
				"Error in version %d, level %d. rsBlockNum1 was %d, expected %d.\n",
				correct[i][0], correct[i][1],
				QRspec_rsBlockNum1(spec), correct[i][3]);
			assert_equal(QRspec_rsDataCodes1(spec) + QRspec_rsEccCodes1(spec), correct[i][4],
				"Error in version %d, level %d. rsDataCodes1 + rsEccCodes1 was %d, expected %d.\n",
				correct[i][0], correct[i][1],
				QRspec_rsDataCodes1(spec) + QRspec_rsEccCodes1(spec), correct[i][4]);
			assert_equal(QRspec_rsDataCodes1(spec), correct[i][5],
				"Error in version %d, level %d. rsDataCodes1 was %d, expected %d.\n",
				correct[i][0], correct[i][1],
				QRspec_rsDataCodes1(spec), correct[i][5]);
		} else {
			assert_equal(QRspec_rsBlockNum2(spec), correct[i][3],
				"Error in version %d, level %d. rsBlockNum2 was %d, expected %d.\n",
				correct[i][0], correct[i][1],
				QRspec_rsBlockNum2(spec), correct[i][3]);
			assert_equal(QRspec_rsDataCodes2(spec) + QRspec_rsEccCodes2(spec), correct[i][4],
				"Error in version %d, level %d. rsDataCodes2 + rsEccCodes2 was %d, expected %d.\n",
				correct[i][0], correct[i][1],
				QRspec_rsDataCodes2(spec) + QRspec_rsEccCodes2(spec), correct[i][4]);
			assert_equal(QRspec_rsDataCodes2(spec), correct[i][5],
				"Error in version %d, level %d. rsDataCodes2 was %d, expected %d.\n",
				correct[i][0], correct[i][1],
				QRspec_rsDataCodes2(spec), correct[i][5]);
		}
	}
	testFinish();
}
예제 #3
0
static int RSblock_init(RSblock *blocks, int spec[5], unsigned char *data, unsigned char *ecc)
{
	int i;
	RSblock *block;
	unsigned char *dp, *ep;
	int el, dl;

	dl = QRspec_rsDataCodes1(spec);
	el = QRspec_rsEccCodes1(spec);

	block = blocks;
	dp = data;
	ep = ecc;
	for(i=0; i<QRspec_rsBlockNum1(spec); i++) {
		RSblock_initBlock(block, dl, dp, el, ep);
		dp += dl;
		ep += el;
		block++;
	}

	if(QRspec_rsBlockNum2(spec) == 0) return 0;

	dl = QRspec_rsDataCodes2(spec);
	el = QRspec_rsEccCodes2(spec);
	for(i=0; i<QRspec_rsBlockNum2(spec); i++) {
		RSblock_initBlock(block, dl, dp, el, ep);
		dp += dl;
		ep += el;
		block++;
	}

	return 0;
}
예제 #4
0
파일: qrencode.c 프로젝트: whglyy/NJTourism
static int RSblock_init(RSblock *blocks, int spec[5], unsigned char *data, unsigned char *ecc)
{
	int i;
	RSblock *block;
	unsigned char *dp, *ep;
	RS *rs;
	int el, dl;
	dl = QRspec_rsDataCodes1(spec);
	el = QRspec_rsEccCodes1(spec);
	rs = init_rs(8, 0x11d, 0, 1, el, 255 - dl - el);
	if(rs == NULL) return -1;
	block = blocks;
	dp = data;
	ep = ecc;
	for(i=0; i<QRspec_rsBlockNum1(spec); i++) {
		RSblock_initBlock(block, dl, dp, el, ep, rs);
		dp += dl;
		ep += el;
		block++;
	}
	if(QRspec_rsBlockNum2(spec) == 0) return 0;
	dl = QRspec_rsDataCodes2(spec);
	el = QRspec_rsEccCodes2(spec);
	rs = init_rs(8, 0x11d, 0, 1, el, 255 - dl - el);
	if(rs == NULL) return -1;
	for(i=0; i<QRspec_rsBlockNum2(spec); i++) {
		RSblock_initBlock(block, dl, dp, el, ep, rs);
		dp += dl;
		ep += el;
		block++;
	}
	return 0;
}
예제 #5
0
void test_eccTable(void)
{
	int i, j;
	int ecc;
	int data;
	int err = 0;
	int spec[5];

	testStart("Checking ECC table.");
	for(i=1; i<=QRSPEC_VERSION_MAX; i++) {
		for(j=0; j<4; j++) {
			QRspec_getEccSpec(i, (QRecLevel)j, spec);
			data = QRspec_rsBlockNum1(spec) * QRspec_rsDataCodes1(spec)
			     + QRspec_rsBlockNum2(spec) * QRspec_rsDataCodes2(spec);
			ecc  = QRspec_rsBlockNum1(spec) * QRspec_rsEccCodes1(spec)
			     + QRspec_rsBlockNum2(spec) * QRspec_rsEccCodes2(spec);
			if(data + ecc != QRspec_getDataLength(i, (QRecLevel)j) + QRspec_getECCLength(i, (QRecLevel)j)) {
				printf("Error in version %d, level %d: invalid size\n", i, j);
				printf("%d %d %d %d %d %d\n", spec[0], spec[1], spec[2], spec[3], spec[4], spec[2]);
				err++;
			}
			if(ecc != QRspec_getECCLength(i, (QRecLevel)j)) {
				printf("Error in version %d, level %d: invalid data\n", i, j);
				printf("%d %d %d %d %d %d\n", spec[0], spec[1], spec[2], spec[3], spec[4], spec[2]);
				err++;
			}
		}
	}
	testEnd(err);
}
예제 #6
0
static void compareRS(unsigned char data[])
{
	int i, j;
	RS *rs;
	int spec[5];
	int dl, el;
	unsigned char ecc_expected[256], ecc_rscodec[256];

	for(i = 1; i <= QRSPEC_VERSION_MAX; i++) {
		for(j = QR_ECLEVEL_L; j <= QR_ECLEVEL_H; j++) {
			QRspec_getEccSpec(i, (QRecLevel)j, spec);
			dl = QRspec_rsDataCodes1(spec);
			el = QRspec_rsEccCodes1(spec);
			rs = init_rs(8, 0x11d, 0, 1, el, 255 - dl - el);
			RSECC_encode(dl, el, data, ecc_rscodec);
			encode_rs_char(rs, data, ecc_expected);
			assert_zero(memcmp(ecc_expected, ecc_rscodec, el), "Invalid ECC found: length %d.\n", el);
			free_rs_char(rs);

			dl = QRspec_rsDataCodes2(spec);
			el = QRspec_rsEccCodes2(spec);
			if(dl != 0) {
				rs = init_rs(8, 0x11d, 0, 1, el, 255 - dl - el);
				RSECC_encode(dl, el, data, ecc_rscodec);
				encode_rs_char(rs, data, ecc_expected);
				assert_zero(memcmp(ecc_expected, ecc_rscodec, el), "Invalid ECC found: length %d.\n", el);
				free_rs_char(rs);
			}
		}
	}
}