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);