Re: user color palette & PostScript output

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Nov 16 1999 - 10:11:28 MET


Hi Alexander,
The class TPostScript had still a limitation to 255 colors.
I have removed this limitation in my development version.
Thanks for the remark.

Rene Brun

Alexandr Malusek wrote:
> 
> Hi,
> 
> I use macros for creating color palettes in ROOT. It works OK in X11
> (Solaris 2.6, Creator 3D, TrueColor visual class), but if I save the
> canvas to a PS or EPS file via "File/Save As" menu, GhostScript
> displays colors allocated in the colormap only as a white color.
> 
> Is it a problem in these macros (which I wrote according to comments
> in this list) or in ROOT? Is there a workaround?
> 
> An example:
> root [0] .x paletteGray.C
> root [1] .x surfaces.C                            // from the tutorial
> root [2] PostScript file: c1.ps has been created  // via File/Save As
> root [2] .q
> $ gs c1.ps   # the second graph is white with black contour lines
> 
> The macros follows:
> 
> $ cat paletteGray.C
> // Function paletteGray sets gray palette (white -> black).
> //
> // Examples:
> // root[] .x paletteGray.C      // 128 colors
> // root[] paletteGray(32,450)   // 32 colors, notice 450 > 300+128
> // New histograms will use this palette. Old ones must be "Refreshed".
> //
> // Problems:
> // This macro defines new colors, it does not redefine existing colors.
> // Therefore the startIndex must be greater than indices of colors
> // already allocated by ROOT (at least 150?). It may be a problem
> // for displays with 256 colors.
> 
> void paletteGray(const Int_t colNum = 128, Int_t startIndex = 300)
> {
>   // colNum ....... Number of colors in the palette
>   // startIndex ... starting index of allocated colors
> 
>   Int_t palette[colNum];
>   Float_t val;
> 
>   for (Int_t i=0; i < colNum; i++)
>     {
>       val = 1 - i/(float)colNum;
>       TColor *color = new TColor(startIndex+i, val, val, val, "");
>       palette[i] = startIndex + i;
>     }
>   gStyle->SetPalette(colNum, palette);
> }
> 
> $ cat paletteSpectrum.C
> // Function paletteSpectrum sets spectrum-like palette (violet->red).
> //
> // Examples:
> // root[] .x paletteSpectrum.C      // 128 colors
> // root[] paletteSpectrum(32,450)   // 32 colors, notice 450 > 300+128
> // New histograms will use this palette. Old ones must be "Refreshed".
> //
> // Problems:
> // This macro defines new colors, it does not redefine existing colors.
> // Therefore the startIndex must be greater than indices of colors
> // already allocated by ROOT (at least 150?). It may be a problem
> // for displays with 256 colors.
> 
> void paletteSpectrum(const Int_t colNum = 128, Int_t startIndex = 300)
> {
>   // colNum ....... Number of colors in the palette
>   // startIndex ... starting index of allocated colors
> 
>   const Float_t saturation = 1;
>   const Float_t lightness = 0.5;
>   const Float_t maxHue = 280;
>   const Float_t minHue = 0;
>   Int_t palette[colNum];
>   Float_t hue, r, g, b, rv, gv, bv;
> 
>   for (Int_t i = 0 ; i < colNum ; i++)
>     {
>       TColor *color = new TColor(startIndex + i, 0, 0, 0);
>       hue = maxHue - (i+1) * ((maxHue - minHue) / colNum);
>       color->HLStoRGB(hue, lightness, saturation, r, g, b);
>       color->SetRGB(r, g, b);
>       palette[i] = startIndex + i;
>     }
>   gStyle->SetPalette(colNum, palette);
> }
> 
> Note: I've tested ROOT 2.22/10 and 2.23/08. A PS printer also doesn't
> print the colors so it doesn't seem to be a GhostScript problem.
> 
> Regards,
> ---------------------------------------------------------------------------
> Alexandr Malusek
> Nuclear Physics Institute                        e-mail: malusek@ujf.cas.cz
> Department of Radiation Dosimetry                   tel: +420 2 83842791
> Na Truhlarce 39/64, 180 86 Praha 8, Czech Republic  fax: +420 2 83842788
> ---------------------------------------------------------------------------



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:43 MET