--- ray/src/px/pcompos.c 1989/06/12 10:07:29 1.2 +++ ray/src/px/pcompos.c 1992/07/13 15:04:15 2.8 @@ -1,4 +1,4 @@ -/* Copyright (c) 1987 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -14,8 +14,9 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" +#include "resolu.h" -#define MAXFILE 16 +#define MAXFILE 64 /* output picture size */ int xsiz = 0; @@ -28,12 +29,14 @@ int ymax = 0; COLR bgcolr = BLKCOLR; /* background color */ +int labelht = 24; /* label height */ + int checkthresh = 0; /* check threshold value */ char *progname; struct { - char *name; /* file name */ + char *name; /* file or command name */ FILE *fp; /* stream pointer */ int xres, yres; /* picture size */ int xloc, yloc; /* anchor point */ @@ -43,12 +46,23 @@ struct { int nfile; /* number of files */ +int wrongformat = 0; +FILE *popen(), *lblopen(); + + tabputs(s) /* print line preceded by a tab */ char *s; { - putc('\t', stdout); - fputs(s, stdout); + char fmt[32]; + + if (isformat(s)) { + formatval(fmt, s); + wrongformat = strcmp(fmt, COLRFMT); + } else { + putc('\t', stdout); + fputs(s, stdout); + } } @@ -56,7 +70,10 @@ main(argc, argv) int argc; char *argv[]; { - double atof(); + int ncolumns = 0; + int autolabel = 0; + int curcol = 0, curx = 0, cury = 0; + char *thislabel; int an; progname = argv[0]; @@ -75,6 +92,23 @@ char *argv[]; atof(argv[an+3])); an += 3; break; + case 'a': + ncolumns = atoi(argv[++an]); + break; + case 'l': + switch (argv[an][2]) { + case 'a': + autolabel++; + break; + case 'h': + labelht = atoi(argv[++an]); + break; + case '\0': + goto dofiles; + default: + goto userr; + } + break; case '\0': case 't': goto dofiles; @@ -83,10 +117,9 @@ char *argv[]; } dofiles: for (nfile = 0; an < argc; nfile++) { - if (nfile >= MAXFILE) { - fprintf(stderr, "%s: too many files\n", progname); - quit(1); - } + if (nfile >= MAXFILE) + goto toomany; + thislabel = NULL; input[nfile].hasmin = input[nfile].hasmax = 0; while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+')) switch (argv[an][1]) { @@ -107,39 +140,70 @@ dofiles: } an += 2; break; + case 'l': + if (strcmp(argv[an], "-l")) + goto userr; + thislabel = argv[an+1]; + an += 2; + break; case '\0': if (argv[an][0] == '-') goto getfile; - /* fall through */ + goto userr; default: goto userr; } getfile: - if (argc-an < 3) + if (argc-an < (ncolumns ? 1 : 3)) goto userr; + if (autolabel && thislabel == NULL) + thislabel = argv[an]; if (!strcmp(argv[an], "-")) { input[nfile].name = ""; input[nfile].fp = stdin; } else { - input[nfile].name = argv[an]; - if ((input[nfile].fp = fopen(argv[an], "r")) == NULL) { - fprintf(stderr, "%s: cannot open\n", argv[an]); + if (argv[an][0] == '!') { + input[nfile].name = ""; + input[nfile].fp = popen(argv[an]+1, "r"); + } else { + input[nfile].name = argv[an]; + input[nfile].fp = fopen(argv[an], "r"); + } + if (input[nfile].fp == NULL) { + perror(argv[an]); quit(1); } } an++; /* get header */ printf("%s:\n", input[nfile].name); - getheader(input[nfile].fp, tabputs); + getheader(input[nfile].fp, tabputs, NULL); + if (wrongformat) { + fprintf(stderr, "%s: not a Radiance picture\n", + input[nfile].name); + quit(1); + } /* get picture size */ - if (fscanf(input[nfile].fp, "-Y %d +X %d\n", - &input[nfile].yres, &input[nfile].xres) != 2) { + if (fgetresolu(&input[nfile].xres, &input[nfile].yres, + input[nfile].fp) < 0) { fprintf(stderr, "%s: bad picture size\n", input[nfile].name); quit(1); } - input[nfile].xloc = atoi(argv[an++]); - input[nfile].yloc = atoi(argv[an++]); + if (ncolumns > 0) { + if (curcol >= ncolumns) { + cury = ymax; + curx = 0; + curcol = 0; + } + input[nfile].xloc = curx; + input[nfile].yloc = cury; + curx += input[nfile].xres; + curcol++; + } else { + input[nfile].xloc = atoi(argv[an++]); + input[nfile].yloc = atoi(argv[an++]); + } if (input[nfile].xloc < xmin) xmin = input[nfile].xloc; if (input[nfile].yloc < ymin) @@ -148,6 +212,21 @@ getfile: xmax = input[nfile].xloc+input[nfile].xres; if (input[nfile].yloc+input[nfile].yres > ymax) ymax = input[nfile].yloc+input[nfile].yres; + if (thislabel != NULL) { + if (++nfile >= MAXFILE) + goto toomany; + input[nfile].name = "