Package: qpxtool / 0.7.2-4.1

04-fix-build-with-libpng15.patch Patch series | download
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
Description: Fix FTBFS with libpng >= 1.4
Author: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Bug-Debian: http://bugs.debian.org/662481
            http://bugs.debian.org/648127
Last-Update: 2013-04-16

--- a/console/f1tattoo/f1tattoo.cpp
+++ b/console/f1tattoo/f1tattoo.cpp
@@ -81,6 +81,58 @@
 }
 
 #ifdef USE_LIBPNG
+static int my_png_get_image_width(png_structp png_ptr, png_infop info_ptr) {
+#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4 
+	return png_get_image_width(png_ptr, info_ptr);
+#else
+	return info_ptr->width;
+#endif
+}
+
+static int my_png_get_image_height(png_structp png_ptr, png_infop info_ptr) {
+#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4 
+	return png_get_image_height(png_ptr, info_ptr);
+#else
+	return info_ptr->height;
+#endif
+}
+
+static png_byte my_png_get_color_type(png_structp png_ptr, png_infop info_ptr)
+{
+#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4
+	return png_get_color_type(png_ptr, info_ptr);
+#else
+	return info_ptr->color_type;
+#endif
+}
+
+static png_uint_32 my_png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flags)
+{
+#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4
+	return png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE);
+#else
+	return (info_ptr->valid & flags);
+#endif
+}
+
+static int my_png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
+{
+#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4
+	return png_get_bit_depth(png_ptr, info_ptr);
+#else
+	return info_ptr->bit_depth;
+#endif
+}
+
+static int my_png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
+{
+#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4
+	return png_get_rowbytes(png_ptr, info_ptr);
+#else
+	return info_ptr->rowbytes;
+#endif
+}
+
 bool tattoo_read_png(unsigned char *buf, uint32_t rows, FILE *fp)
 {
 	png_byte	header[8];	// 8 is the maximum size that can be checked
@@ -95,6 +147,10 @@
 	uint32_t row, col;
 	int      c;
 	int32_t  r,g,b;
+	int num_palette;
+#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4
+	png_colorp palette;
+#endif
 
 	if (fread(header, 1, 8, fp) < 8) {
 		printf("Error reading PNG header\n");
@@ -129,9 +185,11 @@
 
 	png_read_info(png_ptr, info_ptr);
 
-	printf("Image size: %ld x %ld\n", info_ptr->width, info_ptr->height);
+	printf("Image size: %ld x %ld\n",
+					my_png_get_image_width(png_ptr, info_ptr),
+					my_png_get_image_height(png_ptr, info_ptr));
 
-	if (info_ptr->width != 3744U || info_ptr->height != rows ) {
+	if (my_png_get_image_width(png_ptr, info_ptr) != 3744U || my_png_get_image_height(png_ptr, info_ptr) != rows ) {
 		printf("Image should be 3744 x %d", rows);
 		return 1;
 	}
@@ -140,17 +198,21 @@
 //	height = info_ptr->height;
 //	bit_depth = info_ptr->bit_depth;
 
+#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4 
 	number_of_passes = png_set_interlace_handling(png_ptr);
+#else
+	number_of_passes = png_set_interlace_handling(png_ptr);
+#endif
 	png_read_update_info(png_ptr, info_ptr);
 
-	printf("Color type: [%d] ", info_ptr->color_type);
-	switch (info_ptr->color_type) {
+	printf("Color type: [%d] ", my_png_get_color_type(png_ptr, info_ptr));
+	switch (my_png_get_color_type(png_ptr, info_ptr)) {
 	    case PNG_COLOR_TYPE_GRAY:
 			printf("PNG_COLOR_TYPE_GRAY\n");
 			break;
 	    case PNG_COLOR_TYPE_PALETTE:
 			printf("PNG_COLOR_TYPE_PALETTE\n");
-			if (!(info_ptr->valid & PNG_INFO_PLTE)) {
+			if (!(my_png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE))) {
 				printf("PNG color type is indexed, but no palette found!");
 				goto err_read_png;
 			}
@@ -168,49 +230,64 @@
 			printf("unlnown PNG color type!\n");
 			goto err_read_png;
 	}
-	printf("Bit depth : %d\n", info_ptr->bit_depth);
-	if (info_ptr->bit_depth != 8) {
+	printf("Bit depth : %d\n", my_png_get_bit_depth(png_ptr, info_ptr));
+	if (my_png_get_bit_depth(png_ptr, info_ptr) != 8) {
 		printf("Unsupported bit depth!\n");
 		goto err_read_png;
 	}
-	if (info_ptr->valid & PNG_INFO_PLTE) {
-		printf("Palette   : %d colors\n", info_ptr->num_palette);
+
+#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4
+	png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
+#else
+	num_palette = info_ptr->num_palette;
+#endif
+	if (my_png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)) {
+		printf("Palette   : %d colors\n", num_palette);
 	} else {
 		printf("Palette   : NO\n");
 	}
-	printf("ROW bytes : %ld\n", info_ptr->rowbytes);
+	printf("ROW bytes : %ld\n", my_png_get_rowbytes(png_ptr, info_ptr));
 
 
 	raw_row_pointer = buf;
-	png_row_pointer = (png_byte*) malloc(info_ptr->rowbytes);
+	png_row_pointer = (png_byte*) malloc(my_png_get_rowbytes(png_ptr, info_ptr));
 	for (row=0; row<rows; row++) {
 		if (setjmp(png_jmpbuf(png_ptr))) {
 			printf("png_jmpbuf failed!\n");
 			goto err_read_png;
 		}
 		png_read_row(png_ptr, png_row_pointer, NULL);
-		if (info_ptr->width < 3744U)
+		if (my_png_get_image_width(png_ptr, info_ptr) < 3744U)
 			memset(raw_row_pointer, 0, 3744);
 
-		switch (info_ptr->color_type) {
+		switch (my_png_get_color_type(png_ptr, info_ptr)) {
 		    case PNG_COLOR_TYPE_GRAY:
-				for (col=0; col<info_ptr->width; col++) {
+				for (col=0; col<my_png_get_image_width(png_ptr, info_ptr); col++) {
 					raw_row_pointer[col] = png_row_pointer[col] ^ 0xFF;
 //					memcpy(raw_row_pointer, png_row_pointer, 3744);
 				}
 				break;
 		    case PNG_COLOR_TYPE_PALETTE:
-				for (col=0; col<info_ptr->width; col++) {
+				for (col=0; col<my_png_get_image_width(png_ptr, info_ptr); col++) {
 					c = png_row_pointer[col];
+#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4
+					r = palette[c].red;
+					g = palette[c].green;
+					b = palette[c].blue;
+#else
 					r = info_ptr->palette[c].red;
 					g = info_ptr->palette[c].green;
 					b = info_ptr->palette[c].blue;
+#endif
 					c = (r*11 + g*16 + b*5) / 32;
 					raw_row_pointer[col] = c ^ 0xFF;
 				}
+#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 4
+				png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
+#endif
 				break;
 		    case PNG_COLOR_TYPE_RGB:
-				for (col=0; col<info_ptr->width; col++) {
+				for (col=0; col< my_png_get_image_width(png_ptr, info_ptr); col++) {
 					r = png_row_pointer[col*3];
 					g = png_row_pointer[col*3+1];
 					b = png_row_pointer[col*3+2];
@@ -219,7 +296,7 @@
 				}
 				break;
 		    case PNG_COLOR_TYPE_RGB_ALPHA:
-				for (col=0; col<info_ptr->width; col++) {
+				for (col=0; col<my_png_get_image_width(png_ptr, info_ptr); col++) {
 					r = png_row_pointer[col*4];
 					g = png_row_pointer[col*4+1];
 					b = png_row_pointer[col*4+2];
@@ -228,7 +305,7 @@
 				}
 				break;
 		    case PNG_COLOR_TYPE_GRAY_ALPHA:
-				for (col=0; col<info_ptr->width; col++) {
+				for (col=0; col<my_png_get_image_width(png_ptr, info_ptr); col++) {
 					raw_row_pointer[col] = png_row_pointer[col*2] ^ 0xFF;
 				}
 				break;