1
/* This file is part of the GNU plotutils package. Copyright (C) 1995,
2
1996, 1997, 1998, 1999, 2000, 2005, Free Software Foundation, Inc.
4
The GNU plotutils package is free software. You may redistribute it
5
and/or modify it under the terms of the GNU General Public License as
6
published by the Free Software foundation; either version 2, or (at your
7
option) any later version.
9
The GNU plotutils package is distributed in the hope that it will be
10
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
General Public License for more details.
14
You should have received a copy of the GNU General Public License along
15
with the GNU plotutils package; see the file COPYING. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
17
Boston, MA 02110-1301, USA. */
1
19
/* This file contains device-specific color computation routines. They are
2
20
called by various PSPlotter methods, before drawing objects. They set
3
21
the appropriate PSPlotter-specific fields in the drawing state. */
8
26
/* forward references */
9
static int _idraw_pseudocolor ____P((int red, int green, int blue));
27
static int _idraw_pseudocolor (int red, int green, int blue);
11
29
/* We call this routine to evaluate _plotter->drawstate->ps_fgcolor lazily,
12
30
i.e. only when needed (just before an object is written to the output
14
32
colors", i.e., pen colors. See p_color2.c for the list of colors. */
18
_p_set_pen_color(S___(Plotter *_plotter))
20
_p_set_pen_color(S___(_plotter))
21
S___(Plotter *_plotter;)
35
_pl_p_set_pen_color(S___(Plotter *_plotter))
24
37
_plotter->drawstate->ps_fgcolor_red =
25
38
((double)((_plotter->drawstate->fgcolor).red))/0xFFFF;
67
75
_plotter->drawstate->ps_fillcolor_blue = blue;
69
77
/* next subroutine needs fields that this will fill in... */
70
_p_set_pen_color (S___(_plotter));
78
_pl_p_set_pen_color (S___(_plotter));
72
80
/* Quantize for idraw, in a complicated way; we can choose from among a
73
81
finite discrete set of values for ps_idraw_bgcolor and
75
83
ps_fillcolor_* because the PS interpreter will use the
76
84
ps_idraw_shading variable to interpolate between fgcolor and bgcolor,
77
85
i.e. fgcolor and fillcolor. */
78
_p_compute_idraw_bgcolor (S___(_plotter));
86
_pl_p_compute_idraw_bgcolor (S___(_plotter));
85
93
distance is our metric. Our convention: no non-white color should be
86
94
mapped to white. */
89
96
_idraw_pseudocolor (int red, int green, int blue)
91
_idraw_pseudocolor (red, green, blue)
99
102
difference = DBL_MAX;
100
for (i = 0; i < IDRAW_NUM_STD_COLORS; i++)
103
for (i = 0; i < PS_NUM_IDRAW_STD_COLORS; i++)
102
105
double newdifference;
104
if (_idraw_stdcolors[i].red == 0xffff
105
&& _idraw_stdcolors[i].green == 0xffff
106
&& _idraw_stdcolors[i].blue == 0xffff)
107
if (_pl_p_idraw_stdcolors[i].red == 0xffff
108
&& _pl_p_idraw_stdcolors[i].green == 0xffff
109
&& _pl_p_idraw_stdcolors[i].blue == 0xffff)
107
110
/* white is a possible quantization only for white itself (our
118
newdifference = ((double)(_idraw_stdcolors[i].red - red)
119
* (double)(_idraw_stdcolors[i].red - red))
120
+ ((double)(_idraw_stdcolors[i].green - green)
121
* (double)(_idraw_stdcolors[i].green - green))
122
+ ((double)(_idraw_stdcolors[i].blue - blue)
123
* (double)(_idraw_stdcolors[i].blue - blue));
121
newdifference = ((double)(_pl_p_idraw_stdcolors[i].red - red)
122
* (double)(_pl_p_idraw_stdcolors[i].red - red))
123
+ ((double)(_pl_p_idraw_stdcolors[i].green - green)
124
* (double)(_pl_p_idraw_stdcolors[i].green - green))
125
+ ((double)(_pl_p_idraw_stdcolors[i].blue - blue)
126
* (double)(_pl_p_idraw_stdcolors[i].blue - blue));
125
128
if (newdifference < difference)
147
150
is very close to the user-specified pen color. */
151
_p_compute_idraw_bgcolor(S___(Plotter *_plotter))
153
_p_compute_idraw_bgcolor(S___(_plotter))
154
S___(Plotter *_plotter;)
153
_pl_p_compute_idraw_bgcolor(S___(Plotter *_plotter))
157
155
double truered, truegreen, trueblue;
158
156
double fgred, fggreen, fgblue;
165
163
truegreen = 0xFFFF * _plotter->drawstate->ps_fillcolor_green;
166
164
trueblue = 0xFFFF * _plotter->drawstate->ps_fillcolor_blue;
168
fgred = (double)(_idraw_stdcolors[_plotter->drawstate->ps_idraw_fgcolor].red);
169
fggreen = (double)(_idraw_stdcolors[_plotter->drawstate->ps_idraw_fgcolor].green);
170
fgblue = (double)(_idraw_stdcolors[_plotter->drawstate->ps_idraw_fgcolor].blue);
166
fgred = (double)(_pl_p_idraw_stdcolors[_plotter->drawstate->ps_idraw_fgcolor].red);
167
fggreen = (double)(_pl_p_idraw_stdcolors[_plotter->drawstate->ps_idraw_fgcolor].green);
168
fgblue = (double)(_pl_p_idraw_stdcolors[_plotter->drawstate->ps_idraw_fgcolor].blue);
172
for (i = 0; i < IDRAW_NUM_STD_COLORS; i++)
170
for (i = 0; i < PS_NUM_IDRAW_STD_COLORS; i++)
174
172
double bgred, bggreen, bgblue;
176
bgred = (double)(_idraw_stdcolors[i].red);
177
bggreen = (double)(_idraw_stdcolors[i].green);
178
bgblue = (double)(_idraw_stdcolors[i].blue);
174
bgred = (double)(_pl_p_idraw_stdcolors[i].red);
175
bggreen = (double)(_pl_p_idraw_stdcolors[i].green);
176
bgblue = (double)(_pl_p_idraw_stdcolors[i].blue);
180
for (j = 0; j < IDRAW_NUM_STD_SHADINGS; j++)
178
for (j = 0; j < PS_NUM_IDRAW_STD_SHADINGS; j++)
182
180
double approxred, approxgreen, approxblue;
183
181
double shade, newdifference;
185
shade = _idraw_stdshadings[j];
183
shade = _pl_p_idraw_stdshadings[j];
187
185
approxred = shade * bgred + (1.0 - shade) * fgred;
188
186
approxgreen = shade * bggreen + (1.0 - shade) * fggreen;