]> git.pld-linux.org Git - packages/amsn.git/blame - amsn-libpng15.patch
- farsight to farstream patch from fedora
[packages/amsn.git] / amsn-libpng15.patch
CommitLineData
c8279b0a
AG
1http://pkgbuild.com/~ioni/libpng-1.5/amsn-0.98.4-libpng15.patch
2
3--- utils/TkCximage/src/CxImage/ximapng.cpp
4+++ utils/TkCximage/src/CxImage/ximapng.cpp
5@@ -15,7 +15,7 @@
6 void CxImagePNG::ima_png_error(png_struct *png_ptr, char *message)
7 {
8 strcpy(info.szLastError,message);
9- longjmp(png_ptr->jmpbuf, 1);
10+ longjmp(png_jmpbuf(png_ptr), 1);
11 }
12 ////////////////////////////////////////////////////////////////////////////////
13 #if CXIMAGE_SUPPORT_DECODE
14@@ -62,7 +62,7 @@
15 /* Set error handling if you are using the setjmp/longjmp method (this is
16 * the normal method of doing things with libpng). REQUIRED unless you
17 * set up your own error handlers in the png_create_read_struct() earlier. */
18- if (setjmp(png_ptr->jmpbuf)) {
19+ if (setjmp(png_jmpbuf(png_ptr))) {
20 /* Free all of the memory associated with the png_ptr and info_ptr */
21 delete [] row_pointers;
22 png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
23@@ -77,15 +77,15 @@
24 png_read_info(png_ptr, info_ptr);
25
26 if (info.nEscape == -1){
27- head.biWidth = info_ptr->width;
28- head.biHeight= info_ptr->height;
29+ head.biWidth = png_get_image_width(png_ptr, info_ptr);
30+ head.biHeight= png_get_image_height(png_ptr, info_ptr);
31 info.dwType = CXIMAGE_FORMAT_PNG;
32- longjmp(png_ptr->jmpbuf, 1);
33+ longjmp(png_jmpbuf(png_ptr), 1);
34 }
35
36 /* calculate new number of channels */
37 int channels=0;
38- switch(info_ptr->color_type){
39+ switch(png_get_color_type(png_ptr, info_ptr)){
40 case PNG_COLOR_TYPE_GRAY:
41 case PNG_COLOR_TYPE_PALETTE:
42 channels = 1;
43@@ -101,71 +101,76 @@
44 break;
45 default:
46 strcpy(info.szLastError,"unknown PNG color type");
47- longjmp(png_ptr->jmpbuf, 1);
48+ longjmp(png_jmpbuf(png_ptr), 1);
49 }
50
51 //find the right pixel depth used for cximage
52- int pixel_depth = info_ptr->pixel_depth;
53+#if MIGHT_BE_BUGGY
54+ int pixel_depth = png_get_pixel_depth(png_ptr, info_ptr);
55 if (channels == 1 && pixel_depth>8) pixel_depth=8;
56+#endif
57+ int pixel_depth;
58+ if (channels == 1) pixel_depth=8;
59 if (channels == 2) pixel_depth=8;
60 if (channels >= 3) pixel_depth=24;
61
62- if (!Create(info_ptr->width, info_ptr->height, pixel_depth, CXIMAGE_FORMAT_PNG)){
63- longjmp(png_ptr->jmpbuf, 1);
64+ if (!Create(png_get_image_width(png_ptr, info_ptr), png_get_image_height(png_ptr, info_ptr), pixel_depth, CXIMAGE_FORMAT_PNG)){
65+ longjmp(png_jmpbuf(png_ptr), 1);
66 }
67
68 /* get metrics */
69- switch (info_ptr->phys_unit_type)
70+ png_uint_32 res_x, res_y;
71+ int unit_type;
72+ png_get_pHYs_dpi(png_ptr, info_ptr, &res_x, &res_y, &unit_type);
73+ switch (unit_type)
74 {
75 case PNG_RESOLUTION_UNKNOWN:
76- SetXDPI(info_ptr->x_pixels_per_unit);
77- SetYDPI(info_ptr->y_pixels_per_unit);
78+ SetXDPI(res_x);
79+ SetYDPI(res_y);
80 break;
81 case PNG_RESOLUTION_METER:
82- SetXDPI((long)floor(info_ptr->x_pixels_per_unit * 254.0 / 10000.0 + 0.5));
83- SetYDPI((long)floor(info_ptr->y_pixels_per_unit * 254.0 / 10000.0 + 0.5));
84+ SetXDPI((long)floor(res_x * 254.0 / 10000.0 + 0.5));
85+ SetYDPI((long)floor(res_y * 254.0 / 10000.0 + 0.5));
86 break;
87 }
88
89- if (info_ptr->num_palette>0){
90- SetPalette((rgb_color*)info_ptr->palette,info_ptr->num_palette);
91- SetClrImportant(info_ptr->num_palette);
92- } else if (info_ptr->bit_depth ==2) { //<DP> needed for 2 bpp grayscale PNGs
93+ png_colorp palette;
94+ int num_palette;
95+ png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
96+ if (num_palette>0){
97+ SetPalette((rgb_color*)palette,num_palette);
98+ SetClrImportant(num_palette);
99+ } else if (png_get_bit_depth(png_ptr, info_ptr) ==2) { //<DP> needed for 2 bpp grayscale PNGs
100 SetPaletteColor(0,0,0,0);
101 SetPaletteColor(1,85,85,85);
102 SetPaletteColor(2,170,170,170);
103 SetPaletteColor(3,255,255,255);
104 } else SetGrayPalette(); //<DP> needed for grayscale PNGs
105
106- int nshift = max(0,(info_ptr->bit_depth>>3)-1)<<3;
107+ int nshift = max(0,(png_get_bit_depth(png_ptr, info_ptr)>>3)-1)<<3;
108
109- if (info_ptr->num_trans!=0){ //palette transparency
110- if (info_ptr->num_trans==1){
111- if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE){
112-#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
113- info.nBkgndIndex = info_ptr->trans_color.index;
114-#else
115- info.nBkgndIndex = info_ptr->trans_values.index;
116-#endif
117+png_uint_32 png_get_tRNS (png_const_structp png_ptr, png_infop
118+info_ptr, png_bytep *trans_alpha, int *num_trans, png_color_16p
119+*trans_color);
120+ png_bytep trans_alpha;
121+ int num_trans;
122+ png_color_16p trans_color;
123+ png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color);
124+ if (num_trans!=0){ //palette transparency
125+ if (num_trans==1){
126+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_PALETTE){
127+ info.nBkgndIndex = trans_color->index;
128 } else{
129-#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
130- info.nBkgndIndex = info_ptr->trans_color.gray>>nshift;
131-#else
132- info.nBkgndIndex = info_ptr->trans_values.gray>>nshift;
133-#endif
134+ info.nBkgndIndex = trans_color->gray>>nshift;
135 }
136 }
137- if (info_ptr->num_trans>1){
138+ if (num_trans>1){
139 RGBQUAD* pal=GetPalette();
140 if (pal){
141 DWORD ip;
142- for (ip=0;ip<min(head.biClrUsed,(unsigned long)info_ptr->num_trans);ip++)
143-#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
144- pal[ip].rgbReserved=info_ptr->trans_alpha[ip];
145-#else
146- pal[ip].rgbReserved=info_ptr->trans[ip];
147-#endif
148- for (ip=info_ptr->num_trans;ip<head.biClrUsed;ip++){
149+ for (ip=0;ip<min(head.biClrUsed,(unsigned long)num_trans);ip++)
150+ pal[ip].rgbReserved=trans_alpha[ip];
151+ for (ip=num_trans;ip<head.biClrUsed;ip++){
152 pal[ip].rgbReserved=255;
153 }
154 info.bAlphaPaletteEnabled=true;
155@@ -178,15 +183,9 @@
156 int num_trans;
157 png_color_16 *image_background;
158 if (png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &image_background)){
159-#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
160- info.nBkgndColor.rgbRed = (BYTE)(info_ptr->trans_color.red>>nshift);
161- info.nBkgndColor.rgbGreen = (BYTE)(info_ptr->trans_color.green>>nshift);
162- info.nBkgndColor.rgbBlue = (BYTE)(info_ptr->trans_color.blue>>nshift);
163-#else
164- info.nBkgndColor.rgbRed = (BYTE)(info_ptr->trans_values.red>>nshift);
165- info.nBkgndColor.rgbGreen = (BYTE)(info_ptr->trans_values.green>>nshift);
166- info.nBkgndColor.rgbBlue = (BYTE)(info_ptr->trans_values.blue>>nshift);
167-#endif
168+ info.nBkgndColor.rgbRed = (BYTE)(trans_color->red>>nshift);
169+ info.nBkgndColor.rgbGreen = (BYTE)(trans_color->green>>nshift);
170+ info.nBkgndColor.rgbBlue = (BYTE)(trans_color->blue>>nshift);
171 info.nBkgndColor.rgbReserved = 0;
172 info.nBkgndIndex = 0;
173 }
174@@ -202,15 +201,15 @@
175 }
176
177 // <vho> - flip the RGB pixels to BGR (or RGBA to BGRA)
178- if (info_ptr->color_type & PNG_COLOR_MASK_COLOR){
179+ if (png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_COLOR){
180 png_set_bgr(png_ptr);
181 }
182
183 // <vho> - handle cancel
184- if (info.nEscape) longjmp(png_ptr->jmpbuf, 1);
185+ if (info.nEscape) longjmp(png_jmpbuf(png_ptr), 1);
186
187 // row_bytes is the width x number of channels x (bit-depth / 8)
188- row_pointers = new BYTE[info_ptr->rowbytes + 8];
189+ row_pointers = new BYTE[png_get_rowbytes(png_ptr, info_ptr) + 8];
190
191 // turn on interlace handling
192 int number_passes = png_set_interlace_handling(png_ptr);
193@@ -221,8 +220,10 @@
194 SetCodecOption(0);
195 }
196
197- int chan_offset = info_ptr->bit_depth >> 3;
198- int pixel_offset = info_ptr->pixel_depth >> 3;
199+ int bit_depth = png_get_bit_depth(png_ptr, info_ptr);
200+ int chan_offset = bit_depth >> 3;
201+ //int pixel_offset = info_ptr->pixel_depth >> 3;
202+ int pixel_offset = (bit_depth * channels) >> 3;
203
204 for (int pass=0; pass < number_passes; pass++) {
205 iter.Upset();
206@@ -230,7 +231,7 @@
207 do {
208
209 // <vho> - handle cancel
210- if (info.nEscape) longjmp(png_ptr->jmpbuf, 1);
211+ if (info.nEscape) longjmp(png_jmpbuf(png_ptr), 1);
212
213 #if CXIMAGE_SUPPORT_ALPHA // <vho>
214 if (AlphaIsValid()) {
215@@ -241,7 +242,7 @@
216 BYTE* prow= iter.GetRow(ay);
217
218 //recover data from previous scan
219- if (info_ptr->interlace_type && pass>0 && pass!=7){
220+ if (png_get_interlace_type(png_ptr, info_ptr) && pass>0 && pass!=7){
221 for(ax=0;ax<head.biWidth;ax++){
222 long px = ax * pixel_offset;
223 if (channels == 2){
224@@ -278,10 +279,10 @@
225 #endif // CXIMAGE_SUPPORT_ALPHA // vho
226 {
227 //recover data from previous scan
228- if (info_ptr->interlace_type && pass>0){
229- iter.GetRow(row_pointers, info_ptr->rowbytes);
230+ if (png_get_interlace_type(png_ptr, info_ptr) && pass>0){
231+ iter.GetRow(row_pointers, png_get_rowbytes(png_ptr, info_ptr));
232 //re-expand buffer for images with bit depth > 8
233- if (info_ptr->bit_depth > 8){
234+ if (png_get_bit_depth(png_ptr, info_ptr) > 8){
235 for(long ax=(head.biWidth*channels-1);ax>=0;ax--)
236 row_pointers[ax*chan_offset] = row_pointers[ax];
237 }
238@@ -291,15 +292,15 @@
239 png_read_row(png_ptr, row_pointers, NULL);
240
241 //shrink 16 bit depth images down to 8 bits
242- if (info_ptr->bit_depth > 8){
243+ if (png_get_bit_depth(png_ptr, info_ptr) > 8){
244 for(long ax=0;ax<(head.biWidth*channels);ax++)
245 row_pointers[ax] = row_pointers[ax*chan_offset];
246 }
247
248 //copy the pixels
249- iter.SetRow(row_pointers, info_ptr->rowbytes);
250+ iter.SetRow(row_pointers, png_get_rowbytes(png_ptr, info_ptr));
251 //<DP> expand 2 bpp images only in the last pass
252- if (info_ptr->bit_depth==2 && pass==(number_passes-1))
253+ if (png_get_bit_depth(png_ptr, info_ptr)==2 && pass==(number_passes-1))
254 expand2to4bpp(iter.GetRow());
255
256 //go on
257@@ -340,6 +341,11 @@
258 BYTE trans[256]; //for transparency (don't move)
259 png_struct *png_ptr;
260 png_info *info_ptr;
261+ png_uint_32 width, height;
262+ png_byte bit_depth;
263+ png_byte color_type;
264+ png_byte interlace_type;
265+ BYTE channels;
266
267 cx_try
268 {
269@@ -362,9 +368,8 @@
270 /* Set error handling. REQUIRED if you aren't supplying your own
271 * error hadnling functions in the png_create_write_struct() call.
272 */
273- if (setjmp(png_ptr->jmpbuf)){
274+ if (setjmp(png_jmpbuf(png_ptr))){
275 /* If we get here, we had a problem reading the file */
276- if (info_ptr->palette) free(info_ptr->palette);
277 png_destroy_write_struct(&png_ptr, (png_infopp)&info_ptr);
278 cx_throw("Error saving PNG file");
279 }
280@@ -376,20 +381,18 @@
281 png_set_write_fn(png_ptr,hFile,/*(png_rw_ptr)*/user_write_data,/*(png_flush_ptr)*/user_flush_data);
282
283 /* set the file information here */
284- info_ptr->width = GetWidth();
285- info_ptr->height = GetHeight();
286- info_ptr->pixel_depth = (BYTE)GetBpp();
287- info_ptr->channels = (GetBpp()>8) ? (BYTE)3: (BYTE)1;
288- info_ptr->bit_depth = (BYTE)(GetBpp()/info_ptr->channels);
289- info_ptr->compression_type = info_ptr->filter_type = 0;
290- info_ptr->valid = 0;
291+ width = GetWidth();
292+ height = GetHeight();
293+ //pixel_depth = (BYTE)GetBpp();
294+ channels = (GetBpp()>8) ? (BYTE)3: (BYTE)1;
295+ bit_depth = (BYTE)(GetBpp()/channels);
296
297 switch(GetCodecOption(CXIMAGE_FORMAT_PNG)){
298 case 1:
299- info_ptr->interlace_type = PNG_INTERLACE_ADAM7;
300+ interlace_type = PNG_INTERLACE_ADAM7;
301 break;
302 default:
303- info_ptr->interlace_type = PNG_INTERLACE_NONE;
304+ interlace_type = PNG_INTERLACE_NONE;
305 }
306
307 /* set compression level */
308@@ -399,19 +402,19 @@
309
310 if (GetNumColors()){
311 if (bGrayScale){
312- info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
313+ color_type = PNG_COLOR_TYPE_GRAY;
314 } else {
315- info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
316+ color_type = PNG_COLOR_TYPE_PALETTE;
317 }
318 } else {
319- info_ptr->color_type = PNG_COLOR_TYPE_RGB;
320+ color_type = PNG_COLOR_TYPE_RGB;
321 }
322 #if CXIMAGE_SUPPORT_ALPHA
323 if (AlphaIsValid()){
324- info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
325- info_ptr->channels++;
326- info_ptr->bit_depth = 8;
327- info_ptr->pixel_depth += 8;
328+ color_type |= PNG_COLOR_MASK_ALPHA;
329+ channels++;
330+ bit_depth = 8;
331+ //pixel_depth += 8;
332 }
333 #endif
334
335@@ -428,29 +431,21 @@
336 /* set metrics */
337 png_set_pHYs(png_ptr, info_ptr, head.biXPelsPerMeter, head.biYPelsPerMeter, PNG_RESOLUTION_METER);
338
339- png_set_IHDR(png_ptr, info_ptr, info_ptr->width, info_ptr->height, info_ptr->bit_depth,
340- info_ptr->color_type, info_ptr->interlace_type,
341+ png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
342+ color_type, interlace_type,
343 PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
344
345 //<DP> simple transparency
346 if (info.nBkgndIndex >= 0){
347- info_ptr->num_trans = 1;
348- info_ptr->valid |= PNG_INFO_tRNS;
349-#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
350- info_ptr->trans_alpha = trans;
351- info_ptr->trans_color.index = (BYTE)info.nBkgndIndex;
352- info_ptr->trans_color.red = tc.rgbRed;
353- info_ptr->trans_color.green = tc.rgbGreen;
354- info_ptr->trans_color.blue = tc.rgbBlue;
355- info_ptr->trans_color.gray = info_ptr->trans_color.index;
356-#else
357- info_ptr->trans = trans;
358- info_ptr->trans_values.index = (BYTE)info.nBkgndIndex;
359- info_ptr->trans_values.red = tc.rgbRed;
360- info_ptr->trans_values.green = tc.rgbGreen;
361- info_ptr->trans_values.blue = tc.rgbBlue;
362- info_ptr->trans_values.gray = info_ptr->trans_values.index;
363-#endif
364+ png_color_16 trans_color;
365+
366+ trans_color.index = (BYTE)info.nBkgndIndex;
367+ trans_color.red = tc.rgbRed;
368+ trans_color.green = tc.rgbGreen;
369+ trans_color.blue = tc.rgbBlue;
370+ trans_color.gray = (BYTE)info.nBkgndIndex;
371+
372+ png_set_tRNS(png_ptr, info_ptr, trans, 1, &trans_color);
373
374 // the transparency indexes start from 0 for non grayscale palette
375 if (!bGrayScale && head.biClrUsed && info.nBkgndIndex)
376@@ -459,30 +454,27 @@
377
378 /* set the palette if there is one */
379 if (GetPalette()){
380- if (!bGrayScale){
381- info_ptr->valid |= PNG_INFO_PLTE;
382- }
383-
384 int nc = GetClrImportant();
385 if (nc==0) nc = GetNumColors();
386
387 if (info.bAlphaPaletteEnabled){
388 for(WORD ip=0; ip<nc;ip++)
389 trans[ip]=GetPaletteColor((BYTE)ip).rgbReserved;
390- info_ptr->num_trans = (WORD)nc;
391- info_ptr->valid |= PNG_INFO_tRNS;
392-#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
393- info_ptr->trans_alpha = trans;
394-#else
395- info_ptr->trans = trans;
396-#endif
397+ png_set_tRNS(png_ptr, info_ptr, trans, (WORD)nc, NULL);
398 }
399
400 // copy the palette colors
401- info_ptr->palette = new png_color[nc];
402- info_ptr->num_palette = (png_uint_16) nc;
403- for (int i=0; i<nc; i++)
404- GetPaletteColor(i, &info_ptr->palette[i].red, &info_ptr->palette[i].green, &info_ptr->palette[i].blue);
405+ if (!bGrayScale) {
406+ png_color *palette;
407+
408+ palette = (png_color *)png_malloc(png_ptr, nc*sizeof(palette[0]));
409+ for (int i=0; i<nc; i++)
410+ GetPaletteColor(i, &palette[i].red, &palette[i].green, &palette[i].blue);
411+ png_set_PLTE(png_ptr, info_ptr, palette, nc);
412+ png_data_freer(png_ptr, info_ptr,
413+ PNG_DESTROY_WILL_FREE_DATA,
414+ PNG_FREE_PLTE);
415+ }
416 }
417
418 #if CXIMAGE_SUPPORT_ALPHA // <vho>
419@@ -496,8 +488,8 @@
420 } } }
421 #endif // CXIMAGE_SUPPORT_ALPHA // <vho>
422
423- int row_size = max(info.dwEffWidth, info_ptr->width*info_ptr->channels*(info_ptr->bit_depth/8));
424- info_ptr->rowbytes = row_size;
425+ int row_size = max(info.dwEffWidth, png_get_rowbytes(png_ptr, info_ptr));
426+ //info_ptr->rowbytes = row_size;
427 BYTE *row_pointers = new BYTE[row_size];
428
429 /* write the file information */
430@@ -515,7 +507,7 @@
431 if (AlphaIsValid()){
432 for (long ax=head.biWidth-1; ax>=0;ax--){
433 c = BlindGetPixelColor(ax,ay);
434- int px = ax * info_ptr->channels;
435+ int px = ax * png_get_channels(png_ptr, info_ptr);
436 if (!bGrayScale){
437 row_pointers[px++]=c.rgbRed;
438 row_pointers[px++]=c.rgbGreen;
439@@ -530,7 +522,7 @@
440 #endif //CXIMAGE_SUPPORT_ALPHA // <vho>
441 {
442 iter.GetRow(row_pointers, row_size);
443- if (info_ptr->color_type == PNG_COLOR_TYPE_RGB) //HACK BY OP
444+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB) //HACK BY OP
445 RGBtoBGR(row_pointers, row_size);
446 png_write_row(png_ptr, row_pointers);
447 }
448@@ -547,12 +539,6 @@
449 /* It is REQUIRED to call this to finish writing the rest of the file */
450 png_write_end(png_ptr, info_ptr);
451
452- /* if you malloced the palette, free it here */
453- if (info_ptr->palette){
454- delete [] (info_ptr->palette);
455- info_ptr->palette = NULL;
456- }
457-
458 /* clean up after the write, and free any memory allocated */
459 png_destroy_write_struct(&png_ptr, (png_infopp)&info_ptr);
460
461--- utils/TkCximage/src/CxImage/ximapng.h
462+++ utils/TkCximage/src/CxImage/ximapng.h
463@@ -64,8 +64,8 @@
464
465 static void PNGAPI user_error_fn(png_structp png_ptr,png_const_charp error_msg)
466 {
467- strncpy((char*)png_ptr->error_ptr,error_msg,255);
468- longjmp(png_ptr->jmpbuf, 1);
469+ strncpy((char*)png_get_error_ptr(png_ptr),error_msg,255);
470+ longjmp(png_jmpbuf(png_ptr), 1);
471 }
472 };
473
This page took 0.197761 seconds and 4 git commands to generate.