Esempio n. 1
0
void test_encode(void)
{
	QRinput *stream;
	char num[9] = "01234567";
	unsigned char *frame;
	int err = 0;
	int x, y, w;
	int mask;
	QRcode *qrcode;

	testStart("Test encode (1-M)");
	stream = QRinput_new();
	QRinput_append(stream, QR_MODE_NUM, 8, (unsigned char *)num);
	for(mask=0; mask<8; mask++) {
		QRinput_setVersion(stream, 1);
		QRinput_setErrorCorrectionLevel(stream, QR_ECLEVEL_M);
		qrcode = QRcode_encodeMask(stream, mask);
		w = qrcode->width;
		frame = qrcode->data;
		for(y=0; y<w; y++) {
			for(x=0; x<w; x++) {
				if(((m1pat[mask][y] >> (20-x)) & 1) != (frame[y*w+x]&1)) {
					printf("Diff in mask=%d (%d,%d)\n", mask, x, y);
					err++;
				}
			}
		}
		QRcode_free(qrcode);
	}
	QRinput_free(stream);
	testEnd(err);
}
Esempio n. 2
0
QRcode *QRcode_encodeInput(QRinput *input)
{
	if(input->mqr) {
		return QRcode_encodeMaskMQR(input, -1);
	} else {
		return QRcode_encodeMask(input, -1);
	}
}
Esempio n. 3
0
void draw_singleQRcode(QRinput *stream, int mask)
{
	QRcode *qrcode;
	int width;

	QRinput_setVersion(stream, version);
	QRinput_setErrorCorrectionLevel(stream, level);
	qrcode = QRcode_encodeMask(stream, mask);
	if(qrcode == NULL) return;

	version = qrcode->version;
	width = (qrcode->width + margin * 2) * size;

	screen = SDL_SetVideoMode(width, width, 32, 0);
	SDL_FillRect(screen, NULL, 0xffffff);
	draw_QRcode(qrcode, 0, 0);
	SDL_Flip(screen);
	QRcode_free(qrcode);
}
Esempio n. 4
0
void test_encode_an(int num)
{
	int ret;
	int len;
	len = fillANData();
	QRcode *qrcode;
	QRdata *qrdata;
	FILE *fp;
	char buf[256];

	qrcode = QRcode_encodeString((char *)data, 0, num % 4, QR_MODE_8, num % 2);
	if(qrcode == NULL) {
		if(errno == ERANGE) return;
		perror("test_encode_an aborted at QRcode_encodeString():");
		printf("Length: %d\n", len);
		printf("Level: %d\n", num % 4);
		return;
	}
	qrdata = QRcode_decode(qrcode);
	if(qrdata == NULL) {
		printf("#%d: Failed to decode this code.\n", num);
		QRcode_free(qrcode);
		return;
	}
	if(qrdata->size != len) {
		printf("#%d: length mismatched (orig: %d, decoded: %d)\n", num, len, qrdata->size);
	}
	ret = memcmp(qrdata->data, data, len);
	if(ret != 0) {
		unsigned char *frame, *p;
		int x,y, c;
		QRinput *input;
		QRcode *origcode;
		BitStream *bstream;
		int spec[5];

		printf("#%d: data mismatched.\n", num);
		printf("Version: %d\n", qrcode->version);
		QRspec_getEccSpec(qrcode->version, num%4, spec);
		printf("DataLength: %d\n", QRspec_rsDataLength(spec));
		printf("BlockNum1: %d\n", QRspec_rsBlockNum1(spec));
		printf("BlockNum: %d\n", QRspec_rsBlockNum(spec));
		printf("DataCodes1: %d\n", QRspec_rsDataCodes1(spec));

		snprintf(buf, 256, "monkey-orig-%d.dat", num);
		fp = fopen(buf, "w");
		fputs((char *)data, fp);
		fclose(fp);

		snprintf(buf, 256, "monkey-result-%d.dat", num);
		fp = fopen(buf, "w");
		fputs((char *)qrdata->data, fp);
		fclose(fp);

		snprintf(buf, 256, "monkey-result-unmasked-%d.dat", num);
		fp = fopen(buf, "w");
		frame = QRcode_unmask(qrcode);
		p = frame;
		for(y=0; y<qrcode->width; y++) {
			for(x=0; x<qrcode->width; x++) {
				fputc((*p&1)?'1':'0', fp);
				p++;
			}
			fputc('\n', fp);
		}
		fclose(fp);
		free(frame);

		snprintf(buf, 256, "monkey-orig-unmasked-%d.dat", num);
		fp = fopen(buf, "w");
		input = QRinput_new2(0, num % 4);
		Split_splitStringToQRinput((char *)data, input, QR_MODE_8, num % 2);
		origcode = QRcode_encodeMask(input, -2);
		p = origcode->data;
		for(y=0; y<origcode->width; y++) {
			for(x=0; x<origcode->width; x++) {
				fputc((*p&1)?'1':'0', fp);
				p++;
			}
			fputc('\n', fp);
		}
		fclose(fp);
		QRcode_free(origcode);

		snprintf(buf, 256, "monkey-orig-bits-%d.dat", num);
		fp = fopen(buf, "w");
		bstream = QRinput_mergeBitStream(input);
		c = 0;
		for(x=0; x<bstream->length; x++) {
			fputc((bstream->data[x]&1)?'1':'0', fp);
			if((x & 7) == 7) {
				fputc(' ', fp);
				c++;
			}
			if((x & 63) == 63) {
				fprintf(fp, "%d\n", c);
			}
		}
		fclose(fp);
		QRinput_free(input);
		BitStream_free(bstream);

		snprintf(buf, 256, "monkey-result-bits-%d.dat", num);
		fp = fopen(buf, "w");
		p = QRcode_extractBits(qrcode, &y);
		c = 0;
		for(x=0; x<y; x++) {
			fputc((p[x]&1)?'1':'0', fp);
			if((x & 7) == 7) {
				fputc(' ', fp);
				c++;
			}
			if((x & 63) == 63) {
				fprintf(fp, "%d\n", c);
			}
		}
		fclose(fp);
		free(p);
	}
	QRdata_free(qrdata);
	QRcode_free(qrcode);
}
Esempio n. 5
0
QRcode *QRcode_encodeInput(QRinput *input)
{
	return QRcode_encodeMask(input, -1);
}