~ubuntu-branches/ubuntu/gutsy/plotutils/gutsy

« back to all changes in this revision

Viewing changes to libplot/p_color.c

  • Committer: Bazaar Package Importer
  • Author(s): Floris Bruynooghe
  • Date: 2007-05-10 19:48:54 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070510194854-mrr3lgwzpxd8hovo
Tags: 2.5-2
Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the GNU plotutils package.  Copyright (C) 1995,
 
2
   1996, 1997, 1998, 1999, 2000, 2005, Free Software Foundation, Inc.
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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. */
 
18
 
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. */
6
24
#include "extern.h"
7
25
 
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);
10
28
 
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. */
15
33
 
16
34
void
17
 
#ifdef _HAVE_PROTOS
18
 
_p_set_pen_color(S___(Plotter *_plotter))
19
 
#else
20
 
_p_set_pen_color(S___(_plotter))
21
 
     S___(Plotter *_plotter;)
22
 
#endif
 
35
_pl_p_set_pen_color(S___(Plotter *_plotter))
23
36
{
24
37
  _plotter->drawstate->ps_fgcolor_red = 
25
38
    ((double)((_plotter->drawstate->fgcolor).red))/0xFFFF;
45
58
   from a fixed set.  See p_color2.c. */
46
59
 
47
60
void
48
 
#ifdef _HAVE_PROTOS
49
 
_p_set_fill_color(S___(Plotter *_plotter))
50
 
#else
51
 
_p_set_fill_color(S___(_plotter))
52
 
     S___(Plotter *_plotter;)
53
 
#endif
 
61
_pl_p_set_fill_color(S___(Plotter *_plotter))
54
62
{
55
63
  double red, green, blue;
56
64
 
67
75
  _plotter->drawstate->ps_fillcolor_blue = blue;
68
76
 
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));
71
79
 
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));
79
87
  
80
88
  return;
81
89
}
85
93
   distance is our metric.  Our convention: no non-white color should be
86
94
   mapped to white. */
87
95
static int
88
 
#ifdef _HAVE_PROTOS
89
96
_idraw_pseudocolor (int red, int green, int blue)
90
 
#else
91
 
_idraw_pseudocolor (red, green, blue)
92
 
     int red, green, blue;
93
 
#endif
94
97
{
95
98
  double difference;
96
99
  int i;
97
100
  int best = 0;
98
101
  
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++)
101
104
    {
102
105
      double newdifference;
103
106
      
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
108
111
           convention) */
109
112
        {
115
118
          continue;
116
119
        }
117
120
 
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));
124
127
      
125
128
      if (newdifference < difference)
126
129
        {
147
150
   is very close to the user-specified pen color. */
148
151
 
149
152
void
150
 
#ifdef _HAVE_PROTOS
151
 
_p_compute_idraw_bgcolor(S___(Plotter *_plotter))
152
 
#else
153
 
_p_compute_idraw_bgcolor(S___(_plotter))
154
 
     S___(Plotter *_plotter;)
155
 
#endif
 
153
_pl_p_compute_idraw_bgcolor(S___(Plotter *_plotter))
156
154
{
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;
167
165
 
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);
171
169
 
172
 
  for (i = 0; i < IDRAW_NUM_STD_COLORS; i++)
 
170
  for (i = 0; i < PS_NUM_IDRAW_STD_COLORS; i++)
173
171
    {
174
172
      double bgred, bggreen, bgblue;
175
173
 
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);
179
177
 
180
 
      for (j = 0; j < IDRAW_NUM_STD_SHADINGS; j++)
 
178
      for (j = 0; j < PS_NUM_IDRAW_STD_SHADINGS; j++)
181
179
        {
182
180
          double approxred, approxgreen, approxblue;
183
181
          double shade, newdifference;
184
182
          
185
 
          shade = _idraw_stdshadings[j];
 
183
          shade = _pl_p_idraw_stdshadings[j];
186
184
          
187
185
          approxred = shade * bgred + (1.0 - shade) * fgred;
188
186
          approxgreen = shade * bggreen + (1.0 - shade) * fggreen;