From: ellson Date: Sun, 28 Sep 2008 16:02:05 +0000 (+0000) Subject: just a good point to save my work X-Git-Tag: LAST_LIBGRAPH~32^2~3286 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5a91bb5158b9dd5bfc0a283c180a5d688d41b59a;p=graphviz just a good point to save my work --- diff --git a/lib/inkpot/inkpot_scheme.c b/lib/inkpot/inkpot_scheme.c index e22afab5f..47024bf82 100644 --- a/lib/inkpot/inkpot_scheme.c +++ b/lib/inkpot/inkpot_scheme.c @@ -41,12 +41,16 @@ inkpot_t *inkpot_init ( void ) inkpot = malloc(sizeof(inkpot_t)); if (inkpot) { + + inkpot->values = inkpot_values_init (); + if (! inkpot->values) { + free(inkpot); + return NULL; + } + inkpot->canon = NULL; inkpot->canon_alloc = 0; - inkpot->palette = NULL; - inkpot->palette_alloc = 0; - inkpot->disc = inkpot_default_disc; inkpot->out_closure = stdout; inkpot->err_closure = stderr; @@ -65,8 +69,8 @@ inkpot_t *inkpot_init ( void ) void inkpot_destroy ( inkpot_t *inkpot ) { + inkpot_values_destroy ( inkpot->values ); free(inkpot->canon); - free(inkpot->palette); free(inkpot); } @@ -226,6 +230,7 @@ inkpot_status_t inkpot_translate ( inkpot_t *inkpot, const char *scheme ) return ((inkpot->status = INKPOT_SUCCESS)); } +#if 0 inkpot_status_t inkpot_palette( inkpot_t *inkpot, int size ) { if (inkpot->palette_alloc < size * sizeof(inkpot_noname_value_t)) { @@ -236,6 +241,7 @@ inkpot_status_t inkpot_palette( inkpot_t *inkpot, int size ) } return ((inkpot->status = INKPOT_SUCCESS)); } +#endif static int inkpot_name_cmpf ( const void *key, const void *base) { @@ -247,8 +253,8 @@ static int inkpot_name_cmpf ( const void *key, const void *base) static inkpot_status_t inkpot_set_value_idx( inkpot_t *inkpot, IDX_VALUES value_idx) { - if (inkpot->value_idx != value_idx) { - inkpot->value_idx = value_idx; + if (inkpot->value.index != value_idx) { + inkpot->value.index = value_idx; inkpot->out_name = NULL; /* value changed so invalidate out_name */ } return ((inkpot->status = INKPOT_SUCCESS)); @@ -379,18 +385,24 @@ static inkpot_status_t inkpot_set_index ( inkpot_t *inkpot, int index ) inkpot_status_t inkpot_set_rgba ( inkpot_t *inkpot, double rgba[4] ) { - VALUE value = 0, v; + inkpot_status_t rc; + inkpot_value_t value; + VALUE v; int i; for (i = 0; i < 4; i++) { - value <<= SZB_RED; + value.value <<= SZB_RED; v = rgba[i]; v = (v < 0.0) ? 0.0 : v; v = (v > 1.0) ? 1.0 : v; - value |= (int)(v * MAX_RED); + value.value |= (int)(v * MAX_RED); } - - return inkpot_set_value ( inkpot, value ); + value.vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes; + + rc = inkpot_value_set ( inkpot->values, &value ); + if (rc == INKPOT_SUCCESS) + inkpot->value = value; + return (inkpot->status = rc); } inkpot_status_t inkpot_set_hsva ( inkpot_t *inkpot, double hsva[4] ) @@ -411,7 +423,7 @@ inkpot_status_t inkpot_set ( inkpot_t *inkpot, const char *color ) const char *p; int i, c, len, index; unsigned int r, g, b, a; - VALUE value; + inkpot_value_t value; double hsva[4]; inkpot_status_t rc = INKPOT_COLOR_UNKNOWN; @@ -450,8 +462,13 @@ inkpot_status_t inkpot_set ( inkpot_t *inkpot, const char *color ) } } if (len >= 3) { - value = (((((((VALUE)r) << SZB_RED) | (VALUE)g) << SZB_RED) | (VALUE)b) << SZB_RED) | (VALUE)a; - rc = inkpot_set_value(inkpot, value); + value.value = (((((((VALUE)r) << SZB_RED) | (VALUE)g) << SZB_RED) | (VALUE)b) << SZB_RED) | (VALUE)a; + value.vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes; + + rc = inkpot_value_set ( inkpot->values, &value ); + if (rc == INKPOT_SUCCESS) + inkpot->value = value; + inkpot->status = rc; } } else if (((c = *inkpot->canon) == '.') || isdigit(c)) { @@ -525,7 +542,7 @@ inkpot_status_t inkpot_get ( inkpot_t *inkpot, const char **color ) } if (inkpot->out_scheme_bit) { - value_idx = inkpot->value_idx; + value_idx = inkpot->value.index; if (value_idx < SZT_VALUES) { for (t = TAB_VALUES[value_idx].toname_idx; t < SZT_NAMES; t++) { out_name = &TAB_NAMES[TAB_NAMES[t].toname_idx]; @@ -565,14 +582,15 @@ inkpot_status_t inkpot_get ( inkpot_t *inkpot, const char **color ) inkpot_status_t inkpot_get_rgba_i ( inkpot_t *inkpot, unsigned short rgba[4] ) { inkpot_status_t rc; - VALUE value; + inkpot_value_t value; int i; - rc = inkpot_get_value( inkpot, &value ); + value = inkpot->value; + rc = inkpot->status = inkpot_value_get( inkpot->values, &value ); if (rc == INKPOT_SUCCESS) { for (i = 3; i >= 0; i--) { - rgba[i] = (value & MSK_RED); - value >>= SZB_RED; + rgba[i] = (value.value & MSK_RED); + value.value >>= SZB_RED; } } return rc; @@ -581,14 +599,15 @@ inkpot_status_t inkpot_get_rgba_i ( inkpot_t *inkpot, unsigned short rgba[4] ) inkpot_status_t inkpot_get_rgba ( inkpot_t *inkpot, double rgba[4] ) { inkpot_status_t rc; - VALUE value; + inkpot_value_t value; int i; - rc = inkpot_get_value( inkpot, &value ); + value = inkpot->value; + rc = inkpot->status = inkpot_value_get( inkpot->values, &value ); if (rc == INKPOT_SUCCESS) { for (i = 3; i >= 0; i--) { - rgba[i] = (value & MSK_RED) / (double)MAX_RED; - value >>= SZB_RED; + rgba[i] = (value.value & MSK_RED) / (double)MAX_RED; + value.value >>= SZB_RED; } } return rc; @@ -842,6 +861,7 @@ inkpot_status_t inkpot_debug_out_names( inkpot_t *inkpot ) return inkpot_debug_names_schemes(inkpot, inkpot->out_scheme_bit, 1, inkpot->out_scheme_list); } +#if 0 /* Print all values that are members of the currently listed * name schemes, with the names in those schemes. * Does not print the indexes in index schemes that a value may @@ -881,6 +901,7 @@ inkpot_status_t inkpot_debug_values( inkpot_t *inkpot ) return ((inkpot->status = INKPOT_SUCCESS)); } +#endif inkpot_status_t inkpot_debug_error ( inkpot_t *inkpot ) { diff --git a/lib/inkpot/inkpot_struct.h b/lib/inkpot/inkpot_struct.h index bf15ae0ba..1a01071fa 100644 --- a/lib/inkpot/inkpot_struct.h +++ b/lib/inkpot/inkpot_struct.h @@ -79,9 +79,6 @@ struct inkpot_s { /* The Ink Pot */ scheme_bits, /* One bit per inkpot_scheme_name_t */ out_scheme_bit; /* One scheme only for output. */ - IDX_VALUES - value_idx; /* The current color */ - IDX_IXVALUES index, /* The index for the current value in active_schemes_index */ out_index; /* The index for the current value in active_out_schemes_index */ @@ -98,21 +95,22 @@ struct inkpot_s { /* The Ink Pot */ char *canon; /* malloc'ed, reused storage for canonicalizing color request strings */ int canon_alloc; - VALUE - no_palette_value; - - inkpot_noname_value_t *palette; /* malloc'ed paletter storage */ - int palette_alloc; - int palette_fill; + inkpot_values_t *values;/* The values store */ + inkpot_value_t value; /* The current value of the inkpot */ - inkpot_cache_element_t cache[SZT_MRU_CACHE]; /* MRU chache of successfull color lookups */ + inkpot_cache_element_t + cache[SZT_MRU_CACHE];/* MRU chache of successful color lookups */ IDX_MRU_CACHE most_recently_used_idx; - inkpot_disc_t disc; /* writers and closures for out and err */ - void *out_closure, *err_closure; + inkpot_disc_t + disc; /* writers and closures for out and err */ + void + *out_closure, + *err_closure; - inkpot_status_t status; /* The status after the last operation */ + inkpot_status_t + status; /* The status after the last operation */ }; #endif /* INKPOT_STRUCTS_H */ diff --git a/lib/inkpot/inkpot_value.c b/lib/inkpot/inkpot_value.c index 95ebe70cf..75a0deab7 100644 --- a/lib/inkpot/inkpot_value.c +++ b/lib/inkpot/inkpot_value.c @@ -15,84 +15,65 @@ **********************************************************/ #include +#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) +struct inkpot_values_s { + VALUE + no_palette_value; + BIT_VTYPE + no_palette_vtype; +}; + +inkpot_values_t* inkpot_values_init ( void ) { - VALUE value_key = *(VALUE*)key; - VALUE value_base = *(VALUE*)base; + inkpot_values_t *values; + + values = (inkpot_values_t*)malloc(sizeof(inkpot_values_t)); + if (values) { - if (value_key > value_base) return 1; - if (value_key < value_base) return -1; - return 0; + } + return values; } -#endif -inkpot_status_t inkpot_set_value ( inkpot_t *inkpot, VALUE value ) +void inkpot_values_destroy ( inkpot_values_t *values ) { + free(values); +} - 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 */ +inkpot_status_t inkpot_value_set ( inkpot_values_t *values, inkpot_value_t *value ) +{ + values->no_palette_value = value->value; + values->no_palette_vtype = value->vtype; + value->index = SZT_VALUES + SZT_NONAME_VALUES; -#endif - return ((inkpot->status = INKPOT_SUCCESS)); + return INKPOT_SUCCESS; } -inkpot_status_t inkpot_get_value ( inkpot_t *inkpot, VALUE *value ) +inkpot_status_t inkpot_value_get ( inkpot_values_t *values, inkpot_value_t *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; + IDX_VALUES index; + + index = value->index; + if (index < SZT_VALUES) { + value->value = TAB_VALUES[index].value; + value->vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes; + } + else if (index - SZT_VALUES < SZT_NONAME_VALUES) { + value->value = TAB_NONAME_VALUES[index - SZT_VALUES].value; + value->vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes; + } + else if (index == SZT_VALUES + SZT_NONAME_VALUES) { + value->value = values->no_palette_value; + value->vtype = values->no_palette_vtype; + } else assert(0); - return ((inkpot->status = INKPOT_SUCCESS)); + return INKPOT_SUCCESS; } diff --git a/lib/inkpot/inkpot_value.h b/lib/inkpot/inkpot_value.h index 2b1c83bc9..472d51c87 100644 --- a/lib/inkpot/inkpot_value.h +++ b/lib/inkpot/inkpot_value.h @@ -21,7 +21,10 @@ extern "C" { #endif -typedef struct inkpot_value_s { /* Numeric color values used by the set +#if 1 +/* FIXME - this stuff needs to go */ + +typedef struct inkpot_oldvalue_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). @@ -42,7 +45,7 @@ typedef struct inkpot_value_s { /* Numeric color values used by the set * that doesn't map to this inkpot_value_t, * or until the end of TAB_NAMES is reached. * (Phew!) */ -} inkpot_value_t; +} inkpot_oldvalue_t; typedef struct inkpot_noname_value_s { /* Numeric color values used by the remainder * of indexes from indexed color schemes @@ -53,13 +56,46 @@ typedef struct inkpot_noname_value_s { /* Numeric color values used by the remai } 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_oldvalue_t TAB_VALUES[]; extern inkpot_noname_value_t TAB_NONAME_VALUES[]; +#endif extern IDX_VALUES TAB_IXVALUES[]; +/* proper api starts here */ + +typedef struct inkpot_values_s inkpot_values_t; + +typedef int BIT_VTYPE; + +#define MSK_VTYPE_size 0x01 +#define BIT_VTYPE_size_8 0x00 +#define BIT_VTYPE_size_16 0x01 + +#define MSK_VTYPE_code 0x0e +#define BIT_VTYPE_code_VALUE 0x00 +#define BIT_VTYPE_code_rgba 0x02 +#define BIT_VTYPE_code_hsva 0x04 +#define BIT_VTYPE_code_cmyk 0x06 + +#define MSK_VTYPE_alpha 0x10 +#define BIT_VTYPE_alpha_no 0x00 +#define BIT_VTYPE_alpha_yes 0x10 + +typedef struct inkpot_value_s { + IDX_VALUES index; /* write by set, read by get, write by first/next */ + BIT_VTYPE vtype; /* read by set, write by get, read by first/next */ + VALUE value; /* read by set, write by get, write by first/next */ +} inkpot_value_t; + +extern inkpot_values_t* inkpot_values_init (); +extern void inkpot_values_destroy ( inkpot_values_t *values ); + +extern inkpot_status_t inkpot_value_set ( inkpot_values_t *values, inkpot_value_t *value ); +extern inkpot_status_t inkpot_value_get ( inkpot_values_t *values, inkpot_value_t *value ); + +extern inkpot_status_t inkpot_value_get_first ( inkpot_values_t *values, inkpot_value_t *value ); +extern inkpot_status_t inkpot_value_get_next ( inkpot_values_t *values, inkpot_value_t *value ); + #ifdef __cplusplus } #endif diff --git a/lib/inkpot/inkpot_value_table.h b/lib/inkpot/inkpot_value_table.h index 7b3f16cba..cfd9e16b2 100644 --- a/lib/inkpot/inkpot_value_table.h +++ b/lib/inkpot/inkpot_value_table.h @@ -14,7 +14,7 @@ * AT&T Research, Florham Park NJ * **********************************************************/ -inkpot_value_t TAB_VALUES[SZT_VALUES] = { /* Must be sort'ed */ +inkpot_oldvalue_t TAB_VALUES[SZT_VALUES] = { /* Must be sort'ed */ { 0x000000000000ffff, 0 }, /* black */ { 0x00000000ffffffff, 1 }, /* bleu, blue */ { 0x0000ffff0000ffff, 3 }, /* green, vert */