12 static int verbose = 0;
23 -static enum imageType image_type = PNG_TYPE;
24 +static enum imageType image_type = SVG_TYPE;
26 static const struct option options[] = {
27 {"help" , no_argument , NULL, 'h'},
31 "Usage: qrencode [OPTION]... [STRING]\n"
32 -"Encode input data in a QR Code and save as a PNG or EPS image.\n\n"
33 +"Encode input data in a QR Code and save as a SVG or EPS image.\n\n"
34 " -h, --help display the help message. -h displays only the help of short\n"
36 " -o FILENAME, --output=FILENAME\n"
37 " write image to FILENAME. If '-' is specified, the result\n"
38 " will be output to standard output. If -S is given, structured\n"
39 -" symbols are written to FILENAME-01.png, FILENAME-02.png, ...\n"
40 +" symbols are written to FILENAME-01.svg, FILENAME-02.svg, ...\n"
41 " (suffix is removed from FILENAME, if specified)\n"
42 " -s NUMBER, --size=NUMBER\n"
43 " specify module size in dots (pixels). (default=3)\n\n"
45 " specify the width of the margins. (default=4 (2 for Micro QR)))\n\n"
46 " -d NUMBER, --dpi=NUMBER\n"
47 " specify the DPI of the generated PNG. (default=72)\n\n"
48 -" -t {PNG,EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}, --type={PNG,EPS,\n"
49 +" -t {EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}, --type={EPS,\n"
50 " SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}\n"
51 -" specify the type of the generated image. (default=PNG)\n\n"
52 +" specify the type of the generated image. (default=SVG)\n\n"
54 " make structured symbols. Version must be specified.\n\n"
55 " -k, --kanji assume that the input text contains kanji (shift-jis).\n\n"
57 " --background=RRGGBB[AA]\n"
58 " specify foreground/background color in hexadecimal notation.\n"
59 " 6-digit (RGB) or 8-digit (RGBA) form are supported.\n"
60 -" Color output support available only in PNG and SVG.\n"
61 +" Color output support available only in SVG.\n"
63 " display the version number and copyrights of the qrencode.\n\n"
68 "Usage: qrencode [OPTION]... [STRING]\n"
69 -"Encode input data in a QR Code and save as a PNG or EPS image.\n\n"
70 +"Encode input data in a QR Code and save as a SVG or EPS image.\n\n"
71 " -h display this message.\n"
72 " --help display the usage of long options.\n"
73 " -o FILENAME write image to FILENAME. If '-' is specified, the result\n"
74 " will be output to standard output. If -S is given, structured\n"
75 -" symbols are written to FILENAME-01.png, FILENAME-02.png, ...\n"
76 +" symbols are written to FILENAME-01.svg, FILENAME-02.svg, ...\n"
77 " (suffix is removed from FILENAME, if specified)\n"
78 " -s NUMBER specify module size in dots (pixels). (default=3)\n"
79 " -l {LMQH} specify error correction level from L (lowest) to H (highest).\n"
81 " -v NUMBER specify the version of the symbol. (default=auto)\n"
82 " -m NUMBER specify the width of the margins. (default=4 (2 for Micro))\n"
83 " -d NUMBER specify the DPI of the generated PNG. (default=72)\n"
84 -" -t {PNG,EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}\n"
85 -" specify the type of the generated image. (default=PNG)\n"
86 +" -t {EPS,SVG,ANSI,ANSI256,ASCII,ASCIIi,UTF8,ANSIUTF8}\n"
87 +" specify the type of the generated image. (default=SVG)\n"
88 " -S make structured symbols. Version must be specified.\n"
89 " -k assume that the input text contains kanji (shift-jis).\n"
90 " -c encode lower-case alphabet characters in 8-bit mode. (default)\n"
92 " --background=RRGGBB[AA]\n"
93 " specify foreground/background color in hexadecimal notation.\n"
94 " 6-digit (RGB) or 8-digit (RGBA) form are supported.\n"
95 -" Color output support available only in PNG and SVG.\n"
96 +" Color output support available only in SVG.\n"
97 " -V display the version number and copyrights of the qrencode.\n"
98 " [STRING] input data. If it is not specified, data will be taken from\n"
100 @@ -253,128 +251,6 @@
104 -static int writePNG(QRcode *qrcode, const char *outfile)
106 - static FILE *fp; // avoid clobbering by setjmp.
107 - png_structp png_ptr;
108 - png_infop info_ptr;
109 - png_colorp palette;
110 - png_byte alpha_values[2];
111 - unsigned char *row, *p, *q;
112 - int x, y, xx, yy, bit;
115 - realwidth = (qrcode->width + margin * 2) * size;
116 - row = (unsigned char *)malloc((realwidth + 7) / 8);
118 - fprintf(stderr, "Failed to allocate memory.\n");
119 - exit(EXIT_FAILURE);
122 - if(outfile[0] == '-' && outfile[1] == '\0') {
125 - fp = fopen(outfile, "wb");
127 - fprintf(stderr, "Failed to create file: %s\n", outfile);
129 - exit(EXIT_FAILURE);
133 - png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
134 - if(png_ptr == NULL) {
135 - fprintf(stderr, "Failed to initialize PNG writer.\n");
136 - exit(EXIT_FAILURE);
139 - info_ptr = png_create_info_struct(png_ptr);
140 - if(info_ptr == NULL) {
141 - fprintf(stderr, "Failed to initialize PNG write.\n");
142 - exit(EXIT_FAILURE);
145 - if(setjmp(png_jmpbuf(png_ptr))) {
146 - png_destroy_write_struct(&png_ptr, &info_ptr);
147 - fprintf(stderr, "Failed to write PNG image.\n");
148 - exit(EXIT_FAILURE);
151 - palette = (png_colorp) malloc(sizeof(png_color) * 2);
152 - if(palette == NULL) {
153 - fprintf(stderr, "Failed to allocate memory.\n");
154 - exit(EXIT_FAILURE);
156 - palette[0].red = fg_color[0];
157 - palette[0].green = fg_color[1];
158 - palette[0].blue = fg_color[2];
159 - palette[1].red = bg_color[0];
160 - palette[1].green = bg_color[1];
161 - palette[1].blue = bg_color[2];
162 - alpha_values[0] = fg_color[3];
163 - alpha_values[1] = bg_color[3];
164 - png_set_PLTE(png_ptr, info_ptr, palette, 2);
165 - png_set_tRNS(png_ptr, info_ptr, alpha_values, 2, NULL);
167 - png_init_io(png_ptr, fp);
168 - png_set_IHDR(png_ptr, info_ptr,
169 - realwidth, realwidth,
171 - PNG_COLOR_TYPE_PALETTE,
172 - PNG_INTERLACE_NONE,
173 - PNG_COMPRESSION_TYPE_DEFAULT,
174 - PNG_FILTER_TYPE_DEFAULT);
175 - png_set_pHYs(png_ptr, info_ptr,
176 - dpi * INCHES_PER_METER,
177 - dpi * INCHES_PER_METER,
178 - PNG_RESOLUTION_METER);
179 - png_write_info(png_ptr, info_ptr);
182 - memset(row, 0xff, (realwidth + 7) / 8);
183 - for(y=0; y<margin * size; y++) {
184 - png_write_row(png_ptr, row);
189 - for(y=0; y<qrcode->width; y++) {
191 - memset(row, 0xff, (realwidth + 7) / 8);
193 - q += margin * size / 8;
194 - bit = 7 - (margin * size % 8);
195 - for(x=0; x<qrcode->width; x++) {
196 - for(xx=0; xx<size; xx++) {
197 - *q ^= (*p & 1) << bit;
206 - for(yy=0; yy<size; yy++) {
207 - png_write_row(png_ptr, row);
210 - /* bottom margin */
211 - memset(row, 0xff, (realwidth + 7) / 8);
212 - for(y=0; y<margin * size; y++) {
213 - png_write_row(png_ptr, row);
216 - png_write_end(png_ptr, info_ptr);
217 - png_destroy_write_struct(&png_ptr, &info_ptr);
226 static int writeEPS(QRcode *qrcode, const char *outfile)
234 - writePNG(qrcode, outfile);
237 writeEPS(qrcode, outfile);
244 - type_suffix = ".png";
247 type_suffix = ".eps";
254 - writePNG(p->code, filename);
257 writeEPS(p->code, filename);
263 - if(strcasecmp(optarg, "png") == 0) {
264 - image_type = PNG_TYPE;
265 - } else if(strcasecmp(optarg, "eps") == 0) {
266 + if(strcasecmp(optarg, "eps") == 0) {
267 image_type = EPS_TYPE;
268 } else if(strcasecmp(optarg, "svg") == 0) {
269 image_type = SVG_TYPE;
270 @@ -1133,11 +998,6 @@
274 - if(outfile == NULL && image_type == PNG_TYPE) {
275 - fprintf(stderr, "No output filename is given.\n");
276 - exit(EXIT_FAILURE);
280 intext = (unsigned char *)argv[optind];
281 length = strlen((char *)intext);
285 [build_tools=$withval], [build_tools=yes])
287 AM_CONDITIONAL(BUILD_TOOLS, [test "x$build_tools" = "xyes" ])
288 -if test x$build_tools = xyes ; then
289 - PKG_CHECK_MODULES(png, "libpng")
293 AC_ARG_WITH([tests], [AS_HELP_STRING([--with-tests], [build tests [default=no]])],
295 echo "/* #undef WITH_TESTS */" >>confdefs.h
298 -if test x$build_tests = xyes ; then
299 - SDL_REQUIRED_VERSION=1.2.0
300 - AM_PATH_SDL($SDL_REQUIRED_VERSION,,AC_MSG_WARN([*** SDL $SDL_REQUIRED_VERSION or better is required.]))
301 - AC_MSG_NOTICE([SDL check done.])
304 AM_CONDITIONAL(HAVE_SDL, [test "x$SDL_CFLAGS" != "x" ])