tioga 1.7 → 1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Tioga_README +45 -29
- data/split/Dvector/dvector.c +1 -1
- data/split/Tioga/{shared/axes.c → axes.c} +360 -36
- data/split/Tioga/figures.c +2 -1
- data/split/Tioga/figures.h +6 -2
- data/split/Tioga/generic.h +0 -1
- data/split/Tioga/lib/FigMkr.rb +3 -1
- data/split/Tioga/lib/X_and_Y_Axes.rb +74 -4
- data/split/Tioga/makers.c +1303 -0
- data/split/Tioga/{shared/pdf_font_dicts.c → pdf_font_dicts.c} +0 -0
- data/split/Tioga/{shared/pdfcolor.c → pdfcolor.c} +304 -145
- data/split/Tioga/pdfcoords.c +534 -0
- data/split/Tioga/{shared/pdffile.c → pdffile.c} +161 -56
- data/split/Tioga/{shared/pdfimage.c → pdfimage.c} +171 -74
- data/split/Tioga/{shared/pdfpath.c → pdfpath.c} +0 -0
- data/split/Tioga/{shared/pdftext.c → pdftext.c} +245 -138
- data/split/Tioga/{shared/texout.c → texout.c} +18 -9
- data/split/Tioga/wrappers.c +23 -7
- data/split/Tioga/wrappers.h +5 -3
- data/split/extconf.rb +1 -1
- metadata +25 -25
- data/split/Tioga/shared/makers.c +0 -1220
- data/split/Tioga/shared/pdfcoords.c +0 -443
File without changes
|
@@ -22,9 +22,11 @@
|
|
22
22
|
#include "figures.h"
|
23
23
|
#include "pdfs.h"
|
24
24
|
|
25
|
+
|
25
26
|
/* functions */
|
26
27
|
|
27
|
-
void
|
28
|
+
void
|
29
|
+
Free_Functions()
|
28
30
|
{
|
29
31
|
Function_Info *fo;
|
30
32
|
while (functions_list != NULL) {
|
@@ -35,7 +37,9 @@ void Free_Functions()
|
|
35
37
|
}
|
36
38
|
}
|
37
39
|
|
38
|
-
|
40
|
+
|
41
|
+
static void
|
42
|
+
Write_Sampled_Function(Function_Info *fo, int *ierr)
|
39
43
|
{
|
40
44
|
fprintf(OF, "%i 0 obj << /FunctionType 0\n", fo->obj_num);
|
41
45
|
fprintf(OF, "\t/Domain [0 1]\n");
|
@@ -45,11 +49,15 @@ static void Write_Sampled_Function(Function_Info *fo, int *ierr)
|
|
45
49
|
fprintf(OF, "\t/Order 1\n");
|
46
50
|
fprintf(OF, "\t/Length %i\n\t>>\nstream\n", fo->lookup_len);
|
47
51
|
if (fwrite(fo->lookup, 1, fo->lookup_len, OF) < fo->lookup_len) {
|
48
|
-
RAISE_ERROR("Error writing function sample data", ierr);
|
52
|
+
RAISE_ERROR("Error writing function sample data", ierr);
|
53
|
+
return;
|
54
|
+
}
|
49
55
|
fprintf(OF, "\nendstream\nendobj\n");
|
50
56
|
}
|
51
57
|
|
52
|
-
|
58
|
+
|
59
|
+
void
|
60
|
+
Write_Functions(int *ierr)
|
53
61
|
{
|
54
62
|
Function_Info *fo;
|
55
63
|
for (fo = functions_list; fo != NULL; fo = fo->next) {
|
@@ -58,7 +66,9 @@ void Write_Functions(int *ierr)
|
|
58
66
|
}
|
59
67
|
}
|
60
68
|
|
61
|
-
|
69
|
+
|
70
|
+
static int
|
71
|
+
create_function(int hival, int lookup_len, unsigned char *lookup)
|
62
72
|
{
|
63
73
|
Function_Info *fo = (Function_Info *)calloc(1,sizeof(Function_Info));
|
64
74
|
fo->next = functions_list;
|
@@ -71,23 +81,29 @@ static int create_function(int hival, int lookup_len, unsigned char *lookup)
|
|
71
81
|
return fo->obj_num;
|
72
82
|
}
|
73
83
|
|
84
|
+
|
74
85
|
/* Opacity */
|
75
86
|
|
76
|
-
void
|
87
|
+
void
|
88
|
+
Free_Stroke_Opacities(void)
|
77
89
|
{
|
78
90
|
Stroke_Opacity_State *p;
|
79
91
|
while (stroke_opacities != NULL) {
|
80
|
-
p = stroke_opacities;
|
92
|
+
p = stroke_opacities;
|
93
|
+
stroke_opacities = p->next;
|
94
|
+
free(p);
|
81
95
|
}
|
82
96
|
}
|
83
97
|
|
84
|
-
|
98
|
+
|
99
|
+
static int
|
100
|
+
Get_Stroke_Opacity_XGS(double stroke_opacity)
|
85
101
|
{
|
86
102
|
Stroke_Opacity_State *p;
|
87
103
|
for (p = stroke_opacities; p != NULL; p = p->next) {
|
88
104
|
if (p->stroke_opacity == stroke_opacity) return p->gs_num;
|
89
105
|
}
|
90
|
-
p = (Stroke_Opacity_State *)calloc(1,sizeof(Stroke_Opacity_State));
|
106
|
+
p = (Stroke_Opacity_State *)calloc(1, sizeof(Stroke_Opacity_State));
|
91
107
|
p->stroke_opacity = stroke_opacity;
|
92
108
|
p->gs_num = next_available_gs_number++;
|
93
109
|
p->obj_num = next_available_object_number++;
|
@@ -96,31 +112,42 @@ static int Get_Stroke_Opacity_XGS(double stroke_opacity)
|
|
96
112
|
return p->gs_num;
|
97
113
|
}
|
98
114
|
|
99
|
-
|
115
|
+
|
116
|
+
void
|
117
|
+
c_stroke_opacity_set(OBJ_PTR fmkr, FM *p, double stroke_opacity, int *ierr)
|
100
118
|
{ // /GSi gs for ExtGState obj with /CS set to stroke opacity val
|
101
119
|
if (constructing_path) {
|
102
|
-
RAISE_ERROR("Sorry: must not be constructing a path when change stroke
|
120
|
+
RAISE_ERROR("Sorry: must not be constructing a path when change stroke"
|
121
|
+
" opacity", ierr);
|
122
|
+
return;
|
123
|
+
}
|
103
124
|
if (stroke_opacity == p->stroke_opacity) return;
|
104
125
|
int gs_num = Get_Stroke_Opacity_XGS(stroke_opacity);
|
105
126
|
fprintf(TF, "/GS%i gs\n", gs_num);
|
106
127
|
p->stroke_opacity = stroke_opacity;
|
107
128
|
}
|
108
129
|
|
109
|
-
|
130
|
+
|
131
|
+
void
|
132
|
+
Free_Fill_Opacities(void)
|
110
133
|
{
|
111
134
|
Fill_Opacity_State *p;
|
112
135
|
while (fill_opacities != NULL) {
|
113
|
-
p = fill_opacities;
|
136
|
+
p = fill_opacities;
|
137
|
+
fill_opacities = p->next;
|
138
|
+
free(p);
|
114
139
|
}
|
115
140
|
}
|
116
141
|
|
117
|
-
|
142
|
+
|
143
|
+
static int
|
144
|
+
Get_Fill_Opacity_XGS(double fill_opacity)
|
118
145
|
{
|
119
146
|
Fill_Opacity_State *p;
|
120
147
|
for (p = fill_opacities; p != NULL; p = p->next) {
|
121
148
|
if (p->fill_opacity == fill_opacity) return p->gs_num;
|
122
149
|
}
|
123
|
-
p = (Fill_Opacity_State *)calloc(1,sizeof(Fill_Opacity_State));
|
150
|
+
p = (Fill_Opacity_State *)calloc(1, sizeof(Fill_Opacity_State));
|
124
151
|
p->fill_opacity = fill_opacity;
|
125
152
|
p->gs_num = next_available_gs_number++;
|
126
153
|
p->obj_num = next_available_object_number++;
|
@@ -129,37 +156,50 @@ static int Get_Fill_Opacity_XGS(double fill_opacity)
|
|
129
156
|
return p->gs_num;
|
130
157
|
}
|
131
158
|
|
132
|
-
|
159
|
+
|
160
|
+
void
|
161
|
+
c_fill_opacity_set(OBJ_PTR fmkr, FM *p, double fill_opacity, int *ierr)
|
133
162
|
{ // /GSi gs for ExtGState obj with /cs set to fill opacity val
|
134
163
|
if (constructing_path) {
|
135
|
-
RAISE_ERROR("Sorry: must not be constructing a path when change fill
|
164
|
+
RAISE_ERROR("Sorry: must not be constructing a path when change fill "
|
165
|
+
"opacity", ierr);
|
166
|
+
return;
|
167
|
+
}
|
136
168
|
if (fill_opacity == p->fill_opacity) return;
|
137
169
|
int gs_num = Get_Fill_Opacity_XGS(fill_opacity);
|
138
170
|
fprintf(TF, "/GS%i gs\n", gs_num);
|
139
171
|
p->fill_opacity = fill_opacity;
|
140
172
|
}
|
141
173
|
|
142
|
-
|
174
|
+
|
175
|
+
void
|
176
|
+
Write_Stroke_Opacity_Objects(void)
|
143
177
|
{
|
144
178
|
Stroke_Opacity_State *p;
|
145
179
|
for (p = stroke_opacities; p != NULL; p = p->next) {
|
146
180
|
Record_Object_Offset(p->obj_num);
|
147
|
-
fprintf(OF, "%2i 0 obj << /Type /ExtGState /CA %g >> endobj\n",
|
181
|
+
fprintf(OF, "%2i 0 obj << /Type /ExtGState /CA %g >> endobj\n",
|
182
|
+
p->obj_num, p->stroke_opacity);
|
148
183
|
}
|
149
184
|
}
|
150
185
|
|
151
|
-
|
186
|
+
|
187
|
+
void
|
188
|
+
Write_Fill_Opacity_Objects(void)
|
152
189
|
{
|
153
190
|
Fill_Opacity_State *p;
|
154
191
|
for (p = fill_opacities; p != NULL; p = p->next) {
|
155
192
|
Record_Object_Offset(p->obj_num);
|
156
|
-
fprintf(OF, "%2i 0 obj << /Type /ExtGState /ca %g >> endobj\n",
|
193
|
+
fprintf(OF, "%2i 0 obj << /Type /ExtGState /ca %g >> endobj\n",
|
194
|
+
p->obj_num, p->fill_opacity);
|
157
195
|
}
|
158
196
|
}
|
159
197
|
|
198
|
+
|
160
199
|
/* Shading */
|
161
200
|
|
162
|
-
void
|
201
|
+
void
|
202
|
+
Free_Shadings()
|
163
203
|
{
|
164
204
|
Shading_Info *so;
|
165
205
|
while (shades_list != NULL) {
|
@@ -169,7 +209,9 @@ void Free_Shadings()
|
|
169
209
|
}
|
170
210
|
}
|
171
211
|
|
172
|
-
|
212
|
+
|
213
|
+
void
|
214
|
+
Write_Shadings(void)
|
173
215
|
{
|
174
216
|
Shading_Info *so;
|
175
217
|
for (so = shades_list; so != NULL; so = so->next) {
|
@@ -177,13 +219,17 @@ void Write_Shadings(void)
|
|
177
219
|
fprintf(OF, "%i 0 obj <<\n", so->obj_num);
|
178
220
|
if (so->axial) {
|
179
221
|
fprintf(OF, "\t/ShadingType 2\n\t/Coords [%0.2f %0.2f %0.2f %0.2f]\n",
|
180
|
-
|
181
|
-
}
|
182
|
-
|
183
|
-
|
222
|
+
so->x0, so->y0, so->x1, so->y1);
|
223
|
+
}
|
224
|
+
else {
|
225
|
+
fprintf(OF, "\t/ShadingType 3\n\t/Coords "
|
226
|
+
"[%0.2f %0.2f %0.2f %0.2f %0.2f %0.2f]\n",
|
227
|
+
so->x0, so->y0, so->r0, so->x1, so->y1, so->r1);
|
184
228
|
}
|
185
|
-
if (so->extend_start || so->extend_end)
|
186
|
-
(
|
229
|
+
if (so->extend_start || so->extend_end)
|
230
|
+
fprintf(OF, "\t/Extend [ %s %s ]\n",
|
231
|
+
(so->extend_start)? "true" : "false",
|
232
|
+
(so->extend_end)? "true" : "false");
|
187
233
|
fprintf(OF, "\t/ColorSpace /DeviceRGB\n");
|
188
234
|
fprintf(OF, "\t/Function %i 0 R\n", so->function);
|
189
235
|
fprintf(OF, ">> endobj\n");
|
@@ -191,10 +237,12 @@ void Write_Shadings(void)
|
|
191
237
|
}
|
192
238
|
|
193
239
|
|
194
|
-
static void
|
195
|
-
|
240
|
+
static void
|
241
|
+
c_axial_shading(FM *p, double x0, double y0, double x1, double y1,
|
242
|
+
int hival, int lookup_len, unsigned char *lookup,
|
243
|
+
bool extend_start, bool extend_end)
|
196
244
|
{
|
197
|
-
Shading_Info *so = (Shading_Info *)calloc(1,sizeof(Shading_Info));
|
245
|
+
Shading_Info *so = (Shading_Info *)calloc(1, sizeof(Shading_Info));
|
198
246
|
so->next = shades_list;
|
199
247
|
shades_list = so;
|
200
248
|
so->shade_num = next_available_shade_number++;
|
@@ -209,30 +257,40 @@ static void c_axial_shading(FM *p, double x0, double y0, double x1, double y1,
|
|
209
257
|
so->extend_end = extend_end;
|
210
258
|
fprintf(TF, "/Shade%i sh\n", so->shade_num);
|
211
259
|
}
|
260
|
+
|
212
261
|
|
213
|
-
void
|
214
|
-
|
262
|
+
void
|
263
|
+
c_private_axial_shading(OBJ_PTR fmkr, FM *p, double x0, double y0, double x1,
|
264
|
+
double y1, OBJ_PTR colormap, bool extend_start,
|
265
|
+
bool extend_end, int *ierr)
|
215
266
|
{
|
216
|
-
int len = Array_Len(colormap,ierr);
|
267
|
+
int len = Array_Len(colormap, ierr);
|
217
268
|
if (*ierr != 0) return;
|
218
269
|
if (len != 2) {
|
219
|
-
RAISE_ERROR("Sorry: colormap must be array [hivalue, lookup]", ierr);
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
270
|
+
RAISE_ERROR("Sorry: colormap must be array [hivalue, lookup]", ierr);
|
271
|
+
return;
|
272
|
+
}
|
273
|
+
OBJ_PTR hival = Array_Entry(colormap, 0, ierr);
|
274
|
+
OBJ_PTR lookup = Array_Entry(colormap, 1, ierr);
|
275
|
+
int hi_value = Number_to_int(hival, ierr);
|
276
|
+
int lookup_len = String_Len(lookup, ierr);
|
277
|
+
unsigned char *lookup_ptr = (unsigned char *)(String_Ptr(lookup, ierr));
|
225
278
|
if (*ierr != 0) return;
|
226
|
-
c_axial_shading(p, convert_figure_to_output_x(p,x0),
|
227
|
-
|
228
|
-
|
279
|
+
c_axial_shading(p, convert_figure_to_output_x(p, x0),
|
280
|
+
convert_figure_to_output_y(p, y0),
|
281
|
+
convert_figure_to_output_x(p, x1),
|
282
|
+
convert_figure_to_output_y(p, y1),
|
283
|
+
hi_value, lookup_len, lookup_ptr, extend_start, extend_end);
|
229
284
|
}
|
230
285
|
|
231
|
-
|
232
|
-
|
233
|
-
|
286
|
+
|
287
|
+
static void
|
288
|
+
c_radial_shading(FM *p, double x0, double y0, double r0, double x1, double y1,
|
289
|
+
double r1, int hival, int lookup_len, unsigned char *lookup,
|
290
|
+
double a, double b, double c, double d, double e, double f,
|
291
|
+
bool extend_start, bool extend_end)
|
234
292
|
{
|
235
|
-
Shading_Info *so = (Shading_Info *)calloc(1,sizeof(Shading_Info));
|
293
|
+
Shading_Info *so = (Shading_Info *)calloc(1, sizeof(Shading_Info));
|
236
294
|
so->next = shades_list;
|
237
295
|
shades_list = so;
|
238
296
|
so->shade_num = next_available_shade_number++;
|
@@ -249,40 +307,49 @@ static void c_radial_shading(FM *p, double x0, double y0, double r0, double x1,
|
|
249
307
|
so->extend_end = extend_end;
|
250
308
|
if (a != 1.0 || b != 0.0 || c != 0.0 || d != 1.0 || e != 0 || f != 0) {
|
251
309
|
fprintf(TF, "q %0.2f %0.2f %0.2f %0.2f %0.2f %0.2f cm /Shade%i sh Q\n",
|
252
|
-
|
253
|
-
}
|
310
|
+
a, b, c, d, e, f, so->shade_num);
|
311
|
+
}
|
312
|
+
else {
|
254
313
|
fprintf(TF, "/Shade%i sh\n", so->shade_num);
|
255
314
|
}
|
256
315
|
}
|
257
316
|
|
258
317
|
|
259
|
-
void
|
260
|
-
|
261
|
-
|
262
|
-
|
318
|
+
void
|
319
|
+
c_private_radial_shading(OBJ_PTR fmkr, FM *p,
|
320
|
+
double x0, double y0, double r0,
|
321
|
+
double x1, double y1, double r1, OBJ_PTR colormap,
|
322
|
+
double a, double b, double c, double d,
|
323
|
+
bool extend_start, bool extend_end, int *ierr)
|
263
324
|
{
|
264
325
|
int len = Array_Len(colormap, ierr);
|
265
326
|
if (*ierr != 0) return;
|
266
327
|
if (len != 2) {
|
267
|
-
RAISE_ERROR("Sorry: colormap must be array [hivalue, lookup]", ierr);
|
328
|
+
RAISE_ERROR("Sorry: colormap must be array [hivalue, lookup]", ierr);
|
329
|
+
return;
|
330
|
+
}
|
268
331
|
OBJ_PTR hival = Array_Entry(colormap, 0, ierr);
|
269
332
|
OBJ_PTR lookup = Array_Entry(colormap, 1, ierr);
|
270
|
-
int hi_value = Number_to_int(hival,ierr);
|
271
|
-
int lookup_len = String_Len(lookup,ierr);
|
272
|
-
unsigned char *lookup_ptr = (unsigned char *)(String_Ptr(lookup,ierr));
|
333
|
+
int hi_value = Number_to_int(hival, ierr);
|
334
|
+
int lookup_len = String_Len(lookup, ierr);
|
335
|
+
unsigned char *lookup_ptr = (unsigned char *)(String_Ptr(lookup, ierr));
|
273
336
|
if (*ierr != 0) return;
|
274
337
|
c_radial_shading(p, x0, y0, r0, x1, y1, r1,
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
338
|
+
hi_value, lookup_len, lookup_ptr,
|
339
|
+
convert_figure_to_output_dx(p, a),
|
340
|
+
convert_figure_to_output_dy(p, b),
|
341
|
+
convert_figure_to_output_dx(p, c),
|
342
|
+
convert_figure_to_output_dy(p, d),
|
343
|
+
convert_figure_to_output_x(p, 0.0),
|
344
|
+
convert_figure_to_output_y(p, 0.0),
|
345
|
+
extend_start, extend_end);
|
280
346
|
}
|
281
347
|
|
282
|
-
/* Colormaps
|
283
|
-
*/
|
284
348
|
|
285
|
-
|
349
|
+
/* Colormaps */
|
350
|
+
|
351
|
+
static double
|
352
|
+
clr_value(double n1, double n2, double hue) // from plplot plctrl.c
|
286
353
|
{
|
287
354
|
double val;
|
288
355
|
while (hue >= 360.) hue -= 360.;
|
@@ -291,10 +358,13 @@ static double clr_value(double n1, double n2, double hue) // from plplot plctrl
|
|
291
358
|
else if (hue < 180.) val = n2;
|
292
359
|
else if (hue < 240.) val = n1 + (n2 - n1) * (240. - hue) / 60.;
|
293
360
|
else val = n1;
|
294
|
-
return
|
361
|
+
return val;
|
295
362
|
}
|
296
363
|
|
297
|
-
|
364
|
+
|
365
|
+
static void
|
366
|
+
convert_hls_to_rgb(double h, double l, double s, double *p_r, double *p_g,
|
367
|
+
double *p_b) // from plplot plctrl.c
|
298
368
|
{
|
299
369
|
double m1, m2;
|
300
370
|
if (l <= .5) m2 = l * (s + 1.);
|
@@ -305,33 +375,38 @@ static void convert_hls_to_rgb(double h, double l, double s, double *p_r, double
|
|
305
375
|
*p_b = clr_value(m1, m2, h - 120.);
|
306
376
|
}
|
307
377
|
|
308
|
-
|
378
|
+
|
379
|
+
static void
|
380
|
+
convert_rgb_to_hls(double r, double g, double b, double *p_h, double *p_l,
|
381
|
+
double *p_s) // from plplot plctrl.c
|
309
382
|
{
|
310
383
|
double h, l, s, d, rc, gc, bc, rgb_min, rgb_max;
|
311
384
|
rgb_min = MIN( r, MIN( g, b ));
|
312
385
|
rgb_max = MAX( r, MAX( g, b ));
|
313
|
-
l = (rgb_min+rgb_max) / 2.0;
|
386
|
+
l = (rgb_min + rgb_max) / 2.0;
|
314
387
|
if (rgb_min == rgb_max) s = h = 0;
|
315
388
|
else {
|
316
389
|
d = rgb_max - rgb_min;
|
317
390
|
if (l < 0.5) s = 0.5 * d / l;
|
318
|
-
else s = 0.5* d / (1.-l);
|
319
|
-
rc = (rgb_max-r) / d;
|
320
|
-
gc = (rgb_max-g) / d;
|
321
|
-
bc = (rgb_max-b) / d;
|
322
|
-
if (r == rgb_max) h = bc-gc;
|
323
|
-
else if (g == rgb_max) h = rc-bc+2;
|
324
|
-
else h = gc-rc-2;
|
325
|
-
h = h*60;
|
326
|
-
if (h < 0) h = h+360;
|
327
|
-
else if (h >= 360) h = h-360;
|
391
|
+
else s = 0.5 * d / (1.-l);
|
392
|
+
rc = (rgb_max - r) / d;
|
393
|
+
gc = (rgb_max - g) / d;
|
394
|
+
bc = (rgb_max - b) / d;
|
395
|
+
if (r == rgb_max) h = bc - gc;
|
396
|
+
else if (g == rgb_max) h = rc - bc + 2;
|
397
|
+
else h = gc - rc - 2;
|
398
|
+
h = h * 60;
|
399
|
+
if (h < 0) h = h + 360;
|
400
|
+
else if (h >= 360) h = h - 360;
|
328
401
|
}
|
329
402
|
*p_h = h;
|
330
403
|
*p_l = l;
|
331
404
|
*p_s = s;
|
332
405
|
}
|
333
406
|
|
334
|
-
|
407
|
+
|
408
|
+
static double
|
409
|
+
linear_interpolate(int num_pts, double *xs, double *ys, double x)
|
335
410
|
{
|
336
411
|
int i;
|
337
412
|
if (num_pts == 1) return ys[0];
|
@@ -343,17 +418,25 @@ static double linear_interpolate(int num_pts, double *xs, double *ys, double x)
|
|
343
418
|
return ys[num_pts-1];
|
344
419
|
}
|
345
420
|
|
346
|
-
|
347
|
-
|
421
|
+
|
422
|
+
static OBJ_PTR
|
423
|
+
c_create_colormap(FM *p, bool rgb_flag, int length, int num_pts, double *ps,
|
424
|
+
double *c1s, double *c2s, double *c3s, int *ierr)
|
348
425
|
{
|
349
426
|
int i;
|
350
427
|
if (ps[0] != 0.0 || ps[num_pts-1] != 1.0) {
|
351
|
-
RAISE_ERROR("Sorry: first control point for create colormap must be
|
428
|
+
RAISE_ERROR("Sorry: first control point for create colormap must be "
|
429
|
+
"at 0.0 and last must be at 1.0", ierr);
|
430
|
+
RETURN_NIL;
|
431
|
+
}
|
352
432
|
for (i = 1; i < num_pts; i++) {
|
353
433
|
if (ps[i-1] > ps[i]) {
|
354
|
-
RAISE_ERROR("Sorry: control points for create colormap must be
|
434
|
+
RAISE_ERROR("Sorry: control points for create colormap must be "
|
435
|
+
"increasing from 0 to 1", ierr);
|
436
|
+
RETURN_NIL;
|
437
|
+
}
|
355
438
|
}
|
356
|
-
int j, buff_len = length * 3, hival = length-1;
|
439
|
+
int j, buff_len = length * 3, hival = length - 1;
|
357
440
|
unsigned char *buff;
|
358
441
|
buff = ALLOC_N_unsigned_char(buff_len);
|
359
442
|
for (j = 0, i = 0; j < length; j++) {
|
@@ -377,42 +460,63 @@ static OBJ_PTR c_create_colormap(FM *p, bool rgb_flag, int length,
|
|
377
460
|
return result;
|
378
461
|
}
|
379
462
|
|
380
|
-
|
381
|
-
|
463
|
+
|
464
|
+
/*
|
465
|
+
* create mappings from 'position' (0 to 1) to color (in HLS or RGB
|
466
|
+
* color spaces)
|
467
|
+
*
|
468
|
+
* the length parameter determines the number of entries in the color
|
469
|
+
* map (any integer between 2 and 256).
|
470
|
+
*
|
471
|
+
* for rgb, the colors are given as (red, green, blue) intensities
|
472
|
+
* from 0.0 to 1.0
|
473
|
+
*
|
474
|
+
* for hls, the colors are given as (hue, lightness, saturation)
|
475
|
+
* lightness and saturation given as values from 0.0 to 1.0 hue given
|
476
|
+
* as degrees (0 to 360) around the color wheel from
|
477
|
+
* red->green->blue->red
|
478
|
+
*
|
479
|
+
* Ps are the locations in (0 to 1) for the control points -- in
|
480
|
+
* increasing order
|
481
|
+
*
|
482
|
+
* must have Ps[0] == 0.0 and Ps[num_ps-1] == 1.0
|
483
|
+
*/
|
484
|
+
OBJ_PTR
|
485
|
+
c_private_create_colormap(OBJ_PTR fmkr, FM *p, bool rgb, int length,
|
486
|
+
OBJ_PTR Ps, OBJ_PTR C1s, OBJ_PTR C2s, OBJ_PTR C3s,
|
487
|
+
int *ierr)
|
382
488
|
{
|
383
|
-
/*
|
384
|
-
create mappings from 'position' (0 to 1) to color (in HLS or RGB color spaces)
|
385
|
-
the length parameter determines the number of entries in the color map (any integer between 2 and 256).
|
386
|
-
for rgb, the colors are given as (red, green, blue) intensities from 0.0 to 1.0
|
387
|
-
for hls, the colors are given as (hue, lightness, saturation)
|
388
|
-
lightness and saturation given as values from 0.0 to 1.0
|
389
|
-
hue given as degrees (0 to 360) around the color wheel from red->green->blue->red
|
390
|
-
Ps are the locations in (0 to 1) for the control points -- in increasing order
|
391
|
-
must have Ps[0] == 0.0 and Ps[num_ps-1] == 1.0
|
392
|
-
*/
|
393
489
|
long p_len, c1_len, c2_len, c3_len;
|
394
490
|
double *p_ptr = Vector_Data_for_Read(Ps, &p_len, ierr);
|
395
|
-
if (*ierr != 0)
|
491
|
+
if (*ierr != 0) RETURN_NIL;
|
396
492
|
double *c1_ptr = Vector_Data_for_Read(C1s, &c1_len, ierr);
|
397
|
-
if (*ierr != 0)
|
493
|
+
if (*ierr != 0) RETURN_NIL;
|
398
494
|
double *c2_ptr = Vector_Data_for_Read(C2s, &c2_len, ierr);
|
399
|
-
if (*ierr != 0)
|
495
|
+
if (*ierr != 0) RETURN_NIL;
|
400
496
|
double *c3_ptr = Vector_Data_for_Read(C3s, &c3_len, ierr);
|
401
|
-
if (*ierr != 0)
|
497
|
+
if (*ierr != 0) RETURN_NIL;
|
402
498
|
if (p_len < 2 || p_len != c1_len || p_len != c2_len || p_len != c3_len) {
|
403
|
-
RAISE_ERROR("Sorry: vectors for create colormap must all be os same
|
499
|
+
RAISE_ERROR("Sorry: vectors for create colormap must all be os same "
|
500
|
+
"length (with at least 2 entries)", ierr);
|
404
501
|
RETURN_NIL;
|
405
502
|
}
|
406
|
-
return c_create_colormap(p, rgb, length, p_len, p_ptr, c1_ptr, c2_ptr,
|
503
|
+
return c_create_colormap(p, rgb, length, p_len, p_ptr, c1_ptr, c2_ptr,
|
504
|
+
c3_ptr, ierr);
|
407
505
|
}
|
506
|
+
|
408
507
|
|
409
|
-
OBJ_PTR
|
410
|
-
|
411
|
-
|
508
|
+
OBJ_PTR
|
509
|
+
c_get_color_from_colormap(OBJ_PTR fmkr, FM *p, OBJ_PTR color_map, double x,
|
510
|
+
int *ierr)
|
511
|
+
{ // x is from 0 to 1. this returns a vector for the RGB color from
|
512
|
+
// the given colormap
|
513
|
+
unsigned char *buff = (unsigned char *)(String_Ptr(color_map,ierr));
|
514
|
+
unsigned char r, g, b, i;
|
412
515
|
int len = String_Len(color_map,ierr);
|
413
516
|
if (*ierr != 0) RETURN_NIL;
|
414
517
|
if (len % 3 != 0) {
|
415
|
-
RAISE_ERROR("Sorry: color_map length must be a multiple of 3
|
518
|
+
RAISE_ERROR("Sorry: color_map length must be a multiple of 3 "
|
519
|
+
"(for R G B components)", ierr);
|
416
520
|
RETURN_NIL;
|
417
521
|
}
|
418
522
|
i = 3 * ROUND(x * ((len/3)-1));
|
@@ -425,20 +529,31 @@ OBJ_PTR c_get_color_from_colormap(OBJ_PTR fmkr, FM *p, OBJ_PTR color_map, double
|
|
425
529
|
return result;
|
426
530
|
}
|
427
531
|
|
428
|
-
|
532
|
+
|
533
|
+
/*
|
534
|
+
* this creates an arbitrary mapping from positions to colors given as
|
535
|
+
* (r,g,b) triples
|
536
|
+
*
|
537
|
+
* the colormap size is set to the length of the vectors
|
538
|
+
*
|
539
|
+
* the Rs, Gs, and Bs are VALUEs from 0 to 1 representing the
|
540
|
+
* intensity of the color component
|
541
|
+
*/
|
542
|
+
OBJ_PTR
|
543
|
+
c_convert_to_colormap(OBJ_PTR fmkr, FM* p, OBJ_PTR Rs, OBJ_PTR Gs, OBJ_PTR Bs,
|
544
|
+
int *ierr)
|
429
545
|
{
|
430
|
-
|
431
|
-
/* the colormap size is set to the length of the vectors */
|
432
|
-
/* the Rs, Gs, and Bs are VALUEs from 0 to 1 representing the intensity of the color component */
|
546
|
+
|
433
547
|
long r_len, g_len, b_len;
|
434
548
|
double *r_ptr = Vector_Data_for_Read(Rs, &r_len, ierr);
|
435
|
-
if (*ierr != 0)
|
549
|
+
if (*ierr != 0) RETURN_NIL;
|
436
550
|
double *g_ptr = Vector_Data_for_Read(Gs, &g_len, ierr);
|
437
|
-
if (*ierr != 0)
|
551
|
+
if (*ierr != 0) RETURN_NIL;
|
438
552
|
double *b_ptr = Vector_Data_for_Read(Bs, &b_len, ierr);
|
439
|
-
if (*ierr != 0)
|
553
|
+
if (*ierr != 0) RETURN_NIL;
|
440
554
|
if (r_len <= 0 || r_len != g_len || b_len != g_len) {
|
441
|
-
RAISE_ERROR("Sorry: vectors for convert_to_colormap must all be of
|
555
|
+
RAISE_ERROR("Sorry: vectors for convert_to_colormap must all be of "
|
556
|
+
"same length", ierr);
|
442
557
|
RETURN_NIL;
|
443
558
|
}
|
444
559
|
int i, j, buff_len = r_len * 3;
|
@@ -458,26 +573,40 @@ OBJ_PTR c_convert_to_colormap(OBJ_PTR fmkr, FM* p, OBJ_PTR Rs, OBJ_PTR Gs, OBJ_P
|
|
458
573
|
return result;
|
459
574
|
}
|
460
575
|
|
461
|
-
|
576
|
+
|
577
|
+
static void
|
578
|
+
Unpack_HLS(OBJ_PTR hls, double *hp, double *lp, double *sp, int *ierr)
|
462
579
|
{
|
463
|
-
int len = Array_Len(hls,ierr);
|
580
|
+
int len = Array_Len(hls, ierr);
|
464
581
|
if (*ierr != 0) return;
|
465
582
|
if (len != 3) {
|
466
|
-
RAISE_ERROR("Sorry: invalid hls array: must have 3 entries", ierr);
|
583
|
+
RAISE_ERROR("Sorry: invalid hls array: must have 3 entries", ierr);
|
584
|
+
return;
|
585
|
+
}
|
467
586
|
OBJ_PTR entry = Array_Entry(hls, 0, ierr); if (*ierr != 0) return;
|
468
587
|
double h = Number_to_double(entry, ierr); if (*ierr != 0) return;
|
469
588
|
entry = Array_Entry(hls, 1, ierr); if (*ierr != 0) return;
|
470
589
|
double l = Number_to_double(entry, ierr); if (*ierr != 0) return;
|
471
590
|
entry = Array_Entry(hls, 2, ierr); if (*ierr != 0) return;
|
472
591
|
double s = Number_to_double(entry, ierr); if (*ierr != 0) return;
|
473
|
-
if (l < 0.0 || l > 1.0) {
|
474
|
-
|
592
|
+
if (l < 0.0 || l > 1.0) {
|
593
|
+
RAISE_ERROR_g("Sorry: invalid lightness (%g) for hls: must be between 0 "
|
594
|
+
"and 1", l, ierr);
|
595
|
+
return;
|
596
|
+
}
|
597
|
+
if (s < 0.0 || s > 1.0) {
|
598
|
+
RAISE_ERROR_g("Sorry: invalid saturation (%g) for hls: must be between "
|
599
|
+
"0 and 1", s, ierr);
|
600
|
+
return;
|
601
|
+
}
|
475
602
|
*hp = h; *lp = l; *sp = s;
|
476
603
|
}
|
477
604
|
|
478
|
-
|
605
|
+
|
606
|
+
OBJ_PTR
|
607
|
+
c_hls_to_rgb(OBJ_PTR fmkr, FM *p, OBJ_PTR hls_vec, int *ierr)
|
479
608
|
{
|
480
|
-
double h, l, s, r, g, b;
|
609
|
+
double h = 0.0, l = 0.0, s = 0.0, r = 0.0, g = 0.0, b = 0.0;
|
481
610
|
Unpack_HLS(hls_vec, &h, &l, &s, ierr);
|
482
611
|
if (*ierr != 0) RETURN_NIL;
|
483
612
|
convert_hls_to_rgb(h, l, s, &r, &g, &b);
|
@@ -488,11 +617,19 @@ OBJ_PTR c_hls_to_rgb(OBJ_PTR fmkr, FM *p, OBJ_PTR hls_vec, int *ierr)
|
|
488
617
|
return result;
|
489
618
|
}
|
490
619
|
|
491
|
-
|
620
|
+
|
621
|
+
|
622
|
+
OBJ_PTR
|
623
|
+
c_rgb_to_hls(OBJ_PTR fmkr, FM *p, OBJ_PTR rgb_vec, int *ierr)
|
492
624
|
{
|
493
|
-
|
494
|
-
|
495
|
-
|
625
|
+
/*
|
626
|
+
* hue is given as an angle from 0 to 360 around the color wheel.
|
627
|
+
*
|
628
|
+
* 0, 60, 120, 180, 240, and 300 are respectively red, yellow,
|
629
|
+
* green, cyan, blue, and magenta.
|
630
|
+
*
|
631
|
+
* lightness and saturation are given as numbers from 0 to 1
|
632
|
+
*/
|
496
633
|
double h, l, s, r, g, b;
|
497
634
|
Unpack_RGB(rgb_vec, &r, &g, &b, ierr);
|
498
635
|
if (*ierr != 0) RETURN_NIL;
|
@@ -501,11 +638,12 @@ OBJ_PTR c_rgb_to_hls(OBJ_PTR fmkr, FM *p, OBJ_PTR rgb_vec, int *ierr)
|
|
501
638
|
Array_Store(result, 0, Float_New(h), ierr);
|
502
639
|
Array_Store(result, 1, Float_New(l), ierr);
|
503
640
|
Array_Store(result, 2, Float_New(s), ierr);
|
504
|
-
return result;
|
641
|
+
return result;
|
505
642
|
}
|
506
643
|
|
507
644
|
|
508
|
-
void
|
645
|
+
void
|
646
|
+
c_title_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
|
509
647
|
{
|
510
648
|
double r, g, b;
|
511
649
|
Unpack_RGB(val, &r, &g, &b, ierr);
|
@@ -516,8 +654,11 @@ void c_title_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
|
|
516
654
|
}
|
517
655
|
|
518
656
|
|
519
|
-
OBJ_PTR
|
520
|
-
|
657
|
+
OBJ_PTR
|
658
|
+
c_title_color_get(OBJ_PTR fmkr, FM *p, int *ierr)
|
659
|
+
{
|
660
|
+
// value is array of [r, g, b] intensities from 0 to 1
|
661
|
+
// r g b RG
|
521
662
|
double r, g, b;
|
522
663
|
r = p->title_color_R;
|
523
664
|
g = p->title_color_G;
|
@@ -530,7 +671,8 @@ OBJ_PTR c_title_color_get(OBJ_PTR fmkr, FM *p, int *ierr) // value is array of [
|
|
530
671
|
}
|
531
672
|
|
532
673
|
|
533
|
-
void
|
674
|
+
void
|
675
|
+
c_xlabel_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
|
534
676
|
{
|
535
677
|
double r, g, b;
|
536
678
|
Unpack_RGB(val, &r, &g, &b, ierr);
|
@@ -538,11 +680,14 @@ void c_xlabel_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
|
|
538
680
|
p->xlabel_color_R = r;
|
539
681
|
p->xlabel_color_G = g;
|
540
682
|
p->xlabel_color_B = b;
|
541
|
-
}
|
542
|
-
|
683
|
+
}
|
543
684
|
|
544
|
-
|
545
|
-
|
685
|
+
|
686
|
+
OBJ_PTR
|
687
|
+
c_xlabel_color_get(OBJ_PTR fmkr, FM *p, int *ierr)
|
688
|
+
{
|
689
|
+
// value is array of [r, g, b] intensities from 0 to 1
|
690
|
+
// r g b RG
|
546
691
|
double r, g, b;
|
547
692
|
r = p->xlabel_color_R;
|
548
693
|
g = p->xlabel_color_G;
|
@@ -555,7 +700,8 @@ OBJ_PTR c_xlabel_color_get(OBJ_PTR fmkr, FM *p, int *ierr) // value is array of
|
|
555
700
|
}
|
556
701
|
|
557
702
|
|
558
|
-
void
|
703
|
+
void
|
704
|
+
c_ylabel_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
|
559
705
|
{
|
560
706
|
double r, g, b;
|
561
707
|
Unpack_RGB(val, &r, &g, &b, ierr);
|
@@ -566,8 +712,11 @@ void c_ylabel_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
|
|
566
712
|
}
|
567
713
|
|
568
714
|
|
569
|
-
OBJ_PTR
|
570
|
-
|
715
|
+
OBJ_PTR
|
716
|
+
c_ylabel_color_get(OBJ_PTR fmkr, FM *p, int *ierr)
|
717
|
+
{
|
718
|
+
// value is array of [r, g, b] intensities from 0 to 1
|
719
|
+
// r g b RG
|
571
720
|
double r, g, b;
|
572
721
|
r = p->ylabel_color_R;
|
573
722
|
g = p->ylabel_color_G;
|
@@ -580,7 +729,8 @@ OBJ_PTR c_ylabel_color_get(OBJ_PTR fmkr, FM *p, int *ierr) // value is array of
|
|
580
729
|
}
|
581
730
|
|
582
731
|
|
583
|
-
void
|
732
|
+
void
|
733
|
+
c_xaxis_stroke_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
|
584
734
|
{
|
585
735
|
double r, g, b;
|
586
736
|
Unpack_RGB(val, &r, &g, &b, ierr);
|
@@ -590,8 +740,12 @@ void c_xaxis_stroke_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
|
|
590
740
|
p->xaxis_stroke_color_B = b;
|
591
741
|
}
|
592
742
|
|
593
|
-
|
594
|
-
|
743
|
+
|
744
|
+
OBJ_PTR
|
745
|
+
c_xaxis_stroke_color_get(OBJ_PTR fmkr, FM *p, int *ierr)
|
746
|
+
{
|
747
|
+
// value is array of [r, g, b] intensities from 0 to 1
|
748
|
+
// r g b RG
|
595
749
|
double r, g, b;
|
596
750
|
r = p->xaxis_stroke_color_R;
|
597
751
|
g = p->xaxis_stroke_color_G;
|
@@ -603,7 +757,9 @@ OBJ_PTR c_xaxis_stroke_color_get(OBJ_PTR fmkr, FM *p, int *ierr) // value is arr
|
|
603
757
|
return result;
|
604
758
|
}
|
605
759
|
|
606
|
-
|
760
|
+
|
761
|
+
void
|
762
|
+
c_yaxis_stroke_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
|
607
763
|
{
|
608
764
|
double r, g, b;
|
609
765
|
Unpack_RGB(val, &r, &g, &b, ierr);
|
@@ -614,8 +770,11 @@ void c_yaxis_stroke_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
|
|
614
770
|
}
|
615
771
|
|
616
772
|
|
617
|
-
OBJ_PTR
|
618
|
-
|
773
|
+
OBJ_PTR
|
774
|
+
c_yaxis_stroke_color_get(OBJ_PTR fmkr, FM *p, int *ierr)
|
775
|
+
{
|
776
|
+
// value is array of [r, g, b] intensities from 0 to 1
|
777
|
+
// r g b RG
|
619
778
|
double r, g, b;
|
620
779
|
r = p->yaxis_stroke_color_R;
|
621
780
|
g = p->yaxis_stroke_color_G;
|