static SkColor HSV_to_RGB(SkColor color, HSV_Choice choice, SkScalar hsv) {
    SkScalar hue = choice == kGetHue ? hsv : RGB_to_HSV(color, kGetHue);
    SkScalar saturation = choice == kGetSaturation ? hsv : RGB_to_HSV(color, kGetSaturation);
    SkScalar value = choice == kGetValue ? hsv : RGB_to_HSV(color, kGetValue);
    value *= 255;
    SkScalar red SK_INIT_TO_AVOID_WARNING;
    SkScalar green SK_INIT_TO_AVOID_WARNING;
    SkScalar blue SK_INIT_TO_AVOID_WARNING;
    if (saturation == 0)    // color is on black-and-white center line
        red = green = blue = value;
    else {
        //SkScalar fraction = SkScalarMod(hue, 60 * SK_Scalar1);
        int sextant = SkScalarFloor(hue / 60);
        SkScalar fraction = hue / 60 - SkIntToScalar(sextant);
        SkScalar p = SkScalarMul(value , SK_Scalar1 - saturation);
        SkScalar q = SkScalarMul(value, SK_Scalar1 - SkScalarMul(saturation, fraction));
        SkScalar t = SkScalarMul(value, SK_Scalar1 - 
            SkScalarMul(saturation, SK_Scalar1 - fraction));
        switch (sextant % 6) {
            case 0: red = value; green = t; blue = p; break;
            case 1: red = q; green = value; blue = p; break;
            case 2: red = p; green = value; blue = t; break;
            case 3: red = p; green = q; blue = value; break;
            case 4: red = t;  green = p; blue = value; break;
            case 5: red = value; green = p; blue = q; break;
        }
    }
    //used to say SkToU8((U8CPU) red) etc
    return SkColorSetARGB(SkColorGetA(color), SkScalarRound(red), 
        SkScalarRound(green), SkScalarRound(blue));
}
bool SkDrawColor::getProperty(int index, SkScriptValue* value) const {
    value->fType = SkType_Float;
    SkScalar result;
    switch(index) {
        case SK_PROPERTY(alpha):
            result = SkIntToScalar(SkColorGetA(color)) / 255;
            break;
        case SK_PROPERTY(blue):
            result = SkIntToScalar(SkColorGetB(color));
            break;
        case SK_PROPERTY(green):
            result = SkIntToScalar(SkColorGetG(color));
            break;
        case SK_PROPERTY(hue):
            result = RGB_to_HSV(color, kGetHue);
            break;
        case SK_PROPERTY(red):
            result = SkIntToScalar(SkColorGetR(color));
            break;
        case SK_PROPERTY(saturation):
            result = RGB_to_HSV(color, kGetSaturation);
            break;
        case SK_PROPERTY(value):
            result = RGB_to_HSV(color, kGetValue);
            break;
        default:
            SkASSERT(0);
            return false;
    }
    value->fOperand.fScalar = result;
    return true;
}
Example #3
0
void ColorPicker::OnSlide(Slide *slide, int slideId, double pos)
{
	switch(slideId)
	{
	case SL_COLOR:
		{
			int color = pos*255;

			if(fixedColor <= FIX_BLUE)
			{
				switch(fixedColor)
				{
				case FIX_RED:
					r = color;			
					break;
					
				case FIX_GREEN:
					g = color;
					break;
					
				case FIX_BLUE:
					b = color;
					break;
				}

				UpdateSample(r, g, b);
			}
			else
			{
				double H, S, V;
				KrRGBA c;

				RGB_to_HSV(r, g, b, H, S, V);

				switch(fixedColor)
				{					
				case FIX_HUE:					
					c = HSV_to_RGB(color, S, V);
					break;
					
				case FIX_SATURATION:
					c = HSV_to_RGB(H, color, V);					
					break;
					
				case FIX_BRIGHTNESS:
					c = HSV_to_RGB(H, S, color);
					break;
				}

				UpdateSample(c.c.red, c.c.green, c.c.blue);
			}			

			UpdateCanvas(color, fixedColor);
		}
		break;
	}

	
}
		void TextChangedCallback(ui::Textbox * sender)
		{
			int r, g, b;
			r = format::StringToNumber<int>(a->rValue->GetText());
			g = format::StringToNumber<int>(a->gValue->GetText());
			b = format::StringToNumber<int>(a->bValue->GetText());
			RGB_to_HSV(r, g, b, &a->currentHue, &a->currentSaturation, &a->currentValue);
		}
Example #5
0
void ColorPicker::UpdateColorControls()
{
	UpdateSlideColor(r, g, b, fixedColor);

	if(fixedColor <= FIX_BLUE)
	{
		switch(fixedColor)
		{
		case FIX_RED:
			colorSlide->SetPos(r/255.0);
			canvas->SetPointer(b, 255 - g);
			break;
			
		case FIX_GREEN:
			colorSlide->SetPos(g/255.0);
			canvas->SetPointer(b, 255 - r);
			break;
			
		case FIX_BLUE:
			colorSlide->SetPos(b/255.0);
			canvas->SetPointer(r, 255 - g);
			break;
		}
	}
	else
	{
		double H, S, V;
		RGB_to_HSV(r, g, b, H, S, V);		
		
		switch(fixedColor)
		{
		case FIX_HUE:					
			colorSlide->SetPos(H/255.0);
			canvas->SetPointer(S, 255 - V);
			break;
			
		case FIX_SATURATION:
			colorSlide->SetPos(S/255.0);
			canvas->SetPointer(H, 255 - V);
			break;
			
		case FIX_BRIGHTNESS:
			colorSlide->SetPos(V/255.0);
			canvas->SetPointer(H, 255 - S);
			break;
		}
		
	}

	UpdateCanvas(colorSlide->GetPos()*255, fixedColor);
}
Example #6
0
//---------------------------------------------------------------------------
void __fastcall TMainForm::CalculateColors()
{
    unsigned char red,green,blue;
    try
    {
        red   = StrToInt(this->LabeledEdit1->Text);
        green = StrToInt(this->LabeledEdit2->Text);
        blue  = StrToInt(this->LabeledEdit3->Text);
    }
    catch(...)
    {
        return;
    }
    double r,g,b;
    double x,y,z;
    double l,a,bb;
    double h,s,v;
    double ll;

    r = (double)red / 255.;
    g = (double)green / 255.;
    b = (double)blue / 255.;

    RGB_to_XYZ(r,g,b,x,y,z);

    LabeledEdit4->Text = FormatFloat("0.000", x);
    LabeledEdit5->Text = FormatFloat("0.000", y);
    LabeledEdit6->Text = FormatFloat("0.000", z);

    XYZ_to_LAB(x,y,z,l,a,bb);

    LabeledEdit7->Text = FormatFloat("000.000", l);
    LabeledEdit8->Text = FormatFloat("000.000", a);
    LabeledEdit9->Text = FormatFloat("000.000", bb);


    RGB_to_HSV(r,g,b,h,s,v);

    LabeledEdit10->Text = FormatFloat(".000", h);
    LabeledEdit11->Text = FormatFloat(".000", s);
    LabeledEdit12->Text = FormatFloat(".000", v);


    RGB_to_HSL(r,g,b,h,s,ll);

    LabeledEdit13->Text = FormatFloat(".000", h);
    LabeledEdit14->Text = FormatFloat(".000", s);
    LabeledEdit15->Text = FormatFloat(".000", ll);
}
Example #7
0
void ColorPicker::OnEditChar(EditBox *edit, SDLKey key, int line)
{
	int value = atol(edit->GetText().c_str());
	bool bUpdateHSV = true;

	if( (edit == rEdit || edit == gEdit || edit == bEdit) &&
		(value < 0 || value > 255))
	{
		return;
	}

	if( edit == hEdit &&
		(value < 0 || value > 359))
	{
		return;
	}

	if( (edit == sEdit || edit == vEdit) &&
		(value < 0 || value > 100))
	{
		return;
	}

	if(edit == rEdit) r = value;
	else if(edit == gEdit) g = value;
	else if(edit == bEdit) b = value;
	else
	{
		double H, S, V;
		KrRGBA c;

		RGB_to_HSV(r, g, b, H, S, V);

		if(edit == hEdit) c = HSV_to_RGB(round(255*value/360.0), S, V);
		else if(edit == sEdit) c = HSV_to_RGB(H, round(255*value/100.0), V);
		else if(edit == vEdit) c = HSV_to_RGB(H, S, round(255*value/100.0));

		r = c.c.red;
		g = c.c.green;
		b = c.c.blue;

		bUpdateHSV = false;
	}

	UpdateColorControls();	
	UpdateSample(r, g, b, bUpdateHSV);
}
Example #8
0
// SetMarkerToColor
void
ColorField::SetMarkerToColor(rgb_color color)
{
	float h, s, v;
	RGB_to_HSV(color.red / 255.0, color.green / 255.0, color.blue / 255.0,
		h, s, v );

	fLastMarkerPosition = fMarkerPosition;

	float width = Width();
	float height = Height();

	switch (fMode) {
		case R_SELECTED:
			fMarkerPosition = BPoint(color.green / 255.0 * width,
				(255.0 - color.blue) / 255.0 * height);
			break;

		case G_SELECTED:
			fMarkerPosition = BPoint(color.red / 255.0 * width,
				(255.0 - color.blue) / 255.0 * height);
			break;

		case B_SELECTED:
			fMarkerPosition = BPoint(color.red / 255.0 * width,
				(255.0 - color.green) / 255.0 * height);
			break;

		case H_SELECTED:
			if (fOrientation == B_VERTICAL)
				fMarkerPosition = BPoint(s * width, height - v * height);
			else
				fMarkerPosition = BPoint(width - v * width, s * height);
			break;

		case S_SELECTED:
			fMarkerPosition = BPoint(h / 6.0 * width, height - v * height);
			break;

		case V_SELECTED:
			fMarkerPosition = BPoint( h / 6.0 * width, height - s * height);
			break;
	}

	Invalidate();
}
		void TextChangedCallback(ui::Textbox * sender)
		{
			int r, g, b, alpha;
			r = format::StringToNumber<int>(a->rValue->GetText());
			g = format::StringToNumber<int>(a->gValue->GetText());
			b = format::StringToNumber<int>(a->bValue->GetText());
			alpha = format::StringToNumber<int>(a->aValue->GetText());
			if (r > 255)
				r = 255;
			if (g > 255)
				g = 255;
			if (b > 255)
				b = 255;
			if (alpha > 255)
				alpha = 255;

			RGB_to_HSV(r, g, b, &a->currentHue, &a->currentSaturation, &a->currentValue);
			a->currentAlpha = alpha;
			a->UpdateTextboxes(r, g, b, alpha);
		}
btVector3 TrackDisplay::modifyColor( btVector3 color,  int colorStyle, float f ) {
	switch(colorStyle) {
	case cs_fixed:
		break;
	case cs_channel:
		break;
	case cs_hue:
		color = RGB_to_HSV(color);
		color.setX( f );
		color = HSV_to_RGB(color);
		break;
	case cs_brightness:
		if(f < 0.5) {
			color = color * (f+0.5);
		} else {
			color = btVector3(1,1,1) - ( (btVector3(1,1,1) - color) * (0.5 + (1-f)) );
		}
		break;
	}
	return(color);
}
Example #11
0
// SetMarkerToColor
void
ColorSlider::SetMarkerToColor(rgb_color color)
{
	float h, s, v;
	if (fMode & (H_SELECTED | S_SELECTED | V_SELECTED)) {
		RGB_to_HSV((float)color.red / 255.0, 
				   (float)color.green / 255.0,
				   (float)color.blue / 255.0,
				   h, s, v);
	}
	
	switch (fMode) {
				
		case R_SELECTED: {
			SetValue( 255 - color.red );
		} break;
		
		case G_SELECTED: {
			SetValue( 255 - color.green );
		} break;

		case B_SELECTED: {
			SetValue( 255 - color.blue );
		} break;
		
		case H_SELECTED: {
			SetValue( 255.0 - round(h / 6.0 * 255.0) );
		} break;
		
		case S_SELECTED: {
			SetValue( 255.0 - round(s * 255.0) );
		} break;
		
		case V_SELECTED: {
			SetValue( 255.0 - round(v * 255.0) );
		} break;
		
	}
}
Example #12
0
void
ColorField::SetMarkerToColor(rgb_color color)
{
	float h;
	float s;
	float v;

	RGB_to_HSV((float)color.red / 255.0f, (float)color.green / 255.0f,
		(float)color.blue / 255.0f, h, s, v);

	fLastMarkerPosition = fMarkerPosition;

	switch (fColorMode) {
		case R_SELECTED:
			fMarkerPosition = BPoint(color.green, 255.0 - color.blue);
			break;

		case G_SELECTED:
			fMarkerPosition = BPoint(color.red, 255.0 - color.blue);
			break;

		case B_SELECTED:
			fMarkerPosition = BPoint(color.red, 255.0 - color.green);
			break;

		case H_SELECTED:
			fMarkerPosition = BPoint(s * 255.0, 255.0 - v * 255.0);
			break;

		case S_SELECTED:
			fMarkerPosition = BPoint(h / 6.0 * 255.0, 255.0 - v * 255.0);
			break;

		case V_SELECTED:
			fMarkerPosition = BPoint(h / 6.0 * 255.0, 255.0 - s * 255.0);
			break;
	}
}
Example #13
0
void ColorPicker::UpdateSample(int _r, int _g, int _b, bool bUpdateHSV)
{
	newColor->SetColor(_r, _g, _b);
	

	rSample = _r;
	gSample = _g;
	bSample = _b;

	rEdit->SetText(rSample);
	gEdit->SetText(gSample);
	bEdit->SetText(bSample);

	double H, S, V;
	RGB_to_HSV(rSample, gSample, bSample, H, S, V);

	if(bUpdateHSV)
	{
		hEdit->SetText(round(360*H/255.0));
		sEdit->SetText(round(100*S/255.0));
		vEdit->SetText(round(100*V/255.0));
	}
}
void TrackDisplay::createAxes(Ogre::Vector3 pos, Ogre::Quaternion orient,
		Ogre::Vector3 scale, btVector3 color, std::vector<
				ogre_tools::BillboardLine*> &vec) {


	for(int i=0;i<3;i++) {
		ogre_tools::BillboardLine* lines = newBillboardLine();

		lines->clear();
		lines->setPosition(pos);
		lines->setOrientation(orient);
		lines->setScale(scale);

		btVector3 hsv = RGB_to_HSV(color);
		hsv.setX(i/3.0);
		btVector3 axis_color = HSV_to_RGB(hsv);
		lines->setColor(axis_color.x(), axis_color.y(), axis_color.z(), alpha_);

		lines->setLineWidth(lineWidth_);
		lines->setMaxPointsPerLine(2);
		lines->setNumLines(1);

		Ogre::Vector3 v;

		v = Ogre::Vector3(0, 0, 0);
		v[i] = lineWidth_ * 5;
		rviz::robotToOgre(v);
		lines->addPoint(v);

		v = Ogre::Vector3(0, 0, 0);
		v[i] = -lineWidth_ * 5;
		rviz::robotToOgre(v);
		lines->addPoint(v);

		vec.push_back(lines);
	}
}
Example #15
0
void ColorPicker::UpdateSlideColor(int r, int g, int b, int fixedColor)
{
	KrRGBA *pixels = colorSlide->getCanvasResource()->Pixels(), color1, color2;
		
	int width = colorSlide->Width();

	if(fixedColor <= FIX_BLUE)
	{
		switch(fixedColor)
		{
		case FIX_RED:
			color1.Set(255, g, b);
			color2.Set(0, g, b);			
			break;
			
		case FIX_GREEN:
			color1.Set(r, 255, b);
			color2.Set(r, 0, b);			
			break;
			
		case FIX_BLUE:
			color1.Set(r, g, 255);
			color2.Set(r, g, 0);			
			break;
		}

		for(int i = 2; i < width - 3; i++)
		{
			for(int j = 1; j < 255; j++)
			{
				pixels[ j*width + i ] = SlowCanvas::MixColors(color1, color2, (j - 1)/(254.0));			
			}
		}
	}
	else
	{
		double H, S, V;
		RGB_to_HSV(r, g, b, H, S, V);
				
		for(int j = 1; j < 255; j++)
		{			
			KrRGBA color;

			switch(fixedColor)
			{
			case FIX_HUE:					
				color = HSV_to_RGB(255 - j, 255, 255);
				break;
				
			case FIX_SATURATION:
				color = HSV_to_RGB(H, 255 - j, V);
				break;
				
			case FIX_BRIGHTNESS:
				color = HSV_to_RGB(H, S, 255 - j);
				break;
			}

			for(int i = 2; i < width - 3; i++)
			{
				pixels[ j*width + i ] = color;				
			}
		}
	}

	colorSlide->getImage()->Invalidate();
	colorSlide->getCanvasResource()->Refresh();
}
Example #16
0
void CMultiColor::hsv(double& h, double& s, double& v)
{
	RGB_to_HSV(m_r, m_g, m_b, h,s,v);
}
ColourPickerActivity::ColourPickerActivity(ui::Colour initialColour, ColourPickedCallback * callback) :
	WindowActivity(ui::Point(-1, -1), ui::Point(266, 175)),
	currentHue(0),
	currentSaturation(0),
	currentValue(0),
	mouseDown(false),
	valueMouseDown(false),
	callback(callback)
{

	class ColourChange : public ui::TextboxAction
	{
		ColourPickerActivity * a;
	public:
		ColourChange(ColourPickerActivity * a) : a(a) {}

		void TextChangedCallback(ui::Textbox * sender)
		{
			int r, g, b, alpha;
			r = format::StringToNumber<int>(a->rValue->GetText());
			g = format::StringToNumber<int>(a->gValue->GetText());
			b = format::StringToNumber<int>(a->bValue->GetText());
			alpha = format::StringToNumber<int>(a->aValue->GetText());
			if (r > 255)
				r = 255;
			if (g > 255)
				g = 255;
			if (b > 255)
				b = 255;
			if (alpha > 255)
				alpha = 255;

			RGB_to_HSV(r, g, b, &a->currentHue, &a->currentSaturation, &a->currentValue);
			a->currentAlpha = alpha;
			a->UpdateTextboxes(r, g, b, alpha);
		}
	};

	rValue = new ui::Textbox(ui::Point(5, Size.Y-23), ui::Point(30, 17), "255");
	rValue->SetActionCallback(new ColourChange(this));
	rValue->SetLimit(3);
	rValue->SetInputType(ui::Textbox::Number);
	AddComponent(rValue);

	gValue = new ui::Textbox(ui::Point(40, Size.Y-23), ui::Point(30, 17), "255");
	gValue->SetActionCallback(new ColourChange(this));
	gValue->SetLimit(3);
	gValue->SetInputType(ui::Textbox::Number);
	AddComponent(gValue);

	bValue = new ui::Textbox(ui::Point(75, Size.Y-23), ui::Point(30, 17), "255");
	bValue->SetActionCallback(new ColourChange(this));
	bValue->SetLimit(3);
	bValue->SetInputType(ui::Textbox::Number);
	AddComponent(bValue);

	aValue = new ui::Textbox(ui::Point(110, Size.Y-23), ui::Point(30, 17), "255");
	aValue->SetActionCallback(new ColourChange(this));
	aValue->SetLimit(3);
	aValue->SetInputType(ui::Textbox::Number);
	AddComponent(aValue);

	hexValue = new::ui::Label(ui::Point(150, Size.Y-23), ui::Point(53, 17), "0xFFFFFFFF");
	AddComponent(hexValue);

	class OkayAction: public ui::ButtonAction
	{
		ColourPickerActivity * a;
	public:
		OkayAction(ColourPickerActivity * a) : a(a) { }
		void ActionCallback(ui::Button * sender)
		{
			int Red, Green, Blue;
			Red = format::StringToNumber<int>(a->rValue->GetText());
			Green = format::StringToNumber<int>(a->gValue->GetText());
			Blue = format::StringToNumber<int>(a->bValue->GetText());
			ui::Colour col(Red, Green, Blue, a->currentAlpha);
			if(a->callback)
				a->callback->ColourPicked(col);
			a->Exit();
		}
	};

	ui::Button * doneButton = new ui::Button(ui::Point(Size.X-45, Size.Y-23), ui::Point(40, 17), "Done");
	doneButton->SetActionCallback(new OkayAction(this));
	AddComponent(doneButton);
	SetOkayButton(doneButton);

	RGB_to_HSV(initialColour.Red, initialColour.Green, initialColour.Blue, &currentHue, &currentSaturation, &currentValue);
	currentAlpha = initialColour.Alpha;
	UpdateTextboxes(initialColour.Red, initialColour.Green, initialColour.Blue, initialColour.Alpha);
}
ColourPickerActivity::ColourPickerActivity(ui::Colour initialColour, ColourPickedCallback * callback) :
	WindowActivity(ui::Point(-1, -1), ui::Point(266, 175)),
	currentHue(0),
	currentSaturation(0),
	currentValue(0),
	mouseDown(false),
	valueMouseDown(false),
	callback(callback)
{

	class ColourChange : public ui::TextboxAction
	{
		ColourPickerActivity * a;
	public:
		ColourChange(ColourPickerActivity * a) : a(a) {}

		void TextChangedCallback(ui::Textbox * sender)
		{
			int r, g, b;
			r = format::StringToNumber<int>(a->rValue->GetText());
			g = format::StringToNumber<int>(a->gValue->GetText());
			b = format::StringToNumber<int>(a->bValue->GetText());
			RGB_to_HSV(r, g, b, &a->currentHue, &a->currentSaturation, &a->currentValue);
		}
	};

	rValue = new ui::Textbox(ui::Point(5, Size.Y-23), ui::Point(30, 17), "255");
	rValue->SetActionCallback(new ColourChange(this));
	rValue->SetLimit(3);
	rValue->SetInputType(ui::Textbox::Number);
	AddComponent(rValue);

	gValue = new ui::Textbox(ui::Point(40, Size.Y-23), ui::Point(30, 17), "255");
	gValue->SetActionCallback(new ColourChange(this));
	gValue->SetLimit(3);
	gValue->SetInputType(ui::Textbox::Number);
	AddComponent(gValue);

	bValue = new ui::Textbox(ui::Point(75, Size.Y-23), ui::Point(30, 17), "255");
	bValue->SetActionCallback(new ColourChange(this));
	bValue->SetLimit(3);
	bValue->SetInputType(ui::Textbox::Number);
	AddComponent(bValue);

	class CancelAction: public ui::ButtonAction
	{
		ColourPickerActivity * a;
	public:
		CancelAction(ColourPickerActivity * a) : a(a) { }
		void ActionCallback(ui::Button * sender)
		{
			a->Exit();
		}
	};

	class OkayAction: public ui::ButtonAction
	{
		ColourPickerActivity * a;
	public:
		OkayAction(ColourPickerActivity * a) : a(a) { }
		void ActionCallback(ui::Button * sender)
		{
			int Red, Green, Blue;
			HSV_to_RGB(a->currentHue, a->currentSaturation, a->currentValue, &Red, &Green, &Blue);
			ui::Colour col(Red, Green, Blue);
			if(a->callback)
				a->callback->ColourPicked(col);
			a->Exit();
		}
	};

	ui::Button * doneButton = new ui::Button(ui::Point(Size.X-45, Size.Y-23), ui::Point(40, 17), "Done");
	doneButton->SetActionCallback(new OkayAction(this));
	AddComponent(doneButton);
	SetOkayButton(doneButton);

	ui::Button * cancelButton = new ui::Button(ui::Point(Size.X-90, Size.Y-23), ui::Point(40, 17), "Cancel");
	cancelButton->SetActionCallback(new CancelAction(this));
	AddComponent(cancelButton);
	SetCancelButton(cancelButton);

	rValue->SetText(format::NumberToString<int>(initialColour.Red));
	gValue->SetText(format::NumberToString<int>(initialColour.Green));
	bValue->SetText(format::NumberToString<int>(initialColour.Blue));
	RGB_to_HSV(initialColour.Red, initialColour.Green, initialColour.Blue, &currentHue, &currentSaturation, &currentValue);
}