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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
|
// Copyright (C) 1999-2017
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"
#include "colorbartruecolor24.h"
#include "util.h"
// Tk Canvas Widget Function Declarations
int ColorbarTrueColor24CreateProc(Tcl_Interp*, Tk_Canvas, Tk_Item*, int,
Tcl_Obj *const []);
// Colorbar Specs
static Tk_CustomOption tagsOption = {
NULL, NULL, NULL
};
static Tk_ConfigSpec colorbarTrueColor24Specs[] = {
{TK_CONFIG_STRING, (char*)"-command", NULL, NULL, "colorbar",
Tk_Offset(ColorbarBaseOptions, cmdName),
TK_CONFIG_OPTION_SPECIFIED, NULL},
{TK_CONFIG_INT, (char*)"-x", NULL, NULL, "1",
Tk_Offset(ColorbarBaseOptions, x), TK_CONFIG_OPTION_SPECIFIED, NULL},
{TK_CONFIG_INT, (char*)"-y", NULL, NULL, "1",
Tk_Offset(ColorbarBaseOptions, y), TK_CONFIG_OPTION_SPECIFIED, NULL},
{TK_CONFIG_INT, (char*)"-width", NULL, NULL, "512",
Tk_Offset(ColorbarBaseOptions, width),
TK_CONFIG_OPTION_SPECIFIED, NULL},
{TK_CONFIG_INT, (char*)"-height", NULL, NULL, "22",
Tk_Offset(ColorbarBaseOptions, height),
TK_CONFIG_OPTION_SPECIFIED, NULL},
{TK_CONFIG_ANCHOR, (char*)"-anchor", NULL, NULL, "nw",
Tk_Offset(ColorbarBaseOptions, anchor), 0, NULL},
{TK_CONFIG_CUSTOM, (char*)"-tags", NULL, NULL, NULL,
0, TK_CONFIG_NULL_OK, &tagsOption},
{TK_CONFIG_STRING, (char*)"-helvetica", NULL, NULL, "helvetica",
Tk_Offset(ColorbarBaseOptions, helvetica), 0, NULL},
{TK_CONFIG_STRING, (char*)"-courier", NULL, NULL, "courier",
Tk_Offset(ColorbarBaseOptions, courier), 0, NULL},
{TK_CONFIG_STRING, (char*)"-times", NULL, NULL, "times",
Tk_Offset(ColorbarBaseOptions, times), 0, NULL},
{TK_CONFIG_BOOLEAN, (char*)"-orientation", NULL, NULL, "0",
Tk_Offset(ColorbarBaseOptions, orientation), 0, NULL},
{TK_CONFIG_INT, (char*)"-size", NULL, NULL, "20",
Tk_Offset(ColorbarBaseOptions, size), 0, NULL},
{TK_CONFIG_STRING, (char*)"-font", NULL, NULL, "helvetica",
Tk_Offset(ColorbarBaseOptions, font), 0, NULL},
{TK_CONFIG_INT, (char*)"-fontsize", NULL, NULL, "10",
Tk_Offset(ColorbarBaseOptions, fontSize), 0, NULL},
{TK_CONFIG_STRING, (char*)"-fontweight", "fontweight", NULL, "normal",
Tk_Offset(ColorbarBaseOptions, fontWeight), 0, NULL},
{TK_CONFIG_SYNONYM, (char*)"-fontstyle", "fontweight", NULL, NULL, 0, 0},
{TK_CONFIG_STRING, (char*)"-fontslant", NULL, NULL, "roman",
Tk_Offset(ColorbarBaseOptions, fontSlant), 0, NULL},
{TK_CONFIG_BOOLEAN, (char*)"-numerics", NULL, NULL, "1",
Tk_Offset(ColorbarBaseOptions, numerics), 0, NULL},
{TK_CONFIG_BOOLEAN, (char*)"-space", NULL, NULL, "1",
Tk_Offset(ColorbarBaseOptions, space), 0, NULL},
{TK_CONFIG_INT, (char*)"-ticks", NULL, NULL, "11",
Tk_Offset(ColorbarBaseOptions, ticks), 0, NULL},
{TK_CONFIG_INT, (char*)"-colors", NULL, NULL, "1024",
Tk_Offset(ColorbarBaseOptions, colors), 0, NULL},
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0, NULL},
};
// Tk Static Structure
static Tk_ItemType colorbarTrueColor24Type = {
(char*)"colorbartruecolor24", // name
sizeof(ColorbarBaseOptions), // size
ColorbarTrueColor24CreateProc, // configProc
colorbarTrueColor24Specs, // configSpecs
WidgetConfigProc, // configProc
WidgetCoordProc, // coordProc
WidgetDeleteProc, // deleteProc
WidgetDisplayProc, // displayProc
0, // alwaysRedraw
WidgetPointProc, // pointProc
WidgetAreaProc, // areaProc
WidgetPostscriptProc, // postscriptProc
WidgetScaleProc, // scaleProc
WidgetTranslateProc, // translateProc
(Tk_ItemIndexProc*)NULL, // indexProc
WidgetICursorProc, // icursorProc
(Tk_ItemSelectionProc*)NULL, // selectionProc
(Tk_ItemInsertProc*)NULL, // insertProc
(Tk_ItemDCharsProc*)NULL, // dCharsProc
(Tk_ItemType*)NULL // nextPtr
};
// Non-Member Functions
int ColorbarTrueColor24_Init(Tcl_Interp* interp)
{
tagsOption.parseProc = Tk_CanvasTagsParseProc;
tagsOption.printProc = Tk_CanvasTagsPrintProc;
Tk_CreateItemType(&colorbarTrueColor24Type);
return TCL_OK;
}
int ColorbarTrueColor24CreateProc(Tcl_Interp* interp, Tk_Canvas canvas,
Tk_Item* item, int argc,
Tcl_Obj *const argv[])
{
ColorbarTrueColor24* colorbar = new ColorbarTrueColor24(interp,canvas,item);
// and set default configuration
if (colorbar->configure(argc, (const char**)argv, 0) != TCL_OK) {
delete colorbar;
Tcl_AppendResult(interp, " error occured while creating colorbar.", NULL);
return TCL_ERROR;
}
return TCL_OK;
}
// ColorbarTrueColor24
ColorbarTrueColor24::ColorbarTrueColor24(Tcl_Interp* i, Tk_Canvas c,
Tk_Item* item)
: Colorbar(i,c,item), TrueColor24(visual)
{
configSpecs = colorbarTrueColor24Specs; // colorbar configure options
loadDefaultCMaps();
}
void ColorbarTrueColor24::updateColorsHorz()
{
int width = options->width-2;
int height = ((ColorbarBaseOptions*)options)->size-2;
char* data = xmap->data;
switch (xmap->bits_per_pixel) {
case 32:
updateColors32Horz(width, height, data);
break;
case 24:
updateColors24Horz(width, height, data);
break;
default:
internalError("Colorbar: bad bits/pixel");
return;
}
}
void ColorbarTrueColor24::updateColorsVert()
{
int width = ((ColorbarBaseOptions*)options)->size-2;
int height = options->height-2;
char* data = xmap->data;
switch (xmap->bits_per_pixel) {
case 32:
updateColors32Vert(width, height, data);
break;
case 24:
updateColors24Vert(width, height, data);
break;
default:
internalError("Colorbar: bad bits/pixel");
return;
}
}
void ColorbarTrueColor24::updateColors24Horz(int width, int height, char* data)
{
// if we have cross platforms, we need to byte swap
if ((!xmap->byte_order && lsb()) || (xmap->byte_order && !lsb())) {
for (int ii=0; ii<width; ii++) {
unsigned int r = colorCells[(int)(double(ii)/width*colorCount)*3+2];
unsigned int g = colorCells[(int)(double(ii)/width*colorCount)*3+1];
unsigned int b = colorCells[(int)(double(ii)/width*colorCount)*3];
unsigned int a = 0;
a |= r << rs_;
a |= g << gs_;
a |= b << bs_;
memcpy(data+ii*3, &a, 3);
}
}
else {
for (int ii=0; ii<width; ii++) {
unsigned int r = colorCells[(int)(double(ii)/width*colorCount)*3+2];
unsigned int g = colorCells[(int)(double(ii)/width*colorCount)*3+1];
unsigned int b = colorCells[(int)(double(ii)/width*colorCount)*3];
unsigned int a = 0;
a |= r << rs_;
a |= g << gs_;
a |= b << bs_;
unsigned char* rr = (unsigned char*)(&a);
*(data+ii*3) = *(rr+3);
*(data+ii*3+1) = *(rr+2);
*(data+ii*3+2) = *(rr+1);
}
}
// --and duplicate for remaining rows
for (int jj=1; jj<height; jj++)
memcpy(data+(jj*xmap->bytes_per_line), data, xmap->bytes_per_line);
}
void ColorbarTrueColor24::updateColors24Vert(int width, int height, char* data)
{
// if we have cross platforms, we need to byte swap
if ((!xmap->byte_order && lsb()) || (xmap->byte_order && !lsb())) {
for (int jj=height-1; jj>=0; jj--, data+=xmap->bytes_per_line) {
unsigned int r = colorCells[(int)(double(jj)/height*colorCount)*3+2];
unsigned int g = colorCells[(int)(double(jj)/height*colorCount)*3+1];
unsigned int b = colorCells[(int)(double(jj)/height*colorCount)*3];
unsigned int a = 0;
a |= r << rs_;
a |= g << gs_;
a |= b << bs_;
for (int ii=0; ii<width; ii++)
memcpy(data+ii*3, &a, 3);
}
}
else {
for (int jj=height-1; jj>=0; jj--, data+=xmap->bytes_per_line) {
unsigned int r = colorCells[(int)(double(jj)/height*colorCount)*3+2];
unsigned int g = colorCells[(int)(double(jj)/height*colorCount)*3+1];
unsigned int b = colorCells[(int)(double(jj)/height*colorCount)*3];
unsigned int a = 0;
a |= r << rs_;
a |= g << gs_;
a |= b << bs_;
unsigned char* rr = (unsigned char*)(&a);
for (int ii=0; ii<width; ii++) {
*(data+ii*3) = *(rr+3);
*(data+ii*3+1) = *(rr+2);
*(data+ii*3+2) = *(rr+1);
}
}
}
}
void ColorbarTrueColor24::updateColors32Horz(int width, int height, char* data)
{
// if we have cross platforms, we need to byte swap
if ((!xmap->byte_order && lsb()) || (xmap->byte_order && !lsb())) {
for (int ii=0; ii<width; ii++) {
unsigned int r = colorCells[(int)(double(ii)/width*colorCount)*3+2];
unsigned int g = colorCells[(int)(double(ii)/width*colorCount)*3+1];
unsigned int b = colorCells[(int)(double(ii)/width*colorCount)*3];
unsigned int a = 0;
#ifdef MAC_OSX_TK
a |= 0xff << 24;
#endif
a |= r << rs_;
a |= g << gs_;
a |= b << bs_;
memcpy(data+ii*4, &a, 4);
}
}
else {
for (int ii=0; ii<width; ii++) {
unsigned int r = colorCells[(int)(double(ii)/width*colorCount)*3+2];
unsigned int g = colorCells[(int)(double(ii)/width*colorCount)*3+1];
unsigned int b = colorCells[(int)(double(ii)/width*colorCount)*3];
unsigned int a = 0;
#ifdef MAC_OSX_TK
a |= 0xff << 24;
#endif
a |= r << rs_;
a |= g << gs_;
a |= b << bs_;
unsigned char* rr = (unsigned char*)(&a);
*(data+ii*4) = *(rr+3);
*(data+ii*4+1) = *(rr+2);
*(data+ii*4+2) = *(rr+1);
*(data+ii*4+3) = *(rr);
}
}
// --and duplicate for remaining rows
for (int jj=1; jj<height; jj++)
memcpy(data+(jj*xmap->bytes_per_line), data, xmap->bytes_per_line);
}
void ColorbarTrueColor24::updateColors32Vert(int width, int height, char* data)
{
// if we have cross platforms, we need to byte swap
if ((!xmap->byte_order && lsb()) || (xmap->byte_order && !lsb())) {
for (int jj=height-1; jj>=0; jj--, data+=xmap->bytes_per_line) {
unsigned int r = colorCells[(int)(double(jj)/height*colorCount)*3+2];
unsigned int g = colorCells[(int)(double(jj)/height*colorCount)*3+1];
unsigned int b = colorCells[(int)(double(jj)/height*colorCount)*3];
unsigned int a = 0;
#ifdef MAC_OSX_TK
a |= 0xff << 24;
#endif
a |= r << rs_;
a |= g << gs_;
a |= b << bs_;
for (int ii=0; ii<width; ii++)
memcpy(data+ii*4, &a, 4);
}
}
else {
for (int jj=height-1; jj>=0; jj--, data+=xmap->bytes_per_line) {
unsigned int r = colorCells[(int)(double(jj)/height*colorCount)*3+2];
unsigned int g = colorCells[(int)(double(jj)/height*colorCount)*3+1];
unsigned int b = colorCells[(int)(double(jj)/height*colorCount)*3];
unsigned int a = 0;
#ifdef MAC_OSX_TK
a |= 0xff << 24;
#endif
a |= r << rs_;
a |= g << gs_;
a |= b << bs_;
unsigned char* rr = (unsigned char*)(&a);
for (int ii=0; ii<width; ii++) {
*(data+ii*4) = *(rr+3);
*(data+ii*4+1) = *(rr+2);
*(data+ii*4+2) = *(rr+1);
*(data+ii*4+3) = *(rr);
}
}
}
}
|