On Sat, Aug 22, 2009 at 4:05 PM, Alan W. Irwin<ir...@beluga.phys.uvic.ca> wrote:
> Here is some background to help all of us figure out what is going on. The
> -cmap0 option is parsed and executed when plparseopts is executed.  If that
> command-line option is not specified, then plinit calls plstrm_init which
> calls plspal0("") (for the case when plsc->cmap0 == NULL) which has exactly
> the same effect (default colours) as the -cmap0 "" option.  So we should
> never get bad cmap0 colours unless plsc->cmap0 != NULL, i.e., some other
> method has been used to initialize colours.
>
> The previous version of the cmap0 initialization used a call to plscmap0n(0)
> rather than plspal0("").  The old version of plscmap0n(0) would give you
> default cmap0 colours under certain circumstances, but now it just gives you
> red colours (see revision 10315 where I changed the identification but not
> the rgb values appropriately to "red" from "black") as a warning that the
> colours have not been initialized properly.
>
> Following up on this, I tried running plscmap0n(0) before plinit in example
> 10 for the python case (note not Ada), and sure enough I got an all-red
> result.  Some of our users must be depending on the old cmap0 initialization
> behaviour (plscmap0n(0) setting default colours if called before plinit) so
> that past behaviour should be restored.
>
> Hez, could you do that by inserting a call to plspal0("") into plscmap0n for
> the case when it is appropriate (plsc->cmap0 == NULL)?  N.B. I am
> specifically not asking for a return to all the specific hard-coded colours
> implemented with color_def that we had before since I far prefer the colour
> palette file approach. Of course, the tricky part of implementing this with
> colour palette files is to avoid infinitely recursive behaviour (since
> plscmap0n(0) is called by plspal0).  That is why I am asking someone more
> expert than me in C to deal with this.  :-)
>
> Once plscmap0n(0) gives default colours like before, I suspect all the Ada
> red issues will go away.  Jerry has remarked before that our Ada bindings do
> their own colour initialization, and my guess is that boils down in the
> cmap0 case to a call to plscmap0n(0).
>
> Alan

Alan,

Thanks for tracking this down.  I have attached a patch which should
properly implement what you want and, hopefully, fix the "all red"
problem.  A brief code-review on the logic in this patch would be
appreciated as well - I don't think that there are any infinite loops
lurking in there, but it is possible.  Example 2 runs cleanly with
this patch using the xwin driver, which is where I ran in to infinite
loop problems when implementing the palette file-based default color
map changes.

I do not have a working Ada install yet, so I can not test the effect
this has on the Ada bindings.  I can, however, call plscmap0n with 0,
negative and positive values before calling plinit from OCaml,
resulting in a proper palette of colors.

If it works for you and/or others I will go ahead and commit the change.

Hez

-- 
Hezekiah M. Carty
Graduate Research Assistant
University of Maryland
Department of Atmospheric and Oceanic Science
diff --git a/src/plctrl.c b/src/plctrl.c
index a6e8a3f..8dcc367 100644
--- a/src/plctrl.c
+++ b/src/plctrl.c
@@ -81,6 +81,9 @@ plcmap1_def(void);
 static PLFLT
 value(double n1, double n2, double hue);
 
+PLBOOL
+is_cmap0_ready(PLINT ncol0);
+
 /* An additional hardwired location for lib files. */
 /* I have no plans to change these again, ever. */
 
@@ -749,6 +752,35 @@ plcmap1_calc(void)
 }
 
 /*--------------------------------------------------------------------------*\
+ * is_cmap0_ready()
+ *
+ * Check to see if color map 0 has enough color slots allocated to house the
+ * requested number of colors.
+\*--------------------------------------------------------------------------*/
+
+PLBOOL
+is_cmap0_ready(PLINT ncol0)
+{
+    PLBOOL ret_val;
+    ret_val = FALSE;
+
+    if (ncol0 > 0 && plsc->ncol0 == ncol0) {
+        /* OK because ncol0 = the number of currently allocated cmap0 colors */
+	ret_val = TRUE;
+    }
+    else if (plsc->ncol0 <= 0 || ncol0 <= 0) {
+        /* NOT OK because cmap0 is not ready to hold any colors */
+        ret_val = FALSE;
+    }
+    else {
+        /* NOT OK because more colors are requested than are currently
+           allocated */
+        ret_val = FALSE;
+    }
+    return ret_val;
+}
+
+/*--------------------------------------------------------------------------*\
  * plscmap0n()
  *
  * Set number of colors in cmap 0, (re-)allocate cmap 0, and fill with
@@ -762,6 +794,10 @@ void
 c_plscmap0n(PLINT ncol0)
 {
     int ncol, size, imin, imax;
+    PLBOOL first_allocation;
+
+    /* Is this the first initialization of cmap0? */
+    first_allocation = FALSE;
 
 /* No change */
 
@@ -788,6 +824,7 @@ c_plscmap0n(PLINT ncol0)
        plexit("c_plscmap0n: Insufficient memory");
      }
 	imin = 0;
+        first_allocation = TRUE;
     }
     else {
 	if ((plsc->cmap0 = (PLColor *) realloc(plsc->cmap0, size))==NULL)
@@ -795,6 +832,7 @@ c_plscmap0n(PLINT ncol0)
        plexit("c_plscmap0n: Insufficient memory");
      }
 	imin = plsc->ncol0;
+        first_allocation = FALSE;
     }
 
 /* Fill in default entries */
@@ -802,6 +840,10 @@ c_plscmap0n(PLINT ncol0)
     plsc->ncol0 = ncol;
     plcmap0_def(imin, imax);
 
+    if (ncol0 == 0 || first_allocation == TRUE) {
+        plspal0("");
+    }
+
     if (plsc->level > 0)
 	plP_state(PLSTATE_CMAP0);
 }
@@ -1208,11 +1250,9 @@ c_plspal0(const char *filename)
     return;
   }
 
-  /* Allocate default number of cmap0 colours if cmap0 allocation not
+  /* Allocate sufficient cmap0 colors to contain the data if it has not been
      done already. */
-  plscmap0n(0);
-  /* Allocate sufficient cmap0 colours to contain present data. */
-  if(number_colors > plsc->ncol0) {
+  if(!is_cmap0_ready(number_colors)) {
     plscmap0n(number_colors);
   }
 
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to