9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] page(1) invert colors
@ 2022-01-13  2:36 qwx
  0 siblings, 0 replies; only message in thread
From: qwx @ 2022-01-13  2:36 UTC (permalink / raw)
  To: 9front

Hello,

Another optional patch for page(1), in case anyone finds it useful,
for inverting image colors, which I find nice for reading pdf's given
my eye strain problems, etc.  etc.  It's a bit silly, and I'm not
aware of any external tool in 9front which can invert images, but
phil9[1] and maybe others have written some.

Cheers,
qwx

[1] gits://shithub.us/phil9/ifilter


diff 6e64d30454f71ecda88dba1bd792e97509115d73 uncommitted
--- a//sys/src/cmd/page.c
+++ b//sys/src/cmd/page.c
@@ -33,6 +33,7 @@
 int imode;
 int newwin;
 int rotate;
+int invert;
 int viewgen;
 int forward;	/* read ahead direction: >= 0 forwards, < 0 backwards */
 Point resize, pos;
@@ -67,6 +68,7 @@
 	Cfitheight,
 	Crotate90,
 	Cupsidedown,
+	Cinvert,
 	Cdummy1,
 	Cnext,
 	Cprev,
@@ -91,6 +93,7 @@
 	[Cfitheight]	"fit height",	'h', 0, 0,
 	[Crotate90]	"rotate 90",	'r', 0, 0,
 	[Cupsidedown]	"upside down",	'u', 0, 0,
+	[Cinvert]	"invert",	'i', 0, 0,
 	[Cdummy1]	"",		0, 0, 0,
 	[Cnext]		"next",		Kright, ' ', '\n', 
 	[Cprev]		"prev",		Kleft, Kbs, 0,
@@ -894,6 +897,26 @@
 }
 
 void
+invertimage(Image *i)
+{
+	int n, m;
+	uchar *b;
+	uintptr *buf, *p;
+
+	n = imagesize(i);
+	if((buf = malloc(n)) == nil)
+		return;
+	unloadimage(i, i->r, (uchar*)buf, n);
+	m = n;
+	for(p=buf; m>=sizeof *p; m-=sizeof *p, p++)
+		*p = ~*p;
+	for(b=(uchar*)p; m>0; m--, b++)
+		*b = ~*b;
+	loadimage(i, i->r, (uchar*)buf, n);
+	free(buf);
+}
+
+void
 loadpage(Page *p)
 {
 	int fd;
@@ -913,6 +936,8 @@
 			p->open = nil;
 		else {
 			lockdisplay(display);
+			if(invert)
+				invertimage(p->image);
 			imemsize += imagesize(p->image);
 			unlockdisplay(display);
 		}
@@ -1492,6 +1517,9 @@
 		zoom = 1;
 		resize = subpt(screen->r.max, screen->r.min);
 		resize.x = 0;
+		goto Unload;
+	case Cinvert:
+		invert = !invert;
 		goto Unload;
 	case Czoomin:
 	case Czoomout:

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-13  2:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-13  2:36 [9front] page(1) invert colors qwx

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).