| 7 |
|
* 6/30/87 |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
– |
#include <stdio.h> |
| 11 |
– |
|
| 10 |
|
#include <math.h> |
| 11 |
|
|
| 12 |
< |
#ifdef MSDOS |
| 15 |
< |
#include <fcntl.h> |
| 16 |
< |
#endif |
| 12 |
> |
#include "copyright.h" |
| 13 |
|
|
| 14 |
< |
#include <time.h> |
| 15 |
< |
|
| 14 |
> |
#include "rtio.h" |
| 15 |
> |
#include "platform.h" |
| 16 |
> |
#include "rterror.h" |
| 17 |
|
#include "color.h" |
| 21 |
– |
|
| 18 |
|
#include "resolu.h" |
| 19 |
|
|
| 20 |
< |
#define MAXFILE 64 |
| 20 |
> |
#ifdef getc_unlocked /* avoid horrendous overhead of flockfile */ |
| 21 |
> |
#undef getc |
| 22 |
> |
#define getc getc_unlocked |
| 23 |
> |
#endif |
| 24 |
|
|
| 25 |
+ |
#define MAXFILE 1024 |
| 26 |
+ |
|
| 27 |
|
#define HASMIN 1 |
| 28 |
|
#define HASMAX 2 |
| 29 |
|
|
| 42 |
|
|
| 43 |
|
int checkthresh = 0; /* check threshold value */ |
| 44 |
|
|
| 45 |
+ |
char StandardInput[] = "<stdin>"; |
| 46 |
|
char Command[] = "<Command>"; |
| 47 |
|
char Label[] = "<Label>"; |
| 48 |
|
|
| 47 |
– |
char *progname; |
| 48 |
– |
|
| 49 |
|
struct { |
| 50 |
|
char *name; /* file or command name */ |
| 51 |
|
FILE *fp; /* stream pointer */ |
| 52 |
|
int xres, yres; /* picture size */ |
| 53 |
|
int xloc, yloc; /* anchor point */ |
| 54 |
|
int flags; /* HASMIN, HASMAX */ |
| 55 |
< |
COLR thmin, thmax; /* thresholds */ |
| 55 |
> |
double thmin, thmax; /* thresholds */ |
| 56 |
|
} input[MAXFILE]; /* our input files */ |
| 57 |
|
|
| 58 |
|
int nfile; /* number of files */ |
| 59 |
|
|
| 60 |
< |
char ourfmt[LPICFMT+1] = PICFMT; |
| 60 |
> |
int echoheader = 1; |
| 61 |
> |
char ourfmt[MAXFMTLEN] = PICFMT; |
| 62 |
|
int wrongformat = 0; |
| 63 |
+ |
double common_expos = 1.; |
| 64 |
|
|
| 65 |
< |
FILE *lblopen(); |
| 64 |
< |
void quit(); |
| 65 |
> |
double this_expos; |
| 66 |
|
|
| 67 |
+ |
static gethfunc headline; |
| 68 |
+ |
static void compos(void); |
| 69 |
+ |
static int cmpcolr(COLR c1, double lv2); |
| 70 |
+ |
static FILE * lblopen(char *s, int *xp, int *yp); |
| 71 |
|
|
| 72 |
< |
tabputs(s) /* print line preceded by a tab */ |
| 73 |
< |
char *s; |
| 72 |
> |
|
| 73 |
> |
|
| 74 |
> |
static int |
| 75 |
> |
headline( /* print line preceded by a tab */ |
| 76 |
> |
char *s, |
| 77 |
> |
void *p |
| 78 |
> |
) |
| 79 |
|
{ |
| 80 |
< |
char fmt[32]; |
| 80 |
> |
char fmt[MAXFMTLEN]; |
| 81 |
|
|
| 82 |
|
if (isheadid(s)) |
| 83 |
|
return(0); |
| 84 |
+ |
if (isexpos(s)) |
| 85 |
+ |
this_expos *= exposval(s); |
| 86 |
|
if (formatval(fmt, s)) { |
| 87 |
|
if (globmatch(ourfmt, fmt)) { |
| 88 |
|
wrongformat = 0; |
| 89 |
|
strcpy(ourfmt, fmt); |
| 90 |
|
} else |
| 91 |
|
wrongformat = 1; |
| 92 |
< |
} else { |
| 93 |
< |
putc('\t', stdout); |
| 92 |
> |
} else if (echoheader) { |
| 93 |
> |
fputc('\t', stdout); |
| 94 |
|
fputs(s, stdout); |
| 95 |
|
} |
| 96 |
|
return(0); |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
< |
main(argc, argv) |
| 101 |
< |
int argc; |
| 102 |
< |
char *argv[]; |
| 100 |
> |
int |
| 101 |
> |
main( |
| 102 |
> |
int argc, |
| 103 |
> |
char *argv[] |
| 104 |
> |
) |
| 105 |
|
{ |
| 106 |
|
int ncolumns = 0; |
| 107 |
|
int autolabel = 0; |
| 109 |
|
int xsgn, ysgn; |
| 110 |
|
char *thislabel; |
| 111 |
|
int an; |
| 98 |
– |
#ifdef MSDOS |
| 99 |
– |
extern int _fmode; |
| 100 |
– |
_fmode = O_BINARY; |
| 101 |
– |
setmode(fileno(stdin), O_BINARY); |
| 102 |
– |
setmode(fileno(stdout), O_BINARY); |
| 103 |
– |
#endif |
| 104 |
– |
progname = argv[0]; |
| 112 |
|
|
| 113 |
+ |
SET_DEFAULT_BINARY(); |
| 114 |
+ |
SET_FILE_BINARY(stdin); |
| 115 |
+ |
SET_FILE_BINARY(stdout); |
| 116 |
+ |
|
| 117 |
+ |
fixargv0(argv[0]); /* sets global progname */ |
| 118 |
+ |
|
| 119 |
|
for (an = 1; an < argc && argv[an][0] == '-'; an++) |
| 120 |
|
switch (argv[an][1]) { |
| 121 |
+ |
case 'h': |
| 122 |
+ |
echoheader = !echoheader; |
| 123 |
+ |
break; |
| 124 |
|
case 'x': |
| 125 |
|
xsiz = atoi(argv[++an]); |
| 126 |
|
break; |
| 179 |
|
checkthresh = 1; |
| 180 |
|
if (argv[an][0] == '-') { |
| 181 |
|
input[nfile].flags |= HASMIN; |
| 182 |
< |
setcolr(input[nfile].thmin, |
| 167 |
< |
atof(argv[an+1]), |
| 168 |
< |
atof(argv[an+1]), |
| 169 |
< |
atof(argv[an+1])); |
| 182 |
> |
input[nfile].thmin = atof(argv[an+1]); |
| 183 |
|
} else if (argv[an][0] == '+') { |
| 184 |
|
input[nfile].flags |= HASMAX; |
| 185 |
< |
setcolr(input[nfile].thmax, |
| 173 |
< |
atof(argv[an+1]), |
| 174 |
< |
atof(argv[an+1]), |
| 175 |
< |
atof(argv[an+1])); |
| 185 |
> |
input[nfile].thmax = atof(argv[an+1]); |
| 186 |
|
} else |
| 187 |
|
goto userr; |
| 188 |
|
an++; |
| 217 |
|
if (autolabel && thislabel == NULL) |
| 218 |
|
thislabel = argv[an]; |
| 219 |
|
if (!strcmp(argv[an], "-")) { |
| 220 |
< |
input[nfile].name = "<stdin>"; |
| 220 |
> |
input[nfile].name = StandardInput; |
| 221 |
|
input[nfile].fp = stdin; |
| 222 |
|
} else { |
| 223 |
|
if (argv[an][0] == '!') { |
| 234 |
|
} |
| 235 |
|
an++; |
| 236 |
|
/* get header */ |
| 237 |
< |
printf("%s:\n", input[nfile].name); |
| 238 |
< |
getheader(input[nfile].fp, tabputs, NULL); |
| 237 |
> |
if (echoheader) |
| 238 |
> |
printf("%s:\n", input[nfile].name); |
| 239 |
> |
this_expos = 1; |
| 240 |
> |
getheader(input[nfile].fp, headline, NULL); |
| 241 |
> |
if (!nfile) |
| 242 |
> |
common_expos = this_expos; |
| 243 |
> |
else if (common_expos > 0 && |
| 244 |
> |
fabs(this_expos/common_expos - 1.) > 0.02) |
| 245 |
> |
common_expos = 0; |
| 246 |
|
if (wrongformat) { |
| 247 |
|
fprintf(stderr, "%s: incompatible input format\n", |
| 248 |
|
input[nfile].name); |
| 255 |
|
input[nfile].name); |
| 256 |
|
quit(1); |
| 257 |
|
} |
| 258 |
< |
if (ncolumns > 0) { |
| 259 |
< |
if (curcol >= ncolumns) { |
| 258 |
> |
if (ncolumns) { |
| 259 |
> |
if (curcol >= abs(ncolumns)) { |
| 260 |
|
cury = ymax + spacing; |
| 261 |
|
curx = x0; |
| 262 |
|
curcol = 0; |
| 309 |
|
ysiz = ymax; |
| 310 |
|
else if (ysiz > ymax) |
| 311 |
|
ymax = ysiz; |
| 312 |
+ |
if (ncolumns < 0) { /* reverse rows if requested */ |
| 313 |
+ |
int i = nfile; |
| 314 |
+ |
while (i--) |
| 315 |
+ |
input[i].yloc = ymax - input[i].yres - input[i].yloc; |
| 316 |
+ |
} |
| 317 |
|
/* add new header info. */ |
| 318 |
|
printargs(argc, argv, stdout); |
| 319 |
+ |
if (common_expos > 0) /* print exposure if shared */ |
| 320 |
+ |
fputexpos(common_expos, stdout); |
| 321 |
|
if (strcmp(ourfmt, PICFMT)) |
| 322 |
|
fputformat(ourfmt, stdout); /* print format if known */ |
| 323 |
|
putchar('\n'); |
| 328 |
|
quit(0); |
| 329 |
|
userr: |
| 330 |
|
fprintf(stderr, |
| 331 |
< |
"Usage: %s [-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ", |
| 331 |
> |
"Usage: %s [-h][-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ", |
| 332 |
|
progname); |
| 333 |
|
fprintf(stderr, "[-t min1][+t max1][-l lab][=SS] pic1 x1 y1 ..\n"); |
| 334 |
|
quit(1); |
| 339 |
|
labelerr: |
| 340 |
|
fprintf(stderr, "%s: error opening label\n", progname); |
| 341 |
|
quit(1); |
| 342 |
+ |
return 1; /* pro forma return */ |
| 343 |
|
} |
| 344 |
|
|
| 345 |
|
|
| 346 |
< |
compos() /* composite pictures */ |
| 346 |
> |
static void |
| 347 |
> |
compos(void) /* composite pictures */ |
| 348 |
|
{ |
| 349 |
|
COLR *scanin, *scanout; |
| 350 |
|
int y; |
| 398 |
|
quit(1); |
| 399 |
|
} |
| 400 |
|
} |
| 401 |
+ |
/* read remainders from streams */ |
| 402 |
+ |
for (i = 0; i < nfile; i++) |
| 403 |
+ |
if (input[i].name[0] == '<') |
| 404 |
+ |
while (getc(input[i].fp) != EOF) |
| 405 |
+ |
; |
| 406 |
|
return; |
| 407 |
|
memerr: |
| 408 |
|
perror(progname); |
| 410 |
|
} |
| 411 |
|
|
| 412 |
|
|
| 413 |
< |
int |
| 414 |
< |
cmpcolr(c1, c2) /* compare two colr's (improvisation) */ |
| 415 |
< |
register COLR c1, c2; |
| 413 |
> |
static int |
| 414 |
> |
cmpcolr( /* compare COLR to luminance */ |
| 415 |
> |
register COLR c1, |
| 416 |
> |
double lv2 |
| 417 |
> |
) |
| 418 |
|
{ |
| 419 |
< |
register int i, j; |
| 420 |
< |
|
| 421 |
< |
j = 4; /* check exponents first! */ |
| 422 |
< |
while (j--) |
| 423 |
< |
if (i = c1[j] - c2[j]) |
| 424 |
< |
return(i); |
| 419 |
> |
double lv1 = .0; |
| 420 |
> |
|
| 421 |
> |
if (c1[EXP]) |
| 422 |
> |
lv1 = ldexp((double)normbright(c1), (int)c1[EXP]-(COLXS+8)); |
| 423 |
> |
if (lv1 < lv2) return(-1); |
| 424 |
> |
if (lv1 > lv2) return(1); |
| 425 |
|
return(0); |
| 426 |
|
} |
| 427 |
|
|
| 428 |
|
|
| 429 |
< |
FILE * |
| 430 |
< |
lblopen(s, xp, yp) /* open pipe to label generator */ |
| 431 |
< |
char *s; |
| 432 |
< |
int *xp, *yp; |
| 429 |
> |
static FILE * |
| 430 |
> |
lblopen( /* open pipe to label generator */ |
| 431 |
> |
char *s, |
| 432 |
> |
int *xp, |
| 433 |
> |
int *yp |
| 434 |
> |
) |
| 435 |
|
{ |
| 436 |
< |
char com[128]; |
| 436 |
> |
char com[PATH_MAX]; |
| 437 |
|
FILE *fp; |
| 438 |
|
|
| 439 |
|
sprintf(com, "psign -s -.15 -a 2 -x %d -y %d '%.90s'", *xp, *yp, s); |