--- ray/src/px/pcompos.c 1993/06/04 14:47:01 2.16 +++ ray/src/px/pcompos.c 2003/11/10 12:28:56 2.26 @@ -1,9 +1,6 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: pcompos.c,v 2.26 2003/11/10 12:28:56 schorsch Exp $"; #endif - /* * pcompos.c - program to composite pictures. * @@ -11,19 +8,22 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include - #include +#include +#include -#ifdef MSDOS -#include -#endif +#include "copyright.h" +#include "platform.h" +#include "rtprocess.h" #include "color.h" - #include "resolu.h" #define MAXFILE 64 +#define HASMIN 1 +#define HASMAX 2 + /* output picture size */ int xsiz = 0; int ysiz = 0; @@ -49,31 +49,37 @@ struct { FILE *fp; /* stream pointer */ int xres, yres; /* picture size */ int xloc, yloc; /* anchor point */ - int hasmin, hasmax; /* has threshold values */ + int flags; /* HASMIN, HASMAX */ COLR thmin, thmax; /* thresholds */ } input[MAXFILE]; /* our input files */ int nfile; /* number of files */ +char ourfmt[LPICFMT+1] = PICFMT; int wrongformat = 0; -FILE *popen(), *lblopen(); +FILE *lblopen(); +void quit(); -extern char *malloc(); - tabputs(s) /* print line preceded by a tab */ char *s; { char fmt[32]; - if (isformat(s)) { - formatval(fmt, s); - wrongformat = strcmp(fmt, COLRFMT); + if (isheadid(s)) + return(0); + if (formatval(fmt, s)) { + if (globmatch(ourfmt, fmt)) { + wrongformat = 0; + strcpy(ourfmt, fmt); + } else + wrongformat = 1; } else { putc('\t', stdout); fputs(s, stdout); } + return(0); } @@ -84,14 +90,12 @@ char *argv[]; int ncolumns = 0; int autolabel = 0; int curcol = 0, x0 = 0, curx = 0, cury = 0, spacing = 0; + int xsgn, ysgn; char *thislabel; int an; -#ifdef MSDOS - extern int _fmode; - _fmode = O_BINARY; - setmode(fileno(stdin), O_BINARY); - setmode(fileno(stdout), O_BINARY); -#endif + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdin); + SET_FILE_BINARY(stdout); progname = argv[0]; for (an = 1; an < argc && argv[an][0] == '-'; an++) @@ -139,36 +143,50 @@ char *argv[]; goto userr; } dofiles: + newheader("RADIANCE", stdout); + fputnow(stdout); for (nfile = 0; an < argc; nfile++) { if (nfile >= MAXFILE) goto toomany; thislabel = NULL; - input[nfile].hasmin = input[nfile].hasmax = 0; - while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+')) + input[nfile].flags = 0; + xsgn = ysgn = '-'; + while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+' + || argv[an][0] == '=')) { switch (argv[an][1]) { case 't': checkthresh = 1; if (argv[an][0] == '-') { - input[nfile].hasmin = 1; + input[nfile].flags |= HASMIN; setcolr(input[nfile].thmin, atof(argv[an+1]), atof(argv[an+1]), atof(argv[an+1])); - } else { - input[nfile].hasmax = 1; + } else if (argv[an][0] == '+') { + input[nfile].flags |= HASMAX; setcolr(input[nfile].thmax, atof(argv[an+1]), atof(argv[an+1]), atof(argv[an+1])); - } - an += 2; + } else + goto userr; + an++; break; case 'l': if (strcmp(argv[an], "-l")) goto userr; - thislabel = argv[an+1]; - an += 2; + thislabel = argv[++an]; break; + case '+': + case '-': + case '0': + if (argv[an][0] != '=') + goto userr; + xsgn = argv[an][1]; + ysgn = argv[an][2]; + if (ysgn != '+' && ysgn != '-' && ysgn != '0') + goto userr; + break; case '\0': if (argv[an][0] == '-') goto getfile; @@ -176,6 +194,8 @@ dofiles: default: goto userr; } + an++; + } getfile: if (argc-an < (ncolumns ? 1 : 3)) goto userr; @@ -202,7 +222,7 @@ getfile: printf("%s:\n", input[nfile].name); getheader(input[nfile].fp, tabputs, NULL); if (wrongformat) { - fprintf(stderr, "%s: not a Radiance picture\n", + fprintf(stderr, "%s: incompatible input format\n", input[nfile].name); quit(1); } @@ -225,7 +245,15 @@ getfile: curcol++; } else { input[nfile].xloc = atoi(argv[an++]); + if (xsgn == '+') + input[nfile].xloc -= input[nfile].xres; + else if (xsgn == '0') + input[nfile].xloc -= input[nfile].xres/2; input[nfile].yloc = atoi(argv[an++]); + if (ysgn == '+') + input[nfile].yloc -= input[nfile].yres; + else if (ysgn == '0') + input[nfile].yloc -= input[nfile].yres/2; } if (input[nfile].xloc < xmin) xmin = input[nfile].xloc; @@ -239,7 +267,7 @@ getfile: if (++nfile >= MAXFILE) goto toomany; input[nfile].name = Label; - input[nfile].hasmin = input[nfile].hasmax = 0; + input[nfile].flags = 0; input[nfile].xres = input[nfile-1].xres; input[nfile].yres = labelht; if ((input[nfile].fp = lblopen(thislabel, @@ -261,7 +289,8 @@ getfile: ymax = ysiz; /* add new header info. */ printargs(argc, argv, stdout); - fputformat(COLRFMT, stdout); + if (strcmp(ourfmt, PICFMT)) + fputformat(ourfmt, stdout); /* print format if known */ putchar('\n'); fprtresolu(xsiz, ysiz, stdout); @@ -272,7 +301,7 @@ userr: fprintf(stderr, "Usage: %s [-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ", progname); - fprintf(stderr, "[-t min1][+t max1][-l lab] pic1 x1 y1 ..\n"); + fprintf(stderr, "[-t min1][+t max1][-l lab][=SS] pic1 x1 y1 ..\n"); quit(1); toomany: fprintf(stderr, "%s: only %d files and labels allowed\n", @@ -321,10 +350,10 @@ compos() /* composite pictures */ if (x > xsiz) x = xsiz; for (x--; x >= 0 && x >= input[i].xloc; x--) { - if (input[i].hasmin && + if (input[i].flags & HASMIN && cmpcolr(scanin[x], input[i].thmin) <= 0) continue; - if (input[i].hasmax && + if (input[i].flags & HASMAX && cmpcolr(scanin[x], input[i].thmax) >= 0) continue; copycolr(scanout[x], scanin[x]); @@ -353,7 +382,7 @@ register COLR c1, c2; j = 4; /* check exponents first! */ while (j--) - if (i = c1[j] - c2[j]) + if ( (i = c1[j] - c2[j]) ) return(i); return(0); } @@ -364,7 +393,7 @@ lblopen(s, xp, yp) /* open pipe to label generator */ char *s; int *xp, *yp; { - char com[128]; + char com[PATH_MAX]; FILE *fp; sprintf(com, "psign -s -.15 -a 2 -x %d -y %d '%.90s'", *xp, *yp, s); @@ -381,6 +410,7 @@ err: } +void quit(code) /* exit gracefully */ int code; {