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