tioga 1.7 → 1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,9 +22,11 @@
22
22
  #include "figures.h"
23
23
  #include "pdfs.h"
24
24
 
25
+
25
26
  /* functions */
26
27
 
27
- void Free_Functions()
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
- static void Write_Sampled_Function(Function_Info *fo, int *ierr)
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); return; }
52
+ RAISE_ERROR("Error writing function sample data", ierr);
53
+ return;
54
+ }
49
55
  fprintf(OF, "\nendstream\nendobj\n");
50
56
  }
51
57
 
52
- void Write_Functions(int *ierr)
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
- static int create_function(int hival, int lookup_len, unsigned char *lookup)
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 Free_Stroke_Opacities(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; stroke_opacities = p->next; free(p);
92
+ p = stroke_opacities;
93
+ stroke_opacities = p->next;
94
+ free(p);
81
95
  }
82
96
  }
83
97
 
84
- static int Get_Stroke_Opacity_XGS(double stroke_opacity)
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
- void c_stroke_opacity_set(OBJ_PTR fmkr, FM *p, double stroke_opacity, int *ierr)
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 opacity", ierr); return; }
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
- void Free_Fill_Opacities(void)
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; fill_opacities = p->next; free(p);
136
+ p = fill_opacities;
137
+ fill_opacities = p->next;
138
+ free(p);
114
139
  }
115
140
  }
116
141
 
117
- static int Get_Fill_Opacity_XGS(double fill_opacity)
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
- void c_fill_opacity_set(OBJ_PTR fmkr, FM *p, double fill_opacity, int *ierr)
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 opacity", ierr); return; }
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
- void Write_Stroke_Opacity_Objects(void)
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", p->obj_num, p->stroke_opacity);
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
- void Write_Fill_Opacity_Objects(void)
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", p->obj_num, p->fill_opacity);
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 Free_Shadings()
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
- void Write_Shadings(void)
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
- so->x0, so->y0, so->x1, so->y1);
181
- } else {
182
- fprintf(OF, "\t/ShadingType 3\n\t/Coords [%0.2f %0.2f %0.2f %0.2f %0.2f %0.2f]\n",
183
- so->x0, so->y0, so->r0, so->x1, so->y1, so->r1);
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) fprintf(OF, "\t/Extend [ %s %s ]\n",
186
- (so->extend_start)? "true" : "false", (so->extend_end)? "true" : "false");
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 c_axial_shading(FM *p, double x0, double y0, double x1, double y1,
195
- int hival, int lookup_len, unsigned char *lookup, bool extend_start, bool extend_end)
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 c_private_axial_shading(OBJ_PTR fmkr, FM *p, double x0, double y0, double x1, double y1,
214
- OBJ_PTR colormap, bool extend_start, bool extend_end, int *ierr)
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); return; }
220
- OBJ_PTR hival = Array_Entry(colormap,0,ierr);
221
- OBJ_PTR lookup = Array_Entry(colormap,1,ierr);
222
- int hi_value = Number_to_int(hival,ierr);
223
- int lookup_len = String_Len(lookup,ierr);
224
- unsigned char *lookup_ptr = (unsigned char *)(String_Ptr(lookup,ierr));
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), convert_figure_to_output_y(p,y0),
227
- convert_figure_to_output_x(p,x1), convert_figure_to_output_y(p,y1),
228
- hi_value, lookup_len, lookup_ptr, extend_start, extend_end);
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
- static void c_radial_shading(FM *p, double x0, double y0, double r0, double x1, double y1, double r1,
232
- int hival, int lookup_len, unsigned char *lookup,
233
- double a, double b, double c, double d, double e, double f, bool extend_start, bool extend_end)
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
- a, b, c, d, e, f, so->shade_num);
253
- } else {
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 c_private_radial_shading(OBJ_PTR fmkr, FM *p,
260
- double x0, double y0, double r0,
261
- double x1, double y1, double r1, OBJ_PTR colormap,
262
- double a, double b, double c, double d, bool extend_start, bool extend_end, int *ierr)
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); return; }
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
- hi_value, lookup_len, lookup_ptr,
276
- convert_figure_to_output_dx(p,a), convert_figure_to_output_dy(p,b),
277
- convert_figure_to_output_dx(p,c), convert_figure_to_output_dy(p,d),
278
- convert_figure_to_output_x(p,0.0), convert_figure_to_output_y(p,0.0),
279
- extend_start, extend_end);
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
- static double clr_value(double n1, double n2, double hue) // from plplot plctrl.c
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 (val);
361
+ return val;
295
362
  }
296
363
 
