DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 1 | // |
| 2 | // "$Id: cmap.cxx 7903 2010-11-28 21:06:39Z matt $" |
| 3 | // |
| 4 | // Colormap generation program for the Fast Light Tool Kit (FLTK). |
| 5 | // |
| 6 | // Copyright 1998-2010 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 on the following page: |
| 24 | // |
| 25 | // http://www.fltk.org/str.php |
| 26 | // |
| 27 | |
| 28 | // This program produces the contents of "fl_cmap.h" as stdout |
| 29 | |
| 30 | // #include <gl/gl.h> |
| 31 | #include <stdio.h> |
| 32 | |
| 33 | // This table is initialized with color values I got by reading the |
| 34 | // colormap on an IRIX 4.3 machine: |
| 35 | |
| 36 | // "full intensity colors" have been turned down some to make white |
| 37 | // background less intense by default. The hope is that this will make |
| 38 | // fltk programs more friendly on color-adjusted screens. If you want |
| 39 | // pure colors you should get them out of the colormap. |
| 40 | |
| 41 | //#define III 244 // maximum intensity of the basic colors |
| 42 | |
| 43 | // that results in errors and unshared colormap entries, so full intensity: |
| 44 | #define III 255 // maximum intensity of the basic colors |
| 45 | |
| 46 | static short cmap[256][3] = { |
| 47 | // 3-bit colormap: |
| 48 | { 0, 0, 0}, // black |
| 49 | {III, 0, 0}, // red |
| 50 | { 0,III, 0}, // green |
| 51 | {III,III, 0}, // yellow |
| 52 | { 0, 0,III}, // blue |
| 53 | {III, 0,III}, // magenta |
| 54 | { 0,III,III}, // cyan |
| 55 | {III,III,III}, // white |
| 56 | // pastel versions of those colors, from SGI's standard color map: |
| 57 | { 85, 85, 85}, // 1/3 gray |
| 58 | {198,113,113}, // salmon? pale red? |
| 59 | {113,198,113}, // pale green |
| 60 | {142,142, 56}, // khaki |
| 61 | {113,113,198}, // pale blue |
| 62 | {142, 56,142}, // purple, orchid, pale magenta |
| 63 | { 56,142,142}, // cadet blue, aquamarine, pale cyan |
| 64 | // The next location is used for FL_SELECTION_COLOR. It formerly was 2/3 gray |
| 65 | // but this is changed to be the Windows blue color. This allows the default |
| 66 | // behavior on both X and Windows to match: |
| 67 | { 0, 0,128}, |
| 68 | //{170,170,170}, // old 2/3 gray color |
| 69 | // These next 16 are the FL_FREE_COLOR area. In some versions of fltk |
| 70 | // these were filled with random colors that a Irix 5.3 machine placed |
| 71 | // in these locations. Other versions of fltk filled this with the 1/3 |
| 72 | // gray above to discourage their use. This newest version uses colors |
| 73 | // that NewTek has assigned for their GUI: |
| 74 | #if 0 |
| 75 | // The Irix 5.3 colors: |
| 76 | { 16, 16, 16}, |
| 77 | {128, 40,128}, |
| 78 | {198, 30, 30}, |
| 79 | { 66, 30, 30}, |
| 80 | {176,140,140}, |
| 81 | { 0, 20, 20}, |
| 82 | { 20, 10, 10}, |
| 83 | { 40, 20, 20}, |
| 84 | { 60, 30, 30}, |
| 85 | { 0, 80, 80}, |
| 86 | { 0, 40, 40}, |
| 87 | { 20, 20, 0}, |
| 88 | { 40, 40, 0}, |
| 89 | { 80, 80, 10}, |
| 90 | {150,150, 20}, |
| 91 | {160, 10, 10}, |
| 92 | #else |
| 93 | // The NewTek colors: (from George Yohng) |
| 94 | {168,168,152}, |
| 95 | {232,232,216}, |
| 96 | {104,104, 88}, |
| 97 | {152,168,168}, |
| 98 | {216,232,232}, |
| 99 | { 88,104,104}, |
| 100 | {156,156,168}, |
| 101 | {220,220,232}, |
| 102 | { 92, 92,104}, |
| 103 | {156,168,156}, |
| 104 | {220,232,220}, |
| 105 | { 92,104, 92}, |
| 106 | {144,144,144}, |
| 107 | {192,192,192}, |
| 108 | { 80, 80, 80}, |
| 109 | {160,160,160}, |
| 110 | #endif |
| 111 | // The rest of the colormap is a gray ramp and table, filled in below: |
| 112 | }; |
| 113 | |
| 114 | // This is Fl::background from Fl_get_system_colors.cxx, with modifications: |
| 115 | |
| 116 | #define FL_GRAY_RAMP 32 |
| 117 | #define FL_NUM_GRAY 24 |
| 118 | #define FL_GRAY 49 // old value is 47 |
| 119 | typedef unsigned char uchar; |
| 120 | #include <math.h> |
| 121 | |
| 122 | void background(uchar r, uchar g, uchar b) { |
| 123 | // replace the gray ramp so that color 47 (by default 2/3) is this color |
| 124 | if (!r) r = 1; else if (r==255) r = 254; |
| 125 | double powr = log(r/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0)); |
| 126 | if (!g) g = 1; else if (g==255) g = 254; |
| 127 | double powg = log(g/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0)); |
| 128 | if (!b) b = 1; else if (b==255) b = 254; |
| 129 | double powb = log(b/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0)); |
| 130 | for (int i = 0; i < FL_NUM_GRAY; i++) { |
| 131 | double gray = i/(FL_NUM_GRAY-1.0); |
| 132 | cmap[i+FL_GRAY_RAMP][0] = uchar(pow(gray,powr)*255+.5); |
| 133 | cmap[i+FL_GRAY_RAMP][1] = uchar(pow(gray,powg)*255+.5); |
| 134 | cmap[i+FL_GRAY_RAMP][2] = uchar(pow(gray,powb)*255+.5); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | int main() { |
| 139 | int i,r,g,b; |
| 140 | #if 0 |
| 141 | /* Read colormap colors into internal table */ |
| 142 | long cmwin; |
| 143 | noport(); |
| 144 | cmwin = winopen("CM"); |
| 145 | for (i=0; i<256; i++) |
| 146 | getmcolor(i,&cmap[i][0],&cmap[i][1],&cmap[i][2]); |
| 147 | winclose(cmwin); |
| 148 | #endif |
| 149 | // overwrite the X allocation area with one color so people are |
| 150 | // discouraged from using it: |
| 151 | //for (i=16; i<32; i++) {cmap[i][0]=cmap[i][1]=cmap[i][2] = 85;} |
| 152 | |
| 153 | // fill in the gray ramp: |
| 154 | background(0xc0, 0xc0, 0xc0); // microsoft colors |
| 155 | // background(170, 170, 170); // old fltk colors |
| 156 | // copy the 1/3 and 2/3 gray to the closest locations in gray ramp: |
| 157 | cmap[39][0] = cmap[39][1] = cmap[39][2] = 85; |
| 158 | cmap[47][0] = cmap[47][1] = cmap[47][2] = 170; |
| 159 | |
| 160 | // fill in the color cube |
| 161 | i = 56; |
| 162 | for (b=0; b<5; b++) |
| 163 | for (r=0; r<5; r++) |
| 164 | for (g=0; g<8; g++) { |
| 165 | cmap[i][0] = r*255/4; |
| 166 | cmap[i][1] = g*255/7; |
| 167 | cmap[i][2] = b*255/4; |
| 168 | i++; |
| 169 | } |
| 170 | |
| 171 | for (i=0; i<256; i++) { |
| 172 | printf("\t0x%02x%02x%02x00",cmap[i][0],cmap[i][1],cmap[i][2]); |
| 173 | if (i < 255) printf(",\n"); |
| 174 | } |
| 175 | printf("\n"); |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | // |
| 180 | // End of "$Id: cmap.cxx 7903 2010-11-28 21:06:39Z matt $". |
| 181 | // |