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

Comparing ray/src/px/ra_tiff.c (file contents):
Revision 2.25 by schorsch, Mon Jul 21 22:30:19 2003 UTC vs.
Revision 2.39 by greg, Fri Jun 6 19:11:21 2025 UTC

# Line 7 | Line 7 | static const char      RCSid[] = "$Id$";
7   *  Added white-balance adjustment 10/01 (GW).
8   */
9  
10 #include  <stdio.h>
10   #include  <math.h>
11   #include  <ctype.h>
12 < #include  <time.h>
12 > #include  "paths.h"
13 > #include  "rtio.h"
14 > #include  "platform.h"
15   #include  "tiffio.h"
16   #include  "color.h"
17   #include  "resolu.h"
# Line 23 | Line 24 | static const char      RCSid[] = "$Id$";
24   #define C_GAMMA         0x4             /* needs gamma correction */
25   #define C_GRY           0x8             /* TIFF is greyscale */
26   #define C_XYZE          0x10            /* Radiance is XYZE */
27 < #define C_RFLT          0x20            /* Radiance data is float */
28 < #define C_TFLT          0x40            /* TIFF data is float */
29 < #define C_TWRD          0x80            /* TIFF data is 16-bit */
30 < #define C_PRIM          0x100           /* has assigned primaries */
27 > #define C_SPEC          0x20            /* Radiance is spectral */
28 > #define C_RFLT          0x40            /* Radiance data is float */
29 > #define C_TFLT          0x80            /* TIFF data is float */
30 > #define C_TWRD          0x100           /* TIFF data is 16-bit */
31 > #define C_PRIM          0x200           /* has assigned primaries */
32  
33 < struct {
33 > typedef void colcvf_t(uint32 y);
34 >
35 > struct CONVST {
36          uint16  flags;          /* conversion flags (defined above) */
37          char    capdate[20];    /* capture date/time */
38          char    owner[256];     /* content owner */
# Line 40 | Line 44 | struct {
44          uint16  orient;         /* visual orientation (TIFF spec.) */
45          double  stonits;        /* input conversion to nits */
46          float   pixrat;         /* pixel aspect ratio */
47 +        int     ncc;            /* # color components for spectral */
48 +        float   wpt[4];         /* wavelength partitions */
49          FILE    *rfp;           /* Radiance stream pointer */
50          TIFF    *tif;           /* TIFF pointer */
51          uint32  xmax, ymax;     /* image dimensions */
# Line 48 | Line 54 | struct {
54          union {
55                  COLR    *colrs;         /* 4-byte ???E pointer */
56                  COLOR   *colors;        /* float array pointer */
57 <                char    *p;             /* generic pointer */
57 >                void    *p;             /* generic pointer */
58          } r;                    /* Radiance scanline */
59          union {
60                  uint8   *bp;            /* byte pointer */
61                  uint16  *wp;            /* word pointer */
62                  float   *fp;            /* float pointer */
63 <                char    *p;             /* generic pointer */
63 >                void    *p;             /* generic pointer */
64          } t;                    /* TIFF scanline */
65 <        void    (*tf)();        /* translation procedure */
65 >        colcvf_t *tf;   /* translation procedure */
66   }       cvts = {        /* conversion structure */
67          0, "", "", COMPRESSION_NONE, PHOTOMETRIC_RGB,
68 <        PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1.,
68 >        PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1., 3,
69   };
70  
71   #define CHK(f)          (cvts.flags & (f))
# Line 67 | Line 73 | struct {
73   #define CLR(f)          (cvts.flags &= ~(f))
74   #define TGL(f)          (cvts.flags ^= (f))
75  
76 < void    Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr();
77 < void    Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry();
78 < void    RRGGBB2Color(), GGry2Color(), Color2RRGGBB(), Color2GGry();
76 > static colcvf_t Luv2Color, L2Color, RGB2Colr, Gry2Colr;
77 > static colcvf_t Color2Luv, Color2L, Colr2RGB, Colr2Gry;
78 > static colcvf_t RRGGBB2Color, GGry2Color, Color2RRGGBB, Color2GGry;
79  
80 + static gethfunc headline;
81 + static void quiterr(char *err);
82 + static void allocbufs(void);
83 + static void initfromtif(void);
84 + static void tiff2ra(int  ac, char  *av[]);
85 + static void initfromrad(void);
86 + static void ra2tiff(int  ac, char  *av[]);
87 + static void ReadRadScan(struct CONVST *cvp);
88 +
89 +
90   #define RfGfBf2Color    Luv2Color
91   #define Gryf2Color      L2Color
92   #define Color2Gryf      Color2L
# Line 92 | Line 108 | short  ortab[8] = {            /* orientation conversion table */
108   extern char     TMSTR[];        /* "CAPDATE=" from header.c */
109   char            OWNSTR[] = "OWNER=";
110  
95 char  *progname;
111  
112 <
113 < main(argc, argv)
99 < int  argc;
100 < char  *argv[];
112 > int
113 > main(int  argc, char  *argv[])
114   {
115          int  reverse = 0;
116          int  i;
117 <        
118 <        progname = argv[0];
117 >                                        /* set global progname */
118 >        fixargv0(argv[0]);
119  
120          for (i = 1; i < argc; i++)
121                  if (argv[i][0] == '-')
# Line 178 | Line 191 | doneopts:
191          exit(0);
192   userr:
193          fprintf(stderr,
194 <        "Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.pic|-} out.tif\n",
194 >        "Usage: %s [-z|-L|-l|-f|-w][-b][-e +/-stops][-g gamma] {in.hdr|-} out.tif\n",
195                          progname);
196          fprintf(stderr,
197 <        "   Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.pic|-]\n",
197 >        "   Or: %s -r [-x][-e +/-stops][-g gamma] in.tif [out.hdr|-]\n",
198                          progname);
199          exit(1);
200   }
201  
202  
203 < quiterr(err)            /* print message and exit */
204 < char  *err;
203 > static void
204 > quiterr(                /* print message and exit */
205 >        char  *err
206 > )
207   {
208          if (err != NULL) {
209                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 198 | Line 213 | char  *err;
213   }
214  
215  
216 < allocbufs()                     /* allocate scanline buffers */
216 > static void
217 > allocbufs(void)                 /* allocate scanline buffers */
218   {
219          int     rsiz, tsiz;
220  
# Line 206 | Line 222 | allocbufs()                    /* allocate scanline buffers */
222          tsiz = (CHK(C_TFLT) ? sizeof(float) :
223                          CHK(C_TWRD) ? sizeof(uint16) : sizeof(uint8)) *
224                          (CHK(C_GRY) ? 1 : 3);
225 <        cvts.r.p = (char *)malloc(rsiz*cvts.xmax);
226 <        cvts.t.p = (char *)malloc(tsiz*cvts.xmax);
227 <        if (cvts.r.p == NULL | cvts.t.p == NULL)
225 >        cvts.r.p = malloc(rsiz*cvts.xmax);
226 >        cvts.t.p = malloc(tsiz*cvts.xmax);
227 >        if ((cvts.r.p == NULL) | (cvts.t.p == NULL))
228                  quiterr("no memory to allocate scanline buffers");
229   }
230  
231  
232 < initfromtif()           /* initialize conversion from TIFF input */
232 > static void
233 > initfromtif(void)               /* initialize conversion from TIFF input */
234   {
235          uint16  hi;
236          char    *cp;
237          float   *fa, f1, f2;
238  
222        CLR(C_GRY|C_GAMMA|C_PRIM|C_RFLT|C_TFLT|C_TWRD|C_CXFM);
223
239          TIFFGetFieldDefaulted(cvts.tif, TIFFTAG_PLANARCONFIG, &cvts.pconf);
240  
241          if (TIFFGetField(cvts.tif, TIFFTAG_PRIMARYCHROMATICITIES, &fa)) {
# Line 258 | Line 273 | initfromtif()          /* initialize conversion from TIFF inpu
273                          cpcolormat(cvts.cmat, xyz2rgbmat);
274                          SET(C_CXFM|C_GAMUT);
275                  } else if (cvts.comp == COMPRESSION_SGILOG)
276 <                        SET(C_GAMUT);
276 >                        SET(C_GAMUT);           /* may be outside XYZ gamut */
277                  if (cvts.pconf != PLANARCONFIG_CONTIG)
278                          quiterr("cannot handle separate Luv planes");
279                  TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT,
# Line 345 | Line 360 | initfromtif()          /* initialize conversion from TIFF inpu
360                  quiterr("unknown input image resolution");
361  
362          if (!TIFFGetField(cvts.tif, TIFFTAG_STONITS, &cvts.stonits))
363 <                cvts.stonits = 1.;
363 >                cvts.stonits = -1.;
364  
365          if (!TIFFGetField(cvts.tif, TIFFTAG_DATETIME, &cp))
366                  cvts.capdate[0] = '\0';
# Line 363 | Line 378 | initfromtif()          /* initialize conversion from TIFF inpu
378          if (cvts.pixrat < .99 || cvts.pixrat > 1.01)
379                  fputaspect(cvts.pixrat, cvts.rfp);
380          if (CHK(C_XYZE)) {
381 <                fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp);
381 >                if (cvts.stonits > .0)
382 >                        fputexpos(pow(2.,(double)cvts.bradj)/cvts.stonits, cvts.rfp);
383                  fputformat(CIEFMT, cvts.rfp);
384          } else {
385                  if (CHK(C_PRIM))
386                          fputprims(cvts.prims, cvts.rfp);
387 <                fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits,
388 <                                cvts.rfp);
387 >                if (cvts.stonits > .0)
388 >                        fputexpos(WHTEFFICACY*pow(2.,(double)cvts.bradj)/cvts.stonits,
389 >                                        cvts.rfp);
390                  fputformat(COLRFMT, cvts.rfp);
391          }
392          if (cvts.capdate[0])
# Line 381 | Line 398 | initfromtif()          /* initialize conversion from TIFF inpu
398   }
399  
400  
401 < tiff2ra(ac, av)         /* convert TIFF image to Radiance picture */
402 < int  ac;
403 < char  *av[];
401 > static void
402 > tiff2ra(                /* convert TIFF image to Radiance picture */
403 >        int  ac,
404 >        char  *av[]
405 > )
406   {
407          int32   y;
408                                          /* open TIFF input */
# Line 394 | Line 413 | char  *av[];
413                  cvts.rfp = stdout;
414          else if ((cvts.rfp = fopen(av[ac+1], "w")) == NULL)
415                  quiterr("cannot open Radiance output picture");
416 +        SET_FILE_BINARY(cvts.rfp);
417                                          /* start output header */
418          newheader("RADIANCE", cvts.rfp);
419          printargs(ac, av, cvts.rfp);
# Line 411 | Line 431 | char  *av[];
431   }
432  
433  
434 < int
435 < headline(s)                     /* process Radiance input header line */
436 < char    *s;
434 > static int
435 > headline(                       /* process Radiance input header line */
436 >        char    *s,
437 >        void    *p
438 > )
439   {
440          static int      tmstrlen = 0;
441          static int      ownstrlen = 0;
442 <        char    fmt[32];
442 >        struct CONVST   *cvp = (struct CONVST *)p;
443 >        char            fmt[MAXFMTLEN];
444  
445 <        if (!tmstrlen)
445 >        if (!tmstrlen) {
446                  tmstrlen = strlen(TMSTR);
424        if (!ownstrlen)
447                  ownstrlen = strlen(OWNSTR);
448 +        }
449          if (formatval(fmt, s)) {
450 <                if (!strcmp(fmt, COLRFMT))
451 <                        CLR(C_XYZE);
429 <                else if (!strcmp(fmt, CIEFMT))
450 >                CLR(C_XYZE|C_SPEC);
451 >                if (!strcmp(fmt, CIEFMT))
452                          SET(C_XYZE);
453 <                else
454 <                        quiterr("unrecognized input picture format");
453 >                else if (!strcmp(fmt, SPECFMT))
454 >                        SET(C_SPEC);
455 >                else if (strcmp(fmt, COLRFMT))
456 >                        return(-1);
457                  return(1);
458          }
459          if (isexpos(s)) {
460 <                cvts.stonits /= exposval(s);
460 >                cvp->stonits /= exposval(s);
461                  return(1);
462          }
463          if (isaspect(s)) {
464 <                cvts.pixrat *= aspectval(s);
464 >                cvp->pixrat *= aspectval(s);
465                  return(1);
466          }
467          if (isprims(s)) {
468 <                primsval(cvts.prims, s);
468 >                primsval(cvp->prims, s);
469                  SET(C_PRIM);
470                  return(1);
471          }
472          if (isdate(s)) {
473                  if (s[tmstrlen] == ' ')
474 <                        strncpy(cvts.capdate, s+tmstrlen+1, 19);
474 >                        strncpy(cvp->capdate, s+tmstrlen+1, 19);
475                  else
476 <                        strncpy(cvts.capdate, s+tmstrlen, 19);
477 <                cvts.capdate[19] = '\0';
476 >                        strncpy(cvp->capdate, s+tmstrlen, 19);
477 >                cvp->capdate[19] = '\0';
478                  return(1);
479          }
480          if (!strncmp(s, OWNSTR, ownstrlen)) {
481 <                register char   *cp = s + ownstrlen;
481 >                char    *cp = s + ownstrlen;
482  
483                  while (isspace(*cp))
484                          ++cp;
485 <                strncpy(cvts.owner, cp, sizeof(cvts.owner));
486 <                cvts.owner[sizeof(cvts.owner)-1] = '\0';
487 <                for (cp = cvts.owner; *cp; cp++)
485 >                strncpy(cvp->owner, cp, sizeof(cvp->owner));
486 >                cvp->owner[sizeof(cvp->owner)-1] = '\0';
487 >                for (cp = cvp->owner; *cp; cp++)
488                          ;
489 <                while (cp > cvts.owner && isspace(cp[-1]))
489 >                while (cp > cvp->owner && isspace(cp[-1]))
490                          *--cp = '\0';
491                  return(1);
492          }
493 +        if (isncomp(s)) {
494 +                cvp->ncc = ncompval(s);
495 +                return((3 <= cvp->ncc) & (cvp->ncc < MAXCSAMP) ? 1 : -1);
496 +        }
497 +        if (iswlsplit(s))
498 +                return(wlsplitval(cvp->wpt, s) ? 1 : -1);
499          return(0);
500   }
501  
502  
503 < initfromrad()                   /* initialize input from a Radiance picture */
503 > static void
504 > initfromrad(void)                       /* initialize input from a Radiance picture */
505   {
506          int     i1, i2, po;
507                                                  /* read Radiance header */
508 <        CLR(C_RFLT|C_XYZE|C_PRIM|C_GAMMA|C_CXFM);
509 <        cvts.capdate[0] = '\0';
510 <        cvts.owner[0] = '\0';
480 <        cvts.stonits = 1.;
481 <        cvts.pixrat = 1.;
482 <        cvts.pconf = PLANARCONFIG_CONTIG;
483 <        getheader(cvts.rfp, headline, NULL);
484 <        if ((po = fgetresolu(&i1, &i2, cvts.rfp)) < 0)
508 >        memcpy(cvts.wpt, WLPART, sizeof(cvts.wpt));
509 >        if (getheader(cvts.rfp, headline, &cvts) < 0 ||
510 >                        (po = fgetresolu(&i1, &i2, cvts.rfp)) < 0)
511                  quiterr("bad Radiance picture");
512          cvts.xmax = i1; cvts.ymax = i2;
513          for (i1 = 0; i1 < 8; i1++)              /* interpret orientation */
# Line 503 | Line 529 | initfromrad()                  /* initialize input from a Radiance pi
529          case PHOTOMETRIC_LOGLUV:
530                  SET(C_RFLT|C_TFLT);
531                  CLR(C_GRY|C_TWRD);
532 <                if (!CHK(C_XYZE)) {
532 >                if (!CHK(C_XYZE|C_SPEC)) {
533                          comprgb2xyzWBmat(cvts.cmat,
534                                          CHK(C_PRIM) ? cvts.prims : stdprims);
535                          SET(C_CXFM);
# Line 528 | Line 554 | initfromrad()                  /* initialize input from a Radiance pi
554                  SET(C_GAMMA|C_GAMUT);
555                  CLR(C_GRY);
556                  setcolrgam(cvts.gamcor);
557 <                if (CHK(C_XYZE)) {
557 >                if (CHK(C_TWRD|C_TFLT) ? CHK(C_XYZE|C_SPEC) : CHK(C_XYZE)) {
558                          compxyz2rgbWBmat(cvts.cmat,
559                                          CHK(C_PRIM) ? cvts.prims : stdprims);
560                          SET(C_CXFM);
# Line 547 | Line 573 | initfromrad()                  /* initialize input from a Radiance pi
573                                          SAMPLEFORMAT_IEEEFP);
574                          cvts.tf = Color2RfGfBf;
575                          SET(C_RFLT);
576 +                        CLR(C_GAMUT);
577                  } else
578                          cvts.tf = Colr2RGB;
579                  break;
# Line 597 | Line 624 | initfromrad()                  /* initialize input from a Radiance pi
624   }
625  
626  
627 < ra2tiff(ac, av)         /* convert Radiance picture to TIFF image */
628 < int  ac;
629 < char  *av[];
627 > static void
628 > ra2tiff(                /* convert Radiance picture to TIFF image */
629 >        int  ac,
630 >        char  *av[]
631 > )
632   {
633          uint32  y;
634                                                  /* open Radiance file */
# Line 607 | Line 636 | char  *av[];
636                  cvts.rfp = stdin;
637          else if ((cvts.rfp = fopen(av[ac], "r")) == NULL)
638                  quiterr("cannot open Radiance input picture");
639 +        SET_FILE_BINARY(cvts.rfp);
640                                                  /* open TIFF file */
641          if ((cvts.tif = TIFFOpen(av[ac+1], "w")) == NULL)
642                  quiterr("cannot open TIFF output");
# Line 621 | Line 651 | char  *av[];
651   }
652  
653  
654 < void
655 < Luv2Color(y)                    /* read/convert/write Luv->COLOR scanline */
626 < uint32  y;
654 > static void
655 > ReadRadScan(struct CONVST *cvp)
656   {
657 <        register int    x;
657 >        static struct CONVST    *lastcvp = NULL;
658 >        static COLOR            scomp[MAXCSAMP];
659  
660 +        if (cvp->ncc > 3) {                     /* convert spectral pixels */
661 +                SCOLR           sclr;
662 +                SCOLOR          scol;
663 +                COLOR           xyz;
664 +                int             x, n;
665 +                if (lastcvp != cvp) {
666 +                    for (n = cvp->ncc; n--; )
667 +                        spec_cie(scomp[n],
668 +                                cvp->wpt[0] + (cvp->wpt[3] - cvp->wpt[0])*(n+1)/cvp->ncc,
669 +                                cvp->wpt[0] + (cvp->wpt[3] - cvp->wpt[0])*n/cvp->ncc);
670 +                    lastcvp = cvp;
671 +                }
672 +                for (x = 0; x < cvp->xmax; x++) {
673 +                        if (getbinary(sclr, cvp->ncc+1, 1, cvp->rfp) != 1)
674 +                                goto readerr;
675 +                        scolr2scolor(scol, sclr, cvp->ncc);
676 +                        setcolor(cvp->r.colors[x], 0, 0, 0);
677 +                        for (n = cvp->ncc; n--; ) {
678 +                                copycolor(xyz, scomp[n]);
679 +                                scalecolor(xyz, scol[n]);
680 +                                addcolor(cvp->r.colors[x], xyz);
681 +                        }
682 +                }
683 +                return;
684 +        }
685 +        if (freadscan(cvp->r.colors, cvp->xmax, cvp->rfp) >= 0)
686 +                return;
687 + readerr:
688 +        quiterr("error reading Radiance picture");
689 + }
690 +
691 +
692 + static void
693 + Luv2Color(                      /* read/convert/write Luv->COLOR scanline */
694 +        uint32  y
695 + )
696 + {
697 +        int     x;
698 +
699          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT))
700                  quiterr("internal error 1 in Luv2Color");
701  
702 +        if (cvts.pconf != PLANARCONFIG_CONTIG)
703 +                quiterr("cannot handle separate 32-bit color planes");
704 +
705          if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0)
706                  quiterr("error reading TIFF input");
707                                          /* also works for float RGB */
# Line 656 | Line 728 | uint32 y;
728   }
729  
730  
731 < void
732 < RRGGBB2Color(y)                 /* read/convert/write RGB16->COLOR scanline */
733 < uint32  y;
731 > static void
732 > RRGGBB2Color(                   /* read/convert/write RGB16->COLOR scanline */
733 >        uint32  y
734 > )
735   {
736 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
737 <        register double d;
738 <        register int    x;
736 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
737 >        double  d;
738 >        int     x;
739  
740          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_TWRD|C_RFLT))
741                  quiterr("internal error 1 in RRGGBB2Color");
742  
743 +        if (cvts.pconf != PLANARCONFIG_CONTIG)
744 +                quiterr("cannot handle separate 16-bit color planes");
745 +
746          if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0)
747                  quiterr("error reading TIFF input");
748          
# Line 683 | Line 759 | uint32 y;
759                  if (CHK(C_CXFM))
760                          colortrans(cvts.r.colors[x], cvts.cmat,
761                                          cvts.r.colors[x]);
686                if (CHK(C_GAMUT))
687                        clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1],
688                                        CGAMUT_LOWER, cblack, cwhite);
762          }
763          if (cvts.bradj) {
764                  d = pow(2.,(double)cvts.bradj);
# Line 698 | Line 771 | uint32 y;
771   }
772  
773  
774 < void
775 < L2Color(y)                      /* read/convert/write Lfloat->COLOR scanline */
776 < uint32  y;
774 > static void
775 > L2Color(                        /* read/convert/write Lfloat->COLOR scanline */
776 >        uint32  y
777 > )
778   {
779          float   m = pow(2., (double)cvts.bradj);
780 <        register int    x;
780 >        int     x;
781  
782          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY))
783                  quiterr("internal error 1 in L2Color");
# Line 712 | Line 786 | uint32 y;
786                  quiterr("error reading TIFF input");
787                                          /* also works for float greyscale */
788          for (x = cvts.xmax; x--; ) {
789 <                register float  f = cvts.t.fp[x];
789 >                float   f = cvts.t.fp[x];
790                  if (cvts.bradj) f *= m;
791                  setcolor(cvts.r.colors[x], f, f, f);
792          }
# Line 721 | Line 795 | uint32 y;
795   }
796  
797  
798 < void
799 < RGB2Colr(y)                     /* read/convert/write RGB->COLR scanline */
800 < uint32  y;
798 > static void
799 > RGB2Colr(                       /* read/convert/write RGB->COLR scanline */
800 >        uint32  y
801 > )
802   {
803          COLOR   ctmp;
804 <        register int    x;
804 >        int     x;
805  
806          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY))
807                  quiterr("internal error 1 in RGB2Colr");
# Line 777 | Line 852 | readerr:
852   }
853  
854  
855 < void
856 < Gry2Colr(y)                     /* read/convert/write G8->COLR scanline */
857 < uint32  y;
855 > static void
856 > Gry2Colr(                       /* read/convert/write G8->COLR scanline */
857 >        uint32  y
858 > )
859   {
860 <        register int    x;
860 >        int     x;
861  
862          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY)
863                  quiterr("internal error 1 in Gry2Colr");
# Line 803 | Line 879 | uint32 y;
879   }
880  
881  
882 < void
883 < GGry2Color(y)                   /* read/convert/write G16->COLOR scanline */
884 < uint32  y;
882 > static void
883 > GGry2Color(                     /* read/convert/write G16->COLOR scanline */
884 >        uint32  y
885 > )
886   {
887 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
887 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
888          double  m;
889 <        register double d;
890 <        register int    x;
889 >        double  d;
890 >        int     x;
891  
892          if (CHK(C_TFLT|C_TWRD|C_GRY|C_RFLT) != (C_GRY|C_RFLT|C_TWRD))
893                  quiterr("internal error 1 in GGry2Color");
# Line 833 | Line 910 | uint32 y;
910   }
911  
912  
913 < void
914 < Color2GGry(y)                   /* read/convert/write COLOR->G16 scanline */
915 < uint32  y;
913 > static void
914 > Color2GGry(                     /* read/convert/write COLOR->G16 scanline */
915 >        uint32  y
916 > )
917   {
918 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
918 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
919          float   m = pow(2.,(double)cvts.bradj);
920 <        register int    x;
920 >        int     x;
921  
922          if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TWRD|C_GRY))
923                  quiterr("internal error 1 in Color2GGry");
924  
925 <        if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0)
848 <                quiterr("error reading Radiance picture");
925 >        ReadRadScan(&cvts);
926  
927          for (x = cvts.xmax; x--; ) {
928 <                register float  f = m*( CHK(C_XYZE) ?
928 >                float   f = m*( CHK(C_XYZE) ?
929                                                  colval(cvts.r.colors[x],CIEY)
930                                                  : bright(cvts.r.colors[x]) );
931                  if (f <= 0)
# Line 867 | Line 944 | uint32 y;
944   }
945  
946  
947 < void
948 < Color2L(y)                      /* read/convert/write COLOR->Lfloat scanline */
949 < uint32  y;
947 > static void
948 > Color2L(                        /* read/convert/write COLOR->Lfloat scanline */
949 >        uint32  y
950 > )
951   {
952          float   m = pow(2.,(double)cvts.bradj);
953 <        register int    x;
953 >        int     x;
954  
955          if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TFLT|C_GRY))
956                  quiterr("internal error 1 in Color2L");
957  
958 <        if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0)
881 <                quiterr("error reading Radiance picture");
958 >        ReadRadScan(&cvts);
959  
960          for (x = cvts.xmax; x--; )
961                  cvts.t.fp[x] = m*( CHK(C_XYZE) ? colval(cvts.r.colors[x],CIEY)
# Line 889 | Line 966 | uint32 y;
966   }
967  
968  
969 < void
970 < Color2Luv(y)                    /* read/convert/write COLOR->Luv scanline */
971 < uint32  y;
969 > static void
970 > Color2Luv(                      /* read/convert/write COLOR->Luv scanline */
971 >        uint32  y
972 > )
973   {
974 <        register int    x;
974 >        int     x;
975  
976          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT))
977                  quiterr("internal error 1 in Color2Luv");
978  
979 <        if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0)
902 <                quiterr("error reading Radiance picture");
979 >        ReadRadScan(&cvts);
980  
981          if (CHK(C_CXFM))
982                  for (x = cvts.xmax; x--; )
# Line 922 | Line 999 | uint32 y;
999   }
1000  
1001  
1002 < void
1003 < Color2RRGGBB(y)                 /* read/convert/write COLOR->RGB16 scanline */
1004 < uint32  y;
1002 > static void
1003 > Color2RRGGBB(                   /* read/convert/write COLOR->RGB16 scanline */
1004 >        uint32  y
1005 > )
1006   {
1007 <        int     dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01;
1007 >        int     dogamma = (cvts.gamcor < 0.99) | (cvts.gamcor > 1.01);
1008          float   m = pow(2.,(double)cvts.bradj);
1009 <        register int    x, i;
1009 >        int     x, i;
1010  
1011          if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TWRD))
1012                  quiterr("internal error 1 in Color2RRGGBB");
1013  
1014 <        if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0)
937 <                quiterr("error reading Radiance picture");
1014 >        ReadRadScan(&cvts);
1015  
1016 <        for (x = cvts.xmax; x--; )
1016 >        for (x = cvts.xmax; x--; ) {
1017 >            if (CHK(C_CXFM)) {
1018 >                        colortrans(cvts.r.colors[x], cvts.cmat,
1019 >                                        cvts.r.colors[x]);
1020 >                if (CHK(C_GAMUT))
1021 >                        clipgamut(cvts.r.colors[x], bright(cvts.r.colors[x]),
1022 >                                        CGAMUT_LOWER, cblack, cwhite);
1023 >            }
1024              for (i = 3; i--; ) {
1025 <                register float  f = m*colval(cvts.r.colors[x],i);
1025 >                float   f = m*colval(cvts.r.colors[x],i);
1026                  if (f <= 0)
1027                          cvts.t.wp[3*x + i] = 0;
1028                  else if (f >= 1)
# Line 949 | Line 1033 | uint32 y;
1033                  else
1034                          cvts.t.wp[3*x + i] = (int)((float)(1L<<16)*f);
1035              }
1036 +        }
1037  
1038          if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0)
1039                  quiterr("error writing TIFF output");
1040   }
1041  
1042  
1043 < void
1044 < Colr2Gry(y)                     /* read/convert/write COLR->RGB scanline */
1045 < uint32  y;
1043 > static void
1044 > Colr2Gry(                       /* read/convert/write COLR->RGB scanline */
1045 >        uint32  y
1046 > )
1047   {
1048 <        register int    x;
1048 >        int     x;
1049  
1050          if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY)
1051                  quiterr("internal error 1 in Colr2Gry");
1052  
1053 <        if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0)
1053 >        if (fread2colrs(cvts.r.colrs, cvts.xmax, cvts.rfp,
1054 >                                cvts.ncc, cvts.wpt) < 0)
1055                  quiterr("error reading Radiance picture");
1056  
1057          if (cvts.bradj)
# Line 981 | Line 1068 | uint32 y;
1068   }
1069  
1070  
1071 < void
1072 < Colr2RGB(y)                     /* read/convert/write COLR->RGB scanline */
1073 < uint32  y;
1071 > static void
1072 > Colr2RGB(                       /* read/convert/write COLR->RGB scanline */
1073 >        uint32  y
1074 > )
1075   {
1076          COLOR   ctmp;
1077 <        register int    x;
1077 >        int     x;
1078  
1079          if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY))
1080                  quiterr("internal error 1 in Colr2RGB");
1081  
1082 <        if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0)
1082 >        if (fread2colrs(cvts.r.colrs, cvts.xmax, cvts.rfp,
1083 >                                cvts.ncc, cvts.wpt) < 0)
1084                  quiterr("error reading Radiance picture");
1085  
1086          if (cvts.bradj)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines