From 3a966b284204ccd07ac46bbf589f92434766a941 Mon Sep 17 00:00:00 2001 From: ellson Date: Wed, 24 Sep 2008 19:46:37 +0000 Subject: [PATCH] establish the real api --- lib/inkpot/inkpot.h | 74 +++++---------- lib/inkpot/inkpot_scheme.c | 184 +++++++++++++++++++++---------------- lib/inkpot/inkpot_xlate.c | 172 +++++++--------------------------- lib/inkpot/test.c | 26 +++--- 4 files changed, 175 insertions(+), 281 deletions(-) diff --git a/lib/inkpot/inkpot.h b/lib/inkpot/inkpot.h index 5879e9db2..5b87b4b3e 100644 --- a/lib/inkpot/inkpot.h +++ b/lib/inkpot/inkpot.h @@ -14,77 +14,45 @@ * AT&T Research, Florham Park NJ * **********************************************************/ -#ifndef COLOR_H -#define COLOR_H +#ifndef INKPOT_H +#define INKPOT_H #ifdef __cplusplus extern "C" { #endif -#ifndef MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif - -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - typedef enum { INKPOT_SUCCESS=0, INKPOT_MALLOC_FAIL, INKPOT_COLOR_UNKNOWN, INKPOT_SCHEME_UNKNOWN, - INKPOT_MAX_ONE_INDEXED_SCHEME + INKPOT_MAX_ONE_INDEXED_SCHEME, + INKPOT_FAIL } inkpot_status_t; typedef struct inkpot_s inkpot_t; -/* possible representations of color in gvcolor_t */ -typedef enum { - HSVA_DOUBLE, - RGBA_DOUBLE, - RGBA_WORD, - RGBA_BYTE, - CMYK_BYTE, - COLOR_STRING, - COLOR_INDEX -} color_type_t; - -/* gvcolor_t can hold a color spec in a choice or representations */ -typedef struct gvcolor_s { - union { - double HSVA[4]; - double RGBA[4]; - int rrggbbaa[4]; - unsigned char rgba[4]; - unsigned char cmyk[4]; - char *string; - int index; - } u; - color_type_t type; -} gvcolor_t; - -extern inkpot_status_t inkpot_init( inkpot_t **inkpot ); -extern inkpot_status_t inkpot_clear( inkpot_t *inkpot ); -extern inkpot_status_t inkpot_add( inkpot_t *inkpot, const char *scheme ); +extern inkpot_status_t inkpot_init ( inkpot_t **inkpot ); +extern inkpot_status_t inkpot_clear ( inkpot_t *inkpot ); +extern inkpot_status_t inkpot_activate ( inkpot_t *inkpot, const char *scheme ); -extern inkpot_status_t inkpot_find( inkpot_t *inkpot, const char *color ); -extern inkpot_status_t inkpot_find_default( inkpot_t *inkpot); -extern void inkpot_get_rgba( inkpot_t *inkpot, - unsigned int *r, unsigned int *g, unsigned int *b, unsigned int *a); -extern void inkpot_get_hsva( inkpot_t *inkpot, - unsigned int *h, unsigned int *s, unsigned int *v, unsigned int *a); +extern inkpot_status_t inkpot_set ( inkpot_t *inkpot, const char *color ); +extern inkpot_status_t inkpot_set_default ( inkpot_t *inkpot ); +extern inkpot_status_t inkpot_set_rgba ( inkpot_t *inkpot, unsigned int rgba[4] ); -extern void inkpot_print_schemes( inkpot_t *inkpot ); -extern void inkpot_print_names( inkpot_t *inkpot ); -extern void inkpot_print_values( inkpot_t *inkpot ); -extern void inkpot_print_rgba( inkpot_t *inkpot ); +extern inkpot_status_t inkpot_get ( inkpot_t *inkpot, const char *scheme, const char **color ); +extern inkpot_status_t inkpot_get_rgba ( inkpot_t *inkpot, unsigned int *rgba ); +extern inkpot_status_t inkpot_get_hsva ( inkpot_t *inkpot, unsigned int *hsva ); +extern inkpot_status_t inkpot_get_cmyk ( inkpot_t *inkpot, unsigned int *cmyk ); +extern inkpot_status_t inkpot_get_RGBA ( inkpot_t *inkpot, double *RGBA ); +extern inkpot_status_t inkpot_get_HSVA ( inkpot_t *inkpot, double *HSVA ); +extern inkpot_status_t inkpot_get_index ( inkpot_t *inkpot, unsigned int *index ); -extern int setColorScheme (const char* s); -extern inkpot_status_t colorxlate(const char *str, gvcolor_t * color, color_type_t target_type); -extern char *canontoken(const char *str); +extern inkpot_status_t inkpot_print_schemes ( inkpot_t *inkpot, FILE *out ); +extern inkpot_status_t inkpot_print_names ( inkpot_t *inkpot, FILE *out ); +extern inkpot_status_t inkpot_print_values ( inkpot_t *inkpot, FILE *out ); #ifdef __cplusplus } #endif -#endif /* COLOR_H */ +#endif /* INKPOT_H */ diff --git a/lib/inkpot/inkpot_scheme.c b/lib/inkpot/inkpot_scheme.c index 7e396b27a..5b947175b 100644 --- a/lib/inkpot/inkpot_scheme.c +++ b/lib/inkpot/inkpot_scheme.c @@ -21,6 +21,7 @@ #include "inkpot.h" #include "inkpot_tables.h" +#include "inkpot_xlate.h" static int string_cmpf (const char *k, const char *b) { @@ -41,7 +42,7 @@ static int inkpot_scheme_name_cmpf ( const void *key, const void *base) return string_cmpf(k, b); } -static inkpot_scheme_name_t *inkpot_find_scheme_name ( const char *scheme ) +static inkpot_scheme_name_t *inkpot_activate_name ( const char *scheme ) { if (scheme == NULL) return NULL; @@ -59,7 +60,7 @@ static int inkpot_scheme_index_cmpf ( const void *key, const void *base) return string_cmpf(k, b); } -static inkpot_scheme_index_t *inkpot_find_scheme_index ( const char *scheme ) +static inkpot_scheme_index_t *inkpot_activate_index ( const char *scheme ) { if (scheme == NULL) return NULL; @@ -85,7 +86,7 @@ inkpot_status_t inkpot_init ( inkpot_t **inkpot) return inkpot_clear ( *inkpot ); } -inkpot_status_t inkpot_add ( inkpot_t *inkpot, const char *scheme ) +inkpot_status_t inkpot_activate ( inkpot_t *inkpot, const char *scheme ) { inkpot_scheme_name_t *inkpot_scheme_name; inkpot_scheme_index_t *inkpot_scheme_index; @@ -93,7 +94,7 @@ inkpot_status_t inkpot_add ( inkpot_t *inkpot, const char *scheme ) if (scheme == NULL) return INKPOT_SCHEME_UNKNOWN; - inkpot_scheme_name = inkpot_find_scheme_name(scheme); + inkpot_scheme_name = inkpot_activate_name(scheme); if (inkpot_scheme_name) { idx = inkpot_scheme_name - TAB_SCHEMES_NAME; if (! inkpot->scheme_bits) { @@ -112,7 +113,7 @@ inkpot_status_t inkpot_add ( inkpot_t *inkpot, const char *scheme ) } } else { - inkpot_scheme_index = inkpot_find_scheme_index(scheme); + inkpot_scheme_index = inkpot_activate_index(scheme); if (! inkpot_scheme_index) return INKPOT_SCHEME_UNKNOWN; if (inkpot->scheme_index != inkpot_scheme_index) { @@ -139,7 +140,7 @@ static int inkpot_name_cmpf ( const void *key, const void *base) return string_cmpf(k, b); } -static inkpot_status_t inkpot_find_name ( inkpot_t *inkpot, const char *color ) +static inkpot_status_t inkpot_set_name ( inkpot_t *inkpot, const char *color ) { inkpot_name_t *name; const char *last_name; @@ -148,7 +149,7 @@ static inkpot_status_t inkpot_find_name ( inkpot_t *inkpot, const char *color ) if (inkpot == NULL) return INKPOT_SCHEME_UNKNOWN; - if (name == NULL) + if (color == NULL) return INKPOT_COLOR_UNKNOWN; if (! inkpot->name /* if we can't use the last result */ || ! ((last_name = &TAB_STRINGS[inkpot->name->string_idx])) @@ -177,7 +178,7 @@ static inkpot_status_t inkpot_find_name ( inkpot_t *inkpot, const char *color ) return INKPOT_SUCCESS; } -static inkpot_status_t inkpot_find_index ( inkpot_t *inkpot, int index ) +static inkpot_status_t inkpot_set_index ( inkpot_t *inkpot, int index ) { inkpot_scheme_index_t *scheme_index; IDX_SCHEMES_INDEX j; @@ -205,21 +206,21 @@ static inkpot_status_t inkpot_find_index ( inkpot_t *inkpot, int index ) return INKPOT_SUCCESS; } -inkpot_status_t inkpot_find( inkpot_t *inkpot, const char *color ) +inkpot_status_t inkpot_set( inkpot_t *inkpot, const char *color ) { int index; inkpot_status_t rc = INKPOT_COLOR_UNKNOWN; if (color && sscanf(color, "%d", &index) == 1) - rc = inkpot_find_index(inkpot, index); + rc = inkpot_set_index(inkpot, index); if (rc != INKPOT_SUCCESS) - rc = inkpot_find_name(inkpot, color); + rc = inkpot_set_name(inkpot, color); return rc; } -inkpot_status_t inkpot_find_default( inkpot_t *inkpot ) +inkpot_status_t inkpot_set_default( inkpot_t *inkpot ) { inkpot->value = &TAB_VALUES[inkpot->default_value_idx]; return INKPOT_SUCCESS; @@ -241,7 +242,7 @@ static int inkpot_value_cmpf ( const void *key, const void *base) return 0; } -static int inkpot_find_value ( inkpot_t *inkpot ) +static int inkpot_set_value ( inkpot_t *inkpot ) { inkpot_value_t *rc, *value = inkpot->value; inkpot_name_t *name; @@ -292,88 +293,113 @@ static int inkpot_find_value ( inkpot_t *inkpot ) return INKPOT_COLOR_UNKNOWN; } -void inkpot_get_rgba ( inkpot_t *inkpot, unsigned int *r, unsigned int *g, unsigned int *b, unsigned int *a) +inkpot_status_t inkpot_get ( inkpot_t *inkpot, const char *scheme, const char **color ) +{ + /* FIXME */ + return INKPOT_FAIL; +} + +inkpot_status_t inkpot_get_rgba ( inkpot_t *inkpot, unsigned int *rgba ) { unsigned char *t = &(inkpot->value->r); - if (r) *r = *t; t++; - if (g) *g = *t; t++; - if (b) *b = *t; t++; - if (a) *a = *t; t++; + *rgba++ = *t++; + *rgba++ = *t++; + *rgba++ = *t++; + *rgba = *t; + + return INKPOT_SUCCESS; } -void inkpot_get_hsva ( inkpot_t *inkpot, unsigned int *h, unsigned int *s, unsigned int *v, unsigned int *a) +inkpot_status_t inkpot_get_hsva ( inkpot_t *inkpot, unsigned int *hsva ) { - unsigned char *t = &(inkpot->value->a); + unsigned char *t = &(inkpot->value->h); - if (a) *a = *t; t++; - if (h) *h = *t; t++; - if (s) *s = *t; t++; - if (v) *v = *t; t++; + *hsva++ = *t++; + *hsva++ = *t++; + *hsva++ = *t; + --t; --t, --t; *hsva = *t; + + return INKPOT_SUCCESS; +} + +inkpot_status_t inkpot_get_cmyk ( inkpot_t *inkpot, unsigned int *cmyk ) +{ + /* FIXME */ + return INKPOT_FAIL; +} + +inkpot_status_t inkpot_get_RGBA ( inkpot_t *inkpot, double *RGBA ) +{ + /* FIXME */ + return INKPOT_FAIL; +} + +inkpot_status_t inkpot_get_HSVA ( inkpot_t *inkpot, double *HSVA ) +{ + /* FIXME */ + return INKPOT_FAIL; +} + +inkpot_status_t inkpot_get_index ( inkpot_t *inkpot, unsigned int *index ) +{ + /* FIXME */ + return INKPOT_FAIL; } + inkpot_status_t inkpot_xlate(inkpot_t *from_scheme, inkpot_t *to_scheme) { - return inkpot_find_value(to_scheme); + return inkpot_set_value(to_scheme); } -void inkpot_print_schemes( inkpot_t *inkpot ) +inkpot_status_t inkpot_print_schemes( inkpot_t *inkpot, FILE *out ) { IDX_SCHEMES_NAME i; - fprintf(stderr, "schemes:\n"); + fprintf(out, "schemes:\n"); for (i = 0; i < SZT_SCHEMES_NAME; i++) { if ((1<scheme_bits) { - fprintf (stderr, "%s", &TAB_STRINGS[TAB_SCHEMES_NAME[i].string_idx]); + fprintf (out, "%s", &TAB_STRINGS[TAB_SCHEMES_NAME[i].string_idx]); if (i == inkpot->default_scheme_name_idx) - fprintf (stderr, " (default)"); - fprintf (stderr, "\n"); + fprintf (out, " (default)"); + fprintf (out, "\n"); } } if (inkpot->scheme_index) - fprintf (stderr, "%s (indexed)\n", &TAB_STRINGS[inkpot->scheme_index->string_idx]); - fprintf(stderr, "\n"); + fprintf (out, "%s (indexed)\n", &TAB_STRINGS[inkpot->scheme_index->string_idx]); + fprintf(out, "\n"); + + return INKPOT_SUCCESS; } -static void inkpot_print_scheme_names( inkpot_t *inkpot, int scheme_bits) +static inkpot_status_t inkpot_print_scheme_names( inkpot_t *inkpot, int scheme_bits, FILE *out) { IDX_SCHEMES_NAME i; int found = 0; - fprintf(stderr, "("); + fprintf(out, "("); for (i = 0; i < SZT_SCHEMES_NAME; i++) { if ((1 << i) & scheme_bits) { if (found++) - fprintf(stderr, " "); - fprintf (stderr, "%s", &TAB_STRINGS[TAB_SCHEMES_NAME[i].string_idx]); + fprintf(out, " "); + fprintf (out, "%s", &TAB_STRINGS[TAB_SCHEMES_NAME[i].string_idx]); } } - fprintf(stderr, ")"); -} + fprintf(out, ")"); -static void inkpot_print_rgba_value( inkpot_value_t *value ) -{ - fprintf (stderr, "%d,%d,%d,%d", - value->r, value->g, value->b, value->a); -} - -void inkpot_print_rgba( inkpot_t *inkpot ) -{ - inkpot_print_rgba_value( inkpot->value ); + return INKPOT_SUCCESS; } -static void inkpot_print_hsva_value(inkpot_value_t *value ) +static inkpot_status_t inkpot_print_rgba( inkpot_value_t *value, FILE *out ) { - fprintf (stderr, " %d,%d,%d,%d\n", - value->h, value->s, value->v, value->a); -} + fprintf (out, "%d,%d,%d,%d", + value->r, value->g, value->b, value->a); -void inkpot_print_hsva( inkpot_t *inkpot ) -{ - inkpot_print_hsva_value( inkpot->value ); + return INKPOT_SUCCESS; } -void inkpot_print_names( inkpot_t *inkpot ) +inkpot_status_t inkpot_print_names( inkpot_t *inkpot, FILE *out ) { inkpot_name_t *name; inkpot_value_t *value; @@ -383,7 +409,7 @@ void inkpot_print_names( inkpot_t *inkpot ) BIT_SCHEMES_NAME inkpot_scheme_bits, scheme_bits; IDX_IXVALUES k, first, last; - fprintf(stderr, "names:\n"); + fprintf(out, "names:\n"); inkpot_scheme_bits = inkpot->scheme_bits; if (inkpot_scheme_bits) { for (i = 0; i < SZT_NAMES; i++) { @@ -391,11 +417,11 @@ void inkpot_print_names( inkpot_t *inkpot ) scheme_bits = name->scheme_bits & inkpot_scheme_bits; if (scheme_bits) { value = &TAB_VALUES[name->value_idx]; - fprintf(stderr, "%s", &TAB_STRINGS[TAB_NAMES[i].string_idx]); - inkpot_print_scheme_names(inkpot, scheme_bits); - fprintf(stderr, " "); - inkpot_print_rgba_value(value); - fprintf(stderr, "\n"); + fprintf(out, "%s", &TAB_STRINGS[TAB_NAMES[i].string_idx]); + inkpot_print_scheme_names(inkpot, scheme_bits, out); + fprintf(out, " "); + inkpot_print_rgba(value, out); + fprintf(out, "\n"); } } } @@ -411,15 +437,17 @@ void inkpot_print_names( inkpot_t *inkpot ) for (k = first; k < last; k++) { value = &TAB_VALUES[TAB_IXVALUES[j]]; - fprintf (stderr, "%d(%s) ", k - first , &TAB_STRINGS[scheme_index->string_idx]); - inkpot_print_rgba_value(value); - fprintf(stderr, "\n"); + fprintf (out, "%d(%s) ", k - first , &TAB_STRINGS[scheme_index->string_idx]); + inkpot_print_rgba(value, out); + fprintf(out, "\n"); } } - fprintf(stderr, "\n"); + fprintf(out, "\n"); + + return INKPOT_SUCCESS; } -void inkpot_print_values( inkpot_t *inkpot ) +inkpot_status_t inkpot_print_values( inkpot_t *inkpot, FILE *out ) { inkpot_value_t *value; inkpot_name_t *name; @@ -431,7 +459,7 @@ void inkpot_print_values( inkpot_t *inkpot ) IDX_IXVALUES k, first, last; int found; - fprintf(stderr, "values:\n"); + fprintf(out, "values:\n"); for (i = 0; i < SZT_VALUES; i++) { value = &TAB_VALUES[i]; found = 0; @@ -442,11 +470,11 @@ void inkpot_print_values( inkpot_t *inkpot ) scheme_bits = name->scheme_bits & inkpot->scheme_bits; if (scheme_bits) { if (found++) - fprintf(stderr, " "); + fprintf(out, " "); else - inkpot_print_rgba_value(value); - fprintf(stderr, " %s", &TAB_STRINGS[name->string_idx]); - inkpot_print_scheme_names(inkpot, scheme_bits); + inkpot_print_rgba(value, out); + fprintf(out, " %s", &TAB_STRINGS[name->string_idx]); + inkpot_print_scheme_names(inkpot, scheme_bits, out); } } scheme_index = inkpot->scheme_index; @@ -462,18 +490,20 @@ void inkpot_print_values( inkpot_t *inkpot ) for (k = first; k < last; k++) { if (TAB_IXVALUES[k] == i) { if (found++) - fprintf(stderr, " "); + fprintf(out, " "); else { - inkpot_print_rgba_value(value); - fprintf(stderr, " "); + inkpot_print_rgba(value, out); + fprintf(out, " "); } - fprintf(stderr, "%d(%s)", k - first, &TAB_STRINGS[scheme_index->string_idx]); + fprintf(out, "%d(%s)", k - first, &TAB_STRINGS[scheme_index->string_idx]); break; } } } if (found) - fprintf(stderr, "\n"); + fprintf(out, "\n"); } - fprintf(stderr, "\n"); + fprintf(out, "\n"); + + return INKPOT_SUCCESS; } diff --git a/lib/inkpot/inkpot_xlate.c b/lib/inkpot/inkpot_xlate.c index 9f9068f0d..a2494a36e 100644 --- a/lib/inkpot/inkpot_xlate.c +++ b/lib/inkpot/inkpot_xlate.c @@ -18,19 +18,9 @@ #include #include #include -#ifdef WIN32 -#include "compat.h" -#endif #include "inkpot.h" - -static inkpot_t *inkpot; -static const char *colorscheme; - -#ifdef WIN32 -extern int strcasecmp(const char *s1, const char *s2); -extern int strncasecmp(const char *s1, const char *s2, unsigned int n); -#endif +#include "inkpot_xlate.h" static void hsv2rgb(double h, double s, double v, double *r, double *g, double *b) { @@ -129,7 +119,8 @@ static void rgb2cmyk(double r, double g, double b, double *c, double *m, double *y -= *k; } -char *canontoken(const char *str) +#if 0 +static char *canoncolortoken(const char *str) { static char *canon; static int allocated; @@ -147,8 +138,8 @@ char *canontoken(const char *str) } q = canon; while ((c = *p++)) { - /* if (isalnum(c) == FALSE) */ - /* continue; */ + if (! isalnum(c)) + continue; if (isupper(c)) c = tolower(c); *q++ = c; @@ -156,84 +147,7 @@ char *canontoken(const char *str) *q = '\0'; return canon; } - -/* fullColor: - * Return "/prefix/str" - */ -static char* fullColor (const char* prefix, const char* str) -{ - static char *fulls; - static int allocated; - int len = strlen (prefix) + strlen (str) + 3; - - if (len >= allocated) { - allocated = len + 10; - fulls = realloc(fulls, allocated); - } - sprintf (fulls, "/%s/%s", prefix, str); - return fulls; -} - -/* resolveColor: - * Resolve input color str allowing color scheme namespaces. - * 0) "black" => "black" - * NB: This is something of a hack due to the remaining codegen. - * Once these are gone, this case could be removed and all references - * to "black" could be replaced by "/x11/black". - * 1) No initial / => - * if colorscheme is defined and no "x11", return /colorscheme/str - * else return str - * 2) One initial / => return str+1 - * 3) Two initial /'s => - * a) If colorscheme is defined and not "x11", return /colorscheme/(str+2) - * b) else return (str+2) - * 4) Two /'s, not both initial => return str. - * - * Note that 1), 2), and 3b) allow the default x11 color scheme. - * - * In other words, - * xxx => /colorscheme/xxx if colorscheme is defined and not "x11" - * xxx => xxx otherwise - * /xxx => xxx - * /x11/yyy => yyy - * /xxx/yyy => /xxx/yyy - * //yyy => /colorscheme/yyy if colorscheme is defined and not "x11" - * //yyy => yyy otherwise - * - * At present, no other error checking is done. For example, - * yyy could be "". This will be caught later. - */ - -#define DFLT_SCHEME "x11/" /* Must have final '/' */ -#define DFLT_SCHEME_LEN ((sizeof(DFLT_SCHEME)-1)/sizeof(char)) -#define ISNONDFLT(s) ((s) && *(s) && strncasecmp(DFLT_SCHEME, s, DFLT_SCHEME_LEN-1)) - -static char* resolveColor (const char* str) -{ - const char* s; - const char* ss; /* second slash */ - const char* c2; /* second char */ - - if ((*str == 'b') || !strncmp(str+1,"lack",4)) return (char*)str; - else if (*str == '/') { /* if begins with '/' */ - c2 = str+1; - if ((ss = strchr(c2, '/'))) { /* if has second '/' */ - if (*c2 == '/') { /* if second '/' is second character */ - /* Do not compare against final '/' */ - if (ISNONDFLT(colorscheme)) - s = fullColor (colorscheme, c2+1); - else - s = c2+1; - } - else if (strncasecmp(DFLT_SCHEME, c2, DFLT_SCHEME_LEN)) s = str; - else s = ss + 1; - } - else s = c2; - } - else if (ISNONDFLT(colorscheme)) s = fullColor (colorscheme, str); - else s = str; - return canontoken(s); -} +#endif inkpot_status_t colorxlate(const char *str, gvcolor_t * color, color_type_t target_type) { @@ -243,10 +157,10 @@ inkpot_status_t colorxlate(const char *str, gvcolor_t * color, color_type_t targ unsigned char c; double H, S, V, A, R, G, B; double C, M, Y, K; - unsigned int r, g, b, a, h, s, v; + unsigned int r, g, b, a; + unsigned int rgba[4], hsva[4]; int len; inkpot_status_t rc; - const char *key; color->type = target_type; @@ -378,31 +292,28 @@ inkpot_status_t colorxlate(const char *str, gvcolor_t * color, color_type_t targ } } - /* test for known color name */ -// key = resolveColor(str); - key = str; - rc = inkpot_find(inkpot, key); +// rc = inkpot_set(inkpot, str); if (rc == INKPOT_SUCCESS) { switch (target_type) { case HSVA_DOUBLE: - inkpot_get_hsva(inkpot, &h, &s, &v, &a); - color->u.HSVA[0] = h / 255.0; - color->u.HSVA[1] = s / 255.0; - color->u.HSVA[2] = v / 255.0; - color->u.HSVA[3] = a / 255.0; +// inkpot_get_hsva(inkpot, hsva); + color->u.HSVA[0] = hsva[0] / 255.0; + color->u.HSVA[1] = hsva[1] / 255.0; + color->u.HSVA[2] = hsva[2] / 255.0; + color->u.HSVA[3] = hsva[3] / 255.0; break; case RGBA_BYTE: - inkpot_get_rgba(inkpot, &r, &g, &b, &a); - color->u.rgba[0] = r; - color->u.rgba[1] = g; - color->u.rgba[2] = b; - color->u.rgba[3] = a; +// inkpot_get_rgba(inkpot, rgba); + color->u.rgba[0] = rgba[0]; + color->u.rgba[1] = rgba[1]; + color->u.rgba[2] = rgba[2]; + color->u.rgba[3] = rgba[3]; break; case CMYK_BYTE: - inkpot_get_rgba(inkpot, &r, &g, &b, &a); - R = r / 255.0; - G = g / 255.0; - B = b / 255.0; +// inkpot_get_rgba(inkpot, rgba); + R = rgba[0] / 255.0; + G = rgba[1] / 255.0; + B = rgba[2] / 255.0; rgb2cmyk(R, G, B, &C, &M, &Y, &K); color->u.cmyk[0] = (int) C * 255; color->u.cmyk[1] = (int) M * 255; @@ -410,18 +321,18 @@ inkpot_status_t colorxlate(const char *str, gvcolor_t * color, color_type_t targ color->u.cmyk[3] = (int) K * 255; break; case RGBA_WORD: - inkpot_get_rgba(inkpot, &r, &g, &b, &a); - color->u.rrggbbaa[0] = r * 65535 / 255; - color->u.rrggbbaa[1] = g * 65535 / 255; - color->u.rrggbbaa[2] = b * 65535 / 255; - color->u.rrggbbaa[3] = a * 65535 / 255; +// inkpot_get_rgba(inkpot, rgba); + color->u.rrggbbaa[0] = rgba[0] * 65535 / 255; + color->u.rrggbbaa[1] = rgba[1] * 65535 / 255; + color->u.rrggbbaa[2] = rgba[2] * 65535 / 255; + color->u.rrggbbaa[3] = rgba[3] * 65535 / 255; break; case RGBA_DOUBLE: - inkpot_get_rgba(inkpot, &r, &g, &b, &a); - color->u.RGBA[0] = r / 255.0; - color->u.RGBA[1] = g / 255.0; - color->u.RGBA[2] = b / 255.0; - color->u.RGBA[3] = a / 255.0; +// inkpot_get_rgba(inkpot, rgba); + color->u.RGBA[0] = rgba[0] / 255.0; + color->u.RGBA[1] = rgba[1] / 255.0; + color->u.RGBA[2] = rgba[2] / 255.0; + color->u.RGBA[3] = rgba[3] / 255.0; break; case COLOR_STRING: break; @@ -461,20 +372,3 @@ inkpot_status_t colorxlate(const char *str, gvcolor_t * color, color_type_t targ } return rc; } - -/* setColorScheme: - * Set current color scheme for resolving names. - */ -int setColorScheme (const char* scheme) -{ - inkpot_status_t rc; - - colorscheme = scheme; - rc = inkpot_init(&inkpot); - if (rc != INKPOT_SUCCESS) - return rc; - return inkpot_add(inkpot, scheme); -} - - - diff --git a/lib/inkpot/test.c b/lib/inkpot/test.c index e281e285e..a97a16d2f 100644 --- a/lib/inkpot/test.c +++ b/lib/inkpot/test.c @@ -9,7 +9,7 @@ int main (int argc, char *argv[]) inkpot_status_t rc; char *color; int i; - unsigned int r, g, b, a; + unsigned int rgba[4]; rc = inkpot_init(&inkpot); if (rc == INKPOT_MALLOC_FAIL) { @@ -18,12 +18,12 @@ int main (int argc, char *argv[]) } if (argc < 3) { - rc = inkpot_add(inkpot, "x11"); + rc = inkpot_activate(inkpot, "x11"); assert(rc == INKPOT_SUCCESS); } else { for (i = 2; i < argc; i++) { - rc = inkpot_add(inkpot, argv[i]); + rc = inkpot_activate(inkpot, argv[i]); if (rc == INKPOT_SCHEME_UNKNOWN) { fprintf (stderr, "color scheme \"%s\" was not found\n", argv[i]); } @@ -36,27 +36,29 @@ int main (int argc, char *argv[]) } } - inkpot_print_schemes(inkpot); + inkpot_print_schemes(inkpot, stderr); - inkpot_print_names(inkpot); + inkpot_print_names(inkpot, stderr); - inkpot_print_values(inkpot); + inkpot_print_values(inkpot, stderr); if (argc < 2) color = NULL; else color = argv[1]; - rc = inkpot_find(inkpot, color); + rc = inkpot_set(inkpot, color); if (rc == INKPOT_SUCCESS) { - inkpot_get_rgba(inkpot, &r, &g, &b, &a); - fprintf(stderr, "%s %d,%d,%d,%d\n", color, r, g, b, a); + inkpot_get_rgba(inkpot, rgba); + fprintf(stderr, "%s %d,%d,%d,%d\n", + color, rgba[0], rgba[1], rgba[2], rgba[3]); } else { - rc = inkpot_find_default(inkpot); + rc = inkpot_set_default(inkpot); assert (rc == INKPOT_SUCCESS); - inkpot_get_rgba(inkpot, &r, &g, &b, &a); - fprintf(stderr, "%s (not found) %d,%d,%d,%d (default)\n", color, r, g, b, a); + inkpot_get_rgba(inkpot, rgba); + fprintf(stderr, "%s (not found) %d,%d,%d,%d (default)\n", + color, rgba[0], rgba[1], rgba[2], rgba[3]); } return 0; -- 2.40.0