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

Comparing ray/src/px/ra_t8.c (file contents):
Revision 2.7 by greg, Fri Jun 10 12:51:18 1994 UTC vs.
Revision 2.19 by greg, Sat Jun 7 05:09:46 2025 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 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_t8.c - program to convert between RADIANCE and
6   *              Targa 8-bit color-mapped images.
# Line 11 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   *      8/22/88         Adapted from ra_pr.c
9   */
10  
11 < #include  <stdio.h>
12 <
11 > #include  <math.h>
12 > #include  "platform.h"
13 > #include  "rtio.h"
14 > #include  "rtmisc.h"
15   #include  "color.h"
17
16   #include  "resolu.h"
17 <
17 > #include  "clrtab.h"
18   #include  "targa.h"
19  
22 #ifdef MSDOS
23 #include  <fcntl.h>
24 #endif
20  
26 #include  <math.h>
27
28 #ifndef  BSD
29 #define  bcopy(s,d,n)           (void)memcpy(d,s,n)
30 extern char  *memcpy();
31 #endif
32
21   #define  goodpic(h)     (my_imType(h) && my_mapType(h))
22   #define  my_imType(h)   (((h)->dataType==IM_CMAP || (h)->dataType==IM_CCMAP) \
23                                  && (h)->dataBits==8 && (h)->imType==0)
24   #define  my_mapType(h)  ((h)->mapType==CM_HASMAP && \
25                                  ((h)->CMapBits==24 || (h)->CMapBits==32))
26  
27 < #define  taralloc(h)    (BYTE *)emalloc((h)->x*(h)->y)
27 > #define  taralloc(h)    (uby8 *)emalloc((h)->x*(h)->y)
28  
29 < BYTE  clrtab[256][3];
42 <
29 > uby8  clrtab[256][3];
30   extern int      samplefac;
44
45 extern char     *ecalloc(), *emalloc();
46
47 extern long  ftell();
48
31   double  gamv = 2.2;                     /* gamv correction */
50
32   int  bradj = 0;                         /* brightness adjustment */
52
53 char  *progname;
54
33   char  errmsg[128];
56
34   COLR    *inl;
35 <
59 < BYTE    *tarData;
60 <
35 > uby8    *tarData;
36   int  xmax, ymax;
37  
38 + static int getint2(FILE *fp);
39 + static void putint2(int  i, FILE        *fp);
40 + static void quiterr(char  *err);
41 + static int getthead(struct hdStruct      *hp, char  *ip, FILE  *fp);
42 + static int putthead(struct hdStruct      *hp, char  *ip, FILE  *fp);
43 + static int getrhead(struct hdStruct  *h, FILE  *fp);
44 + static void tg2ra(struct hdStruct        *hp);
45 + static void getmapped(int  nc, int  dith);
46 + static void getgrey(int  nc);
47 + static void writetarga(struct hdStruct   *h, uby8  *d, FILE  *fp);
48 + static void readtarga(struct hdStruct    *h, uby8  *data, FILE  *fp);
49  
50 < main(argc, argv)
51 < int  argc;
52 < char  *argv[];
50 >
51 > int
52 > main(
53 >        int  argc,
54 >        char  *argv[]
55 > )
56   {
57          struct hdStruct  head;
58          int  dither = 1;
# Line 71 | Line 60 | char  *argv[];
60          int  ncolors = 256;
61          int  greyscale = 0;
62          int  i;
63 < #ifdef MSDOS
64 <        extern int  _fmode;
65 <        _fmode = O_BINARY;
66 <        setmode(fileno(stdin), O_BINARY);
67 <        setmode(fileno(stdout), O_BINARY);
79 < #endif
80 <        progname = argv[0];
63 >        
64 >        SET_DEFAULT_BINARY();
65 >        SET_FILE_BINARY(stdin);
66 >        SET_FILE_BINARY(stdout);
67 >        fixargv0(argv[0]);
68          samplefac = 0;
69  
70          for (i = 1; i < argc; i++)
# Line 154 | Line 141 | char  *argv[];
141          quiterr(NULL);
142   userr:
143          fprintf(stderr,
144 <        "Usage: %s [-d][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n",
144 >        "Usage: %s [-d][-n samp][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n",
145                          progname);
146          fprintf(stderr, "   Or: %s -r [-g gamv][-e +/-stops] [input [output]]\n",
147                          progname);
# Line 162 | Line 149 | userr:
149   }
150  
151  
152 < int
153 < getint2(fp)                     /* get a 2-byte positive integer */
154 < register FILE   *fp;
152 > static int
153 > getint2(                        /* get a 2-byte positive integer */
154 >        FILE    *fp
155 > )
156   {
157 <        register int  b1, b2;
157 >        int  b1, b2;
158  
159          if ((b1 = getc(fp)) == EOF || (b2 = getc(fp)) == EOF)
160                  quiterr("read error");
# Line 175 | Line 163 | register FILE  *fp;
163   }
164  
165  
166 < putint2(i, fp)                  /* put a 2-byte positive integer */
167 < register int  i;
168 < register FILE   *fp;
166 > static void
167 > putint2(                        /* put a 2-byte positive integer */
168 >        int  i,
169 >        FILE    *fp
170 > )
171   {
172          putc(i&0xff, fp);
173          putc(i>>8&0xff, fp);
174   }
175  
176  
177 < quiterr(err)            /* print message and exit */
178 < char  *err;
177 > static void
178 > quiterr(                /* print message and exit */
179 >        char  *err
180 > )
181   {
182          if (err != NULL) {
183                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 195 | Line 187 | char  *err;
187   }
188  
189  
190 < eputs(s)
191 < char *s;
190 > void
191 > eputs(const char *s)
192   {
193          fputs(s, stderr);
194   }
195  
196  
197 < quit(code)
198 < int code;
197 > void
198 > quit(int code)
199   {
200          exit(code);
201   }
202  
203  
204 < getthead(hp, ip, fp)            /* read header from input */
205 < struct hdStruct  *hp;
206 < char  *ip;
207 < register FILE  *fp;
204 > static int
205 > getthead(               /* read header from input */
206 >        struct hdStruct  *hp,
207 >        char  *ip,
208 >        FILE  *fp
209 > )
210   {
211          int     nidbytes;
212  
# Line 242 | Line 236 | register FILE  *fp;
236   }
237  
238  
239 < putthead(hp, ip, fp)            /* write header to output */
240 < struct hdStruct  *hp;
241 < char  *ip;
242 < register FILE  *fp;
239 > static int
240 > putthead(               /* write header to output */
241 >        struct hdStruct  *hp,
242 >        char  *ip,
243 >        FILE  *fp
244 > )
245   {
246          if (ip != NULL)
247                  putc(strlen(ip), fp);
# Line 270 | Line 266 | register FILE  *fp;
266   }
267  
268  
269 < getrhead(h, fp)                 /* load RADIANCE input file header */
270 < register struct hdStruct  *h;
271 < FILE  *fp;
269 > static int
270 > getrhead(                       /* load RADIANCE input file header */
271 >        struct hdStruct  *h,
272 >        FILE  *fp
273 > )
274   {
275                                          /* get header info. */
276          if (checkheader(fp, COLRFMT, NULL) < 0 ||
# Line 300 | Line 298 | FILE  *fp;
298   }
299  
300  
301 < tg2ra(hp)                       /* targa file to RADIANCE file */
302 < struct hdStruct  *hp;
301 > static void
302 > tg2ra(                  /* targa file to RADIANCE file */
303 >        struct hdStruct  *hp
304 > )
305   {
306          union {
307 <                BYTE  c3[256][3];
308 <                BYTE  c4[256][4];
307 >                uby8  c3[256][3];
308 >                uby8  c4[256][4];
309          } map;
310          COLR  ctab[256];
311          COLR  *scanline;
312 <        register int  i, j;
312 >        int  i, j;
313  
314                                          /* get color table */
315          if ((hp->CMapBits==24 ? fread((char *)(map.c3+hp->mapOrig),
# Line 344 | Line 344 | struct hdStruct         *hp;
344                  if (fwritecolrs(scanline, xmax, stdout) < 0)
345                          quiterr("error writing RADIANCE file");
346          }
347 <        free((char *)scanline);
348 <        free((char *)tarData);
347 >        free((void *)scanline);
348 >        free((void *)tarData);
349   }
350  
351  
352 < getmapped(nc, dith)             /* read in and quantize image */
353 < int  nc;                /* number of colors to use */
354 < int  dith;              /* use dithering? */
352 > static void
353 > getmapped(              /* read in and quantize image */
354 >        int  nc,                /* number of colors to use */
355 >        int  dith               /* use dithering? */
356 > )
357   {
358          long  fpos;
359 <        register int  y;
359 >        int  y;
360  
361          setcolrgam(gamv);
362          fpos = ftell(stdin);
# Line 397 | Line 399 | int  dith;             /* use dithering? */
399   }
400  
401  
402 < getgrey(nc)                     /* read in and convert to greyscale image */
403 < int  nc;                /* number of colors to use */
402 > static void
403 > getgrey(                        /* read in and convert to greyscale image */
404 >        int  nc         /* number of colors to use */
405 > )
406   {
407          int  y;
408 <        register BYTE  *dp;
409 <        register int  x;
408 >        uby8  *dp;
409 >        int  x;
410  
411          setcolrgam(gamv);
412          dp = tarData+xmax*ymax;;
# Line 429 | Line 433 | int  nc;               /* number of colors to use */
433   }
434  
435  
436 < writetarga(h, d, fp)            /* write out targa data */
437 < struct hdStruct  *h;
438 < BYTE  *d;
439 < FILE  *fp;
436 > static void
437 > writetarga(             /* write out targa data */
438 >        struct hdStruct  *h,
439 >        uby8  *d,
440 >        FILE  *fp
441 > )
442   {
443 <        register int  i, j;
443 >        int  i, j;
444  
445          for (i = 0; i < h->mapLength; i++)      /* write color map */
446                  for (j = 2; j >= 0; j--)
447                          putc(clrtab[i][j], fp);
448          if (h->dataType == IM_CMAP) {           /* uncompressed */
449 <                if (fwrite((char *)d,h->x*sizeof(BYTE),h->y,fp) != h->y)
449 >                if (fwrite((char *)d,h->x*sizeof(uby8),h->y,fp) != h->y)
450                          quiterr("error writing targa file");
451                  return;
452          }
# Line 448 | Line 454 | FILE  *fp;
454   }
455  
456  
457 < readtarga(h, data, fp)          /* read in targa data */
458 < struct hdStruct  *h;
459 < BYTE  *data;
460 < FILE  *fp;
457 > static void
458 > readtarga(              /* read in targa data */
459 >        struct hdStruct  *h,
460 >        uby8  *data,
461 >        FILE  *fp
462 > )
463   {
464 <        register int  cnt, c;
465 <        register BYTE   *dp;
464 >        int  cnt, c;
465 >        uby8    *dp;
466  
467          if (h->dataType == IM_CMAP) {           /* uncompressed */
468 <                if (fread((char *)data,h->x*sizeof(BYTE),h->y,fp) != h->y)
468 >                if (fread((char *)data,h->x*sizeof(uby8),h->y,fp) != h->y)
469                          goto readerr;
470                  return;
471          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines