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.1 by greg, Tue Nov 12 16:05:41 1991 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines