[Gimp-developer] Patch for curve tool

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
the attached patch changes the curve tool in the following way.

1. the setting of the curve is remembered if the tool is closed. (this change 
does not increase ram usage, but increases speed a little bit)

2. added a little bit comments.

3. some further small changes.

Ralf Engels
diff -Naur tools-alt/gimpcurvestool.c tools/gimpcurvestool.c
--- tools-alt/gimpcurvestool.c	Sat Aug  4 19:31:11 2001
+++ tools/gimpcurvestool.c	Sat Aug  4 22:15:02 2001
@@ -138,7 +138,8 @@
 static void   curves_free_callback        (GtkWidget      *widget,
 					   gpointer        data);
 
-static void   curves_channel_reset        (gint            );
+static void   curves_channel_reset        (CurvesDialog   *cd,
+					   gint            );
 static void   curves_reset_callback       (GtkWidget      *widget,
 					   gpointer        data);
 static void   curves_ok_callback          (GtkWidget      *widget,
@@ -186,7 +187,7 @@
 static GtkWidget *file_dlg = NULL;
 static gboolean   load_save;
 
-static GtkWidget *channel_items[5];
+static GtkWidget *channel_items[CURVE_NUM_CHANNELS];
 
 static CRMatrix CR_basis =
 {
@@ -307,16 +308,7 @@
       curves_dialog = curves_dialog_new ();
     }
      
-  /*  Initialize the values  */
-  curves_dialog->channel = GIMP_HISTOGRAM_VALUE;
-  for (i = 0; i < 5; i++)
-    for (j = 0; j < 256; j++)
-      curves_dialog->curve[i][j] = j;
-  
-  for (i = 0; i < 5; i++)
-    {
-      curves_channel_reset (i);
-    }
+  /*  Initialize image dependent values  */
 
   curves_dialog->drawable  = gimp_image_active_drawable (gdisp->gimage);
   curves_dialog->color     = gimp_drawable_is_rgb (curves_dialog->drawable);
@@ -349,6 +341,9 @@
     gtk_widget_show (curves_dialog->shell);
 
   curves_update (curves_dialog, GRAPH | DRAW);
+
+  if (curves_dialog->preview)
+    curves_preview (curves_dialog);
 }
 
 static void
@@ -650,24 +645,44 @@
   gint i, j;
 
   cd = g_new (CurvesDialog, 1);
-  cd->cursor_ind_height = -1;
-  cd->cursor_ind_width  = -1;
-  cd->preview           = TRUE;
+
+  /* Try to init all parameters with good values */
   cd->pixmap            = NULL;
+  cd->drawable          = NULL;
+  cd->color             = TRUE;
   cd->channel           = GIMP_HISTOGRAM_VALUE;
+  cd->preview           = TRUE;
 
-  for (i = 0; i < 5; i++)
+  for (i = 0; i < CURVE_NUM_CHANNELS; i++)
     cd->curve_type[i] = SMOOTH;
 
-  for (i = 0; i < 5; i++)
+  for (i = 0; i < CURVE_NUM_CHANNELS; i++)
     for (j = 0; j < 256; j++)
       cd->curve[i][j] = j;
 
   for (i = 0; i < (sizeof (cd->col_value) / sizeof (cd->col_value[0])); i++)
     cd->col_value[i] = 0;
 
+  cd->channel = GIMP_HISTOGRAM_VALUE;
+  for (i = 0; i < CURVE_NUM_CHANNELS; i++)
+    for (j = 0; j < 256; j++)
+      cd->curve[i][j] = j;
+  
+  /* reset all channels */
+  for (i = 0; i < CURVE_NUM_CHANNELS; i++)
+    {
+      curves_channel_reset (cd, i);
+    }
+
+  /* the next three values are computed on demand. */
+  cd->cursor_ind_height = -1;
+  cd->cursor_ind_width  = -1;
+  cd->cursor_ind_ascent = -1;
+
   cd->lut = gimp_lut_new ();
 
+
+
   /*  The shell and main vbox  */
   cd->shell = gimp_dialog_new (_("Curves"), "curves",
 			       tool_manager_help_func, NULL,
@@ -1324,21 +1339,21 @@
 }
 
 static void
