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 1.5 by greg, Thu Aug 15 15:47:35 1991 UTC

# Line 20 | Line 20 | extern char  *malloc(), *realloc();
20  
21   int  lzcomp = 0;                        /* use Lempel-Ziv compression? */
22  
23 + int  greyscale = 0;                     /* produce greyscale image? */
24 +
25   double  gamma = 2.2;                    /* gamma correction */
26  
27   int  bradj = 0;                         /* brightness adjustment */
# Line 45 | Line 47 | char  *argv[];
47                          case 'z':
48                                  lzcomp = !lzcomp;
49                                  break;
50 +                        case 'b':
51 +                                greyscale = !greyscale;
52 +                                break;
53                          case 'e':
54                                  if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
55                                          goto userr;
# Line 77 | Line 82 | doneopts:
82          exit(0);
83   userr:
84          fprintf(stderr,
85 <                "Usage: %s [-r][-z][-e +/-stops][-g gamma] input output\n",
85 >        "Usage: %s [-r][-b][-z][-e +/-stops][-g gamma] input output\n",
86                          progname);
87          exit(1);
88   }
# Line 99 | Line 104 | char   *inpf, *outf;
104   {
105          unsigned long   xmax, ymax;
106          TIFF    *tif;
107 <        unsigned short  pconfig;
107 >        unsigned short  pconfig, nsamps;
108          unsigned short  hi;
109          register BYTE   *scanin;
110          register COLR   *scanout;
# Line 108 | Line 113 | char   *inpf, *outf;
113                                          /* open/check  TIFF file */
114          if ((tif = TIFFOpen(inpf, "r")) == NULL)
115                  quiterr("cannot open TIFF input");
116 <        if (!TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &hi) || hi != 3)
116 >        if (!TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &nsamps) ||
117 >                        (nsamps != 1 && nsamps != 3))
118                  quiterr("unsupported samples per pixel");
119          if (!TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &hi) || hi != 8)
120                  quiterr("unsupported bits per sample");
121 <        if (TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &hi) && hi != 2)
121 >        if (TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &hi) &&
122 >                        hi != (nsamps==1 ? 1 : 2))
123                  quiterr("unsupported photometric interpretation");
124          if (!TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &pconfig) ||
125                          (pconfig != 1 && pconfig != 2))
# Line 137 | Line 144 | char   *inpf, *outf;
144          putchar('\n');
145          fputresolu(YDECR|YMAJOR, xmax, ymax, stdout);
146                                                  /* convert image */
147 +        if (nsamps == 1)
148 +                pconfig = 1;
149          for (y = 0; y < ymax; y++) {
150                  if (pconfig == 1) {
151                          if (TIFFReadScanline(tif, scanin, y, 0) < 0)
152                                  goto readerr;
153 <                        for (x = 0; x < xmax; x++) {
154 <                                scanout[x][RED] = scanin[3*x];
155 <                                scanout[x][GRN] = scanin[3*x+1];
156 <                                scanout[x][BLU] = scanin[3*x+2];
157 <                        }
153 >                        if (nsamps == 1)
154 >                                for (x = 0; x < xmax; x++)
155 >                                        scanout[x][RED] =
156 >                                        scanout[x][GRN] =
157 >                                        scanout[x][BLU] = scanin[x];
158 >                        else
159 >                                for (x = 0; x < xmax; x++) {
160 >                                        scanout[x][RED] = scanin[3*x];
161 >                                        scanout[x][GRN] = scanin[3*x+1];
162 >                                        scanout[x][BLU] = scanin[3*x+2];
163 >                                }
164                  } else {
165                          if (TIFFReadScanline(tif, scanin, y, 0) < 0)
166                                  goto readerr;
# Line 196 | Line 211 | char   *inpf, *outf;
211                  quiterr("cannot open TIFF output");
212          TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (unsigned long)xmax);
213          TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (unsigned long)ymax);
214 <        TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3);
214 >        TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, greyscale ? 1 : 3);
215          TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
216 <        TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, 2);
216 >        TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, greyscale ? 1 : 2);
217          TIFFSetField(tif, TIFFTAG_PLANARCONFIG, 1);
218          if (lzcomp)
219                  TIFFSetField(tif, TIFFTAG_COMPRESSION, (unsigned short)5);
# Line 213 | Line 228 | char   *inpf, *outf;
228                          quiterr("error reading Radiance picture");
229                  if (bradj)
230                          shiftcolrs(scanin, xmax, bradj);
231 <                colrs_gambs(scanin, xmax);
232 <                for (x = 0; x < xmax; x++) {
233 <                        scanout[3*x] = scanin[x][RED];
234 <                        scanout[3*x+1] = scanin[x][GRN];
235 <                        scanout[3*x+2] = scanin[x][BLU];
231 >                if (greyscale) {
232 >                        for (x = 0; x < xmax; x++)
233 >                                scanin[x][GRN] = normbright(scanin[x]);
234 >                        colrs_gambs(scanin, xmax);
235 >                        for (x = 0; x < xmax; x++)
236 >                                scanout[x] = scanin[x][GRN];
237 >                } else {
238 >                        colrs_gambs(scanin, xmax);
239 >                        for (x = 0; x < xmax; x++) {
240 >                                scanout[3*x] = scanin[x][RED];
241 >                                scanout[3*x+1] = scanin[x][GRN];
242 >                                scanout[3*x+2] = scanin[x][BLU];
243 >                        }
244                  }
245                  if (TIFFWriteScanline(tif, scanout, y, 0) < 0)
246                          quiterr("error writing TIFF output");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines