[xiph-commits] r13551 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Wed Aug 15 15:56:18 PDT 2007


Author: xiphmont
Date: 2007-08-15 15:56:18 -0700 (Wed, 15 Aug 2007)
New Revision: 13551

Modified:
   trunk/sushivision/dimension.c
   trunk/sushivision/example_fractal.c
   trunk/sushivision/internal.h
   trunk/sushivision/objective.c
   trunk/sushivision/scale.c
   trunk/sushivision/sushivision.h
Log:
Some work simplifying usage of scale API



Modified: trunk/sushivision/dimension.c
===================================================================
--- trunk/sushivision/dimension.c	2007-08-15 21:37:14 UTC (rev 13550)
+++ trunk/sushivision/dimension.c	2007-08-15 22:56:18 UTC (rev 13551)
@@ -732,17 +732,19 @@
 
 // XXXX need to recompute after
 // XXXX need to add scale cloning to compute to make this safe in callbacks
-int sv_dim_make_scale(unsigned scalevals, 
-		      double *scaleval_list,
-		      char **scalelabel_list,
-		      unsigned flags){
+int sv_dim_make_scale(char *first, char *second, ...){
   sv_dim_t *d = sv_dim(0);
+  sv_scale_t *scale;
+  va_list ap;
+  int ret;
+
+  va_start(ap, second);  
   if(!d) return -EINVAL;
-
-  sv_scale_t *scale = sv_scale_new(d->name,scalevals,scaleval_list,scalelabel_list,0);
+  scale = _sv_scale_new_v(d->name,first,second,ap);
   if(!scale)return errno;
-
-  int ret = sv_dim_set_scale(scale);
+  va_end(ap);
+  
+  ret = sv_dim_set_scale(scale);
   sv_scale_free(scale);
   return ret;
 }

Modified: trunk/sushivision/example_fractal.c
===================================================================
--- trunk/sushivision/example_fractal.c	2007-08-15 21:37:14 UTC (rev 13550)
+++ trunk/sushivision/example_fractal.c	2007-08-15 22:56:18 UTC (rev 13551)
@@ -59,23 +59,23 @@
 
 
   sv_dim_t *d0 = sv_dim_new(0, "Re(c)", 0);
-  sv_dim_make_scale(5, (double []){-2.25,-0.75,0,0.25,0.75}, NULL, 0);
+  sv_dim_make_scale("-2.25","-0.75","0","0.25","0.75","");
   
   sv_dim_t *d1 = sv_dim_new(1, "Im(c)", 0);
-  sv_dim_make_scale(5, (double []){-2,-1,0,1,2}, NULL, 0);
+  sv_dim_make_scale("-2","-1","0","1","2","");
 
   sv_dim_t *d2 = sv_dim_new(2, "Re(z0)", 0);
-  sv_dim_make_scale(5, (double []){-2.25,-1,0,1,2.25}, NULL, 0);
+  sv_dim_make_scale("-2.25","-1","0","1","2.25","");
 
   sv_dim_t *d3 = sv_dim_new(3, "Im(z0)", 0);
-  sv_dim_make_scale(5, (double []){-2.25,-1,0,1,2.25}, NULL, 0);
+  sv_dim_make_scale("-2.25","-1","0","1","2.25","");
 
   sv_dim_t *d4 = sv_dim_new(4, "Max Iterations", 0);
-  sv_dim_make_scale(4, (double []){100,1000,10000,100000},
-		    (char *[]){"one hundred",
-			"one thousand",
-			"ten thousand",
-			"one hundred thousand"}, 0);
+  sv_dim_make_scale("100:one hundred",
+		    "1000:one thousand",
+		    "10000:ten thousand",
+		    "100000:one hundred thousand",
+		    "");
 
   sv_dim_set_picklist();
   sv_dim_set_value(100);
@@ -86,13 +86,13 @@
 			    (sv_func_t *[]){f},
 			    (int []){0},
 			    "Y", 0);
-  sv_obj_make_scale(o0, 5, (double []){0, .001, .01, .1, 1.0}, NULL, 0);
+  sv_obj_make_scale(o0, "0", ".001", ".01", ".1", "1.0", "");
   
   sv_obj_t *o1 = sv_obj_new(1,"inner",
 			    (sv_func_t *[]){f},
 			    (int []){1},
 			    "Y", 0);
