From 8bdaa13fda5cece286ba96ea9c996e98fb5bf774 Mon Sep 17 00:00:00 2001 From: ellson Date: Wed, 1 Oct 2008 22:05:25 +0000 Subject: [PATCH] bug fixing --- lib/inkpot/Makefile.old | 1 - lib/inkpot/inkpot_scheme.c | 40 ++++++++++++++++++-------------------- lib/inkpot/inkpot_value.c | 19 +++++++++--------- lib/inkpot/inkpot_value.h | 3 +-- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/lib/inkpot/Makefile.old b/lib/inkpot/Makefile.old index 60e236395..8ea5af824 100644 --- a/lib/inkpot/Makefile.old +++ b/lib/inkpot/Makefile.old @@ -21,7 +21,6 @@ inkpot_scheme_table.h: inkpot_define.h inkpot_define.h: scripts/lib-h.tcl tk.lib svg.lib x11.lib scripts/lib-h.tcl tk.lib svg.lib x11.lib - rm tk.lib svg.lib x11.lib x11.lib: scripts/rgb.txt-x11.lib.tcl data/rgb.txt scripts/rgb.txt-x11.lib.tcl data/rgb.txt diff --git a/lib/inkpot/inkpot_scheme.c b/lib/inkpot/inkpot_scheme.c index 55dabe7dd..c943077b1 100644 --- a/lib/inkpot/inkpot_scheme.c +++ b/lib/inkpot/inkpot_scheme.c @@ -372,15 +372,14 @@ inkpot_status_t inkpot_put_rgba ( inkpot_t *inkpot, double rgba[4] ) { inkpot_status_t rc; inkpot_value_t value; - unsigned long v; + double v; int i; for (i = 0; i < 4; i++) { - value.value <<= 16; v = rgba[i]; v = (v < 0.0) ? 0.0 : v; v = (v > 1.0) ? 1.0 : v; - value.value |= (int)(v * 65535); + value.value[i] = (unsigned short)(v * 65535); } value.vtype = VTYPE_rgba; @@ -438,20 +437,18 @@ inkpot_status_t inkpot_put ( inkpot_t *inkpot, const char *color ) if (*inkpot->canon == '#') { a = 65535; if ((len = sscanf(inkpot->canon, "#%4x%4x%4x%4x", &r, &g, &b, &a)) >= 3) { - value.value = (((((((unsigned long)r) << 16) - | (unsigned long)g) << 16) - | (unsigned long)b) << 16) - | (unsigned long)a; + value.value[0] = r; + value.value[1] = g; + value.value[2] = b; + value.value[3] = a; } else if (len < 3) { a = 255; if ((len = sscanf(inkpot->canon, "#%2x%2x%2x%2x", &r, &g, &b, &a)) >= 3) { -/* r *= 65535/255; g *= 65535/255; b *= 65535/255; a *= 65535/255; // too ugly */ - value.value = (((((((unsigned long)r) << 16) - | (unsigned long)g) << 16) - | (unsigned long)b) << 16) - | (unsigned long)a; - value.value |= value.value << 8; /* not ugly */ + value.value[0] = r | r << 8; + value.value[1] = g | r << 8; + value.value[2] = b | r << 8; + value.value[3] = a | r << 8; } } if (len >= 3) { @@ -527,7 +524,7 @@ inkpot_status_t inkpot_get ( inkpot_t *inkpot, const char **color ) IDX_ALTS i; IDX_VALUES value_idx; int maybe; - + /* FIXME - why isn't this checking the current value then the 4 level cache? */ out_name = inkpot->out_name; if (out_name) { /* if we have a cached name */ @@ -604,9 +601,8 @@ inkpot_status_t inkpot_get_rgba_i ( inkpot_t *inkpot, unsigned short rgba[4] ) value = inkpot->value; rc = inkpot->status = inkpot_value_get( &inkpot->values, &value ); if (rc == INKPOT_SUCCESS) { - for (i = 3; i >= 0; i--) { - rgba[i] = (value.value & 65535); - value.value >>= 16; + for (i = 0; i < 4; i++) { + rgba[i] = value.value[i]; } } return rc; @@ -621,9 +617,8 @@ inkpot_status_t inkpot_get_rgba ( inkpot_t *inkpot, double rgba[4] ) value = inkpot->value; rc = inkpot->status = inkpot_value_get( &inkpot->values, &value ); if (rc == INKPOT_SUCCESS) { - for (i = 3; i >= 0; i--) { - rgba[i] = (value.value & 65535) / (double)65535; - value.value >>= 16; + for (i = 0; i < 4; i++) { + rgba[i] = value.value[i] / (double)65535; } } return rc; @@ -761,9 +756,12 @@ inkpot_status_t inkpot_debug_schemes( inkpot_t *inkpot ) if (! found) { inkpot_puts(inkpot, " "); inkpot_puts(inkpot, &TAB_SCHEME_STRINGS[TAB_SCHEMES[i].string_idx]); - inkpot_puts(inkpot, "(out)"); + found++; } + inkpot_puts(inkpot, "(out)"); } + if (found) + inkpot_puts(inkpot, "\n"); } for (j = 0; j < inkpot->active_schemes; j++) { inkpot_puts(inkpot, " "); diff --git a/lib/inkpot/inkpot_value.c b/lib/inkpot/inkpot_value.c index a0afb9153..106f80bb1 100644 --- a/lib/inkpot/inkpot_value.c +++ b/lib/inkpot/inkpot_value.c @@ -34,28 +34,27 @@ inkpot_status_t inkpot_value_set ( inkpot_values_t *values, inkpot_value_t *valu inkpot_status_t inkpot_value_get ( inkpot_values_t *values, inkpot_value_t *value ) { IDX_VALUES_24 i; + unsigned short v; /* FIXME - this routine must check for 8 bit values and properly scale to 16 for the api */ if (value->index < SZT_VALUES) { i = 3 * value->index; - value->value = TAB_VALUES_24[i++] << 16; - value->value |= TAB_VALUES_24[i++] << 16; - value->value |= TAB_VALUES_24[i] << 16; - value->value |= 0xff; - value->value |= value->value << 8; + v = TAB_VALUES_24[i++]; value->value[0] = v | v << 8; + v = TAB_VALUES_24[i++]; value->value[1] = v | v << 8; + v = TAB_VALUES_24[i]; value->value[2] = v | v << 8; + value->value[3] = 0xffff; value->vtype = VTYPE_rgba; /* FIXME */ } else if (value->index - SZT_VALUES < SZT_NONAME_VALUES) { i = 3 * value->index; - value->value = TAB_NONAME_VALUES_24[i++] << 16; - value->value |= TAB_NONAME_VALUES_24[i++] << 16; - value->value |= TAB_NONAME_VALUES_24[i] << 16; - value->value |= 0xff; - value->value |= value->value << 8; + v = TAB_NONAME_VALUES_24[i++]; value->value[0] = v | v << 8; + v = TAB_NONAME_VALUES_24[i++]; value->value[1] = v | v << 8; + v = TAB_NONAME_VALUES_24[i]; value->value[2] = v | v << 8; + value->value[3] = 0xffff; value->vtype = VTYPE_rgba; /* FIXME */ } diff --git a/lib/inkpot/inkpot_value.h b/lib/inkpot/inkpot_value.h index c70985e7f..64c1130d1 100644 --- a/lib/inkpot/inkpot_value.h +++ b/lib/inkpot/inkpot_value.h @@ -22,7 +22,6 @@ extern "C" { #endif typedef int BIT_VTYPE; -typedef unsigned long VALUE; typedef enum { VTYPE_rgba = 0, @@ -56,7 +55,7 @@ typedef struct inkpot_values_s { typedef struct inkpot_value_s { IDX_VALUES index; /* write by set, read by get, write by first, read/write by next */ BIT_VTYPE vtype; /* read by set, write by get, read by first, read by next */ - VALUE value; /* read by set, write by get, write by first, write by next */ + unsigned short value[4]; /* read by set, write by get, write by first, write by next */ } inkpot_value_t; extern inkpot_status_t inkpot_value_set ( inkpot_values_t *values, inkpot_value_t *value ); -- 2.40.0