/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; #endif /* * pcompos.c - program to composite pictures. * * 6/30/87 */ #include #include "color.h" #include "resolu.h" #define MAXFILE 32 /* output picture size */ int xsiz = 0; int ysiz = 0; /* input dimensions */ int xmin = 0; int ymin = 0; int xmax = 0; 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 or command name */ FILE *fp; /* stream pointer */ int xres, yres; /* picture size */ int xloc, yloc; /* anchor point */ int hasmin, hasmax; /* has threshold values */ COLR thmin, thmax; /* thresholds */ } input[MAXFILE]; /* our input files */ int nfile; /* number of files */ int wrongformat = 0; FILE *popen(), *lblopen(); tabputs(s) /* print line preceded by a tab */ char *s; { char fmt[32]; if (isformat(s)) { formatval(fmt, s); wrongformat = strcmp(fmt, COLRFMT); } else { putc('\t', stdout); fputs(s, stdout); } } main(argc, argv) int argc; char *argv[]; { int ncolumns = 0; int autolabel = 0; int curcol = 0, curx = 0, cury = 0; char *thislabel; int an; progname = argv[0]; for (an = 1; an < argc && argv[an][0] == '-'; an++) switch (argv[an][1]) { case 'x': xmax = xsiz = atoi(argv[++an]); break; case 'y': ymax = ysiz = atoi(argv[++an]); break; case 'b': setcolr(bgcolr, atof(argv[an+1]), atof(argv[an+2]), 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; default: goto userr; } dofiles: for (nfile = 0; an < argc; nfile++) { if (nfile >= MAXFILE) goto toomany; if (autolabel) thislabel = argv[an]; else thislabel = NULL; input[nfile].hasmin = input[nfile].hasmax = 0; while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+')) switch (argv[an][1]) { case 't': checkthresh = 1; if (argv[an][0] == '-') { input[nfile].hasmin = 1; setcolr(input[nfile].thmin, atof(argv[an+1]), atof(argv[an+1]), atof(argv[an+1])); } else { input[nfile].hasmax = 1; setcolr(input[nfile].thmax, atof(argv[an+1]), atof(argv[an+1]), atof(argv[an+1])); } 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; goto userr; default: goto userr; } getfile: if (argc-an < (ncolumns ? 1 : 3)) goto userr; if (!strcmp(argv[an], "-")) { input[nfile].name = ""; input[nfile].fp = stdin; } else { 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, NULL); if (wrongformat) { fprintf(stderr, "%s: not a Radiance picture\n", input[nfile].name); quit(1); } /* get picture size */ if (fgetresolu(&input[nfile].xres, &input[nfile].yres, input[nfile].fp) < 0) { fprintf(stderr, "%s: bad picture size\n", input[nfile].name); quit(1); } 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) ymin = input[nfile].yloc; if (input[nfile].xloc+input[nfile].xres > xmax) 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 = "