1
/* This file is part of hp2ps, a graph drawer for memory profiles.
2
Copyright (C) 2002 The University Court of the University of Glasgow.
3
This program is governed by the license contained in the file LICENSE. */
11
#include "Utilities.h"
21
static int shademapmax = 0;
22
static int shademapindex = 0;
25
* Set the shade to be used for "ident" to "shade".
29
ShadeFor(ident, shade)
34
shademapmax = (nidents > TWENTY ? nidents : TWENTY) * 2;
35
/* Assume nidents read is indication of the No of
36
idents in the .aux file (*2 for good luck) */
37
/* NB *2 is needed as .aux and .hp elements may differ */
38
shademap = xmalloc(shademapmax * sizeof(struct shade));
41
if (shademapindex < shademapmax) {
42
shademap[ shademapindex ].ident = copystring(ident);
43
shademap[ shademapindex ].shade = shade;
46
Disaster("shade map overflow");
51
* Get the shade to be used for "ident" if there is one.
52
* Otherwise, think of a new one.
55
static floatish ThinkOfAShade PROTO((void)); /* forward */
64
for (i = 0; i < shademapindex; i++) {
65
if (strcmp(shademap[i].ident, ident) == 0) { /* got it */
66
return(shademap[i].shade);
70
shade = ThinkOfAShade();
72
ShadeFor(ident, shade);
79
#define N_MONO_SHADES 10
81
static floatish m_shades[ N_MONO_SHADES ] = {
82
0.00000, 0.20000, 0.60000, 0.30000, 0.90000,
83
0.40000, 1.00000, 0.70000, 0.50000, 0.80000
86
#define N_COLOUR_SHADES 27
88
/* HACK: 0.100505 means 100% red, 50% green, 50% blue */
90
static floatish c_shades[ N_COLOUR_SHADES ] = {
91
0.000000, 0.000010, 0.001000, 0.001010, 0.100000,
92
0.100010, 0.101000, 0.101010, 0.000005, 0.000500,
93
0.000510, 0.001005, 0.050000, 0.050010, 0.051000,
94
0.051010, 0.100005, 0.100500, 0.100510, 0.101005,
95
0.000505, 0.050005, 0.050500, 0.050510, 0.051005,
102
static int thisshade = -1;
106
c_shades[ thisshade % N_COLOUR_SHADES ] :
107
m_shades[ thisshade % N_MONO_SHADES ] ;
111
extract_colour(floatish shade, intish factor)
115
i = (int)(shade * factor);
117
return (i - j * 100) / 10.0;
125
fprintf(psfp, "%f %f %f setrgbcolor\n",
126
extract_colour(shade, (intish)100),
127
extract_colour(shade, (intish)10000),
128
extract_colour(shade, (intish)1000000));
130
fprintf(psfp, "%f setgray\n", shade);