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.4 by greg, Tue Oct 13 11:36:13 1992 UTC vs.
Revision 2.12 by schorsch, Thu Jun 5 19:29:34 2003 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 12 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   */
10  
11   #include  <stdio.h>
12 + #include  <time.h>
13 + #include  <math.h>
14  
15 + #include  "platform.h"
16   #include  "color.h"
17
17   #include  "resolu.h"
19
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)
# Line 38 | Line 26 | extern char  *memcpy();
26  
27   #define  taralloc(h)    (BYTE *)emalloc((h)->x*(h)->y)
28  
29 < extern BYTE  clrtab[][3];
29 > BYTE  clrtab[256][3];
30  
31 + extern int      samplefac;
32 +
33   extern char     *ecalloc(), *emalloc();
34  
35   extern long  ftell();
# Line 69 | Line 59 | char  *argv[];
59          int  ncolors = 256;
60          int  greyscale = 0;
61          int  i;
62 < #ifdef MSDOS
63 <        extern int  _fmode;
64 <        _fmode = O_BINARY;
75 <        setmode(fileno(stdin), O_BINARY);
76 <        setmode(fileno(stdout), O_BINARY);
77 < #endif
62 >        SET_DEFAULT_BINARY();
63 >        SET_FILE_BINARY(stdin);
64 >        SET_FILE_BINARY(stdout);
65          progname = argv[0];
66 +        samplefac = 0;
67  
68          for (i = 1; i < argc; i++)
69                  if (argv[i][0] == '-')
# Line 100 | Line 88 | char  *argv[];
88                          case 'c':
89                                  ncolors = atoi(argv[++i]);
90                                  break;
91 +                        case 'n':
92 +                                samplefac = atoi(argv[++i]);
93 +                                break;
94                          default:
95                                  goto userr;
96                          }
# Line 125 | Line 116 | char  *argv[];
116                  xmax = head.x;
117                  ymax = head.y;
118                                          /* put header */
119 +                newheader("RADIANCE", stdout);
120                  printargs(i, argv, stdout);
121                  fputformat(COLRFMT, stdout);
122                  putchar('\n');
# Line 147 | Line 139 | char  *argv[];
139          quiterr(NULL);
140   userr:
141          fprintf(stderr,
142 <        "Usage: %s [-d][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n",
142 >        "Usage: %s [-d][-n samp][-c ncolors][-b][-g gamv][-e +/-stops] input [output]\n",
143                          progname);
144          fprintf(stderr, "   Or: %s -r [-g gamv][-e +/-stops] [input [output]]\n",
145                          progname);
# Line 188 | Line 180 | char  *err;
180   }
181  
182  
183 + void
184   eputs(s)
185   char *s;
186   {
# Line 195 | Line 188 | char *s;
188   }
189  
190  
191 + void
192   quit(code)
193   int code;
194   {
# Line 337 | Line 331 | struct hdStruct         *hp;
331                  if (fwritecolrs(scanline, xmax, stdout) < 0)
332                          quiterr("error writing RADIANCE file");
333          }
334 <        free((char *)scanline);
335 <        free((char *)tarData);
334 >        free((void *)scanline);
335 >        free((void *)tarData);
336   }
337  
338  
# Line 351 | Line 345 | int  dith;             /* use dithering? */
345  
346          setcolrgam(gamv);
347          fpos = ftell(stdin);
348 <        new_histo();                    /* build histogram */
348 >        if ((samplefac ? neu_init(xmax*ymax) : new_histo(xmax*ymax)) == -1)
349 >                quiterr("cannot initialized histogram");
350          for (y = ymax-1; y >= 0; y--) {
351                  if (freadcolrs(inl, xmax, stdin) < 0)
352                          quiterr("error reading Radiance input");
353                  if (bradj)
354                          shiftcolrs(inl, xmax, bradj);
355                  colrs_gambs(inl, xmax);
356 <                cnt_colrs(inl, xmax);
356 >                if (samplefac)
357 >                        neu_colrs(inl, xmax);
358 >                else
359 >                        cnt_colrs(inl, xmax);
360          }
361          if (fseek(stdin, fpos, 0) == EOF)
362                  quiterr("Radiance input must be from a file");
363 <        new_clrtab(nc);                 /* map colors */
363 >        if (samplefac)                  /* map colors */
364 >                neu_clrtab(nc);
365 >        else
366 >                new_clrtab(nc);
367          for (y = ymax-1; y >= 0; y--) {
368                  if (freadcolrs(inl, xmax, stdin) < 0)
369                          quiterr("error reading Radiance input");
370                  if (bradj)
371                          shiftcolrs(inl, xmax, bradj);
372                  colrs_gambs(inl, xmax);
373 <                if (dith)
374 <                        dith_colrs(tarData+y*xmax, inl, xmax);
373 >                if (samplefac)
374 >                        if (dith)
375 >                                neu_dith_colrs(tarData+y*xmax, inl, xmax);
376 >                        else
377 >                                neu_map_colrs(tarData+y*xmax, inl, xmax);
378                  else
379 <                        map_colrs(tarData+y*xmax, inl, xmax);
379 >                        if (dith)
380 >                                dith_colrs(tarData+y*xmax, inl, xmax);
381 >                        else
382 >                                map_colrs(tarData+y*xmax, inl, xmax);
383          }
384   }
385  
# Line 391 | Line 398 | int  nc;               /* number of colors to use */
398                          quiterr("error reading Radiance input");
399                  if (bradj)
400                          shiftcolrs(inl, xmax, bradj);
401 +                x = xmax;
402 +                while (x--)
403 +                        inl[x][GRN] = normbright(inl[x]);
404                  colrs_gambs(inl, xmax);
405                  x = xmax;
406                  if (nc < 256)
407                          while (x--)
408 <                                *--dp = ((long)normbright(inl[x])*nc+128)>>8;
408 >                                *--dp = ((long)inl[x][GRN]*nc+nc/2)>>8;
409                  else
410                          while (x--)
411 <                                *--dp = normbright(inl[x]);
411 >                                *--dp = inl[x][GRN];
412          }
413          for (x = 0; x < nc; x++)
414                  clrtab[x][RED] = clrtab[x][GRN] =
415 <                        clrtab[x][BLU] = ((long)x*256+nc/2)/nc;
415 >                        clrtab[x][BLU] = ((long)x*256+128)/nc;
416   }
417  
418  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines