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.19 by greg, Thu Aug 18 00:52:48 2016 UTC vs.
Revision 2.24 by greg, Tue Apr 22 04:45:25 2025 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines