--- ray/src/px/pcompos.c 1989/06/12 10:07:29 1.2 +++ ray/src/px/pcompos.c 1991/04/18 14:35:19 1.6 @@ -15,7 +15,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" -#define MAXFILE 16 +#define MAXFILE 32 /* output picture size */ int xsiz = 0; @@ -43,12 +43,21 @@ struct { int nfile; /* number of files */ +int wrongformat = 0; + 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); + } } @@ -123,17 +132,22 @@ getfile: } else { input[nfile].name = argv[an]; if ((input[nfile].fp = fopen(argv[an], "r")) == NULL) { - fprintf(stderr, "%s: cannot open\n", argv[an]); + 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) != (YMAJOR|YDECR)) { fprintf(stderr, "%s: bad picture size\n", input[nfile].name); quit(1); @@ -155,6 +169,7 @@ getfile: ysiz = ymax; /* add new header info. */ printargs(argc, argv, stdout); + fputformat(COLRFMT, stdout); printf("\n-Y %d +X %d\n", ysiz, xsiz); compos(); @@ -173,8 +188,7 @@ compos() /* composite pictures */ int y; register int x, i; - scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR)) - xmin; - scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR)) - xmin; + scanin = (COLR *)malloc((xmax-xmin)*sizeof(COLR)); if (scanin == NULL) goto memerr; scanin -= xmin; @@ -218,13 +232,13 @@ compos() /* composite pictures */ if (y >= ysiz) continue; if (fwritecolrs(scanout, xsiz, stdout) < 0) { - fprintf(stderr, "%s: write error\n", progname); + perror(progname); quit(1); } } return; memerr: - fprintf(stderr, "%s: out of memory\n", progname); + perror(progname); quit(1); }