qrencode  4.1.1
About: libqrencode is a fast and compact library and command-line utility for encoding data in a QR Code symbol.
  Fossies Dox: qrencode-4.1.1.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

qrencode.c
Go to the documentation of this file.
1/*
2 * qrencode - QR Code encoder
3 *
4 * Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#if HAVE_CONFIG_H
22# include "config.h"
23#endif
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <errno.h>
28
29#include "qrencode.h"
30#include "qrspec.h"
31#include "mqrspec.h"
32#include "bitstream.h"
33#include "qrinput.h"
34#include "rsecc.h"
35#include "split.h"
36#include "mask.h"
37#include "mmask.h"
38
39/******************************************************************************
40 * Raw code
41 *****************************************************************************/
42
43typedef struct {
46 unsigned char *data;
47 unsigned char *ecc;
48} RSblock;
49
50typedef struct {
54 unsigned char *datacode;
55 unsigned char *ecccode;
56 int b1;
57 int blocks;
59 int count;
60} QRRawCode;
61
62static void RSblock_initBlock(RSblock *block, int dl, unsigned char *data, int el, unsigned char *ecc)
63{
64 block->dataLength = dl;
65 block->data = data;
66 block->eccLength = el;
67 block->ecc = ecc;
68
69 RSECC_encode((size_t)dl, (size_t)el, data, ecc);
70}
71
72static int RSblock_init(RSblock *blocks, int spec[5], unsigned char *data, unsigned char *ecc)
73{
74 int i;
75 RSblock *block;
76 unsigned char *dp, *ep;
77 int el, dl;
78
79 dl = QRspec_rsDataCodes1(spec);
80 el = QRspec_rsEccCodes1(spec);
81
82 block = blocks;
83 dp = data;
84 ep = ecc;
85 for(i = 0; i < QRspec_rsBlockNum1(spec); i++) {
86 RSblock_initBlock(block, dl, dp, el, ep);
87 dp += dl;
88 ep += el;
89 block++;
90 }
91
92 if(QRspec_rsBlockNum2(spec) == 0) return 0;
93
94 dl = QRspec_rsDataCodes2(spec);
95 el = QRspec_rsEccCodes2(spec);
96 for(i = 0; i < QRspec_rsBlockNum2(spec); i++) {
97 RSblock_initBlock(block, dl, dp, el, ep);
98 dp += dl;
99 ep += el;
100 block++;
101 }
102
103 return 0;
104}
105
106STATIC_IN_RELEASE void QRraw_free(QRRawCode *raw);
107STATIC_IN_RELEASE QRRawCode *QRraw_new(QRinput *input)
108{
109 QRRawCode *raw;
110 int spec[5], ret;
111
112 raw = (QRRawCode *)malloc(sizeof(QRRawCode));
113 if(raw == NULL) return NULL;
114
115 raw->datacode = QRinput_getByteStream(input);
116 if(raw->datacode == NULL) {
117 free(raw);
118 return NULL;
119 }
120
121 QRspec_getEccSpec(input->version, input->level, spec);
122
123 raw->version = input->version;
124 raw->b1 = QRspec_rsBlockNum1(spec);
125 raw->dataLength = QRspec_rsDataLength(spec);
126 raw->eccLength = QRspec_rsEccLength(spec);
127 raw->ecccode = (unsigned char *)malloc((size_t)raw->eccLength);
128 if(raw->ecccode == NULL) {
129 free(raw->datacode);
130 free(raw);
131 return NULL;
132 }
133
134 raw->blocks = QRspec_rsBlockNum(spec);
135 raw->rsblock = (RSblock *)calloc((size_t)(raw->blocks), sizeof(RSblock));
136 if(raw->rsblock == NULL) {
137 QRraw_free(raw);
138 return NULL;
139 }
140 ret = RSblock_init(raw->rsblock, spec, raw->datacode, raw->ecccode);
141 if(ret < 0) {
142 QRraw_free(raw);
143 return NULL;
144 }
145
146 raw->count = 0;
147
148 return raw;
149}
150
151/**
152 * Return a code (byte).
153 * This function can be called iteratively.
154 * @param raw raw code.
155 * @return code
156 */
157STATIC_IN_RELEASE unsigned char QRraw_getCode(QRRawCode *raw)
158{
159 int col, row;
160 unsigned char ret;
161
162 if(raw->count < raw->dataLength) {
163 row = raw->count % raw->blocks;
164 col = raw->count / raw->blocks;
165 if(col >= raw->rsblock[0].dataLength) {
166 row += raw->b1;
167 }
168 ret = raw->rsblock[row].data[col];
169 } else if(raw->count < raw->dataLength + raw->eccLength) {
170 row = (raw->count - raw->dataLength) % raw->blocks;
171 col = (raw->count - raw->dataLength) / raw->blocks;
172 ret = raw->rsblock[row].ecc[col];
173 } else {
174 return 0;
175 }
176 raw->count++;
177 return ret;
178}
179
180STATIC_IN_RELEASE void QRraw_free(QRRawCode *raw)
181{
182 if(raw != NULL) {
183 free(raw->datacode);
184 free(raw->ecccode);
185 free(raw->rsblock);
186 free(raw);
187 }
188}
189
190/******************************************************************************
191 * Raw code for Micro QR Code
192 *****************************************************************************/
193
194typedef struct {
198 unsigned char *datacode;
199 unsigned char *ecccode;
202 int count;
203} MQRRawCode;
204
205STATIC_IN_RELEASE void MQRraw_free(MQRRawCode *raw);
206STATIC_IN_RELEASE MQRRawCode *MQRraw_new(QRinput *input)
207{
208 MQRRawCode *raw;
209
210 raw = (MQRRawCode *)malloc(sizeof(MQRRawCode));
211 if(raw == NULL) return NULL;
212
213 raw->version = input->version;
214 raw->dataLength = MQRspec_getDataLength(input->version, input->level);
215 raw->eccLength = MQRspec_getECCLength(input->version, input->level);
216 raw->oddbits = raw->dataLength * 8 - MQRspec_getDataLengthBit(input->version, input->level);
217 raw->datacode = QRinput_getByteStream(input);
218 if(raw->datacode == NULL) {
219 free(raw);
220 return NULL;
221 }
222 raw->ecccode = (unsigned char *)malloc((size_t)raw->eccLength);
223 if(raw->ecccode == NULL) {
224 free(raw->datacode);
225 free(raw);
226 return NULL;
227 }
228
229 raw->rsblock = (RSblock *)calloc(1, sizeof(RSblock));
230 if(raw->rsblock == NULL) {
231 MQRraw_free(raw);
232 return NULL;
233 }
234
235 RSblock_initBlock(raw->rsblock, raw->dataLength, raw->datacode, raw->eccLength, raw->ecccode);
236
237 raw->count = 0;
238
239 return raw;
240}
241
242/**
243 * Return a code (byte).
244 * This function can be called iteratively.
245 * @param raw raw code.
246 * @return code
247 */
248STATIC_IN_RELEASE unsigned char MQRraw_getCode(MQRRawCode *raw)
249{
250 unsigned char ret;
251
252 if(raw->count < raw->dataLength) {
253 ret = raw->datacode[raw->count];
254 } else if(raw->count < raw->dataLength + raw->eccLength) {
255 ret = raw->ecccode[raw->count - raw->dataLength];
256 } else {
257 return 0;
258 }
259 raw->count++;
260 return ret;
261}
262
263STATIC_IN_RELEASE void MQRraw_free(MQRRawCode *raw)
264{
265 if(raw != NULL) {
266 free(raw->datacode);
267 free(raw->ecccode);
268 free(raw->rsblock);
269 free(raw);
270 }
271}
272
273
274/******************************************************************************
275 * Frame filling
276 *****************************************************************************/
277
278typedef struct {
279 int width;
280 unsigned char *frame;
281 int x, y;
282 int dir;
283 int bit;
284 int mqr;
286
287static void FrameFiller_set(FrameFiller *filler, int width, unsigned char *frame, int mqr)
288{
289 filler->width = width;
290 filler->frame = frame;
291 filler->x = width - 1;
292 filler->y = width - 1;
293 filler->dir = -1;
294 filler->bit = -1;
295 filler->mqr = mqr;
296}
297
298static unsigned char *FrameFiller_next(FrameFiller *filler)
299{
300 unsigned char *p;
301 int x, y, w;
302
303 if(filler->bit == -1) {
304 filler->bit = 0;
305 return filler->frame + filler->y * filler->width + filler->x;
306 }
307
308 x = filler->x;
309 y = filler->y;
310 p = filler->frame;
311 w = filler->width;
312
313 if(filler->bit == 0) {
314 x--;
315 filler->bit++;
316 } else {
317 x++;
318 y += filler->dir;
319 filler->bit--;
320 }
321
322 if(filler->dir < 0) {
323 if(y < 0) {
324 y = 0;
325 x -= 2;
326 filler->dir = 1;
327 if(!filler->mqr && x == 6) {
328 x--;
329 y = 9;
330 }
331 }
332 } else if(y == w) {
333 y = w - 1;
334 x -= 2;
335 filler->dir = -1;
336 if(!filler->mqr && x == 6) {
337 x--;
338 y -= 8;
339 }
340 }
341 if(x < 0 || y < 0) return NULL;
342
343 filler->x = x;
344 filler->y = y;
345
346 if(p[y * w + x] & 0x80) {
347 // This tail recursion could be optimized.
348 return FrameFiller_next(filler);
349 }
350 return &p[y * w + x];
351}
352
353#ifdef WITH_TESTS
354unsigned char *FrameFiller_test(int version)
355{
356 int width;
357 unsigned char *frame, *p;
358 int i, length;
359 FrameFiller filler;
360
361 width = QRspec_getWidth(version);
362 frame = QRspec_newFrame(version);
363 if(frame == NULL) return NULL;
364 FrameFiller_set(&filler, width, frame, 0);
368 for(i = 0; i < length; i++) {
369 p = FrameFiller_next(&filler);
370 if(p == NULL) {
371 free(frame);
372 return NULL;
373 }
374 *p = (unsigned char)(i & 0x7f) | 0x80;
375 }
376 return frame;
377}
378
379unsigned char *FrameFiller_testMQR(int version)
380{
381 int width;
382 unsigned char *frame, *p;
383 int i, length;
384 FrameFiller filler;
385
386 width = MQRspec_getWidth(version);
387 frame = MQRspec_newFrame(version);
388 if(frame == NULL) return NULL;
389 FrameFiller_set(&filler, width, frame, 1);
392 for(i = 0; i < length; i++) {
393 p = FrameFiller_next(&filler);
394 if(p == NULL) {
395 fprintf(stderr, "Frame filler run over the frame!\n");
396 return frame;
397 }
398 *p = (unsigned char)(i & 0x7f) | 0x80;
399 }
400 return frame;
401}
402#endif
403
404
405/******************************************************************************
406 * QR-code encoding
407 *****************************************************************************/
408
409STATIC_IN_RELEASE QRcode *QRcode_new(int version, int width, unsigned char *data)
410{
411 QRcode *qrcode;
412
413 qrcode = (QRcode *)malloc(sizeof(QRcode));
414 if(qrcode == NULL) return NULL;
415
416 qrcode->version = version;
417 qrcode->width = width;
418 qrcode->data = data;
419
420 return qrcode;
421}
422
423void QRcode_free(QRcode *qrcode)
424{
425 if(qrcode != NULL) {
426 free(qrcode->data);
427 free(qrcode);
428 }
429}
430
431STATIC_IN_RELEASE QRcode *QRcode_encodeMask(QRinput *input, int mask)
432{
433 int width, version;
434 QRRawCode *raw;
435 unsigned char *frame, *masked, *p, code, bit;
436 int i, j;
437 QRcode *qrcode = NULL;
438 FrameFiller filler;
439
440 if(input->mqr) {
441 errno = EINVAL;
442 return NULL;
443 }
444 if(input->version < 0 || input->version > QRSPEC_VERSION_MAX) {
445 errno = EINVAL;
446 return NULL;
447 }
448 if(!(input->level >= QR_ECLEVEL_L && input->level <= QR_ECLEVEL_H)) {
449 errno = EINVAL;
450 return NULL;
451 }
452
453 raw = QRraw_new(input);
454 if(raw == NULL) return NULL;
455
456 version = raw->version;
457 width = QRspec_getWidth(version);
458 frame = QRspec_newFrame(version);
459 if(frame == NULL) {
460 QRraw_free(raw);
461 return NULL;
462 }
463 FrameFiller_set(&filler, width, frame, 0);
464
465 /* interleaved data and ecc codes */
466 for(i = 0; i < raw->dataLength; i++) {
467 code = QRraw_getCode(raw);
468 bit = 0x80;
469 for(j = 0; j < 8; j++) {
470 p = FrameFiller_next(&filler);
471 if(p == NULL) goto EXIT;
472 *p = ((bit & code) != 0);
473 bit = bit >> 1;
474 }
475 }
476 for(i = 0; i < raw->eccLength; i++) {
477 code = QRraw_getCode(raw);
478 bit = 0x80;
479 for(j = 0; j < 8; j++) {
480 p = FrameFiller_next(&filler);
481 if(p == NULL) goto EXIT;
482 *p = 0x02 | ((bit & code) != 0);
483 bit = bit >> 1;
484 }
485 }
486 QRraw_free(raw);
487 raw = NULL;
488 /* remainder bits */
490 for(i = 0; i < j; i++) {
491 p = FrameFiller_next(&filler);
492 if(p == NULL) goto EXIT;
493 *p = 0x02;
494 }
495
496 /* masking */
497 if(mask == -2) { // just for debug purpose
498 masked = (unsigned char *)malloc((size_t)(width * width));
499 memcpy(masked, frame, (size_t)(width * width));
500 } else if(mask < 0) {
501 masked = Mask_mask(width, frame, input->level);
502 } else {
503 masked = Mask_makeMask(width, frame, mask, input->level);
504 }
505 if(masked == NULL) {
506 goto EXIT;
507 }
508 qrcode = QRcode_new(version, width, masked);
509 if(qrcode == NULL) {
510 free(masked);
511 }
512
513EXIT:
514 QRraw_free(raw);
515 free(frame);
516 return qrcode;
517}
518
519STATIC_IN_RELEASE QRcode *QRcode_encodeMaskMQR(QRinput *input, int mask)
520{
521 int width, version;
522 MQRRawCode *raw;
523 unsigned char *frame, *masked, *p, code, bit;
524 int i, j, length;
525 QRcode *qrcode = NULL;
526 FrameFiller filler;
527
528 if(!input->mqr) {
529 errno = EINVAL;
530 return NULL;
531 }
532 if(input->version <= 0 || input->version > MQRSPEC_VERSION_MAX) {
533 errno = EINVAL;
534 return NULL;
535 }
536 if(!(input->level >= QR_ECLEVEL_L && input->level <= QR_ECLEVEL_Q)) {
537 errno = EINVAL;
538 return NULL;
539 }
540
541 raw = MQRraw_new(input);
542 if(raw == NULL) return NULL;
543
544 version = raw->version;
545 width = MQRspec_getWidth(version);
546 frame = MQRspec_newFrame(version);
547 if(frame == NULL) {
548 MQRraw_free(raw);
549 return NULL;
550 }
551 FrameFiller_set(&filler, width, frame, 1);
552
553 /* interleaved data and ecc codes */
554 for(i = 0; i < raw->dataLength; i++) {
555 code = MQRraw_getCode(raw);
556 bit = 0x80;
557 if(raw->oddbits && i == raw->dataLength - 1) {
558 length = raw->oddbits;
559 } else {
560 length = 8;
561 }
562 for(j = 0; j < length; j++) {
563 p = FrameFiller_next(&filler);
564 if(p == NULL) goto EXIT;
565 *p = ((bit & code) != 0);
566 bit = bit >> 1;
567 }
568 }
569 for(i = 0; i < raw->eccLength; i++) {
570 code = MQRraw_getCode(raw);
571 bit = 0x80;
572 length = 8;
573 for(j = 0; j < length; j++) {
574 p = FrameFiller_next(&filler);
575 if(p == NULL) goto EXIT;
576 *p = 0x02 | ((bit & code) != 0);
577 bit = bit >> 1;
578 }
579 }
580 MQRraw_free(raw);
581 raw = NULL;
582
583 /* masking */
584 if(mask == -2) { // just for debug purpose
585 masked = (unsigned char *)malloc((size_t)(width * width));
586 memcpy(masked, frame, (size_t)(width * width));
587 } else if(mask < 0) {
588 masked = MMask_mask(version, frame, input->level);
589 } else {
590 masked = MMask_makeMask(version, frame, mask, input->level);
591 }
592 if(masked == NULL) {
593 goto EXIT;
594 }
595
596 qrcode = QRcode_new(version, width, masked);
597 if(qrcode == NULL) {
598 free(masked);
599 }
600
601EXIT:
602 MQRraw_free(raw);
603 free(frame);
604 return qrcode;
605}
606
608{
609 if(input->mqr) {
610 return QRcode_encodeMaskMQR(input, -1);
611 } else {
612 return QRcode_encodeMask(input, -1);
613 }
614}
615
616static QRcode *QRcode_encodeStringReal(const char *string, int version, QRecLevel level, int mqr, QRencodeMode hint, int casesensitive)
617{
618 QRinput *input;
619 QRcode *code;
620 int ret;
621
622 if(string == NULL) {
623 errno = EINVAL;
624 return NULL;
625 }
626 if(hint != QR_MODE_8 && hint != QR_MODE_KANJI) {
627 errno = EINVAL;
628 return NULL;
629 }
630
631 if(mqr) {
632 input = QRinput_newMQR(version, level);
633 } else {
634 input = QRinput_new2(version, level);
635 }
636 if(input == NULL) return NULL;
637
638 ret = Split_splitStringToQRinput(string, input, hint, casesensitive);
639 if(ret < 0) {
640 QRinput_free(input);
641 return NULL;
642 }
643 code = QRcode_encodeInput(input);
644 QRinput_free(input);
645
646 return code;
647}
648
650{
652}
653
655{
656 int i;
657
658 if(version == 0) {
659 version = 1;
660 }
661 for(i = version; i <= MQRSPEC_VERSION_MAX ; i++) {
662 QRcode *code = QRcode_encodeStringReal(string, i, level, 1, hint, casesensitive);
663 if(code != NULL) return code;
664 }
665
666 return NULL;
667}
668
669static QRcode *QRcode_encodeDataReal(const unsigned char *data, int length, int version, QRecLevel level, int mqr)
670{
671 QRinput *input;
672 QRcode *code;
673 int ret;
674
675 if(data == NULL || length == 0) {
676 errno = EINVAL;
677 return NULL;
678 }
679
680 if(mqr) {
681 input = QRinput_newMQR(version, level);
682 } else {
683 input = QRinput_new2(version, level);
684 }
685 if(input == NULL) return NULL;
686
687 ret = QRinput_append(input, QR_MODE_8, length, data);
688 if(ret < 0) {
689 QRinput_free(input);
690 return NULL;
691 }
692 code = QRcode_encodeInput(input);
693 QRinput_free(input);
694
695 return code;
696}
697
698QRcode *QRcode_encodeData(int size, const unsigned char *data, int version, QRecLevel level)
699{
700 return QRcode_encodeDataReal(data, size, version, level, 0);
701}
702
704{
705 if(string == NULL) {
706 errno = EINVAL;
707 return NULL;
708 }
709 return QRcode_encodeDataReal((unsigned char *)string, (int)strlen(string), version, level, 0);
710}
711
712QRcode *QRcode_encodeDataMQR(int size, const unsigned char *data, int version, QRecLevel level)
713{
714 int i;
715
716 if(version == 0) {
717 version = 1;
718 }
719 for(i = version; i <= MQRSPEC_VERSION_MAX; i++) {
720 QRcode *code = QRcode_encodeDataReal(data, size, i, level, 1);
721 if(code != NULL) return code;
722 }
723
724 return NULL;
725}
726
728{
729 int i;
730
731 if(string == NULL) {
732 errno = EINVAL;
733 return NULL;
734 }
735 if(version == 0) {
736 version = 1;
737 }
738 for(i = version; i <= MQRSPEC_VERSION_MAX; i++) {
739 QRcode *code = QRcode_encodeDataReal((unsigned char *)string, (int)strlen(string), i, level, 1);
740 if(code != NULL) return code;
741 }
742
743 return NULL;
744}
745
746
747/******************************************************************************
748 * Structured QR-code encoding
749 *****************************************************************************/
750
752{
753 QRcode_List *entry;
754
755 entry = (QRcode_List *)malloc(sizeof(QRcode_List));
756 if(entry == NULL) return NULL;
757
758 entry->next = NULL;
759 entry->code = NULL;
760
761 return entry;
762}
763
765{
766 if(entry != NULL) {
767 QRcode_free(entry->code);
768 free(entry);
769 }
770}
771
773{
774 QRcode_List *list = qrlist, *next;
775
776 while(list != NULL) {
777 next = list->next;
779 list = next;
780 }
781}
782
784{
785 QRcode_List *list = qrlist;
786 int size = 0;
787
788 while(list != NULL) {
789 size++;
790 list = list->next;
791 }
792
793 return size;
794}
795
796#if 0
797static unsigned char QRcode_parity(const char *str, int size)
798{
799 unsigned char parity = 0;
800 int i;
801
802 for(i = 0; i < size; i++) {
803 parity ^= str[i];
804 }
805
806 return parity;
807}
808#endif
809
811{
812 QRcode_List *head = NULL;
813 QRcode_List *tail = NULL;
814 QRcode_List *entry;
815 QRinput_InputList *list = s->head;
816
817 while(list != NULL) {
818 if(head == NULL) {
819 entry = QRcode_List_newEntry();
820 if(entry == NULL) goto ABORT;
821 head = entry;
822 tail = head;
823 } else {
824 entry = QRcode_List_newEntry();
825 if(entry == NULL) goto ABORT;
826 tail->next = entry;
827 tail = tail->next;
828 }
829 tail->code = QRcode_encodeInput(list->input);
830 if(tail->code == NULL) {
831 goto ABORT;
832 }
833 list = list->next;
834 }
835
836 return head;
837ABORT:
838 QRcode_List_free(head);
839 return NULL;
840}
841
843{
845 QRcode_List *codes;
846
848 if(s == NULL) return NULL;
849
852
853 return codes;
854}
855
857 int size, const unsigned char *data,
860{
861 QRinput *input;
862 QRcode_List *codes;
863 int ret;
864
865 if(version <= 0) {
866 errno = EINVAL;
867 return NULL;
868 }
869 if(!eightbit && (hint != QR_MODE_8 && hint != QR_MODE_KANJI)) {
870 errno = EINVAL;
871 return NULL;
872 }
873
874 input = QRinput_new2(version, level);
875 if(input == NULL) return NULL;
876
877 if(eightbit) {
878 ret = QRinput_append(input, QR_MODE_8, size, data);
879 } else {
880 ret = Split_splitStringToQRinput((char *)data, input, hint, casesensitive);
881 }
882 if(ret < 0) {
883 QRinput_free(input);
884 return NULL;
885 }
886 codes = QRcode_encodeInputToStructured(input);
887 QRinput_free(input);
888
889 return codes;
890}
891
892QRcode_List *QRcode_encodeDataStructured(int size, const unsigned char *data, int version, QRecLevel level) {
894}
895
897 if(string == NULL) {
898 errno = EINVAL;
899 return NULL;
900 }
901 return QRcode_encodeDataStructured((int)strlen(string), (unsigned char *)string, version, level);
902}
903
905{
906 if(string == NULL) {
907 errno = EINVAL;
908 return NULL;
909 }
910 return QRcode_encodeDataStructuredReal((int)strlen(string), (unsigned char *)string, version, level, 0, hint, casesensitive);
911}
912
913/******************************************************************************
914 * System utilities
915 *****************************************************************************/
916
917void QRcode_APIVersion(int *major_version, int *minor_version, int *micro_version)
918{
919 if(major_version != NULL) {
920 *major_version = MAJOR_VERSION;
921 }
922 if(minor_version != NULL) {
923 *minor_version = MINOR_VERSION;
924 }
925 if(micro_version != NULL) {
926 *micro_version = MICRO_VERSION;
927 }
928}
929
931{
932 return VERSION;
933}
934
936{
937 return;
938}
unsigned char * Mask_mask(int width, unsigned char *frame, QRecLevel level)
Definition: mask.c:322
unsigned char * Mask_makeMask(int width, unsigned char *frame, int mask, QRecLevel level)
Definition: mask.c:164
unsigned char * MMask_makeMask(int version, unsigned char *frame, int mask, QRecLevel level)
Definition: mmask.c:108
unsigned char * MMask_mask(int version, unsigned char *frame, QRecLevel level)
Definition: mmask.c:148
int MQRspec_getECCLength(int version, QRecLevel level)
Return maximum error correction code length (bytes) for the version.
Definition: mqrspec.c:75
unsigned char * MQRspec_newFrame(int version)
Frame.
Definition: mqrspec.c:227
int MQRspec_getWidth(int version)
Return the width of the symbol for the version.
Definition: mqrspec.c:80
int MQRspec_getDataLengthBit(int version, QRecLevel level)
Return maximum data code length (bits) for the version.
Definition: mqrspec.c:59
int MQRspec_getDataLength(int version, QRecLevel level)
Return maximum data code length (bytes) for the version.
Definition: mqrspec.c:70
static QRencodeMode hint
Definition: qrenc.c:51
static int size
Definition: qrenc.c:41
static int casesensitive
Definition: qrenc.c:38
static QRecLevel level
Definition: qrenc.c:50
static int eightbit
Definition: qrenc.c:39
static int version
Definition: qrenc.c:40
QRcode_List * QRcode_encodeString8bitStructured(const char *string, int version, QRecLevel level)
Same to QRcode_encodeStringStructured(), but encode whole data in 8-bit mode.
Definition: qrencode.c:896
static QRcode_List * QRcode_List_newEntry(void)
Structured QR-code encoding.
Definition: qrencode.c:751
QRcode * QRcode_encodeInput(QRinput *input)
Create a symbol from the input data.
Definition: qrencode.c:607
static QRcode * QRcode_encodeDataReal(const unsigned char *data, int length, int version, QRecLevel level, int mqr)
Definition: qrencode.c:669
STATIC_IN_RELEASE void MQRraw_free(MQRRawCode *raw)
Definition: qrencode.c:263
void QRcode_List_free(QRcode_List *qrlist)
Free the QRcode_List.
Definition: qrencode.c:772
QRcode_List * QRcode_encodeStringStructured(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive)
Create structured symbols from the string.
Definition: qrencode.c:904
void QRcode_APIVersion(int *major_version, int *minor_version, int *micro_version)
System utilities.
Definition: qrencode.c:917
static QRcode_List * QRcode_encodeInputToStructured(QRinput *input)
Definition: qrencode.c:842
static void FrameFiller_set(FrameFiller *filler, int width, unsigned char *frame, int mqr)
Definition: qrencode.c:287
static void QRcode_List_freeEntry(QRcode_List *entry)
Definition: qrencode.c:764
STATIC_IN_RELEASE void QRraw_free(QRRawCode *raw)
Definition: qrencode.c:180
QRcode * QRcode_encodeStringMQR(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive)
Micro QR Code version of QRcode_encodeString().
Definition: qrencode.c:654
STATIC_IN_RELEASE QRRawCode * QRraw_new(QRinput *input)
Definition: qrencode.c:107
STATIC_IN_RELEASE unsigned char MQRraw_getCode(MQRRawCode *raw)
Return a code (byte).
Definition: qrencode.c:248
static QRcode * QRcode_encodeStringReal(const char *string, int version, QRecLevel level, int mqr, QRencodeMode hint, int casesensitive)
Definition: qrencode.c:616
STATIC_IN_RELEASE MQRRawCode * MQRraw_new(QRinput *input)
Definition: qrencode.c:206
STATIC_IN_RELEASE unsigned char QRraw_getCode(QRRawCode *raw)
Return a code (byte).
Definition: qrencode.c:157
static void RSblock_initBlock(RSblock *block, int dl, unsigned char *data, int el, unsigned char *ecc)
Definition: qrencode.c:62
QRcode_List * QRcode_encodeDataStructured(int size, const unsigned char *data, int version, QRecLevel level)
Create structured symbols from byte stream (may include '\0').
Definition: qrencode.c:892
QRcode * QRcode_encodeString8bitMQR(const char *string, int version, QRecLevel level)
Micro QR Code version of QRcode_encodeString8bit().
Definition: qrencode.c:727
void QRcode_clearCache(void)
Definition: qrencode.c:935
static unsigned char * FrameFiller_next(FrameFiller *filler)
Definition: qrencode.c:298
static QRcode_List * QRcode_encodeDataStructuredReal(int size, const unsigned char *data, int version, QRecLevel level, int eightbit, QRencodeMode hint, int casesensitive)
Definition: qrencode.c:856
char * QRcode_APIVersionString(void)
Return a string that identifies the library version.
Definition: qrencode.c:930
static int RSblock_init(RSblock *blocks, int spec[5], unsigned char *data, unsigned char *ecc)
Definition: qrencode.c:72
QRcode_List * QRcode_encodeInputStructured(QRinput_Struct *s)
Create structured symbols from the input data.
Definition: qrencode.c:810
STATIC_IN_RELEASE QRcode * QRcode_new(int version, int width, unsigned char *data)
QR-code encoding.
Definition: qrencode.c:409
STATIC_IN_RELEASE QRcode * QRcode_encodeMaskMQR(QRinput *input, int mask)
Definition: qrencode.c:519
QRcode * QRcode_encodeDataMQR(int size, const unsigned char *data, int version, QRecLevel level)
Micro QR Code version of QRcode_encodeData().
Definition: qrencode.c:712
STATIC_IN_RELEASE QRcode * QRcode_encodeMask(QRinput *input, int mask)
QR-code encoding.
Definition: qrencode.c:431
void QRcode_free(QRcode *qrcode)
Free the instance of QRcode class.
Definition: qrencode.c:423
QRcode * QRcode_encodeString8bit(const char *string, int version, QRecLevel level)
Same to QRcode_encodeString(), but encode whole data in 8-bit mode.
Definition: qrencode.c:703
QRcode * QRcode_encodeData(int size, const unsigned char *data, int version, QRecLevel level)
Encode byte stream (may include '\0') in 8-bit mode.
Definition: qrencode.c:698
int QRcode_List_size(QRcode_List *qrlist)
Return the number of symbols included in a QRcode_List.
Definition: qrencode.c:783
QRcode * QRcode_encodeString(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive)
Create a symbol from the string.
Definition: qrencode.c:649
QRecLevel
Level of error correction.
Definition: qrencode.h:124
@ QR_ECLEVEL_Q
Definition: qrencode.h:127
@ QR_ECLEVEL_H
highest
Definition: qrencode.h:128
@ QR_ECLEVEL_L
lowest
Definition: qrencode.h:125
void QRinput_free(QRinput *input)
Free the input object.
Definition: qrinput.c:294
int QRinput_append(QRinput *input, QRencodeMode mode, int size, const unsigned char *data)
Append data to an input object.
Definition: qrinput.c:223
QRinput_Struct * QRinput_splitQRinputToStruct(QRinput *input)
Split a QRinput to QRinput_Struct.
Definition: qrinput.c:1485
QRencodeMode
Encoding mode.
Definition: qrencode.h:109
@ QR_MODE_KANJI
Kanji (shift-jis) mode.
Definition: qrencode.h:114
@ QR_MODE_8
8-bit data mode
Definition: qrencode.h:113
@ QR_MODE_NUL
Terminator (NUL character). Internal use only.
Definition: qrencode.h:110
#define MQRSPEC_VERSION_MAX
Maximum version (size) of QR-code symbol.
Definition: qrencode.h:139
QRinput * QRinput_new2(int version, QRecLevel level)
Instantiate an input data object.
Definition: qrinput.c:116
#define QRSPEC_VERSION_MAX
Maximum version (size) of QR-code symbol.
Definition: qrencode.h:134
QRinput * QRinput_newMQR(int version, QRecLevel level)
Instantiate an input data object.
Definition: qrinput.c:138
void QRinput_Struct_free(QRinput_Struct *s)
Free all of QRinput in the set.
Definition: qrinput.c:1417
unsigned char * FrameFiller_testMQR(int version)
unsigned char * FrameFiller_test(int version)
Frame filling.
unsigned char * QRinput_getByteStream(QRinput *input)
Pack all bit streams padding bits into a byte array.
Definition: qrinput.c:1326
int QRspec_getRemainder(int version)
Return the numer of remainder bits.
Definition: qrspec.c:126
unsigned char * QRspec_newFrame(int version)
Frame.
Definition: qrspec.c:509
int QRspec_getWidth(int version)
Return the width of the symbol for the version.
Definition: qrspec.c:121
int QRspec_getECCLength(int version, QRecLevel level)
Return maximum error correction code length (bytes) for the version.
Definition: qrspec.c:103
void QRspec_getEccSpec(int version, QRecLevel level, int spec[5])
Error correction code.
Definition: qrspec.c:234
int QRspec_getDataLength(int version, QRecLevel level)
Return maximum data code length (bytes) for the version.
Definition: qrspec.c:98
#define QRspec_rsDataCodes1(__spec__)
Definition: qrspec.h:110
#define QRspec_rsDataCodes2(__spec__)
Definition: qrspec.h:113
#define QRspec_rsBlockNum1(__spec__)
Definition: qrspec.h:109
#define QRspec_rsBlockNum2(__spec__)
Definition: qrspec.h:112
#define QRspec_rsBlockNum(__spec__)
Definition: qrspec.h:108
#define QRspec_rsEccCodes1(__spec__)
Definition: qrspec.h:111
#define QRspec_rsEccLength(__spec__)
Definition: qrspec.h:119
#define QRspec_rsEccCodes2(__spec__)
Definition: qrspec.h:114
#define QRspec_rsDataLength(__spec__)
Definition: qrspec.h:116
int RSECC_encode(size_t data_length, size_t ecc_length, const unsigned char *data, unsigned char *ecc)
Definition: rsecc.c:105
int Split_splitStringToQRinput(const char *string, QRinput *input, QRencodeMode hint, int casesensitive)
Split the input string (null terminated) into QRinput.
Definition: split.c:303
Frame filling.
Definition: qrencode.c:278
unsigned char * frame
Definition: qrencode.c:280
Raw code for Micro QR Code.
Definition: qrencode.c:194
int oddbits
Definition: qrencode.c:201
int version
Definition: qrencode.c:195
unsigned char * datacode
Definition: qrencode.c:198
int eccLength
Definition: qrencode.c:197
int count
Definition: qrencode.c:202
RSblock * rsblock
Definition: qrencode.c:200
int dataLength
Definition: qrencode.c:196
unsigned char * ecccode
Definition: qrencode.c:199
int b1
Definition: qrencode.c:56
int dataLength
Definition: qrencode.c:52
unsigned char * ecccode
Definition: qrencode.c:55
unsigned char * datacode
Definition: qrencode.c:54
int blocks
Definition: qrencode.c:57
RSblock * rsblock
Definition: qrencode.c:58
int eccLength
Definition: qrencode.c:53
int count
Definition: qrencode.c:59
int version
Definition: qrencode.c:51
QRcode output (qrencode.c)
Definition: qrencode.h:375
int width
width of the symbol
Definition: qrencode.h:377
int version
version of the symbol
Definition: qrencode.h:376
unsigned char * data
symbol data
Definition: qrencode.h:378
Raw code.
Definition: qrencode.c:43
unsigned char * ecc
Definition: qrencode.c:47
unsigned char * data
Definition: qrencode.c:46
int dataLength
Definition: qrencode.c:44
int eccLength
Definition: qrencode.c:45
Singly-linked list of QRcode.
Definition: qrencode.h:385
QRcode * code
Definition: qrencode.h:386
struct _QRcode_List * next
Definition: qrencode.h:387
QRinput_InputList * next
Definition: qrinput.h:63
QRinput * input
Definition: qrinput.h:62
QRinput_InputList * head
Definition: qrinput.h:69
Input Data.
Definition: qrinput.h:46
int mqr
Definition: qrinput.h:51
int version
Definition: qrinput.h:47
QRecLevel level
Definition: qrinput.h:48