In libmng-1.0.10/doc you can find two large PNG files:
Plan1.png and Plan2.png .

Both have alpha transparency and are interlaced.
fltk-2.0.x-r6970 - not handling interlace - offered a
horrible result.

The following patch allows to show a good result.

winfried

--- fl_png.cxx.orig     2010-02-21 15:07:19.000000000 +0100
+++ fl_png.cxx  2010-02-21 20:52:14.000000000 +0100
@@ -74,6 +74,8 @@
   png_infop info_ptr;
   png_uint_32 width, height;
   int bit_depth, color_type;
+  int interlace_type = 0;
+  int pass, nr_passes = 0;

   png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0,0,0);

@@ -117,16 +119,16 @@
   png_read_info(png_ptr, info_ptr);

   png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,&color_type,
-              NULL,NULL,NULL);
+              &interlace_type, NULL, NULL);

-  if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8)
-    png_set_expand(png_ptr);
+  if (color_type == PNG_COLOR_TYPE_PALETTE)
+    png_set_palette_to_rgb(png_ptr);

   if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
-    png_set_expand(png_ptr);
+    png_set_expand_gray_1_2_4_to_8(png_ptr);

-/*  if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
-      png_set_expand(png_ptr);*/
+  if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
+      png_set_tRNS_to_alpha(png_ptr);

   if (bit_depth == 16)
     png_set_strip_16(png_ptr);
@@ -143,6 +145,8 @@
   else
     png_set_gamma(png_ptr, screen_gamma, 0.50);*/

+  nr_passes = png_set_interlace_handling(png_ptr);
+
   png_read_update_info(png_ptr, info_ptr);

   png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,&color_type,
@@ -155,11 +159,30 @@
   setpixeltype(alpha ? RGBM : RGB);

   { // avoid y initialization error in VC6 because of 'goto error' code
-  for (unsigned y=0; y<height; y++) {
+   if(interlace_type)
+   {
+   for(pass = 0; pass < nr_passes; pass++)
+  {
+   for (unsigned y=0; y<height; y++)
+ {
+   uchar* b = linebuffer(y);
+   png_read_row(png_ptr, b, NULL);
+ }
+  }
+   for (unsigned y=0; y<height; y++)
+  {
+   uchar* b = linebuffer(y);
+   setpixels(b, y);
+  }
+   }
+   else // image not interlaced
+   for (unsigned y=0; y<height; y++)
+   {
     uchar* b = linebuffer(y);
     png_read_row(png_ptr, b, NULL);
     setpixels(b, y);
-  }
+   }
+
   }

   png_read_end(png_ptr, NULL);

_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs

Reply via email to