shithub: vshot

Download patch

ref: 7f4168e943ebae1f9d1fc55a701be107830b80f5
parent: 722caafd611b09cb542755fa3f6f01be36acc34f
author: phil9 <telephil9@gmail.com>
date: Mon Feb 5 17:45:48 EST 2024

fix rendering when display is not 32bpp

	code was assuming a 32bpp display which lead to thumbnails
	having weird colors.
	We now convert input image to XRGB32 before creating thumbnails.

--- a/vshot.c
+++ b/vshot.c
@@ -186,30 +186,46 @@
 		w = floor(h*a);
 	}
 	return Rect(0, 0, w, h);
-}		
+}
 
+Memimage*
+winimage(int wid)
+{
+	Memimage *i, *o;
+	char *path;
+	int fd;
+	
+	path = smprint("/dev/wsys/%d/window", wid);
+	fd = open(path, OREAD);
+	if(fd<0)
+		sysfatal("open: %r");
+	free(path);
+	i = readmemimage(fd);
+	if(i==nil)
+		sysfatal("readmemimage: %r");
+	close(fd);
+	if(i->nchan != 4){ /* convert to XRGB32 */
+		o = allocmemimage(i->r, XRGB32);
+		memimagedraw(o, o->r, i, i->r.min, nil, ZP, S);
+		freememimage(i);
+		i = o;
+	}
+	return i;
+}
+
 void
 loadthumbproc(void *arg)
 {
 	Win *w;
-	char *path;
 	Memimage *i;
 	Image *t;
 	u8int *in, *out;
 	Rectangle sr;
 	int iw, ih, ow, oh;
-	int fd, n, err;
+	int n, err;
 
 	w = arg;
-	path = smprint("/dev/wsys/%d/window", w->id);
-	fd = open(path, OREAD);
-	if(fd<0)
-		sysfatal("open: %r");
-	free(path);
-	i = readmemimage(fd);
-	if(i==nil)
-		sysfatal("readmemimage: %r");
-	close(fd);
+	i = winimage(w->id);
 	iw = Dx(i->r);
 	ih = Dy(i->r);
 	sr = scaledrect(i->r);
@@ -230,7 +246,7 @@
 	if(err != 1)
 		sysfatal("resize failed (window %d)", w->id);
 	lockdisplay(display);
-	t = allocimage(display, sr, screen->chan, 0, DNofill);
+	t = allocimage(display, sr, XRGB32, 0, DNofill);
 	if(t==nil)
 		sysfatal("allocimage: %r");
 	if(loadimage(t, sr, out, n) <= 0)