Update: the first version of the patch didn't allow the -zoom auto option to
persist across multiple images. This version fixes that.

diff -ruNp a/TODO b/TODO
--- a/TODO      2000-02-09 04:23:32.000000000 -0500
+++ b/TODO      2007-09-03 23:31:28.000000000 -0500
@@ -22,7 +22,6 @@ add vicar reader, copyright Noel Gorelic
 developed by NASA/JPL.'
 
 make fast image scaling a subfeature of -zoom, eliminate -iscale
-and add -zoom auto
 
 add a TIFF reader?
 
diff -ruNp a/misc.c b/misc.c
--- a/misc.c    2000-02-09 04:23:33.000000000 -0500
+++ b/misc.c    2007-09-03 22:40:36.000000000 -0500
@@ -104,6 +104,8 @@ char *tail(char *path)
        return (t);
 }
 
+#define MIN(a,b) ( (a)<(b) ? (a) : (b))
+
 Image *processImage(DisplayInfo *dinfo, Image *iimage, ImageOptions *options)
 {
        Image *image = iimage, *tmpimage;
@@ -132,6 +134,19 @@ Image *processImage(DisplayInfo *dinfo, 
                image = tmpimage;
        }
        /* zoom image */
+       if (options->zoom_auto) {
+               if (image->width > globals.dinfo.width * .9)
+                       options->xzoom = globals.dinfo.width * 90 / 
image->width;
+               else
+                       options->xzoom = 100;
+               if (image->height > globals.dinfo.height * .9)
+                       options->yzoom = globals.dinfo.height * 90 / 
image->height;
+               else
+                       options->yzoom = 100;
+               /* both dimensions should be shrunk by the same factor */
+               options->xzoom = options->yzoom =
+                       MIN(options->xzoom, options->yzoom);
+       }
        if (options->xzoom || options->yzoom) {
                /* if the image is to be blown up, compress before doing it */
                if (!options->colors && RGBP(image) &&  
diff -ruNp a/options.c b/options.c
--- a/options.c 1999-10-24 21:15:00.000000000 -0500
+++ b/options.c 2007-09-04 16:15:42.000000000 -0500
@@ -731,13 +731,20 @@ int doLocalOption(OptionId opid, char **
 
        case ZOOM:
                if (argv[++a]) {
-                       if (atoi(argv[a]) < 0) {
-                               printf("Zoom argument must be positive 
(ignored).\n");
-                               break;
+                       if (!strcmp(argv[a], "auto")) {
+                                image_ops->zoom_auto = TRUE;
+                        } else {
+                               if (atoi(argv[a]) < 0) {
+                                       printf("Zoom argument must be positive 
(ignored).\n");
+                                       break;
+                               }
+                               image_ops->xzoom = image_ops->yzoom = 
atoi(argv[a]);
+                               image_ops->zoom_auto = FALSE;
                        }
-                       image_ops->xzoom = image_ops->yzoom = atoi(argv[a]);
-                       if (setpersist)
+                       if (setpersist) {
                                persist_ops->xzoom = persist_ops->yzoom = 
image_ops->xzoom;
+                               persist_ops->zoom_auto = image_ops->zoom_auto;
+                       }
                }
                break;
 
diff -ruNp a/xli.c b/xli.c
--- a/xli.c     2000-02-09 04:23:35.000000000 -0500
+++ b/xli.c     2007-09-04 16:32:12.000000000 -0500
@@ -90,6 +90,7 @@ int main(int argc, char *argv[])
        persist_ops.xpmkeyc = 0;        /* none */
        persist_ops.xzoom = 0;
        persist_ops.yzoom = 0;
+       persist_ops.zoom_auto = FALSE;
        persist_ops.iscale = 0;
        persist_ops.iscale_auto = FALSE;
 
@@ -201,6 +202,7 @@ int main(int argc, char *argv[])
                        images[nimages].xpmkeyc = persist_ops.xpmkeyc;
                        images[nimages].xzoom = persist_ops.xzoom;
                        images[nimages].yzoom = persist_ops.yzoom;
+                       images[nimages].zoom_auto = persist_ops.zoom_auto;
                        images[nimages].iscale_auto = persist_ops.iscale_auto;
                        nimages++;
                        INIT_IMAGE_OPTS(images[nimages]);
@@ -541,6 +543,7 @@ int main(int argc, char *argv[])
                                break;
                        }
                        io->xzoom = io->yzoom = 0;
+                       io->zoom_auto = 0;
                        io->iscale_auto = 0;
 
                        if (globals.verbose) {
diff -ruNp a/xli.h b/xli.h
--- a/xli.h     1999-10-24 21:15:07.000000000 -0500
+++ b/xli.h     2007-09-03 22:40:36.000000000 -0500
@@ -55,6 +55,7 @@ typedef struct {
        char *title;            /* Override title on image */
        unsigned int xzoom, yzoom;
                                /* zoom percentages */
+       boolean zoom_auto;      /* automatically zoom to fit on screen */
        char *fg, *bg;          /* foreground/background colors if mono image */
        boolean done_to;        /* TRUE if we have already looked for trailing
                                 * options
diff -ruNp a/xli.man b/xli.man
--- a/xli.man   2007-09-03 22:40:08.000000000 -0500
+++ b/xli.man   2007-09-04 00:02:38.000000000 -0500
@@ -317,6 +317,9 @@ more information.  Technically the perce
 square of the number supplied since the zoom is to both axes, but I
 opted for consistency instead of accuracy.
 .TP
+\-zoom auto
+Zoom large images to fit the screen; don't zoom small images.
+.TP
 \-newoptions
 Reset options that propagate.  The \fI\-bright, \-colors, \-colordither, 
\-delay,
 \-dither, \-gamma, \-gray, \-normalize, \-smooth, \-xzoom, \-yzoom\fR, and



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to