* [9front] page(1) invert colors
@ 2022-01-13 2:36 qwx
2023-03-09 18:30 ` mkf9
0 siblings, 1 reply; 4+ messages 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] 4+ messages in thread
* Re: [9front] page(1) invert colors
2022-01-13 2:36 [9front] page(1) invert colors qwx
@ 2023-03-09 18:30 ` mkf9
2023-03-09 19:22 ` phil9
0 siblings, 1 reply; 4+ messages in thread
From: mkf9 @ 2023-03-09 18:30 UTC (permalink / raw)
To: 9front
qwx@sciops.net wrote:
> 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
>
This patch is wonderfully useful :D,
can we have it on base so this wont get lost later on?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [9front] page(1) invert colors
2023-03-09 18:30 ` mkf9
@ 2023-03-09 19:22 ` phil9
2023-03-09 22:49 ` qwx
0 siblings, 1 reply; 4+ messages in thread
From: phil9 @ 2023-03-09 19:22 UTC (permalink / raw)
To: 9front
I have a somewhat similar patch (calling ifilter) but did not share it
as this hack leads to images (within documents) also being inverted.
I had tried to do the right thing by having ghostscript invert text
colors but never managed to do it :(
On Thu, Mar 9, 2023 at 8:05 PM mkf9 <mkf9@riseup.net> wrote:
>
> qwx@sciops.net wrote:
> > 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
> >
>
> This patch is wonderfully useful :D,
> can we have it on base so this wont get lost later on?
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [9front] page(1) invert colors
2023-03-09 19:22 ` phil9
@ 2023-03-09 22:49 ` qwx
0 siblings, 0 replies; 4+ messages in thread
From: qwx @ 2023-03-09 22:49 UTC (permalink / raw)
To: 9front
The patch lives in my `patch' repo along with other questionable stuff
[1]. Using an external tool is in line with other transforms page
already does, I think it makes more sense, but such a tool must be
imported first. Since it would be useful to have outside of page for
image manipulation, I also think that that would be more useful than
attempting ghostscript black magic. Technically, an implementation of
pico (like [2]) can do that kind of stuff and might be neat to have; I
am not really happy with my implementation and would have to revisit
it first, but if there's interest, I can do that. Otherwise, iirc
Sigrid also has some image filters that could be interesting, besides
ifilter.
Cheers,
qwx
[1] http://shithub.us/qwx/patch/a2261b507684fa6af14c42c5647401e29e617ff8/page-invert/raw
[2] http://shithub.us/qwx/pico/HEAD/info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-09 22:51 UTC | newest]
Thread overview: 4+ messages (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
2023-03-09 18:30 ` mkf9
2023-03-09 19:22 ` phil9
2023-03-09 22:49 ` 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).