comparison src/libharu-1-fixes.patch @ 2235:29d81342a180

package libharu: libpng 1.5 compatibility
author Mark Brand <mabrand@mabrand.nl>
date Fri, 03 Feb 2012 15:50:23 +0100
parents
children 158396fb40ff
comparison
equal deleted inserted replaced
2234:109d622402db 2235:29d81342a180
1 # This file is part of mingw-cross-env.
2 # See doc/index.html for further information.
3
4 From 531d2a9af8c51ad8badc32bc9ba43bb3b87b0e9f Mon Sep 17 00:00:00 2001
5 From: Antony Dovgal <tony@daylessday.org>
6 Date: Mon, 10 Jan 2011 01:22:14 +0300
7 Subject: [PATCH] fix build with libpng 1.5.0 (reported by Tamas Tevesz)
8 (cherry picked from commit
9 e5bf8b01f6c3d5e3fe0e26ac5345e0da10c03934)
10
11 Conflicts:
12
13 CHANGES
14 ---
15 src/hpdf_image_png.c | 109 +++++++++++++++++++++++++++-----------------------
16 1 files changed, 59 insertions(+), 50 deletions(-)
17
18 diff --git a/src/hpdf_image_png.c b/src/hpdf_image_png.c
19 index b8f831e..6057424 100644
20 --- a/src/hpdf_image_png.c
21 +++ b/src/hpdf_image_png.c
22 @@ -109,14 +109,15 @@ ReadPngData_Interlaced (HPDF_Dict image,
23 png_infop info_ptr)
24 {
25 png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
26 + png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
27 png_bytep* row_pointers = HPDF_GetMem (image->mmgr,
28 - info_ptr->height * sizeof (png_bytep));
29 + height * sizeof (png_bytep));
30
31 if (row_pointers) {
32 HPDF_UINT i;
33
34 - HPDF_MemSet (row_pointers, 0, info_ptr->height * sizeof (png_bytep));
35 - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
36 + HPDF_MemSet (row_pointers, 0, height * sizeof (png_bytep));
37 + for (i = 0; i < (HPDF_UINT)height; i++) {
38 row_pointers[i] = HPDF_GetMem (image->mmgr, len);
39
40 if (image->error->error_no != HPDF_OK)
41 @@ -126,7 +127,7 @@ ReadPngData_Interlaced (HPDF_Dict image,
42 if (image->error->error_no == HPDF_OK) {
43 png_read_image(png_ptr, row_pointers);
44 if (image->error->error_no == HPDF_OK) { /* add this line */
45 - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
46 + for (i = 0; i < (HPDF_UINT)height; i++) {
47 if (HPDF_Stream_Write (image->stream, row_pointers[i], len) !=
48 HPDF_OK)
49 break;
50 @@ -135,7 +136,7 @@ ReadPngData_Interlaced (HPDF_Dict image,
51 }
52
53 /* clean up */
54 - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
55 + for (i = 0; i < (HPDF_UINT)height; i++) {
56 HPDF_FreeMem (image->mmgr, row_pointers[i]);
57 }
58
59 @@ -151,12 +152,13 @@ ReadPngData (HPDF_Dict image,
60 png_infop info_ptr)
61 {
62 png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
63 + png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
64 png_bytep buf_ptr = HPDF_GetMem (image->mmgr, len);
65
66 if (buf_ptr) {
67 HPDF_UINT i;
68
69 - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
70 + for (i = 0; i < (HPDF_UINT)height; i++) {
71 png_read_rows(png_ptr, (png_byte**)&buf_ptr, NULL, 1);
72 if (image->error->error_no != HPDF_OK)
73 break;
74 @@ -182,14 +184,16 @@ ReadTransparentPaletteData (HPDF_Dict image,
75 HPDF_STATUS ret = HPDF_OK;
76 HPDF_UINT i, j;
77 png_bytep *row_ptr;
78 + png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
79 + png_uint_32 width = png_get_image_width(png_ptr, info_ptr);
80
81 - row_ptr = HPDF_GetMem (image->mmgr, info_ptr->height * sizeof(png_bytep));
82 + row_ptr = HPDF_GetMem (image->mmgr, height * sizeof(png_bytep));
83 if (!row_ptr) {
84 return HPDF_FAILD_TO_ALLOC_MEM;
85 } else {
86 png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
87
88 - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
89 + for (i = 0; i < (HPDF_UINT)height; i++) {
90 row_ptr[i] = HPDF_GetMem(image->mmgr, len);
91 if (!row_ptr[i]) {
92 for (; i >= 0; i--) {
93 @@ -207,19 +211,19 @@ ReadTransparentPaletteData (HPDF_Dict image,
94 goto Error;
95 }
96
97 - for (j = 0; j < info_ptr->height; j++) {
98 - for (i = 0; i < info_ptr->width; i++) {
99 - smask_data[info_ptr->width * j + i] = (row_ptr[j][i] < num_trans) ? trans[row_ptr[j][i]] : 0xFF;
100 + for (j = 0; j < height; j++) {
101 + for (i = 0; i < width; i++) {
102 + smask_data[width * j + i] = (row_ptr[j][i] < num_trans) ? trans[row_ptr[j][i]] : 0xFF;
103 }
104
105 - if (HPDF_Stream_Write (image->stream, row_ptr[j], info_ptr->width) != HPDF_OK) {
106 + if (HPDF_Stream_Write (image->stream, row_ptr[j], width) != HPDF_OK) {
107 ret = HPDF_FILE_IO_ERROR;
108 goto Error;
109 }
110 }
111
112 Error:
113 - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
114 + for (i = 0; i < (HPDF_UINT)height; i++) {
115 HPDF_FreeMem (image->mmgr, row_ptr[i]);
116 }
117
118 @@ -238,6 +242,8 @@ ReadTransparentPngData (HPDF_Dict image,
119 HPDF_UINT i, j;
120 png_bytep *row_ptr, row;
121 png_byte color_type;
122 + png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
123 + png_uint_32 width = png_get_image_width(png_ptr, info_ptr);
124
125 color_type = png_get_color_type(png_ptr, info_ptr);
126
127 @@ -245,13 +251,13 @@ ReadTransparentPngData (HPDF_Dict image,
128 return HPDF_INVALID_PNG_IMAGE;
129 }
130
131 - row_ptr = HPDF_GetMem (image->mmgr, info_ptr->height * sizeof(png_bytep));
132 + row_ptr = HPDF_GetMem (image->mmgr, height * sizeof(png_bytep));
133 if (!row_ptr) {
134 return HPDF_FAILD_TO_ALLOC_MEM;
135 } else {
136 png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
137
138 - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
139 + for (i = 0; i < (HPDF_UINT)height; i++) {
140 row_ptr[i] = HPDF_GetMem(image->mmgr, len);
141 if (!row_ptr[i]) {
142 for (; i >= 0; i--) {
143 @@ -271,12 +277,12 @@ ReadTransparentPngData (HPDF_Dict image,
144
145 switch (color_type) {
146 case PNG_COLOR_TYPE_RGB_ALPHA:
147 - row_len = 3 * info_ptr->width * sizeof(png_byte);
148 - for (j = 0; j < info_ptr->height; j++) {
149 - for (i = 0; i < info_ptr->width; i++) {
150 + row_len = 3 * width * sizeof(png_byte);
151 + for (j = 0; j < height; j++) {
152 + for (i = 0; i < width; i++) {
153 row = row_ptr[j];
154 memmove(row + (3 * i), row + (4*i), 3);
155 - smask_data[info_ptr->width * j + i] = row[4 * i + 3];
156 + smask_data[width * j + i] = row[4 * i + 3];
157 }
158
159 if (HPDF_Stream_Write (image->stream, row, row_len) != HPDF_OK) {
160 @@ -286,12 +292,12 @@ ReadTransparentPngData (HPDF_Dict image,
161 }
162 break;
163 case PNG_COLOR_TYPE_GRAY_ALPHA:
164 - row_len = info_ptr->width * sizeof(png_byte);
165 - for (j = 0; j < info_ptr->height; j++) {
166 - for (i = 0; i < info_ptr->width; i++) {
167 + row_len = width * sizeof(png_byte);
168 + for (j = 0; j < height; j++) {
169 + for (i = 0; i < width; i++) {
170 row = row_ptr[j];
171 row[i] = row[2 * i];
172 - smask_data[info_ptr->width * j + i] = row[2 * i + 1];
173 + smask_data[width * j + i] = row[2 * i + 1];
174 }
175
176 if (HPDF_Stream_Write (image->stream, row, row_len) != HPDF_OK) {
177 @@ -306,7 +312,7 @@ ReadTransparentPngData (HPDF_Dict image,
178 }
179
180 Error:
181 - for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
182 + for (i = 0; i < (HPDF_UINT)height; i++) {
183 HPDF_FreeMem (image->mmgr, row_ptr[i]);
184 }
185
186 @@ -415,7 +421,8 @@ LoadPngData (HPDF_Dict image,
187
188 {
189 HPDF_STATUS ret = HPDF_OK;
190 -
191 + png_uint_32 width, height;
192 + int bit_depth, color_type;
193 png_structp png_ptr = NULL;
194 png_infop info_ptr = NULL;
195
196 @@ -447,8 +454,10 @@ LoadPngData (HPDF_Dict image,
197 goto Exit;
198 }
199
200 + png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL);
201 +
202 /* 16bit images are not supported. */
203 - if (info_ptr->bit_depth == 16) {
204 + if (bit_depth == 16) {
205 png_set_strip_16(png_ptr);
206 }
207
208 @@ -458,7 +467,7 @@ LoadPngData (HPDF_Dict image,
209 }
210
211 /* check palette-based images for transparent areas and load them immediately if found */
212 - if (xref && PNG_COLOR_TYPE_PALETTE & info_ptr->color_type) {
213 + if (xref && PNG_COLOR_TYPE_PALETTE & color_type) {
214 png_bytep trans;
215 int num_trans;
216 HPDF_Dict smask;
217 @@ -478,10 +487,10 @@ LoadPngData (HPDF_Dict image,
218 smask->header.obj_class |= HPDF_OSUBCLASS_XOBJECT;
219 ret = HPDF_Dict_AddName (smask, "Type", "XObject");
220 ret += HPDF_Dict_AddName (smask, "Subtype", "Image");
221 - ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)info_ptr->width);
222 - ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)info_ptr->height);
223 + ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)width);
224 + ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)height);
225 ret += HPDF_Dict_AddName (smask, "ColorSpace", "DeviceGray");
226 - ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)info_ptr->bit_depth);
227 + ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)bit_depth);
228
229 if (ret != HPDF_OK) {
230 HPDF_Dict_Free(smask);
231 @@ -489,7 +498,7 @@ LoadPngData (HPDF_Dict image,
232 goto Exit;
233 }
234
235 - smask_data = HPDF_GetMem(image->mmgr, info_ptr->width * info_ptr->height);
236 + smask_data = HPDF_GetMem(image->mmgr, width * height);
237 if (!smask_data) {
238 HPDF_Dict_Free(smask);
239 ret = HPDF_FAILD_TO_ALLOC_MEM;
240 @@ -503,7 +512,7 @@ LoadPngData (HPDF_Dict image,
241 goto Exit;
242 }
243
244 - if (HPDF_Stream_Write(smask->stream, smask_data, info_ptr->width * info_ptr->height) != HPDF_OK) {
245 + if (HPDF_Stream_Write(smask->stream, smask_data, width * height) != HPDF_OK) {
246 HPDF_FreeMem(image->mmgr, smask_data);
247 HPDF_Dict_Free(smask);
248 ret = HPDF_FILE_IO_ERROR;
249 @@ -513,9 +522,9 @@ LoadPngData (HPDF_Dict image,
250
251
252 ret += CreatePallet(image, png_ptr, info_ptr);
253 - ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)info_ptr->width);
254 - ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)info_ptr->height);
255 - ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)info_ptr->bit_depth);
256 + ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width);
257 + ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height);
258 + ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)bit_depth);
259 ret += HPDF_Dict_Add (image, "SMask", smask);
260
261 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
262 @@ -526,7 +535,7 @@ no_transparent_color_in_palette:
263
264 /* read images with alpha channel right away
265 we have to do this because image transparent mask must be added to the Xref */
266 - if (xref && PNG_COLOR_MASK_ALPHA & info_ptr->color_type) {
267 + if (xref && PNG_COLOR_MASK_ALPHA & color_type) {
268 HPDF_Dict smask;
269 png_bytep smask_data;
270
271 @@ -539,10 +548,10 @@ no_transparent_color_in_palette:
272 smask->header.obj_class |= HPDF_OSUBCLASS_XOBJECT;
273 ret = HPDF_Dict_AddName (smask, "Type", "XObject");
274 ret += HPDF_Dict_AddName (smask, "Subtype", "Image");
275 - ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)info_ptr->width);
276 - ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)info_ptr->height);
277 + ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)width);
278 + ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)height);
279 ret += HPDF_Dict_AddName (smask, "ColorSpace", "DeviceGray");
280 - ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)info_ptr->bit_depth);
281 + ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)bit_depth);
282
283 if (ret != HPDF_OK) {
284 HPDF_Dict_Free(smask);
285 @@ -550,7 +559,7 @@ no_transparent_color_in_palette:
286 goto Exit;
287 }
288
289 - smask_data = HPDF_GetMem(image->mmgr, info_ptr->width * info_ptr->height);
290 + smask_data = HPDF_GetMem(image->mmgr, width * height);
291 if (!smask_data) {
292 HPDF_Dict_Free(smask);
293 ret = HPDF_FAILD_TO_ALLOC_MEM;
294 @@ -564,7 +573,7 @@ no_transparent_color_in_palette:
295 goto Exit;
296 }
297
298 - if (HPDF_Stream_Write(smask->stream, smask_data, info_ptr->width * info_ptr->height) != HPDF_OK) {
299 + if (HPDF_Stream_Write(smask->stream, smask_data, width * height) != HPDF_OK) {
300 HPDF_FreeMem(image->mmgr, smask_data);
301 HPDF_Dict_Free(smask);
302 ret = HPDF_FILE_IO_ERROR;
303 @@ -572,14 +581,14 @@ no_transparent_color_in_palette:
304 }
305 HPDF_FreeMem(image->mmgr, smask_data);
306
307 - if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
308 + if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
309 ret += HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray");
310 } else {
311 ret += HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB");
312 }
313 - ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)info_ptr->width);
314 - ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)info_ptr->height);
315 - ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)info_ptr->bit_depth);
316 + ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width);
317 + ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height);
318 + ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)bit_depth);
319 ret += HPDF_Dict_Add (image, "SMask", smask);
320
321 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
322 @@ -589,9 +598,9 @@ no_transparent_color_in_palette:
323 /* if the image has color palette, copy the pallet of the image to
324 * create color map.
325 */
326 - if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
327 + if (color_type == PNG_COLOR_TYPE_PALETTE)
328 ret = CreatePallet(image, png_ptr, info_ptr);
329 - else if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)
330 + else if (color_type == PNG_COLOR_TYPE_GRAY)
331 ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray");
332 else
333 ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB");
334 @@ -617,16 +626,16 @@ no_transparent_color_in_palette:
335 }
336
337 /* setting the info of the image. */
338 - if (HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)info_ptr->width)
339 + if (HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width)
340 != HPDF_OK)
341 goto Exit;
342
343 - if (HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)info_ptr->height)
344 + if (HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height)
345 != HPDF_OK)
346 goto Exit;
347
348 if (HPDF_Dict_AddNumber (image, "BitsPerComponent",
349 - (HPDF_UINT)info_ptr->bit_depth) != HPDF_OK)
350 + (HPDF_UINT)bit_depth) != HPDF_OK)
351 goto Exit;
352
353 /* clean up */
354 --
355 1.7.8.3
356