Beispiel #1
0
void vtkLookupTable2D::RgbToHsv(unsigned char r, unsigned char g, unsigned char b, double *h, double *s, double *v){
	double dr, dg, db;
	dr = ((double) ((int) r)) / 255.0;
	dg = ((double) ((int) g)) / 255.0;
	db = ((double) ((int) b)) / 255.0;

	RgbToHsv(dr, dg, db, h, s, v);
}
Beispiel #2
0
void vtkLookupTable2D::RgbToHsv(unsigned char r, unsigned char g, unsigned char b, unsigned char *h, unsigned char *s, unsigned char *v){
	double dr, dg, db, dh, ds, dv;
	int ir, ig, ib, ih, is, iv;

	dr = ((double) ((int) r)) / 255.0;
	dg = ((double) ((int) g)) / 255.0;
	db = ((double) ((int) b)) / 255.0;

	RgbToHsv(dr, dg, db, &dh, &ds, &dv);

	ih = (int) (dh * 255.0);
	is = (int) (ds * 255.0);
	iv = (int) (dv * 255.0);

	*h = (unsigned char) ih;
	*s = (unsigned char) is;
	*v = (unsigned char) iv;
}
Beispiel #3
0
COLORREF ChangeColorBrightness(COLORREF color, float modifier) {
  float r = static_cast<float>(GetRValue(color)) / 255.0f;
  float g = static_cast<float>(GetGValue(color)) / 255.0f;
  float b = static_cast<float>(GetBValue(color)) / 255.0f;

  float h, s, v;

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

  v += modifier;
  if (v < 0.0f) v = 0.0f;
  if (v > 1.0f) v = 1.0f;

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

  return RGB(static_cast<BYTE>(r * 255),
             static_cast<BYTE>(g * 255),
             static_cast<BYTE>(b * 255));
}
Beispiel #4
0
/**
 * A smallprogram to read out colorvalues of pixels on the screen.
 * Left-Click: get color values.
 * Right-Click: exit.
 * 
 * @autor: Marcel Schneider; mostly based on Stackoverflow snippets [1] and [2]
 * [1]: http://stackoverflow.com/questions/16122196/getting-mouseclick-coordinates-with-xlib
 * [2]: http://stackoverflow.com/questions/17518610/how-to-get-a-screen-pixels-color-in-x11
 */
