From 85cabe61e1277c7fed4e70a8cbe03ae0d0096497 Mon Sep 17 00:00:00 2001 From: ellson Date: Sun, 28 Sep 2008 13:11:44 +0000 Subject: [PATCH] break out code for color value handling --- lib/inkpot/Makefile.old | 11 +- lib/inkpot/inkpot_define.h | 50 ++++ lib/inkpot/inkpot_name_table.h | 63 +++++ lib/inkpot/inkpot_scheme.c | 229 ++++++------------ .../{inkpot_structs.h => inkpot_struct.h} | 32 --- lib/inkpot/inkpot_tables.h | 115 --------- lib/inkpot/inkpot_value.c | 98 ++++++++ lib/inkpot/inkpot_value.h | 67 +++++ lib/inkpot/inkpot_value_table.h | 37 +++ 9 files changed, 402 insertions(+), 300 deletions(-) create mode 100644 lib/inkpot/inkpot_define.h create mode 100644 lib/inkpot/inkpot_name_table.h rename lib/inkpot/{inkpot_structs.h => inkpot_struct.h} (78%) delete mode 100644 lib/inkpot/inkpot_tables.h create mode 100644 lib/inkpot/inkpot_value.c create mode 100644 lib/inkpot/inkpot_value.h create mode 100644 lib/inkpot/inkpot_value_table.h diff --git a/lib/inkpot/Makefile.old b/lib/inkpot/Makefile.old index ab37a25d7..715d5fa21 100644 --- a/lib/inkpot/Makefile.old +++ b/lib/inkpot/Makefile.old @@ -1,10 +1,15 @@ CFLAGS = -Wall -g -O0 -test: inkpot_scheme.o inkpot_xlate.o test.o +test: inkpot_scheme.o inkpot_value.o inkpot_xlate.o test.o -inkpot_scheme.o: inkpot_scheme.c inkpot.h inkpot_structs.h inkpot_tables.h +inkpot_scheme.o: inkpot_scheme.c inkpot.h \ + inkpot_define.h inkpot_value.h inkpot_struct.h \ + inkpot_name_table.h inkpot_value_table.h \ + inkpot_xlate.h -inkpot_xlate.o: inkpot_xlate.c inkpot.h +inkpot_xlate.o: inkpot_xlate.c inkpot.h inkpot_xlate.h + +inkpot_value.o: inkpot_value.c inkpot.h inkpot_value.h inkpot_value_table.h test.o: test.c inkpot.h diff --git a/lib/inkpot/inkpot_define.h b/lib/inkpot/inkpot_define.h new file mode 100644 index 000000000..a8de6a725 --- /dev/null +++ b/lib/inkpot/inkpot_define.h @@ -0,0 +1,50 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/*********************************************************** + * This software is part of the graphviz package * + * http://www.graphviz.org/ * + * * + * Copyright (c) 1994-2008 AT&T Corp. * + * and is licensed under the * + * Common Public License, Version 1.0 * + * by AT&T Corp. * + * * + * Information and Software Systems Research * + * AT&T Research, Florham Park NJ * + **********************************************************/ + +typedef unsigned int IDX_STRINGS; +typedef unsigned short MSK_SCHEMES_NAME; +typedef unsigned char IDX_SCHEMES_NAME; +typedef unsigned char IDX_SCHEMES_INDEX; +typedef unsigned int IDX_NAMES; +typedef unsigned char IDX_NAME_ALTS; + +typedef unsigned int IDX_MRU_CACHE; +#define SZT_MRU_CACHE 4 + +#define SZT_SCHEMES_INDEX 2 + +#define SZL_STRINGS 6 + +#define SZT_STRINGS 79 +#define SZT_SCHEMES_NAME 3 +#define SZT_NAMES 11 +#define SZT_NAME_ALTS 2 + + +/* for values */ + +typedef unsigned int IDX_VALUES; +typedef unsigned int IDX_IXVALUES; +typedef unsigned long VALUE; +#define SZB_RED 16 +#define MSK_RED 65535 +#define MAX_RED 65535 + +#define SZT_VALUES 7 +#define SZT_NONAME_VALUES 4 +#define SZT_IXVALUES 7 + + diff --git a/lib/inkpot/inkpot_name_table.h b/lib/inkpot/inkpot_name_table.h new file mode 100644 index 000000000..319a04151 --- /dev/null +++ b/lib/inkpot/inkpot_name_table.h @@ -0,0 +1,63 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/*********************************************************** + * This software is part of the graphviz package * + * http://www.graphviz.org/ * + * * + * Copyright (c) 1994-2008 AT&T Corp. * + * and is licensed under the * + * Common Public License, Version 1.0 * + * by AT&T Corp. * + * * + * Information and Software Systems Research * + * AT&T Research, Florham Park NJ * + **********************************************************/ + +const char TAB_STRINGS[SZT_STRINGS] = { + "french\0" + "svg\0" + "x11\0" + "black\0" + "bleu\0" + "blue\0" + "green\0" + "jaune\0" + "red\0" + "rouge\0" + "vert\0" + "yellow\0" + "white\0" + "xxx\0" + "yyy\0" +}; + +inkpot_scheme_name_t TAB_SCHEMES_NAME[SZT_SCHEMES_NAME] = { /* schemes of named colors */ + { 0, }, /* french */ + { 7, }, /* svg */ + { 11, }, /* x11 */ +}; + +inkpot_scheme_index_t TAB_SCHEMES_INDEX[SZT_SCHEMES_INDEX] = { /* schemes of indexed colors */ + { 71, 0, }, /* xxx */ + { 75, 5, }, /* yyy */ +}; + +inkpot_name_t TAB_NAMES[SZT_NAMES] = { /* Must be LC_ALL=C sort'ed by name with each alt */ + { 15, 0, 0x6, /* black */ 0, /* black */ }, /* 0 */ + { 21, 1, 0x1, /* bleu */ 1, /* bleu, blue */ }, /* 1 */ + { 26, 1, 0x6, /* blue */ 2, }, /* 2 */ + { 31, 2, 0x6, /* green */ 3, /* green, vert */ }, /* 3 */ + { 37, 5, 0x1, /* jaune */ 7, }, /* 4 */ + { 43, 3, 0x6, /* red */ 5, /* red, rouge */ }, /* 5 */ + { 47, 3, 0x1, /* rouge */ 6, }, /* 6 */ + { 53, 2, 0x1, /* vert */ 10, /* yellow(alt1) */ }, /* 7 */ + { 65, 6, 0x6, /* white */ 4, /* jaune, yellow */ }, /* 8 */ + { 58, 5, 0x4, /* yellow */ 9, }, /* 9 */ +/* alt1 */ + { 58, 4, 0x2, /* yellow */ 8, /* white */ }, /* 10 */ +}; + +IDX_NAMES TAB_NAME_ALTS[SZT_NAME_ALTS] = { + 0, 10, +}; diff --git a/lib/inkpot/inkpot_scheme.c b/lib/inkpot/inkpot_scheme.c index 16b62f7c1..e22afab5f 100644 --- a/lib/inkpot/inkpot_scheme.c +++ b/lib/inkpot/inkpot_scheme.c @@ -21,7 +21,10 @@ #include #include "inkpot.h" -#include "inkpot_tables.h" +#include "inkpot_define.h" +#include "inkpot_value.h" +#include "inkpot_struct.h" +#include "inkpot_name_table.h" #include "inkpot_xlate.h" static size_t inkpot_writer (void *closure, const char *data, size_t length) @@ -374,64 +377,6 @@ static inkpot_status_t inkpot_set_index ( inkpot_t *inkpot, int index ) return inkpot_set_value_idx(inkpot, value_idx); } -#if 0 -static int inkpot_value_cmpf ( const void *key, const void *base) -{ - VALUE value_key = *(VALUE*)key; - VALUE value_base = *(VALUE*)base; - - if (value_key > value_base) return 1; - if (value_key < value_base) return -1; - return 0; -} -#endif - -static inkpot_status_t inkpot_set_value ( inkpot_t *inkpot, VALUE value ) -{ - - inkpot->no_palette_value = value; - inkpot->value_idx = SZT_VALUES + SZT_NONAME_VALUES; /* indicate presence of no_palette_value */ - - -#if 0 - inkpot_value_t *value; - inkpot_noname_value_t *noname_value; - -/* - * FIXME - implement caching and check here - */ - - value = (inkpot_value_t *) bsearch( - (void*)(value), (void*)TAB_VALUES, - SZT_VALUES, sizeof(inkpot_value_t), - inkpot_value_cmpf); - - if (value) - return inkpot_set_value_idx(inkpot, (value - TAB_VALUES)); - - noname_value = (inkpot_noname_value_t *) bsearch( - (void*)(value), (void*)TAB_NONAME_VALUES, - SZT_NONAME_VALUES, sizeof(inkpot_noname_value_t), - inkpot_value_cmpf); - - if (noname_value) - return inkpot_set_value_idx(inkpot, ((noname_value - TAB_NONAME_VALUES) + SZT_VALUES)); - - return ((inkpot->status = INKPOT_COLOR_NONAME)); - /* need some sort of btree here so that we can insert value - * values and keep sorted */ - - noname_value = (inkpot_noname_value_t *) bsearch( - (void*)(value), (void*)TAB_DYNAMIC_VALUES, - SZT_DYNAMIC_VALUES, sizeof(inkpot_noname_value_t), - inkpot_value_cmpf); - - /* insert value and keep sorted */ - -#endif - return ((inkpot->status = INKPOT_SUCCESS)); -} - inkpot_status_t inkpot_set_rgba ( inkpot_t *inkpot, double rgba[4] ) { VALUE value = 0, v; @@ -617,22 +562,6 @@ inkpot_status_t inkpot_get ( inkpot_t *inkpot, const char **color ) return ((inkpot->status = INKPOT_COLOR_NONAME)); } -static inkpot_status_t inkpot_get_value ( inkpot_t *inkpot, VALUE *value ) -{ - IDX_VALUES value_idx = inkpot->value_idx; - - if (value_idx < SZT_VALUES) - *value = TAB_VALUES[value_idx].value; - else if (value_idx - SZT_VALUES < SZT_NONAME_VALUES) - *value = TAB_NONAME_VALUES[value_idx - SZT_VALUES].value; - else if (value_idx == SZT_VALUES + SZT_NONAME_VALUES) - *value = inkpot->no_palette_value; - else - assert(0); - - return ((inkpot->status = INKPOT_SUCCESS)); -} - inkpot_status_t inkpot_get_rgba_i ( inkpot_t *inkpot, unsigned short rgba[4] ) { inkpot_status_t rc; @@ -698,6 +627,81 @@ inkpot_status_t inkpot_get_index ( inkpot_t *inkpot, unsigned int *index ) } #endif +inkpot_status_t inkpot_write ( inkpot_t *inkpot ) +{ + inkpot_status_t rc; + const char *color; + + rc = inkpot_get(inkpot, &color); + if (rc == INKPOT_SUCCESS) + inkpot->disc.out_writer(inkpot->out_closure, color, strlen(color)); + return rc; +} + +inkpot_status_t inkpot_write_rgba16 ( inkpot_t *inkpot ) +{ + inkpot_status_t rc; + unsigned short rgba[4]; + char buf[17]; + int len; + + rc = inkpot_get_rgba_i ( inkpot, rgba ); + if (rc == INKPOT_SUCCESS) { + len = sprintf(buf, "%04x%04x%04x%04x", rgba[0], rgba[1], rgba[2], rgba[3]); + assert(len==16); + inkpot->disc.out_writer(inkpot->out_closure, buf, len); + } + return rc; +} + +inkpot_status_t inkpot_write_rgb16 ( inkpot_t *inkpot ) +{ + inkpot_status_t rc; + unsigned short rgba[4]; + char buf[13]; + int len; + + rc = inkpot_get_rgba_i ( inkpot, rgba ); + if (rc == INKPOT_SUCCESS) { + len = sprintf(buf, "%04x%04x%04x", rgba[0], rgba[1], rgba[2]); + assert(len==12); + inkpot->disc.out_writer(inkpot->out_closure, buf, len); + } + return rc; +} + +inkpot_status_t inkpot_write_rgba8 ( inkpot_t *inkpot ) +{ + inkpot_status_t rc; + unsigned short rgba[4]; + char buf[9]; + int len; + + rc = inkpot_get_rgba_i ( inkpot, rgba ); + if (rc == INKPOT_SUCCESS) { + len = sprintf(buf, "%02x%02x%02x%02x", rgba[0]>>8, rgba[1]>>8, rgba[2]>>8, rgba[3]>>8); + assert(len==8); + inkpot->disc.out_writer(inkpot->out_closure, buf, len); + } + return rc; +} + +inkpot_status_t inkpot_write_rgb8 ( inkpot_t *inkpot ) +{ + inkpot_status_t rc; + unsigned short rgba[4]; + char buf[7]; + int len; + + rc = inkpot_get_rgba_i ( inkpot, rgba ); + if (rc == INKPOT_SUCCESS) { + len = sprintf(buf, "%02x%02x%02x", rgba[0]>>8, rgba[1]>>8, rgba[2]>>8); + assert(len==6); + inkpot->disc.out_writer(inkpot->out_closure, buf, len); + } + return rc; +} + static void errputs(inkpot_t *inkpot, const char *s) { inkpot->disc.err_writer(inkpot->err_closure, s, strlen(s)); @@ -878,81 +882,6 @@ inkpot_status_t inkpot_debug_values( inkpot_t *inkpot ) return ((inkpot->status = INKPOT_SUCCESS)); } -inkpot_status_t inkpot_write ( inkpot_t *inkpot ) -{ - inkpot_status_t rc; - const char *color; - - rc = inkpot_get(inkpot, &color); - if (rc == INKPOT_SUCCESS) - inkpot->disc.out_writer(inkpot->out_closure, color, strlen(color)); - return rc; -} - -inkpot_status_t inkpot_write_rgba16 ( inkpot_t *inkpot ) -{ - inkpot_status_t rc; - unsigned short rgba[4]; - char buf[17]; - int len; - - rc = inkpot_get_rgba_i ( inkpot, rgba ); - if (rc == INKPOT_SUCCESS) { - len = sprintf(buf, "%04x%04x%04x%04x", rgba[0], rgba[1], rgba[2], rgba[3]); - assert(len==16); - inkpot->disc.out_writer(inkpot->out_closure, buf, len); - } - return rc; -} - -inkpot_status_t inkpot_write_rgb16 ( inkpot_t *inkpot ) -{ - inkpot_status_t rc; - unsigned short rgba[4]; - char buf[13]; - int len; - - rc = inkpot_get_rgba_i ( inkpot, rgba ); - if (rc == INKPOT_SUCCESS) { - len = sprintf(buf, "%04x%04x%04x", rgba[0], rgba[1], rgba[2]); - assert(len==12); - inkpot->disc.out_writer(inkpot->out_closure, buf, len); - } - return rc; -} - -inkpot_status_t inkpot_write_rgba8 ( inkpot_t *inkpot ) -{ - inkpot_status_t rc; - unsigned short rgba[4]; - char buf[9]; - int len; - - rc = inkpot_get_rgba_i ( inkpot, rgba ); - if (rc == INKPOT_SUCCESS) { - len = sprintf(buf, "%02x%02x%02x%02x", rgba[0]>>8, rgba[1]>>8, rgba[2]>>8, rgba[3]>>8); - assert(len==8); - inkpot->disc.out_writer(inkpot->out_closure, buf, len); - } - return rc; -} - -inkpot_status_t inkpot_write_rgb8 ( inkpot_t *inkpot ) -{ - inkpot_status_t rc; - unsigned short rgba[4]; - char buf[7]; - int len; - - rc = inkpot_get_rgba_i ( inkpot, rgba ); - if (rc == INKPOT_SUCCESS) { - len = sprintf(buf, "%02x%02x%02x", rgba[0]>>8, rgba[1]>>8, rgba[2]>>8); - assert(len==6); - inkpot->disc.out_writer(inkpot->out_closure, buf, len); - } - return rc; -} - inkpot_status_t inkpot_debug_error ( inkpot_t *inkpot ) { const char *m; diff --git a/lib/inkpot/inkpot_structs.h b/lib/inkpot/inkpot_struct.h similarity index 78% rename from lib/inkpot/inkpot_structs.h rename to lib/inkpot/inkpot_struct.h index fab82fab2..bf15ae0ba 100644 --- a/lib/inkpot/inkpot_structs.h +++ b/lib/inkpot/inkpot_struct.h @@ -63,38 +63,6 @@ typedef struct inkpot_name_s { /* Color_name used by one or more * get better packing by this merging */ } inkpot_name_t; -typedef struct inkpot_value_s { /* Numeric color values used by the set - * of inkpot_name_t and indexes from - * indexed color schemes ( total presumed - * to be less than all possible color values). - * inkpot_value_t instances are unique and - * are numerically sorted by rgb value - * in TAB_VALUES[] */ - - VALUE value; - - IDX_NAMES - toname_idx; /* An index into TAB_NAMES to the toname - * which indexes the first inkpot_name_t - * in TAB_NAMES that maps to this color, - * followed in TAB_NAMES by the toname indexes - * of other inkpot_name_t that also map to - * this inkpot_value_t, until a toname index - * in TAB_NAMES indexes a inkpot_name_t - * that doesn't map to this inkpot_value_t, - * or until the end of TAB_NAMES is reached. - * (Phew!) */ -} inkpot_value_t; - -typedef struct inkpot_noname_value_s { /* Numeric color values used by the remainder - * of indexes from indexed color schemes - * inkpot_noname_value_t instances are unique and - * are numerically sorted by rgba value - * in TAB_NONAME_VALUES[] */ - VALUE value; - -} inkpot_noname_value_t; - typedef struct inkpot_cache_element_s { IDX_MRU_CACHE next_recently_used_idx; diff --git a/lib/inkpot/inkpot_tables.h b/lib/inkpot/inkpot_tables.h deleted file mode 100644 index cddb94dd4..000000000 --- a/lib/inkpot/inkpot_tables.h +++ /dev/null @@ -1,115 +0,0 @@ -/* $Id$ $Revision$ */ -/* vim:set shiftwidth=4 ts=8: */ - -/*********************************************************** - * This software is part of the graphviz package * - * http://www.graphviz.org/ * - * * - * Copyright (c) 1994-2008 AT&T Corp. * - * and is licensed under the * - * Common Public License, Version 1.0 * - * by AT&T Corp. * - * * - * Information and Software Systems Research * - * AT&T Research, Florham Park NJ * - **********************************************************/ - -typedef unsigned int IDX_STRINGS; -typedef unsigned short MSK_SCHEMES_NAME; -typedef unsigned char IDX_SCHEMES_NAME; -typedef unsigned char IDX_SCHEMES_INDEX; -typedef unsigned int IDX_NAMES; -typedef unsigned char IDX_NAME_ALTS; -typedef unsigned int IDX_VALUES; -typedef unsigned int IDX_IXVALUES; - -typedef unsigned long VALUE; -#define SZB_RED 16 -#define MSK_RED 65535 -#define MAX_RED 65535 - -typedef unsigned int IDX_MRU_CACHE; -#define SZT_MRU_CACHE 4 - -#define SZT_SCHEMES_INDEX 2 - -#include "inkpot_structs.h" - -#define SZL_STRINGS 6 - -const char TAB_STRINGS[] = { - "french\0" - "svg\0" - "x11\0" - "black\0" - "bleu\0" - "blue\0" - "green\0" - "jaune\0" - "red\0" - "rouge\0" - "vert\0" - "yellow\0" - "white\0" - "xxx\0" - "yyy\0" -}; -#define SZT_STRINGS sizeof(TAB_STRINGS)/sizeof(TAB_STRINGS[0]) - -inkpot_scheme_name_t TAB_SCHEMES_NAME[] = { /* schemes of named colors */ - { 0, }, /* french */ - { 7, }, /* svg */ - { 11, }, /* x11 */ -}; -#define SZT_SCHEMES_NAME (sizeof(TAB_SCHEMES_NAME)/sizeof(TAB_SCHEMES_NAME[0])) - -inkpot_scheme_index_t TAB_SCHEMES_INDEX[SZT_SCHEMES_INDEX] = { /* schemes of indexed colors */ - { 71, 0, }, /* xxx */ - { 75, 5, }, /* yyy */ -}; - -inkpot_name_t TAB_NAMES[] = { /* Must be LC_ALL=C sort'ed by name with each alt */ - { 15, 0, 0x6, /* black */ 0, /* black */ }, /* 0 */ - { 21, 1, 0x1, /* bleu */ 1, /* bleu, blue */ }, /* 1 */ - { 26, 1, 0x6, /* blue */ 2, }, /* 2 */ - { 31, 2, 0x6, /* green */ 3, /* green, vert */ }, /* 3 */ - { 37, 5, 0x1, /* jaune */ 7, }, /* 4 */ - { 43, 3, 0x6, /* red */ 5, /* red, rouge */ }, /* 5 */ - { 47, 3, 0x1, /* rouge */ 6, }, /* 6 */ - { 53, 2, 0x1, /* vert */ 10, /* yellow(alt1) */ }, /* 7 */ - { 65, 6, 0x6, /* white */ 4, /* jaune, yellow */ }, /* 8 */ - { 58, 5, 0x4, /* yellow */ 9, }, /* 9 */ -/* alt1 */ - { 58, 4, 0x2, /* yellow */ 8, /* white */ }, /* 10 */ -}; -#define SZT_NAMES (sizeof(TAB_NAMES)/sizeof(TAB_NAMES[0])) - -IDX_NAMES TAB_NAME_ALTS[] = { - 0, 10, -}; -#define SZT_NAME_ALTS (sizeof(TAB_NAME_ALTS)/sizeof(TAB_NAME_ALTS[0])) - -inkpot_value_t TAB_VALUES[] = { /* Must be sort'ed */ - { 0x000000000000ffff, 0 }, /* black */ - { 0x00000000ffffffff, 1 }, /* bleu, blue */ - { 0x0000ffff0000ffff, 3 }, /* green, vert */ - { 0xffff00000000ffff, 5 }, /* red, rouge */ - { 0xffffcf000000ffff, 7 }, /* yellow (svg) */ - { 0xffffffff0000ffff, 8 }, /* yellow (x11), jaune */ - { 0xffffffffffffffff, 10}, /* white */ -}; -#define SZT_VALUES (sizeof(TAB_VALUES)/sizeof(TAB_VALUES[0])) - -inkpot_noname_value_t TAB_NONAME_VALUES[] = { /* Must be sort'ed */ - { 0x000000008000ffff, }, - { 0x00000000a400ffff, }, - { 0x00000000c800ffff, }, - { 0x00000000ea00ffff, }, -}; -#define SZT_NONAME_VALUES (sizeof(TAB_NONAME_VALUES)/sizeof(TAB_NONAME_VALUES[0])) - -IDX_VALUES TAB_IXVALUES[] = { - 7, 8, 9, 10, 1, /* xxx */ - 0, 6, /* yyy */ -}; -#define SZT_IXVALUES sizeof(TAB_IXVALUES)/sizeof(TAB_IXVALUES[0]) diff --git a/lib/inkpot/inkpot_value.c b/lib/inkpot/inkpot_value.c new file mode 100644 index 000000000..95ebe70cf --- /dev/null +++ b/lib/inkpot/inkpot_value.c @@ -0,0 +1,98 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/*********************************************************** + * This software is part of the graphviz package * + * http://www.graphviz.org/ * + * * + * Copyright (c) 1994-2008 AT&T Corp. * + * and is licensed under the * + * Common Public License, Version 1.0 * + * by AT&T Corp. * + * * + * Information and Software Systems Research * + * AT&T Research, Florham Park NJ * + **********************************************************/ + +#include +#include + +#include "inkpot.h" +#include "inkpot_define.h" +#include "inkpot_value.h" +#include "inkpot_struct.h" +#include "inkpot_value_table.h" + +#if 0 +static int inkpot_value_cmpf ( const void *key, const void *base) +{ + VALUE value_key = *(VALUE*)key; + VALUE value_base = *(VALUE*)base; + + if (value_key > value_base) return 1; + if (value_key < value_base) return -1; + return 0; +} +#endif + +inkpot_status_t inkpot_set_value ( inkpot_t *inkpot, VALUE value ) +{ + + inkpot->no_palette_value = value; + inkpot->value_idx = SZT_VALUES + SZT_NONAME_VALUES; /* indicate presence of no_palette_value */ + + +#if 0 + inkpot_value_t *value; + inkpot_noname_value_t *noname_value; + +/* + * FIXME - implement caching and check here + */ + + value = (inkpot_value_t *) bsearch( + (void*)(value), (void*)TAB_VALUES, + SZT_VALUES, sizeof(inkpot_value_t), + inkpot_value_cmpf); + + if (value) + return inkpot_set_value_idx(inkpot, (value - TAB_VALUES)); + + noname_value = (inkpot_noname_value_t *) bsearch( + (void*)(value), (void*)TAB_NONAME_VALUES, + SZT_NONAME_VALUES, sizeof(inkpot_noname_value_t), + inkpot_value_cmpf); + + if (noname_value) + return inkpot_set_value_idx(inkpot, ((noname_value - TAB_NONAME_VALUES) + SZT_VALUES)); + + return ((inkpot->status = INKPOT_COLOR_NONAME)); + /* need some sort of btree here so that we can insert value + * values and keep sorted */ + + noname_value = (inkpot_noname_value_t *) bsearch( + (void*)(value), (void*)TAB_DYNAMIC_VALUES, + SZT_DYNAMIC_VALUES, sizeof(inkpot_noname_value_t), + inkpot_value_cmpf); + + /* insert value and keep sorted */ + +#endif + return ((inkpot->status = INKPOT_SUCCESS)); +} + +inkpot_status_t inkpot_get_value ( inkpot_t *inkpot, VALUE *value ) +{ + IDX_VALUES value_idx = inkpot->value_idx; + + if (value_idx < SZT_VALUES) + *value = TAB_VALUES[value_idx].value; + else if (value_idx - SZT_VALUES < SZT_NONAME_VALUES) + *value = TAB_NONAME_VALUES[value_idx - SZT_VALUES].value; + else if (value_idx == SZT_VALUES + SZT_NONAME_VALUES) + *value = inkpot->no_palette_value; + else + assert(0); + + return ((inkpot->status = INKPOT_SUCCESS)); +} diff --git a/lib/inkpot/inkpot_value.h b/lib/inkpot/inkpot_value.h new file mode 100644 index 000000000..2b1c83bc9 --- /dev/null +++ b/lib/inkpot/inkpot_value.h @@ -0,0 +1,67 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/*********************************************************** + * This software is part of the graphviz package * + * http://www.graphviz.org/ * + * * + * Copyright (c) 1994-2008 AT&T Corp. * + * and is licensed under the * + * Common Public License, Version 1.0 * + * by AT&T Corp. * + * * + * Information and Software Systems Research * + * AT&T Research, Florham Park NJ * + **********************************************************/ + +#ifndef INKPOT_VALUE_H +#define INKPOT_VALUE_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct inkpot_value_s { /* Numeric color values used by the set + * of inkpot_name_t and indexes from + * indexed color schemes ( total presumed + * to be less than all possible color values). + * inkpot_value_t instances are unique and + * are numerically sorted by rgb value + * in TAB_VALUES[] */ + + VALUE value; + + IDX_NAMES /* FIXME - searate this in to a separate table */ + toname_idx; /* An index into TAB_NAMES to the toname + * which indexes the first inkpot_name_t + * in TAB_NAMES that maps to this color, + * followed in TAB_NAMES by the toname indexes + * of other inkpot_name_t that also map to + * this inkpot_value_t, until a toname index + * in TAB_NAMES indexes a inkpot_name_t + * that doesn't map to this inkpot_value_t, + * or until the end of TAB_NAMES is reached. + * (Phew!) */ +} inkpot_value_t; + +typedef struct inkpot_noname_value_s { /* Numeric color values used by the remainder + * of indexes from indexed color schemes + * inkpot_noname_value_t instances are unique and + * are numerically sorted by rgba value + * in TAB_NONAME_VALUES[] */ + VALUE value; + +} inkpot_noname_value_t; + +extern inkpot_status_t inkpot_set_value ( inkpot_t *inkpot, VALUE value ); +extern inkpot_status_t inkpot_get_value ( inkpot_t *inkpot, VALUE *value ); + +extern inkpot_value_t TAB_VALUES[]; +extern inkpot_noname_value_t TAB_NONAME_VALUES[]; +extern IDX_VALUES TAB_IXVALUES[]; + +#ifdef __cplusplus +} +#endif +#endif /* INKPOT_VALUE_H */ + diff --git a/lib/inkpot/inkpot_value_table.h b/lib/inkpot/inkpot_value_table.h new file mode 100644 index 000000000..7b3f16cba --- /dev/null +++ b/lib/inkpot/inkpot_value_table.h @@ -0,0 +1,37 @@ +/* $Id$ $Revision$ */ +/* vim:set shiftwidth=4 ts=8: */ + +/*********************************************************** + * This software is part of the graphviz package * + * http://www.graphviz.org/ * + * * + * Copyright (c) 1994-2008 AT&T Corp. * + * and is licensed under the * + * Common Public License, Version 1.0 * + * by AT&T Corp. * + * * + * Information and Software Systems Research * + * AT&T Research, Florham Park NJ * + **********************************************************/ + +inkpot_value_t TAB_VALUES[SZT_VALUES] = { /* Must be sort'ed */ + { 0x000000000000ffff, 0 }, /* black */ + { 0x00000000ffffffff, 1 }, /* bleu, blue */ + { 0x0000ffff0000ffff, 3 }, /* green, vert */ + { 0xffff00000000ffff, 5 }, /* red, rouge */ + { 0xffffcf000000ffff, 7 }, /* yellow (svg) */ + { 0xffffffff0000ffff, 8 }, /* yellow (x11), jaune */ + { 0xffffffffffffffff, 10}, /* white */ +}; + +inkpot_noname_value_t TAB_NONAME_VALUES[SZT_NONAME_VALUES] = { /* Must be sort'ed */ + { 0x000000008000ffff, }, + { 0x00000000a400ffff, }, + { 0x00000000c800ffff, }, + { 0x00000000ea00ffff, }, +}; + +IDX_VALUES TAB_IXVALUES[SZT_IXVALUES] = { + 7, 8, 9, 10, 1, /* xxx */ + 0, 6, /* yyy */ +}; -- 2.40.0