summaryrefslogtreecommitdiff
path: root/sys/src/cmd/jpg
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2014-02-08 02:33:29 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2014-02-08 02:33:29 +0100
commit7af85b9e74ab055d55ad20ce8dd6d9caf002d525 (patch)
tree47ec8e423f2bf5b4736078276aad4aeec198773a /sys/src/cmd/jpg
parentb3df8945bd2512349ae7662843d5bdcf15b3804d (diff)
jpg: center image in screen
when using the jpg(1) programs interactively, draw the image in the center of it. this avoids wasting space with always on borders on small windows and looks better when used in fullscreen.
Diffstat (limited to 'sys/src/cmd/jpg')
-rw-r--r--sys/src/cmd/jpg/bmp.c14
-rw-r--r--sys/src/cmd/jpg/gif.c10
-rw-r--r--sys/src/cmd/jpg/jpg.c14
-rw-r--r--sys/src/cmd/jpg/png.c14
-rw-r--r--sys/src/cmd/jpg/ppm.c14
-rw-r--r--sys/src/cmd/jpg/tga.c14
-rw-r--r--sys/src/cmd/jpg/tif.c14
-rw-r--r--sys/src/cmd/jpg/v210.c14
-rw-r--r--sys/src/cmd/jpg/yuv.c14
9 files changed, 93 insertions, 29 deletions
diff --git a/sys/src/cmd/jpg/bmp.c b/sys/src/cmd/jpg/bmp.c
index 9aacdb0d0..c1775b71e 100644
--- a/sys/src/cmd/jpg/bmp.c
+++ b/sys/src/cmd/jpg/bmp.c
@@ -24,6 +24,16 @@ char *show(int, char*);
Rawimage** readbmp(int fd, int colorspace);
+Rectangle
+imager(Image *i)
+{
+ Point p1, p2;
+
+ p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
+ p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
+ return rectaddpt(i->r, subpt(p2, p1));
+}
+
void
eresized(int new)
{
@@ -35,9 +45,7 @@ eresized(int new)
}
if(image == nil)
return;
- r = insetrect(screen->clipr, Edge+Border);
- r.max.x = r.min.x+Dx(image->r);
- r.max.y = r.min.y+Dy(image->r);
+ r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);
diff --git a/sys/src/cmd/jpg/gif.c b/sys/src/cmd/jpg/gif.c
index 33d703bc9..235a9dce1 100644
--- a/sys/src/cmd/jpg/gif.c
+++ b/sys/src/cmd/jpg/gif.c
@@ -26,14 +26,14 @@ char *show(int, char*);
Rectangle
imager(void)
{
- Rectangle r;
+ Point p1, p2;
if(allims==nil || allims[0]==nil)
return screen->r;
- r = insetrect(screen->clipr, Edge+Border);
- r.max.x = r.min.x+Dx(allims[0]->r);
- r.max.y = r.min.y+Dy(allims[0]->r);
- return r;
+
+ p1 = addpt(divpt(subpt(allims[0]->r.max, allims[0]->r.min), 2), allims[0]->r.min);
+ p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
+ return rectaddpt(allims[0]->r, subpt(p2, p1));
}
void
diff --git a/sys/src/cmd/jpg/jpg.c b/sys/src/cmd/jpg/jpg.c
index 307dc347f..cf1eb4127 100644
--- a/sys/src/cmd/jpg/jpg.c
+++ b/sys/src/cmd/jpg/jpg.c
@@ -26,6 +26,16 @@ enum{
char *show(int, char*, int);
+Rectangle
+imager(Image *i)
+{
+ Point p1, p2;
+
+ p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
+ p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
+ return rectaddpt(i->r, subpt(p2, p1));
+}
+
void
eresized(int new)
{
@@ -37,9 +47,7 @@ eresized(int new)
}
if(image == nil)
return;
- r = insetrect(screen->clipr, Edge+Border);
- r.max.x = r.min.x+Dx(image->r);
- r.max.y = r.min.y+Dy(image->r);
+ r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);
diff --git a/sys/src/cmd/jpg/png.c b/sys/src/cmd/jpg/png.c
index a27461186..cf8803e87 100644
--- a/sys/src/cmd/jpg/png.c
+++ b/sys/src/cmd/jpg/png.c
@@ -23,6 +23,16 @@ enum{
char *show(int, char*, int);
+Rectangle
+imager(Image *i)
+{
+ Point p1, p2;
+
+ p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
+ p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
+ return rectaddpt(i->r, subpt(p2, p1));
+}
+
void
eresized(int new)
{
@@ -34,9 +44,7 @@ eresized(int new)
}
if(image == nil)
return;
- r = insetrect(screen->clipr, Edge+Border);
- r.max.x = r.min.x+Dx(image->r);
- r.max.y = r.min.y+Dy(image->r);
+ r = imager(image);
border(screen, r, -Border, nil, ZP);
draw(screen, r, image, nil, image->r.min);
flushimage(display, 1);
diff --git a/sys/src/cmd/jpg/ppm.c b/sys/src/cmd/jpg/ppm.c
index 58811b921..89945ae63 100644
--- a/sys/src/cmd/jpg/ppm.c
+++ b/sys/src/cmd/jpg/ppm.c
@@ -22,6 +22,16 @@ enum{
char *show(int, char*);
+Rectangle
+imager(Image *i)
+{
+ Point p1, p2;
+
+ p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
+ p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
+ return rectaddpt(i->r, subpt(p2, p1));
+}
+
void
eresized(int new)
{
@@ -33,9 +43,7 @@ eresized(int new)
}
if(image == nil)
return;
- r = insetrect(screen->clipr, Edge+Border);
- r.max.x = r.min.x+Dx(image->r);
- r.max.y = r.min.y+Dy(image->r);
+ r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);
diff --git a/sys/src/cmd/jpg/tga.c b/sys/src/cmd/jpg/tga.c
index 940d76d88..a505792fb 100644
--- a/sys/src/cmd/jpg/tga.c
+++ b/sys/src/cmd/jpg/tga.c
@@ -24,6 +24,16 @@ char *show(int, char*);
Rawimage** readtga(int fd);
+Rectangle
+imager(Image *i)
+{
+ Point p1, p2;
+
+ p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
+ p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
+ return rectaddpt(i->r, subpt(p2, p1));
+}
+
void
eresized(int new)
{
@@ -35,9 +45,7 @@ eresized(int new)
}
if(image == nil)
return;
- r = insetrect(screen->clipr, Edge+Border);
- r.max.x = r.min.x+Dx(image->r);
- r.max.y = r.min.y+Dy(image->r);
+ r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);
diff --git a/sys/src/cmd/jpg/tif.c b/sys/src/cmd/jpg/tif.c
index 70c4f2282..9f7bc8a60 100644
--- a/sys/src/cmd/jpg/tif.c
+++ b/sys/src/cmd/jpg/tif.c
@@ -22,6 +22,16 @@ enum {
int init(void);
char *show(int, char *, int);
+Rectangle
+imager(Image *i)
+{
+ Point p1, p2;
+
+ p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
+ p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
+ return rectaddpt(i->r, subpt(p2, p1));
+}
+
void
eresized(int new)
{
@@ -31,9 +41,7 @@ eresized(int new)
sysfatal("getwindow: %r");
if(image == nil)
return;
- r = insetrect(screen->clipr, Edge+Border);
- r.max.x = r.min.x + Dx(image->r);
- r.max.y = r.min.y + Dy(image->r);
+ r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);
diff --git a/sys/src/cmd/jpg/v210.c b/sys/src/cmd/jpg/v210.c
index 1bb581349..65f5ff5de 100644
--- a/sys/src/cmd/jpg/v210.c
+++ b/sys/src/cmd/jpg/v210.c
@@ -24,6 +24,16 @@ char *show(int, char*);
Rawimage** readV210(int fd, int colorspace);
+Rectangle
+imager(Image *i)
+{
+ Point p1, p2;
+
+ p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
+ p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
+ return rectaddpt(i->r, subpt(p2, p1));
+}
+
void
eresized(int new)
{
@@ -35,9 +45,7 @@ eresized(int new)
}
if(image == nil)
return;
- r = insetrect(screen->clipr, Edge+Border);
- r.max.x = r.min.x+Dx(image->r);
- r.max.y = r.min.y+Dy(image->r);
+ r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);
diff --git a/sys/src/cmd/jpg/yuv.c b/sys/src/cmd/jpg/yuv.c
index 4b52d4ff8..47811ab22 100644
--- a/sys/src/cmd/jpg/yuv.c
+++ b/sys/src/cmd/jpg/yuv.c
@@ -24,6 +24,16 @@ char *show(int, char*);
Rawimage** readyuv(int fd, int colorspace);
+Rectangle
+imager(Image *i)
+{
+ Point p1, p2;
+
+ p1 = addpt(divpt(subpt(i->r.max, i->r.min), 2), i->r.min);
+ p2 = addpt(divpt(subpt(screen->clipr.max, screen->clipr.min), 2), screen->clipr.min);
+ return rectaddpt(i->r, subpt(p2, p1));
+}
+
void
eresized(int new)
{
@@ -35,9 +45,7 @@ eresized(int new)
}
if(image == nil)
return;
- r = insetrect(screen->clipr, Edge+Border);
- r.max.x = r.min.x+Dx(image->r);
- r.max.y = r.min.y+Dy(image->r);
+ r = imager(image);
border(screen, r, -Border, nil, ZP);
drawop(screen, r, image, nil, image->r.min, S);
flushimage(display, 1);