Example #1
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 ColourPickerActivity::OnDraw()
{
	Graphics * g = ui::Engine::Ref().g;
	//g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3);
	g->fillrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3, 0, 0, 0, currentAlpha);
	g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);

	g->drawrect(Position.X+4, Position.Y+4, 258, 130, 180, 180, 180, 255);

	g->drawrect(Position.X+4, Position.Y+4+4+128, 258, 12, 180, 180, 180, 255);


	int offsetX = Position.X+5;
	int offsetY = Position.Y+5;


	//draw color square
	int lastx = -1, currx = 0;
	for(int saturation = 0; saturation <= 255; saturation+=2)
	{
		for(int hue = 0; hue <= 359; hue++)
		{
			currx = clamp_flt(hue, 0, 359)+offsetX;
			if (currx == lastx)
				continue;
			lastx = currx;
			int cr = 0;
			int cg = 0;
			int cb = 0;
			HSV_to_RGB(hue, 255-saturation, currentValue, &cr, &cg, &cb);
			g->blendpixel(currx, (saturation/2)+offsetY, cr, cg, cb, currentAlpha);
		}
	}

	//draw brightness bar
	for(int value = 0; value <= 255; value++)
		for(int i = 0;  i < 10; i++)
		{
			int cr = 0;
			int cg = 0;
			int cb = 0;
			HSV_to_RGB(currentHue, currentSaturation, value, &cr, &cg, &cb);

			g->blendpixel(value+offsetX, i+offsetY+127+5, cr, cg, cb, currentAlpha);
		}

	//draw color square pointer
	int currentHueX = clamp_flt(currentHue, 0, 359);
	int currentSaturationY = ((255-currentSaturation)/2);
	g->xor_line(offsetX+currentHueX, offsetY+currentSaturationY-5, offsetX+currentHueX, offsetY+currentSaturationY-1);
	g->xor_line(offsetX+currentHueX, offsetY+currentSaturationY+1, offsetX+currentHueX, offsetY+currentSaturationY+5);
	g->xor_line(offsetX+currentHueX-5, offsetY+currentSaturationY, offsetX+currentHueX-1, offsetY+currentSaturationY);
	g->xor_line(offsetX+currentHueX+1, offsetY+currentSaturationY, offsetX+currentHueX+5, offsetY+currentSaturationY);

	//draw brightness bar pointer
	int currentValueX = restrict_flt(currentValue, 0, 254);
	g->xor_line(offsetX+currentValueX, offsetY+4+128, offsetX+currentValueX, offsetY+13+128);
	g->xor_line(offsetX+currentValueX+1, offsetY+4+128, offsetX+currentValueX+1, offsetY+13+128);
}
SkColor SkDrawColor::getColor() { 
    if (fDirty) {
        if (SkScalarIsNaN(fValue) == false)
            color = HSV_to_RGB(color, kGetValue, fValue);
        if (SkScalarIsNaN(fSaturation) == false)
            color = HSV_to_RGB(color, kGetSaturation, fSaturation);
        if (SkScalarIsNaN(fHue) == false)
            color = HSV_to_RGB(color, kGetHue, fHue);
        fDirty = false;
    }
    return color; 
}
Example #4
0
PixelBuf GradientMap::GetRegion(
        const MapPixelCoordInt &pos, const MapPixelDeltaInt &size) const
{
    auto fixed_bounds_pb = GetRegion_BoundsHelper(*this, pos, size);
    if (fixed_bounds_pb.GetData())
        return fixed_bounds_pb;

    //time_counter_loaddisc.Start();
    MapPixelCoordInt req_pos = pos - MapPixelDeltaInt(1, 1);
    MapPixelDeltaInt req_size = size + MapPixelDeltaInt(2, 2);
    auto orig_data = m_orig_map->GetRegion(req_pos, req_size);
    //auto orig_data = LoadBufferFromBMP(L"example.bmp");
    PixelBuf result(size.x, size.y);

    unsigned int *src = orig_data.GetRawData();
    unsigned int *dest = result.GetRawData();
    //time_counter_loaddisc.Stop();
    //time_counter.Start();
    for (int x=0; x < size.x; x++) {
        for (int y=0; y < size.y; y++) {
            unsigned int elevation = SRC(x+1, y+1);
            MapPixelCoordInt pos(x+1, y+1);
            MapBezierGradient grad = Fast3x3CenterGradient(src, pos, req_size);

            DEST(x, y) = HSV_to_RGB(
                      255*240/360 - elevation*255/4000,
                      255,
                      ValueBetween(0,
                                   static_cast<int>(128+1.25*(grad.x-grad.y)),
                                   255));
        }
    }
    //time_counter.Stop();
    return result;
}
Example #5
0
void MpColor::SetHSVA (int h, int s, int v, int alpha)
{
  float H(h/64), S(s/65535.0), V(v/65535.0), R,G,B;
  HSV_to_RGB (H,S,V, R,G,B);
  SetRGBA( uint32_t(R*65535),uint32_t(G*65535),uint32_t(B*65535),alpha);
  // color is un-allocated now
}
Example #6
0
void MpColor::SetHSVA (float h, float s, float v, float alpha)
{
  float R,G,B;
  HSV_to_RGB (h,s,v, R,G,B);
  SetRGBA(R,G,B,alpha);
  // color is un-allocated now
}
Example #7
0
Color Color::toRGB(bool internal_check) const {
	float R, G, B;
	float X, Y, Z;
	switch (space) {
		case RGB:
			return *this;
		case CMY:
			CMY_to_RGB(a, b, c, R, G, B);
			break;
		case HLS:
			HLS_to_RGB(a, b, c, R, G, B);
			break;
		case HSV:
			HSV_to_RGB(a, b, c, R, G, B);
			break;
		case CIEXYZ: //convert to RGB709
			XYZ_to_RGB709(a, b, c, R, G, B);
			break;
		case CIExyY:
			xyY_to_XYZ(a, b, c, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_RGB709(X, Y, Z, R, G, B);
			break;	
		case CIELuv:
			Luv_to_XYZ(a, b, c, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_RGB709(X, Y, Z, R, G, B);
			break;	
		default:
			return Color(0.0, 0.0, 0.0, INVALID);
	}
	RGB_check(R, G, B);
	return Color(R, G, B, RGB);
}
Example #8
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);
}
void ColourPickerActivity::OnDraw()
{
	Graphics * g = ui::Engine::Ref().g;
	g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3);
	g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);

	g->drawrect(Position.X+4, Position.Y+4, 258, 130, 180, 180, 180, 255);

	g->drawrect(Position.X+4, Position.Y+4+4+128, 258, 12, 180, 180, 180, 255);


	int offsetX = Position.X+5;
	int offsetY = Position.Y+5;


	for(int saturation = 0; saturation <= 255; saturation+=2)
		for(int hue = 0; hue <= 359; hue++)
		{
			int cr = 0;
			int cg = 0;
			int cb = 0;
			HSV_to_RGB(hue, 255-saturation, 255-saturation, &cr, &cg, &cb);

			g->blendpixel(clamp_flt(hue, 0, 359)+offsetX, (saturation/2)+offsetY, cr, cg, cb, 255);
		}

	//draw brightness bar
	for(int value = 0; value <= 255; value++)
		for(int i = 0;  i < 10; i++)
		{
			int cr = 0;
			int cg = 0;
			int cb = 0;
			HSV_to_RGB(currentHue, currentSaturation, value, &cr, &cg, &cb);

			g->blendpixel(value+offsetX, i+offsetY+127+5, cr, cg, cb, 255);
		}

	int currentHueX = clamp_flt(currentHue, 0, 359);
	int currentSaturationY = ((255-currentSaturation)/2);
	g->xor_line(offsetX+currentHueX, offsetY+currentSaturationY-5, offsetX+currentHueX, offsetY+currentSaturationY+5);
	g->xor_line(offsetX+currentHueX-5, offsetY+currentSaturationY, offsetX+currentHueX+5, offsetY+currentSaturationY);

	g->xor_line(offsetX+currentValue, offsetY+4+128, offsetX+currentValue, offsetY+13+128);
	g->xor_line(offsetX+currentValue+1, offsetY+4+128, offsetX+currentValue+1, offsetY+13+128);
}
Example #10
0
 RGB genColor()
 {
   static double golden_ratio = 0.618033988749895;
   srand(time(NULL));
   static int h = rand();
   h += golden_ratio;
   h = h%1;
   return HSV_to_RGB(h,0.5,0.95);    
 }
		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();
		}
Example #12
0
//#TPT-Directive ElementHeader Element_TRON static void init_graphics()
void Element_TRON::init_graphics()
{
	int i;
	int r, g, b;
	for (i=0; i<32; i++)
	{
		HSV_to_RGB(i<<4,255,255,&r,&g,&b);
		tron_colours[i] = r<<16 | g<<8 | b;
	}
}
Example #13
0
Color Color::toCIExyY(bool internal_check) const {
	float x, y;
	float R, G, B;
	float X, Y, Z;
	switch (space) {
		case CIExyY:
			return *this;
		case CIEXYZ:
			XYZ_to_xyY(a, b, c, x, y, Y);
			break;
		case CIELuv:
			Luv_to_XYZ(a, b, c, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_xyY(X, Y, Z, x, y, Y);
			break;
		case RGB:
			RGB709_to_XYZ(a, b, c, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_xyY(X, Y, Z, x, y, Y);
			break;
		case CMY:
			CMY_to_RGB(a, b, c, R, G, B);
			if (internal_check) RGB_check(R, G, B);
			RGB709_to_XYZ(R, G, B, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_xyY(X, Y, Z, x, y, Y);
			break;
		case HLS:
			HLS_to_RGB(a, b, c, R, G, B);
			if (internal_check) RGB_check(R, G, B);
			RGB709_to_XYZ(R, G, B, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_xyY(X, Y, Z, x, y, Y);
			break;
		case HSV:
			HSV_to_RGB(a, b, c, R, G, B);
			if (internal_check) RGB_check(R, G, B);
			RGB709_to_XYZ(R, G, B, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_xyY(X, Y, Z, x, y, Y);
			break;
		default:
			return Color(0.0, 0.0, 0.0, INVALID);
	}
	xyY_check(x, y, Y);
	return Color(x, y, Y, CIExyY);
}
Example #14
0
Color Color::toCIELuv(bool internal_check) const {
	float L, u, v;
	float X, Y, Z;
	float R, G, B;
	switch (space) {
		case CIELuv:
			return *this;
		case CIExyY:
			xyY_to_XYZ(a, b, c, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_Luv(X, Y, Z, L, u, v);
			break;
		case CIEXYZ:
			XYZ_to_Luv(a, b, c, L, u, v);
			break;
		case RGB:
			RGB709_to_XYZ(a, b, c, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_Luv(X, Y, Z, L, u, v);
		case CMY:
			CMY_to_RGB(a, b, c, R, G, B);
			if (internal_check) RGB_check(R, G, B);
			RGB709_to_XYZ(R, G, B, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_Luv(X, Y, Z, L, u, v);
			break;
		case HLS:
			HLS_to_RGB(a, b, c, R, G, B);
			if (internal_check) RGB_check(R, G, B);
			RGB709_to_XYZ(R, G, B, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_Luv(X, Y, Z, L, u, v);
			break;
		case HSV:
			HSV_to_RGB(a, b, c, R, G, B);
			if (internal_check) RGB_check(R, G, B);
			RGB709_to_XYZ(R, G, B, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_Luv(X, Y, Z, L, u, v);
			break;
		default:
			return Color(0.0, 0.0, 0.0, INVALID);
	}
	Luv_check(L, u, v);
	return Color(L, u, v, CIELuv);
}
void ColourPickerActivity::OnMouseUp(int x, int y, unsigned button)
{
	if(mouseDown || valueMouseDown)
	{
		int cr, cg, cb;
		HSV_to_RGB(currentHue, currentSaturation, currentValue, &cr, &cg, &cb);
		rValue->SetText(format::NumberToString<int>(cr));
		gValue->SetText(format::NumberToString<int>(cg));
		bValue->SetText(format::NumberToString<int>(cb));
	}

	if(mouseDown)
	{
		mouseDown = false;
		x -= Position.X+5;
		y -= Position.Y+5;

		currentHue = (float(x)/float(255))*359.0f;
		currentSaturation = 255-(y*2);

		if(currentSaturation > 255)
			currentSaturation = 255;
		if(currentSaturation < 0)
			currentSaturation = 0;
		if(currentHue > 359)
			currentHue = 359;
		if(currentHue < 0)
			currentHue = 0;
	}

	if(valueMouseDown)
	{
		valueMouseDown = false;

		x -= Position.X+5;
		y -= Position.Y+5;

		currentValue = x;

		if(currentValue > 255)
			currentValue = 255;
		if(currentValue < 0)
			currentValue = 0;
	}
}
void ColourPickerActivity::OnMouseUp(int x, int y, unsigned button)
{
	if(mouseDown || valueMouseDown)
	{
		int cr, cg, cb;
		HSV_to_RGB(currentHue, currentSaturation, currentValue, &cr, &cg, &cb);
		UpdateTextboxes(cr, cg, cb, currentAlpha);
	}

	if(mouseDown)
	{
		mouseDown = false;
		x -= Position.X+5;
		y -= Position.Y+5;

		currentHue = (float(x)/float(255))*359.0f;
		currentSaturation = 255-(y*2);

		if(currentSaturation > 255)
			currentSaturation = 255;
		if(currentSaturation < 0)
			currentSaturation = 0;
		if(currentHue > 359)
			currentHue = 359;
		if(currentHue < 0)
			currentHue = 0;
	}

	if(valueMouseDown)
	{
		valueMouseDown = false;

		x -= Position.X+5;
		y -= Position.Y+5;

		currentValue = x;

		if(currentValue > 255)
			currentValue = 255;
		if(currentValue < 0)
			currentValue = 0;
	}
}
Example #17
0
Color Color::toHLS(bool internal_check) const {
	float H, L, S;
	float R, G, B;
	float X, Y, Z;
	switch (space) {
		case HLS:
			return *this;
		case CIELuv:
			H = atan2f(c, b);
			L = a;
			S = sqrtf(b+c);
			break;
		case CIExyY:
			xyY_to_XYZ(a, b, c, X, Y, Z);
			if (internal_check) XYZ_check(X, Y, Z);
			XYZ_to_RGB709(X, Y, Z, R, G, B);
			if (internal_check) RGB_check(R, G, B);
			RGB_to_HLS(R, G, B, H, L, S);
			break;
		case CIEXYZ:
			XYZ_to_RGB709(a, b, c, R, G, B);
			if (internal_check) RGB_check(R, G, B);
			RGB_to_HLS(R, G, B, H, L, S);
			break;
		case RGB:
			RGB_to_HLS(a, b, c, H, L, S);
			break;
		case CMY:
			CMY_to_RGB(a, b, c, R, G, B);
			if (internal_check) RGB_check(R, G, B);
			RGB_to_HLS(R, G, B, H, L, S);
			break;
		case HSV:
			HSV_to_RGB(a, b, c, R, G, B);
			if (internal_check) RGB_check(R, G, B);
			RGB_to_HLS(R, G, B, H, L, S);
			break;
		default:
			return Color(0.0, 0.0, 0.0, INVALID);
	}
	HLS_check(H, L, S);
	return Color(H, L, S, HLS);
}
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 #19
0
void setup()
{
    ebox_init();
    PB8.mode(OUTPUT_PP);
    lcd.begin(1);
    lcd.clear(RED);
    uart1.begin(9600);
    
    lcd.column_order(1);
    lcd.row_order(1);

    lcd.front_color = RED;
    lcd.back_color = BLACK;
    hsv.s = 1;
    hsv.v = 0.5;
    hsv.h = 0;

    lcd.front_color = RED;
    if(index >= 0x50)index = 0x20;
    for(int i = 0; i < 160; i++){
        hsv.h = i*36/16;
        hsv.h %= 360;
        HSV_to_RGB(hsv,rgb);
        rgb_to_565(rgb,_color[i]);
       lcd.front_color = _color[i];
       lcd.draw_h_line(0,i,128);
    }
    lcd.disp_char8x16(0,0,index++);
    
    lcd.printf(2,2,"1231asddfgdsfgthkfhddddj2nhd");
    

    lcd.front_color = GREEN;
    lcd.draw_circle(50,50,50);
    lcd.draw_line(64,50,r,100);
    

}
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 #21
0
// _FillBitmap
void
ColorField::_FillBitmap(BBitmap* bitmap, SelectedColorMode mode,
	float fixedValue, orientation orient) const
{
	int32 width = bitmap->Bounds().IntegerWidth();
	int32 height = bitmap->Bounds().IntegerHeight();
	uint32 bpr = bitmap->BytesPerRow();

//bigtime_t now = system_time();
	uint8* bits = (uint8*)bitmap->Bits();

	float r = 0;
	float g = 0;
	float b = 0;
	float h;
	float s;
	float v;

	switch (mode) {
		case R_SELECTED:
			r = round(fixedValue * 255);
			for (int y = height; y >= 0; y--) {
				uint8* bitsHandle = bits;
				b = y * 255 / height;
				for (int32 x = 0; x <= width; x++) {
					g = x * 255 / width;
					set_bits(bitsHandle, (uint8)r, (uint8)g, (uint8)b);
					bitsHandle += 4;
				}
				bits += bpr;
			}
			break;

		case G_SELECTED:
			g = round(fixedValue * 255);
			for (int y = height; y >= 0; y--) {
				uint8* bitsHandle = bits;
				b = y * 255 / height;
				for (int x = 0; x <= width; x++) {
					r = x * 255 / width;
					set_bits(bitsHandle, (uint8)r, (uint8)g, (uint8)b);
					bitsHandle += 4;
				}
				bits += bpr;
			}
			break;

		case B_SELECTED:
			b = round(fixedValue * 255);
			for (int y = height; y >= 0; y--) {
				uint8* bitsHandle = bits;
				g = y * 255 / height;
				for (int x = 0; x <= width; ++x) {
					r = x * 255 / width;
					set_bits(bitsHandle, (uint8)r, (uint8)g, (uint8)b);
					bitsHandle += 4;
				}
				bits += bpr;
			}
			break;

		case H_SELECTED:
			h = fixedValue;
			if (orient == B_VERTICAL) {
				for (int y = 0; y <= height; ++y) {
					v = (float)(height - y) / height;
					uint8* bitsHandle = bits;
					for (int x = 0; x <= width; ++x) {
						s = (float)x / width;
						HSV_to_RGB(h, s, v, r, g, b);
						set_bits(bitsHandle,
							round(r * 255.0),
							round(g * 255.0),
							round(b * 255.0));
						bitsHandle += 4;
					}
					bits += bpr;
				}
			} else {
				for (int y = 0; y <= height; ++y) {
					s = (float)y / height;
					uint8* bitsHandle = bits;
					for (int x = 0; x <= width; ++x) {
						v = (float)(width - x) / width;
						HSV_to_RGB(h, s, v, r, g, b);
						set_bits(bitsHandle,
							round(r * 255.0),
							round(g * 255.0),
							round(b * 255.0));
						bitsHandle += 4;
					}
					bits += bpr;
				}
			}
			break;

		case S_SELECTED:
			s = fixedValue;
			for (int y = 0; y <= height; ++y) {
				v = (float)(height - y) / height;
				uint8* bitsHandle = bits;
				for (int x = 0; x <= width; ++x) {
					h = 6.0 / width * x;
					HSV_to_RGB(h, s, v, r, g, b);
					set_bits(bitsHandle,
						round(r * 255.0),
						round(g * 255.0),
						round(b * 255.0));
					bitsHandle += 4;
				}
				bits += bpr;
			}
			break;

		case V_SELECTED:
			v = fixedValue;
			for (int y = 0; y <= height; ++y) {
				s = (float)(height - y) / height;
				uint8* bitsHandle = bits;
				for (int x = 0; x <= width; ++x) {
					h = 6.0 / width * x;
					HSV_to_RGB(h, s, v, r, g, b);
					set_bits(bitsHandle,
						round(r * 255.0),
						round(g * 255.0),
						round(b * 255.0));
					bitsHandle += 4;
				}
				bits += bpr;
			}
			break;
	}
}
Example #22
0
int32
ColorField::_UpdateThread(void *data)
{
	// initialization

	ColorField *colorField = (ColorField *)data;
	BLooper *looper = colorField->Looper();

	if (looper)
		looper->Lock();

	BBitmap* bitmap = colorField->fBgBitmap[0];
	BView* view = colorField->fBgView[0];

	port_id port = colorField->fUpdatePort;

	if (looper)
		looper->Unlock();

	// draw

	float h, s, v, r, g, b;
	int R, G, B;

	int32 msg_code;
	char msg_buffer;

	while (true) {
		port_info info;
		do {
			read_port(port, &msg_code, &msg_buffer, sizeof(msg_buffer));
			get_port_info(port, &info);
		} while (info.queue_count);

		if (looper)
			looper->Lock();
	
		uint colormode = colorField->fColorMode;
		float fixedvalue = colorField->fFixedValue;

		if (looper)
			looper->Unlock();

		bitmap->Lock();
		view->BeginLineArray(256 * 256);

		switch (colormode)
		{
			case R_SELECTED:
			{
				R = round(fixedvalue * 255);
				for (int G = 0; G < 256; ++G)
					for (int B = 0; B < 256; ++B)
						DrawColorPoint(BPoint(G, 255.0 - B), R, G, B);
				break;
			}

			case G_SELECTED:
			{
				G = round(fixedvalue * 255);
				for (int R = 0; R < 256; ++R)
					for (int B = 0; B < 256; ++B)
						DrawColorPoint(BPoint(R, 255.0 - B), R, G, B);
				break;
			}

			case B_SELECTED:
			{
				B = round(fixedvalue * 255);
				for (int R = 0; R < 256; ++R)
					for (int G = 0; G < 256; ++G)
						DrawColorPoint(BPoint(R, 255.0 - G), R, G, B);
				break;
			}

			case H_SELECTED:
			{
				h = fixedvalue;
				for (int x = 0; x < 256; ++x) {
					s = (float)x / 255.0;
					for (int y = 0; y < 256; ++y) {
						v = (float)y / 255.0;
						HSV_to_RGB(h, s, v, r, g, b);
						DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0),
							round(g * 255.0), round(b * 255.0));
					}
				}
				break;
			}

			case S_SELECTED:
			{
				s = fixedvalue;
				for (int x = 0; x < 256; ++x) {
					h = 6.0 / 255 * x;
					for (int y = 0; y<256; ++y) {
						v = (float)y / 255.0;
						HSV_to_RGB(h, s, v, r, g, b);
						DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0),
							round(g * 255.0), round(b * 255.0));
					}
				}
				break;
			}

			case V_SELECTED:
			{
				v = fixedvalue;
				for (int x = 0; x < 256; ++x) {
					h = 6.0 / 255 * x;
					for (int y = 0; y < 256; ++y) {
						s = (float)y / 255.0;
						HSV_to_RGB(h, s, v, r, g, b);
						DrawColorPoint(BPoint(x, 255.0 - y), round(r * 255.0),
							round(g * 255.0), round(b * 255.0));
					}
				}
				break;
			}
		}

		view->EndLineArray();
		view->Sync();

		bitmap->Unlock();

		looper = colorField->Looper();
		if (looper && looper->Lock()) {
			colorField->Update(2);
			looper->Unlock();
		}
	}

	return 0;
}
Example #23
0
void
ColorField::SetModeAndValue(color_mode mode, float fixed_value)
{
	float R(0);
	float G(0);
	float B(0);
	float H(0);
	float S(0);
	float V(0);

	fBgBitmap[0]->Lock();

	switch (fColorMode) {
		case R_SELECTED:
			R = fFixedValue * 255;
			G = round(fMarkerPosition.x);
			B = round(255.0 - fMarkerPosition.y);
			break;

		case G_SELECTED:
			R = round(fMarkerPosition.x);
			G = fFixedValue * 255;
			B = round(255.0 - fMarkerPosition.y);
			break;

		case B_SELECTED:
			R = round(fMarkerPosition.x);
			G = round(255.0 - fMarkerPosition.y);
			B = fFixedValue * 255;
			break;

		case H_SELECTED:
			H = fFixedValue;
			S = fMarkerPosition.x / 255.0;
			V = 1.0 - fMarkerPosition.y / 255.0;
			break;

		case S_SELECTED:
			H = fMarkerPosition.x / 255.0 * 6.0;
			S = fFixedValue;
			V = 1.0 - fMarkerPosition.y / 255.0;
			break;

		case V_SELECTED:
			H = fMarkerPosition.x / 255.0 * 6.0;
			S = 1.0 - fMarkerPosition.y / 255.0;
			V = fFixedValue;
			break;
	}

	if (fColorMode & (H_SELECTED | S_SELECTED | V_SELECTED)) {
		HSV_to_RGB(H, S, V, R, G, B);
		R *= 255.0;
		G *= 255.0;
		B *= 255.0;
	}

	rgb_color color = { round(R), round(G), round(B), 255 };

	fBgBitmap[0]->Unlock();

	fFixedValue = fixed_value;
	fColorMode = mode;

	Update(3);

	SetMarkerToColor(color);
}
Example #24
0
void ColorPicker::UpdateCanvas(int c, int fixedColor)
{
	//Draw
	KrRGBA *pixels = canvas->getCanvasResource()->Pixels(), color;
		
	int i, width = canvas->Width();

	if(fixedColor <= FIX_BLUE)
	{
		//RGB

		for(i = 0; i < 256; i++)
		{
			for(int j = 0; j < 256; j++)
			{
				switch(fixedColor)
				{
				case FIX_RED:
					color.Set(c, 255 - j, i, 255);
					break;
					
				case FIX_GREEN:
					color.Set(255 - j, c,  i, 255);
					break;
					
				case FIX_BLUE:
					color.Set(i, 255 - j, c, 255);
					break;
				}
				
				pixels[ j*width + i ] = color;			
			}
		}
	}
	else
	{
		//HSV
		double H, S, V;
		
		for(i = 0; i < 256; i++)
		{
			for(int j = 0; j < 256; j++)
			{
				switch(fixedColor)
				{
				case FIX_HUE:
					H = c;
					S = i;
					V = 255 - j;					
					break;
					
				case FIX_SATURATION:
					H = i;
					S = c;
					V = 255 - j;					
					break;
					
				case FIX_BRIGHTNESS:
					H = i;
					S = 255 - j;
					V = c;					
					break;
				}

				color = HSV_to_RGB(H, S, V, false);								
				pixels[ j*width + i ] = color;			
			}
		}
	}

	canvas->getImage()->Invalidate();
	canvas->getCanvasResource()->Refresh();
}
Example #25
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 #26
0
// SetModeAndValue
void
ColorField::SetModeAndValue(selected_color_mode mode, float fixed_value)
{
	float R(0), G(0), B(0);
	float H(0), S(0), V(0);
	
	fBgBitmap[0]->Lock();

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

	switch (fMode) {
		
		case R_SELECTED: {
			R = fFixedValue * 255;
			G = round(fMarkerPosition.x / width * 255.0);
			B = round(255.0 - fMarkerPosition.y / height * 255.0);
		}; break;
		
		case G_SELECTED: {
			R = round(fMarkerPosition.x / width * 255.0);
			G = fFixedValue * 255;
			B = round(255.0 - fMarkerPosition.y / height * 255.0);
		}; break;

		case B_SELECTED: {
			R = round(fMarkerPosition.x / width * 255.0);
			G = round(255.0 - fMarkerPosition.y / height * 255.0);
			B = fFixedValue * 255;
		}; break;

		case H_SELECTED: {
			H = fFixedValue;
			S = fMarkerPosition.x / width;
			V = 1.0 - fMarkerPosition.y / height;
		}; break;

		case S_SELECTED: {
			H = fMarkerPosition.x / width * 6.0;
			S = fFixedValue;
			V = 1.0 - fMarkerPosition.y / height;
		}; break;

		case V_SELECTED: {
			H = fMarkerPosition.x / width * 6.0;
			S = 1.0 - fMarkerPosition.y / height;
			V = fFixedValue;
		}; break;
	}

	if (fMode & (H_SELECTED | S_SELECTED | V_SELECTED)) {
		HSV_to_RGB(H, S, V, R, G, B);
		R *= 255.0; G *= 255.0; B *= 255.0;
	}
	
	rgb_color color = { round(R), round(G), round(B), 255 };

	fBgBitmap[0]->Unlock();

	if (fFixedValue != fixed_value || fMode != mode) {
		fFixedValue = fixed_value;
		fMode = mode;
	
		Update(3);
	}

	SetMarkerToColor(color);
}
Example #27
0
osg::Vec4 rainbowColorMap(float hue) {
    return HSV_to_RGB(osg::Vec4(hue, 1.0f, 1.0f,1.0));
}
// SetModeAndValues
void
ColorSlider::SetModeAndValues(selected_color_mode mode,
							  float value1, float value2)
{
	float R(0), G(0), B(0);
	float h(0), s(0), v(0);
	
	fBgBitmap->Lock();
	
	switch (fMode) {
		
		case R_SELECTED: {
			R = 255 - Value();
			G = round(fFixedValue1 * 255.0);
			B = round(fFixedValue2 * 255.0);
		}; break;
		
		case G_SELECTED: {
			R = round(fFixedValue1 * 255.0);
			G = 255 - Value();
			B = round(fFixedValue2 * 255.0);
		}; break;
		
		case B_SELECTED: {
			R = round(fFixedValue1 * 255.0);
			G = round(fFixedValue2 * 255.0);
			B = 255 - Value();
		}; break;
		
		case H_SELECTED: {
			h = (1.0 - (float)Value()/255.0)*6.0;
			s = fFixedValue1;
			v = fFixedValue2;
		}; break;
		
		case S_SELECTED: {
			h = fFixedValue1;
			s = 1.0 - (float)Value()/255.0;
			v = fFixedValue2;
		}; break;
		
		case V_SELECTED: {
			h = fFixedValue1;
			s = fFixedValue2;
			v = 1.0 - (float)Value()/255.0;
		}; break;
	}

	if (fMode & (H_SELECTED|S_SELECTED|V_SELECTED) ) {
		HSV_to_RGB(h, s, v, R, G, B);
		R*=255.0; G*=255.0; B*=255.0;
	}
	
	rgb_color color = { round(R), round(G), round(B), 255 };
	
	fMode = mode;
	SetOtherValues(value1, value2);
	fBgBitmap->Unlock();

	SetMarkerToColor( color );
	Update(2);
}
// _UpdateThread
status_t
ColorSlider::_UpdateThread(void* data)
{
	// initializing
	ColorSlider* colorSlider = (ColorSlider*)data;
	
	bool looperLocked = colorSlider->LockLooper();

	port_id	port = colorSlider->fUpdatePort;
	orientation orient = colorSlider->fOrientation;

	if (looperLocked)
		colorSlider->UnlockLooper();
	
	float h, s, v, r, g, b;
	int R, G, B;
		
	// drawing

    int32 msg_code;
    char msg_buffer;

	while (true) {

		port_info info;

		do {

			read_port(port, &msg_code, &msg_buffer, sizeof(msg_buffer));
			get_port_info(port, &info);
			
		} while (info.queue_count);
		
		if (colorSlider->LockLooper()) {
	
			uint 	colormode = colorSlider->fMode;
			float	fixedvalue1 = colorSlider->fFixedValue1;
			float	fixedvalue2 = colorSlider->fFixedValue2;
		    
			BBitmap* bitmap = colorSlider->fBgBitmap;
			BView* view = colorSlider->fBgView;

			bitmap->Lock();

			colorSlider->UnlockLooper();	
	
			view->BeginLineArray(256);
			
			switch (colormode) {
				
				case R_SELECTED: {
					G = round(fixedvalue1 * 255);
					B = round(fixedvalue2 * 255);
					for (int R = 0; R < 256; ++R) {
						_DrawColorLineY( view, R, R, G, B );
					}
				}; break;
				
				case G_SELECTED: {
					R = round(fixedvalue1 * 255);
					B = round(fixedvalue2 * 255);
					for (int G = 0; G < 256; ++G) {
						_DrawColorLineY( view, G, R, G, B );
					}
				}; break;
				
				case B_SELECTED: {
					R = round(fixedvalue1 * 255);
					G = round(fixedvalue2 * 255);
					for (int B = 0; B < 256; ++B) {
						_DrawColorLineY( view, B, R, G, B );
					}
				}; break;
				
				case H_SELECTED: {
					s = 1.0;//fixedvalue1;
					v = 1.0;//fixedvalue2;
					if (orient == B_VERTICAL) {
						for (int y = 0; y < 256; ++y) {
							HSV_to_RGB( (float)y*6.0/255.0, s, v, r, g, b );
							_DrawColorLineY( view, y, r*255, g*255, b*255 );
						}
					} else {
						for (int x = 0; x < 256; ++x) {
							HSV_to_RGB( (float)x*6.0/255.0, s, v, r, g, b );
							_DrawColorLineX( view, x, r*255, g*255, b*255 );
						}
					}
				}; break;
				
				case S_SELECTED: {
					h = fixedvalue1;
					v = 1.0;//fixedvalue2;
					for (int y = 0; y < 256; ++y) {
						HSV_to_RGB( h, (float)y/255, v, r, g, b );
						_DrawColorLineY( view, y, r*255, g*255, b*255 );
					}
				}; break;
				
				case V_SELECTED: {
					h = fixedvalue1;
					s = 1.0;//fixedvalue2;
					for (int y = 0; y < 256; ++y) {
						HSV_to_RGB( h, s, (float)y/255, r, g, b );
						_DrawColorLineY( view, y, r*255, g*255, b*255 );
					}
				}; break;
			}
		
			view->EndLineArray();
			view->Sync();
			bitmap->Unlock();

			if (colorSlider->LockLooper()) {
				colorSlider->Update(1);
				colorSlider->UnlockLooper();
			}
		}
	}
	return B_OK;
}
Example #30
0
// _UpdateThread
int32
ColorField::_UpdateThread(void* data)
{
	// initializing
	ColorField* colorField = (ColorField *)data;
	
	bool looperLocked = colorField->LockLooper();

	BBitmap* bitmap = colorField->fBgBitmap[0];
	port_id	port = colorField->fUpdatePort;
	orientation orient = colorField->fOrientation;

	if (looperLocked)
		colorField->UnlockLooper();
	
	float h, s, v, r, g, b;
	int R, G, B;
		
	// drawing

    int32 msg_code;
    char msg_buffer;

	while (true) {

		port_info info;

		do {

			read_port(port, &msg_code, &msg_buffer, sizeof(msg_buffer));
			get_port_info(port, &info);
			
		} while (info.queue_count);
		
		if (colorField->LockLooper()) {
		
			uint 	colormode = colorField->fMode;
			float	fixedvalue = colorField->fFixedValue;
		
			int width = (int)colorField->Width();
			int height = (int)colorField->Height();
		     
			colorField->UnlockLooper();
		
			bitmap->Lock();
	//bigtime_t now = system_time();
			uint8* bits = (uint8*)bitmap->Bits();
			uint32 bpr = bitmap->BytesPerRow();
			// offset 2 pixels from top and left
			bits += 2 * 4 + 2 * bpr;
			
			switch (colormode) {
				
				case R_SELECTED: {
					R = round(fixedvalue * 255);
					for (int y = height; y >= 0; y--) {
						uint8* bitsHandle = bits;
						int B = y / height * 255;
						for (int x = 0; x <= width; ++x) {
							int G = x / width * 255;
							set_bits(bitsHandle, R, G, B);
							bitsHandle += 4;
						}
						bits += bpr;
					}
				}; break;
				
				case G_SELECTED: {
					G = round(fixedvalue * 255);
					for (int y = height; y >= 0; y--) {
						uint8* bitsHandle = bits;
						int B = y / height * 255;
						for (int x = 0; x <= width; ++x) {
							int R = x / width * 255;
							set_bits(bitsHandle, R, G, B);
							bitsHandle += 4;
						}
						bits += bpr;
					}
				}; break;
				
				case B_SELECTED: {
					B = round(fixedvalue * 255);
					for (int y = height; y >= 0; y--) {
						uint8* bitsHandle = bits;
						int G = y / height * 255;
						for (int x = 0; x <= width; ++x) {
							int R = x / width * 255;
							set_bits(bitsHandle, R, G, B);
							bitsHandle += 4;
						}
						bits += bpr;
					}
				}; break;
				
				case H_SELECTED: {
					h = fixedvalue;
					if (orient == B_VERTICAL) {
						for (int y = 0; y <= height; ++y) {
							v = (float)(height - y) / height;
							uint8* bitsHandle = bits;
							for (int x = 0; x <= width; ++x) {
								s = (float)x / width;
								HSV_to_RGB( h, s, v, r, g, b );
								set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0));
								bitsHandle += 4;
							}
							bits += bpr;
						}
					} else {
						for (int y = 0; y <= height; ++y) {
							s = (float)y / height;
							uint8* bitsHandle = bits;
							for (int x = 0; x <= width; ++x) {
								v = (float)(width - x) / width;
								HSV_to_RGB( h, s, v, r, g, b );
								set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0));
								bitsHandle += 4;
							}
							bits += bpr;
						}
					}
				}; break;
				
				case S_SELECTED: {
					s = fixedvalue;
					for (int y = 0; y <= height; ++y) {
						v = (float)(height - y) / height;
						uint8* bitsHandle = bits;
						for (int x = 0; x <= width; ++x) {
							h = 6.0 / width * x;
							HSV_to_RGB( h, s, v, r, g, b );
							set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0));
							bitsHandle += 4;
						}
						bits += bpr;
					}
				}; break;
				
				case V_SELECTED: {
					v = fixedvalue;
					for (int y = 0; y <= height; ++y) {
						s = (float)(height - y) / height;
						uint8* bitsHandle = bits;
						for (int x = 0; x <= width; ++x) {
							h = 6.0 / width * x;
							HSV_to_RGB( h, s, v, r, g, b );
							set_bits(bitsHandle, round(r * 255.0), round(g * 255.0), round(b * 255.0));
							bitsHandle += 4;
						}
						bits += bpr;
					}
				}; break;
			}
	
	//printf("color field update: %lld\n", system_time() - now);
			bitmap->Unlock();
	
			if (colorField->LockLooper()) {
				colorField->Update(2);
				colorField->UnlockLooper();
			}
		}
	}
}