#ifndef _COLOR_H
#define _COLOR_H

#include "octree.h"


#define CF_Perm     0x00000001      // do not move from this index
#define CF_Bright   0x00000002      // do not fade this color


typedef struct color_s {
	float            r, g, b;    // color's rgb value
	float            count;      // weight
	float            dist;       // used by brute
	int              index;      // final index in palette
	unsigned long    flags;      // see above
    struct color_s  *close;      // used by brute
	struct color_s  *p, *n;      // link pointers
} color_t;



typedef struct {
	int           colorCount;
	color_t      *colorHead, *colorTail;
} colorList_t;


void Color_Init(colorList_t *clist);
void Color_Free(colorList_t *clist);
int  Color_Len(colorList_t *clist);
void Color_Set(colorList_t *dest, colorList_t *source);
void Color_ForceTuple(colorList_t *clist, int index, float r, float g, float b, unsigned long flags, int weight);
void Color_AddTuple(colorList_t *clist, float r, float g, float b, int weight);
void Color_ClearFound(colorList_t *clist);
void Color_AddFile(colorList_t *clist, char *source);
void Color_SortByWeight(colorList_t *clist);
void Color_SortByIndex(colorList_t *clist);
void Color_Draw(colorList_t *clist, char *dest);
void Color_DelNode(colorList_t *clist, color_t *node, int freeNode);
void Color_AddHead(colorList_t *clist, color_t *node);
int  Color_Count(colorList_t *clist, float r, float g, float b);
void Color_SaveList(colorList_t *clist, char *fileName);
void Color_LoadList(colorList_t *clist, char *fileName);
void Color_AddOctree(colorList_t *clist, octree_t *otree);
void Color_ColorMap(colorList_t *clist);

color_t *Color_FindTuple(colorList_t *clist, float r, float g, float b);
color_t *Color_FindHeavy(colorList_t *clist);
color_t *Color_FindFlag(colorList_t *clist, unsigned long flag);
color_t *Color_GetIndex(colorList_t *clist, int index);
color_t *Color_FindHue(colorList_t *clist);
color_t *Color_RemoveNode(colorList_t *clist, color_t *node);

#endif
