Index: gimpcurvestool.c
===================================================================
RCS file: /cvs/gnome/gimp/app/tools/gimpcurvestool.c,v
retrieving revision 1.164
diff -u -3 -r1.164 gimpcurvestool.c
--- gimpcurvestool.c	12 Feb 2004 13:12:56 -0000	1.164
+++ gimpcurvestool.c	27 Feb 2004 13:50:45 -0000
@@ -1360,46 +1360,86 @@
   gint  fields;
   gchar buf[50];
   gint  index[5][17];
-  gint  value[5][17];
+  gint  value[5][256];
+  gint curve_type[5];
+  gint version;
 
   if (! fgets (buf, 50, file))
     return FALSE;
 
-  if (strcmp (buf, "# GIMP Curves File\n") != 0)
+  if (strcmp (buf, "# GIMP Curves File\n") != 0 &&
+        strcmp (buf, "# GIMP2 Curves File\n") != 0 )
     return FALSE;
+  if (strcmp (buf, "# GIMP2 Curves File\n")==0)
+    {
+       /* Version 2 and above includes support for loading  and saving GIMP_CURVE_FREE curves*/
+       fields= fscanf (file, "%d", &version);
+       if (fields != 1)
+         return FALSE;
+       if (version>=2)
+         {
+           for ( i = 0; i < 5; i++)
+             {
+               fields = fscanf (file, "%d ", &curve_type[i]);
+               if ( fields != 1 )
+                 return FALSE;
+             }
+         }
+    }
+  else
+    version = 1;
+
+  if (version == 1)
+    for (i = 0; i < 5 ; i++)
+      curve_type[i] = GIMP_CURVE_SMOOTH;
 
   for (i = 0; i < 5; i++)
     {
-      for (j = 0; j < 17; j++)
-	{
-	  fields = fscanf (file, "%d %d ", &index[i][j], &value[i][j]);
-	  if (fields != 2)
-	    {
-	      g_print ("fields != 2");
-	      return FALSE;
-	    }
-	}
+      if (curve_type [i] == GIMP_CURVE_SMOOTH)
+        for (j = 0; j < 17; j++)
+          {
+            fields = fscanf (file, "%d %d ", &index[i][j], &value[i][j]);
+            if (fields != 2)
+             {
+               g_print ("fields != 2");
+               return FALSE;
+             }
+          }
+      else
+        for (j = 0; j < 256;  j++)
+          {
+            fields = fscanf (file, "%d ",  &value[i][j]);
+            if (fields != 1)
+              {
+                g_print ("fields != 1");
+                return FALSE;
+              }
+          }
     }
 
   for (i = 0; i < 5; i++)
     {
-      c_tool->curves->curve_type[i] = GIMP_CURVE_SMOOTH;
-
-      for (j = 0; j < 17; j++)
-	{
-	  c_tool->curves->points[i][j][0] = index[i][j];
-	  c_tool->curves->points[i][j][1] = value[i][j];
-	}
+      c_tool->curves->curve_type[i] = curve_type[i];
+      if (curve_type [i] == GIMP_CURVE_SMOOTH)
+        for (j = 0; j < 17; j++)
+          {
+             c_tool->curves->points[i][j][0] = index[i][j];
+             c_tool->curves->points[i][j][1] = value[i][j];
+          }
+      else
+        for  (j = 0; j < 256; j++)
+          c_tool->curves->curve[i][j] = value[i][j];
     }
 
   for (i = 0; i < 5; i++)
-    curves_calculate_curve (c_tool->curves, i);
+    if (curve_type[i] == GIMP_CURVE_SMOOTH)
+        curves_calculate_curve (c_tool->curves, i);
 
   curves_update (c_tool, ALL);
   gtk_widget_queue_draw (c_tool->graph);
 
-  gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (c_tool->curve_type),
-			           GIMP_CURVE_SMOOTH);
+   gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (c_tool->curve_type),
+                curve_type[c_tool->channel]);
 
   gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (c_tool));
 
@@ -1411,30 +1451,25 @@
                       FILE           *file)
 {
   gint   i, j;
-  gint32 index;
+
+  fprintf (file, "# GIMP2 Curves File\n");
+  fprintf (file, "2\n");
 
   for (i = 0; i < 5; i++)
-    if (c_tool->curves->curve_type[i] == GIMP_CURVE_FREE)
-      {
-	/*  pick representative points from the curve
-            and make them control points  */
-	for (j = 0; j <= 8; j++)
-	  {
-	    index = CLAMP0255 (j * 32);
-	    c_tool->curves->points[i][j * 2][0] = index;
-	    c_tool->curves->points[i][j * 2][1] = c_tool->curves->curve[i][index];
-	  }
-      }
+      fprintf (file, "%d ",c_tool->curves->curve_type[i]);
+  fprintf (file, "\n");
 
-  fprintf (file, "# GIMP Curves File\n");
 
   for (i = 0; i < 5; i++)
     {
-      for (j = 0; j < 17; j++)
-	fprintf (file, "%d %d ",
+      if (c_tool->curves->curve_type[i] == GIMP_CURVE_SMOOTH)
+        for (j = 0; j < 17; j++)
+          fprintf (file, "%d %d ",
                  c_tool->curves->points[i][j][0],
                  c_tool->curves->points[i][j][1]);
-
+      else
+        for (j = 0; j < 256; j++)
+          fprintf (file, "%d ", c_tool->curves->curve[i][j]);
       fprintf (file, "\n");
     }
 }
