shithub: picker

Download patch

ref: 3897a967274ce9d36bb9ea10432bb7bec5de8b16
parent: 33a7fcd3976241e3e22a69f24bff13e5999e2aa1
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Mar 12 19:49:00 EDT 2020

no need for min/init

--- a/picker.c
+++ b/picker.c
@@ -25,7 +25,7 @@
 	char opt;
 	void (*torgb)(double *x, double *r, double *g, double *b);
 	void (*fromrgb)(double r, double g, double b, double *x);
-	double min[3], max[3], init[3];
+	double max[3];
 };
 
 static void
@@ -74,9 +74,7 @@
 		.opt = 's',
 		.torgb = _hsluv2rgb,
 		.fromrgb = _rgb2hsluv,
-		.min = {0.0, 0.0, 0.0},
 		.max = {360.0, 100.0, 100.0},
-		.init = {0.0, 100.0, 50.0},
 	},
 	{
 		.name = "HPLuv",
@@ -83,9 +81,7 @@
 		.opt = 'l',
 		.torgb = _hpluv2rgb,
 		.fromrgb = _rgb2hpluv,
-		.min = {0.0, 0.0, 0.0},
 		.max = {360.0, 100.0, 100.0},
-		.init = {0.0, 100.0, 50.0},
 	},
 	{
 		.name = "RGB",
@@ -92,9 +88,7 @@
 		.opt = 'r',
 		.torgb = _rgbto,
 		.fromrgb = _rgbfrom,
-		.min = {0.0, 0.0, 0.0},
 		.max = {1.0, 1.0, 1.0},
-		.init = {0.5, 0.5, 0.5},
 	},
 };
 
@@ -103,12 +97,12 @@
 static Mode *mode;
 
 static Image *
-gradient(double *col_, int w, int e)
+gradient(double *color, int w, int e)
 {
 	Rectangle rect;
 	u8int *data;
 	Image *im;
-	double color[3];
+	double c[3];
 	double r, g, b, x;
 	int i, mi;
 
@@ -116,15 +110,13 @@
 	if ((im = allocimage(display, rect, BGR24, 1, DNofill)) == nil)
 		sysfatal("allocimage: %r");
 
-	color[0] = col_[0];
-	color[1] = col_[1];
-	color[2] = col_[2];
+	memmove(c, color, sizeof(c));
 	data = malloc(3*w);
-	x = (mode->max[e] - mode->min[e]) / w;
-	mi = (color[e] - mode->min[e]) / x;
-	color[e] = mode->min[e];
+	x = mode->max[e] / w;
+	mi = c[e] / x;
+	c[e] = 0.0;
 	for (i = 0; i < w; i++) {
-		mode->torgb(color, &r, &g, &b);
+		mode->torgb(c, &r, &g, &b);
 		data[i*3+0] = r*255.0;
 		data[i*3+1] = g*255.0;
 		data[i*3+2] = b*255.0;
@@ -133,9 +125,9 @@
 			data[i*3+1] = ~data[i*3+1];
 			data[i*3+2] = ~data[i*3+2];
 		}
-		color[e] += x;
-		if (color[e] > mode->max[e])
-			color[e] = mode->max[e];
+		c[e] += x;
+		if (c[e] > mode->max[e])
+			c[e] = mode->max[e];
 	}
 	loadimage(im, rect, data, 3*w);
 	free(data);
@@ -235,7 +227,6 @@
 		break;
 	}ARGEND
 
-	//setfcr(FPRZ|FPPDBL);
 	ncolors = argc;
 	if (ncolors < 1) {
 		fprint(2, "no colors specified\n");
@@ -294,7 +285,7 @@
 				m.xy.x = MAX(screen->r.min.x, MIN(screen->r.max.x, m.xy.x));
 				for (i = 0; i < 3; i++) {
 					if (m.xy.y >= p.y && m.xy.y < p.y+dh) {
-						colors[4*0 + i] = MIN(mode->max[i], MAX(mode->min[i], mode->min[i] + (m.xy.x - screen->r.min.x) * (mode->max[i] - mode->min[i])/Dx(screen->r)));
+						colors[4*0 + i] = MIN(mode->max[i], (m.xy.x - screen->r.min.x) * mode->max[i]/Dx(screen->r));
 						redraw();
 						break;
 					}