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
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
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);
}
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));
}
{
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;
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));
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));
}
{
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 */
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));
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<<i) & inkpot->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<<i) & inkpot->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)");
}
#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;
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");
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;
/* 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. */
#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
"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 */
};
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 */
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 */