ref: 64483f35745627ddb2e7d678a10a052aef38895e
dir: /page-invert/
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: