Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
colorutil.c
Go to the documentation of this file.
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 <sparse/colorutil.h>
12#include <sparse/general.h>
13#include <stdio.h>
14#include <util/agxbuf.h>
15
16static int r2i(float r) {
17 /* convert a number in [0,1] to 0 to 255 */
18 return (int)(255 * r + 0.5);
19}
20
21void rgb2hex(float r, float g, float b, agxbuf *cstring, const char *opacity) {
22 agxbprint(cstring, "#%02x%02x%02x", r2i(r), r2i(g), r2i(b));
23 // set to semitransparent for multiple sets vis
24 if (opacity && strlen(opacity) >= 2) {
25 agxbput_n(cstring, opacity, 2);
26 }
27}
static size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz)
append string s of length ssz into xb
Definition agxbuf.h:250
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
Definition agxbuf.h:234
static int r2i(float r)
Definition colorutil.c:16
void rgb2hex(float r, float g, float b, agxbuf *cstring, const char *opacity)
Definition colorutil.c:21