Esempio n. 1
0
void palette_normalize_range(palette_t *palette, UINT32 start, UINT32 end, int lum_min, int lum_max)
{
	UINT32 ymin = 1000 * 255, ymax = 0;
	UINT32 tmin, tmax;
	UINT32 index;

	/* clamp within range */
	start = MAX(start, 0);
	end = MIN(end, palette->numcolors - 1);

	/* find the minimum and maximum brightness of all the colors in the range */
	for (index = start; index <= end; index++)
	{
		rgb_t rgb = palette->entry_color[index];
		UINT32 y = 299 * RGB_RED(rgb) + 587 * RGB_GREEN(rgb) + 114 * RGB_BLUE(rgb);
		ymin = MIN(ymin, y);
		ymax = MAX(ymax, y);
	}

	/* determine target minimum/maximum */
	tmin = (lum_min < 0) ? ((ymin + 500) / 1000) : lum_min;
	tmax = (lum_max < 0) ? ((ymax + 500) / 1000) : lum_max;

	/* now normalize the palette */
	for (index = start; index <= end; index++)
	{
		rgb_t rgb = palette->entry_color[index];
		UINT32 y = 299 * RGB_RED(rgb) + 587 * RGB_GREEN(rgb) + 114 * RGB_BLUE(rgb);
		UINT32 target = tmin + ((y - ymin) * (tmax - tmin + 1)) / (ymax - ymin);
		UINT8 r = (y == 0) ? 0 : rgb_clamp(RGB_RED(rgb) * 1000 * target / y);
		UINT8 g = (y == 0) ? 0 : rgb_clamp(RGB_GREEN(rgb) * 1000 * target / y);
		UINT8 b = (y == 0) ? 0 : rgb_clamp(RGB_BLUE(rgb) * 1000 * target / y);
		palette_entry_set_color(palette, index, MAKE_RGB(r, g, b));
	}
}
Esempio n. 2
0
INLINE rgb_t adjust_palette_entry(rgb_t entry, float brightness, float contrast, const UINT8 *gamma_map)
{
	int r = rgb_clamp((float)gamma_map[RGB_RED(entry)] * contrast + brightness);
	int g = rgb_clamp((float)gamma_map[RGB_GREEN(entry)] * contrast + brightness);
	int b = rgb_clamp((float)gamma_map[RGB_BLUE(entry)] * contrast + brightness);
	int a = RGB_ALPHA(entry);
	return MAKE_ARGB(a,r,g,b);
}
void razer_mix_frame_column(struct razer_rgb_frame *frame,int column_index,struct razer_rgb *color,float opacity)
{
	if(column_index<0 || column_index>21)
		return;
	int y;
	for(y=0;y<6;y++)
	{
		frame->rows[y].column[column_index].r = rgb_clamp((1.0f-opacity)*frame->rows[y].column[column_index].r + color->r*opacity);
		frame->rows[y].column[column_index].g = rgb_clamp((1.0f-opacity)*frame->rows[y].column[column_index].g + color->g*opacity);
		frame->rows[y].column[column_index].b = rgb_clamp((1.0f-opacity)*frame->rows[y].column[column_index].b + color->b*opacity);
	}
	frame->update_mask = 63;
}
Esempio n. 4
0
void palette_set_shadow_dRGB32(running_machine *machine, int mode, int dr, int dg, int db, int noclip)
{
	palette_private *palette = machine->palette_data;
	shadow_table_data *stable = &palette->shadow_table[mode];
	int i;

	/* only applies to RGB direct modes */
	assert(palette->format != BITMAP_FORMAT_INDEXED16);
	assert(stable->base != NULL);

	/* clamp the deltas (why?) */
	if (dr < -0xff) dr = -0xff; else if (dr > 0xff) dr = 0xff;
	if (dg < -0xff) dg = -0xff; else if (dg > 0xff) dg = 0xff;
	if (db < -0xff) db = -0xff; else if (db > 0xff) db = 0xff;

	/* early exit if nothing changed */
	if (dr == stable->dr && dg == stable->dg && db == stable->db && noclip == stable->noclip)
		return;
	stable->dr = dr;
	stable->dg = dg;
	stable->db = db;
	stable->noclip = noclip;

	#if VERBOSE
		popmessage("shadow %d recalc %d %d %d %02x", mode, dr, dg, db, noclip);
	#endif

	/* regenerate the table */
	for (i = 0; i < 32768; i++)
	{
		int r = pal5bit(i >> 10) + dr;
		int g = pal5bit(i >> 5) + dg;
		int b = pal5bit(i >> 0) + db;
		pen_t final;

		/* apply clipping */
		if (!noclip)
		{
			r = rgb_clamp(r);
			g = rgb_clamp(g);
			b = rgb_clamp(b);
		}
		final = MAKE_RGB(r, g, b);

		/* store either 16 or 32 bit */
		if (palette->format == BITMAP_FORMAT_RGB32)
			stable->base[i] = final;
		else
Esempio n. 5
0
void palette_set_gamma(palette_t *palette, float gamma)
{
	int groupnum, index;

	/* set the global gamma if changed */
	if (palette->gamma == gamma)
		return;
	palette->gamma = gamma;

	/* recompute the gamma map */
	gamma = 1.0f / gamma;
	for (index = 0; index < 256; index++)
	{
		float fval = (float)index * (1.0f / 255.0f);
		float fresult = pow(fval, gamma);
		palette->gamma_map[index] = rgb_clamp(255.0f * fresult);
	}

	/* update across all indices in all groups */
	for (groupnum = 0; groupnum < palette->numgroups; groupnum++)
		for (index = 0; index < palette->numcolors; index++)
			update_adjusted_color(palette, groupnum, index);
}
void rgb_mix(struct razer_rgb *dst,struct razer_rgb *src,float dst_opacity)
{
	dst->r = rgb_clamp((1.0f-dst_opacity)*dst->r + src->r*dst_opacity);
	dst->g = rgb_clamp((1.0f-dst_opacity)*dst->g + src->g*dst_opacity);
	dst->b = rgb_clamp((1.0f-dst_opacity)*dst->b + src->b*dst_opacity);
}
void rgb_add(struct razer_rgb *dst,struct razer_rgb *src)
{
	dst->r = rgb_clamp(dst->r + src->r);
	dst->g = rgb_clamp(dst->g + src->g);
	dst->b = rgb_clamp(dst->b + src->b);
}
Esempio n. 8
0
static void	set_color_max(t_phpa *ph)
{
	rgb_add(ph->color, ph->diffuse->r, ph->diffuse->g, ph->diffuse->b);
	rgb_add(ph->color, ph->specular->r, ph->specular->g, ph->specular->b);
	rgb_clamp(ph->color);
}
void rgb_mix_into(struct razer_rgb *dst,struct razer_rgb *src_a,struct razer_rgb *src_b,float dst_opacity)
{
	dst->r = rgb_clamp((1.0f-dst_opacity)*src_a->r + src_b->r*dst_opacity);
	dst->g = rgb_clamp((1.0f-dst_opacity)*src_a->g + src_b->g*dst_opacity);
	dst->b = rgb_clamp((1.0f-dst_opacity)*src_a->b + src_b->b*dst_opacity);
}