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.

306 lines
9.5 KiB

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