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.3 by greg, Thu Aug 15 14:04:21 1991 UTC vs.
Revision 2.2 by greg, Thu Dec 19 14:52:25 1991 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines