You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
9.2 KiB

  1. --- a/configure.ac
  2. +++ b/configure.ac
  3. @@ -58,9 +58,6 @@
  4. [build_tools=$withval], [build_tools=yes])
  5. AM_CONDITIONAL(BUILD_TOOLS, [test "x$build_tools" = "xyes" ])
  6. -if test x$build_tools = xyes ; then
  7. - PKG_CHECK_MODULES(png, "libpng")
  8. -fi
  9. dnl --with-tests
  10. AC_ARG_WITH([tests], [AS_HELP_STRING([--with-tests], [build tests [default=no]])],
  11. --- a/qrenc.c
  12. +++ b/qrenc.c
  13. @@ -25,7 +25,6 @@
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. -#include <png.h>
  18. #include <getopt.h>
  19. #include "qrencode.h"
  20. @@ -49,7 +48,6 @@
  21. static int verbose = 0;
  22. enum imageType {
  23. - PNG_TYPE,
  24. EPS_TYPE,
  25. SVG_TYPE,
  26. ANSI_TYPE,
  27. @@ -60,7 +58,7 @@
  28. ANSIUTF8_TYPE
  29. };
  30. -static enum imageType image_type = PNG_TYPE;
  31. +static enum imageType image_type = SVG_TYPE;
  32. static const struct option options[] = {
  33. {"help" , no_argument , NULL, 'h'},
  34. @@ -96,13 +94,13 @@
  35. if(longopt) {
  36. fprintf(stderr,
  37. "Usage: qrencode [OPTION]... [STRING]\n"
  38. -"Encode input data in a QR Code and save as a PNG or EPS image.\n\n"
  39. +"Encode input data in a QR Code and save as a SVG or EPS image.\n\n"
  40. " -h, --help display the help message. -h displays only the help of short\n"
  41. " options.\n\n"
  42. " -o FILENAME, --output=FILENAME\n"
  43. " write image to FILENAME. If '-' is specified, the result\n"
  44. " will be output to standard output. If -S is given, structured\n"
  45. -" symbols are written to FILENAME-01.png, FILENAME-02.png, ...\n"
  46. +" symbols are written to FILENAME-01.svg, FILENAME-02.svg, ...\n"
  47. " (suffix is removed from FILENAME, if specified)\n"
  48. " -s NUMBER, --size=NUMBER\n"
  49. " specify module size in dots (pixels). (default=3)\n\n"
  50. @@ -116,9 +114,9 @@
  51. " specify the width of the margins. (default=4 (2 for Micro QR)))\n\n"
  52. " -d NUMBER, --dpi=NUMBER\n"
  53. " specify the DPI of the generated PNG. (default=72)\n\n"
  54. -" -t {PNG,EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}, --type={PNG,EPS,\n"
  55. +" -t {EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}, --type={EPS,\n"
  56. " SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}\n"
  57. -" specify the type of the generated image. (default=PNG)\n\n"
  58. +" specify the type of the generated image. (default=SVG)\n\n"
  59. " -S, --structured\n"
  60. " make structured symbols. Version must be specified.\n\n"
  61. " -k, --kanji assume that the input text contains kanji (shift-jis).\n\n"
  62. @@ -133,7 +131,7 @@
  63. " --background=RRGGBB[AA]\n"
  64. " specify foreground/background color in hexadecimal notation.\n"
  65. " 6-digit (RGB) or 8-digit (RGBA) form are supported.\n"
  66. -" Color output support available only in PNG and SVG.\n"
  67. +" Color output support available only in SVG.\n"
  68. " -V, --version\n"
  69. " display the version number and copyrights of the qrencode.\n\n"
  70. " --verbose\n"
  71. @@ -153,12 +151,12 @@
  72. } else {
  73. fprintf(stderr,
  74. "Usage: qrencode [OPTION]... [STRING]\n"
  75. -"Encode input data in a QR Code and save as a PNG or EPS image.\n\n"
  76. +"Encode input data in a QR Code and save as a SVG or EPS image.\n\n"
  77. " -h display this message.\n"
  78. " --help display the usage of long options.\n"
  79. " -o FILENAME write image to FILENAME. If '-' is specified, the result\n"
  80. " will be output to standard output. If -S is given, structured\n"
  81. -" symbols are written to FILENAME-01.png, FILENAME-02.png, ...\n"
  82. +" symbols are written to FILENAME-01.svg, FILENAME-02.svg, ...\n"
  83. " (suffix is removed from FILENAME, if specified)\n"
  84. " -s NUMBER specify module size in dots (pixels). (default=3)\n"
  85. " -l {LMQH} specify error correction level from L (lowest) to H (highest).\n"
  86. @@ -166,8 +164,8 @@
  87. " -v NUMBER specify the version of the symbol. (default=auto)\n"
  88. " -m NUMBER specify the width of the margins. (default=4 (2 for Micro))\n"
  89. " -d NUMBER specify the DPI of the generated PNG. (default=72)\n"
  90. -" -t {PNG,EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}\n"
  91. -" specify the type of the generated image. (default=PNG)\n"
  92. +" -t {EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}\n"
  93. +" specify the type of the generated image. (default=SVG)\n"
  94. " -S make structured symbols. Version must be specified.\n"
  95. " -k assume that the input text contains kanji (shift-jis).\n"
  96. " -c encode lower-case alphabet characters in 8-bit mode. (default)\n"
  97. @@ -178,7 +176,7 @@
  98. " --background=RRGGBB[AA]\n"
  99. " specify foreground/background color in hexadecimal notation.\n"
  100. " 6-digit (RGB) or 8-digit (RGBA) form are supported.\n"
  101. -" Color output support available only in PNG and SVG.\n"
  102. +" Color output support available only in SVG.\n"
  103. " -V display the version number and copyrights of the qrencode.\n"
  104. " [STRING] input data. If it is not specified, data will be taken from\n"
  105. " standard input.\n"
  106. @@ -253,128 +251,6 @@
  107. return fp;
  108. }
  109. -static int writePNG(QRcode *qrcode, const char *outfile)
  110. -{
  111. - static FILE *fp; // avoid clobbering by setjmp.
  112. - png_structp png_ptr;
  113. - png_infop info_ptr;
  114. - png_colorp palette;
  115. - png_byte alpha_values[2];
  116. - unsigned char *row, *p, *q;
  117. - int x, y, xx, yy, bit;
  118. - int realwidth;
  119. -
  120. - realwidth = (qrcode->width + margin * 2) * size;
  121. - row = (unsigned char *)malloc((realwidth + 7) / 8);
  122. - if(row == NULL) {
  123. - fprintf(stderr, "Failed to allocate memory.\n");
  124. - exit(EXIT_FAILURE);
  125. - }
  126. -
  127. - if(outfile[0] == '-' && outfile[1] == '\0') {
  128. - fp = stdout;
  129. - } else {
  130. - fp = fopen(outfile, "wb");
  131. - if(fp == NULL) {
  132. - fprintf(stderr, "Failed to create file: %s\n", outfile);
  133. - perror(NULL);
  134. - exit(EXIT_FAILURE);
  135. - }
  136. - }
  137. -
  138. - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  139. - if(png_ptr == NULL) {
  140. - fprintf(stderr, "Failed to initialize PNG writer.\n");
  141. - exit(EXIT_FAILURE);
  142. - }
  143. -
  144. - info_ptr = png_create_info_struct(png_ptr);
  145. - if(info_ptr == NULL) {
  146. - fprintf(stderr, "Failed to initialize PNG write.\n");
  147. - exit(EXIT_FAILURE);
  148. - }
  149. -
  150. - if(setjmp(png_jmpbuf(png_ptr))) {
  151. - png_destroy_write_struct(&png_ptr, &info_ptr);
  152. - fprintf(stderr, "Failed to write PNG image.\n");
  153. - exit(EXIT_FAILURE);
  154. - }
  155. -
  156. - palette = (png_colorp) malloc(sizeof(png_color) * 2);
  157. - if(palette == NULL) {
  158. - fprintf(stderr, "Failed to allocate memory.\n");
  159. - exit(EXIT_FAILURE);
  160. - }
  161. - palette[0].red = fg_color[0];
  162. - palette[0].green = fg_color[1];
  163. - palette[0].blue = fg_color[2];
  164. - palette[1].red = bg_color[0];
  165. - palette[1].green = bg_color[1];
  166. - palette[1].blue = bg_color[2];
  167. - alpha_values[0] = fg_color[3];
  168. - alpha_values[1] = bg_color[3];
  169. - png_set_PLTE(png_ptr, info_ptr, palette, 2);
  170. - png_set_tRNS(png_ptr, info_ptr, alpha_values, 2, NULL);
  171. -
  172. - png_init_io(png_ptr, fp);
  173. - png_set_IHDR(png_ptr, info_ptr,
  174. - realwidth, realwidth,
  175. - 1,
  176. - PNG_COLOR_TYPE_PALETTE,
  177. - PNG_INTERLACE_NONE,
  178. - PNG_COMPRESSION_TYPE_DEFAULT,
  179. - PNG_FILTER_TYPE_DEFAULT);
  180. - png_set_pHYs(png_ptr, info_ptr,
  181. - dpi * INCHES_PER_METER,
  182. - dpi * INCHES_PER_METER,
  183. - PNG_RESOLUTION_METER);
  184. - png_write_info(png_ptr, info_ptr);
  185. -
  186. - /* top margin */
  187. - memset(row, 0xff, (realwidth + 7) / 8);
  188. - for(y=0; y<margin * size; y++) {
  189. - png_write_row(png_ptr, row);
  190. - }
  191. -
  192. - /* data */
  193. - p = qrcode->data;
  194. - for(y=0; y<qrcode->width; y++) {
  195. - bit = 7;
  196. - memset(row, 0xff, (realwidth + 7) / 8);
  197. - q = row;
  198. - q += margin * size / 8;
  199. - bit = 7 - (margin * size % 8);
  200. - for(x=0; x<qrcode->width; x++) {
  201. - for(xx=0; xx<size; xx++) {
  202. - *q ^= (*p & 1) << bit;
  203. - bit--;
  204. - if(bit < 0) {
  205. - q++;
  206. - bit = 7;
  207. - }
  208. - }
  209. - p++;
  210. - }
  211. - for(yy=0; yy<size; yy++) {
  212. - png_write_row(png_ptr, row);
  213. - }
  214. - }
  215. - /* bottom margin */
  216. - memset(row, 0xff, (realwidth + 7) / 8);
  217. - for(y=0; y<margin * size; y++) {
  218. - png_write_row(png_ptr, row);
  219. - }
  220. -
  221. - png_write_end(png_ptr, info_ptr);
  222. - png_destroy_write_struct(&png_ptr, &info_ptr);
  223. -
  224. - fclose(fp);
  225. - free(row);
  226. - free(palette);
  227. -
  228. - return 0;
  229. -}
  230. -
  231. static int writeEPS(QRcode *qrcode, const char *outfile)
  232. {
  233. FILE *fp;
  234. @@ -831,9 +707,6 @@
  235. }
  236. switch(image_type) {
  237. - case PNG_TYPE:
  238. - writePNG(qrcode, outfile);
  239. - break;
  240. case EPS_TYPE:
  241. writeEPS(qrcode, outfile);
  242. break;
  243. @@ -887,9 +760,6 @@
  244. size_t suffix_size;
  245. switch(image_type) {
  246. - case PNG_TYPE:
  247. - type_suffix = ".png";
  248. - break;
  249. case EPS_TYPE:
  250. type_suffix = ".eps";
  251. break;
  252. @@ -948,9 +818,6 @@
  253. }
  254. switch(image_type) {
  255. - case PNG_TYPE:
  256. - writePNG(p->code, filename);
  257. - break;
  258. case EPS_TYPE:
  259. writeEPS(p->code, filename);
  260. break;
  261. @@ -1062,9 +929,7 @@
  262. }
  263. break;
  264. case 't':
  265. - if(strcasecmp(optarg, "png") == 0) {
  266. - image_type = PNG_TYPE;
  267. - } else if(strcasecmp(optarg, "eps") == 0) {
  268. + if(strcasecmp(optarg, "eps") == 0) {
  269. image_type = EPS_TYPE;
  270. } else if(strcasecmp(optarg, "svg") == 0) {
  271. image_type = SVG_TYPE;
  272. @@ -1133,11 +998,6 @@
  273. exit(EXIT_SUCCESS);
  274. }
  275. - if(outfile == NULL && image_type == PNG_TYPE) {
  276. - fprintf(stderr, "No output filename is given.\n");
  277. - exit(EXIT_FAILURE);
  278. - }
  279. -
  280. if(optind < argc) {
  281. intext = (unsigned char *)argv[optind];
  282. length = strlen((char *)intext);