int main() {
	int x = -1, y = -1;
	XEvent event;
	int button = 0;
	Display *display = XOpenDisplay(NULL);
	if (display == NULL) {
		fprintf(stderr, "Cannot connect to X server!\n");
		exit(EXIT_FAILURE);
	}
	Window root = XDefaultRootWindow(display);
	XGrabPointer(display, root, False, ButtonReleaseMask, GrabModeAsync,
	GrabModeAsync, None, None, CurrentTime);

	XSelectInput(display, root, ButtonReleaseMask);
	printf("Right-click to exit.\n");
	while (button != Button3) {
		while (1) {
			XNextEvent(display, &event);
			switch (event.type) {
			case ButtonRelease:
				switch (event.xbutton.button) {
				case Button1:
					x = event.xbutton.x;
					y = event.xbutton.y;
					button = Button1;
					break;

				case Button3:
					x = event.xbutton.x;
					y = event.xbutton.y;
					button = Button3;
					break;
				default:
					break;
				}
				break;
			default:
				break;
			}
			if (x >= 0 && y >= 0)
				break;
		}

		XColor c;
		XImage *image;
		image = XGetImage(display, RootWindow(display, DefaultScreen (display)),
				x, y, 1, 1, AllPlanes, XYPixmap);
		c.pixel = XGetPixel(image, 0, 0);
		XFree(image);
		XQueryColor(display, DefaultColormap(display, DefaultScreen (display)),
				&c);
		c.red /= 256;
		c.green /= 256;
		c.blue /= 256;
		RgbColor rgb;
		rgb.r = c.red;
		rgb.g = c.green;
		rgb.b = c.blue;
		HsvColor hsv = RgbToHsv(rgb);
		printf("x,y: %d,%d\n\trgb(%3d,%3d,%3d)\n", x, y, c.red, c.green,
				c.blue);
		printf("\thsv(%3d,%3d,%3d)\n", hsv.h, hsv.s, hsv.v);
	}
	XCloseDisplay(display);
	return 0;
}
Beispiel #5
0
void checkIR(IRMP_DATA *irmp_data) {

	if (irmp_get_data(irmp_data)) {

		if (pwm_status == POWER_OFF && irmp_data->command != 1)
			return;

		if (!(irmp_data->flags & IRMP_FLAG_REPETITION)) {

			switch (irmp_data->command) {

			case (1):
			if (pwm_status == POWER_ON) {
				pwm_disable_all();
				off(DEBUGLED);
			} else {
				pwm_enable_all();
				on(DEBUGLED);
			}
			action = NONE;
			break;

			case (30):
			change_white(1);
			break;

			case (36):
			change_white(-1);
			break;

			case (4):
			change_white(-255);
			break;

			case (14):
			rgb_color.r=0; rgb_color.g=0; rgb_color.b=0;
			hsv_color = RgbToHsv(&rgb_color);
			update_color();
			break;

			case (40):
			change_hue(5.);
			action = NONE;
			break;

			case (41):
			change_hue(-5.);
			action = NONE;
			break;

			case (44):
			change_saturation(0.1);
			action = NONE;
			break;

			case (45):
			change_saturation(-0.1);
			action = NONE;
			break;

			case (9):
			change_value(0.1);
			action = NONE;
			break;

			case (5):
			change_value(-0.1);
			action = NONE;
			break;

			case (7):
			duration += 10;
			break;

			case (8):
			duration -= 10;
			break;

			case (16):
			colors_gen(RED, &rgb_color, &hsv_color);
			update_color();
			action = NONE;
			break;
			case (17):
			colors_gen(GREEN, &rgb_color, &hsv_color);
			update_color();
			action = NONE;
			break;
			case (18):
			colors_gen(BLUE, &rgb_color, &hsv_color);
			update_color();
			action = NONE;
			break;
			case (19):
			colors_gen(CYAN, &rgb_color, &hsv_color);
			update_color();
			action = NONE;
			break;
			case (20):
			colors_gen(MAGENTA, &rgb_color, &hsv_color);
			update_color();
			action = NONE;
			break;
			case (21):
			colors_gen(YELLOW, &rgb_color, &hsv_color);
			update_color();
			action = NONE;
			break;
			case (22):
			colors_gen(WHITE, &rgb_color, &hsv_color);
			update_color();
			action = NONE;
			break;
			case (23):
			colors_gen(BROWN, &rgb_color, &hsv_color);
			update_color();
			action = NONE;
			break;
			case (24):
			colors_gen(RANDOM, &rgb_color, &hsv_color);
			update_color();
			action = NONE;
			break;

			case (15):
			action = (action == HUE_FADE) ? NONE : HUE_FADE;
			break;

			default:
				break;
			}
		} else {
			switch (irmp_data->command) { // if you press the button longer
			case (30):
			change_white(5);
			break;
			case (36):
			change_white(-5);
			break;
			case (40):
			change_hue(0.5);
			break;
			case (41):
			change_hue(-0.5);
			break;
			case (44):
			change_saturation(0.01);
			break;
			case (45):
			change_saturation(-0.01);
			break;
			case (9):
			change_value(0.01);
			break;
			case (5):
			change_value(-0.01);
			break;
			case (7):
			duration += 5;
			break;
			case (8):
			duration -= 5;
			break;
			default:
				break;
			}
		}
	} //end remote switch

	switch (action) {
		case (HUE_FADE):
   			if (duration <= 0)
    				duration = 0;
			if ((millis - last_millis) > duration) {
				change_hue(1.);
				last_millis = millis;
			}
		break;

		default:
		break;
	} // action switch
}