From: qwx@sciops.net
To: 9front@9front.org
Subject: [9front] page(1) invert colors
Date: Thu, 13 Jan 2022 03:36:01 +0100 [thread overview]
Message-ID: <676DBB4BC5C037D3DD28D4476572730F@wopr.sciops.net> (raw)
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:
next reply other threads:[~2022-01-13 2:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-13 2:36 qwx [this message]
2023-03-09 18:30 ` mkf9
2023-03-09 19:22 ` phil9
2023-03-09 22:49 ` qwx
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=676DBB4BC5C037D3DD28D4476572730F@wopr.sciops.net \
--to=qwx@sciops.net \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).