void draw_structuredQRcode(QRinput_Struct *s) { int i, w, h, n, x, y; int swidth; QRcode_List *qrcodes, *p; qrcodes = QRcode_encodeInputStructured(s); if(qrcodes == NULL) return; swidth = (qrcodes->code->width + margin * 2) * size; n = QRcode_List_size(qrcodes); w = (n < 4)?n:4; h = (n - 1) / 4 + 1; screen = SDL_SetVideoMode(swidth * w, swidth * h, 32, 0); SDL_FillRect(screen, NULL, 0xffffff); p = qrcodes; for(i=0; i<n; i++) { x = (i % 4) * swidth; y = (i / 4) * swidth; draw_QRcode(p->code, x, y); p = p->next; } SDL_Flip(screen); QRcode_List_free(qrcodes); }
static QRcode_List *QRcode_encodeInputToStructured(QRinput *input) { QRinput_Struct *s; QRcode_List *codes; s = QRinput_splitQRinputToStruct(input); if(s == NULL) return NULL; codes = QRcode_encodeInputStructured(s); QRinput_Struct_free(s); return codes; }
void test_split_structure(int num) { QRinput *input; QRinput_Struct *s; QRcode_List *codes, *list; QRinput_InputList *il; int version; QRecLevel level; int c, i, ret; version = (int)drand(40) + 1; level = (QRecLevel)drand(4); fill8bitString(); input = QRinput_new2(version, level); if(input == NULL) { perror("test_split_structure aborted at QRinput_new2():"); return; } ret = Split_splitStringToQRinput((char *)data, input, QR_MODE_KANJI, 1); if(ret < 0) { perror("test_split_structure aborted at Split_splitStringToQRinput():"); QRinput_free(input); return; } s = QRinput_splitQRinputToStruct(input); if(s == NULL) { if(errno != 0 && errno != ERANGE) { perror("test_split_structure aborted at QRinput_splitQRinputToStruct():"); } QRinput_free(input); return; } il = s->head; i = 0; while(il != NULL) { if(il->input->version != version) { printf("Test: version %d, level %c\n", version, levelChar[level]); printf("wrong version number.\n"); printQRinputInfo(il->input); exit(1); } i++; il = il->next; } codes = QRcode_encodeInputStructured(s); if(codes == NULL) { perror("test_split_structure aborted at QRcode_encodeInputStructured():"); QRinput_free(input); QRinput_Struct_free(s); return; } list = codes; il = s->head; c = 0; while(list != NULL) { if(list->code->version != version) { printf("#%d: data mismatched.\n", num); printf("Test: version %d, level %c\n", version, levelChar[level]); printf("code #%d\n", c); printf("Version mismatch: %d should be %d\n", list->code->version, version); printf("max bits: %d\n", QRspec_getDataLength(version, level) * 8 - 20); printQRinputInfo(il->input); printQRinput(input); exit(1); } list = list->next; il = il->next; c++; } QRinput_free(input); QRinput_Struct_free(s); QRcode_List_free(codes); }