Reformat src/cmap.cxx and regen src/fl_cmap.h

- remove obsolete code / comments (see Git for history)
- add copyright to generated file src/fl_cmap.h
- generate copyright year in src/fl_cmap.h automatically
- add color indices as comments to color values
- remove $Id header
- replace $Id trailer with a more useful comment
This commit is contained in:
Albrecht Schlosser 2020-04-29 14:48:00 +02:00
parent 9fe77c6ff5
commit 70d41b06a9
2 changed files with 371 additions and 357 deletions

View File

@ -1,28 +1,30 @@
//
// "$Id$"
//
// Colormap generation program for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2016 by Bill Spitzak and others.
// Copyright 1998-2020 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// http://www.fltk.org/COPYING.php
// https://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
// https://www.fltk.org/str.php
//
//
// This program produces the contents of "fl_cmap.h" as stdout
//
// Compile, link, and run (example):
// Compile, link, run and delete the program 'cmap' (for instance on a
// Linux system) to generate fl_cmap.h:
//
// gcc -o cmap cmap.cxx -lm && ./cmap > fl_cmap.h
// $ gcc -o cmap cmap.cxx -lm && ./cmap > fl_cmap.h && rm -f ./cmap
#include <stdio.h>
#include <math.h>
#include <time.h>
// This table is initialized with color values I got by reading the
// colormap on an IRIX 4.3 machine:
@ -32,13 +34,16 @@
// fltk programs more friendly on color-adjusted screens. If you want
// pure colors you should get them out of the colormap.
//#define III 244 // maximum intensity of the basic colors
// #define III 244 // maximum intensity of the basic colors
// that results in errors and unshared colormap entries, so full intensity:
#define III 255 // maximum intensity of the basic colors
static short cmap[256][3] = {
// 3-bit colormap:
// 3-bit colormap:
{ 0, 0, 0}, // black
{III, 0, 0}, // red
{ 0,III, 0}, // green
@ -47,7 +52,9 @@ static short cmap[256][3] = {
{III, 0,III}, // magenta
{ 0,III,III}, // cyan
{III,III,III}, // white
// pastel versions of those colors, from SGI's standard color map:
// pastel versions of those colors, from SGI's standard color map:
{ 85, 85, 85}, // 1/3 gray
{198,113,113}, // salmon? pale red?
{113,198,113}, // pale green
@ -55,37 +62,22 @@ static short cmap[256][3] = {
{113,113,198}, // pale blue
{142, 56,142}, // purple, orchid, pale magenta
{ 56,142,142}, // cadet blue, aquamarine, pale cyan
// The next location is used for FL_SELECTION_COLOR. It formerly was 2/3 gray
// but this is changed to be the Windows blue color. This allows the default
// behavior on both X and Windows to match:
{ 0, 0,128},
//{170,170,170}, // old 2/3 gray color
// These next 16 are the FL_FREE_COLOR area. In some versions of fltk
// these were filled with random colors that a Irix 5.3 machine placed
// in these locations. Other versions of fltk filled this with the 1/3
// gray above to discourage their use. This newest version uses colors
// that NewTek has assigned for their GUI:
#if 0
// The Irix 5.3 colors:
{ 16, 16, 16},
{128, 40,128},
{198, 30, 30},
{ 66, 30, 30},
{176,140,140},
{ 0, 20, 20},
{ 20, 10, 10},
{ 40, 20, 20},
{ 60, 30, 30},
{ 0, 80, 80},
{ 0, 40, 40},
{ 20, 20, 0},
{ 40, 40, 0},
{ 80, 80, 10},
{150,150, 20},
{160, 10, 10},
#else
// The NewTek colors: (from George Yohng)
{168,168,152},
// The next location (15) is used for FL_SELECTION_COLOR. It formerly was
// 2/3 gray but this is changed to be the Windows blue color. This allows
// the default behavior on both X and Windows to match:
// {170,170,170}, // old 2/3 gray color
{ 0, 0,128}, // 15 = FL_SELECTION_COLOR
// These next 16 (index 16 - 31) are the FL_FREE_COLOR area. In some
// versions of fltk these were filled with random colors that a Irix 5.3
// machine placed in these locations.
// This version uses colors that NewTek has assigned for their GUI
// (from George Yohng):
{168,168,152}, // 16 = FL_FREE_COLOR
{232,232,216},
{104,104, 88},
{152,168,168},
@ -100,9 +92,9 @@ static short cmap[256][3] = {
{144,144,144},
{192,192,192},
{ 80, 80, 80},
{160,160,160},
#endif
// The rest of the colormap is a gray ramp and table, filled in below:
{160,160,160}, // 31
// The rest of the colormap is a gray ramp and table, filled in below:
};
// This is Fl::background from Fl_get_system_colors.cxx, with modifications:
@ -111,83 +103,95 @@ static short cmap[256][3] = {
#define FL_NUM_GRAY 24
#define FL_GRAY 49 // old value is 47
typedef unsigned char uchar;
#include <math.h>
void background(uchar r, uchar g, uchar b) {
// replace the gray ramp so that color 47 (by default 2/3) is this color
if (!r) r = 1; else if (r==255) r = 254;
double powr = log(r/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
if (!g) g = 1; else if (g==255) g = 254;
double powg = log(g/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
if (!b) b = 1; else if (b==255) b = 254;
double powb = log(b/255.0)/log((FL_GRAY-FL_GRAY_RAMP)/(FL_NUM_GRAY-1.0));
if (!r)
r = 1;
else if (r == 255)
r = 254;
double powr = log(r / 255.0) / log((FL_GRAY - FL_GRAY_RAMP) / (FL_NUM_GRAY - 1.0));
if (!g)
g = 1;
else if (g == 255)
g = 254;
double powg = log(g / 255.0) / log((FL_GRAY - FL_GRAY_RAMP) / (FL_NUM_GRAY - 1.0));
if (!b)
b = 1;
else if (b == 255)
b = 254;
double powb = log(b / 255.0) / log((FL_GRAY - FL_GRAY_RAMP) / (FL_NUM_GRAY - 1.0));
for (int i = 0; i < FL_NUM_GRAY; i++) {
double gray = i/(FL_NUM_GRAY-1.0);
cmap[i+FL_GRAY_RAMP][0] = uchar(pow(gray,powr)*255+.5);
cmap[i+FL_GRAY_RAMP][1] = uchar(pow(gray,powg)*255+.5);
cmap[i+FL_GRAY_RAMP][2] = uchar(pow(gray,powb)*255+.5);
double gray = i / (FL_NUM_GRAY - 1.0);
cmap[i + FL_GRAY_RAMP][0] = uchar(pow(gray, powr) * 255 + .5);
cmap[i + FL_GRAY_RAMP][1] = uchar(pow(gray, powg) * 255 + .5);
cmap[i + FL_GRAY_RAMP][2] = uchar(pow(gray, powb) * 255 + .5);
}
}
int main() {
int i,r,g,b;
#if 0
/* Read colormap colors into internal table */
long cmwin;
noport();
cmwin = winopen("CM");
for (i=0; i<256; i++)
getmcolor(i,&cmap[i][0],&cmap[i][1],&cmap[i][2]);
winclose(cmwin);
#endif
// overwrite the X allocation area with one color so people are
// discouraged from using it:
// for (i=16; i<32; i++) {cmap[i][0]=cmap[i][1]=cmap[i][2] = 85;}
int i, r, g, b, year;
time_t t = time(0);
struct tm *lt = localtime(&t);
year = lt->tm_year + 1900; // copyright year
// fill in the gray ramp:
background(0xc0, 0xc0, 0xc0); // microsoft colors
// background(170, 170, 170); // old fltk colors
background(0xc0, 0xc0, 0xc0); // microsoft colors
// copy the 1/3 and 2/3 gray to the closest locations in gray ramp:
cmap[39][0] = cmap[39][1] = cmap[39][2] = 85;
cmap[47][0] = cmap[47][1] = cmap[47][2] = 170;
// fill in the color cube
i = 56;
for (b=0; b<5; b++)
for (r=0; r<5; r++)
for (g=0; g<8; g++) {
cmap[i][0] = r*255/4;
cmap[i][1] = g*255/7;
cmap[i][2] = b*255/4;
for (b = 0; b < 5; b++) {
for (r = 0; r < 5; r++) {
for (g = 0; g < 8; g++) {
cmap[i][0] = r * 255 / 4;
cmap[i][1] = g * 255 / 7;
cmap[i][2] = b * 255 / 4;
i++;
}
// write comment into 'cmap.h' so the reader knows what it is good for
printf("//\n");
printf("// \"$%s$\"\n","Id"); // avoid expansion of Id
printf("//\n");
printf("// DO NOT EDIT THIS FILE !\n");
printf("//\n");
printf("// This file must be created with \"src/cmap.cxx\".\n");
printf("//\n");
// write color map values
for (i=0; i<256; i++) {
printf("\t0x%02x%02x%02x00",cmap[i][0],cmap[i][1],cmap[i][2]);
if (i < 255) printf(",\n");
}
}
printf("\n");
// write final comment
// write comment into 'cmap.h' so the reader knows what it is good for
printf("//\n");
printf("// End of \"$%s$\".\n","Id"); // avoid expansion of Id
printf("//\n");
printf("//\n");
printf("// DO NOT EDIT THIS FILE !\n");
printf("//\n");
printf("// This file must be created with \"src/cmap.cxx\".\n");
printf("//\n");
printf("// Copyright 1998-%d by Bill Spitzak and others.\n", year);
printf("//\n");
printf("// This library is free software. Distribution and use rights are outlined in\n");
printf("// the file \"COPYING\" which should have been included with this file. If this\n");
printf("// file is missing or damaged, see the license at:\n");
printf("//\n");
printf("// https://www.fltk.org/COPYING.php\n");
printf("//\n");
printf("// Please report all bugs and problems on the following page:\n");
printf("//\n");
printf("// https://www.fltk.org/str.php\n");
printf("//\n");
// write color map values
for (i = 0; i < 256; i++) {
printf("\t0x%02x%02x%02x00", cmap[i][0], cmap[i][1], cmap[i][2]);
if (i < 255)
printf(", // %3d\n", i);
else
printf(" // %3d\n", i);
}
// write final comment
printf("//\n");
printf("// End of fl_cmap.h - generated by cmap.cxx\n");
printf("//\n");
return 0;
}

View File

@ -1,266 +1,276 @@
//
// "$Id$"
//
// DO NOT EDIT THIS FILE !
//
// This file must be created with "src/cmap.cxx".
//
0x00000000,
0xff000000,
0x00ff0000,
0xffff0000,
0x0000ff00,
0xff00ff00,
0x00ffff00,
0xffffff00,
0x55555500,
0xc6717100,
0x71c67100,
0x8e8e3800,
0x7171c600,
0x8e388e00,
0x388e8e00,
0x00008000,
0xa8a89800,
0xe8e8d800,
0x68685800,
0x98a8a800,
0xd8e8e800,
0x58686800,
0x9c9ca800,
0xdcdce800,
0x5c5c6800,
0x9ca89c00,
0xdce8dc00,
0x5c685c00,
0x90909000,
0xc0c0c000,
0x50505000,
0xa0a0a000,
0x00000000,
0x0d0d0d00,
0x1a1a1a00,
0x26262600,
0x31313100,
0x3d3d3d00,
0x48484800,
0x55555500,
0x5f5f5f00,
0x6a6a6a00,
0x75757500,
0x80808000,
0x8a8a8a00,
0x95959500,
0xa0a0a000,
0xaaaaaa00,
0xb5b5b500,
0xc0c0c000,
0xcbcbcb00,
0xd5d5d500,
0xe0e0e000,
0xeaeaea00,
0xf5f5f500,
0xffffff00,
0x00000000,
0x00240000,
0x00480000,
0x006d0000,
0x00910000,
0x00b60000,
0x00da0000,
0x00ff0000,
0x3f000000,
0x3f240000,
0x3f480000,
0x3f6d0000,
0x3f910000,
0x3fb60000,
0x3fda0000,
0x3fff0000,
0x7f000000,
0x7f240000,
0x7f480000,
0x7f6d0000,
0x7f910000,
0x7fb60000,
0x7fda0000,
0x7fff0000,
0xbf000000,
0xbf240000,
0xbf480000,
0xbf6d0000,
0xbf910000,
0xbfb60000,
0xbfda0000,
0xbfff0000,
0xff000000,
0xff240000,
0xff480000,
0xff6d0000,
0xff910000,
0xffb60000,
0xffda0000,
0xffff0000,
0x00003f00,
0x00243f00,
0x00483f00,
0x006d3f00,
0x00913f00,
0x00b63f00,
0x00da3f00,
0x00ff3f00,
0x3f003f00,
0x3f243f00,
0x3f483f00,
0x3f6d3f00,
0x3f913f00,
0x3fb63f00,
0x3fda3f00,
0x3fff3f00,
0x7f003f00,
0x7f243f00,
0x7f483f00,
0x7f6d3f00,
0x7f913f00,
0x7fb63f00,
0x7fda3f00,
0x7fff3f00,
0xbf003f00,
0xbf243f00,
0xbf483f00,
0xbf6d3f00,
0xbf913f00,
0xbfb63f00,
0xbfda3f00,
0xbfff3f00,
0xff003f00,
0xff243f00,
0xff483f00,
0xff6d3f00,
0xff913f00,
0xffb63f00,
0xffda3f00,
0xffff3f00,
0x00007f00,
0x00247f00,
0x00487f00,
0x006d7f00,
0x00917f00,
0x00b67f00,
0x00da7f00,
0x00ff7f00,
0x3f007f00,
0x3f247f00,
0x3f487f00,
0x3f6d7f00,
0x3f917f00,
0x3fb67f00,
0x3fda7f00,
0x3fff7f00,
0x7f007f00,
0x7f247f00,
0x7f487f00,
0x7f6d7f00,
0x7f917f00,
0x7fb67f00,
0x7fda7f00,
0x7fff7f00,
0xbf007f00,
0xbf247f00,
0xbf487f00,
0xbf6d7f00,
0xbf917f00,
0xbfb67f00,
0xbfda7f00,
0xbfff7f00,
0xff007f00,
0xff247f00,
0xff487f00,
0xff6d7f00,
0xff917f00,
0xffb67f00,
0xffda7f00,
0xffff7f00,
0x0000bf00,
0x0024bf00,
0x0048bf00,
0x006dbf00,
0x0091bf00,
0x00b6bf00,
0x00dabf00,
0x00ffbf00,
0x3f00bf00,
0x3f24bf00,
0x3f48bf00,
0x3f6dbf00,
0x3f91bf00,
0x3fb6bf00,
0x3fdabf00,
0x3fffbf00,
0x7f00bf00,
0x7f24bf00,
0x7f48bf00,
0x7f6dbf00,
0x7f91bf00,
0x7fb6bf00,
0x7fdabf00,
0x7fffbf00,
0xbf00bf00,
0xbf24bf00,
0xbf48bf00,
0xbf6dbf00,
0xbf91bf00,
0xbfb6bf00,
0xbfdabf00,
0xbfffbf00,
0xff00bf00,
0xff24bf00,
0xff48bf00,
0xff6dbf00,
0xff91bf00,
0xffb6bf00,
0xffdabf00,
0xffffbf00,
0x0000ff00,
0x0024ff00,
0x0048ff00,
0x006dff00,
0x0091ff00,
0x00b6ff00,
0x00daff00,
0x00ffff00,
0x3f00ff00,
0x3f24ff00,
0x3f48ff00,
0x3f6dff00,
0x3f91ff00,
0x3fb6ff00,
0x3fdaff00,
0x3fffff00,
0x7f00ff00,
0x7f24ff00,
0x7f48ff00,
0x7f6dff00,
0x7f91ff00,
0x7fb6ff00,
0x7fdaff00,
0x7fffff00,
0xbf00ff00,
0xbf24ff00,
0xbf48ff00,
0xbf6dff00,
0xbf91ff00,
0xbfb6ff00,
0xbfdaff00,
0xbfffff00,
0xff00ff00,
0xff24ff00,
0xff48ff00,
0xff6dff00,
0xff91ff00,
0xffb6ff00,
0xffdaff00,
0xffffff00
// Copyright 1998-2020 by Bill Spitzak and others.
//
// End of "$Id$".
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// https://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
// https://www.fltk.org/str.php
//
0x00000000, // 0
0xff000000, // 1
0x00ff0000, // 2
0xffff0000, // 3
0x0000ff00, // 4
0xff00ff00, // 5
0x00ffff00, // 6
0xffffff00, // 7
0x55555500, // 8
0xc6717100, // 9
0x71c67100, // 10
0x8e8e3800, // 11
0x7171c600, // 12
0x8e388e00, // 13
0x388e8e00, // 14
0x00008000, // 15
0xa8a89800, // 16
0xe8e8d800, // 17
0x68685800, // 18
0x98a8a800, // 19
0xd8e8e800, // 20
0x58686800, // 21
0x9c9ca800, // 22
0xdcdce800, // 23
0x5c5c6800, // 24
0x9ca89c00, // 25
0xdce8dc00, // 26
0x5c685c00, // 27
0x90909000, // 28
0xc0c0c000, // 29
0x50505000, // 30
0xa0a0a000, // 31
0x00000000, // 32
0x0d0d0d00, // 33
0x1a1a1a00, // 34
0x26262600, // 35
0x31313100, // 36
0x3d3d3d00, // 37
0x48484800, // 38
0x55555500, // 39
0x5f5f5f00, // 40
0x6a6a6a00, // 41
0x75757500, // 42
0x80808000, // 43
0x8a8a8a00, // 44
0x95959500, // 45
0xa0a0a000, // 46
0xaaaaaa00, // 47
0xb5b5b500, // 48
0xc0c0c000, // 49
0xcbcbcb00, // 50
0xd5d5d500, // 51
0xe0e0e000, // 52
0xeaeaea00, // 53
0xf5f5f500, // 54
0xffffff00, // 55
0x00000000, // 56
0x00240000, // 57
0x00480000, // 58
0x006d0000, // 59
0x00910000, // 60
0x00b60000, // 61
0x00da0000, // 62
0x00ff0000, // 63
0x3f000000, // 64
0x3f240000, // 65
0x3f480000, // 66
0x3f6d0000, // 67
0x3f910000, // 68
0x3fb60000, // 69
0x3fda0000, // 70
0x3fff0000, // 71
0x7f000000, // 72
0x7f240000, // 73
0x7f480000, // 74
0x7f6d0000, // 75
0x7f910000, // 76
0x7fb60000, // 77
0x7fda0000, // 78
0x7fff0000, // 79
0xbf000000, // 80
0xbf240000, // 81
0xbf480000, // 82
0xbf6d0000, // 83
0xbf910000, // 84
0xbfb60000, // 85
0xbfda0000, // 86
0xbfff0000, // 87
0xff000000, // 88
0xff240000, // 89
0xff480000, // 90
0xff6d0000, // 91
0xff910000, // 92
0xffb60000, // 93
0xffda0000, // 94
0xffff0000, // 95
0x00003f00, // 96
0x00243f00, // 97
0x00483f00, // 98
0x006d3f00, // 99
0x00913f00, // 100
0x00b63f00, // 101
0x00da3f00, // 102
0x00ff3f00, // 103
0x3f003f00, // 104
0x3f243f00, // 105
0x3f483f00, // 106
0x3f6d3f00, // 107
0x3f913f00, // 108
0x3fb63f00, // 109
0x3fda3f00, // 110
0x3fff3f00, // 111
0x7f003f00, // 112
0x7f243f00, // 113
0x7f483f00, // 114
0x7f6d3f00, // 115
0x7f913f00, // 116
0x7fb63f00, // 117
0x7fda3f00, // 118
0x7fff3f00, // 119
0xbf003f00, // 120
0xbf243f00, // 121
0xbf483f00, // 122
0xbf6d3f00, // 123
0xbf913f00, // 124
0xbfb63f00, // 125
0xbfda3f00, // 126
0xbfff3f00, // 127
0xff003f00, // 128
0xff243f00, // 129
0xff483f00, // 130
0xff6d3f00, // 131
0xff913f00, // 132
0xffb63f00, // 133
0xffda3f00, // 134
0xffff3f00, // 135
0x00007f00, // 136
0x00247f00, // 137
0x00487f00, // 138
0x006d7f00, // 139
0x00917f00, // 140
0x00b67f00, // 141
0x00da7f00, // 142
0x00ff7f00, // 143
0x3f007f00, // 144
0x3f247f00, // 145
0x3f487f00, // 146
0x3f6d7f00, // 147
0x3f917f00, // 148
0x3fb67f00, // 149
0x3fda7f00, // 150
0x3fff7f00, // 151
0x7f007f00, // 152
0x7f247f00, // 153
0x7f487f00, // 154
0x7f6d7f00, // 155
0x7f917f00, // 156
0x7fb67f00, // 157
0x7fda7f00, // 158
0x7fff7f00, // 159
0xbf007f00, // 160
0xbf247f00, // 161
0xbf487f00, // 162
0xbf6d7f00, // 163
0xbf917f00, // 164
0xbfb67f00, // 165
0xbfda7f00, // 166
0xbfff7f00, // 167
0xff007f00, // 168
0xff247f00, // 169
0xff487f00, // 170
0xff6d7f00, // 171
0xff917f00, // 172
0xffb67f00, // 173
0xffda7f00, // 174
0xffff7f00, // 175
0x0000bf00, // 176
0x0024bf00, // 177
0x0048bf00, // 178
0x006dbf00, // 179
0x0091bf00, // 180
0x00b6bf00, // 181
0x00dabf00, // 182
0x00ffbf00, // 183
0x3f00bf00, // 184
0x3f24bf00, // 185
0x3f48bf00, // 186
0x3f6dbf00, // 187
0x3f91bf00, // 188
0x3fb6bf00, // 189
0x3fdabf00, // 190
0x3fffbf00, // 191
0x7f00bf00, // 192
0x7f24bf00, // 193
0x7f48bf00, // 194
0x7f6dbf00, // 195
0x7f91bf00, // 196
0x7fb6bf00, // 197
0x7fdabf00, // 198
0x7fffbf00, // 199
0xbf00bf00, // 200
0xbf24bf00, // 201
0xbf48bf00, // 202
0xbf6dbf00, // 203
0xbf91bf00, // 204
0xbfb6bf00, // 205
0xbfdabf00, // 206
0xbfffbf00, // 207
0xff00bf00, // 208
0xff24bf00, // 209
0xff48bf00, // 210
0xff6dbf00, // 211
0xff91bf00, // 212
0xffb6bf00, // 213
0xffdabf00, // 214
0xffffbf00, // 215
0x0000ff00, // 216
0x0024ff00, // 217
0x0048ff00, // 218
0x006dff00, // 219
0x0091ff00, // 220
0x00b6ff00, // 221
0x00daff00, // 222
0x00ffff00, // 223
0x3f00ff00, // 224
0x3f24ff00, // 225
0x3f48ff00, // 226
0x3f6dff00, // 227
0x3f91ff00, // 228
0x3fb6ff00, // 229
0x3fdaff00, // 230
0x3fffff00, // 231
0x7f00ff00, // 232
0x7f24ff00, // 233
0x7f48ff00, // 234
0x7f6dff00, // 235
0x7f91ff00, // 236
0x7fb6ff00, // 237
0x7fdaff00, // 238
0x7fffff00, // 239
0xbf00ff00, // 240
0xbf24ff00, // 241
0xbf48ff00, // 242
0xbf6dff00, // 243
0xbf91ff00, // 244
0xbfb6ff00, // 245
0xbfdaff00, // 246
0xbfffff00, // 247
0xff00ff00, // 248
0xff24ff00, // 249
0xff48ff00, // 250
0xff6dff00, // 251
0xff91ff00, // 252
0xffb6ff00, // 253
0xffdaff00, // 254
0xffffff00 // 255
//
// End of fl_cmap.h - generated by cmap.cxx
//