-  sv_obj_make_scale(o1, 5, (double []){0, .001, .01, .1, 1.0}, NULL, 0);
+  sv_obj_make_scale(o1, "0", ".001", ".01", ".1", "1.0", "");
   
   sv_panel_new_2d(0,"Mandel/Julia Fractal",
 		  (sv_obj_t *[]){o0,o1,NULL},

Modified: trunk/sushivision/internal.h
===================================================================
--- trunk/sushivision/internal.h	2007-08-15 21:37:14 UTC (rev 13550)
+++ trunk/sushivision/internal.h	2007-08-15 22:56:18 UTC (rev 13551)
@@ -194,6 +194,8 @@
 extern void _sv_undo_up();
 extern void _sv_undo_down();
 
+extern sv_scale_t *_sv_scale_new_v(char *legend, char *first, char *second, va_list ap);
+
 extern sig_atomic_t _sv_exiting;
 extern char *_sv_filebase;
 extern char *_sv_filename;

Modified: trunk/sushivision/objective.c
===================================================================
--- trunk/sushivision/objective.c	2007-08-15 21:37:14 UTC (rev 13550)
+++ trunk/sushivision/objective.c	2007-08-15 22:56:18 UTC (rev 13551)
@@ -199,16 +199,22 @@
 // XXXX need to recompute after
 // XXXX need to add scale cloning to compute to make this safe in callbacks
 int sv_obj_make_scale(sv_obj_t *in,
-		      unsigned scalevals, 
-		      double *scaleval_list,
-		      char **scalelabel_list,
-		      unsigned flags){
+		      char *first,
+		      char *second,
+		      ...){
+
   sv_obj_t *o = (sv_obj_t *)in; //unwrap
+  sv_scale_t *scale;
+  va_list ap;
+  int ret;
 
-  sv_scale_t *scale = sv_scale_new(o->name,scalevals,scaleval_list,scalelabel_list,0);
+  va_start(ap, second);  
+  if(!o) return -EINVAL;
+  scale = _sv_scale_new_v(o->name,first,second,ap);
   if(!scale)return errno;
+  va_end(ap);
 
-  int ret = sv_obj_set_scale(o,scale);
+  ret = sv_obj_set_scale(o,scale);
   sv_scale_free(scale);
   return ret;
 }

Modified: trunk/sushivision/scale.c
===================================================================
--- trunk/sushivision/scale.c	2007-08-15 21:37:14 UTC (rev 13550)
+++ trunk/sushivision/scale.c	2007-08-15 22:56:18 UTC (rev 13551)
@@ -161,52 +161,82 @@
   }
 }
 
