fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

cmap.cxx

Go to the documentation of this file.
00001 //
00002 // "$Id: cmap.cxx 7903 2010-11-28 21:06:39Z matt $"
00003 //
00004 // Colormap generation program for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2010 by Bill Spitzak and others.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems on the following page:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 
00028 // This program produces the contents of "fl_cmap.h" as stdout
00029 
00030 // #include <gl/gl.h>
00031 #include <stdio.h>
00032 
00033 // This table is initialized with color values I got by reading the
00034 // colormap on an IRIX 4.3 machine:
00035 
00036 // "full intensity colors" have been turned down some to make white
00037 // background less intense by default.  The hope is that this will make
00038 // fltk programs more friendly on color-adjusted screens.  If you want
00039 // pure colors you should get them out of the colormap.
00040 
00041 //#define III 244 // maximum intensity of the basic colors
00042 
00043 // that results in errors and unshared colormap entries, so full intensity:
00044 #define III 255 // maximum intensity of the basic colors
00045 
00046 static short cmap[256][3] = {
00047 // 3-bit colormap:
00048   {  0,  0,  0},        // black
00049   {III,  0,  0},        // red
00050   {  0,III,  0},        // green
00051   {III,III,  0},        // yellow
00052   {  0,  0,III},        // blue
00053   {III,  0,III},        // magenta
00054   {  0,III,III},        // cyan
00055   {III,III,III},        // white
00056 // pastel versions of those colors, from SGI's standard color map:
00057   { 85, 85, 85},        // 1/3 gray
00058   {198,113,113},        // salmon? pale red?
00059   {113,198,113},        // pale green
00060   {142,142, 56},        // khaki
00061   {113,113,198},        // pale blue
00062   {142, 56,142},        // purple, orchid, pale magenta
00063   { 56,142,142},        // cadet blue, aquamarine, pale cyan
00064 // The next location is used for FL_SELECTION_COLOR. It formerly was 2/3 gray
00065 // but this is changed to be the Windows blue color. This allows the default
00066 // behavior on both X and Windows to match:
00067   {  0,  0,128},
00068 //{170,170,170},        // old 2/3 gray color
00069 // These next 16 are the FL_FREE_COLOR area. In some versions of fltk
00070 // these were filled with random colors that a Irix 5.3 machine placed
00071 // in these locations. Other versions of fltk filled this with the 1/3
00072 // gray above to discourage their use. This newest version uses colors
00073 // that NewTek has assigned for their GUI:
00074 #if 0
00075   // The Irix 5.3 colors:
00076   { 16, 16, 16},
00077   {128, 40,128},
00078   {198, 30, 30},
00079   { 66, 30, 30},
00080   {176,140,140},
00081   {  0, 20, 20},
00082   { 20, 10, 10},
00083   { 40, 20, 20},
00084   { 60, 30, 30},
00085   {  0, 80, 80},
00086   {  0, 40, 40},
00087   { 20, 20,  0},
00088   { 40, 40,  0},
00089   { 80, 80, 10},
00090   {150,150, 20},
00091   {160, 10, 10},
00092 #else
00093   // The NewTek colors: (from George Yohng)
00094   {168,168,152},
00095   {232,232,216},
00096   {104,104, 88},
00097   {152,168,168},
00098   {216,232,232},
00099   { 88,104,104},
00100   {156,156,168},
00101   {220,220,232},
00102   { 92, 92,104},
00103   {156,168,156},
00104   {220,232,220},
00105   { 92,104, 92},
00106   {144,144,144},
00107   {192,192,192},
00108   { 80, 80, 80},
00109   {160,160,160},
00110 #endif
00111 // The rest of the colormap is a gray ramp and table, filled in below:
00112 };
00113 
00114 // This is Fl::background from Fl_get_system_colors.cxx, with modifications:
00115 
00116 #define FL_GRAY_RAMP 32
00117 #define FL_NUM_GRAY  24
00118 #define FL_GRAY 49 // old value is 47
00119 typedef unsigned char uchar;
00120 #include <math.h>
00121 
00122 void background(uchar r, uchar g, uchar b) {
00123   // replace the gray ramp so that color 47 (by default 2/3) is this color
00124   if (!r) r = 1; else if (r==255) r = 254;
00125   double powr = log(r/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
00126   if (!g) g = 1; else if (g==255) g = 254;
00127   double powg = log(g/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
00128   if (!b) b = 1; else if (b==255) b = 254;
00129   double powb = log(b/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
00130   for (int i = 0; i < FL_NUM_GRAY; i++) {
00131     double gray = i/(FL_NUM_GRAY-1.0);
00132     cmap[i+FL_GRAY_RAMP][0] = uchar(pow(gray,powr)*255+.5);
00133     cmap[i+FL_GRAY_RAMP][1] = uchar(pow(gray,powg)*255+.5);
00134     cmap[i+FL_GRAY_RAMP][2] = uchar(pow(gray,powb)*255+.5);
00135   }
00136 }
00137 
00138 int main() {
00139   int i,r,g,b;
00140 #if 0
00141   /* Read colormap colors into internal table */
00142   long cmwin;
00143   noport();
00144   cmwin = winopen("CM");
00145   for (i=0; i<256; i++)
00146     getmcolor(i,&cmap[i][0],&cmap[i][1],&cmap[i][2]);
00147   winclose(cmwin);
00148 #endif
00149 // overwrite the X allocation area with one color so people are
00150 // discouraged from using it:
00151   //for (i=16; i<32; i++) {cmap[i][0]=cmap[i][1]=cmap[i][2] = 85;}
00152 
00153   // fill in the gray ramp:
00154   background(0xc0, 0xc0, 0xc0); // microsoft colors
00155   // background(170, 170, 170); // old fltk colors
00156   // copy the 1/3 and 2/3 gray to the closest locations in gray ramp:
00157   cmap[39][0] = cmap[39][1] = cmap[39][2] = 85;
00158   cmap[47][0] = cmap[47][1] = cmap[47][2] = 170;
00159 
00160   // fill in the color cube
00161   i = 56;
00162   for (b=0; b<5; b++)
00163     for (r=0; r<5; r++)
00164       for (g=0; g<8; g++) {
00165         cmap[i][0] = r*255/4;
00166         cmap[i][1] = g*255/7;
00167         cmap[i][2] = b*255/4;
00168         i++;
00169       }
00170 
00171   for (i=0; i<256; i++) {
00172     printf("\t0x%02x%02x%02x00",cmap[i][0],cmap[i][1],cmap[i][2]);
00173     if (i < 255) printf(",\n");
00174   }
00175   printf("\n");
00176   return 0;
00177 }
00178 
00179 //
00180 // End of "$Id: cmap.cxx 7903 2010-11-28 21:06:39Z matt $".
00181 //