wok-next rev 20209

cinepaint: add png patch
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Nov 04 12:45:00 2017 +0100 (2017-11-04)
parents 2e60fe1db5a4
children d2f636276174
files cinepaint/stuff/patches/cinepaint-1.4-png.patch cinepaint/stuff/patches/series
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/cinepaint/stuff/patches/cinepaint-1.4-png.patch	Sat Nov 04 12:45:00 2017 +0100
     1.3 @@ -0,0 +1,418 @@
     1.4 +diff -ur cinepaint/plug-ins/png/png.c cinepaint-png15/plug-ins/png/png.c
     1.5 +--- cinepaint/plug-ins/png/png.c	2006-11-24 15:52:55.000000000 -0500
     1.6 ++++ cinepaint-png15/plug-ins/png/png.c	2013-03-02 03:37:33.304142225 -0500
     1.7 +@@ -405,7 +405,7 @@
     1.8 +   info = (png_infop)calloc(sizeof(png_info), 1);
     1.9 + #endif /* PNG_LIBPNG_VER > 88 */
    1.10 + 
    1.11 +-  if (setjmp (pp->jmpbuf))
    1.12 ++  if (setjmp (png_jmpbuf(pp)))
    1.13 +   {
    1.14 +     g_message ("%s\nPNG error. File corrupted?", filename);
    1.15 +     return image;
    1.16 +@@ -448,15 +448,15 @@
    1.17 +   */
    1.18 + 
    1.19 + #ifndef WORDS_BIGENDIAN
    1.20 +-  if(info->bit_depth == 16)
    1.21 ++  if(png_get_bit_depth(pp,info) == 16)
    1.22 + 	  png_set_swap(pp);
    1.23 + #endif
    1.24 + 
    1.25 +-  if (info->color_type == PNG_COLOR_TYPE_GRAY && info->bit_depth < 8) {
    1.26 ++  if (png_get_color_type(pp,info) == PNG_COLOR_TYPE_GRAY && png_get_bit_depth(pp,info) < 8) {
    1.27 +     png_set_expand(pp);
    1.28 +   }
    1.29 + 
    1.30 +-  if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8) {
    1.31 ++  if (png_get_color_type(pp,info) == PNG_COLOR_TYPE_PALETTE && png_get_bit_depth(pp,info) < 8) {
    1.32 +     png_set_packing(pp);
    1.33 +   }
    1.34 + 
    1.35 +@@ -464,8 +464,8 @@
    1.36 +   * Expand G+tRNS to GA, RGB+tRNS to RGBA
    1.37 +   */
    1.38 + 
    1.39 +-  if (info->color_type != PNG_COLOR_TYPE_PALETTE &&
    1.40 +-                       (info->valid & PNG_INFO_tRNS)) {
    1.41 ++  if (png_get_color_type(pp,info) != PNG_COLOR_TYPE_PALETTE &&
    1.42 ++                  (png_get_valid(pp,info,PNG_INFO_tRNS) & PNG_INFO_tRNS)) {
    1.43 +     png_set_expand(pp);
    1.44 +   }
    1.45 + 
    1.46 +@@ -482,7 +482,7 @@
    1.47 + 
    1.48 + #if PNG_LIBPNG_VER > 99
    1.49 +   if (png_get_valid(pp, info, PNG_INFO_tRNS) &&
    1.50 +-      info->color_type == PNG_COLOR_TYPE_PALETTE)
    1.51 ++      png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE)
    1.52 +   {
    1.53 +     png_get_tRNS(pp, info, &alpha_ptr, &num, NULL);
    1.54 +     /* Copy the existing alpha values from the tRNS chunk */
    1.55 +@@ -505,9 +505,9 @@
    1.56 + 
    1.57 +   png_read_update_info(pp, info);
    1.58 +   
    1.59 +-  if(info->bit_depth==16)
    1.60 ++  if(png_get_bit_depth(pp,info)==16)
    1.61 +   {
    1.62 +-	  switch (info->color_type)
    1.63 ++	  switch (png_get_color_type(pp, info))
    1.64 + 	  {
    1.65 + 		  case PNG_COLOR_TYPE_RGB :		/* RGB */
    1.66 + 			  bpp        = 6;
    1.67 +@@ -545,7 +545,7 @@
    1.68 +   }
    1.69 +   else
    1.70 +   {
    1.71 +-	  switch (info->color_type)
    1.72 ++	  switch (png_get_color_type(pp, info))
    1.73 + 	  {
    1.74 + 		  case PNG_COLOR_TYPE_RGB :		/* RGB */
    1.75 + 			  bpp        = 3;
    1.76 +@@ -582,7 +582,7 @@
    1.77 + 	  };
    1.78 +   }
    1.79 + 
    1.80 +-  image = gimp_image_new(info->width, info->height, image_type);
    1.81 ++  image = gimp_image_new(png_get_image_width(pp,info), png_get_image_height(pp,info), image_type);
    1.82 +   if (image == -1)
    1.83 +   {
    1.84 +     g_message("Can't allocate new image\n%s", filename);
    1.85 +@@ -595,7 +595,7 @@
    1.86 +   * Create the "background" layer to hold the image...
    1.87 +   */
    1.88 + 
    1.89 +-  layer = gimp_layer_new(image, _("Background"), info->width, info->height,
    1.90 ++  layer = gimp_layer_new(image, _("Background"), png_get_image_width(pp,info), png_get_image_height(pp,info),
    1.91 +                          layer_type, 100, NORMAL_MODE);
    1.92 +   gimp_image_add_layer(image, layer, 0);
    1.93 + 
    1.94 +@@ -627,20 +627,23 @@
    1.95 + 
    1.96 +   empty= 0; /* by default assume no full transparent palette entries */
    1.97 + 
    1.98 +-  if (info->color_type & PNG_COLOR_MASK_PALETTE) {
    1.99 ++  if (png_get_color_type(pp, info) & PNG_COLOR_MASK_PALETTE) {
   1.100 ++	png_colorp palette;
   1.101 ++	int num_palette;
   1.102 ++	png_get_PLTE(pp, info, &palette, &num_palette);
   1.103 ++
   1.104 + 
   1.105 + #if PNG_LIBPNG_VER > 99
   1.106 +     if (png_get_valid(pp, info, PNG_INFO_tRNS)) {
   1.107 +       for (empty= 0; empty < 256 && alpha[empty] == 0; ++empty);
   1.108 +         /* Calculates number of fully transparent "empty" entries */
   1.109 + 
   1.110 +-      gimp_image_set_cmap(image, (guchar *) (info->palette + empty),
   1.111 +-                          info->num_palette - empty);
   1.112 ++      gimp_image_set_cmap(image, (guchar *) &palette + empty,num_palette - empty);
   1.113 +     } else {
   1.114 +-      gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette);
   1.115 ++      gimp_image_set_cmap(image, (guchar *)&palette, num_palette);
   1.116 +     }
   1.117 + #else
   1.118 +-    gimp_image_set_cmap(image, (guchar *)info->palette, info->num_palette);
   1.119 ++    gimp_image_set_cmap(image, (guchar *)&palette, num_palette);
   1.120 + #endif /* PNG_LIBPNG_VER > 99 */
   1.121 + 
   1.122 +   }
   1.123 +@@ -659,18 +662,18 @@
   1.124 +   */
   1.125 + 
   1.126 +   tile_height = gimp_tile_height ();
   1.127 +-  pixel       = g_new(guchar, tile_height * info->width * bpp);
   1.128 ++  pixel       = g_new(guchar, tile_height * png_get_image_width(pp,info) * bpp);
   1.129 +   pixels      = g_new(guchar *, tile_height);
   1.130 + 
   1.131 +-  if(info->bit_depth==16)
   1.132 ++  if(png_get_bit_depth(pp,info)==16)
   1.133 +   {
   1.134 + 	  for (i = 0; i < tile_height; i ++)
   1.135 +-		  pixels[i] = pixel + info->width * info->channels * i * 2;
   1.136 ++		  pixels[i] = pixel + png_get_image_width(pp,info) * png_get_channels(pp,info) * i * 2;
   1.137 +   }
   1.138 +   else
   1.139 +   {
   1.140 + 	  for (i = 0; i < tile_height; i ++)
   1.141 +-		  pixels[i] = pixel + info->width * info->channels * i;
   1.142 ++		  pixels[i] = pixel + png_get_image_width(pp,info) * png_get_channels(pp,info) * i;
   1.143 +   }
   1.144 + 
   1.145 +   for (pass = 0; pass < num_passes; pass ++)
   1.146 +@@ -680,11 +683,11 @@
   1.147 + 	   */
   1.148 + 
   1.149 + 	  for (begin = 0, end = tile_height;
   1.150 +-			  begin < info->height;
   1.151 ++			  begin < png_get_image_height(pp,info);
   1.152 + 			  begin += tile_height, end += tile_height)
   1.153 + 	  {
   1.154 +-		  if (end > info->height)
   1.155 +-			  end = info->height;
   1.156 ++		  if (end > png_get_image_height(pp,info))
   1.157 ++			  end = png_get_image_height(pp,info);
   1.158 + 
   1.159 + 		  num = end - begin;
   1.160 + 
   1.161 +@@ -697,21 +700,24 @@
   1.162 + 		  gimp_pixel_rgn_set_rect(&pixel_rgn, pixel, 0, begin,
   1.163 + 				  drawable->width, num);
   1.164 + 
   1.165 +-		  gimp_progress_update(((double)pass + (double)end / (double)info->height) /
   1.166 ++		  gimp_progress_update(((double)pass + (double)end / (double)png_get_image_height(pp,info)) /
   1.167 + 				  (double)num_passes);
   1.168 + 	  };
   1.169 +   };
   1.170 + 
   1.171 + #if defined(PNG_iCCP_SUPPORTED)
   1.172 ++{
   1.173 +   /* set icc profile */
   1.174 +-  if (info->iccp_proflen > 0) {
   1.175 +-    gimp_image_set_icc_profile_by_mem (image, info->iccp_proflen,
   1.176 +-                                              info->iccp_profile,
   1.177 +-                                              ICC_IMAGE_PROFILE);
   1.178 ++  png_charpp name;
   1.179 ++  int ctype = PNG_COMPRESSION_TYPE_BASE;
   1.180 ++  png_bytepp prof;
   1.181 ++  png_uint_32 proflen;
   1.182 ++  if (png_get_iCCP(pp,info,name,&ctype,prof,&proflen) > 0) {
   1.183 ++    gimp_image_set_icc_profile_by_mem (image, proflen, prof, ICC_IMAGE_PROFILE);
   1.184 +     printf ("%s:%d %s() set embedded profile \"%s\"\n",
   1.185 +-             __FILE__,__LINE__,__func__,
   1.186 +-                                              info->iccp_name);
   1.187 ++             __FILE__,__LINE__,__func__,(const char *)name);
   1.188 +   }
   1.189 ++}
   1.190 + #endif
   1.191 + 
   1.192 +  /*
   1.193 +@@ -774,6 +780,8 @@
   1.194 +  * 'save_image ()' - Save the specified image to a PNG file.
   1.195 +  */
   1.196 + 
   1.197 ++typedef png_info *png_infop;
   1.198 ++
   1.199 + static gint
   1.200 + save_image (gchar  *filename,	        /* I - File to save to */
   1.201 + 	    gint32  image_ID,	        /* I - Image to save */
   1.202 +@@ -794,7 +802,7 @@
   1.203 +   GPixelRgn	pixel_rgn;	/* Pixel region for layer */
   1.204 +   png_structp	pp;		/* PNG read pointer */
   1.205 +   png_infop	info;		/* PNG info pointer */
   1.206 +-  gint		num_colors;	/* Number of colors in colormap */
   1.207 ++  gint		num_colors = 0;	/* Number of colors in colormap */
   1.208 +   gint		offx, offy;	/* Drawable offsets from origin */
   1.209 +   guchar	**pixels,	/* Pixel rows */
   1.210 + 		*fixed,		/* Fixed-up pixel data */
   1.211 +@@ -808,6 +816,7 @@
   1.212 +                 blue;           /* Used for palette background */
   1.213 +   time_t	cutime;         /* Time since epoch */
   1.214 +   struct tm	*gmt;		/* GMT broken down */
   1.215 ++  int bit_depth,color_type;
   1.216 + 
   1.217 +  /*
   1.218 +   * PNG 0.89 and newer have a sane, forwards compatible constructor.
   1.219 +@@ -824,7 +833,7 @@
   1.220 +   info = (png_infop)calloc(sizeof(png_info), 1);
   1.221 + #endif /* PNG_LIBPNG_VER > 88 */
   1.222 + 
   1.223 +-  if (setjmp (pp->jmpbuf))
   1.224 ++  if (setjmp (png_jmpbuf(pp)))
   1.225 +   {
   1.226 +     g_message ("%s\nPNG error. Couldn't save image", filename);
   1.227 +     return 0;
   1.228 +@@ -863,10 +872,6 @@
   1.229 + 
   1.230 +   png_set_compression_level (pp, pngvals.compression_level);
   1.231 + 
   1.232 +-  info->width          = drawable->width;
   1.233 +-  info->height         = drawable->height;
   1.234 +-  info->interlace_type = pngvals.interlaced;
   1.235 +-
   1.236 +  /*
   1.237 +   * Set color type and remember bytes per pixel count 
   1.238 +   */
   1.239 +@@ -874,71 +879,69 @@
   1.240 +   switch (type)
   1.241 +   {
   1.242 +     case RGB_IMAGE :
   1.243 +-        info->color_type = PNG_COLOR_TYPE_RGB;
   1.244 +-	info->bit_depth      = 8;
   1.245 ++        color_type = PNG_COLOR_TYPE_RGB;
   1.246 ++	bit_depth      = 8;
   1.247 +         bpp              = 3;
   1.248 +         break;
   1.249 +     case RGBA_IMAGE :
   1.250 +-        info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
   1.251 +-	info->bit_depth      = 8;
   1.252 ++        color_type = PNG_COLOR_TYPE_RGB_ALPHA;
   1.253 ++	bit_depth      = 8;
   1.254 +         bpp              = 4;
   1.255 +         break;
   1.256 +     case GRAY_IMAGE :
   1.257 +-        info->color_type = PNG_COLOR_TYPE_GRAY;
   1.258 +-	info->bit_depth      = 8;
   1.259 ++        color_type = PNG_COLOR_TYPE_GRAY;
   1.260 ++	bit_depth      = 8;
   1.261 +         bpp              = 1;
   1.262 +         break;
   1.263 +     case GRAYA_IMAGE :
   1.264 +-        info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
   1.265 +-	info->bit_depth      = 8;
   1.266 ++        color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
   1.267 ++	bit_depth      = 8;
   1.268 +         bpp              = 2;
   1.269 +         break;
   1.270 +     case INDEXED_IMAGE :
   1.271 + 	bpp		 = 1;
   1.272 +-	info->bit_depth      = 8;
   1.273 +-        info->color_type = PNG_COLOR_TYPE_PALETTE;
   1.274 +-	info->valid      |= PNG_INFO_PLTE;
   1.275 +-        info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors);
   1.276 +-        info->num_palette= num_colors;
   1.277 ++	bit_depth      = 8;
   1.278 ++        color_type = PNG_COLOR_TYPE_PALETTE;
   1.279 ++	void *plte = gimp_image_get_cmap(image_ID, &num_colors);
   1.280 ++	png_set_PLTE(pp,info,plte,num_colors);
   1.281 +         break;
   1.282 +     case INDEXEDA_IMAGE :
   1.283 + 	bpp		 = 2;
   1.284 +-	info->bit_depth      = 8;
   1.285 +-	info->color_type = PNG_COLOR_TYPE_PALETTE;
   1.286 ++	bit_depth      = 8;
   1.287 ++	color_type = PNG_COLOR_TYPE_PALETTE;
   1.288 + 	respin_cmap (pp, info, image_ID); /* fix up transparency */
   1.289 + 	break;
   1.290 +     case U16_RGB_IMAGE :
   1.291 +-        info->color_type = PNG_COLOR_TYPE_RGB;
   1.292 +-	info->bit_depth      = 16;
   1.293 ++        color_type = PNG_COLOR_TYPE_RGB;
   1.294 ++	bit_depth      = 16;
   1.295 +         bpp              = 6;
   1.296 +         break;
   1.297 +     case U16_RGBA_IMAGE :
   1.298 +-        info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
   1.299 +-	info->bit_depth      = 16;
   1.300 ++        color_type = PNG_COLOR_TYPE_RGB_ALPHA;
   1.301 ++	bit_depth      = 16;
   1.302 +         bpp              = 8;
   1.303 +         break;
   1.304 +     case U16_GRAY_IMAGE :
   1.305 +-        info->color_type = PNG_COLOR_TYPE_GRAY;
   1.306 +-	info->bit_depth      = 16;
   1.307 ++        color_type = PNG_COLOR_TYPE_GRAY;
   1.308 ++	bit_depth      = 16;
   1.309 +         bpp              = 2;
   1.310 +         break;
   1.311 +     case U16_GRAYA_IMAGE :
   1.312 +-        info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
   1.313 +-	info->bit_depth      = 16;
   1.314 ++        color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
   1.315 ++	bit_depth      = 16;
   1.316 +         bpp              = 4;
   1.317 +         break;
   1.318 +-    case U16_INDEXED_IMAGE :
   1.319 ++    case U16_INDEXED_IMAGE :{
   1.320 + 	bpp		 = 2;
   1.321 +-	info->bit_depth      = 16;
   1.322 +-        info->color_type = PNG_COLOR_TYPE_PALETTE;
   1.323 +-	info->valid      |= PNG_INFO_PLTE;
   1.324 +-        info->palette= (png_colorp) gimp_image_get_cmap(image_ID, &num_colors);
   1.325 +-        info->num_palette= num_colors;
   1.326 ++	bit_depth      = 16;
   1.327 ++        color_type = PNG_COLOR_TYPE_PALETTE;
   1.328 ++	void *plte = gimp_image_get_cmap(image_ID, &num_colors);
   1.329 ++	png_set_PLTE(pp,info,plte,num_colors);
   1.330 +         break;
   1.331 +-    case U16_INDEXEDA_IMAGE :
   1.332 ++    }case U16_INDEXEDA_IMAGE :
   1.333 + 	bpp		 = 4;
   1.334 +-	info->bit_depth      = 16;
   1.335 +-	info->color_type = PNG_COLOR_TYPE_PALETTE;
   1.336 ++	bit_depth      = 16;
   1.337 ++	color_type = PNG_COLOR_TYPE_PALETTE;
   1.338 + 	respin_cmap (pp, info, image_ID); /* fix up transparency */
   1.339 + 	break;
   1.340 +     default:
   1.341 +@@ -950,16 +953,21 @@
   1.342 +   * Fix bit depths for (possibly) smaller colormap images
   1.343 +   */
   1.344 +   
   1.345 +-  if (info->valid & PNG_INFO_PLTE) {
   1.346 +-    if (info->num_palette <= 2)
   1.347 +-      info->bit_depth= 1;
   1.348 +-    else if (info->num_palette <= 4)
   1.349 +-      info->bit_depth= 2;
   1.350 +-    else if (info->num_palette <= 16)
   1.351 +-      info->bit_depth= 4;
   1.352 ++  if (png_get_valid(pp,info,PNG_INFO_PLTE) & PNG_INFO_PLTE) {
   1.353 ++    if (num_colors <= 2)
   1.354 ++      bit_depth= 1;
   1.355 ++    else if (num_colors <= 4)
   1.356 ++      bit_depth= 2;
   1.357 ++    else if (num_colors <= 16)
   1.358 ++      bit_depth= 4;
   1.359 +     /* otherwise the default is fine */
   1.360 +   }
   1.361 + 
   1.362 ++  png_set_IHDR(pp,info,drawable->width,drawable->height,
   1.363 ++		bit_depth,color_type,pngvals.interlaced,
   1.364 ++		PNG_COMPRESSION_TYPE_DEFAULT,
   1.365 ++		PNG_FILTER_TYPE_DEFAULT);
   1.366 ++
   1.367 +   // write icc profile
   1.368 + #if defined(PNG_iCCP_SUPPORTED)
   1.369 +   if (gimp_image_has_icc_profile (image_ID, ICC_IMAGE_PROFILE)) {
   1.370 +@@ -973,7 +981,7 @@
   1.371 +                   0, buffer, size);
   1.372 +     printf ("%s:%d %s() embedd icc profile \"%s\"\n",
   1.373 +              __FILE__,__LINE__,__func__,
   1.374 +-                                              info->iccp_name);
   1.375 ++           gimp_image_get_icc_profile_description (image_ID, ICC_IMAGE_PROFILE));
   1.376 +   }
   1.377 + #endif
   1.378 + 
   1.379 +@@ -1039,13 +1047,13 @@
   1.380 +   * Convert unpacked pixels to packed if necessary
   1.381 +   */
   1.382 + 
   1.383 +-  if (info->color_type == PNG_COLOR_TYPE_PALETTE && info->bit_depth < 8)
   1.384 ++  if (png_get_color_type(pp, info) == PNG_COLOR_TYPE_PALETTE && png_get_bit_depth(pp,info) < 8)
   1.385 +     png_set_packing(pp);
   1.386 + 
   1.387 +   /* Set swapping for 16 bit per sample images */
   1.388 +   
   1.389 + #ifndef WORDS_BIGENDIAN
   1.390 +-  if (info->bit_depth == 16)
   1.391 ++  if (png_get_bit_depth(pp,info) == 16)
   1.392 + 	  png_set_swap(pp);
   1.393 + #endif
   1.394 +   
   1.395 +@@ -1077,7 +1085,7 @@
   1.396 + 	num = end - begin;
   1.397 + 	
   1.398 + 	gimp_pixel_rgn_get_rect (&pixel_rgn, pixel, 0, begin, drawable->width, num);
   1.399 +-        if (info->valid & PNG_INFO_tRNS) {
   1.400 ++        if (png_get_valid(pp,info,PNG_INFO_tRNS) & PNG_INFO_tRNS) {
   1.401 +           for (i = 0; i < num; ++i) {
   1.402 + 	    fixed= pixels[i];
   1.403 +             for (k = 0; k < drawable->width; ++k) {
   1.404 +@@ -1085,7 +1093,7 @@
   1.405 +             }
   1.406 +           }
   1.407 +        /* Forgot this case before, what if there are too many colors? */
   1.408 +-        } else if (info->valid & PNG_INFO_PLTE && bpp == 2) {
   1.409 ++        } else if (png_get_valid(pp,info,PNG_INFO_PLTE) & PNG_INFO_PLTE && bpp == 2) {
   1.410 +           for (i = 0; i < num; ++i) {
   1.411 + 	    fixed= pixels[i];
   1.412 +             for (k = 0; k < drawable->width; ++k) {
   1.413 +@@ -1097,7 +1105,7 @@
   1.414 + 	png_write_rows (pp, pixels, num);
   1.415 + 	
   1.416 + 	gimp_progress_update (((double)pass + (double)end /
   1.417 +-                    (double)info->height) / (double)num_passes);
   1.418 ++                    (double)png_get_image_height(pp,info)) / (double)num_passes);
   1.419 +       };
   1.420 +   };
   1.421 + 
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/cinepaint/stuff/patches/series	Sat Nov 04 12:45:00 2017 +0100
     2.3 @@ -0,0 +1,1 @@
     2.4 +cinepaint-1.4-png.patch