-sv_scale_t *sv_scale_new(char *legend, 
-			 unsigned scalevals, double *scaleval_list, char **labels, 
-			 unsigned flags){
-  int i;
+sv_scale_t *_sv_scale_new_v(char *legend, char *first, char *second, va_list ap){
+  int i=0;
+  sv_scale_t *s = calloc(1, sizeof(*s));
+  va_list ac;
+  char *arg;
+  int count=0;
 
-  sv_scale_t *s = NULL;
-
-  if(scalevals<2){
-    fprintf(stderr,"Scale requires at least two scale values.");
-    return NULL;
+  va_copy(ac, ap);
+  arg = va_arg(ac, char *);
+  while(arg && arg[0]){
+    count++;
+    arg = va_arg(ac, char *);
   }
+  va_end(ac);
 
-  s = calloc(1, sizeof(*s));
-  
-  // copy values
-  s->vals = scalevals;
-  s->val_list = calloc(scalevals,sizeof(*s->val_list));
-  for(i=0;i<(int)scalevals;i++)
-    s->val_list[i] = scaleval_list[i];
+  s->vals = count+2;
+  s->val_list = calloc(s->vals,sizeof(*s->val_list));
+  s->label_list = calloc(s->vals,sizeof(*s->label_list));
 
-  if(labels){
-    // copy labels
-    s->label_list = calloc(scalevals,sizeof(*s->label_list));
-    for(i=0;i<(int)scalevals;i++)
-      if(labels[i]){
-	s->label_list[i] = strdup(labels[i]);
-      }else{
-	s->label_list[i] = strdup("");
-      }
-  }else{
-    // generate labels
-    s->label_list = scale_generate_labels(scalevals,scaleval_list);
+  arg=first;
+  while(arg && arg[0]){
+    // an argument is a number and potentially a colon followed by an auxiliary label.
+    char *buf = strdup(arg);
+    char *pos = strchr(buf,':');
+    if(pos){
+      s->label_list[i] = strdup(pos+1);
+      *pos='\0';
+      s->val_list[i]=atof(buf);
+      free(buf);
+    }else{
+      s->label_list[i] = buf;
+      s->val_list[i]=atof(buf);
+    }
+    
+    if(arg==first){
+      arg=second;
+    }else{
+      arg=va_arg(ap, char *);
+    }
+    i++;
   }
+
   if(legend)
     s->legend=strdup(legend);
   else
     s->legend=strdup("");
 
-  s->flags = flags;
   return s;
 }
 
-sv_scale_t *sv_scale_copy(sv_scale_t *s){
-  return sv_scale_new(s->legend, s->vals, s->val_list, (char **)s->label_list, s->flags);
+sv_scale_t *sv_scale_new(char *legend, char *first, char *second, ...){
+  va_list ap;
+  sv_scale_t *ret;
+
+  va_start(ap, second);
+  ret = _sv_scale_new_v(legend,first,second,ap);
+  va_end(ap);
+  return ret;
 }
 
+sv_scale_t *sv_scale_copy(sv_scale_t *in){
+  sv_scale_t *s = calloc(1, sizeof(*s));
+  int i;
+
+  s->vals = in->vals;
+  s->val_list = calloc(s->vals,sizeof(*s->val_list));
+  s->label_list = calloc(s->vals,sizeof(*s->label_list));
+  s->legend = strdup(in->legend);
+
+  for(i=0;i<s->vals;i++){
+    s->val_list[i]=in->val_list[i];
+    s->label_list[i] = strdup(in->label_list[i]);
+  }
+  return s;
+}
+
 /************************* plot and graph scalespaces *********************/
 
 double _sv_scalespace_value(_sv_scalespace_t *s, double pixel){

Modified: trunk/sushivision/sushivision.h
===================================================================
--- trunk/sushivision/sushivision.h	2007-08-15 21:37:14 UTC (rev 13550)
+++ trunk/sushivision/sushivision.h	2007-08-15 22:56:18 UTC (rev 13551)
@@ -21,7 +21,9 @@
 
 #ifndef _SUSHIVISION_
 #define _SUSHIVISION_
-  
+
+#include <stdarg.h>
+
 typedef struct sv_scale sv_scale_t;
 typedef struct sv_panel sv_panel_t;
 typedef struct sv_dim   sv_dim_t;
@@ -60,10 +62,9 @@
 };
 
 sv_scale_t        *sv_scale_new (char *legend,
-				 unsigned scalevals, 
-				 double *scaleval_list, 
-				 char **scalelabel_list,
-				 unsigned flags);
+				 char *first,
+				 char *second,
+				 ...);
 
 sv_scale_t       *sv_scale_copy (sv_scale_t *s);
 
@@ -104,10 +105,9 @@
 
 int            sv_dim_set_scale (sv_scale_t *scale);
 
-int           sv_dim_make_scale (unsigned scalevals, 
-				 double *scaleval_list, 
-				 char **scalelabel_list,
-				 unsigned flags);
+int           sv_dim_make_scale (char *first,
+				 char *second,
+				 ...);
 
 int         sv_dim_set_discrete (long quant_numerator,
 				 long quant_denominator);
@@ -176,14 +176,13 @@
 				 sv_func_t *function,
 				 unsigned flags);
 
-int            sv_obj_set_scale (sv_obj_t *d,
+int            sv_obj_set_scale (sv_obj_t *o,
 				 sv_scale_t *scale);
 
-int           sv_obj_make_scale (sv_obj_t *d,
-				 unsigned scalevals, 
-				 double *scaleval_list, 
-				 char **scalelabel_list,
-				 unsigned flags);
+int           sv_obj_make_scale (sv_obj_t *o,
+				 char *first,
+				 char *second,
+				 ...);
 
 /* panels ********************************************************/
 



More information about the commits mailing list