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

Comparing ray/src/px/ra_rgbe.c (file contents):
Revision 2.21 by greg, Sat Dec 28 18:05:14 2019 UTC vs.
Revision 2.26 by greg, Sat Jun 7 05:09:46 2025 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9  
10   #include  "platform.h"
11   #include  "rtio.h"
12 #include  "paths.h"
12   #include  "color.h"
13   #include  "resolu.h"
14  
# Line 21 | Line 20 | int  force = 0;                                /* force file overwrite? */
20   int  findframe = 0;                     /* find a specific frame? */
21   int  frameno = 0;                       /* current frame number */
22   int  fmterr = 0;                        /* got input format error */
23 < char  *headlines;                       /* current header info. */
24 < int  headlen;                           /* current header length */
23 > char  *headlines = NULL;                /* current header info. */
24 > int  headlen1 = 0;                      /* length of initial frame header */
25 > int  headlen = 0;                       /* current header length */
26 > char  fmt[MAXFMTLEN];                   /* input format */
27  
28   char  *progname;
29  
# Line 107 | Line 108 | transfer(                      /* transfer a Radiance picture */
108          if (findframe && findframe < frameno)
109                  return(0);
110                                          /* allocate scanline */
111 <        scanin = (COLR *)tempbuffer(xmax*sizeof(COLR));
111 >        scanin = (COLR *)malloc(xmax*sizeof(COLR));
112          if (scanin == NULL) {
113                  perror(progname);
114                  exit(1);
115          }
116                                          /* skip frame? */
117          if (findframe > frameno) {
118 <                for (y = ymax; y--; )
118 >                if (NCSAMP > 3) {
119 >                        if (fseek(stdin, ymax*xmax*LSCOLR, SEEK_CUR) < 0) {
120 >                                perror(progname);
121 >                                exit(1);
122 >                        }
123 >                } else
124 >                    for (y = ymax; y--; )
125                          if (freadcolrs(scanin, xmax, stdin) < 0) {
126                                  fprintf(stderr,
127                                          "%s: error reading input picture\n",
128                                                  progname);
129                                  exit(1);
130                          }
131 +                free(scanin);
132                  return(1);
133          }
134                                          /* open output file/command */
# Line 150 | Line 158 | transfer(                      /* transfer a Radiance picture */
158                  }
159          }
160          SET_FILE_BINARY(fp);
161 <        dumpheader(fp);                 /* put out header */
161 >        newheader("RADIANCE", fp);              /* put out header */
162 >        dumpheader(fp);
163          fputs(progname, fp);
164          if (bradj)
165                  fprintf(fp, " -e %+d", bradj);
# Line 159 | Line 168 | transfer(                      /* transfer a Radiance picture */
168          fputc('\n', fp);
169          if (bradj)
170                  fputexpos(pow(2.0, (double)bradj), fp);
171 +        if (frameno)
172 +                fprintf(fp, "FRAME=%d\n", frameno);
173 +        if (fmt[0])
174 +                fputformat(fmt, fp);
175          fputc('\n', fp);
176          fputresolu(order, xmax, ymax, fp);
177                                          /* transfer picture */
178          for (y = ymax; y--; ) {
179 <                if (freadcolrs(scanin, xmax, stdin) < 0) {
179 >                if (fread2colrs(scanin, xmax, stdin, NCSAMP, WLPART) < 0) {
180                          fprintf(stderr, "%s: error reading input picture\n",
181                                          progname);
182                          exit(1);
183                  }
184                  if (bradj)
185                          shiftcolrs(scanin, xmax, bradj);
186 <                if (doflat)
187 <                        putbinary((char *)scanin, sizeof(COLR), xmax, fp);
188 <                else
176 <                        fwritecolrs(scanin, xmax, fp);
177 <                if (ferror(fp)) {
178 <                        fprintf(stderr, "%s: error writing output to \"%s\"\n",
179 <                                        progname, oname);
180 <                        exit(1);
181 <                }
186 >                if (doflat ? (putbinary(scanin, sizeof(COLR), xmax, fp) != xmax) :
187 >                                (fwritecolrs(scanin, xmax, fp) < 0))
188 >                        goto writerr;
189          }
190 <                                        /* clean up */
191 <        if (oname[0] == '!')
192 <                pclose(fp);
193 <        else if (ospec != NULL)
190 >        free(scanin);                   /* clean up */
191 >        if (fflush(fp) == EOF)
192 >                goto writerr;
193 >        if (oname[0] == '!') {
194 >                if (pclose(fp) != 0)
195 >                        fprintf(stderr, "%s: warning - bad status from \"%s\"\n",
196 >                                        progname, oname);
197 >        } else if (ospec != NULL)
198                  fclose(fp);
199          return(1);
200 + writerr:
201 +        fprintf(stderr, "%s: error writing output to \"%s\"\n",
202 +                        progname, oname);
203 +        exit(1);
204   }
205  
206  
# Line 195 | Line 210 | addhline(                      /* add a line to our info. header */
210          void    *p
211   )
212   {
198        char    fmt[MAXFMTLEN];
213          int     n;
214  
215 <        if (formatval(fmt, s))
216 <                fmterr += !globmatch(PICFMT, fmt);
217 <        else if (!strncmp(s, "FRAME=", 6))
215 >        if (isheadid(s))
216 >                return(0);
217 >        if (!strncmp(s, "FRAME=", 6)) {
218                  frameno = atoi(s+6);
219 +                return(0);
220 +        }
221 +        if (formatval(fmt, s)) {
222 +                if (!strcmp(fmt, SPECFMT))
223 +                        strcpy(fmt, COLRFMT);
224 +                else
225 +                        fmterr += !globmatch(PICFMT, fmt);
226 +                return(0);
227 +        }
228 +        if (isncomp(s)) {
229 +                NCSAMP = ncompval(s);
230 +                return(NCSAMP - 3);
231 +        }
232 +        if (iswlsplit(s)) {
233 +                wlsplitval(WLPART, s);
234 +                return(0);
235 +        }
236          n = strlen(s);
237          if (headlen)
238                  headlines = (char *)realloc((void *)headlines, headlen+n+1);
# Line 223 | Line 254 | loadheader(                    /* load an info. header into memory */
254   )
255   {
256          fmterr = 0; frameno = 0;
257 <        if (headlen) {                  /* free old header */
258 <                free(headlines);
259 <                headlen = 0;
260 <        }
257 >                                /* revert to initial header length */
258 >        if (!headlen1) headlen1 = headlen;
259 >        else headlen = headlen1;
260 >
261          if (getheader(fp, addhline, NULL) < 0)
262                  return(0);
263          if (fmterr)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines