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