From db9e4370fccf4752565272033bb60d01f6d0cedd Mon Sep 17 00:00:00 2001 From: ellson Date: Mon, 6 Oct 2008 19:17:33 +0000 Subject: [PATCH] checkpoint --- lib/inkpot/inkpot_lib.tcl | 16 ++-- lib/inkpot/inkpot_scheme.c | 170 +++++++++++++++++-------------------- lib/inkpot/inkpot_scheme.h | 53 ++++++------ 3 files changed, 110 insertions(+), 129 deletions(-) diff --git a/lib/inkpot/inkpot_lib.tcl b/lib/inkpot/inkpot_lib.tcl index c3701e141..5d629e78f 100755 --- a/lib/inkpot/inkpot_lib.tcl +++ b/lib/inkpot/inkpot_lib.tcl @@ -144,7 +144,7 @@ foreach {m2} [lsort -dictionary [mapm2 ICRIV]] { set SZT_INDEXES 0 set index -1 tab_initialize $f {set SZT_INDEXES} {list [map2m1 ICRIV $RIV] $size} \ - "IDX_VALUES TAB_INDEXES\[SZT_INDEXES\] = {" + "IDX_VALUES_t TAB_INDEXES\[SZT_INDEXES\] = {" foreach {icolor_range_schemes} [lsort -ascii [array names ALL_RANGES]] { tab_row foreach {m2} $ALL_RANGES($icolor_range_schemes) { @@ -183,7 +183,7 @@ tab_finalize "};\n" set SZT_ICOLORS 0 set last_icolor "" tab_initialize $f {set SZT_ICOLORS} {list $icolor $schemes} \ - "inkpot_scheme_index_t TAB_ICOLORS\[SZT_ICOLORS\] = {" + "inkpot_icolor_t TAB_ICOLORS\[SZT_ICOLORS\] = {" foreach {icolor_range_schemes} [lsort -dictionary [array names ALL_RANGES_coded]] { foreach {icolor range schemes} $icolor_range_schemes {break} foreach {first_idx size} $ALL_RANGES_coded($icolor_range_schemes) {break} @@ -201,7 +201,7 @@ tab_finalize "};\n" # generate TAB_SCHEMES set SZT_SCHEMES 0 tab_initialize $f {set SZT_SCHEMES} {set scheme} \ - "inkpot_scheme_name_t TAB_SCHEMES\[SZT_SCHEMES\] = {" + "inkpot_scheme_t TAB_SCHEMES\[SZT_SCHEMES\] = {" foreach {scheme} [lsort -ascii [array names ALL_SCHEMES]] { # tab_elem $f "{$ALL_SCHEME_STRINGS_coded($scheme),$ALL_INDEX_SCHEMES_coded($scheme)}," tab_elem "{$ALL_SCHEME_STRINGS_coded($scheme)}," @@ -281,7 +281,7 @@ tab_finalize "};\n" # generate TAB_TO_NAMES set SZT_TO_NAMES 0 tab_initialize $f {set SZT_TO_NAMES} {set alias_set} \ - "IDX_NAMES TAB_TO_NAMES\[SZT_TO_NAMES\] = {" + "IDX_NAMES_t TAB_TO_NAMES\[SZT_TO_NAMES\] = {" foreach {m2} [mapm2 CV] { set alias_set [mapm21 CV $m2] foreach {value schemeset} $m2 {break} @@ -300,7 +300,7 @@ tab_finalize "};\n" # generate TAB_VALUE_TO set SZT_VALUE_TO 0 tab_initialize $f {set SZT_VALUE_TO} {set ALL_TO_NAMES_coded($value)} \ - "IDX_TO_NAMES TAB_VALUE_TO\[SZT_VALUE_TO\] = {" + "IDX_TO_NAMES_t TAB_VALUE_TO\[SZT_VALUE_TO\] = {" # NB - this sort order must match TAB_VALUES foreach {value} [lsort -dictionary [map2 CV]] { tab_elem $ALL_TO_NAMES_coded($value), @@ -338,7 +338,7 @@ foreach {i} { set int "unsigned long" } puts $f "\#define SZT_$i [set SZT_$i]" - puts $f "typedef $int IDX_$i\;" + puts $f "typedef $int IDX_[set i]_t\;" puts $f "" } foreach {i} {SCHEMES} { @@ -351,9 +351,9 @@ foreach {i} {SCHEMES} { } elseif {[set SZT_$i] < 64} { set int "unsigned long" } else { - puts stderr "more that 64 bits in MSK_$i" + puts stderr "more that 64 bits in MSK_[set i]_t" } - puts $f "typedef $int MSK_$i\;" + puts $f "typedef $int MSK_[set i]_t\;" puts $f "" } close $f diff --git a/lib/inkpot/inkpot_scheme.c b/lib/inkpot/inkpot_scheme.c index cc1a4b9e7..a46533e33 100644 --- a/lib/inkpot/inkpot_scheme.c +++ b/lib/inkpot/inkpot_scheme.c @@ -76,91 +76,73 @@ static int string_cmpf (const char *k, const char *b) return 0; } -static int inkpot_scheme_name_cmpf ( const void *key, const void *base) +static int inkpot_scheme_cmpf ( const void *key, const void *base) { const char *k = (const char*)key; - const char *b = &TAB_STRINGS[((inkpot_scheme_name_t *)base)->string_idx]; + const char *b = &TAB_STRINGS[((inkpot_scheme_t *)base)->string_idx]; return string_cmpf(k, b); } -static inkpot_scheme_name_t *inkpot_find_scheme_name ( const char *scheme ) +static inkpot_scheme_t *inkpot_find_scheme ( const char *scheme ) { if (scheme == NULL) return NULL; /* FIXME - split scheme/subscheme/n */ - return (inkpot_scheme_name_t *) bsearch( + return (inkpot_scheme_t *) bsearch( (void*)scheme, (void*)TAB_SCHEMES, - SZT_SCHEMES, sizeof(inkpot_scheme_name_t), - inkpot_scheme_name_cmpf); + SZT_SCHEMES, sizeof(inkpot_scheme_t), + inkpot_scheme_cmpf); } -static int inkpot_scheme_index_cmpf ( const void *key, const void *base) +static int inkpot_icolor_cmpf ( const void *key, const void *base) { const char *k = (const char*)key; - const char *b = &TAB_STRINGS[((inkpot_scheme_index_t *)base)->scheme_string_idx]; + const char *b = &TAB_STRINGS[((inkpot_icolor_t *)base)->string_idx]; return string_cmpf(k, b); } -static int inkpot_subscheme_index_cmpf ( const void *key, const void *base) +static inkpot_icolor_t *inkpot_find_icolor ( const char *icolor) { - const char *k = (const char*)key; - const char *b = &TAB_STRINGS[((inkpot_scheme_index_t *)base)->subscheme_string_idx]; - - return string_cmpf(k, b); -} - -static inkpot_scheme_index_t *inkpot_find_scheme_index ( const char *scheme) -{ - if (scheme == NULL) + if (icolor == NULL) return NULL; - return (inkpot_scheme_index_t *) bsearch( - (void*)scheme, (void*)TAB_SCHEMES_INDEX, - SZT_SCHEMES_INDEX, sizeof(inkpot_scheme_index_t), - inkpot_scheme_index_cmpf); -} - -#if 0 -static inkpot_subscheme_index_t *inkpot_find_subscheme_index ( const char *subscheme ) -{ - if (subscheme == NULL) - return NULL; - - return (inkpot_subscheme_index_t *) bsearch( - (void*)subscheme, (void*)TAB_SUBSCHEMES_INDEX, - SZT_SUBSCHEMES_INDEX, sizeof(inkpot_subscheme_index_t), - inkpot_subscheme_index_cmpf); + return (inkpot_icolor_t *) bsearch( + (void*)icolor, (void*)TAB_ICOLORS, + SZT_ICOLORS, sizeof(inkpot_icolor_t), + inkpot_icolor_cmpf); } -#endif static inkpot_status_t inkpot_scheme ( inkpot_t *inkpot, const char *scheme ) { - inkpot_scheme_name_t *inkpot_scheme_name; - inkpot_scheme_index_t *inkpot_scheme_index; - IDX_SCHEMES_INDEX i; + inkpot_scheme_t *inkpot_scheme; + inkpot_icolor_t *inkpot_icolor; + IDX_ICOLORS_t i; if (scheme == NULL) return ((inkpot->status = INKPOT_SCHEME_UNKNOWN)); - inkpot_scheme_name = inkpot_find_scheme_name(scheme); - if (inkpot_scheme_name) { - inkpot->scheme_bits |= 1 << (inkpot_scheme_name - TAB_SCHEMES); + inkpot_scheme = inkpot_find_scheme(scheme); + if (inkpot_scheme) { + inkpot->scheme_bits |= 1 << (inkpot_scheme - TAB_SCHEMES); return ((inkpot->status = INKPOT_SUCCESS)); } - inkpot_scheme_index = inkpot_find_scheme_index(scheme); - if (! inkpot_scheme_index) +#if 0 + inkpot_icolor = inkpot_find_icolor(icolor); + if (! inkpot_icolor) return ((inkpot->status = INKPOT_SCHEME_UNKNOWN)); for (i = 0; i < inkpot->active_schemes; i++) - if (inkpot->scheme_list[i] == (inkpot_scheme_index - TAB_SCHEMES_INDEX)) + if (inkpot->scheme_list[i] == (inkpot_icolor - TAB_ICOLORS)) return ((inkpot->status = INKPOT_SUCCESS)); - inkpot->scheme_list[i] = (inkpot_scheme_index - TAB_SCHEMES_INDEX); + inkpot->scheme_list[i] = (inkpot_icolor - TAB_ICOLORS); inkpot->active_schemes++; return ((inkpot->status = INKPOT_SUCCESS)); +#endif + return ((inkpot->status = INKPOT_SCHEME_UNKNOWN)); } inkpot_status_t inkpot_schemes_put ( inkpot_t *inkpot, const char *schemes ) @@ -202,16 +184,16 @@ inkpot_status_t inkpot_schemes_put ( inkpot_t *inkpot, const char *schemes ) inkpot_status_t inkpot_scheme_get ( inkpot_t *inkpot, const char *scheme ) { - inkpot_scheme_name_t *inkpot_scheme_name; - inkpot_scheme_index_t *inkpot_scheme_index; - IDX_SCHEMES idx; + inkpot_scheme_t *inkpot_scheme; + inkpot_icolor_t *inkpot_icolor; + IDX_SCHEMES_t idx; if (scheme == NULL) return ((inkpot->status = INKPOT_SCHEME_UNKNOWN)); - inkpot_scheme_name = inkpot_find_scheme_name(scheme); - if (inkpot_scheme_name) { - idx = inkpot_scheme_name - TAB_SCHEMES; + inkpot_scheme = inkpot_find_scheme(scheme); + if (inkpot_scheme) { + idx = inkpot_scheme - TAB_SCHEMES; if (! (inkpot->out_scheme_bit & (1 << idx))) { inkpot->out_scheme_bit = 1 << idx; inkpot->active_out_schemes = 0; @@ -220,13 +202,13 @@ inkpot_status_t inkpot_scheme_get ( inkpot_t *inkpot, const char *scheme ) return ((inkpot->status = INKPOT_SUCCESS)); } - inkpot_scheme_index = inkpot_find_scheme_index(scheme); - if (! inkpot_scheme_index) + inkpot_icolor = inkpot_find_icolor(scheme); /* FIXME */ + if (! inkpot_icolor) return ((inkpot->status = INKPOT_SCHEME_UNKNOWN)); if (inkpot->active_out_schemes == 0 - || (inkpot->out_scheme_list[0] != (inkpot_scheme_index - TAB_SCHEMES_INDEX))) { - inkpot->out_scheme_list[0] = (inkpot_scheme_index - TAB_SCHEMES_INDEX); + || (inkpot->out_scheme_list[0] != (inkpot_icolor - TAB_ICOLORS))) { + inkpot->out_scheme_list[0] = (inkpot_icolor - TAB_ICOLORS); inkpot->active_out_schemes = 1; inkpot->out_scheme_bit = 0; inkpot->out_name = NULL; /* clear cached name */ @@ -255,7 +237,7 @@ static int inkpot_name_cmpf ( const void *key, const void *base) return string_cmpf(k, b); } -static inkpot_status_t inkpot_put_value_idx( inkpot_t *inkpot, IDX_VALUES value_idx) +static inkpot_status_t inkpot_put_value_idx( inkpot_t *inkpot, IDX_VALUES_t value_idx) { if (inkpot->value.index != value_idx) { inkpot->value.index = value_idx; @@ -266,8 +248,8 @@ static inkpot_status_t inkpot_put_value_idx( inkpot_t *inkpot, IDX_VALUES value_ static inkpot_status_t inkpot_cache_get( inkpot_t *inkpot ) { - IDX_MRU_CACHE i; - IDX_NAMES cache_name_idx; + IDX_MRU_CACHE_t i; + IDX_NAMES_t cache_name_idx; const char *cache_color; char *color; @@ -299,9 +281,9 @@ static inkpot_status_t inkpot_cache_get( inkpot_t *inkpot ) return ((inkpot->status = INKPOT_COLOR_UNKNOWN)); } -static inkpot_status_t inkpot_cache_put ( inkpot_t *inkpot, IDX_NAMES name_idx ) +static inkpot_status_t inkpot_cache_put ( inkpot_t *inkpot, IDX_NAMES_t name_idx ) { - IDX_MRU_CACHE i; + IDX_MRU_CACHE_t i; for (i = 0; i < SZT_MRU_CACHE; i++) { if (inkpot->cache[i].next_recently_used_idx == SZT_MRU_CACHE) { @@ -322,7 +304,7 @@ static inkpot_status_t inkpot_put_name ( inkpot_t *inkpot ) inkpot_status_t rc; char *color; inkpot_name_t *name; - IDX_ALTS i; + IDX_ALTS_t i; if (inkpot == NULL || ! inkpot->scheme_bits) return ((inkpot->status = INKPOT_SCHEME_UNKNOWN)); @@ -363,19 +345,19 @@ static inkpot_status_t inkpot_put_name ( inkpot_t *inkpot ) static inkpot_status_t inkpot_put_index ( inkpot_t *inkpot, int index ) { - IDX_SCHEMES_INDEX j; - IDX_INDEXES first, last; - IDX_VALUES value_idx; + IDX_ICOLORS_t j; + IDX_INDEXES_t first, last; + IDX_VALUES_t value_idx; if (!inkpot->active_schemes) return ((inkpot->status = INKPOT_SCHEME_UNKNOWN)); j = inkpot->scheme_list[0]; - first = TAB_SCHEMES_INDEX[j].first_value_idx; - if (++j >= SZT_SCHEMES_INDEX) + first = TAB_ICOLORS[j].range_idx; + if (++j >= SZT_ICOLORS) last = SZT_INDEXES; else - last = TAB_SCHEMES_INDEX[j].first_value_idx; + last = TAB_ICOLORS[j].range_idx; last = last-1-first; /* clip user-provided index to fit available range */ @@ -424,9 +406,9 @@ inkpot_status_t inkpot_put_hsva ( inkpot_t *inkpot, double hsva[4] ) inkpot_status_t inkpot_put ( inkpot_t *inkpot, const char *color ) { inkpot_status_t rc = INKPOT_COLOR_UNKNOWN; - IDX_SCHEMES_INDEX j; - IDX_INDEXES first, last; - IDX_VALUES value_idx; + IDX_ICOLORS_t j; + IDX_INDEXES_t first, last; + IDX_VALUES_t value_idx; char *q, *s; const char *p; int i, c, len, index; @@ -504,15 +486,15 @@ inkpot_status_t inkpot_put ( inkpot_t *inkpot, const char *color ) *++q = '\0'; for (i=0; i < inkpot->active_schemes; i++) { j = inkpot->scheme_list[i]; - p = &TAB_STRINGS[TAB_SCHEMES_INDEX[j].scheme_string_idx]; + p = &TAB_STRINGS[TAB_ICOLORS[j].string_idx]; if (*p != *s || strcmp(p, s) != 0) continue; /* FIXME - deal with subschemes */ - first = TAB_SCHEMES_INDEX[j].first_value_idx; - if (++j >= SZT_SCHEMES_INDEX) + first = TAB_ICOLORS[j].range_idx; + if (++j >= SZT_ICOLORS) last = SZT_INDEXES; else - last = TAB_SCHEMES_INDEX[j].first_value_idx; + last = TAB_ICOLORS[j].range_idx; last = last-1-first; /* clip user-provided index to fit available range */ @@ -544,9 +526,9 @@ inkpot_status_t inkpot_put ( inkpot_t *inkpot, const char *color ) inkpot_status_t inkpot_get ( inkpot_t *inkpot, const char **color ) { inkpot_name_t *out_name; - IDX_NAMES t; - IDX_ALTS i; - IDX_VALUES value_idx; + IDX_NAMES_t t; + IDX_ALTS_t i; + IDX_VALUES_t value_idx; int maybe; /* FIXME - why isn't this checking the current value then the 4 level cache? */ @@ -763,8 +745,8 @@ inkpot_status_t inkpot_write_rgb8 ( inkpot_t *inkpot ) inkpot_status_t inkpot_debug_schemes( inkpot_t *inkpot ) { - IDX_SCHEMES i; - IDX_SCHEMES_INDEX j; + IDX_SCHEMES_t i; + IDX_ICOLORS_t j; int found; inkpot_puts(inkpot, "schemes:\n"); @@ -789,12 +771,12 @@ inkpot_status_t inkpot_debug_schemes( inkpot_t *inkpot ) } for (j = 0; j < inkpot->active_schemes; j++) { inkpot_puts(inkpot, " "); - inkpot_puts(inkpot, &TAB_STRINGS[TAB_SCHEMES_INDEX[inkpot->scheme_list[j]].scheme_string_idx]); + inkpot_puts(inkpot, &TAB_STRINGS[TAB_ICOLORS[inkpot->scheme_list[j]].string_idx]); inkpot_puts(inkpot, "#(in)"); } for (j = 0; j < inkpot->active_out_schemes; j++) { inkpot_puts(inkpot, " "); - inkpot_puts(inkpot, &TAB_STRINGS[TAB_SCHEMES_INDEX[inkpot->out_scheme_list[j]].scheme_string_idx]); + inkpot_puts(inkpot, &TAB_STRINGS[TAB_ICOLORS[inkpot->out_scheme_list[j]].string_idx]); inkpot_puts(inkpot, "#(out)"); } inkpot_puts(inkpot, "\n"); @@ -805,7 +787,7 @@ inkpot_status_t inkpot_debug_schemes( inkpot_t *inkpot ) #if 0 static inkpot_status_t inkpot_debug_scheme_names( inkpot_t *inkpot, int scheme_bits ) { - IDX_SCHEMES_NAME i; + IDX_SCHEMES_NAME_t i; int found = 0; inkpot_puts(inkpot, "("); @@ -837,14 +819,14 @@ static void inkpot_debug_rgba( inkpot_t *inkpot, VALUE value ) #endif #if 0 -static inkpot_status_t inkpot_debug_names_schemes( inkpot_t *inkpot, MSK_SCHEMES scheme_bits, IDX_SCHEMES_INDEX active, IDX_SCHEMES_NAME *scheme_index ) +static inkpot_status_t inkpot_debug_names_schemes( inkpot_t *inkpot, MSK_SCHEMES_t scheme_bits, IDX_ICOLORS_t active, IDX_SCHEMES_NAME_t *scheme_index ) { inkpot_name_t *name; - IDX_NAMES i; + IDX_NAMES_t i; #if 0 - IDX_SCHEMES_INDEX j; - IDX_INDEXES k, first, last; - IDX_VALUES v; + IDX_ICOLORS_t j; + IDX_INDEXES_t k, first, last; + IDX_VALUES_t v; char buf[20]; #endif @@ -862,12 +844,12 @@ static inkpot_status_t inkpot_debug_names_schemes( inkpot_t *inkpot, MSK_SCHEMES } #if 0 for (j=0; j < active; j++) { - first = scheme_index->first_value_idx; - j = scheme_index - TAB_SCHEMES_INDEX; - if (++j >= SZT_SCHEMES_INDEX) + first = scheme_index->range_idx; + j = scheme_index - TAB_ICOLORS; + if (++j >= SZT_ICOLORS) last = SZT_INDEXES; else - last = TAB_SCHEMES_INDEX[j].first_value_idx; + last = TAB_ICOLORS[j].range_idx; for (k = first; k < last; k++) { v = TAB_INDEXES[k]; @@ -911,9 +893,9 @@ inkpot_status_t inkpot_debug_values( inkpot_t *inkpot ) inkpot_status_t rc; inkpot_value_t *value; inkpot_name_t *name; - IDX_VALUES i; - IDX_NAMES t; - MSK_SCHEMES scheme_bits; + IDX_VALUES_t i; + IDX_NAMES_t t; + MSK_SCHEMES_t scheme_bits; int found; inkpot_puts(inkpot, "values:\n"); diff --git a/lib/inkpot/inkpot_scheme.h b/lib/inkpot/inkpot_scheme.h index 80eb96051..edca07b01 100644 --- a/lib/inkpot/inkpot_scheme.h +++ b/lib/inkpot/inkpot_scheme.h @@ -17,30 +17,27 @@ #ifndef INKPOT_STRUCTS_H #define INKPOT_STRUCTS_H -typedef unsigned char IDX_MRU_CACHE; +typedef unsigned char IDX_MRU_CACHE_t; #define SZT_MRU_CACHE 4 -typedef struct inkpot_scheme_name_s { - IDX_STRINGS +typedef struct inkpot_scheme_s { + IDX_STRINGS_t string_idx; /* The scheme name in TAB_STRINGS. (e.g. "x11") */ -} inkpot_scheme_name_t; +} inkpot_scheme_t; typedef struct inkpot_range_s { - IDX_INDEXES + IDX_INDEXES_t size, first_value_idx; } inkpot_range_t; -typedef struct inkpot_scheme_index_s { - IDX_STRINGS - scheme_string_idx; /* The indexed scheme name in TAB_STRINGS. e.g "brewer" */ +typedef struct inkpot_icolor_s { + IDX_STRINGS_t + string_idx; /* The icolor name in TAB_STRINGS. */ - IDX_STRINGS - subscheme_string_idx; /* The subscheme name in TAB_STRINGS. e.g "blues7" */ - - IDX_RANGES + IDX_RANGES_t range_idx; -} inkpot_scheme_index_t; +} inkpot_icolor_t; typedef struct inkpot_name_s { /* Color_name used by one or more * inkpot_scheme_name_t. Each instance has @@ -50,44 +47,46 @@ typedef struct inkpot_name_s { /* Color_name used by one or more * inkpot_names_t are alpha sorted in * TAB_NAMES[] */ - IDX_STRINGS + IDX_STRINGS_t string_idx; /* The color name in TAB_STRINGS. * (e.g. "green") */ - IDX_VALUES + IDX_VALUES_t value_idx; /* An index into TAB_VALUE for this * inkpot_name_t */ - MSK_SCHEMES + MSK_SCHEMES_t scheme_bits; /* A bit for each inkpot_scheme_name_t * that includes this inkpot_name_t */ } inkpot_name_t; typedef struct inkpot_cache_element_s { - IDX_MRU_CACHE + IDX_MRU_CACHE_t next_recently_used_idx; - MSK_SCHEMES + MSK_SCHEMES_t scheme_bits; - IDX_NAMES + IDX_NAMES_t name_idx; } inkpot_cache_element_t; /* typedef struct inkpot_s inkpot_t; */ /* public opaque type in inkpot.h */ struct inkpot_s { /* The Ink Pot */ - MSK_SCHEMES + MSK_SCHEMES_t scheme_bits, /* One bit per inkpot_scheme_name_t */ out_scheme_bit; /* One scheme only for output. */ - IDX_INDEXES + IDX_INDEXES_t index, /* The index for the current value in active_schemes_index */ out_index; /* The index for the current value in active_out_schemes_index */ - IDX_SCHEMES_INDEX - active_schemes, /* The number of active index schemes. */ - scheme_list[SZT_SCHEMES_INDEX], /* The list of active index schemes. */ - active_out_schemes, /* The number of active index schemes. */ - out_scheme_list[1]; /* The list of active index schemes. */ + int + active_schemes, /* The number of active index schemes. */ + active_out_schemes; /* The number of active index schemes. */ + + IDX_ICOLORS_t + scheme_list[SZT_ICOLORS], /* The list of active index schemes. */ + out_scheme_list[1]; /* The list of active index schemes. */ inkpot_name_t *out_name; /* The current output name, or NULL. */ @@ -100,7 +99,7 @@ struct inkpot_s { /* The Ink Pot */ inkpot_cache_element_t cache[SZT_MRU_CACHE];/* MRU chache of successful color lookups */ - IDX_MRU_CACHE + IDX_MRU_CACHE_t most_recently_used_idx; inkpot_write_disc_t -- 2.40.0