File: s_color.c

package info (click to toggle)
plotutils 2.4.1-11
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 11,676 kB
  • ctags: 6,967
  • sloc: ansic: 76,305; sh: 15,172; cpp: 12,403; yacc: 2,604; makefile: 888; lex: 144
file content (69 lines) | stat: -rw-r--r-- 1,760 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "sys-defines.h"
#include "extern.h"

#define NUM_SVG_COLORNAMES 16

const plColorNameInfo _svg_colornames[NUM_SVG_COLORNAMES + 1] =
{
  {"aqua",		0x00, 0xff, 0xff},
  {"black",		0x00, 0x00, 0x00},
  {"blue",		0x00, 0x00, 0xff},
  {"fuchsia",		0xff, 0x00, 0xff},
  {"gray",		0x80, 0x80, 0x80},
  {"green",		0x00, 0x80, 0x00},
  {"lime",		0x00, 0xff, 0x00},
  {"maroon",		0x80, 0x00, 0x00},
  {"navy",		0x00, 0x00, 0x80},
  {"olive",		0x80, 0x80, 0x00},
  {"purple",		0x80, 0x00, 0x80},
  {"red",		0xff, 0x00, 0x00},
  {"silver",		0xc0, 0xc0, 0xc0},
  {"teal",		0x00, 0x80, 0x80},
  {"white",		0xff, 0xff, 0xff},
  {"yellow",		0xff, 0xff, 0x00},
  {NULL,		   0,    0,    0}
};

/* convert a 48-bit libplot color to a string resembling "#ffffff" for SVG;
   may also return a string in our database of SVG's builtin colors */

const char *
#ifdef _HAVE_PROTOS
_libplot_color_to_svg_color (plColor color_48, char charbuf[8])
#else
_libplot_color_to_svg_color (color_48, charbuf)
     plColor color_48;
     char charbuf[8];		/* passed storage */
#endif
{
  plColor color_24;
  int i;
  bool found = false;
  const char *svg_color;
  
  color_24.red = ((unsigned int)color_48.red) >> 8;
  color_24.green = ((unsigned int)color_48.green) >> 8;
  color_24.blue = ((unsigned int)color_48.blue) >> 8;
  
  for (i = 0; i < NUM_SVG_COLORNAMES; i++)
    {
      if (color_24.red == _svg_colornames[i].red
	  && color_24.green == _svg_colornames[i].green
	  && color_24.blue == _svg_colornames[i].blue)
	{
	  found = true;
	  break;
	}
    }

  if (found)
    svg_color = _svg_colornames[i].name;
  else
    {
      sprintf (charbuf, "#%02x%02x%02x", 
	       color_24.red, color_24.green, color_24.blue);
      svg_color = charbuf;
    }
  
  return svg_color;
}