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

Comparing ray/src/px/macbethcal.c (file contents):
Revision 2.15 by greg, Thu Feb 6 11:36:53 1997 UTC vs.
Revision 2.19 by schorsch, Mon Jul 21 22:30:18 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Calibrate a scanned MacBeth Color Checker Chart
6   *
# Line 15 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include <stdio.h>
14   #include <math.h>
15 < #ifdef MSDOS
16 < #include <fcntl.h>
17 < #endif
15 > #include <time.h>
16 >
17 > #include "platform.h"
18   #include "color.h"
19   #include "resolu.h"
20   #include "pmap.h"
# Line 100 | Line 97 | short  mbneu[NMBNEU] = {Black,Neutral35,Neutral5,Neutra
97   #define  RG_ORIG        02      /* original color region */
98   #define  RG_CORR        04      /* corrected color region */
99  
100 + #ifndef  DISPCOM
101 + #define  DISPCOM        "ximage -op %s"
102 + #endif
103 +
104   int     scanning = 1;           /* scanned input (or recorded output)? */
105   double  irrad = 1.0;            /* irradiance multiplication factor */
106   int     rawmap = 0;             /* put out raw color mapping? */
# Line 121 | Line 122 | WARP3D *wcor = NULL;           /* color space warp */
122   FILE    *debugfp = NULL;        /* debug output picture */
123   char    *progname;
124  
124 extern char     *malloc();
125  
126
126   main(argc, argv)
127   int     argc;
128   char    **argv;
# Line 141 | Line 140 | char   **argv;
140                                  perror(argv[i]);
141                                  exit(1);
142                          }
143 < #ifdef MSDOS
145 <                        setmode(fileno(debugfp), O_BINARY);
146 < #endif
143 >                        SET_FILE_BINARY(debugfp);
144                          newheader("RADIANCE", debugfp);         /* start */
145                          printargs(argc, argv, debugfp);         /* header */
146                          break;
# Line 160 | Line 157 | char   **argv;
157                          bounds[3][1] = atoi(argv[++i]);
158                          scanning = 2;
159                          break;
160 +                case 'P':                               /* pick position */
161 +                        scanning = 3;
162 +                        break;
163                  case 'i':                               /* irradiance factor */
164                          i++;
165                          if (badarg(argc-i, argv+i, "f"))
# Line 185 | Line 185 | char   **argv;
185                  exit(1);
186          }
187          if (scanning) {                 /* load input picture header */
188 < #ifdef MSDOS
189 <                setmode(fileno(stdin), O_BINARY);
190 < #endif
188 >                SET_FILE_BINARY(stdin);
189                  if (checkheader(stdin, COLRFMT, NULL) < 0 ||
190                                  fgetresolu(&xmax, &ymax, stdin) < 0) {
191                          fprintf(stderr, "%s: bad input picture\n", progname);
192                          exit(1);
193                  }
194 +                if (scanning == 3) {
195 +                        if (i >= argc)
196 +                                goto userr;
197 +                        pickchartpos(argv[i]);
198 +                        scanning = 2;
199 +                }
200          } else {                        /* else set default xmax and ymax */
201                  xmax = 512;
202                  ymax = 2*512/3;
# Line 237 | Line 241 | char   **argv;
241                  printf("}\n");
242                  putmapping();                   /* put out color mapping */
243          }
244 <        if (debugfp != NULL)            /* put out debug picture */
244 >        if (debugfp != NULL) {          /* put out debug picture */
245                  if (scanning)
246                          picdebug();
247                  else
248                          clrdebug();
249 +        }
250          exit(0);
251   userr:
252          fprintf(stderr,
253 < "Usage: %s [-d dbg.pic][-p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n",
253 > "Usage: %s [-d dbg.pic][-P | -p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n",
254                          progname);
255          fprintf(stderr, "   or: %s [-d dbg.pic][-i irrad][-m] -c [xyY.dat [output.{cal|cwp}]]\n",
256                          progname);
# Line 349 | Line 354 | getpicture()                           /* load in picture colors */
354                  scalecolor(inpRGB[i], d);
355                  inpflags |= 1L<<i;
356          }
357 <        free((char *)scanln);
357 >        free((void *)scanln);
358   }
359  
360  
# Line 699 | Line 704 | picdebug()                     /* put out debugging picture */
704          }
705                                                  /* clean up */
706          fclose(debugfp);
707 <        free((char *)scan);
707 >        free((void *)scan);
708   }
709  
710  
# Line 769 | Line 774 | clrdebug()                     /* put out debug picture from color input
774          }
775                                                  /* clean up */
776          fclose(debugfp);
777 <        free((char *)scan);
777 >        free((void *)scan);
778 > }
779 >
780 >
781 > getpos(name, bnds, fp)          /* get boundary position */
782 > char    *name;
783 > int     bnds[2];
784 > FILE    *fp;
785 > {
786 >        char    buf[64];
787 >
788 >        fprintf(stderr, "\tSelect corner: %s\n", name);
789 >        if (fgets(buf, sizeof(buf), fp) == NULL ||
790 >                        sscanf(buf, "%d %d", &bnds[0], &bnds[1]) != 2) {
791 >                fprintf(stderr, "%s: read error from display process\n",
792 >                                progname);
793 >                exit(1);
794 >        }
795 > }
796 >
797 >
798 > pickchartpos(pfn)               /* display picture and pick chart location */
799 > char    *pfn;
800 > {
801 >        char    combuf[512];
802 >        FILE    *pfp;
803 >
804 >        sprintf(combuf, DISPCOM, pfn);
805 >        if ((pfp = popen(combuf, "r")) == NULL) {
806 >                perror(combuf);
807 >                exit(1);
808 >        }
809 >        fputs("Use middle mouse button to select chart corners:\n", stderr);
810 >        getpos("upper left (dark skin)", bounds[0], pfp);
811 >        getpos("upper right (bluish green)", bounds[1], pfp);
812 >        getpos("lower left (white)", bounds[2], pfp);
813 >        getpos("lower right (black)", bounds[3], pfp);
814 >        fputs("Got it -- quit display program.\n", stderr);
815 >        pclose(pfp);
816   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines