--- png.c.~1~	2005-09-20 18:19:36.000000000 +0200
+++ png.c	2005-10-19 14:05:19.000000000 +0200
@@ -683,6 +683,32 @@ load_image (const gchar *filename,
   png_textp  text;
   gint       num_texts;
 
+#if defined(PNG_iCCP_SUPPORTED)
+  /*
+   * Get the iCCP (colour profile) chunk, if any, and attach it as
+   * a parasite
+   */
+
+  if (1) {
+    png_uint_32 proflen;
+    int profcomp;
+    png_charp profname, profile;
+
+    if (png_get_iCCP(pp, info, &profname, &profcomp, &profile, &proflen)) {
+      GimpParasite *parasite;
+      parasite = gimp_parasite_new("icc-profile", 0, proflen,
+                                   profile);
+      gimp_image_parasite_attach(image, parasite);
+      gimp_parasite_free(parasite);
+      parasite  = gimp_parasite_new("icc-profile-name", 0, 
+                                    /* +1: include trailing NUL in length */
+                                    strlen(profname) + 1, profname);
+      gimp_image_parasite_attach(image, parasite);
+      gimp_parasite_free(parasite);
+    }
+  } 
+#endif
+
   /*
    * PNG 0.89 and newer have a sane, forwards compatible constructor.
    * Some SGI IRIX users will not have a new enough version though
@@ -1387,6 +1413,28 @@ save_image (const gchar *filename,
 
 #endif /* PNG_LIBPNG_VER > 99 */
 
+#if defined(PNG_iCCP_SUPPORTED)
+  if (1) {
+    GimpParasite *profile_parasite;
+    guint32 profile_size;
+    guchar *profile, *profname;
+    profile_parasite = gimp_image_parasite_find(orig_image_ID, "icc-profile");
+    if (profile_parasite) {
+      GimpParasite *profile_name_parasite;
+      profile_name_parasite
+        = gimp_image_parasite_find(orig_image_ID, "icc-profile-name");
+      if (profile_name_parasite) {
+        profname = gimp_parasite_data(profile_name_parasite);
+      } else {
+        profname = "profile";
+      }
+      profile_size = gimp_parasite_data_size(profile_parasite);
+      profile = gimp_parasite_data(profile_parasite);
+      png_set_iCCP(pp, info, profname, 0, profile, profile_size);
+    }
+  }
+#endif
+
   png_write_info (pp, info);
 
   /*
