From: Emden R. Gansner Date: Sun, 2 Mar 2014 23:44:39 +0000 (-0500) Subject: Further processing of Yifan's edge painting code: add copyright notice X-Git-Tag: 2.38.0~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a1fce6ff1b05c2c917875a1313b9c682f0d81a4e;p=graphviz Further processing of Yifan's edge painting code: add copyright notice to new source files and #ifndefs to .h files; update gvmap to use color_schemes; pull valid color scheme name test from main programs and make a function in the color_palette library. --- diff --git a/cmd/edgepaint/edgepaintmain.c b/cmd/edgepaint/edgepaintmain.c index d6b28f88f..bf082e759 100644 --- a/cmd/edgepaint/edgepaintmain.c +++ b/cmd/edgepaint/edgepaintmain.c @@ -120,8 +120,6 @@ static void init(int argc, char *argv[], real *angle, real *accuracy, char **inf unsigned int c; char* cmd = argv[0]; - int cs_len = 10000; - int r, g, b; outfile = NULL; Verbose = FALSE; @@ -130,8 +128,7 @@ static void init(int argc, char *argv[], real *angle, real *accuracy, char **inf *infile = NULL; *check_edges_with_same_endpoint = 0; *seed = 123; - if (!(*color_scheme)) *color_scheme = malloc(sizeof(char)*cs_len); - strcpy(*color_scheme, "lab"); + *color_scheme = "lab"; *lightness = NULL; while ((c = getopt(argc, argv, ":vc:a:s:r:l:o")) != -1) { @@ -167,14 +164,11 @@ static void init(int argc, char *argv[], real *angle, real *accuracy, char **inf break; case 'c': if (strncmp(optarg,"olor_scheme=", 12) == 0){ - if (strcmp(optarg + 12,"rgb") != 0 && strcmp(optarg + 12,"lab") != 0 && strcmp(optarg + 12,"gray") != 0 && - (!color_palettes_Q(optarg + 12)) && - sscanf(optarg + 12,"#%02X%02X%02X", &r, &g, &b) != 3){ + if (knownColorScheme(optarg + 12)) + *color_scheme = optarg+12; + else { fprintf(stderr,"-color_scheme option must be a valid string\n"); usage(cmd, 1); - } else { - if (strlen(*color_scheme) < strlen(optarg + 12)) *color_scheme = realloc(*color_scheme, sizeof(char)*(strlen(optarg + 12) + 1)); - strcpy(*color_scheme, optarg + 12); } } else { usage(cmd, 1); @@ -251,10 +245,10 @@ int main(int argc, char *argv[]) int check_edges_with_same_endpoint, seed; char *color_scheme = NULL; char *lightness = NULL; - Agraph_t *g; - Agraph_t *prev = NULL; - ingraph_state ig; - int rv = 0; + Agraph_t *g; + Agraph_t *prev = NULL; + ingraph_state ig; + int rv = 0; init(argc, argv, &angle, &accuracy, &infile, &check_edges_with_same_endpoint, &seed, &color_scheme, &lightness); newIngraph(&ig, Files, gread); diff --git a/cmd/gvmap/Makefile.am b/cmd/gvmap/Makefile.am index e18b18a5c..ab6c81d47 100644 --- a/cmd/gvmap/Makefile.am +++ b/cmd/gvmap/Makefile.am @@ -11,6 +11,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/lib/neatogen \ -I$(top_srcdir)/lib/sfdpgen \ -I$(top_srcdir)/lib/sparse \ + -I$(top_srcdir)/lib/edgepaint \ -I$(top_srcdir)/lib/cgraph \ -I$(top_srcdir)/lib/ingraphs \ -I$(top_srcdir)/lib/cdt @@ -31,6 +32,7 @@ gvmap_CPPFLAGS = $(AM_CPPFLAGS) cluster_CPPFLAGS = $(AM_CPPFLAGS) -g gvmap_LDADD = \ + $(top_builddir)/lib/edgepaint/libedgepaint_C.la \ $(top_builddir)/lib/sfdpgen/libsfdpgen_C.la \ $(top_builddir)/lib/neatogen/libneatogen_C.la \ $(top_builddir)/lib/sparse/libsparse_C.la \ @@ -41,6 +43,7 @@ gvmap_LDADD = \ $(GTS_LIBS) -lm cluster_LDADD = \ + $(top_builddir)/lib/edgepaint/libedgepaint_C.la \ $(top_builddir)/lib/sfdpgen/libsfdpgen_C.la \ $(top_builddir)/lib/neatogen/libneatogen_C.la \ $(top_builddir)/lib/sparse/libsparse_C.la \ diff --git a/cmd/gvmap/gvmap.c b/cmd/gvmap/gvmap.c index 9025a0755..40b02a798 100644 --- a/cmd/gvmap/gvmap.c +++ b/cmd/gvmap/gvmap.c @@ -36,6 +36,8 @@ #include "ingraphs.h" #include "DotIO.h" #include "colorutil.h" +#include "color_palette.h" + #ifdef WIN32 #define strdup(x) _strdup(x) #endif @@ -109,6 +111,7 @@ typedef struct { int plotedges; int color_scheme; real line_width; + char *color_scheme_str; char *opacity; char *plot_label; real *bg_color; @@ -275,6 +278,7 @@ init(int argc, char **argv, params_t* pm) pm->outfile = NULL; pm->opacity = NULL; + pm->color_scheme_str = NULL; pm->nrandom = -1; pm->dim = 2; pm->shore_depth_tol = 0; @@ -385,8 +389,12 @@ init(int argc, char **argv, params_t* pm) pm->opacity = strdup(stmp); } else if ((sscanf(optarg,"%d",&r) > 0) && r >= COLOR_SCHEME_NONE && r <= COLOR_SCHEME_GREY){ pm->color_scheme = r; + } else if (knownColorScheme(optarg)) { + pm->color_scheme = COLOR_SCHEME_NONE; + pm->color_scheme_str = optarg; } else { - usage(cmd,1); + fprintf(stderr,"-c option %s is invalid, must be a valid integer or string\n", optarg); + usage(cmd, 1); } break; case 'd': @@ -560,6 +568,10 @@ makeMap (SparseMatrix graph, int n, real* x, real* width, int* grouping, /* compute a good color permutation */ if (pm->color_optimize && country_graph && rgb_r && rgb_g && rgb_b) map_optimal_coloring(pm->seed, country_graph, rgb_r, rgb_g, rgb_b); + else if (pm->color_scheme_str){ + map_palette_optimal_coloring(pm->color_scheme_str, "0,100", country_graph, 0.01, -10, + &rgb_r, &rgb_g, &rgb_b); + } #ifdef TIME fprintf(stderr, "map making time = %f\n",((real) (clock() - cpu)) / CLOCKS_PER_SEC); diff --git a/cmd/gvmap/make_map.c b/cmd/gvmap/make_map.c index b9d7bcb0f..59adbb621 100644 --- a/cmd/gvmap/make_map.c +++ b/cmd/gvmap/make_map.c @@ -32,6 +32,67 @@ #endif /* not SINGLE */ /* #include "triangle.h" */ +#include "lab.h" +#include "node_distinct_coloring.h" + +void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMatrix A0, real accuracy, int seed, + float **rgb_r, float **rgb_g, float **rgb_b){ + /* + for a graph A, get a distinctive color of its nodes so that the color distanmce among all nodes are maximized. Here + color distance on a node is defined as the minimum of color differences between a node and its neighbors. + accuracy is the threshold given so that when finding the coloring for each node, the optimal is + with in "accuracy" of the true global optimal. + color_scheme: rgb, gray, lab, or one of the color palettes in color_palettes.h, or a list of hex rgb colors separaterd by comma like "#ff0000,#00ff00" + lightness: of the form 0,70, specifying the range of lightness of LAB color. Ignored if scheme is not COLOR_LAB. + . if NULL, 0,70 is assumed + A: the graph of n nodes + accuracy: how accurate to find the optimal + cdim: dimension of the color space + seed: random_seed. If negative, consider -seed as the number of random start iterations + rgb_r, rgb_g, rgb_b: float array of length A->m + 1, which contains color for each country. 1-based + */ + + /*color: On input an array of size n*cdim, if NULL, will be allocated. On exit the final color assignment for node i is [cdim*i,cdim*(i+1)), in RGB (between 0 to 1) + color_diff: the minuimum color difference across all edges + color_diff_sum: the sum of min color dfference across all nodes + */ + real *colors = NULL, color_diff, color_diff_sum; + int flag; + int n = A0->m, i, cdim; + + SparseMatrix A, B; + int weightedQ = TRUE; + int iter_max = 100; + + {real *dist = NULL; + A = SparseMatrix_symmetrize(A0, FALSE); + SparseMatrix_distance_matrix(A, 0, &dist); + SparseMatrix_delete(A); + A = SparseMatrix_from_dense(n, n, dist); + FREE(dist); + A = SparseMatrix_remove_diagonal(A); + SparseMatrix_export(stdout, A); + } + + // A = SparseMatrix_multiply(A0, A0); + node_distinct_coloring(color_scheme, lightness, weightedQ, A, accuracy, iter_max, seed, &cdim, &colors, &color_diff, &color_diff_sum, &flag); + + if (A != A0){ + SparseMatrix_delete(A); + } + *rgb_r = MALLOC(sizeof(float)*(n+1)); + *rgb_g = MALLOC(sizeof(float)*(n+1)); + *rgb_b = MALLOC(sizeof(float)*(n+1)); + + for (i = 0; i < n; i++){ + (*rgb_r)[i+1] = (float) colors[cdim*i]; + (*rgb_g)[i+1] = (float) colors[cdim*i + 1]; + (*rgb_b)[i+1] = (float) colors[cdim*i + 2]; + } + FREE(colors); + +} + void map_optimal_coloring(int seed, SparseMatrix A, float *rgb_r, float *rgb_g, float *rgb_b){ int *p = NULL; float *u = NULL; diff --git a/cmd/gvmap/make_map.h b/cmd/gvmap/make_map.h index 84223b478..15d5d5ec8 100644 --- a/cmd/gvmap/make_map.h +++ b/cmd/gvmap/make_map.h @@ -48,6 +48,7 @@ void plot_processing_map(Agraph_t* gr, int n, int dim, real *x, SparseMatrix pol #endif void map_optimal_coloring(int seed, SparseMatrix A, float *rgb_r, float *rgb_g, float *rgb_b); +void map_palette_optimal_coloring(char *color_scheme, char *lightness, SparseMatrix A, real accuracy, int seed, float **rgb_r, float **rgb_g, float **rgb_b); enum {POLY_LINE_REAL_EDGE, POLY_LINE_NOT_REAL_EDGE}; enum {OUT_PS = 1, OUT_M = 0, OUT_M_COUNTRY_GRAPH = 2, OUT_DOT = 3, OUT_PROCESSING = 4}; diff --git a/lib/edgepaint/edge_distinct_coloring.c b/lib/edgepaint/edge_distinct_coloring.c index dd520c7de..41a5c002e 100644 --- a/lib/edgepaint/edge_distinct_coloring.c +++ b/lib/edgepaint/edge_distinct_coloring.c @@ -1,3 +1,12 @@ +/************************************************************************* + * Copyright (c) 2011 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ #include "general.h" #include "time.h" #include "SparseMatrix.h" diff --git a/lib/edgepaint/edge_distinct_coloring.h b/lib/edgepaint/edge_distinct_coloring.h index f819e0335..a059f7f9c 100644 --- a/lib/edgepaint/edge_distinct_coloring.h +++ b/lib/edgepaint/edge_distinct_coloring.h @@ -1 +1,16 @@ +/************************************************************************* + * Copyright (c) 2014 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ + +#ifndef EDGE_DISTINCT_COLORING_H +#define EDGE_DISTINCT_COLORING_H + Agraph_t* edge_distinct_coloring(char *color_scheme, char *lightness, Agraph_t* g, real angle, real accuracy, real check_edges_with_same_endpoint, int seed); + +#endif diff --git a/lib/edgepaint/furtherest_point.c b/lib/edgepaint/furtherest_point.c index 05cf55c8d..77d0336b2 100644 --- a/lib/edgepaint/furtherest_point.c +++ b/lib/edgepaint/furtherest_point.c @@ -1,3 +1,12 @@ +/************************************************************************* + * Copyright (c) 2011 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ #include "general.h" #include "QuadTree.h" #include "furtherest_point.h" diff --git a/lib/edgepaint/furtherest_point.h b/lib/edgepaint/furtherest_point.h index c09d100a5..c12a2da6b 100644 --- a/lib/edgepaint/furtherest_point.h +++ b/lib/edgepaint/furtherest_point.h @@ -1,3 +1,18 @@ +/************************************************************************* + * Copyright (c) 2014 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ + +#ifndef FURTHEREST_POINT_H +#define FURTHEREST_POINT_H + void furtherest_point(int k, int dim, real *wgt, real *pts, real *center, real width, int max_level, real (*usr_dist)(int, real*, real*), real *dist_max, real **argmax); void furtherest_point_in_list(int k, int dim, real *wgt, real *pts, QuadTree qt, int max_level, real (*usr_dist)(int, real*, real*), real *dist_max, real **argmax); + +#endif diff --git a/lib/edgepaint/intersection.c b/lib/edgepaint/intersection.c index 6659537e9..e7063d098 100644 --- a/lib/edgepaint/intersection.c +++ b/lib/edgepaint/intersection.c @@ -1,3 +1,12 @@ +/************************************************************************* + * Copyright (c) 2011 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ #include "general.h" static real cross(real *u, real *v){ diff --git a/lib/edgepaint/intersection.h b/lib/edgepaint/intersection.h index c2e5f2ac5..30f6b64d1 100644 --- a/lib/edgepaint/intersection.h +++ b/lib/edgepaint/intersection.h @@ -1 +1,16 @@ +/************************************************************************* + * Copyright (c) 2014 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ + +#ifndef INTERSECTION_H +#define INTERSECTION_H + real intersection_angle(real *p1, real *p2, real *q1, real *q2); + +#endif diff --git a/lib/edgepaint/lab.c b/lib/edgepaint/lab.c index 13fecb2ee..d1fc4e7b1 100644 --- a/lib/edgepaint/lab.c +++ b/lib/edgepaint/lab.c @@ -1,3 +1,12 @@ +/************************************************************************* + * Copyright (c) 2011 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ #include "general.h" #include "QuadTree.h" #include "lab.h" diff --git a/lib/edgepaint/lab.h b/lib/edgepaint/lab.h index 713424b25..c5fd60ab8 100644 --- a/lib/edgepaint/lab.h +++ b/lib/edgepaint/lab.h @@ -1,3 +1,12 @@ +/************************************************************************* + * Copyright (c) 2014 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ #ifndef LAB_H #define LAB_H diff --git a/lib/edgepaint/lab_gamut.h b/lib/edgepaint/lab_gamut.h index f97e62a31..2a30bec09 100644 --- a/lib/edgepaint/lab_gamut.h +++ b/lib/edgepaint/lab_gamut.h @@ -1,3 +1,16 @@ +/************************************************************************* + * Copyright (c) 2014 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ + +#ifndef LAB_GAMUT_H +#define LAB_GAMUT_H + static color_lab lab_gamut_data[] = {{0,0,0}, {1,-2,1}, {1,-1,-1}, @@ -826814,3 +826827,5 @@ static color_lab lab_gamut_data[] = {{0,0,0}, {99,1,1}, {99,2,-1}, {100,0,0}}; + +#endif diff --git a/lib/edgepaint/node_distinct_coloring.c b/lib/edgepaint/node_distinct_coloring.c index 829a536a7..399553861 100644 --- a/lib/edgepaint/node_distinct_coloring.c +++ b/lib/edgepaint/node_distinct_coloring.c @@ -1,3 +1,12 @@ +/************************************************************************* + * Copyright (c) 2011 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ #include "general.h" #include "SparseMatrix.h" #include "QuadTree.h" diff --git a/lib/edgepaint/node_distinct_coloring.h b/lib/edgepaint/node_distinct_coloring.h index 625bf7ffe..c560b1107 100644 --- a/lib/edgepaint/node_distinct_coloring.h +++ b/lib/edgepaint/node_distinct_coloring.h @@ -1,3 +1,18 @@ +/************************************************************************* + * Copyright (c) 2014 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ + +#ifndef NODE_DISTINCT_COLORING_H +#define NODE_DISTINCT_COLORING_H + enum {COLOR_RGB, COLOR_GRAY, COLOR_LAB}; enum {ERROR_BAD_LAB_GAMUT_FILE = -10, ERROR_BAD_COLOR_SCHEME = -9}; void node_distinct_coloring(char *color_scheme, char *lightness, int weightedQ, SparseMatrix A, real accuracy, int iter_max, int seed, int *cdim, real **colors, real *color_diff, real *color_diff_sum, int *flag); + +#endif diff --git a/lib/sfdpgen/spring_electrical.c b/lib/sfdpgen/spring_electrical.c index b55779d62..29485cd63 100644 --- a/lib/sfdpgen/spring_electrical.c +++ b/lib/sfdpgen/spring_electrical.c @@ -234,8 +234,9 @@ void export_embedding(FILE *fp, int dim, SparseMatrix A, real *x, real *width){ if (width && dim == 2){ for (i = 0; i < A->m; i++){ if (i >= 0) fprintf(fp,","); - fprintf(fp,"(*%f,%f*){GrayLevel[.5,.5],Rectangle[{%f,%f},{%f,%f}]}", width[i*dim], width[i*dim+1],x[i*dim] - width[i*dim] + 5, x[i*dim+1] - width[i*dim+1] + 5, - x[i*dim] + width[i*dim] - 5, x[i*dim+1] + width[i*dim+1] - 5); + fprintf(fp,"(*width={%f,%f}, x = {%f,%f}*){GrayLevel[.5,.5],Rectangle[{%f,%f},{%f,%f}]}", width[i*dim], width[i*dim+1], x[i*dim], x[i*dim + 1], + x[i*dim] - width[i*dim], x[i*dim+1] - width[i*dim+1], + x[i*dim] + width[i*dim], x[i*dim+1] + width[i*dim+1]); } } @@ -479,7 +480,7 @@ void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrica int max_qtree_level = ctrl->max_qtree_level; oned_optimizer qtree_level_optimizer = NULL; - if (!A) return; + if (!A || maxiter <= 0) return; m = A->m, n = A->n; if (n <= 0 || dim <= 0) return; @@ -682,7 +683,7 @@ void spring_electrical_embedding_slow(int dim, SparseMatrix A0, spring_electrica oned_optimizer qtree_level_optimizer = NULL; fprintf(stderr,"spring_electrical_embedding_slow"); - if (!A) return; + if (!A || maxiter <= 0) return; m = A->m, n = A->n; if (n <= 0 || dim <= 0) return; @@ -941,7 +942,7 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con int max_qtree_level = ctrl->max_qtree_level; oned_optimizer qtree_level_optimizer = NULL; - if (!A) return; + if (!A || maxiter <= 0) return; m = A->m, n = A->n; if (n <= 0 || dim <= 0) return; @@ -1267,7 +1268,7 @@ void spring_maxent_embedding(int dim, SparseMatrix A0, SparseMatrix D, spring_el double stress = 0; #endif - if (!A) return; + if (!A || maxiter <= 0) return; m = A->m, n = A->n; if (n <= 0 || dim <= 0) return; @@ -1525,7 +1526,7 @@ void spring_electrical_spring_embedding(int dim, SparseMatrix A0, SparseMatrix D real *center = NULL, *supernode_wgts = NULL, *distances = NULL, nsuper_avg, counts = 0; int max_qtree_level = 10; - if (!A) return; + if (!A || maxiter <= 0) return; m = A->m, n = A->n; if (n <= 0 || dim <= 0) return; @@ -2191,12 +2192,14 @@ static void multilevel_spring_electrical_embedding_core(int dim, SparseMatrix A0 post_process_smoothing(dim, A, ctrl, node_weights, x, flag); + if (Verbose) fprintf(stderr, "ctrl->overlap=%d\n",ctrl->overlap); + + /* rotation has to be done before overlap removal, since rotation could induce overlaps */ if (dim == 2){ pcp_rotate(n, dim, x); } if (ctrl->rotation != 0) rotate(n, dim, x, ctrl->rotation); - if (Verbose) fprintf(stderr, "ctrl->overlap=%d\n",ctrl->overlap); remove_overlap(dim, A, x, label_sizes, ctrl->overlap, ctrl->initial_scaling, ctrl->edge_labeling_scheme, n_edge_label_nodes, edge_label_nodes, A, ctrl->do_shrinking, flag); diff --git a/lib/sparse/color_palette.c b/lib/sparse/color_palette.c index 4b57a97e4..b04c6ead6 100644 --- a/lib/sparse/color_palette.c +++ b/lib/sparse/color_palette.c @@ -1,5 +1,28 @@ + +/************************************************************************* + * Copyright (c) 2013 AT&T Intellectual Property + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: See CVS logs. Details at http://www.graphviz.org/ + *************************************************************************/ + #include "color_palette.h" #include "string.h" +#include "macros.h" + +int knownColorScheme (char* name) +{ + int r, g, b; + + return streq(name,"rgb") + || streq(name,"lab") + || streq(name,"gray") + || color_palettes_Q(name) + || (sscanf(name,"#%02X%02X%02X", &r, &g, &b) == 3); +} char *color_palettes_get(char *color_palette_name){ int i; diff --git a/lib/sparse/color_palette.h b/lib/sparse/color_palette.h index 044805a80..991497811 100644 --- a/lib/sparse/color_palette.h +++ b/lib/sparse/color_palette.h @@ -17,10 +17,12 @@ enum {MAX_COLOR = 1001}; enum {npalettes = 265}; +extern int knownColorScheme (char*); extern char *color_palettes[npalettes][2]; -char *color_palettes_get(char *color_palette_name);/* return a list of rgb in hex form: "#ff0000,#00ff00,..." */ -void color_palettes_name_print(FILE *fp); -int color_palettes_Q(char *color_palette_name); + /* return a list of rgb in hex form: "#ff0000,#00ff00,..." */ +extern char *color_palettes_get(char *color_palette_name); +extern void color_palettes_name_print(FILE *fp); +extern int color_palettes_Q(char *color_palette_name); extern float palette_pastel[1001][3]; extern float palette_blue_to_yellow[1001][3];