1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
// Copyright (C) 1999-2016
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"
#include "colorscale.h"
ColorScale::ColorScale(int ss)
{
size_ = ss;
psColors_ = new unsigned char[ss*3];
memset(psColors_, '0', size_*3);
}
ColorScale::~ColorScale()
{
if (psColors_)
delete [] psColors_;
}
LinearScale::LinearScale(int ss, unsigned char* colorCells, int count)
: ColorScale(ss)
{
for (int ii=0; ii<ss; ii++) {
double aa = double(ii)/ss;
int ll = (int)(aa * count);
memcpy(psColors_+ii*3, colorCells+ll*3,3);
}
}
LogScale::LogScale(int ss, unsigned char* colorCells, int count, double exp)
: ColorScale(ss)
{
for (int ii=0; ii<ss; ii++) {
double aa = log10(exp*double(ii)/ss +1) / log10(exp);
int ll = (int)(aa * count);
// aa can grow slightly greater than 1
if (ll>=count)
ll = count-1;
memcpy(psColors_+ii*3, colorCells+ll*3, 3);
}
}
PowScale::PowScale(int ss, unsigned char* colorCells, int count, double exp)
: ColorScale(ss)
{
for (int ii=0; ii<ss; ii++) {
double aa = (::pow(exp,double(ii)/ss) -1) / exp;
int ll = (int)(aa * count);
// should not be needed
if (ll>=count)
ll = count-1;
memcpy(psColors_+ii*3, colorCells+ll*3, 3);
}
}
SqrtScale::SqrtScale(int ss, unsigned char* colorCells, int count)
: ColorScale(ss)
{
for(int ii=0; ii<ss; ii++) {
double aa = double(ii)/ss;
int ll = (int)(sqrt(aa) * count);
memcpy(psColors_+ii*3, colorCells+ll*3,3);
}
}
SquaredScale::SquaredScale(int ss, unsigned char* colorCells, int count)
: ColorScale(ss)
{
for(int ii=0; ii<ss; ii++) {
double aa = double(ii)/ss;
int ll = (int)(aa*aa * count);
memcpy(psColors_+ii*3, colorCells+ll*3,3);
}
}
AsinhScale::AsinhScale(int ss, unsigned char* colorCells, int count)
: ColorScale(ss)
{
for(int ii=0; ii<ss; ii++) {
double aa = double(ii)/ss;
int ll = (int)(asinh(10*aa)/3 * count);
// it can spill over
if (ll>=count)
ll = count-1;
memcpy(psColors_+ii*3, colorCells+ll*3,3);
}
}
SinhScale::SinhScale(int ss, unsigned char* colorCells, int count)
: ColorScale(ss)
{
for(int ii=0; ii<ss; ii++) {
double aa = double(ii)/ss;
int ll = (int)(sinh(3*aa)/10 * count);
// it can spill over
if (ll>=count)
ll = count-1;
memcpy(psColors_+ii*3, colorCells+ll*3,3);
}
}
HistEquScale::HistEquScale(int ss, unsigned char* colorCells, int count,
double* hist, int histsize)
: ColorScale(ss)
{
// if no histogram, return linear distribution
if (!hist)
for (int ii=0; ii<ss; ii++) {
double aa = double(ii)/ss;
int ll = (int)(aa * count);
memcpy(psColors_+ii*3, colorCells+ll*3,3);
}
else {
for (int ii=0; ii<ss; ii++) {
double aa = hist[ii*histsize/ss];
int ll = (int)(aa * count);
memcpy(psColors_+ii*3, colorCells+ll*3,3);
}
}
}
IISScale::IISScale(unsigned char* colorCells, int count)
: ColorScale(IISSIZE)
{
for (int ii=0; ii<IISCOLORS; ii++) {
double aa = double(ii)/IISCOLORS;
int ll = (int)(aa * count);
memcpy(psColors_+ii*3, colorCells+ll*3,3);
}
unsigned char* ptr;
// 0 white (background)
ptr = psColors_;
*ptr++ = 255;
*ptr++ = 255;
*ptr++ = 255;
ptr = psColors_+IISMAX*3;
// 201 white
*ptr++ = 255;
*ptr++ = 255;
*ptr++ = 255;
// 202 black
*ptr++ = 0;
*ptr++ = 0;
*ptr++ = 0;
// 203 white
*ptr++ = 255;
*ptr++ = 255;
*ptr++ = 255;
// 204 red
*ptr++ = 0;
*ptr++ = 0;
*ptr++ = 255;
// 205 green
*ptr++ = 0;
*ptr++ = 255;
*ptr++ = 0;
// 206 blue
*ptr++ = 255;
*ptr++ = 0;
*ptr++ = 0;
// 207 yellow
*ptr++ = 0;
*ptr++ = 255;
*ptr++ = 255;
// 209 cyan
*ptr++ = 255;
*ptr++ = 255;
*ptr++ = 0;
// 209 magenta
*ptr++ = 255;
*ptr++ = 0;
*ptr++ = 255;
// 210 coral
*ptr++ = 80;
*ptr++ = 127;
*ptr++ = 255;
// 211 maroon
*ptr++ = 96;
*ptr++ = 48;
*ptr++ = 176;
// 212 orange
*ptr++ = 0;
*ptr++ = 165;
*ptr++ = 255;
// 213 khaki
*ptr++ = 140;
*ptr++ = 230;
*ptr++ = 240;
// 214 orchid
*ptr++ = 214;
*ptr++ = 112;
*ptr++ = 218;
// 215 turquoise
*ptr++ = 208;
*ptr++ = 224;
*ptr++ = 64;
// 216 violet
*ptr++ = 238;
*ptr++ = 130;
*ptr++ = 238;
// 217 wheat
*ptr++ = 179;
*ptr++ = 222;
*ptr++ = 245;
}
|