ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pcompos.c
(Generate patch)

Comparing ray/src/px/pcompos.c (file contents):
Revision 2.29 by schorsch, Sun Mar 28 20:33:14 2004 UTC vs.
Revision 2.42 by greg, Sat Jun 7 05:09:46 2025 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *     6/30/87
8   */
9  
10 #include  <stdio.h>
10   #include  <math.h>
12 #include  <time.h>
13 #include  <string.h>
11  
12   #include "copyright.h"
13  
14 + #include  "rtio.h"
15   #include  "platform.h"
18 #include  "rtprocess.h"
16   #include  "rterror.h"
17   #include  "color.h"
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  
# Line 44 | Line 46 | 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 + double  this_expos;
66  
67 < static gethfunc tabputs;
67 > static gethfunc headline;
68   static void compos(void);
69 < static int cmpcolr(COLR  c1, COLR  c2);
69 > static int cmpcolr(COLR  c1, double lv2);
70   static FILE * lblopen(char  *s, int  *xp, int  *yp);
71  
72  
73  
74   static int
75 < tabputs(                        /* print line preceded by a tab */
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);
# Line 104 | Line 109 | main(
109          int  xsgn, ysgn;
110          char  *thislabel;
111          int  an;
112 +
113          SET_DEFAULT_BINARY();
114          SET_FILE_BINARY(stdin);
115          SET_FILE_BINARY(stdout);
110        progname = argv[0];
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;
# Line 169 | Line 179 | dofiles:
179                                  checkthresh = 1;
180                                  if (argv[an][0] == '-') {
181                                          input[nfile].flags |= HASMIN;
182 <                                        setcolr(input[nfile].thmin,
173 <                                                        atof(argv[an+1]),
174 <                                                        atof(argv[an+1]),
175 <                                                        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,
179 <                                                        atof(argv[an+1]),
180 <                                                        atof(argv[an+1]),
181 <                                                        atof(argv[an+1]));
185 >                                        input[nfile].thmax = atof(argv[an+1]);
186                                  } else
187                                          goto userr;
188                                  an++;
# Line 230 | Line 234 | getfile:
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);
# Line 244 | Line 255 | getfile:
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;
# Line 298 | Line 309 | getfile:
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');
# Line 310 | Line 328 | getfile:
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);
# Line 393 | Line 411 | memerr:
411  
412  
413   static int
414 < cmpcolr(                        /* compare two colr's (improvisation) */
414 > cmpcolr(                        /* compare COLR to luminance */
415          register COLR  c1,
416 <        register COLR  c2
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines