#ifndef		__WCOL_GRADGEN_H__
#define		__WCOL_GRADGEN_H__



/* "Dynamic Color Gradient Generator (wip V2)"
   using "color attractors".
   Aug. 3rd 2005 -Dennis Busch- "http://www.dennisbusch.de"
   "Greetings to Allegroids all over the world!" :)
*/

/* What does it do (see main for example usage or just compile and run):
   ---------------------------------------------------------------------
   Version 2: (Aug. 5th 2005) (minor changes: fixed typo, prevent div by 0)
   Added support for color "absorbers"(introducing CA_MODE for future extensions),
   they work against the "attractors" in the way that they will take away color.
   The nearer a pixel lies to one of them, the greater a fraction of the color
   specified by the "absorber" will be taken away.
   Also added the possibility to play around with "p" an "exp" which will
   change the intensity(distance)=p * distance^exp of an an "attractor"

   Version 1: (Aug. 3rd 2005) (everything is preserved, version2 uses new structs and functions)
   User(==programmer, sorry no GUI available) fills a list with a
   freely choosable number of so called "color attractors"(hehe, i just invented
   that name) and then calls a function that will fill a bitmap with colors.
   Each pixels' color will be an average of all the colors used by
   the "color attractors". The nearer a pixel lies to one of the color attractors
   the more it gets mixed with that color as a fraction of the distance relative
   to that color attractor's range.
   Note: The "color attractors" do not necessarily have to lay "inside" the bitmap. */

/* Instructions:
   -------------
   Quick start: version2: "enum CA_MODE" is new and "struct CA_DESC2"

                version1:
                Read the comments to "enum CA_TYPE", "struct CA_DESC",
                quickly fly over the function declaration "add_to_ca_list",
                (Just ignore everything else.)
*/

/* Requirements:
   -------------
   -the marvellous Allegro Library ("http://alleg.sourceforge.net/")
   -some plain C programming knowledge
   -a machine capable of displaying 32bpp color modes (look for "bbp" in main to change)
    (only if you actually want to see something, of course you can just
     render to a non-screen bitmap and then save that into a file) */

/* "Feel free to experiment, modify, change, improve, rip, use, optimize,..." ;)
   "...but in any case make sure you give me credit!" */

#include <allegro.h> /* without this, NOTHING works ;) */

/* different "color attractor" types */
enum CA_TYPE
{
	CA_GLOBAL=0, /* a color attractor with a fixed mixin percentage to every pixel */
	CA_POINT, /* a color attractor with definite location in 2D space */
	CA_HBAR, /* ignores vertical component of distance vector in computations */
	CA_VBAR, /* ignores horizontal component of distance vector in computations */
};
typedef enum CA_TYPE col_att_type;

enum CA_MODE
{
	CA_ATTRACT=0, /* ADDs fractions of its' color */
	CA_ABSORB     /* SUBTRACTs fractions of its' color */
};
typedef enum CA_MODE col_att_mode;

// 8192 should do
#define		LUT_SIZE	8192

/* a full "color attractor" description */
struct CA_DESC
{
	col_att_type t; /* one of the types in CA_TYPE */
	col_att_mode m; /* one of the types in CA_MODE, set to CA_ATTRACT causes equal behaviour as version1 */
	int x; /* global percentage of color(actually 100-that) if t==GLOBAL; x-location otherwise */
	int y; /* y-location */
	int r,g,b; /* color triplet; values other than from 0 to 255 can cause weird
					behaviour */
	int range; /* range in which the ca is active (ignored for GLOBAL) */
	float linearity;	/* typically between 0.0 and 2.0 */
	float multiplier; /* typically around 1.0 */

	float LINEARITY[LUT_SIZE+1]; /* linearity look-up table; supposed to be private */
	struct CA_DESC* pnext; /* for color attractor lists */
};
typedef struct CA_DESC col_att;
typedef struct CA_DESC* pcol_att;

/* MESSY C LIST STUFF */
/* a "color attractor" list */
struct CA_DESC_LIST
{
	int link_count;
	pcol_att plist;
};
typedef struct CA_DESC_LIST col_att_list;

int kill_ca_list(col_att_list* pcal);
int init_ca_list(col_att_list* pcal);
int add_to_ca_list(col_att_list* pcal, col_att_type t, col_att_mode m, int x, int y, int r, int g, int b, int range, float linearity, float multiplier);
/* END OF MESSY C LIST STUFF */


/* the function that does all the work described at the beginning of this file,
	 takes a target bitmap and a pointer to the list of "color attractors" used;
	 Note to user: DON'T call this on screen or videobitmaps(sloooow!)
	 Note to self: Optimization, readability improvement and further modularization
								 should be done here. */
void render_col_grad_to_bitmap(BITMAP *bmp, col_att_list* pcal);


#endif		//__WCOL_GRADGEN_H__
