inkpot = malloc(sizeof(inkpot_t));
if (inkpot) {
+
+ inkpot->values = inkpot_values_init ();
+ if (! inkpot->values) {
+ free(inkpot);
+ return NULL;
+ }
+
inkpot->canon = NULL;
inkpot->canon_alloc = 0;
- inkpot->palette = NULL;
- inkpot->palette_alloc = 0;
-
inkpot->disc = inkpot_default_disc;
inkpot->out_closure = stdout;
inkpot->err_closure = stderr;
void inkpot_destroy ( inkpot_t *inkpot )
{
+ inkpot_values_destroy ( inkpot->values );
free(inkpot->canon);
- free(inkpot->palette);
free(inkpot);
}
return ((inkpot->status = INKPOT_SUCCESS));
}
+#if 0
inkpot_status_t inkpot_palette( inkpot_t *inkpot, int size )
{
if (inkpot->palette_alloc < size * sizeof(inkpot_noname_value_t)) {
}
return ((inkpot->status = INKPOT_SUCCESS));
}
+#endif
static int inkpot_name_cmpf ( const void *key, const void *base)
{
static inkpot_status_t inkpot_set_value_idx( inkpot_t *inkpot, IDX_VALUES value_idx)
{
- if (inkpot->value_idx != value_idx) {
- inkpot->value_idx = value_idx;
+ if (inkpot->value.index != value_idx) {
+ inkpot->value.index = value_idx;
inkpot->out_name = NULL; /* value changed so invalidate out_name */
}
return ((inkpot->status = INKPOT_SUCCESS));
inkpot_status_t inkpot_set_rgba ( inkpot_t *inkpot, double rgba[4] )
{
- VALUE value = 0, v;
+ inkpot_status_t rc;
+ inkpot_value_t value;
+ VALUE v;
int i;
for (i = 0; i < 4; i++) {
- value <<= SZB_RED;
+ value.value <<= SZB_RED;
v = rgba[i];
v = (v < 0.0) ? 0.0 : v;
v = (v > 1.0) ? 1.0 : v;
- value |= (int)(v * MAX_RED);
+ value.value |= (int)(v * MAX_RED);
}
-
- return inkpot_set_value ( inkpot, value );
+ value.vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes;
+
+ rc = inkpot_value_set ( inkpot->values, &value );
+ if (rc == INKPOT_SUCCESS)
+ inkpot->value = value;
+ return (inkpot->status = rc);
}
inkpot_status_t inkpot_set_hsva ( inkpot_t *inkpot, double hsva[4] )
const char *p;
int i, c, len, index;
unsigned int r, g, b, a;
- VALUE value;
+ inkpot_value_t value;
double hsva[4];
inkpot_status_t rc = INKPOT_COLOR_UNKNOWN;
}
}
if (len >= 3) {
- value = (((((((VALUE)r) << SZB_RED) | (VALUE)g) << SZB_RED) | (VALUE)b) << SZB_RED) | (VALUE)a;
- rc = inkpot_set_value(inkpot, value);
+ 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;
+
+ rc = inkpot_value_set ( inkpot->values, &value );
+ if (rc == INKPOT_SUCCESS)
+ inkpot->value = value;
+ inkpot->status = rc;
}
}
else if (((c = *inkpot->canon) == '.') || isdigit(c)) {
}
if (inkpot->out_scheme_bit) {
- value_idx = inkpot->value_idx;
+ value_idx = inkpot->value.index;
if (value_idx < SZT_VALUES) {
for (t = TAB_VALUES[value_idx].toname_idx; t < SZT_NAMES; t++) {
out_name = &TAB_NAMES[TAB_NAMES[t].toname_idx];
inkpot_status_t inkpot_get_rgba_i ( inkpot_t *inkpot, unsigned short rgba[4] )
{
inkpot_status_t rc;
- VALUE value;
+ inkpot_value_t value;
int i;
- rc = inkpot_get_value( inkpot, &value );
+ 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 & MSK_RED);
- value >>= SZB_RED;
+ rgba[i] = (value.value & MSK_RED);
+ value.value >>= SZB_RED;
}
}
return rc;
inkpot_status_t inkpot_get_rgba ( inkpot_t *inkpot, double rgba[4] )
{
inkpot_status_t rc;
- VALUE value;
+ inkpot_value_t value;
int i;
- rc = inkpot_get_value( inkpot, &value );
+ 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 & MSK_RED) / (double)MAX_RED;
- value >>= SZB_RED;
+ rgba[i] = (value.value & MSK_RED) / (double)MAX_RED;
+ value.value >>= SZB_RED;
}
}
return rc;
return inkpot_debug_names_schemes(inkpot, inkpot->out_scheme_bit, 1, inkpot->out_scheme_list);
}
+#if 0
/* Print all values that are members of the currently listed
* name schemes, with the names in those schemes.
* Does not print the indexes in index schemes that a value may
return ((inkpot->status = INKPOT_SUCCESS));
}
+#endif
inkpot_status_t inkpot_debug_error ( inkpot_t *inkpot )
{
scheme_bits, /* One bit per inkpot_scheme_name_t */
out_scheme_bit; /* One scheme only for output. */
- IDX_VALUES
- value_idx; /* The current color */
-
IDX_IXVALUES
index, /* The index for the current value in active_schemes_index */
out_index; /* The index for the current value in active_out_schemes_index */
char *canon; /* malloc'ed, reused storage for canonicalizing color request strings */
int canon_alloc;
- VALUE
- no_palette_value;
-
- inkpot_noname_value_t *palette; /* malloc'ed paletter storage */
- int palette_alloc;
- int palette_fill;
+ inkpot_values_t *values;/* The values store */
+ inkpot_value_t value; /* The current value of the inkpot */
- inkpot_cache_element_t cache[SZT_MRU_CACHE]; /* MRU chache of successfull color lookups */
+ inkpot_cache_element_t
+ cache[SZT_MRU_CACHE];/* MRU chache of successful color lookups */
IDX_MRU_CACHE
most_recently_used_idx;
- inkpot_disc_t disc; /* writers and closures for out and err */
- void *out_closure, *err_closure;
+ inkpot_disc_t
+ disc; /* writers and closures for out and err */
+ void
+ *out_closure,
+ *err_closure;
- inkpot_status_t status; /* The status after the last operation */
+ inkpot_status_t
+ status; /* The status after the last operation */
};
#endif /* INKPOT_STRUCTS_H */
**********************************************************/
#include <stdio.h>
+#include <stdlib.h>
#include <assert.h>
#include "inkpot.h"
#include "inkpot_define.h"
#include "inkpot_value.h"
-#include "inkpot_struct.h"
#include "inkpot_value_table.h"
-#if 0
-static int inkpot_value_cmpf ( const void *key, const void *base)
+struct inkpot_values_s {
+ VALUE
+ no_palette_value;
+ BIT_VTYPE
+ no_palette_vtype;
+};
+
+inkpot_values_t* inkpot_values_init ( void )
{
- VALUE value_key = *(VALUE*)key;
- VALUE value_base = *(VALUE*)base;
+ inkpot_values_t *values;
+
+ values = (inkpot_values_t*)malloc(sizeof(inkpot_values_t));
+ if (values) {
- if (value_key > value_base) return 1;
- if (value_key < value_base) return -1;
- return 0;
+ }
+ return values;
}
-#endif
-inkpot_status_t inkpot_set_value ( inkpot_t *inkpot, VALUE value )
+void inkpot_values_destroy ( inkpot_values_t *values )
{
+ free(values);
+}
- inkpot->no_palette_value = value;
- inkpot->value_idx = SZT_VALUES + SZT_NONAME_VALUES; /* indicate presence of no_palette_value */
-
-
-#if 0
- inkpot_value_t *value;
- inkpot_noname_value_t *noname_value;
-
-/*
- * FIXME - implement caching and check here
- */
-
- value = (inkpot_value_t *) bsearch(
- (void*)(value), (void*)TAB_VALUES,
- SZT_VALUES, sizeof(inkpot_value_t),
- inkpot_value_cmpf);
-
- if (value)
- return inkpot_set_value_idx(inkpot, (value - TAB_VALUES));
-
- noname_value = (inkpot_noname_value_t *) bsearch(
- (void*)(value), (void*)TAB_NONAME_VALUES,
- SZT_NONAME_VALUES, sizeof(inkpot_noname_value_t),
- inkpot_value_cmpf);
-
- if (noname_value)
- return inkpot_set_value_idx(inkpot, ((noname_value - TAB_NONAME_VALUES) + SZT_VALUES));
-
- return ((inkpot->status = INKPOT_COLOR_NONAME));
- /* need some sort of btree here so that we can insert value
- * values and keep sorted */
-
- noname_value = (inkpot_noname_value_t *) bsearch(
- (void*)(value), (void*)TAB_DYNAMIC_VALUES,
- SZT_DYNAMIC_VALUES, sizeof(inkpot_noname_value_t),
- inkpot_value_cmpf);
-
- /* insert value and keep sorted */
+inkpot_status_t inkpot_value_set ( inkpot_values_t *values, inkpot_value_t *value )
+{
+ values->no_palette_value = value->value;
+ values->no_palette_vtype = value->vtype;
+ value->index = SZT_VALUES + SZT_NONAME_VALUES;
-#endif
- return ((inkpot->status = INKPOT_SUCCESS));
+ return INKPOT_SUCCESS;
}
-inkpot_status_t inkpot_get_value ( inkpot_t *inkpot, VALUE *value )
+inkpot_status_t inkpot_value_get ( inkpot_values_t *values, inkpot_value_t *value )
{
- IDX_VALUES value_idx = inkpot->value_idx;
-
- if (value_idx < SZT_VALUES)
- *value = TAB_VALUES[value_idx].value;
- else if (value_idx - SZT_VALUES < SZT_NONAME_VALUES)
- *value = TAB_NONAME_VALUES[value_idx - SZT_VALUES].value;
- else if (value_idx == SZT_VALUES + SZT_NONAME_VALUES)
- *value = inkpot->no_palette_value;
+ IDX_VALUES index;
+
+ index = value->index;
+ if (index < SZT_VALUES) {
+ value->value = TAB_VALUES[index].value;
+ value->vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes;
+ }
+ else if (index - SZT_VALUES < SZT_NONAME_VALUES) {
+ value->value = TAB_NONAME_VALUES[index - SZT_VALUES].value;
+ value->vtype = BIT_VTYPE_size_16 | BIT_VTYPE_code_VALUE | BIT_VTYPE_alpha_yes;
+ }
+ else if (index == SZT_VALUES + SZT_NONAME_VALUES) {
+ value->value = values->no_palette_value;
+ value->vtype = values->no_palette_vtype;
+ }
else
assert(0);
- return ((inkpot->status = INKPOT_SUCCESS));
+ return INKPOT_SUCCESS;
}
extern "C" {
#endif
-typedef struct inkpot_value_s { /* Numeric color values used by the set
+#if 1
+/* FIXME - this stuff needs to go */
+
+typedef struct inkpot_oldvalue_s { /* Numeric color values used by the set
* of inkpot_name_t and indexes from
* indexed color schemes ( total presumed
* to be less than all possible color values).
* that doesn't map to this inkpot_value_t,
* or until the end of TAB_NAMES is reached.
* (Phew!) */
-} inkpot_value_t;
+} inkpot_oldvalue_t;
typedef struct inkpot_noname_value_s { /* Numeric color values used by the remainder
* of indexes from indexed color schemes
} inkpot_noname_value_t;
-extern inkpot_status_t inkpot_set_value ( inkpot_t *inkpot, VALUE value );
-extern inkpot_status_t inkpot_get_value ( inkpot_t *inkpot, VALUE *value );
-
-extern inkpot_value_t TAB_VALUES[];
+extern inkpot_oldvalue_t TAB_VALUES[];
extern inkpot_noname_value_t TAB_NONAME_VALUES[];
+#endif
extern IDX_VALUES TAB_IXVALUES[];
+/* proper api starts here */
+
+typedef struct inkpot_values_s inkpot_values_t;
+
+typedef int BIT_VTYPE;
+
+#define MSK_VTYPE_size 0x01
+#define BIT_VTYPE_size_8 0x00
+#define BIT_VTYPE_size_16 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_no 0x00
+#define BIT_VTYPE_alpha_yes 0x10
+
+typedef struct inkpot_value_s {
+ IDX_VALUES index; /* write by set, read by get, write by first/next */
+ BIT_VTYPE vtype; /* read by set, write by get, read by first/next */
+ VALUE value; /* read by set, write by get, write by first/next */
+} inkpot_value_t;
+
+extern inkpot_values_t* inkpot_values_init ();
+extern void inkpot_values_destroy ( inkpot_values_t *values );
+
+extern inkpot_status_t inkpot_value_set ( inkpot_values_t *values, inkpot_value_t *value );
+extern inkpot_status_t inkpot_value_get ( inkpot_values_t *values, inkpot_value_t *value );
+
+extern inkpot_status_t inkpot_value_get_first ( inkpot_values_t *values, inkpot_value_t *value );
+extern inkpot_status_t inkpot_value_get_next ( inkpot_values_t *values, inkpot_value_t *value );
+
#ifdef __cplusplus
}
#endif
* AT&T Research, Florham Park NJ *
**********************************************************/
-inkpot_value_t TAB_VALUES[SZT_VALUES] = { /* Must be sort'ed */
+inkpot_oldvalue_t TAB_VALUES[SZT_VALUES] = { /* Must be sort'ed */
{ 0x000000000000ffff, 0 }, /* black */
{ 0x00000000ffffffff, 1 }, /* bleu, blue */
{ 0x0000ffff0000ffff, 3 }, /* green, vert */