shithub: zuke

Download patch

ref: 77777700c0f4bfcd97bfa212ff5588c5cb14d101
parent: 274a7f635969b31e7259dc841092067c7e0f42de
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Dec 6 11:46:51 EST 2019

cover image: support png and use resample(1) for better quality

--- a/zuke.c
+++ b/zuke.c
@@ -232,7 +232,7 @@
 coverload(void *player_)
 {
 	int p[2], pid, fd;
-	char *prog, *path, *s;
+	char *prog, *path, *s, tmp[32];
 	Meta *m;
 	Channel *ch;
 	Player *player;
@@ -244,30 +244,35 @@
 	pid = -1;
 	ch = player->img;
 	fd = -1;
+	prog = nil;
 
-	if(m->imagefmt == nil || m->imagereader != 0)
-		goto done;
-	if(strcmp(m->imagefmt, "image/png") == 0)
-		prog = "png -9t | resize -x128";
-	else if(strcmp(m->imagefmt, "image/jpeg") == 0)
-		prog = "jpg -9t | resize -x128";
-	else{
+	if(m->imagefmt != nil && m->imagereader == 0){
+		if(strcmp(m->imagefmt, "image/png") == 0)
+			prog = "png";
+		else if(strcmp(m->imagefmt, "image/jpeg") == 0)
+			prog = "jpg";
+	}
+
+	if(prog == nil){
 		path = strdup(m->path);
-		prog = "jpg -9t | resize -x128";
 		if(path != nil && (s = utfrrune(path, '/')) != nil){
 			*s = 0;
-			if((s = smprint("%s/cover.jpg", path)) != nil && (fd = open(s, OREAD)) < 0){
-				free(s);
-				if((s = smprint("%s/Cover.jpg", path)) != nil)
-					fd = open(s, OREAD);
-			}
+
+			if((s = smprint("%s/cover.jpg", path)) != nil && (fd = open(s, OREAD)) >= 0)
+				prog = "jpg";
 			free(s);
+			s = nil;
+
+			if(fd < 0 && (s = smprint("%s/cover.png", path)) != nil && (fd = open(s, OREAD)) >= 0)
+				prog = "png";
+			free(s);
 		}
 		free(path);
-		if(fd < 0)
-			goto done;
 	}
 
+	if(prog == nil)
+		goto done;
+
 	if(fd < 0){
 		fd = open(m->path, OREAD);
 		seek(fd, m->imageoffset, 0);
@@ -277,7 +282,8 @@
 		dup(fd, 0); close(fd);
 		dup(p[1], 1); close(p[1]);
 		close(2);
-		execl("/bin/rc", "rc", "-c", prog, nil);
+		snprint(tmp, sizeof(tmp), "%s -9t | resample -x128", prog);
+		execl("/bin/rc", "rc", "-c", tmp, nil);
 		sysfatal("execl: %r");
 	}
 	close(fd);