]> git.pld-linux.org Git - packages/cinepaint.git/blob - cinepaint-libpng.patch
Release 12 (by relup.sh)
[packages/cinepaint.git] / cinepaint-libpng.patch
1 --- cinepaint/plug-ins/png/png.c.orig   2006-11-24 21:52:55.000000000 +0100
2 +++ cinepaint/plug-ins/png/png.c        2023-08-30 18:58:13.093905639 +0200
3 @@ -390,7 +390,16 @@ load_image (gchar *filename)       /* I - File
4    gchar                *progress;      /* Title for progress display... */
5    guchar       alpha[256],     /* Index -> Alpha */
6                 *alpha_ptr;     /* Temporary pointer */
7 -
8 +  png_byte     color_type;
9 +  png_byte     bit_depth;
10 +  png_colorp palette;
11 +  int num_palette;
12 +  png_charpp iccp_name;
13 +  int compression_type;
14 +  png_bytepp iccp_profile;
15 +  png_uint_32 iccp_proflen;
16 +  png_uint_32 width, height;
17 +  png_byte channels;
18   /*
19    * PNG 0.89 and newer have a sane, forwards compatible constructor.
20    * Some SGI IRIX users will not have a new enough version though
21 @@ -405,7 +414,7 @@ load_image (gchar *filename)        /* I - File
22    info = (png_infop)calloc(sizeof(png_info), 1);
23  #endif /* PNG_LIBPNG_VER > 88 */
24  
25 -  if (setjmp (pp->jmpbuf))
26 +  if (setjmp (png_jmpbuf(pp)))
27    {
28      g_message ("%s\nPNG error. File corrupted?", filename);
29      return image;
30 @@ -442,21 +451,23 @@ load_image (gchar *filename)      /* I - File
31    */
32  
33    png_read_info(pp, info);
34 -
35 +  color_type = png_get_color_type(pp, info);
36 +  width=png_get_image_width(pp, info);
37 +  height=png_get_image_height(pp, info);
38   /*
39    * Latest attempt, this should be my best yet :)
40    */
41 -
42 +  bit_depth = png_get_bit_depth(pp, info);
43  #ifndef WORDS_BIGENDIAN
44 -  if(info->bit_depth == 16)
45 -         png_set_swap(pp);
46 +  if(bit_depth == 16)
47 +    png_set_swap(pp);
48  #endif
49  
50 -  if (info->color_type == PNG_COLOR_TYPE_GRAY && info->bit_depth < 8) {
51 +  if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
52      png_set_expand(pp);
53    }
54  
55 -  if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8) {
56 +  if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth < 8) {
57      png_set_packing(pp);
58    }
59  
60 @@ -464,8 +475,8 @@ load_image (gchar *filename)        /* I - File
61    * Expand G+tRNS to GA, RGB+tRNS to RGBA
62    */
63  
64 -  if (info->color_type != PNG_COLOR_TYPE_PALETTE &&
65 -                       (info->valid & PNG_INFO_tRNS)) {
66 +  if (color_type != PNG_COLOR_TYPE_PALETTE &&
67 +      (png_get_valid(pp, info, PNG_INFO_tRNS))) {
68      png_set_expand(pp);
69    }
70  
71 @@ -482,7 +493,7 @@ load_image (gchar *filename)        /* I - File
72  
73  #if PNG_LIBPNG_VER > 99
74    if (png_get_valid(pp, info, PNG_INFO_tRNS) &&
75 -      info->color_type == PNG_COLOR_TYPE_PALETTE)
76 +      color_type == PNG_COLOR_TYPE_PALETTE)
77    {
78      png_get_tRNS(pp, info, &alpha_ptr, &num, NULL);
79      /* Copy the existing alpha values from the tRNS chunk */
80 @@ -505,12 +516,12 @@ load_image (gchar *filename)      /* I - File
81  
82    png_read_update_info(pp, info);
83    
84 -  if(info->bit_depth==16)
85 +  if(bit_depth==16)
86    {
87 -         switch (info->color_type)
88 +         switch (color_type)
89           {
90                   case PNG_COLOR_TYPE_RGB :             /* RGB */
91 -                         bpp        = 6;
92 +                          bpp        = 6;
93                           image_type = U16_RGB;
94                           layer_type = U16_RGB_IMAGE;
95                           break;
96 @@ -545,10 +556,10 @@ load_image (gchar *filename)      /* I - File
97    }
98    else
99    {
100 -         switch (info->color_type)
101 +         switch (color_type)
102           {
103                   case PNG_COLOR_TYPE_RGB :             /* RGB */
104 -                         bpp        = 3;
105 +                          bpp        = 3;
106                           image_type = RGB;
107                           layer_type = RGB_IMAGE;
108                           break;
109 @@ -582,7 +593,7 @@ load_image (gchar *filename)        /* I - File
110           };
111    }
112  
113 -  image = gimp_image_new(info->width, info->height, image_type);
114 +  image = gimp_image_new(width, height, image_type);
115    if (image == -1)
116    {
117      g_message("Can't allocate new image\n%s", filename);
118 @@ -595,7 +606,7 @@ load_image (gchar *filename)        /* I - File
119    * Create the "background" layer to hold the image...
120    */
121  
122 -  layer = gimp_layer_new(image, _("Background"), info->width, info->height,
123 +  layer = gimp_layer_new(image, _("Background"), width, height,
124                           layer_type, 100, NORMAL_MODE);
125    gimp_image_add_layer(image, layer, 0);
126  
127 @@ -627,20 +638,21 @@ load_image (gchar *filename)      /* I - File
128  
129    empty= 0; /* by default assume no full transparent palette entries */
130  
131 -  if (info->color_type & PNG_COLOR_MASK_PALETTE) {
132 +  if (color_type & PNG_COLOR_MASK_PALETTE) {
133  
134  #if PNG_LIBPNG_VER > 99
135 +    png_get_PLTE(pp, info, &palette, &num_palette);
136      if (png_get_valid(pp, info, PNG_INFO_tRNS)) {
137        for (empty= 0; empty < 256 && alpha[empty] == 0; ++empty);
138          /* Calculates number of fully transparent "empty" entries */
139  
140 -      gimp_image_set_cmap(image, (guchar *) (info->palette + empty),
141 -                          info->num_palette - empty);
142 +      gimp_image_set_cmap(image, (guchar *) (palette + empty),
143 +                          num_palette - empty);
144      } else {
145 -      gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette);
146 +      gimp_image_set_cmap(image, (guchar *)palette, num_palette);
147      }
148  #else
149 -    gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette);
150 +    gimp_image_set_cmap(image, (guchar *)palette, num_palette);
151  #endif /* PNG_LIBPNG_VER > 99 */
152  
153    }
154 @@ -659,18 +671,19 @@ load_image (gchar *filename)      /* I - File
155    */
156  
157    tile_height = gimp_tile_height ();
158 -  pixel       = g_new(guchar, tile_height * info->width * bpp);
159 +  pixel       = g_new(guchar, tile_height * width * bpp);
160    pixels      = g_new(guchar *, tile_height);
161 +  channels=png_get_channels(pp, info);
162  
163 -  if(info->bit_depth==16)
164 +  if(bit_depth==16)
165    {
166           for (i = 0; i < tile_height; i ++)
167 -                 pixels[i] = pixel + info->width * info->channels * i * 2;
168 +                 pixels[i] = pixel + width * channels * i * 2;
169    }
170    else
171    {
172           for (i = 0; i < tile_height; i ++)
173 -                 pixels[i] = pixel + info->width * info->channels * i;
174 +                 pixels[i] = pixel + width * channels * i;
175    }
176  
177    for (pass = 0; pass < num_passes; pass ++)
178 @@ -680,11 +693,11 @@ load_image (gchar *filename)      /* I - File
179            */
180  
181           for (begin = 0, end = tile_height;
182 -                         begin < info->height;
183 +                         begin < height;
184                           begin += tile_height, end += tile_height)
185           {
186 -                 if (end > info->height)
187 -                         end = info->height;
188 +                 if (end > height)
189 +                         end = height;
190  
191                   num = end - begin;
192  
193 @@ -697,20 +710,21 @@ load_image (gchar *filename)      /* I - File
194                   gimp_pixel_rgn_set_rect(&pixel_rgn, pixel, 0, begin,
195                                   drawable->width, num);
196  
197 -                 gimp_progress_update(((double)pass + (double)end / (double)info->height) /
198 +                 gimp_progress_update(((double)pass + (double)end / (double)height) /
199                                   (double)num_passes);
200           };
201    };
202  
203  #if defined(PNG_iCCP_SUPPORTED)
204    /* set icc profile */
205 -  if (info->iccp_proflen > 0) {
206 -    gimp_image_set_icc_profile_by_mem (image, info->iccp_proflen,
207 -                                              info->iccp_profile,
208 -                                              ICC_IMAGE_PROFILE);
209 +  png_get_iCCP(pp, info,  (png_charpp)iccp_name, &compression_type, iccp_profile, &iccp_proflen);
210 +  if (iccp_proflen > 0) {
211 +    gimp_image_set_icc_profile_by_mem (image, iccp_proflen,
212 +                                      (gchar *)iccp_profile,
213 +                                      ICC_IMAGE_PROFILE);
214      printf ("%s:%d %s() set embedded profile \"%s\"\n",
215               __FILE__,__LINE__,__func__,
216 -                                              info->iccp_name);
217 +           (char *)iccp_name);
218    }
219  #endif
220  
221 @@ -809,6 +823,15 @@ save_image (gchar  *filename,              /*
222    time_t       cutime;         /* Time since epoch */
223    struct tm    *gmt;           /* GMT broken down */
224  
225 +  png_byte     color_type;
226 +  png_byte     bit_depth;
227 +  int filter_method=0;
228 +  png_colorp palette;
229 +  int num_palette;
230 +  png_charpp iccp_name;
231 +  png_uint_32 height;
232 +  int compression_type;
233 +
234   /*
235    * PNG 0.89 and newer have a sane, forwards compatible constructor.
236    * Some SGI IRIX users will not have a new enough version though
237 @@ -824,7 +847,7 @@ save_image (gchar  *filename,               /*
238    info = (png_infop)calloc(sizeof(png_info), 1);
239  #endif /* PNG_LIBPNG_VER > 88 */
240  
241 -  if (setjmp (pp->jmpbuf))
242 +  if (setjmp (png_jmpbuf(pp)))
243    {
244      g_message ("%s\nPNG error. Couldn't save image", filename);
245      return 0;
246 @@ -858,87 +881,75 @@ save_image (gchar  *filename,             /*
247    type     = gimp_drawable_type (drawable_ID);
248  
249   /*
250 -  * Set the image dimensions, bit depth, interlacing and compression
251 -  */
252 -
253 -  png_set_compression_level (pp, pngvals.compression_level);
254 -
255 -  info->width          = drawable->width;
256 -  info->height         = drawable->height;
257 -  info->interlace_type = pngvals.interlaced;
258 -
259 - /*
260    * Set color type and remember bytes per pixel count 
261    */
262  
263    switch (type)
264    {
265      case RGB_IMAGE :
266 -        info->color_type = PNG_COLOR_TYPE_RGB;
267 -       info->bit_depth      = 8;
268 +        color_type = PNG_COLOR_TYPE_RGB;
269 +       bit_depth      = 8;
270          bpp              = 3;
271          break;
272      case RGBA_IMAGE :
273 -        info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
274 -       info->bit_depth      = 8;
275 +        color_type = PNG_COLOR_TYPE_RGB_ALPHA;
276 +       bit_depth      = 8;
277          bpp              = 4;
278          break;
279      case GRAY_IMAGE :
280 -        info->color_type = PNG_COLOR_TYPE_GRAY;
281 -       info->bit_depth      = 8;
282 +        color_type = PNG_COLOR_TYPE_GRAY;
283 +       bit_depth      = 8;
284          bpp              = 1;
285          break;
286      case GRAYA_IMAGE :
287 -        info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
288 -       info->bit_depth      = 8;
289 +        color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
290 +       bit_depth      = 8;
291          bpp              = 2;
292          break;
293      case INDEXED_IMAGE :
294         bpp              = 1;
295 -       info->bit_depth      = 8;
296 -        info->color_type = PNG_COLOR_TYPE_PALETTE;
297 -       info->valid      |= PNG_INFO_PLTE;
298 -        info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors);
299 -        info->num_palette= num_colors;
300 +       bit_depth      = 8;
301 +        color_type = PNG_COLOR_TYPE_PALETTE;
302 +       png_get_valid(pp, info, PNG_INFO_PLTE);
303 +       png_set_PLTE(pp, info, (png_colorp) gimp_image_get_cmap(image_ID, &num_colors), num_colors);
304          break;
305      case INDEXEDA_IMAGE :
306         bpp              = 2;
307 -       info->bit_depth      = 8;
308 -       info->color_type = PNG_COLOR_TYPE_PALETTE;
309 +       bit_depth      = 8;
310 +       color_type = PNG_COLOR_TYPE_PALETTE;
311         respin_cmap (pp, info, image_ID); /* fix up transparency */
312         break;
313      case U16_RGB_IMAGE :
314 -        info->color_type = PNG_COLOR_TYPE_RGB;
315 -       info->bit_depth      = 16;
316 +        color_type = PNG_COLOR_TYPE_RGB;
317 +       bit_depth      = 16;
318          bpp              = 6;
319          break;
320      case U16_RGBA_IMAGE :
321 -        info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
322 -       info->bit_depth      = 16;
323 +        color_type = PNG_COLOR_TYPE_RGB_ALPHA;
324 +       bit_depth      = 16;
325          bpp              = 8;
326          break;
327      case U16_GRAY_IMAGE :
328 -        info->color_type = PNG_COLOR_TYPE_GRAY;
329 -       info->bit_depth      = 16;
330 +        color_type = PNG_COLOR_TYPE_GRAY;
331 +       bit_depth      = 16;
332          bpp              = 2;
333          break;
334      case U16_GRAYA_IMAGE :
335 -        info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
336 -       info->bit_depth      = 16;
337 +        color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
338 +       bit_depth      = 16;
339          bpp              = 4;
340          break;
341      case U16_INDEXED_IMAGE :
342         bpp              = 2;
343 -       info->bit_depth      = 16;
344 -        info->color_type = PNG_COLOR_TYPE_PALETTE;
345 -       info->valid      |= PNG_INFO_PLTE;
346 -        info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors);
347 -        info->num_palette= num_colors;
348 +       bit_depth      = 16;
349 +        color_type = PNG_COLOR_TYPE_PALETTE;
350 +       png_get_valid(pp, info, PNG_INFO_PLTE);
351 +       png_set_PLTE(pp, info, (png_colorp) gimp_image_get_cmap(image_ID, &num_colors), num_colors);
352          break;
353      case U16_INDEXEDA_IMAGE :
354         bpp              = 4;
355 -       info->bit_depth      = 16;
356 -       info->color_type = PNG_COLOR_TYPE_PALETTE;
357 +       bit_depth      = 16;
358 +       color_type = PNG_COLOR_TYPE_PALETTE;
359         respin_cmap (pp, info, image_ID); /* fix up transparency */
360         break;
361      default:
362 @@ -950,16 +961,21 @@ save_image (gchar  *filename,             /*
363    * Fix bit depths for (possibly) smaller colormap images
364    */
365    
366 -  if (info->valid & PNG_INFO_PLTE) {
367 -    if (info->num_palette <= 2)
368 -      info->bit_depth= 1;
369 -    else if (info->num_palette <= 4)
370 -      info->bit_depth= 2;
371 -    else if (info->num_palette <= 16)
372 -      info->bit_depth= 4;
373 +  if (png_get_valid(pp, info, PNG_INFO_PLTE)) {
374 +    png_get_PLTE(pp, info, &palette, &num_palette);
375 +    if (num_palette <= 2)
376 +      bit_depth= 1;
377 +    else if (num_palette <= 4)
378 +      bit_depth= 2;
379 +    else if (num_palette <= 16)
380 +      bit_depth= 4;
381      /* otherwise the default is fine */
382    }
383  
384 + png_set_compression_level (pp, pngvals.compression_level);
385 + png_set_IHDR(pp, info, drawable->width, drawable->height,
386 +             bit_depth, color_type, pngvals.interlaced, compression_type, filter_method);
387 +
388    // write icc profile
389  #if defined(PNG_iCCP_SUPPORTED)
390    if (gimp_image_has_icc_profile (image_ID, ICC_IMAGE_PROFILE)) {
391 @@ -970,10 +986,10 @@ save_image (gchar  *filename,             /*
392                                                  ICC_IMAGE_PROFILE);
393      png_set_iCCP (pp, info,
394             gimp_image_get_icc_profile_description (image_ID, ICC_IMAGE_PROFILE),
395 -                  0, buffer, size);
396 +                  0, (png_const_bytep)buffer, size);
397      printf ("%s:%d %s() embedd icc profile \"%s\"\n",
398               __FILE__,__LINE__,__func__,
399 -                                              info->iccp_name);
400 +           (char *)iccp_name);
401    }
402  #endif
403  
404 @@ -1039,13 +1055,13 @@ save_image (gchar  *filename,           /*
405    * Convert unpacked pixels to packed if necessary
406    */
407  
408 -  if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8)
409 +  if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth < 8)
410      png_set_packing(pp);
411  
412    /* Set swapping for 16 bit per sample images */
413    
414  #ifndef WORDS_BIGENDIAN
415 -  if (info->bit_depth == 16)
416 +  if (bit_depth == 16)
417           png_set_swap(pp);
418  #endif
419    
420 @@ -1063,6 +1079,7 @@ save_image (gchar  *filename,             /*
421  
422    gimp_pixel_rgn_init(&pixel_rgn, drawable, 0, 0, drawable->width,
423                        drawable->height, FALSE, FALSE);
424 +  height=png_get_image_height(pp, info);
425  
426    for (pass = 0; pass < num_passes; pass ++)
427    {
428 @@ -1077,7 +1094,7 @@ save_image (gchar  *filename,             /*
429         num = end - begin;
430         
431         gimp_pixel_rgn_get_rect (&pixel_rgn, pixel, 0, begin, drawable->width, num);
432 -        if (info->valid & PNG_INFO_tRNS) {
433 +        if (png_get_valid(pp, info, PNG_INFO_tRNS)) {
434            for (i = 0; i < num; ++i) {
435             fixed= pixels[i];
436              for (k = 0; k < drawable->width; ++k) {
437 @@ -1085,7 +1102,7 @@ save_image (gchar  *filename,             /*
438              }
439            }
440         /* Forgot this case before, what if there are too many colors? */
441 -        } else if (info->valid & PNG_INFO_PLTE && bpp == 2) {
442 +        } else if (png_get_valid(pp, info, PNG_INFO_PLTE) && bpp == 2) {
443            for (i = 0; i < num; ++i) {
444             fixed= pixels[i];
445              for (k = 0; k < drawable->width; ++k) {
446 @@ -1097,7 +1114,7 @@ save_image (gchar  *filename,             /*
447         png_write_rows (pp, pixels, num);
448         
449         gimp_progress_update (((double)pass + (double)end /
450 -                    (double)info->height) / (double)num_passes);
451 +                    (double)height) / (double)num_passes);
452        };
453    };
454  
This page took 0.070777 seconds and 3 git commands to generate.