Debian Codegraph @

lib/sparse/colorutil.c

raw
1 /*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11 #include "config.h"
12
13 #include <sparse/colorutil.h>
14 #include <sparse/general.h>
15 #include <stdio.h>
16 #include <util/agxbuf.h>
17
18 static int r2i(float r) {
19 /* convert a number in [0,1] to 0 to 255 */
20 return (int)(255 * r + 0.5);
21 }
22
23 void rgb2hex(float r, float g, float b, agxbuf *cstring, const char *opacity) {
24 agxbprint(cstring, "#%02x%02x%02x", r2i(r), r2i(g), r2i(b));
25 // set to semitransparent for multiple sets vis
26 if (opacity && strlen(opacity) >= 2) {
27 agxbput_n(cstring, opacity, 2);
28 }
29 }