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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines