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.14 by greg, Tue Feb 4 16:04:23 1997 UTC vs.
Revision 2.21 by schorsch, Mon Oct 27 10:24:51 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 "rtprocess.h"
19   #include "color.h"
20   #include "resolu.h"
21   #include "pmap.h"
# Line 100 | Line 98 | short  mbneu[NMBNEU] = {Black,Neutral35,Neutral5,Neutra
98   #define  RG_ORIG        02      /* original color region */
99   #define  RG_CORR        04      /* corrected color region */
100  
101 + #ifndef  DISPCOM
102 + #define  DISPCOM        "ximage -op %s"
103 + #endif
104 +
105   int     scanning = 1;           /* scanned input (or recorded output)? */
106   double  irrad = 1.0;            /* irradiance multiplication factor */
107   int     rawmap = 0;             /* put out raw color mapping? */
# Line 121 | Line 123 | WARP3D *wcor = NULL;           /* color space warp */
123   FILE    *debugfp = NULL;        /* debug output picture */
124   char    *progname;
125  
124 extern char     *malloc();
126  
126
127   main(argc, argv)
128   int     argc;
129   char    **argv;
# Line 141 | Line 141 | char   **argv;
141                                  perror(argv[i]);
142                                  exit(1);
143                          }
144 < #ifdef MSDOS
145 <                        setmode(fileno(debugfp), O_BINARY);
146 < #endif
144 >                        SET_FILE_BINARY(debugfp);
145                          newheader("RADIANCE", debugfp);         /* start */
146                          printargs(argc, argv, debugfp);         /* header */
147                          break;
# Line 160 | Line 158 | char   **argv;
158                          bounds[3][1] = atoi(argv[++i]);
159                          scanning = 2;
160                          break;
161 +                case 'P':                               /* pick position */
162 +                        scanning = 3;
163 +                        break;
164                  case 'i':                               /* irradiance factor */
165                          i++;
166                          if (badarg(argc-i, argv+i, "f"))
# Line 185 | Line 186 | char   **argv;
186                  exit(1);
187          }
188          if (scanning) {                 /* load input picture header */
189 < #ifdef MSDOS
189 <                setmode(fileno(stdin), O_BINARY);
190 < #endif
189 >                SET_FILE_BINARY(stdin);
190                  if (checkheader(stdin, COLRFMT, NULL) < 0 ||
191                                  fgetresolu(&xmax, &ymax, stdin) < 0) {
192                          fprintf(stderr, "%s: bad input picture\n", progname);
193                          exit(1);
194                  }
195 +                if (scanning == 3) {
196 +                        if (i >= argc)
197 +                                goto userr;
198 +                        pickchartpos(argv[i]);
199 +                        scanning = 2;
200 +                }
201          } else {                        /* else set default xmax and ymax */
202                  xmax = 512;
203                  ymax = 2*512/3;
# Line 214 | Line 219 | char   **argv;
219  
220                  printf("# Color correspondence produced by:\n#\t\t");
221                  printargs(argc, argv, stdout);
222 <                printf("#\tUsage: pcwarp -m %s uncorrected.pic > corrected.pic\n",
222 >                printf("#\tUsage: pcwarp %s uncorrected.pic > corrected.pic\n",
223                                  i+1 < argc ? argv[i+1] : "{this_file}");
224                  printf("#\t   Or: pcond [options] -m %s orig.pic > output.pic\n",
225                                  i+1 < argc ? argv[i+1] : "{this_file}");
# Line 237 | Line 242 | char   **argv;
242                  printf("}\n");
243                  putmapping();                   /* put out color mapping */
244          }
245 <        if (debugfp != NULL)            /* put out debug picture */
245 >        if (debugfp != NULL) {          /* put out debug picture */
246                  if (scanning)
247                          picdebug();
248                  else
249                          clrdebug();
250 +        }
251          exit(0);
252   userr:
253          fprintf(stderr,
254 < "Usage: %s [-d dbg.pic][-p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n",
254 > "Usage: %s [-d dbg.pic][-P | -p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n",
255                          progname);
256          fprintf(stderr, "   or: %s [-d dbg.pic][-i irrad][-m] -c [xyY.dat [output.{cal|cwp}]]\n",
257                          progname);
# Line 349 | Line 355 | getpicture()                           /* load in picture colors */
355                  scalecolor(inpRGB[i], d);
356                  inpflags |= 1L<<i;
357          }
358 <        free((char *)scanln);
358 >        free((void *)scanln);
359   }
360  
361  
# Line 361 | Line 367 | getcolors()                    /* get xyY colors from standard input */
367          float   xyYin[3];
368  
369          while (fgetval(stdin, 'i', &n) == 1) {          /* read colors */
370 <                if (n < 0 | n > 24 ||
370 >                if ((n < 0) | (n > 24) ||
371                                  fgetval(stdin, 'f', &xyYin[0]) != 1 ||
372                                  fgetval(stdin, 'f', &xyYin[1]) != 1 ||
373                                  fgetval(stdin, 'f', &xyYin[2]) != 1 ||
374 <                                xyYin[0] < 0. | xyYin[1] < 0. ||
374 >                                (xyYin[0] < 0.) | (xyYin[1] < 0.) ||
375                                  xyYin[0] + xyYin[1] > 1.) {
376                          fprintf(stderr, "%s: bad color input data\n",
377                                          progname);
# Line 699 | Line 705 | picdebug()                     /* put out debugging picture */
705          }
706                                                  /* clean up */
707          fclose(debugfp);
708 <        free((char *)scan);
708 >        free((void *)scan);
709   }
710  
711  
# Line 769 | Line 775 | clrdebug()                     /* put out debug picture from color input
775          }
776                                                  /* clean up */
777          fclose(debugfp);
778 <        free((char *)scan);
778 >        free((void *)scan);
779 > }
780 >
781 >
782 > getpos(name, bnds, fp)          /* get boundary position */
783 > char    *name;
784 > int     bnds[2];
785 > FILE    *fp;
786 > {
787 >        char    buf[64];
788 >
789 >        fprintf(stderr, "\tSelect corner: %s\n", name);
790 >        if (fgets(buf, sizeof(buf), fp) == NULL ||
791 >                        sscanf(buf, "%d %d", &bnds[0], &bnds[1]) != 2) {
792 >                fprintf(stderr, "%s: read error from display process\n",
793 >                                progname);
794 >                exit(1);
795 >        }
796 > }
797 >
798 >
799 > pickchartpos(pfn)               /* display picture and pick chart location */
800 > char    *pfn;
801 > {
802 >        char    combuf[512];
803 >        FILE    *pfp;
804 >
805 >        sprintf(combuf, DISPCOM, pfn);
806 >        if ((pfp = popen(combuf, "r")) == NULL) {
807 >                perror(combuf);
808 >                exit(1);
809 >        }
810 >        fputs("Use middle mouse button to select chart corners:\n", stderr);
811 >        getpos("upper left (dark skin)", bounds[0], pfp);
812 >        getpos("upper right (bluish green)", bounds[1], pfp);
813 >        getpos("lower left (white)", bounds[2], pfp);
814 >        getpos("lower right (black)", bounds[3], pfp);
815 >        fputs("Got it -- quit display program.\n", stderr);
816 >        pclose(pfp);
817   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines