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

Comparing ray/src/px/ra_t16.c (file contents):
Revision 2.2 by greg, Thu Dec 19 14:52:20 1991 UTC vs.
Revision 2.9 by greg, Tue Mar 20 18:45:04 2018 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  ra_t16.c - program to convert between RADIANCE and
6   *              Targa 16, 24 and 32-bit images.
# Line 12 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   */
10  
11   #include  <stdio.h>
12 + #include  <string.h>
13 + #include  <time.h>
14 + #include  <math.h>
15  
16 + #include  "platform.h"
17 + #include  "rtio.h"
18 + #include  "rtmisc.h"
19   #include  "color.h"
17
20   #include  "resolu.h"
19
21   #include  "random.h"
21
22   #include  "targa.h"
23  
24   #define  goodpic(h)     (((h)->dataType==IM_RGB || (h)->dataType==IM_CRGB) \
# Line 26 | Line 26 | static char SCCSid[] = "$SunId$ LBL";
26  
27   #define  taralloc(h)    (unsigned char *)emalloc((h)->x*(h)->y*(h)->dataBits/8)
28  
29 < #define  readtarga(h,d,f)       ((h)->dataBits==16 ? readt16(h,d,f) : \
30 <                                        readt24(h,d,f))
29 > #define  readtarga(h,d,f)       ((h)->dataBits==16 ? \
30 >                        readt16(h,(unsigned short*)d,f) : readt24(h,d,f))
31  
32 < #define  writetarga(h,d,f)      ((h)->dataBits==16 ? writet16(h,d,f) : \
33 <                                        writet24(h,d,f))
32 > #define  writetarga(h,d,f)      ((h)->dataBits==16 ? \
33 >                        writet16(h,(unsigned short*)d,f) : writet24(h,d,f))
34  
35 < extern char     *ecalloc(), *emalloc();
36 <
37 < extern double  pow();
38 <
39 < double  gamma = 2.2;                    /* gamma correction */
40 <
35 > double  gamcor = 2.2;                   /* gamma correction */
36   int  bradj = 0;                         /* brightness adjustment */
42
37   char  *progname;
44
38   char  msg[128];
39  
40 + static int getint2(FILE *fp);
41 + static void putint2(int i, FILE *fp);
42 + static void quiterr(char *err);
43 + static int getthead(struct hdStruct *hp, char *ip, FILE *fp);
44 + static int putthead(struct hdStruct *hp, char *ip, FILE *fp);
45 + static void tg2ra(struct hdStruct *hp);
46 + static void ra2tg(struct hdStruct *hp);
47 + static void writet24(struct hdStruct *h, unsigned char *d, FILE *fp);
48 + static void writet16(struct hdStruct *h, unsigned short *d, FILE *fp);
49 + static void readt24(struct hdStruct *h, unsigned char *data, FILE *fp);
50 + static void readt16(struct hdStruct *h, unsigned short *data, FILE *fp);
51  
52 < main(argc, argv)
53 < int  argc;
54 < char  *argv[];
52 >
53 > int
54 > main(int  argc, char  *argv[])
55   {
56          struct hdStruct  head;
57          int  reverse = 0;
58          int  i;
59 <        
59 >        SET_DEFAULT_BINARY();
60 >        SET_FILE_BINARY(stdin);
61 >        SET_FILE_BINARY(stdout);
62          progname = argv[0];
63  
64          head.dataBits = 16;
# Line 60 | Line 66 | char  *argv[];
66                  if (argv[i][0] == '-')
67                          switch (argv[i][1]) {
68                          case 'g':
69 <                                gamma = atof(argv[++i]);
69 >                                gamcor = atof(argv[++i]);
70                                  break;
71                          case 'r':
72                                  reverse = !reverse;
# Line 95 | Line 101 | char  *argv[];
101                  quiterr(msg);
102          }
103                                          /* set gamma */
104 <        setcolrgam(gamma);
104 >        setcolrgam(gamcor);
105                                          /* convert */
106          if (reverse) {
107                                          /* get header */
# Line 104 | Line 110 | char  *argv[];
110                  if (!goodpic(&head))
111                          quiterr("incompatible format");
112                                          /* put header */
113 +                newheader("RADIANCE", stdout);
114                  printargs(i, argv, stdout);
115                  fputformat(COLRFMT, stdout);
116                  putchar('\n');
# Line 134 | Line 141 | userr:
141   }
142  
143  
144 < int
145 < getint2(fp)                     /* get a 2-byte positive integer */
146 < register FILE   *fp;
144 > static int
145 > getint2(                        /* get a 2-byte positive integer */
146 >        register FILE   *fp
147 > )
148   {
149          register int  b1, b2;
150  
# Line 147 | Line 155 | register FILE  *fp;
155   }
156  
157  
158 < putint2(i, fp)                  /* put a 2-byte positive integer */
159 < register int  i;
160 < register FILE   *fp;
158 > static void
159 > putint2(                        /* put a 2-byte positive integer */
160 >        register int  i,
161 >        register FILE   *fp
162 > )
163   {
164          putc(i&0xff, fp);
165          putc(i>>8&0xff, fp);
166   }
167  
168  
169 < quiterr(err)            /* print message and exit */
170 < char  *err;
169 > static void
170 > quiterr(                /* print message and exit */
171 >        char  *err
172 > )
173   {
174          fprintf(stderr, "%s: %s\n", progname, err);
175          exit(1);
176   }
177  
178  
179 < eputs(s)
180 < char *s;
179 > void
180 > eputs(
181 >        char *s
182 > )
183   {
184          fputs(s, stderr);
185   }
186  
187  
188 < quit(code)
189 < int code;
188 > void
189 > quit(
190 >        int code
191 > )
192   {
193          exit(code);
194   }
195  
196  
197 < getthead(hp, ip, fp)            /* read header from input */
198 < struct hdStruct  *hp;
199 < char  *ip;
200 < register FILE  *fp;
197 > static int
198 > getthead(               /* read header from input */
199 >        struct hdStruct  *hp,
200 >        char  *ip,
201 >        register FILE  *fp
202 > )
203   {
204          int     nidbytes;
205  
# Line 211 | Line 229 | register FILE  *fp;
229   }
230  
231  
232 < putthead(hp, ip, fp)            /* write header to output */
233 < struct hdStruct  *hp;
234 < char  *ip;
235 < register FILE  *fp;
232 > static int
233 > putthead(               /* write header to output */
234 >        struct hdStruct  *hp,
235 >        char  *ip,
236 >        register FILE  *fp
237 > )
238   {
239          if (ip != NULL)
240                  putc(strlen(ip), fp);
# Line 239 | Line 259 | register FILE  *fp;
259   }
260  
261  
262 < tg2ra(hp)                       /* targa file to RADIANCE file */
263 < struct hdStruct  *hp;
262 > static void
263 > tg2ra(                  /* targa file to RADIANCE file */
264 >        struct hdStruct  *hp
265 > )
266   {
267          COLR  *scanline;
268          unsigned char  *tarData;
# Line 281 | Line 303 | struct hdStruct  *hp;
303                  if (fwritecolrs(scanline, hp->x, stdout) < 0)
304                          quiterr("error writing RADIANCE file");
305          }
306 <        free((char *)scanline);
307 <        free((char *)tarData);
306 >        free((void *)scanline);
307 >        free((void *)tarData);
308   }
309  
310  
311 < ra2tg(hp)                       /* convert radiance to targa file */
312 < struct hdStruct  *hp;
311 > static void
312 > ra2tg(                  /* convert radiance to targa file */
313 >        struct hdStruct  *hp
314 > )
315   {
316          register int    i, j;
317          unsigned char  *tarData;
# Line 330 | Line 354 | struct hdStruct  *hp;
354                                                  /* write out targa data */
355          writetarga(hp, tarData, stdout);
356  
357 <        free((char *)inl);
358 <        free((char *)tarData);
357 >        free((void *)inl);
358 >        free((void *)tarData);
359   }
360  
361  
362 < writet24(h, d, fp)              /* write out 24-bit targa data */
363 < struct hdStruct  *h;
364 < unsigned char  *d;
365 < FILE  *fp;
362 > static void
363 > writet24(               /* write out 24-bit targa data */
364 >        struct hdStruct  *h,
365 >        unsigned char  *d,
366 >        FILE  *fp
367 > )
368   {
369          if (h->dataType == IM_RGB) {            /* uncompressed */
370                  if (fwrite((char *)d, 3*h->x, h->y, fp) != h->y)
# Line 349 | Line 375 | FILE  *fp;
375   }
376  
377  
378 < writet16(h, d, fp)              /* write out 16-bit targa data */
379 < struct hdStruct  *h;
380 < register unsigned short  *d;
381 < FILE  *fp;
378 > static void
379 > writet16(               /* write out 16-bit targa data */
380 >        struct hdStruct  *h,
381 >        register unsigned short  *d,
382 >        FILE  *fp
383 > )
384   {
385          register int  cnt;
386  
# Line 367 | Line 395 | FILE  *fp;
395   }
396  
397  
398 < readt24(h, data, fp)            /* read in 24-bit targa data */
399 < register struct hdStruct  *h;
400 < unsigned char  *data;
401 < FILE  *fp;
398 > static void
399 > readt24(                /* read in 24-bit targa data */
400 >        register struct hdStruct  *h,
401 >        unsigned char  *data,
402 >        FILE  *fp
403 > )
404   {
405          register int  cnt, c;
406          register unsigned char  *dp;
# Line 408 | Line 438 | readerr:
438   }
439  
440  
441 < readt16(h, data, fp)            /* read in 16-bit targa data */
442 < register struct hdStruct  *h;
443 < unsigned short  *data;
444 < FILE  *fp;
441 > static void
442 > readt16(                /* read in 16-bit targa data */
443 >        register struct hdStruct  *h,
444 >        unsigned short  *data,
445 >        FILE  *fp
446 > )
447   {
448          register int  cnt, c;
449          register unsigned short  *dp;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines