Example #1
0
// Create a lookup table for 50% opacity
unsigned char *palette_table_half(unsigned char *pal) {
	int fg, bg;
	int red, green, blue;
	unsigned char *lut;
	int dither = 0;

	if(pal == NULL)
		return NULL;

	lut = (unsigned char *) malloc(256 * 256);
	if(lut == NULL)
		return NULL;

	for(fg = 0; fg < 256; fg++) {
		for(bg = fg; bg < 256; bg++) {
			red = (pal[bg * 3] + pal[fg * 3] + (++dither & 1)) / 2;
			green = (pal[bg * 3 + 1] + pal[fg * 3 + 1] + (++dither & 1)) / 2;
			blue = (pal[bg * 3 + 2] + pal[fg * 3 + 2] + (++dither & 1)) / 2;

			lut[(fg << 8) + bg] = palette_find(pal, red, green, blue);
			lut[(bg << 8) + fg] = lut[(fg << 8) + bg];
		}
	}
	return lut;
}
Example #2
0
// Create a lookup table for "dodge".
// Very nice for a colourful boost of light.
unsigned char * palette_table_dodge(unsigned char *pal){
	int fg, bg;
	int c1, c2;
	int t1, t2;
	int red, green, blue;
	unsigned char * lut;

	if(pal==NULL) return NULL;

	lut = (unsigned char*)malloc(256*256);
	if(lut==NULL) return NULL;


	for(fg=0, c2=0; fg<256; fg++, c2+=3){
		for(bg=0, c1=0; bg<256; bg++){
			t2 = pal[c2];
			t1 = pal[c1++];
			red = (t1 * 256) / (256 - t2);
			if(red>255) red = 255;

			t2 = pal[c2+1];
			t1 = pal[c1++];
			green = (t1 * 256) / (256 - t2);
			if(green>255) green = 255;

			t2 = pal[c2+2];
			t1 = pal[c1++];
			blue = (t1 * 256) / (256 - t2);
			if(blue>255) blue = 255;

			lut[(fg<<8)+bg] = palette_find(pal, red, green, blue);
		}
	}
	return lut;
}
Example #3
0
void grx_init_color( color * dst, int r, int g, int b )
{
	dst->screen_sig = gr_screen.signature;
	dst->red = (unsigned char)r;
	dst->green = (unsigned char)g;
	dst->blue = (unsigned char)b;
	dst->alpha = 255;
	dst->ac_type = AC_TYPE_NONE;
	dst->is_alphacolor = 0;
	dst->alphacolor = -1;
	dst->magic = 0xAC01;

	dst->raw8 = (unsigned char)palette_find( r, g, b );
}
Example #4
0
// Create "hard light" lookup table (multiply and screen combined)
unsigned char * palette_table_hardlight(unsigned char *pal){
	int fg, bg;
	int red, green, blue;
	unsigned char * lut;

	if(pal==NULL) return NULL;

	lut = (unsigned char*)malloc(256*256);
	if(lut==NULL) return NULL;

	for(fg=0; fg<256; fg++){
		for(bg=fg; bg<256; bg++){
			red = hardlight(pal[bg*3], pal[fg*3]);
			green = hardlight(pal[bg*3+1], pal[fg*3+1]);
			blue = hardlight(pal[bg*3+2], pal[fg*3+2]);

			lut[(fg<<8)+bg] = palette_find(pal, red, green, blue);
			lut[(bg<<8)+fg] = lut[(fg<<8)+bg];
		}
	}
	return lut;
}
Example #5
0
// Create a lookup table for 'screen'
unsigned char * palette_table_screen(unsigned char *pal){
	int fg, bg;
	int red, green, blue;
	unsigned char * lut;

	if(pal==NULL) return NULL;

	lut = (unsigned char*)malloc(256*256);
	if(lut==NULL) return NULL;

	for(fg=0; fg<256; fg++){
		for(bg=fg; bg<256; bg++){
			red =   ((pal[fg*3] * (255 - pal[bg*3])) / 255) + pal[bg*3];
			green = ((pal[fg*3+1] * (255 - pal[bg*3+1])) / 255) + pal[bg*3+1];
			blue =  ((pal[fg*3+2] * (255 - pal[bg*3+2])) / 255) + pal[bg*3+2];

			lut[(fg<<8)+bg] = palette_find(pal, red, green, blue);
			lut[(bg<<8)+fg] = lut[(fg<<8)+bg];
		}
	}
	return lut;
}
Example #6
0
// Create a lookup table used for shadows (multiply in photoshop)
unsigned char * palette_table_multiply(unsigned char *pal){
	int fg, bg;
	int red, green, blue;
	unsigned char * lut;

	if(pal==NULL) return NULL;

	lut = (unsigned char*)malloc(256*256);
	if(lut==NULL) return NULL;

	for(fg=0; fg<256; fg++){
		for(bg=fg; bg<256; bg++){
			red = pal[bg*3] * pal[fg*3] / 255;
			green = pal[bg*3+1] * pal[fg*3+1] / 255;
			blue = pal[bg*3+2] * pal[fg*3+2] / 255;

			lut[(fg<<8)+bg] = palette_find(pal, red, green, blue);
			lut[(bg<<8)+fg] = lut[(fg<<8)+bg];
		}
	}
	return lut;
}
Example #7
0
void calc_alphacolor_hud_type_old( alphacolor_old * ac )
{
	int i,j;
	int tr,tg,tb, Sr, Sg, Sb;
	ubyte * pal;
	int r, g, b, alpha;
	float falpha;

	// Assert(Alphacolors_intited);

//	mprintf(( "Calculating alphacolor for %d,%d,%d,%d\n", ac->r, ac->g, ac->b, ac->alpha ));

	falpha = i2fl(ac->alpha)/255.0f;
	if ( falpha<0.0f ) falpha = 0.0f; else if ( falpha > 1.0f ) falpha = 1.0f;

	alpha = ac->alpha >> 4;
	if (alpha < 0 ) alpha = 0; else if (alpha > 15 ) alpha = 15;
	r = ac->r;
	if (r < 0 ) r = 0; else if (r > 255 ) r = 255;
	g = ac->g;
	if (g < 0 ) g = 0; else if (g > 255 ) g = 255;
	b = ac->b;
	if (b < 0 ) b = 0; else if (b > 255 ) b = 255;

	int ii[16];

	for (j=1; j<15; j++ )	{

		// JAS: Use 1.5/Gamma instead of 1/Gamma because on Adam's
		// PC a gamma of 1.2 makes text look good, but his gamma is
		// really 1.8.   1.8/1.2 = 1.5
		float factor = falpha * (float)pow(i2fl(j)/14.0f, 1.5f/Gr_gamma);
		//float factor = i2fl(j)/14.0f;

		tr = fl2i( i2fl(r) * factor );
		tg = fl2i( i2fl(g) * factor );
		tb = fl2i( i2fl(b) * factor );

		ii[j] = tr;
		if ( tg > ii[j] )	ii[j] = tg;
		if ( tb > ii[j] )	ii[j] = tb;
	}

	pal = gr_palette;

	int m = r;
	if ( g > m ) m = g;
	if ( b > m ) m = b;

	ubyte ri[256], gi[256], bi[256];

	if ( m > 0 )	{
		for (i=0; i<256; i++ )	{
			ri[i] = ubyte((i*r)/m);
			gi[i] = ubyte((i*g)/m);
			bi[i] = ubyte((i*b)/m);
		}
	} else {
		for (i=0; i<256; i++ )	{
			ri[i] = 0;
			gi[i] = 0;
			bi[i] = 0;
		}
	}

	for (i=0; i<256; i++ )	{
		Sr = pal[0];
		Sg = pal[1];
		Sb = pal[2];
		pal += 3;

		int dst_intensity = Sr;
		if ( Sg > dst_intensity ) dst_intensity = Sg;
		if ( Sb > dst_intensity ) dst_intensity = Sb;

		ac->table.lookup[0][i] = (unsigned char)i;

		for (j=1; j<15; j++ )	{

			int tmp_i = max( ii[j], dst_intensity );

			ac->table.lookup[j][i] = (unsigned char)palette_find(ri[tmp_i],gi[tmp_i],bi[tmp_i]);
		}

		float di = (i2fl(Sr)*.30f+i2fl(Sg)*0.60f+i2fl(Sb)*.10f)/255.0f;
		float factor = 0.0f + di*0.75f;

		tr = fl2i( factor*i2fl(r)*falpha );
		tg = fl2i( factor*i2fl(g)*falpha );
		tb = fl2i( factor*i2fl(b)*falpha );

		if ( tr > 255 ) tr = 255; else if ( tr < 0 ) tr = 0;
		if ( tg > 255 ) tg = 255; else if ( tg < 0 ) tg = 0; 
		if ( tb > 255 ) tb = 255; else if ( tb < 0 ) tb = 0;

		ac->table.lookup[15][i] = (unsigned char)palette_find(tr,tg,tb);
		//ac->table.lookup[15][i] = (unsigned char)palette_find(255,0,0);
	}
}
Example #8
0
void calc_alphacolor_blend_type( alphacolor * ac )
{
#ifndef HARDWARE_ONLY
	int i,j;
	int tr,tg,tb, Sr, Sg, Sb;
	int Dr, Dg, Db;
	ubyte * pal;
	int r, g, b, alpha;

	Assert(Alphacolors_intited);

//	mprintf(( "Calculating alphacolor for %d,%d,%d,%d\n", ac->r, ac->g, ac->b, ac->alpha ));

	alpha = ac->alpha >> 4;
	if (alpha < 0 ) alpha = 0; else if (alpha > 15 ) alpha = 15;
	r = ac->r;
	if (r < 0 ) r = 0; else if (r > 255 ) r = 255;
	g = ac->g;
	if (g < 0 ) g = 0; else if (g > 255 ) g = 255;
	b = ac->b;
	if (b < 0 ) b = 0; else if (b > 255 ) b = 255;

	int gamma_j1[16];

	for (j=1; j<16; j++ )	{
		// JAS: Use 1.5/Gamma instead of 1/Gamma because on Adam's
		// PC a gamma of 1.2 makes text look good, but his gamma is
		// really 1.8.   1.8/1.2 = 1.5
		gamma_j1[j] = (int)((pow(i2fl(j)/15.0f, 1.5f/Gr_gamma)*16.0f) + 0.5);
	}

	pal = gr_palette;

	for (i=0; i<256; i++ )	{
		Sr = pal[0];
		Sg = pal[1];
		Sb = pal[2];
		pal += 3;
	
		Dr = ( Sr*(16-alpha) + (r*alpha) ) >> 4;
		Dg = ( Sg*(16-alpha) + (g*alpha) ) >> 4;
		Db = ( Sb*(16-alpha) + (b*alpha) ) >> 4;

		ac->table.lookup[0][i] = (unsigned char)i;

		for (j=1; j<16; j++ )	{

			int j1 = gamma_j1[j];

			tr = ( Sr*(16-j1) + (Dr*j1) ) >> 4;
			tg = ( Sg*(16-j1) + (Dg*j1) ) >> 4;
			tb = ( Sb*(16-j1) + (Db*j1) ) >> 4;

			if ( tr > 255 ) tr = 255; else if ( tr < 0 ) tr = 0;
			if ( tg > 255 ) tg = 255; else if ( tg < 0 ) tg = 0; 
			if ( tb > 255 ) tb = 255; else if ( tb < 0 ) tb = 0;

			ac->table.lookup[j][i] = (unsigned char)palette_find(tr,tg,tb);
		}
	}
#endif
}