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

Comparing ray/src/px/ra_pict.c (file contents):
Revision 2.2 by greg, Thu Nov 21 11:34:10 1991 UTC vs.
Revision 2.10 by schorsch, Sun Mar 28 20:33:14 2004 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ Auckuni";
2 > static const char       RCSid[] = "$Id$";
3   #endif
4 <
5 < /*
6 < *      rad2pict -
7 < *              Convert an Radiance image to APPLE pict format.
4 > /*              Convert an Radiance image to APPLE pict format.
5   *
6   *                      Orginally Iris to PICT by       Paul Haeberli - 1990
7   *                      Hacked into Rad to PICT by Russell Street 1990
# Line 20 | Line 17 | static char SCCSid[] = "$SunId$ Auckuni";
17   */
18  
19   #include <stdio.h>
20 < #include <stdlib.h>
20 > #include <math.h>
21 > #include  <time.h>
22  
23 + #include "platform.h"
24   #include "pict.h"
25   #include "color.h"
26   #include "resolu.h"
# Line 29 | Line 28 | static char SCCSid[] = "$SunId$ Auckuni";
28   int     outbytes;                   /* This had better be 32 bits! */
29   char    *progname;
30   int     verbose = 0;
31 < float   gamma = 2.0;
31 > float   gamcor = 2.0;
32   int     bradj = 0;
33  
34 <        /* First some utility routines */
34 > static void putrect(int xorg, int yorg, int xsize, int ysize);
35 > static void putfprect(int xorg, int yorg, int xsize, int ysize);
36 > static void putalong(long l);
37 > static void putashort(short s);
38 > static void putbyte(int b);
39 > static void putbytes(unsigned char *buf, int n );
40 > static void putpict(int xsize, int ysize);
41 > static void getrow(FILE *in, char *cbuf, int xsize);
42 > static int packbits(unsigned char *ibits, unsigned char *pbits, int nbits);
43 > static void usage(void);
44  
45 < putrect(xorg,yorg,xsize,ysize)
46 < int xorg, yorg, xsize, ysize;
45 >
46 >        /* First some utility routines */
47 > static void
48 > putrect(
49 >        int xorg,
50 >        int yorg,
51 >        int xsize,
52 >        int ysize
53 > )
54   {
55      putashort(yorg);
56      putashort(xorg);
# Line 43 | Line 58 | int xorg, yorg, xsize, ysize;
58      putashort(xsize);
59   }
60  
61 < putfprect(xorg,yorg,xsize,ysize)
62 < int xorg, yorg, xsize, ysize;
61 > static void
62 > putfprect(
63 >        int xorg,
64 >        int yorg,
65 >        int xsize,
66 >        int ysize
67 > )
68   {
69      putalong(yorg<<16);
70      putalong(xorg<<16);
# Line 52 | Line 72 | int xorg, yorg, xsize, ysize;
72      putalong(xsize<<16);
73   }
74  
75 < putalong(l)
76 < long l;
75 > static void
76 > putalong(
77 >        long l
78 > )
79   {
80      putbyte((l>>24)&0xff);
81      putbyte((l>>16)&0xff);
# Line 61 | Line 83 | long l;
83      putbyte((l>>0)&0xff);
84   }
85  
86 < putashort(s)
87 < short s;
86 > static void
87 > putashort(
88 >        short s
89 > )
90   {
91      putbyte((s>>8)&0xff);
92      putbyte((s>>0)&0xff);
93   }
94  
95 < putbyte(b)
96 < int b;
95 > static void
96 > putbyte(
97 >        int b
98 > )
99   {
100      if (putc(b,stdout) == EOF && ferror(stdout)) {
101          fprintf(stderr,"%s: error on write\n", progname);
# Line 78 | Line 104 | int b;
104      outbytes++;
105   }
106  
107 < putbytes(buf,n)
108 < unsigned char *buf;
109 < int n;
107 > static void
108 > putbytes(
109 >        unsigned char *buf,
110 >        int n
111 > )
112   {
113      if(!fwrite(buf,n,1,stdout)) {
114          fprintf(stderr,"%s: error on write\n", progname);
# Line 89 | Line 117 | int n;
117      outbytes+=n;
118   }
119  
120 < main(argc,argv)
121 < int argc;
122 < char **argv;
120 > int
121 > main(
122 >        int argc,
123 >        char **argv
124 > )
125   {
126      int xsize, ysize;
127      int i, picsize;
128      int ssizepos, lsizepos;
129 <
129 >        SET_DEFAULT_BINARY();
130 >    SET_FILE_BINARY(stdin);
131 >    SET_FILE_BINARY(stdout);
132      progname = argv[0];
133  
134      for (i = 1; i < argc ; i++)
135 <        if (argv[i][0] ==  '-')
135 >        if (argv[i][0] ==  '-')
136              switch (argv[i][1]) {
137 <                case 'g':       gamma = atof(argv[++i]);
137 >                case 'g':       gamcor = atof(argv[++i]);
138                                  break;
139  
140                  case 'e':       if (argv[i+1][0] != '+' && argv[i+1][0] != '-')
# Line 122 | Line 154 | char **argv;
154                                  goto outofparse;
155                                  break;              /* NOTREACHED */
156  
157 <                otherwise:      usage();
157 >                default:
158 >                                usage();
159                                  break;
160                   }
161          else
# Line 147 | Line 180 | outofparse:
180          
181   #ifdef DEBUG
182          fprintf(stderr, "Input file: %s\n", i <= argc - 1 ? argv[i] : "stdin");
183 <        fprintf(stderr, "Outut file: %s\n", i <= argc - 2 ? argv[i+1] : "stdout" );
184 <        fprintf(stderr, "Gamma: %f\n", gamma);
183 >        fprintf(stderr, "Outut file: %s\n", i <= argc - 2 ? argv[i+1] : "stdout" );
184 >        fprintf(stderr, "Gamma: %f\n", gamcor);
185          fprintf(stderr, "Brightness adjust: %d\n", bradj);
186 <        fprintf(stderr, "Verbose: %s\n", verbose ? "on" : "off");
186 >        fprintf(stderr, "Verbose: %s\n", verbose ? "on" : "off");
187   #endif
188  
189  
190 <             /* OK. Now we read the size of the Radiance picture */
190 >             /* OK. Now we read the size of the Radiance picture */
191      if (checkheader(stdin, COLRFMT, NULL) < 0 ||
192 <            fgetresolu(&xsize, &ysize, stdin) < 0 /* != (YMAJOR|YDECR) */ ) {
193 <        fprintf(stderr, "%s: not a radiance picture\n", progname);
194 <        exit(1);
192 >            fgetresolu(&xsize, &ysize, stdin) < 0 /* != (YMAJOR|YDECR) */ ) {
193 >        fprintf(stderr, "%s: not a radiance picture\n", progname);
194 >        exit(1);
195          }
196  
197              /* Set the gamma correction */
198  
199 <    setcolrgam(gamma);
199 >    setcolrgam(gamcor);
200  
201      for(i=0; i<HEADER_SIZE; i++)
202          putbyte(0);
203  
204      ssizepos = outbytes;
205 <    putashort(0);               /* low 16 bits of file size less HEADER_SIZE */
205 >    putashort(0);               /* low 16 bits of file size less HEADER_SIZE */
206      putrect(0,0,xsize,ysize);   /* bounding box of picture */
207      putashort(PICT_picVersion);
208      putashort(0x02ff);          /* version 2 pict */
209      putashort(PICT_reservedHeader);     /* reserved header opcode */
210  
211      lsizepos = outbytes;
212 <    putalong(0);                /* full size of the file */
213 <    putfprect(0,0,xsize,ysize); /* fixed point bounding box of picture */
214 <    putalong(0);                /* reserved */
212 >    putalong(0);                /* full size of the file */
213 >    putfprect(0,0,xsize,ysize); /* fixed point bounding box of picture */
214 >    putalong(0);                /* reserved */
215  
216 <    putashort(PICT_clipRgn);    /* the clip region */
216 >    putashort(PICT_clipRgn);    /* the clip region */
217      putashort(10);
218      putrect(0,0,xsize,ysize);
219  
220      if (verbose)
221          fprintf(stderr, "%s: The picture is %d by %d, with a gamma of %f\n",
222 <            progname, xsize, ysize, gamma);
222 >            progname, xsize, ysize, gamcor);
223  
224  
225      putpict(xsize, ysize);      /* Here is where all the work is done */
# Line 206 | Line 239 | outofparse:
239      return 0;       /* lint fodder */
240   }
241  
242 < putpict(xsize, ysize)
243 < int xsize;
244 < int ysize;
242 > static void
243 > putpict(
244 >        int xsize,
245 >        int ysize
246 > )
247   {
248      int     y;
249      int     nbytes, rowbytes;
250      char    *cbuf, *pbuf;
251  
252 <    cbuf = malloc(4 * xsize);
252 >    cbuf = (char *)malloc(4 * xsize);
253  
254      if (cbuf == NULL) {
255          fprintf(stderr, "%s: not enough memory\n", progname);
256          exit(1);
257          }
258  
259 <    pbuf = malloc(4 * xsize);
259 >    pbuf = (char *)malloc(4 * xsize);
260  
261      if (pbuf == NULL) {
262          fprintf(stderr, "%s: not enough memory\n", progname);
# Line 235 | Line 270 | int ysize;
270  
271      if(rowbytes&1)
272          rowbytes++;
273 <    putashort(rowbytes|0x8000); /* rowbytes */
273 >    putashort(rowbytes|0x8000); /* rowbytes */
274      putrect(0,0,xsize,ysize);   /* bounds */
275      putashort(0);               /* version */
276  
# Line 279 | Line 314 | int ysize;
314      free(pbuf);
315   }
316  
317 < int getrow(in, cbuf, xsize)
318 < FILE *in;
319 < char *cbuf;
320 < int xsize;
317 > static void
318 > getrow(
319 >        FILE *in,
320 >        char *cbuf,
321 >        int xsize
322 > )
323   {
324 <    extern char *tempbuffer();          /* defined in color.c */
324 >    extern char *tempbuffer();          /* defined in color.c */
325      COLR    *scanin = NULL;
326      int     x;
327  
# Line 294 | Line 331 | int xsize;
331      }
332  
333      if (freadcolrs(scanin, xsize, in) < 0) {
334 <        fprintf(stderr, "%s: read error\n", progname);
335 <        exit(1);
336 <        }
334 >        fprintf(stderr, "%s: read error\n", progname);
335 >        exit(1);
336 >        }
337  
338      if (bradj)      /* Adjust exposure level */
339          shiftcolrs(scanin, xsize, bradj);
# Line 313 | Line 350 | int xsize;
350   }
351  
352  
353 < packbits(ibits,pbits,nbits)
354 < unsigned char *ibits, *pbits;
355 < int nbits;
353 > static int
354 > packbits(
355 >        unsigned char *ibits,
356 >        unsigned char *pbits,
357 >        int nbits
358 > )
359   {
320    int bytes;                      /* UNUSED */
360      unsigned char *sptr;
361      unsigned char *ibitsend;
362      unsigned char *optr = pbits;
# Line 330 | Line 369 | int nbits;
369          ibits += 2;
370          while((ibits<ibitsend)&&((ibits[-2]!=ibits[-1])||(ibits[-1]!=ibits[0])))
371              ibits++;
372 <        if(ibits != ibitsend) {
372 >        if(ibits != ibitsend) {
373              ibits -= 2;
374          }
375          count = ibits-sptr;
# Line 358 | Line 397 | int nbits;
397      return optr-pbits;
398   }
399  
400 < usage()
400 > static void
401 > usage(void)
402   {
403      fprintf(stderr, "Usage: %s [-v] [-g gamma] [infile [outfile]]\n",
404          progname);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines