--- ray/src/px/pcompos.c 2005/05/25 04:44:26 2.30 +++ ray/src/px/pcompos.c 2009/08/10 04:26:38 2.33 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pcompos.c,v 2.30 2005/05/25 04:44:26 greg Exp $"; +static const char RCSid[] = "$Id: pcompos.c,v 2.33 2009/08/10 04:26:38 greg Exp $"; #endif /* * pcompos.c - program to composite pictures. @@ -20,7 +20,7 @@ static const char RCSid[] = "$Id: pcompos.c,v 2.30 200 #include "color.h" #include "resolu.h" -#define MAXFILE 512 +#define MAXFILE 1024 #define HASMIN 1 #define HASMAX 2 @@ -52,24 +52,25 @@ struct { int xres, yres; /* picture size */ int xloc, yloc; /* anchor point */ int flags; /* HASMIN, HASMAX */ - COLR thmin, thmax; /* thresholds */ + double thmin, thmax; /* thresholds */ } input[MAXFILE]; /* our input files */ int nfile; /* number of files */ +int echoheader = 1; char ourfmt[LPICFMT+1] = PICFMT; int wrongformat = 0; -static gethfunc tabputs; +static gethfunc headline; static void compos(void); -static int cmpcolr(COLR c1, COLR c2); +static int cmpcolr(COLR c1, double lv2); static FILE * lblopen(char *s, int *xp, int *yp); static int -tabputs( /* print line preceded by a tab */ +headline( /* print line preceded by a tab */ char *s, void *p ) @@ -84,7 +85,7 @@ tabputs( /* print line preceded by a tab */ strcpy(ourfmt, fmt); } else wrongformat = 1; - } else { + } else if (echoheader) { putc('\t', stdout); fputs(s, stdout); } @@ -111,6 +112,9 @@ main( for (an = 1; an < argc && argv[an][0] == '-'; an++) switch (argv[an][1]) { + case 'h': + echoheader = !echoheader; + break; case 'x': xsiz = atoi(argv[++an]); break; @@ -169,16 +173,10 @@ dofiles: checkthresh = 1; if (argv[an][0] == '-') { input[nfile].flags |= HASMIN; - setcolr(input[nfile].thmin, - atof(argv[an+1]), - atof(argv[an+1]), - atof(argv[an+1])); + input[nfile].thmin = atof(argv[an+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])); + input[nfile].thmax = atof(argv[an+1]); } else goto userr; an++; @@ -230,8 +228,9 @@ getfile: } an++; /* get header */ - printf("%s:\n", input[nfile].name); - getheader(input[nfile].fp, tabputs, NULL); + if (echoheader) + printf("%s:\n", input[nfile].name); + getheader(input[nfile].fp, headline, NULL); if (wrongformat) { fprintf(stderr, "%s: incompatible input format\n", input[nfile].name); @@ -310,7 +309,7 @@ getfile: quit(0); userr: fprintf(stderr, - "Usage: %s [-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ", + "Usage: %s [-h][-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][=SS] pic1 x1 y1 ..\n"); quit(1); @@ -393,17 +392,17 @@ memerr: static int -cmpcolr( /* compare two colr's (improvisation) */ +cmpcolr( /* compare COLR to luminance */ register COLR c1, - register COLR c2 + double lv2 ) { - register int i, j; - - j = 4; /* check exponents first! */ - while (j--) - if ( (i = c1[j] - c2[j]) ) - return(i); + double lv1 = .0; + + if (c1[EXP]) + lv1 = ldexp((double)normbright(c1), (int)c1[EXP]-(COLXS+8)); + if (lv1 < lv2) return(-1); + if (lv1 > lv2) return(1); return(0); }