-curves_channel_reset (int i)
+curves_channel_reset (CurvesDialog *cd, int i)
 {
   gint j;
 
-  curves_dialog->grab_point = -1;
+  cd->grab_point = -1;
 
   for (j = 0; j < 17; j++)
   {
-    curves_dialog->points[i][j][0] = -1;
-    curves_dialog->points[i][j][1] = -1;
+    cd->points[i][j][0] = -1;
+    cd->points[i][j][1] = -1;
   }
-  curves_dialog->points[i][0][0] = 0;
-  curves_dialog->points[i][0][1] = 0;
-  curves_dialog->points[i][16][0] = 255;
-  curves_dialog->points[i][16][1] = 255;
+  cd->points[i][0][0] = 0;
+  cd->points[i][0][1] = 0;
+  cd->points[i][16][0] = 255;
+  cd->points[i][16][1] = 255;
 }
 
 
@@ -1355,7 +1370,7 @@
   for (i = 0; i < 256; i++)
     cd->curve[cd->channel][i] = i;
 
-  curves_channel_reset (cd->channel);
+  curves_channel_reset (cd, cd->channel);
 
   curves_calculate_curve (cd);
   curves_update (cd, GRAPH | XRANGE_TOP | DRAW);
@@ -1834,8 +1849,8 @@
   gint  i, j;
   gint  fields;
   gchar buf[50];
-  gint  index[5][17];
-  gint  value[5][17];
+  gint  index[CURVE_NUM_CHANNELS][17];
+  gint  value[CURVE_NUM_CHANNELS][17];
   gint  current_channel;
   
   if (!fgets (buf, 50, f))
@@ -1844,7 +1859,7 @@
   if (strcmp (buf, "# GIMP Curves File\n") != 0)
     return FALSE;
 
-  for (i = 0; i < 5; i++)
+  for (i = 0; i < CURVE_NUM_CHANNELS; i++)
     {
       for (j = 0; j < 17; j++)
 	{
@@ -1857,7 +1872,7 @@
 	}
     }
 
-  for (i = 0; i < 5; i++)
+  for (i = 0; i < CURVE_NUM_CHANNELS; i++)
     {
       curves_dialog->curve_type[i] = SMOOTH;
       for (j = 0; j < 17; j++)
@@ -1869,7 +1884,7 @@
 
   /* this is ugly, but works ... */
   current_channel = curves_dialog->channel;
-  for (i = 0; i < 5; i++)
+  for (i = 0; i < CURVE_NUM_CHANNELS; i++)
     {
       curves_dialog->channel = i;
       curves_calculate_curve (curves_dialog);
@@ -1892,7 +1907,7 @@
   gint   i, j;
   gint32 index;
 
-  for (i = 0; i < 5; i++)
+  for (i = 0; i < CURVE_NUM_CHANNELS; i++)
     if (curves_dialog->curve_type[i] == GFREE)
       {  
 	/*  pick representative points from the curve and make them control points  */
@@ -1906,7 +1921,7 @@
   
   fprintf (f, "# GIMP Curves File\n");
 
-  for (i = 0; i < 5; i++)
+  for (i = 0; i < CURVE_NUM_CHANNELS; i++)
     {
       for (j = 0; j < 17; j++)
 	fprintf (f, "%d %d ", curves_dialog->points[i][j][0], 
diff -Naur tools-alt/gimpcurvestool.h tools/gimpcurvestool.h
--- tools-alt/gimpcurvestool.h	Sat Aug  4 19:31:11 2001
+++ tools/gimpcurvestool.h	Sat Aug  4 20:05:36 2001
@@ -22,6 +22,8 @@
 
 #include "gimpimagemaptool.h"
 
+/* number of channels of curve tool */
+#define CURVE_NUM_CHANNELS 5
 
 #define SMOOTH 0
 #define GFREE  1
@@ -64,19 +66,23 @@
   GimpDrawable *drawable;
   ImageMap     *image_map;
 
-  gint          color;
-  gint          channel;
-  gboolean      preview;
+  gint          color;   /* true if drawable is color */
+  gint          channel; /* active channel (in dialog) */
+  gboolean      preview; /* do we make a preview */
 
+  /* the following values are used when editing the curve */
   gint          grab_point;
   gint          last;
   gint          leftmost;
   gint          rightmost;
-  gint          curve_type[5];
-  gint          points[5][17][2];
-  guchar        curve[5][256];
-  gint          col_value[5];
+
+  /* and now the curve */
+  gint          curve_type[CURVE_NUM_CHANNELS];
+  gint          points[CURVE_NUM_CHANNELS][17][2];
+  guchar        curve[CURVE_NUM_CHANNELS][256];
+  gint          col_value[CURVE_NUM_CHANNELS];
   
+  /* the following values are used when painting the curve */
   gint          cursor_ind_height;
   gint          cursor_ind_width;
   gint          cursor_ind_ascent;

[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux