From: ellson Date: Sun, 28 Sep 2008 18:04:50 +0000 (+0000) Subject: make api constant type X-Git-Tag: LAST_LIBGRAPH~32^2~3284 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=11b220f65fade464bc4df1fc8c14ac693aec9970;p=graphviz make api constant type --- diff --git a/lib/inkpot/inkpot_define.h b/lib/inkpot/inkpot_define.h index fcaff6899..0ad2da58d 100644 --- a/lib/inkpot/inkpot_define.h +++ b/lib/inkpot/inkpot_define.h @@ -39,11 +39,6 @@ typedef unsigned int IDX_IXVALUES; typedef unsigned int IDX_TONAMES; #define SZT_TONAMES 7 -typedef unsigned long VALUE; -#define SZB_RED 16 -#define MSK_RED 65535 -#define MAX_RED 65535 - typedef unsigned int IDX_VALUES; #define SZT_VALUES 7 #define SZT_NONAME_VALUES 4 diff --git a/lib/inkpot/inkpot_scheme.c b/lib/inkpot/inkpot_scheme.c index 67fe99339..d018423d5 100644 --- a/lib/inkpot/inkpot_scheme.c +++ b/lib/inkpot/inkpot_scheme.c @@ -43,11 +43,11 @@ inkpot_t *inkpot_init ( void ) if (inkpot) { inkpot->values.no_palette_value = 0; - inkpot->values.no_palette_vtype = (BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes); + inkpot->values.no_palette_vtype = (BIT_VTYPE_size_16 | BIT_VTYPE_code_rgb); inkpot->value.index = 0; inkpot->value.value = 0; - inkpot->value.vtype = (BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes); + inkpot->value.vtype = (BIT_VTYPE_size_16 | BIT_VTYPE_code_rgb); inkpot->canon = NULL; inkpot->canon_alloc = 0; @@ -387,17 +387,17 @@ inkpot_status_t inkpot_set_rgba ( inkpot_t *inkpot, double rgba[4] ) { inkpot_status_t rc; inkpot_value_t value; - VALUE v; + unsigned long v; int i; for (i = 0; i < 4; i++) { - value.value <<= SZB_RED; + value.value <<= 16; v = rgba[i]; v = (v < 0.0) ? 0.0 : v; v = (v > 1.0) ? 1.0 : v; - value.value |= (int)(v * MAX_RED); + value.value |= (int)(v * 65535); } - value.vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes; + value.vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_rgba; rc = inkpot_value_set ( &inkpot->values, &value ); if (rc == INKPOT_SUCCESS) @@ -453,17 +453,23 @@ inkpot_status_t inkpot_set ( 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) { - r *= MAX_RED/65535; g *= MAX_RED/65535; b *= MAX_RED/65535; a *= MAX_RED/65535; + if (len == 4) + value.vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_rgba; + else + value.vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_rgb; } - if (len < 3) { + else if (len < 3) { a = 255; if ((len = sscanf(inkpot->canon, "#%2x%2x%2x%2x", &r, &g, &b, &a)) >= 3) { - r *= MAX_RED/255; g *= MAX_RED/255; b *= MAX_RED/255; a *= MAX_RED/255; + r *= 65535/255; g *= 65535/255; b *= 65535/255; a *= 65535/255; + if (len == 4) + value.vtype = BIT_VTYPE_size_8 | BIT_VTYPE_code_rgba; + else + value.vtype = BIT_VTYPE_size_8 | BIT_VTYPE_code_rgb; } } if (len >= 3) { - value.value = (((((((VALUE)r) << SZB_RED) | (VALUE)g) << SZB_RED) | (VALUE)b) << SZB_RED) | (VALUE)a; - value.vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes; + value.value = (((((((unsigned long)r) << 16) | (unsigned long)g) << 16) | (unsigned long)b) << 16) | (unsigned long)a; rc = inkpot_value_set ( &inkpot->values, &value ); if (rc == INKPOT_SUCCESS) @@ -474,7 +480,7 @@ inkpot_status_t inkpot_set ( inkpot_t *inkpot, const char *color ) else if (((c = *inkpot->canon) == '.') || isdigit(c)) { hsva[3] = 1.0; if (sscanf(inkpot->canon, "%lf%lf%lf%lf", &hsva[0], &hsva[1], &hsva[2], &hsva[3]) >= 3) - rc = inkpot_set_hsva(inkpot, hsva); + rc = inkpot_set_hsva(inkpot, hsva); /* FIXME */ else if (sscanf(inkpot->canon, "%d", &index) == 1) /* simple indexes */ rc = inkpot_set_index(inkpot, index); @@ -589,8 +595,8 @@ inkpot_status_t inkpot_get_rgba_i ( inkpot_t *inkpot, unsigned short rgba[4] ) rc = inkpot->status = inkpot_value_get( &inkpot->values, &value ); if (rc == INKPOT_SUCCESS) { for (i = 3; i >= 0; i--) { - rgba[i] = (value.value & MSK_RED); - value.value >>= SZB_RED; + rgba[i] = (value.value & 65535); + value.value >>= 16; } } return rc; @@ -606,8 +612,8 @@ inkpot_status_t inkpot_get_rgba ( inkpot_t *inkpot, double rgba[4] ) rc = inkpot->status = inkpot_value_get( &inkpot->values, &value ); if (rc == INKPOT_SUCCESS) { for (i = 3; i >= 0; i--) { - rgba[i] = (value.value & MSK_RED) / (double)MAX_RED; - value.value >>= SZB_RED; + rgba[i] = (value.value & 65535) / (double)65535; + value.value >>= 16; } } return rc; @@ -792,8 +798,8 @@ static void inkpot_debug_rgba( inkpot_t *inkpot, VALUE value ) int i; for (i = 3; i >= 0; i--) { - rgba[i] = (value & MSK_RED); - value >>= SZB_RED; + rgba[i] = (value & 65535); + value >>= 16; } sprintf(buf, "#%04x%04x%04x%04x", rgba[0], rgba[1], rgba[2], rgba[3]); errputs(inkpot, buf); diff --git a/lib/inkpot/inkpot_value.c b/lib/inkpot/inkpot_value.c index e62ee4725..46faf61bc 100644 --- a/lib/inkpot/inkpot_value.c +++ b/lib/inkpot/inkpot_value.c @@ -35,15 +35,17 @@ 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 index; + + /* FIXME - this routine must check for 8 bit values and properly scale to 16 for the api */ index = value->index; if (index < SZT_VALUES) { value->value = TAB_VALUES[index]; - value->vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes; + value->vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_rgba; /* FIXME */ } else if (index - SZT_VALUES < SZT_NONAME_VALUES) { value->value = TAB_NONAME_VALUES[index - SZT_VALUES]; - value->vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes; + value->vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_rgba; /* FIXME */ } else if (index == SZT_VALUES + SZT_NONAME_VALUES) { value->value = values->no_palette_value; diff --git a/lib/inkpot/inkpot_value.h b/lib/inkpot/inkpot_value.h index 395017c81..1e86788a2 100644 --- a/lib/inkpot/inkpot_value.h +++ b/lib/inkpot/inkpot_value.h @@ -28,24 +28,21 @@ typedef int BIT_VTYPE; #define BIT_VTYPE_size_8 0x01 #define MSK_VTYPE_code 0x0e -#define BIT_VTYPE_code_VALUE 0x00 -#define BIT_VTYPE_code_rgba 0x02 -#define BIT_VTYPE_code_hsva 0x04 -#define BIT_VTYPE_code_cmyk 0x06 - -#define MSK_VTYPE_alpha 0x10 -#define BIT_VTYPE_alpha_yes 0x00 -#define BIT_VTYPE_alpha_no 0x10 +#define BIT_VTYPE_code_rgba 0x00 +#define BIT_VTYPE_code_hsva 0x02 +#define BIT_VTYPE_code_cmyk 0x04 +#define BIT_VTYPE_code_rgb 0x06 +#define BIT_VTYPE_code_hsv 0x08 typedef struct inkpot_values_s { - VALUE no_palette_value; + unsigned long no_palette_value; BIT_VTYPE no_palette_vtype; } inkpot_values_t; 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 */ + 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 */ + unsigned long value; /* 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 ); diff --git a/lib/inkpot/inkpot_value_table.h b/lib/inkpot/inkpot_value_table.h index 083225457..0c8a410bb 100644 --- a/lib/inkpot/inkpot_value_table.h +++ b/lib/inkpot/inkpot_value_table.h @@ -14,7 +14,7 @@ * AT&T Research, Florham Park NJ * **********************************************************/ -VALUE TAB_VALUES[SZT_VALUES] = { +unsigned long TAB_VALUES[SZT_VALUES] = { 0x000000000000ffff, /* black */ 0x00000000ffffffff, /* bleu, blue */ 0x0000ffff0000ffff, /* green, vert */ @@ -24,7 +24,7 @@ VALUE TAB_VALUES[SZT_VALUES] = { 0xffffffffffffffff, /* white */ }; -VALUE TAB_NONAME_VALUES[SZT_NONAME_VALUES] = { +unsigned long TAB_NONAME_VALUES[SZT_NONAME_VALUES] = { 0x000000008000ffff, 0x00000000a400ffff, 0x00000000c800ffff,