Exemplo n.º 1
0
static void
RenderPalette(AG_HSVPal *pal)
{
	AG_Surface *ds = pal->surface;
	float h, cur_h, cur_s, cur_v;
	AG_Color C;
	Uint32 px;
/*	Uint8 da; */
	int x, y, i;
	AG_Rect rd;

	AG_FillRect(ds, NULL, AG_ColorRGB(0,0,0));

	cur_h = (AG_GetFloat(pal, "hue")/360) * 2*AG_PI;
	cur_s = AG_GetFloat(pal, "saturation");
	cur_v = AG_GetFloat(pal, "value");

	/* Render the circle of hues. */
	for (h = 0.0; h < 2*AG_PI; h += pal->circle.dh) {
		AG_HSV2RGB((h/(2*AG_PI)*360.0), 1.0, 1.0, &C.r, &C.g, &C.b);
		px = AG_MapColorRGB(ds->format, C);

		for (i = 0; i < pal->circle.width; i++) {
			x = (pal->circle.rout - i)*Cos(h);
			y = (pal->circle.rout - i)*Sin(h);

			AG_PUT_PIXEL2(ds,
			    pal->circle.x+x,
			    pal->circle.y+y,
			    px);
		}
	}

	/* Render the triangle of saturation and value. */
	for (y = 0; y < pal->triangle.h; y += 2) {
		float sat = (float)(pal->triangle.h - y) /
		            (float)(pal->triangle.h);

		for (x = 0; x < y; x++) {
			AG_HSV2RGB((cur_h/(2*AG_PI))*360.0, sat,
			    1.0 - ((float)x/(float)pal->triangle.h),
			    &C.r, &C.g, &C.b);
			px = AG_MapColorRGB(ds->format, C);
			AG_PUT_PIXEL2(ds,
			    pal->triangle.x + x - y/2,
			    pal->triangle.y + y,
			    px);
			AG_PUT_PIXEL2(ds,
			    pal->triangle.x + x - y/2,
			    pal->triangle.y + y + 1,
			    px);
		}
	}

	if (!(pal->flags & AG_HSVPAL_NOALPHA)) {
		/* Render the color preview. */
		/* XXX overblending */
		for (y = 8; y < pal->rAlpha.h+16; y+=8) {
			for (x = 0; x < pal->rAlpha.w; x+=16) {
				rd.w = 8;
				rd.h = 8;
				rd.x = pal->rAlpha.x+x;
				rd.y = pal->rAlpha.y+y;
				AG_FillRect(ds, &rd, pal->cTile);
			}
			y += 8;
			for (x = 8; x < pal->rAlpha.w; x+=16) {
				rd.w = 8;
				rd.h = 8;
				rd.x = pal->rAlpha.x+x;
				rd.y = pal->rAlpha.y+y;
				AG_FillRect(ds, &rd, pal->cTile);
			}
		}
		AG_HSV2RGB((cur_h/(2*AG_PI))*360.0, cur_s, cur_v,
		    &C.r, &C.g, &C.b);
/*		da = MIN(1, ds->w/255); */
		for (y = pal->rAlpha.y+8; y < ds->h; y++) {
			for (x = 0, C.a = 0;
			     x < ds->w;
			     x++) {
				AG_BLEND_RGBA2(ds, x, y,
				    C.r, C.g, C.b, C.a, AG_ALPHA_SRC);
				C.a = x*255/ds->w;
			}
		}
	}
}
Exemplo n.º 2
0
Arquivo: fill.c Projeto: adsr/agar
void
RG_FillApply(void *p, RG_Tile *t, int x, int y)
{
	struct rg_fill_feature *fi = p;
	AG_Surface *su = t->su;
	AG_Color C;
	Uint8 a;
	
	switch (fi->type) {
	case FILL_SOLID:
		AG_FillRect(su, NULL, fi->f_solid.c);
		break;
	case FILL_HGRADIENT:
		{
			int x, y;
			AG_Color c1 = fi->f_gradient.c1;
			AG_Color c2 = fi->f_gradient.c2;
	
			C.a = fi->alpha;
			for (y = 0; y < su->h; y++) {
				a = (Uint8)(su->h-y)*255/su->h;
				C.r = (((c1.r - c2.r)*a)>>8) + c2.r;
				C.g = (((c1.g - c2.g)*a)>>8) + c2.g;
				C.b = (((c1.b - c2.b)*a)>>8) + c2.b;

				if (fi->alpha == 255) {
					for (x = 0; x < su->w; x++) {
						RG_PutPixel(t->su, x, y,
						    AG_MapColorRGB(t->su->format, C));
					}
				} else {
					for (x = 0; x < su->w; x++) {
						RG_BlendRGB(t->su, x, y,
						    RG_PRIM_OVERLAY_ALPHA,
						    C);
					}
				}
			}
		}
		break;
	case FILL_VGRADIENT:
		{
			int x, y;
			AG_Color c1 = fi->f_gradient.c1;
			AG_Color c2 = fi->f_gradient.c2;
			
			C.a = fi->alpha;
			for (y = 0; y < su->h; y++) {
				for (x = 0; x < su->w; x++) {
					a = (su->h - x)*255/su->h;
					C.r = (((c1.r - c2.r)*a)>>8) + c2.r;
					C.g = (((c1.g - c2.g)*a)>>8) + c2.g;
					C.b = (((c1.b - c2.b)*a)>>8) + c2.b;

					RG_BlendRGB(t->su, x, y,
					    RG_PRIM_OVERLAY_ALPHA, C);
				}
			}
		}
		break;
	case FILL_CGRADIENT:
		{
			int i, r = MAX(su->w,su->h);
			int x = su->w/2;
			int y = su->h/2;
			AG_Color c1 = fi->f_gradient.c1;
			AG_Color c2 = fi->f_gradient.c2;
		
			C.a = fi->alpha;
			for (i = 0; i < r; i++) {
				a = (r - i)*255/r;
				C.r = (((c1.r - c2.r)*a)>>8) + c2.r;
				C.g = (((c1.g - c2.g)*a)>>8) + c2.g;
				C.b = (((c1.b - c2.b)*a)>>8) + c2.b;
				RG_ColorRGBA(t, C);
				RG_Circle2(t, x,y, i);
			}
		}
		break;
	default:
		break;
	}
}