source: rtems-graphics-toolkit/fltk-1.1.10/src/cmap.cxx @ 513eea1

Last change on this file since 513eea1 was 513eea1, checked in by Joel Sherrill <joel.sherrill@…>, on 01/09/10 at 22:43:24

2010-01-08 Joel Sherrill <joel.sherrill@…>

fltk 1.1.10. imported

  • ORIGIN: Updated.
  • Property mode set to 100644
File size: 5.4 KB
Line 
1//
2// "$Id$"
3//
4// Colormap generation program for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2005 by Bill Spitzak and others.
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21// USA.
22//
23// Please report all bugs and problems to "fltk-bugs@easysw.com".
24//
25
26// This program produces the contents of "fl_cmap.h" as stdout
27
28// #include <gl/gl.h>
29#include <stdio.h>
30
31// This table is initialized with color values I got by reading the
32// colormap on an IRIX 4.3 machine:
33
34// "full intensity colors" have been turned down some to make white
35// background less intense by default.  The hope is that this will make
36// fltk programs more friendly on color-adjusted screens.  If you want
37// pure colors you should get them out of the colormap.
38
39//#define III 244 // maximum intensity of the basic colors
40
41// that results in errors and unshared colormap entries, so full intensity:
42#define III 255 // maximum intensity of the basic colors
43
44static short cmap[256][3] = {
45// 3-bit colormap:
46  {  0,  0,  0},        // black
47  {III,  0,  0},        // red
48  {  0,III,  0},        // green
49  {III,III,  0},        // yellow
50  {  0,  0,III},        // blue
51  {III,  0,III},        // magenta
52  {  0,III,III},        // cyan
53  {III,III,III},        // white
54// pastel versions of those colors, from SGI's standard color map:
55  { 85, 85, 85},        // 1/3 gray
56  {198,113,113},        // salmon? pale red?
57  {113,198,113},        // pale green
58  {142,142, 56},        // khaki
59  {113,113,198},        // pale blue
60  {142, 56,142},        // purple, orchid, pale magenta
61  { 56,142,142},        // cadet blue, aquamarine, pale cyan
62// The next location is used for FL_SELECTION_COLOR. It formerly was 2/3 gray
63// but this is changed to be the Windows blue color. This allows the default
64// behavior on both X and Windows to match:
65  {  0,  0,128},
66//{170,170,170},        // old 2/3 gray color
67// These next 16 are the FL_FREE_COLOR area. In some versions of fltk
68// these were filled with random colors that a Irix 5.3 machine placed
69// in these locations. Other versions of fltk filled this with the 1/3
70// gray above to discourage their use. This newest version uses colors
71// that NewTek has assigned for their GUI:
72#if 0
73  // The Irix 5.3 colors:
74  { 16, 16, 16},
75  {128, 40,128},
76  {198, 30, 30},
77  { 66, 30, 30},
78  {176,140,140},
79  {  0, 20, 20},
80  { 20, 10, 10},
81  { 40, 20, 20},
82  { 60, 30, 30},
83  {  0, 80, 80},
84  {  0, 40, 40},
85  { 20, 20,  0},
86  { 40, 40,  0},
87  { 80, 80, 10},
88  {150,150, 20},
89  {160, 10, 10},
90#else
91  // The NewTek colors: (from George Yohng)
92  {168,168,152},
93  {232,232,216},
94  {104,104, 88},
95  {152,168,168},
96  {216,232,232},
97  { 88,104,104},
98  {156,156,168},
99  {220,220,232},
100  { 92, 92,104},
101  {156,168,156},
102  {220,232,220},
103  { 92,104, 92},
104  {144,144,144},
105  {192,192,192},
106  { 80, 80, 80},
107  {160,160,160},
108#endif
109// The rest of the colormap is a gray ramp and table, filled in below:
110};
111
112// This is Fl::background from Fl_get_system_colors.cxx, with modifications:
113
114#define FL_GRAY_RAMP 32
115#define FL_NUM_GRAY  24
116#define FL_GRAY 49 // old value is 47
117typedef unsigned char uchar;
118#include <math.h>
119
120void background(uchar r, uchar g, uchar b) {
121  // replace the gray ramp so that color 47 (by default 2/3) is this color
122  if (!r) r = 1; else if (r==255) r = 254;
123  double powr = log(r/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
124  if (!g) g = 1; else if (g==255) g = 254;
125  double powg = log(g/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
126  if (!b) b = 1; else if (b==255) b = 254;
127  double powb = log(b/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
128  for (int i = 0; i < FL_NUM_GRAY; i++) {
129    double gray = i/(FL_NUM_GRAY-1.0);
130    cmap[i+FL_GRAY_RAMP][0] = uchar(pow(gray,powr)*255+.5);
131    cmap[i+FL_GRAY_RAMP][1] = uchar(pow(gray,powg)*255+.5);
132    cmap[i+FL_GRAY_RAMP][2] = uchar(pow(gray,powb)*255+.5);
133  }
134}
135
136int main() {
137  int i,r,g,b;
138#if 0
139  /* Read colormap colors into internal table */
140  long cmwin;
141  noport();
142  cmwin = winopen("CM");
143  for (i=0; i<256; i++)
144    getmcolor(i,&cmap[i][0],&cmap[i][1],&cmap[i][2]);
145  winclose(cmwin);
146#endif
147// overwrite the X allocation area with one color so people are
148// discouraged from using it:
149  //for (i=16; i<32; i++) {cmap[i][0]=cmap[i][1]=cmap[i][2] = 85;}
150
151  // fill in the gray ramp:
152  background(0xc0, 0xc0, 0xc0); // microsoft colors
153  // background(170, 170, 170); // old fltk colors
154  // copy the 1/3 and 2/3 gray to the closest locations in gray ramp:
155  cmap[39][0] = cmap[39][1] = cmap[39][2] = 85;
156  cmap[47][0] = cmap[47][1] = cmap[47][2] = 170;
157
158  // fill in the color cube
159  i = 56;
160  for (b=0; b<5; b++)
161    for (r=0; r<5; r++)
162      for (g=0; g<8; g++) {
163        cmap[i][0] = r*255/4;
164        cmap[i][1] = g*255/7;
165        cmap[i][2] = b*255/4;
166        i++;
167      }
168
169  for (i=0; i<256; i++) {
170    printf("\t0x%02x%02x%02x00",cmap[i][0],cmap[i][1],cmap[i][2]);
171    if (i < 255) printf(",\n");
172  }
173  printf("\n");
174  return 0;
175}
176
177//
178// End of "$Id$".
179//
Note: See TracBrowser for help on using the repository browser.