]> granicus.if.org Git - graphviz/commitdiff
good progress
authorellson <devnull@localhost>
Mon, 29 Sep 2008 21:08:38 +0000 (21:08 +0000)
committerellson <devnull@localhost>
Mon, 29 Sep 2008 21:08:38 +0000 (21:08 +0000)
lib/inkpot/Makefile.am
lib/inkpot/inkpot_scheme.c
lib/inkpot/inkpot_scheme.h
lib/inkpot/test/inkpot_define.h
lib/inkpot/test/inkpot_scheme_table.h

index 61a2ffc2c08bbfca53fdebb9c594b73dab8d6252..c0e0f5dd9e1d41a91033b111490e3940fef807e0 100644 (file)
@@ -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
index a6c5b735cbb61226162e7eb2d7d2ee1adc5fc240..1739d17c993de51b5fa378c033f8a98bc3c1dfe8 100644 (file)
@@ -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<<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)");
         }
@@ -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");
index 3f1da0fd084fc30adf0c6c1a91bbdcb92aa50958..59950c922496c9f21702497440f0d2539219e910 100644 (file)
@@ -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. */
 
index 2a5b02b0b0d2d04f71193524e3c9dd5cbaebc0b3..0ca7b10b466562b847f2d346be59415da3c62238 100644 (file)
@@ -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
index c5487790d20ad0ab706851babda9632f53c1bd42..8f3e6be2afede0ec702dc85aa6a24a47e683a223 100644 (file)
@@ -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 */