void test_encodeData(void) { QRcode *qrcode; testStart("Test QRencode_encodeData."); qrcode = QRcode_encodeData(0, NULL, 0, QR_ECLEVEL_H); assert_null(qrcode, "QRcode_encodeData(NULL, 0) returned something.\n"); if(qrcode != NULL) QRcode_free(qrcode); qrcode = QRcode_encodeData(10, (unsigned char*)"test\0\0test", 0, QR_ECLEVEL_H); assert_nonnull(qrcode, "QRcode_encodeData() failed.\n"); if(qrcode != NULL) QRcode_free(qrcode); testFinish(); }
void test_encode_8(int num) { QRcode *qrcode; QRdata *qrdata; int len, ret; len = fill8bitData(); qrcode = QRcode_encodeData(len, data, 0, num % 4); if(qrcode == NULL) { if(errno == ERANGE) return; perror("test_encdoe_8 aborted at QRcode_encodeData():"); 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) { printf("#%d: data mismatched.\n", num); } QRdata_free(qrdata); QRcode_free(qrcode); }
QRcode* QRimage_encode(QRimageEncodeParams* params) { QRcode *code; if (NULL == params) { return NULL; } if(params->micro) { if(params->eightbit) { code = QRcode_encodeDataMQR(params->size, params->data, params->version, params->level); } else { code = QRcode_encodeStringMQR((char *)params->data, params->version, params->level, params->hint, params->casesensitive); } } else { if(params->eightbit) { code = QRcode_encodeData(params->size, params->data, params->version, params->level); } else { code = QRcode_encodeString((char *)params->data, params->version, params->level, params->hint, params->casesensitive); } } return code; }
void encode(uchar *buf, size_t length, cv::Mat &m, int size) { auto qrcode = QRcode_encodeData(length, buf, 0, QR_ECLEVEL_L); int width = qrcode->width; m = cv::Mat(width * size, width * size, CV_8U); auto pr = qrcode->data; for (int r = 0; r != width; ++r) { for (int c = 0; c != width; ++c) { set(m, r, c, size, *pr++ & 1); } } QRcode_free(qrcode); }
static QRcode *encode(const unsigned char *intext, int length) { QRcode *code; if(micro) { if(eightbit) { code = QRcode_encodeDataMQR(length, intext, version, level); } else { code = QRcode_encodeStringMQR((char *)intext, version, level, hint, casesensitive); } } else if(eightbit) { code = QRcode_encodeData(length, intext, version, level); } else { code = QRcode_encodeString((char *)intext, version, level, hint, casesensitive); } return code; }
void command_success_qrcode(sourceinfo_t *si, const char *data) { #ifdef HAVE_LIBQRENCODE char *buf; QRcode *code; size_t bufsize, realwidth; size_t y; return_if_fail(si != NULL); return_if_fail(data != NULL); code = QRcode_encodeData(strlen(data), data, 4, QR_ECLEVEL_L); realwidth = (code->width + 3 * 2) * 2; bufsize = strlen(prologue) + (realwidth * 3) + strlen(prologue); buf = smalloc(bufsize); /* header */ for (y = 0; y < 3; y++) { qrcode_margin(buf, bufsize, realwidth); command_success_nodata(si, "%s", buf); } /* qrcode contents + side margins */ for (y = 0; y < code->width; y++) { qrcode_scanline(buf, bufsize, code->data + (y * code->width), code->width); command_success_nodata(si, "%s", buf); } /* footer */ for (y = 0; y < 3; y++) { qrcode_margin(buf, bufsize, realwidth); command_success_nodata(si, "%s", buf); } free(buf); QRcode_free(code); #endif }