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

Comparing ray/src/px/ra_ppm.c (file contents):
Revision 2.10 by schorsch, Thu Jun 5 19:29:34 2003 UTC vs.
Revision 2.16 by greg, Tue Mar 20 18:45:04 2018 UTC

# Line 11 | Line 11 | static const char      RCSid[] = "$Id$";
11   #include  <time.h>
12  
13   #include  "platform.h"
14 + #include  "rtio.h"
15   #include  "color.h"
16   #include  "resolu.h"
17  
17
18 int  agryscan(), bgryscan(), aclrscan(), bclrscan();
19 int  agryscan2(), bgryscan2(), aclrscan2(), bclrscan2();
20 int  normval();
21 unsigned int    scanint(), intv(), getby2();
22
18   #define fltv(i)         (((i)+.5)/(maxval+1.))
24
19   int  bradj = 0;                         /* brightness adjustment */
26
20   double  gamcor = 2.2;                   /* gamma correction value */
28
21   int  maxval = 255;                      /* maximum primary value */
30
22   char  *progname;
32
23   int  xmax, ymax;
24  
25 + typedef int colrscanf_t(COLR *scan, int len, FILE *fp);
26 + typedef int colorscanf_t(COLOR *scan, int len, FILE *fp);
27  
28 < main(argc, argv)
29 < int  argc;
30 < char  *argv[];
28 > static colrscanf_t agryscan, bgryscan, aclrscan, bclrscan;
29 > static void ppm2ra(colrscanf_t *getscan);
30 > static void ra2ppm(int  binary, int  grey);
31 >
32 > static colorscanf_t agryscan2, bgryscan2, aclrscan2, bclrscan2;
33 > static void ppm2ra2(colorscanf_t *getscan);
34 > static void ra2ppm2(int  binary, int  grey);
35 >
36 > static int normval(unsigned int  v);
37 > static unsigned int scanint(FILE  *fp);
38 > static unsigned int intv(double v);
39 > static unsigned int getby2(FILE *fp);
40 > static void putby2(unsigned int w, FILE *fp);
41 > static void quiterr(char  *err);
42 >
43 >
44 > int
45 > main(
46 >        int  argc,
47 >        char  *argv[]
48 > )
49   {
50          char  inpbuf[2];
51          int  gryflag = 0;
# Line 94 | Line 104 | char  *argv[];
104                  if (read(fileno(stdin), inpbuf, 2) != 2 || inpbuf[0] != 'P')
105                          quiterr("input not a Poskanzer Pixmap");
106                  ptype = inpbuf[1];
107 < #ifdef _WIN32
107 > #if defined(_WIN32) || defined(_WIN64)
108                  if (ptype > 4)
109                          SET_FILE_BINARY(stdin);
110                  SET_FILE_BINARY(stdout);
# Line 144 | Line 154 | char  *argv[];
154                                  quiterr("unsupported Pixmap type");
155                          }
156          } else {
157 < #ifdef _WIN32
157 > #if defined(_WIN32) || defined(_WIN64)
158                  SET_FILE_BINARY(stdin);
159                  if (binflag)
160                          SET_FILE_BINARY(stdout);
# Line 171 | Line 181 | userr:
181   }
182  
183  
184 < quiterr(err)            /* print message and exit */
185 < char  *err;
184 > static void
185 > quiterr(                /* print message and exit */
186 >        char  *err
187 > )
188   {
189          if (err != NULL) {
190                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 182 | Line 194 | char  *err;
194   }
195  
196  
197 < ppm2ra(getscan)         /* convert 1-byte Pixmap to Radiance picture */
198 < int  (*getscan)();
197 > static void
198 > ppm2ra(         /* convert 1-byte Pixmap to Radiance picture */
199 >        colrscanf_t *getscan
200 > )
201   {
202          COLR    *scanout;
203          int     y;
# Line 206 | Line 220 | int  (*getscan)();
220   }
221  
222  
223 < ra2ppm(binary, grey)    /* convert Radiance picture to Pixmap */
224 < int  binary, grey;
223 > static void
224 > ra2ppm( /* convert Radiance picture to 1-byte/sample Pixmap */
225 >        int  binary,
226 >        int  grey
227 > )
228   {
229          COLR    *scanin;
230          register int    x;
# Line 252 | Line 269 | int  binary, grey;
269   }
270  
271  
272 < ppm2ra2(getscan)        /* convert 2-byte Pixmap to Radiance picture */
273 < int  (*getscan)();
272 > static void
273 > ppm2ra2(        /* convert 2-byte Pixmap to Radiance picture */
274 >        colorscanf_t *getscan
275 > )
276   {
277          COLOR   *scanout;
278          double  mult;
# Line 269 | Line 288 | int  (*getscan)();
288          for (y = ymax-1; y >= 0; y--) {
289                  if ((*getscan)(scanout, xmax, stdin) < 0)
290                          quiterr("error reading Pixmap");
291 <                for (x = gamcor>1.01|gamcor<0.99?xmax:0; x--; ) {
291 >                for (x = (gamcor>1.01)|(gamcor<0.99)?xmax:0; x--; ) {
292                          colval(scanout[x],RED) =
293                                          pow(colval(scanout[x],RED), gamcor);
294                          colval(scanout[x],GRN) =
# Line 287 | Line 306 | int  (*getscan)();
306   }
307  
308  
309 < ra2ppm2(binary, grey)   /* convert Radiance picture to Pixmap (2-byte) */
310 < int  binary, grey;
309 > static void
310 > ra2ppm2(        /* convert Radiance picture to Pixmap (2-byte) */
311 >        int  binary,
312 >        int  grey
313 > )
314   {
315          COLOR   *scanin;
316          double  mult, d;
# Line 309 | Line 331 | int  binary, grey;
331                  for (x = grey?xmax:0; x--; )
332                          colval(scanin[x],GRN) = bright(scanin[x]);
333                  d = 1./gamcor;
334 <                for (x = d>1.01|d<0.99?xmax:0; x--; ) {
334 >                for (x = (d>1.01)|(d<0.99)?xmax:0; x--; ) {
335                          colval(scanin[x],GRN) = pow(colval(scanin[x],GRN), d);
336                          if (!grey) {
337                                  colval(scanin[x],RED) =
# Line 351 | Line 373 | int  binary, grey;
373   }
374  
375  
376 < agryscan(scan, len, fp)                 /* get an ASCII greyscale scanline */
377 < register COLR  *scan;
378 < register int  len;
379 < FILE  *fp;
376 > static int
377 > agryscan(                       /* get an ASCII greyscale scanline */
378 >        register COLR  *scan,
379 >        register int  len,
380 >        FILE  *fp
381 > )
382   {
383          while (len-- > 0) {
384                  scan[0][RED] =
# Line 366 | Line 390 | FILE  *fp;
390   }
391  
392  
393 < bgryscan(scan, len, fp)                 /* get a binary greyscale scanline */
394 < register COLR  *scan;
395 < int  len;
396 < register FILE  *fp;
393 > static int
394 > bgryscan(                       /* get a binary greyscale scanline */
395 >        register COLR  *scan,
396 >        int  len,
397 >        register FILE  *fp
398 > )
399   {
400          register int  c;
401  
# Line 387 | Line 413 | register FILE  *fp;
413   }
414  
415  
416 < aclrscan(scan, len, fp)                 /* get an ASCII color scanline */
417 < register COLR  *scan;
418 < register int  len;
419 < FILE  *fp;
416 > static int
417 > aclrscan(                       /* get an ASCII color scanline */
418 >        register COLR  *scan,
419 >        register int  len,
420 >        FILE  *fp
421 > )
422   {
423          while (len-- > 0) {
424                  scan[0][RED] = normval(scanint(fp));
# Line 402 | Line 430 | FILE  *fp;
430   }
431  
432  
433 < bclrscan(scan, len, fp)                 /* get a binary color scanline */
434 < register COLR  *scan;
435 < int  len;
436 < register FILE  *fp;
433 > static int
434 > bclrscan(                       /* get a binary color scanline */
435 >        register COLR  *scan,
436 >        int  len,
437 >        register FILE  *fp
438 > )
439   {
440          int  r, g, b;
441  
# Line 429 | Line 459 | register FILE  *fp;
459   }
460  
461  
462 < agryscan2(scan, len, fp)                /* get an ASCII greyscale scanline */
463 < register COLOR  *scan;
464 < register int  len;
465 < FILE  *fp;
462 > static int
463 > agryscan2(              /* get an ASCII greyscale scanline */
464 >        register COLOR  *scan,
465 >        register int  len,
466 >        FILE  *fp
467 > )
468   {
469          while (len-- > 0) {
470                  colval(scan[0],RED) =
# Line 444 | Line 476 | FILE  *fp;
476   }
477  
478  
479 < bgryscan2(scan, len, fp)                /* get a binary greyscale scanline */
480 < register COLOR  *scan;
481 < int  len;
482 < register FILE  *fp;
479 > static int
480 > bgryscan2(              /* get a binary greyscale scanline */
481 >        register COLOR  *scan,
482 >        int  len,
483 >        register FILE  *fp
484 > )
485   {
486          register int  c;
487  
# Line 463 | Line 497 | register FILE  *fp;
497   }
498  
499  
500 < aclrscan2(scan, len, fp)                /* get an ASCII color scanline */
501 < register COLOR  *scan;
502 < register int  len;
503 < FILE  *fp;
500 > static int
501 > aclrscan2(              /* get an ASCII color scanline */
502 >        register COLOR  *scan,
503 >        register int  len,
504 >        FILE  *fp
505 > )
506   {
507          while (len-- > 0) {
508                  colval(scan[0],RED) = fltv(scanint(fp));
# Line 478 | Line 514 | FILE  *fp;
514   }
515  
516  
517 < bclrscan2(scan, len, fp)                /* get a binary color scanline */
518 < register COLOR  *scan;
519 < int  len;
520 < register FILE  *fp;
517 > static int
518 > bclrscan2(              /* get a binary color scanline */
519 >        register COLOR  *scan,
520 >        int  len,
521 >        register FILE  *fp
522 > )
523   {
524          int  r, g, b;
525  
# Line 499 | Line 537 | register FILE  *fp;
537   }
538  
539  
540 < unsigned int
541 < scanint(fp)                     /* scan the next positive integer value */
542 < register FILE  *fp;
540 > static unsigned int
541 > scanint(                        /* scan the next positive integer value */
542 >        register FILE  *fp
543 > )
544   {
545          register int  c;
546          register unsigned int  i;
# Line 527 | Line 566 | tryagain:
566   }
567  
568  
569 < int
570 < normval(v)                      /* normalize a value to [0,255] */
571 < register unsigned int  v;
569 > static int
570 > normval(                        /* normalize a value to [0,255] */
571 >        register unsigned int  v
572 > )
573   {
574          if (v >= maxval)
575                  return(255);
# Line 539 | Line 579 | register unsigned int  v;
579   }
580  
581  
582 < unsigned int
583 < getby2(fp)                      /* return 2-byte quantity from fp */
584 < register FILE   *fp;
582 > static unsigned int
583 > getby2(                 /* return 2-byte quantity from fp */
584 >        register FILE   *fp
585 > )
586   {
587          register int    lowerb, upperb;
588  
548        lowerb = getc(fp);
589          upperb = getc(fp);
590 <        if (upperb == EOF)
590 >        lowerb = getc(fp);
591 >        if (lowerb == EOF)
592                  return(EOF);
593          return(upperb<<8 | lowerb);
594   }
595  
596  
597 < putby2(w, fp)                   /* put 2-byte quantity to fp */
598 < register unsigned int   w;
599 < register FILE   *fp;
597 > static void
598 > putby2(                 /* put 2-byte quantity to fp */
599 >        register unsigned int   w,
600 >        register FILE   *fp
601 > )
602   {
560        putc(w & 0xff, fp);
603          putc(w>>8 & 0xff, fp);
604 +        putc(w & 0xff, fp);
605          if (ferror(fp)) {
606                  fprintf(stderr, "%s: write error on PPM output\n", progname);
607                  exit(1);
# Line 566 | Line 609 | register FILE  *fp;
609   }
610  
611  
612 < unsigned int
613 < intv(v)                         /* return integer quantity for v */
614 < register double v;
612 > static unsigned int
613 > intv(                           /* return integer quantity for v */
614 >        register double v
615 > )
616   {
617          if (v >= 0.99999)
618                  return(maxval);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines