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

Comparing ray/src/px/ra_tiff.c (file contents):
Revision 1.4 by greg, Thu Aug 15 14:48:55 1991 UTC vs.
Revision 2.6 by greg, Sun Feb 27 10:17:27 1994 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include  <stdio.h>
12  
13 + #include  <math.h>
14 +
15   #include  "tiffio.h"
16  
17   #include  "color.h"
18  
19 < extern double  atof();
19 > #include  "resolu.h"
20  
21 +
22   extern char  *malloc(), *realloc();
23  
24   int  lzcomp = 0;                        /* use Lempel-Ziv compression? */
25  
26 < double  gamma = 2.2;                    /* gamma correction */
26 > int  greyscale = 0;                     /* produce greyscale image? */
27  
28 + double  gamcor = 2.2;                   /* gamma correction */
29 +
30   int  bradj = 0;                         /* brightness adjustment */
31  
32   char  *progname;
# Line 40 | Line 45 | char  *argv[];
45                  if (argv[i][0] == '-')
46                          switch (argv[i][1]) {
47                          case 'g':
48 <                                gamma = atof(argv[++i]);
48 >                                gamcor = atof(argv[++i]);
49                                  break;
50                          case 'z':
51                                  lzcomp = !lzcomp;
52                                  break;
53 +                        case 'b':
54 +                                greyscale = !greyscale;
55 +                                break;
56                          case 'e':
57                                  if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
58                                          goto userr;
# Line 61 | Line 69 | char  *argv[];
69                  else
70                          break;
71   doneopts:
72 <        setcolrgam(gamma);
72 >        setcolrgam(gamcor);
73  
74          if (reverse)
75                  if (i != argc-2 && i != argc-1)
# Line 77 | Line 85 | doneopts:
85          exit(0);
86   userr:
87          fprintf(stderr,
88 <                "Usage: %s [-r][-z][-e +/-stops][-g gamma] input output\n",
88 >        "Usage: %s [-r][-b][-z][-e +/-stops][-g gamma] input output\n",
89                          progname);
90          exit(1);
91   }
# Line 99 | Line 107 | char   *inpf, *outf;
107   {
108          unsigned long   xmax, ymax;
109          TIFF    *tif;
110 <        unsigned short  pconfig;
110 >        unsigned short  pconfig, nsamps;
111          unsigned short  hi;
112          register BYTE   *scanin;
113          register COLR   *scanout;
# Line 108 | Line 116 | char   *inpf, *outf;
116                                          /* open/check  TIFF file */
117          if ((tif = TIFFOpen(inpf, "r")) == NULL)
118                  quiterr("cannot open TIFF input");
119 <        if (!TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &hi) || hi != 3)
119 >        if (!TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &nsamps) ||
120 >                        (nsamps != 1 && nsamps != 3))
121                  quiterr("unsupported samples per pixel");
122          if (!TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &hi) || hi != 8)
123                  quiterr("unsupported bits per sample");
124 <        if (TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &hi) && hi != 2)
124 >        if (TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &hi) &&
125 >                        hi != (nsamps==1 ? 1 : 2))
126                  quiterr("unsupported photometric interpretation");
127          if (!TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &pconfig) ||
128                          (pconfig != 1 && pconfig != 2))
# Line 129 | Line 139 | char   *inpf, *outf;
139          if (outf != NULL && strcmp(outf, "-") &&
140                          freopen(outf, "w", stdout) == NULL)
141                  quiterr("cannot open Radiance output file");
142 +        newheader("RADIANCE", stdout);
143          fputs(progname, stdout);
144          if (bradj)
145                  printf(" -e %+d", bradj);
146          fputs(" -r\n", stdout);
147          fputformat(COLRFMT, stdout);
148          putchar('\n');
149 <        fputresolu(YDECR|YMAJOR, xmax, ymax, stdout);
149 >        fprtresolu((int)xmax, (int)ymax, stdout);
150                                                  /* convert image */
151 +        if (nsamps == 1)
152 +                pconfig = 1;
153          for (y = 0; y < ymax; y++) {
154                  if (pconfig == 1) {
155                          if (TIFFReadScanline(tif, scanin, y, 0) < 0)
156                                  goto readerr;
157 <                        for (x = 0; x < xmax; x++) {
158 <                                scanout[x][RED] = scanin[3*x];
159 <                                scanout[x][GRN] = scanin[3*x+1];
160 <                                scanout[x][BLU] = scanin[3*x+2];
161 <                        }
157 >                        if (nsamps == 1)
158 >                                for (x = 0; x < xmax; x++)
159 >                                        scanout[x][RED] =
160 >                                        scanout[x][GRN] =
161 >                                        scanout[x][BLU] = scanin[x];
162 >                        else
163 >                                for (x = 0; x < xmax; x++) {
164 >                                        scanout[x][RED] = scanin[3*x];
165 >                                        scanout[x][GRN] = scanin[3*x+1];
166 >                                        scanout[x][BLU] = scanin[3*x+2];
167 >                                }
168                  } else {
169                          if (TIFFReadScanline(tif, scanin, y, 0) < 0)
170                                  goto readerr;
# Line 189 | Line 208 | char   *inpf, *outf;
208          if (strcmp(inpf, "-") && freopen(inpf, "r", stdin) == NULL)
209                  quiterr("cannot open Radiance input file");
210          if (checkheader(stdin, COLRFMT, NULL) < 0 ||
211 <                        fgetresolu(&xmax, &ymax, stdin) != (YDECR|YMAJOR))
211 >                        fgetresolu(&xmax, &ymax, stdin) < 0)
212                  quiterr("bad Radiance picture");
213                                                  /* open TIFF file */
214          if ((tif = TIFFOpen(outf, "w")) == NULL)
215                  quiterr("cannot open TIFF output");
216          TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (unsigned long)xmax);
217          TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (unsigned long)ymax);
218 <        TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
218 >        TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, greyscale ? 1 : 3);
219          TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
220 <        TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, 2);
220 >        TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, greyscale ? 1 : 2);
221          TIFFSetField(tif, TIFFTAG_PLANARCONFIG, 1);
222          if (lzcomp)
223                  TIFFSetField(tif, TIFFTAG_COMPRESSION, (unsigned short)5);
# Line 213 | Line 232 | char   *inpf, *outf;
232                          quiterr("error reading Radiance picture");
233                  if (bradj)
234                          shiftcolrs(scanin, xmax, bradj);
235 <                colrs_gambs(scanin, xmax);
236 <                for (x = 0; x < xmax; x++) {
237 <                        scanout[3*x] = scanin[x][RED];
238 <                        scanout[3*x+1] = scanin[x][GRN];
239 <                        scanout[3*x+2] = scanin[x][BLU];
235 >                if (greyscale) {
236 >                        for (x = 0; x < xmax; x++)
237 >                                scanin[x][GRN] = normbright(scanin[x]);
238 >                        colrs_gambs(scanin, xmax);
239 >                        for (x = 0; x < xmax; x++)
240 >                                scanout[x] = scanin[x][GRN];
241 >                } else {
242 >                        colrs_gambs(scanin, xmax);
243 >                        for (x = 0; x < xmax; x++) {
244 >                                scanout[3*x] = scanin[x][RED];
245 >                                scanout[3*x+1] = scanin[x][GRN];
246 >                                scanout[3*x+2] = scanin[x][BLU];
247 >                        }
248                  }
249                  if (TIFFWriteScanline(tif, scanout, y, 0) < 0)
250                          quiterr("error writing TIFF output");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines