Example #1
0
void cairox_select_colour_scale(cairo_t *cr, double d)
{
    double r, g, b;

    if (d < 1.0) {
        hsl_to_rgb(d * 0.667, 1.0, 0.5, &r, &g, &b);
    }
    else{
        hsl_to_rgb(0.667, 1.0, 0.5, &r, &g, &b);
    }
    cairo_set_source_rgb(cr, r, g, b);
}
// must match hslimage.c
vector hslimage_color(vector v, vector margin)
{
    v_x = (v_x - margin_x) / (1 - 2 * margin_x);
    v_y = (v_y - margin_y) / (1 - 2 * margin_y);
    if(v_x < 0) v_x = 0;
    if(v_y < 0) v_y = 0;
    if(v_x > 1) v_x = 1;
    if(v_y > 1) v_y = 1;
    if(v_y > 0.875) // grey bar
        return hsl_to_rgb(eZ * v_x);
    else
        return hsl_to_rgb(v_x * 6 * eX + eY + v_y / 0.875 * eZ);
}
Example #3
0
AudioColorScheme::AudioColorScheme(int prec, std::string const& scheme_name, int audio_rendering_style)
: palette((3<<prec) + 3)
, factor(1<<prec)
{
	std::string opt_base = "Colour/Schemes/" + scheme_name + "/";
	switch (static_cast<AudioRenderingStyle>(audio_rendering_style))
	{
		case AudioStyle_Normal:   opt_base += "Normal/"; break;
		case AudioStyle_Inactive: opt_base += "Inactive/"; break;
		case AudioStyle_Selected: opt_base += "Selection/"; break;
		case AudioStyle_Primary:  opt_base += "Primary/"; break;
		default: throw agi::InternalError("Unknown audio rendering styling");
	}

	double h_base  = OPT_GET(opt_base + "Hue Offset")->GetDouble();
	double h_scale = OPT_GET(opt_base + "Hue Scale")->GetDouble();
	double s_base  = OPT_GET(opt_base + "Saturation Offset")->GetDouble();
	double s_scale = OPT_GET(opt_base + "Saturation Scale")->GetDouble();
	double l_base  = OPT_GET(opt_base + "Lightness Offset")->GetDouble();
	double l_scale = OPT_GET(opt_base + "Lightness Scale")->GetDouble();

	for (size_t i = 0; i <= factor; ++i)
	{
		float t = (float)i / factor;
		hsl_to_rgb(
			mid<int>(0, h_base + t * h_scale, 255),
			mid<int>(0, s_base + t * s_scale, 255),
			mid<int>(0, l_base + t * l_scale, 255),
			&palette[i * 3 + 0],
			&palette[i * 3 + 1],
			&palette[i * 3 + 2]);
	}
}
Example #4
0
void MENUS::render_loading(float percent)
{
	static int64 last_load_render = 0;

	// make sure that we don't render for each little thing we load
	// because that will slow down loading if we have vsync
	if(time_get()-last_load_render < time_freq()/60)
		return;
		
	last_load_render = time_get();
	
	// need up date this here to get correct
	vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f));
	gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f);
	
    RECT screen = *ui_screen();
	gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
	
	render_background();

	float tw;

	float w = 700;
	float h = 200;
	float x = screen.w/2-w/2;
	float y = screen.h/2-h/2;

	gfx_blend_normal();

	gfx_texture_set(-1);
	gfx_quads_begin();
	gfx_setcolor(0,0,0,0.50f);
	draw_round_rect(x, y, w, h, 40.0f);
	gfx_quads_end();


	const char *caption = localize("Loading");

	tw = gfx_text_width(0, 48.0f, caption, -1);
	RECT r;
	r.x = x;
	r.y = y+20;
	r.w = w;
	r.h = h;
	ui_do_label(&r, caption, 48.0f, 0, -1);

	gfx_texture_set(-1);
	gfx_quads_begin();
	gfx_setcolor(1,1,1,0.75f);
	draw_round_rect(x+40, y+h-75, (w-80)*percent, 25, 5.0f);
	gfx_quads_end();

	gfx_swap();
}
Example #5
0
// calculate new brighter color using rgb_color
//
COLORREF GetLighterColor(COLORREF rgb_color, float percent)
{
	float h, s, l;
	rgb_to_hsl(GetRValue(rgb_color) / 255.0f, GetGValue(rgb_color) / 255.0f, GetBValue(rgb_color) / 255.0f, &h, &s, &l);

//	l += (l + 0.01f) * percent / 100.0f;
	l += percent / 100.0f;
	if (l < 0.0f)
		l = 0.0f;
	else if (l > 1.0f)
		l = 1.0f;

	float r, g, b;
	hsl_to_rgb(h, s, l, &r, &g, &b);

	return RGB(uint8(r * 255), uint8(g * 255), uint8(b * 255));
}
Example #6
0
Color3
ShadingSystemImpl::to_rgb (ustring fromspace, float a, float b, float c)
{
    if (fromspace == Strings::RGB || fromspace == Strings::rgb)
        return Color3 (a, b, c);
    if (fromspace == Strings::hsv)
        return hsv_to_rgb (a, b, c);
    if (fromspace == Strings::hsl)
        return hsl_to_rgb (a, b, c);
    if (fromspace == Strings::YIQ)
        return YIQ_to_rgb (a, b, c);
    if (fromspace == Strings::XYZ)
        return XYZ_to_RGB (a, b, c);
    if (fromspace == Strings::xyY)
        return XYZ_to_RGB (xyY_to_XYZ (Color3(a,b,c)));
    error ("Unknown color space \"%s\"", fromspace.c_str());
    return Color3 (a, b, c);
}
static PyObject *
pyhsl_to_rgb(PyObject *self, PyObject *args)
{
    double r,g,b,a=1.0,h,l,s;
    if(!PyArg_ParseTuple(
	   args,
	   "ddd|d",
	   &h,&s,&l,&a))
    {
	return NULL;
    }

    hsl_to_rgb(h,s,l,&r,&g,&b);

    return Py_BuildValue(
	"(dddd)",
	r,g,b,a);
}
Example #8
0
void plot_segment_order(const Route& r, const char* filename) {
  std::ofstream os(filename);
  SvgWriter svg(r, os);

  hsl_color hsl;
  rgb_color rgb;

  hsl.h = 0;
  hsl.s = 100;
  hsl.l = 50;


  float step = 360.0f / segments(r).size();
  for(const SegmentPtr seg : segments(r)) {
    hsl.h = (hsl.h+step);
    if (hsl.h >= 360) {
      hsl.h = 1;
    }
    rgb = hsl_to_rgb(hsl);
    string strokergb = (boost::format("stroke:rgb(%u,%u,%u)") % round(rgb.r) % round(rgb.g) % round(rgb.b)).str();
    svg.write(*seg.get(), strokergb + ";stroke-width:10;");
 }

  uint32_t count = 0;
  Coord_t a,b;
  Point front, back, mark;

  for(const SegmentPtr seg : segments(r)) {
    front = seg.get()->front();
    back = seg.get()->back();
    a = std::abs(front.x - back.x);
    b = std::abs(front.y - back.y);

    mark.x = std::min(front.x, back.x) + a/2;
    mark.y = std::min(front.y, back.y) + b/2;

    svg.write(mark, "stroke:rgb(255,0,0);stroke-width:40;");
    svg.write((boost::format("%d") % count).str(), mark, "font-size=\"50\" fill=\"black\"");

    ++count;
  }
}
Example #9
0
void plot_path_order(const Route& r, const char* filename) {
  std::ofstream os(filename);
  SvgWriter svg(r, os);
  std::vector<Point> sharedPoints;

  hsl_color hsl;
  rgb_color rgb;

  hsl.h = 0;
  hsl.s = 100;
  hsl.l = 50;

  float step = 360.0f / r.size();
  for(const Path& path : r) {
    hsl.h = (hsl.h+step);
    if (hsl.h >= 360) {
      hsl.h = 1;
    }
    rgb = hsl_to_rgb(hsl);
    string strokergb = (boost::format("stroke:rgb(%u,%u,%u)") % round(rgb.r) % round(rgb.g) % round(rgb.b)).str();
    svg.write(path, strokergb + ";stroke-width:10;fill:none;");

    svg.write(path.front(), "stroke:rgb(255,0,0);stroke-width:40;");
    svg.write(path.back(), "stroke:rgb(0,255,0);stroke-width:35;");
  }

  uint32_t count = 0;
  for(const Path& path : r) {
    svg.write(path.front(), "stroke:rgb(255,0,0);stroke-width:40;");
    svg.write(path.back(), "stroke:rgb(0,255,0);stroke-width:35;");
    svg.write((boost::format("%d") % count).str(), path.front(), "font-size=\"50\" fill=\"black\"");
    svg.write((boost::format("%d") % count).str(), path.back(), "font-size=\"50\" fill=\"black\"");

    ++count;
  }

  for(const Point& p : sharedPoints) {
    svg.write(p, "stroke:rgb(255,0,0);stroke-width:10;fill:none");
  }
}
Example #10
0
void plot_point_order(const Route& r, const char* filename) {
  std::ofstream os(filename);
  SvgWriter svg(r, os);

  hsl_color hsl;
  rgb_color rgb;

  hsl.h = 0;
  hsl.s = 100;
  hsl.l = 50;


  float step = 360.0f / segments(r).size();
  for(const SegmentPtr seg : segments(r)) {
    hsl.h = (hsl.h+step);
    if (hsl.h >= 360) {
      hsl.h = 1;
    }
    rgb = hsl_to_rgb(hsl);
    string strokergb = (boost::format("stroke:rgb(%u,%u,%u)") % round(rgb.r) % round(rgb.g) % round(rgb.b)).str();
    svg.write(*seg.get(), strokergb + ";stroke-width:10;");
  }

  uint32_t count = 0;
  Point last;
  for(const Path& path : r) {
    for(const Point& p : path) {
      if(p == last)
        return;
      svg.write(p, "fill:rgb(127,127,127);stroke-width:0;");
      svg.write((boost::format("%d") % count).str(), p, "font-size=\"50\" fill=\"black\"");
      ++count;
      last = p;
    }
  }
}
Example #11
0
void MENUS::on_render()
{
	/*
	// text rendering test stuff
	render_background();

	TEXT_CURSOR cursor;
	gfx_text_set_cursor(&cursor, 10, 10, 20, TEXTFLAG_RENDER);
	gfx_text_ex(&cursor, "ようこそ - ガイド", -1);

	gfx_text_set_cursor(&cursor, 10, 30, 15, TEXTFLAG_RENDER);
	gfx_text_ex(&cursor, "ようこそ - ガイド", -1);
	
	//gfx_texture_set(-1);
	gfx_quads_begin();
	gfx_quads_drawTL(60, 60, 5000, 5000);
	gfx_quads_end();
	return;*/
	
	if(client_state() != CLIENTSTATE_ONLINE && client_state() != CLIENTSTATE_DEMOPLAYBACK)
		set_active(true);

	if(client_state() == CLIENTSTATE_DEMOPLAYBACK)
	{
		RECT screen = *ui_screen();
		gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);
		render_demoplayer(screen);
	}
	
	if(client_state() == CLIENTSTATE_ONLINE && gameclient.servermode == gameclient.SERVERMODE_PUREMOD)
	{
		client_disconnect();
		set_active(true);
		popup = POPUP_PURE;
	}
	
	if(!is_active())
	{
		escape_pressed = false;
		enter_pressed = false;
		num_inputevents = 0;
		return;
	}
	
	// update colors
	vec3 rgb = hsl_to_rgb(vec3(config.ui_color_hue/255.0f, config.ui_color_sat/255.0f, config.ui_color_lht/255.0f));
	gui_color = vec4(rgb.r, rgb.g, rgb.b, config.ui_color_alpha/255.0f);

	color_tabbar_inactive_outgame = vec4(0,0,0,0.25f);
	color_tabbar_active_outgame = vec4(0,0,0,0.5f);

	float color_ingame_scale_i = 0.5f;
	float color_ingame_scale_a = 0.2f;
	color_tabbar_inactive_ingame = vec4(
		gui_color.r*color_ingame_scale_i,
		gui_color.g*color_ingame_scale_i,
		gui_color.b*color_ingame_scale_i,
		gui_color.a*0.8f);
	
	color_tabbar_active_ingame = vec4(
		gui_color.r*color_ingame_scale_a,
		gui_color.g*color_ingame_scale_a,
		gui_color.b*color_ingame_scale_a,
		gui_color.a);
    
	// update the ui
	RECT *screen = ui_screen();
	float mx = (mouse_pos.x/(float)gfx_screenwidth())*screen->w;
	float my = (mouse_pos.y/(float)gfx_screenheight())*screen->h;
		
	int buttons = 0;
	if(inp_key_pressed(KEY_MOUSE_1)) buttons |= 1;
	if(inp_key_pressed(KEY_MOUSE_2)) buttons |= 2;
	if(inp_key_pressed(KEY_MOUSE_3)) buttons |= 4;
		
	ui_update(mx,my,mx*3.0f,my*3.0f,buttons);
    
	// render
	if(client_state() != CLIENTSTATE_DEMOPLAYBACK)
		render();

	// render cursor
	gfx_texture_set(data->images[IMAGE_CURSOR].id);
	gfx_quads_begin();
	gfx_setcolor(1,1,1,1);
	gfx_quads_drawTL(mx,my,24,24);
	gfx_quads_end();

	// render debug information
	if(config.debug)
	{
		RECT screen = *ui_screen();
		gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);

		char buf[512];
		str_format(buf, sizeof(buf), "%p %p %p", ui_hot_item(), ui_active_item(), ui_last_active_item());
		TEXT_CURSOR cursor;
		gfx_text_set_cursor(&cursor, 10, 10, 10, TEXTFLAG_RENDER);
		gfx_text_ex(&cursor, buf, -1);
	}

	escape_pressed = false;
	enter_pressed = false;
	num_inputevents = 0;
}
Example #12
0
char* hsl_to_hex(t_hsl color)
{
    t_rgb ncolor = hsl_to_rgb(color);
    return rgb_to_hex(ncolor);
}
Example #13
0
void egraphics_set_color_hsl(t_elayer *g, const t_hsl *hsl)
{
    t_rgb color = hsl_to_rgb(*hsl);
    g->e_color = gensym(rgb_to_hex(color));
}
Example #14
0
/// @brief Constructor 
/// @param _fps    
/// @param frames  
/// @param _width  
/// @param _height 
/// @param colour  
/// @param pattern 
///
void DummyVideoProvider::Create(double _fps, int frames, int _width, int _height, const wxColour &colour, bool pattern) {
	lastFrame = -1;
	framecount = frames;
	fps = _fps;
	width = _width;
	height = _height;

	frame = AegiVideoFrame(width,height);
	unsigned char *dst = frame.data;
	unsigned char r = colour.Red(), g = colour.Green(), b = colour.Blue();

	unsigned char h, s, l, lr, lg, lb; // light variants
	rgb_to_hsl(r, g, b, &h, &s, &l);
	l += 24;
	if (l < 24) l -= 48;
	hsl_to_rgb(h, s, l, &lr, &lg, &lb);

	if (pattern) {
		int ppitch = frame.pitch / frame.GetBpp();
		for (unsigned int y = 0; y < frame.h; ++y) {
			if ((y / 8) & 1) {
				for (int x = 0; x < ppitch; ++x) {
					if ((x / 8) & 1) {
						*dst++ = b;
						*dst++ = g;
						*dst++ = r;
						*dst++ = 0;
					}
					else {
						*dst++ = lb;
						*dst++ = lg;
						*dst++ = lr;
						*dst++ = 0;
					}
				}
			}
			else {
				for (int x = 0; x < ppitch; ++x) {
					if ((x / 8) & 1) {
						*dst++ = lb;
						*dst++ = lg;
						*dst++ = lr;
						*dst++ = 0;
					}
					else {
						*dst++ = b;
						*dst++ = g;
						*dst++ = r;
						*dst++ = 0;
					}
				}
			}
		}
	}
	else {
		for (int i=frame.pitch*frame.h/frame.GetBpp();--i>=0;) {
			*dst++ = b;
			*dst++ = g;
			*dst++ = r;
			*dst++ = 0;
		}
	}
}