From 368bf51e6213d4825b33b28b0c94f272f8e4241a Mon Sep 17 00:00:00 2001 From: ellson Date: Mon, 29 Sep 2008 21:08:38 +0000 Subject: [PATCH] good progress --- lib/inkpot/Makefile.am | 4 +- lib/inkpot/inkpot_scheme.c | 97 +++++++++++++++++---------- lib/inkpot/inkpot_scheme.h | 14 +--- lib/inkpot/test/inkpot_define.h | 20 +++--- lib/inkpot/test/inkpot_scheme_table.h | 41 ++++++----- 5 files changed, 103 insertions(+), 73 deletions(-) diff --git a/lib/inkpot/Makefile.am b/lib/inkpot/Makefile.am index 61a2ffc2c..c0e0f5dd9 100644 --- a/lib/inkpot/Makefile.am +++ b/lib/inkpot/Makefile.am @@ -1,6 +1,6 @@ CFLAGS = -Wall -g -O0 -all: inkpot_table.h +try: try.o inkpot_scheme.o inkpot_xlate.o inkpot_value.o inkpot_scheme.o: inkpot_scheme.c inkpot_scheme.h inkpot.h inkpot_define.h \ inkpot_value.c inkpot_xlate.c inkpot_table.h @@ -18,4 +18,4 @@ x11.lib: data/rgb.txt scripts/rgb_txt_2_x11_lib.tcl scripts/rgb_txt_2_x11_lib.tcl data/rgb.txt clean: - rm -rf *.o test *.lib inkpot_table.h inkpot_define.h + rm -rf *.o try *.lib inkpot_table.h inkpot_define.h diff --git a/lib/inkpot/inkpot_scheme.c b/lib/inkpot/inkpot_scheme.c index a6c5b735c..1739d17c9 100644 --- a/lib/inkpot/inkpot_scheme.c +++ b/lib/inkpot/inkpot_scheme.c @@ -87,8 +87,8 @@ static inkpot_scheme_name_t *inkpot_find_scheme_name ( const char *scheme ) if (scheme == NULL) return NULL; return (inkpot_scheme_name_t *) bsearch( - (void*)scheme, (void*)TAB_SCHEMES_NAME, - SZT_SCHEMES_NAME, sizeof(inkpot_scheme_name_t), + (void*)scheme, (void*)TAB_SCHEMES, + SZT_SCHEMES, sizeof(inkpot_scheme_name_t), inkpot_scheme_name_cmpf); } @@ -121,7 +121,7 @@ static inkpot_status_t inkpot_scheme ( inkpot_t *inkpot, const char *scheme ) inkpot_scheme_name = inkpot_find_scheme_name(scheme); if (inkpot_scheme_name) { - inkpot->scheme_bits |= 1 << (inkpot_scheme_name - TAB_SCHEMES_NAME); + inkpot->scheme_bits |= 1 << (inkpot_scheme_name - TAB_SCHEMES); return ((inkpot->status = INKPOT_SUCCESS)); } @@ -179,14 +179,14 @@ inkpot_status_t inkpot_translate ( inkpot_t *inkpot, const char *scheme ) { inkpot_scheme_name_t *inkpot_scheme_name; inkpot_scheme_index_t *inkpot_scheme_index; - IDX_SCHEMES_NAME idx; + IDX_SCHEMES 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_NAME; + idx = inkpot_scheme_name - TAB_SCHEMES; if (! (inkpot->out_scheme_bit & (1 << idx))) { inkpot->out_scheme_bit = 1 << idx; inkpot->active_out_schemes = 0; @@ -297,8 +297,7 @@ static inkpot_status_t inkpot_set_name ( inkpot_t *inkpot ) inkpot_status_t rc; char *color; inkpot_name_t *name; - IDX_NAME_ALTS i; - IDX_NAMES base, top; + IDX_ALTS i; if (inkpot == NULL || ! inkpot->scheme_bits) return ((inkpot->status = INKPOT_SCHEME_UNKNOWN)); @@ -309,26 +308,31 @@ static inkpot_status_t inkpot_set_name ( inkpot_t *inkpot ) if (rc == INKPOT_SUCCESS) return rc; - for (i = 0; i < SZT_NAME_ALTS; ) { - base = TAB_NAME_ALTS[i++]; - if (i == SZT_NAME_ALTS) - top = SZT_NAMES; - else - top = TAB_NAME_ALTS[i]; - - name = (inkpot_name_t *) bsearch( - (void*)color, (void*)(&TAB_NAMES[base]), - top-base, sizeof(inkpot_name_t), - inkpot_name_cmpf); - if (name == NULL) - return ((inkpot->status = INKPOT_COLOR_UNKNOWN)); + name = (inkpot_name_t *) bsearch( + (void*)color, (void*)TAB_NAMES, + SZT_NAMES, sizeof(inkpot_name_t), + inkpot_name_cmpf); + if (name == NULL) + return ((inkpot->status = INKPOT_COLOR_UNKNOWN)); - if (inkpot->scheme_bits & name->scheme_bits) { + if (name->scheme_bits) { + if (inkpot->scheme_bits & name->scheme_bits) { rc = inkpot_set_value_idx(inkpot, name->value_idx); assert(rc == INKPOT_SUCCESS); return inkpot_cache_put(inkpot, (name - TAB_NAMES) ); } } + else { + for (i = name->value_idx; i < SZT_ALTS; i++) { + if (inkpot->scheme_bits & TAB_ALTS[i].scheme_bits) { + rc = inkpot_set_value_idx(inkpot, TAB_ALTS[i].value_idx); + assert(rc == INKPOT_SUCCESS); + return inkpot_cache_put(inkpot, (name - TAB_NAMES) ); + } + if (! TAB_ALTS[i].string_idx) + break; + } + } return ((inkpot->status = INKPOT_COLOR_UNKNOWN)); } @@ -518,7 +522,9 @@ 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; + int maybe; out_name = inkpot->out_name; if (out_name) { /* if we have a cached name */ @@ -532,15 +538,34 @@ inkpot_status_t inkpot_get ( inkpot_t *inkpot, const char **color ) if (inkpot->out_scheme_bit) { value_idx = inkpot->value.index; if (value_idx < SZT_VALUES) { - for (t = TAB_TONAMES[value_idx]; t < SZT_NAMES; t++) { - out_name = &TAB_NAMES[TAB_NAMES[t].toname_idx]; - if (out_name->value_idx != value_idx) - break; - if (out_name->scheme_bits & inkpot->out_scheme_bit) { - inkpot->out_name = out_name; - *color = &TAB_STRINGS[out_name->string_idx]; - return ((inkpot->status = INKPOT_SUCCESS)); - } + for (t = TAB_VALUE_TO[value_idx]; t < SZT_TO_NAMES; t++) { + out_name = &TAB_NAMES[TAB_TO_NAMES[t]]; + if (out_name->scheme_bits) { + if (out_name->value_idx != value_idx) + break; + if (out_name->scheme_bits & inkpot->out_scheme_bit) { + inkpot->out_name = out_name; + *color = &TAB_STRINGS[out_name->string_idx]; + return ((inkpot->status = INKPOT_SUCCESS)); + } + } + else { + maybe = 0; + for (i = out_name->value_idx; i < SZT_ALTS; i++) { + if ( TAB_ALTS[i].value_idx == value_idx) { + maybe++; + if (inkpot->out_scheme_bit & TAB_ALTS[i].scheme_bits) { + inkpot->out_name = out_name; + *color = &TAB_STRINGS[out_name->string_idx]; + return ((inkpot->status = INKPOT_SUCCESS)); + } + } + if (! TAB_ALTS[i].string_idx) + break; + } + if (!maybe) + break; + } } *color = NULL; return ((inkpot->status = INKPOT_COLOR_NONAME)); @@ -716,23 +741,23 @@ static void errputs(inkpot_t *inkpot, const char *s) inkpot_status_t inkpot_debug_schemes( inkpot_t *inkpot ) { - IDX_SCHEMES_NAME i; + IDX_SCHEMES i; IDX_SCHEMES_INDEX j; int found; errputs(inkpot, "schemes:\n"); - for (i = 0; i < SZT_SCHEMES_NAME; i++) { + for (i = 0; i < SZT_SCHEMES; i++) { found = 0; if ((1<scheme_bits) { errputs(inkpot, " "); - errputs(inkpot, &TAB_STRINGS[TAB_SCHEMES_NAME[i].string_idx]); + errputs(inkpot, &TAB_STRINGS[TAB_SCHEMES[i].string_idx]); errputs(inkpot, " (in)"); found++; } if ((1<out_scheme_bit) { if (! found) { errputs(inkpot, " "); - errputs(inkpot, &TAB_STRINGS[TAB_SCHEMES_NAME[i].string_idx]); + errputs(inkpot, &TAB_STRINGS[TAB_SCHEMES[i].string_idx]); } errputs(inkpot, " (out)"); } @@ -789,7 +814,7 @@ 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_NAME scheme_bits, IDX_SCHEMES_INDEX active, IDX_SCHEMES_NAME *scheme_index ) +static inkpot_status_t inkpot_debug_names_schemes( inkpot_t *inkpot, MSK_SCHEMES scheme_bits, IDX_SCHEMES_INDEX active, IDX_SCHEMES_NAME *scheme_index ) { inkpot_name_t *name; IDX_NAMES i; @@ -865,7 +890,7 @@ inkpot_status_t inkpot_debug_values( inkpot_t *inkpot ) inkpot_name_t *name; IDX_VALUES i; IDX_NAMES t; - MSK_SCHEMES_NAME scheme_bits; + MSK_SCHEMES scheme_bits; int found; errputs(inkpot, "values:\n"); diff --git a/lib/inkpot/inkpot_scheme.h b/lib/inkpot/inkpot_scheme.h index 3f1da0fd0..59950c922 100644 --- a/lib/inkpot/inkpot_scheme.h +++ b/lib/inkpot/inkpot_scheme.h @@ -53,23 +53,15 @@ typedef struct inkpot_name_s { /* Color_name used by one or more value_idx; /* An index into TAB_VALUE for this * inkpot_name_t */ - MSK_SCHEMES_NAME + MSK_SCHEMES scheme_bits; /* A bit for each inkpot_scheme_name_t * that includes this inkpot_name_t */ - - IDX_NAMES - toname_idx; /* This is the element of TAB_TONAME that - * indexes an element in TAB_NAME. - * TAB_TONAME is a logically separate table - * from TAB_NAMES, but it happens to be - * exactly the same SZT, so we are trying to - * get better packing by this merging */ } inkpot_name_t; typedef struct inkpot_cache_element_s { IDX_MRU_CACHE next_recently_used_idx; - MSK_SCHEMES_NAME + MSK_SCHEMES scheme_bits; IDX_NAMES name_idx; @@ -78,7 +70,7 @@ typedef struct inkpot_cache_element_s { /* typedef struct inkpot_s inkpot_t; */ /* public opaque type in inkpot.h */ struct inkpot_s { /* The Ink Pot */ - MSK_SCHEMES_NAME + MSK_SCHEMES scheme_bits, /* One bit per inkpot_scheme_name_t */ out_scheme_bit; /* One scheme only for output. */ diff --git a/lib/inkpot/test/inkpot_define.h b/lib/inkpot/test/inkpot_define.h index 2a5b02b0b..0ca7b10b4 100644 --- a/lib/inkpot/test/inkpot_define.h +++ b/lib/inkpot/test/inkpot_define.h @@ -18,23 +18,27 @@ typedef unsigned int IDX_STRINGS; #define SZT_STRINGS 79 #define SZL_STRINGS 6 -typedef unsigned short MSK_SCHEMES_NAME; -typedef unsigned char IDX_SCHEMES_NAME; -#define SZT_SCHEMES_NAME 3 +typedef unsigned short MSK_SCHEMES; +typedef unsigned char IDX_SCHEMES; +#define SZT_SCHEMES 3 typedef unsigned char IDX_SCHEMES_INDEX; #define SZT_SCHEMES_INDEX 2 typedef unsigned int IDX_NAMES; -#define SZT_NAMES 11 +#define SZT_NAMES 10 -typedef unsigned char IDX_NAME_ALTS; -#define SZT_NAME_ALTS 2 +typedef unsigned char IDX_ALTS; +#define SZT_ALTS 2 typedef unsigned int IDX_IXVALUES; #define SZT_IXVALUES 7 -typedef unsigned int IDX_TONAMES; -#define SZT_TONAMES 7 + +typedef unsigned int IDX_VALUE_TO; +#define SZT_VALUE_TO 7 + +typedef unsigned int IDX_TO_NAMES; +#define SZT_TO_NAMES 11 typedef unsigned int IDX_VALUES; #define SZT_VALUES 7 diff --git a/lib/inkpot/test/inkpot_scheme_table.h b/lib/inkpot/test/inkpot_scheme_table.h index c5487790d..8f3e6be2a 100644 --- a/lib/inkpot/test/inkpot_scheme_table.h +++ b/lib/inkpot/test/inkpot_scheme_table.h @@ -32,7 +32,7 @@ const char TAB_STRINGS[SZT_STRINGS] = { "yyy\0" }; -inkpot_scheme_name_t TAB_SCHEMES_NAME[SZT_SCHEMES_NAME] = { /* schemes of named colors */ +inkpot_scheme_name_t TAB_SCHEMES[SZT_SCHEMES] = { /* schemes of named colors */ { 0, }, /* french */ { 7, }, /* svg */ { 11, }, /* x11 */ @@ -44,25 +44,24 @@ inkpot_scheme_index_t TAB_SCHEMES_INDEX[SZT_SCHEMES_INDEX] = { /* schemes of ind }; 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 */ + { 15, 0, 0x6, }, /* black */ + { 21, 1, 0x1, }, /* bleu */ + { 26, 1, 0x6, }, /* blue */ + { 31, 2, 0x6, }, /* green */ + { 37, 5, 0x1, }, /* jaune */ + { 43, 3, 0x6, }, /* red */ + { 47, 3, 0x1, }, /* rouge */ + { 53, 2, 0x1, }, /* vert */ + { 65, 6, 0x6, }, /* white */ + { 58, 0, 0, }, /* yellow */ }; -IDX_NAMES TAB_NAME_ALTS[SZT_NAME_ALTS] = { - 0, 10, +inkpot_name_t TAB_ALTS[SZT_ALTS] = { + { 1, 5, 0x4, }, /* yellow (x11) */ + { 0, 4, 0x2, }, /* yellow (svg) */ }; -IDX_TONAMES TAB_TONAMES[SZT_TONAMES] = { +IDX_VALUE_TO TAB_VALUE_TO[SZT_VALUE_TO] = { 0, /* black */ 1, /* bleu, blue */ 3, /* green, vert */ @@ -72,6 +71,16 @@ IDX_TONAMES TAB_TONAMES[SZT_TONAMES] = { 10, /* white */ }; +IDX_NAMES TAB_TO_NAMES[SZT_TO_NAMES] = { + 0, /* black */ + 1, 2, /* bleu, blue */ + 3, 7, /* green, vert */ + 5, 6, /* red, rouge */ + 9, /* yellow(alt1) */ + 4, 9, /* jaune, yellow */ + 8, /* white */ +}; + IDX_VALUES TAB_IXVALUES[SZT_IXVALUES] = { 7, 8, 9, 10, 1, /* xxx */ 0, 6, /* yyy */ -- 2.40.0