Re: cairo built against libpng16

Ingmar Runge <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAAUiU8Z14zwjTjcKqgeOECxCjnTO3YD4mV+iNOb56CXxWU3j6A@mail.gmail.com>
Hey everyone, here's a possible patch. It's the least invasive patch I
could think of.

On Wed, Mar 20, 2013 at 10:16 AM,  <[email protected]> wrote:
> Hi,
>
> simple program attached seems to have different results when
> cairo is built against libpng15 and when it is built against
> libpng16*):
>
> cairo-libpng15-changeroot> ./cairo-fail tmp.png
> PNG image read.
>
> cairo-libpng16-changeroot> ./cairo-fail tmp.png
> Error reading PNG image tmp.png: out of memory
>
>
> The difference between changeroots are really only libpng version:
> @@ -141,9 +141,9 @@ libpcrecpp0-8.31-5.1.x86_64
>  libpcreposix0-8.31-5.1.x86_64
>  libpixman-1-0-0.28.2-3.1.x86_64
>  libpixman-1-0-devel-0.28.2-3.1.x86_64
> -libpng15-15-1.5.14-1.1.x86_64
> -libpng15-compat-devel-1.5.14-1.1.x86_64
> -libpng15-devel-1.5.14-1.1.x86_64
> +libpng16-16-1.6.0-25.1.x86_64
> +libpng16-compat-devel-1.6.0-25.1.x86_64
> +libpng16-devel-1.6.0-25.1.x86_64
>  libpopt0-1.16-20.1.x86_64
>  libppl9-0.11.2-15.1.x86_64
>  libppl_c4-0.11.2-15.1.x86_64
>
> cairo-libpng1{5,6}-changeroot> rpm -q cairo-devel
> cairo-devel-1.12.14-0.x86_64
>
> Petr
>
>
> *) This boiled down when building perl-Cairo against cairo(libpng16).
> 40-th test from CairoSurface.t failed. In turn that means that second
> test from the following doesn't succed.
>
> use strict;
> use warnings;
>
> use Test::More tests => 2;
>
> use constant IMG_WIDTH => 256;
> use constant IMG_HEIGHT => 256;
>
> use Cairo;
>
> my $surf = Cairo::ImageSurface->create ('rgb24', IMG_WIDTH,
> IMG_HEIGHT);
> is ($surf->write_to_png ('tmp.png'), 'success');
>
> $surf = Cairo::ImageSurface->create_from_png ('tmp.png');
> is ($surf->status, 'success');
>
>
> --
> cairo mailing list
> [email protected]
> http://lists.cairographics.org/mailman/listinfo/cairo

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
cairo-libpng16.patch (application/octet-stream, 1.6 KB)
--- cairo-png.c	2012-03-29 12:05:32.000000000 +0200
+++ cairo-png.c	2013-03-30 09:13:50.817181600 +0100
@@ -497,6 +497,20 @@
     }
 }
 
+/* branches into premultiply_data or convert_bytes_to_data depending on color type */
+static void read_user_transform_func (png_structp png, png_row_infop row_info, png_bytep data)
+{
+    switch ((cairo_format_t) png_get_user_transform_ptr (png)) {
+        case CAIRO_FORMAT_ARGB32:
+            premultiply_data (png, row_info, data);
+            break;
+
+        case PNG_COLOR_TYPE_RGB:
+            convert_bytes_to_data (png, row_info, data);
+            break;
+    }
+}
+
 static cairo_status_t
 stdio_read_func (void *closure, unsigned char *data, unsigned int size)
 {
@@ -623,6 +637,9 @@
 
     png_set_filler (png, 0xff, PNG_FILLER_AFTER);
 
+    /* this must be stored before calling png_read_update_info */
+    png_set_read_user_transform_fn (png, read_user_transform_func);
+
     /* recheck header after setting EXPAND options */
     png_read_update_info (png, info);
     png_get_IHDR (png, info,
@@ -643,15 +660,15 @@
 
 	case PNG_COLOR_TYPE_RGB_ALPHA:
 	    format = CAIRO_FORMAT_ARGB32;
-	    png_set_read_user_transform_fn (png, premultiply_data);
 	    break;
 
 	case PNG_COLOR_TYPE_RGB:
 	    format = CAIRO_FORMAT_RGB24;
-	    png_set_read_user_transform_fn (png, convert_bytes_to_data);
 	    break;
     }
 
+    png_set_user_transform_info (png, (void*) format, 0, 0);
+
     stride = cairo_format_stride_for_width (format, png_width);
     if (stride < 0) {
 	surface = _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_STRIDE));
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.