297
- static void convert_hls_to_rgb(double h, double l, double s, double *p_r, double *p_g, double *p_b) // from plplot plctrl.c
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
- static void convert_rgb_to_hls(double r, double g, double b, double *p_h, double *p_l, double *p_s) // from plplot plctrl.c
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
- static double linear_interpolate(int num_pts, double *xs, double *ys, double x)
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
- static OBJ_PTR c_create_colormap(FM *p, bool rgb_flag, int length,
347
- int num_pts, double *ps, double *c1s, double *c2s, double *c3s, int *ierr)
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 at 0.0 and last must be at 1.0", ierr); RETURN_NIL; }
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 increasing from 0 to 1", ierr); RETURN_NIL; }
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
- OBJ_PTR c_private_create_colormap(OBJ_PTR fmkr, FM *p, bool rgb, int length,
381
- OBJ_PTR Ps, OBJ_PTR C1s, OBJ_PTR C2s, OBJ_PTR C3s, int *ierr)
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) return;
491
+ if (*ierr != 0) RETURN_NIL;
396
492
  double *c1_ptr = Vector_Data_for_Read(C1s, &c1_len, ierr);
397
- if (*ierr != 0) return;
493
+ if (*ierr != 0) RETURN_NIL;
398
494
  double *c2_ptr = Vector_Data_for_Read(C2s, &c2_len, ierr);
399
- if (*ierr != 0) return;
495
+ if (*ierr != 0) RETURN_NIL;
400
496
  double *c3_ptr = Vector_Data_for_Read(C3s, &c3_len, ierr);
401
- if (*ierr != 0) return;
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 length (with at least 2 entries)", ierr);
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, c3_ptr, ierr);
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 c_get_color_from_colormap(OBJ_PTR fmkr, FM *p, OBJ_PTR color_map, double x, int *ierr)
410
- { /* x is from 0 to 1. this returns a vector for the RGB color from the given colormap */
411
- unsigned char *buff = (unsigned char *)(String_Ptr(color_map,ierr)), r, g, b, i;
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 (for R G B components)", ierr);
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
- OBJ_PTR c_convert_to_colormap(OBJ_PTR fmkr, FM* p, OBJ_PTR Rs, OBJ_PTR Gs, OBJ_PTR Bs, int *ierr)
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
- /* this creates an arbitrary mapping from positions to colors given as (r,g,b) triples */
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) return;
549
+ if (*ierr != 0) RETURN_NIL;
436
550
  double *g_ptr = Vector_Data_for_Read(Gs, &g_len, ierr);
437
- if (*ierr != 0) return;
551
+ if (*ierr != 0) RETURN_NIL;
438
552
  double *b_ptr = Vector_Data_for_Read(Bs, &b_len, ierr);
439
- if (*ierr != 0) return;
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 same length", ierr);
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
- static void Unpack_HLS(OBJ_PTR hls, double *hp, double *lp, double *sp, int *ierr)
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); return; }
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) { RAISE_ERROR_g("Sorry: invalid lightness (%g) for hls: must be between 0 and 1", l, ierr); return; }
474
- if (s < 0.0 || s > 1.0) { RAISE_ERROR_g("Sorry: invalid saturation (%g) for hls: must be between 0 and 1", s, ierr); return; }
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
- OBJ_PTR c_hls_to_rgb(OBJ_PTR fmkr, FM *p, OBJ_PTR hls_vec, int *ierr)
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
- OBJ_PTR c_rgb_to_hls(OBJ_PTR fmkr, FM *p, OBJ_PTR rgb_vec, int *ierr)
620
+
621
+
622
+ OBJ_PTR
623
+ c_rgb_to_hls(OBJ_PTR fmkr, FM *p, OBJ_PTR rgb_vec, int *ierr)
492
624
  {
493
- /* hue is given as an angle from 0 to 360 around the color wheel.
494
- 0, 60, 120, 180, 240, and 300 are respectively red, yellow, green, cyan, blue, and magenta. */
495
- /* lightness and saturation are given as numbers from 0 to 1 */
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 c_title_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
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 c_title_color_get(OBJ_PTR fmkr, FM *p, int *ierr) // value is array of [r, g, b] intensities from 0 to 1
520
- { // r g b RG
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 c_xlabel_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
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
- OBJ_PTR c_xlabel_color_get(OBJ_PTR fmkr, FM *p, int *ierr) // value is array of [r, g, b] intensities from 0 to 1
545
- { // r g b RG
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 c_ylabel_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
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 c_ylabel_color_get(OBJ_PTR fmkr, FM *p, int *ierr) // value is array of [r, g, b] intensities from 0 to 1
570
- { // r g b RG
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 c_xaxis_stroke_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
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
- OBJ_PTR c_xaxis_stroke_color_get(OBJ_PTR fmkr, FM *p, int *ierr) // value is array of [r, g, b] intensities from 0 to 1
594
- { // r g b RG
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
- void c_yaxis_stroke_color_set(OBJ_PTR fmkr, FM *p, OBJ_PTR val, int *ierr)
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 c_yaxis_stroke_color_get(OBJ_PTR fmkr, FM *p, int *ierr) // value is array of [r, g, b] intensities from 0 to 1
618
- { // r g b RG
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;