~bkerensa/ubuntu/raring/valgrind/merge-from-deb

« back to all changes in this revision

Viewing changes to massif/hp2ps/Shade.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrés Roldán
  • Date: 2008-06-13 02:31:40 UTC
  • mto: (1.4.1 upstream) (2.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20080613023140-iwk33rz9rhvfkr96
Import upstream version 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.  */
4
 
 
5
 
#include <stdio.h>
6
 
#include <stdlib.h>
7
 
#include <string.h>
8
 
#include "Main.h"
9
 
#include "Defines.h"
10
 
#include "Error.h"
11
 
#include "Utilities.h"
12
 
 
13
 
/* own stuff */
14
 
#include "Shade.h"
15
 
 
16
 
static struct shade {
17
 
        char* ident;
18
 
        floatish shade;
19
 
} *shademap;
20
 
 
21
 
static int shademapmax = 0;
22
 
static int shademapindex = 0;
23
 
 
24
 
/*
25
 
 *      Set the shade to be used for "ident" to "shade".
26
 
 */
27
 
 
28
 
void
29
 
ShadeFor(ident, shade)
30
 
  char* ident; 
31
 
  floatish shade;
32
 
{
33
 
    if (! shademap) {
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));
39
 
    }
40
 
 
41
 
    if (shademapindex < shademapmax) {
42
 
        shademap[ shademapindex ].ident = copystring(ident);
43
 
        shademap[ shademapindex ].shade = shade;
44
 
        shademapindex++;
45
 
    } else {
46
 
        Disaster("shade map overflow");
47
 
    }
48
 
}
49
 
 
50
 
/*
51
 
 *      Get the shade to be used for "ident" if there is one. 
52
 
 *      Otherwise, think of a new one.
53
 
 */
54
 
 
55
 
static floatish ThinkOfAShade PROTO((void));    /* forward */
56
 
 
57
 
floatish
58
 
ShadeOf(ident)
59
 
  char* ident;
60
 
{
61
 
    int i;
62
 
    floatish shade;
63
 
 
64
 
    for (i = 0; i < shademapindex; i++) {
65
 
        if (strcmp(shademap[i].ident, ident) == 0) {    /* got it */
66
 
            return(shademap[i].shade);
67
 
        }
68
 
    }
69
 
 
70
 
    shade = ThinkOfAShade();
71
 
 
72
 
    ShadeFor(ident, shade);
73
 
 
74
 
    return shade; 
75
 
}
76
 
 
77
 
 
78
 
 
79
 
#define N_MONO_SHADES 10 
80
 
 
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
84
 
};
85
 
 
86
 
#define N_COLOUR_SHADES 27
87
 
 
88
 
/* HACK: 0.100505 means 100% red, 50% green, 50% blue */
89
 
 
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,
96
 
    0.100505, 0.050505
97
 
};
98
 
 
99
 
static floatish
100
 
ThinkOfAShade()
101
 
{
102
 
    static int thisshade = -1;
103
 
 
104
 
    thisshade++;
105
 
    return cflag ?
106
 
        c_shades[ thisshade % N_COLOUR_SHADES ] :
107
 
        m_shades[ thisshade % N_MONO_SHADES   ] ;
108
 
}
109
 
 
110
 
static floatish
111
 
extract_colour(floatish shade, intish factor)
112
 
{
113
 
    intish i,j;
114
 
 
115
 
    i = (int)(shade * factor);
116
 
    j = i / 100;
117
 
    return (i - j * 100) / 10.0;
118
 
}
119
 
 
120
 
void
121
 
SetPSColour(shade)
122
 
  floatish shade;
123
 
{
124
 
    if (cflag) {
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));
129
 
    } else {
130
 
        fprintf(psfp, "%f setgray\n", shade);
131
 
    }
132
 
}