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

Comparing ray/src/util/rcrop.c (file contents):
Revision 1.2 by greg, Tue Mar 15 01:40:17 2022 UTC vs.
Revision 1.10 by greg, Wed Mar 16 15:50:24 2022 UTC

# Line 18 | Line 18 | char   *progname;              /* global argv[0] */
18  
19   VIEW    vw = STDVIEW;
20   int     gotvw = 0;
21 < char    fmt[MAXFMTLEN] = "Unknown";
21 > char    fmt[MAXFMTLEN] = "ascii";       /* assumed when unspecified */
22   int     ncomp = 0;
23   RESOLU  res;
24   int     rmin, cmin, nrows, ncols;
# Line 79 | Line 79 | colr_copyf(FILE *fp)
79                  return(1);
80   writerr:
81          fputs(progname, stderr);
82 <        fputs(": error writing scanline\n", stderr);
82 >        fputs(": error writing picture\n", stderr);
83          return(0);
84   readerr:
85          fputs(progname, stderr);
86 <        fputs(": error reading scanline\n", stderr);
86 >        fputs(": error reading picture\n", stderr);
87          return(0);
88   }
89  
# Line 91 | Line 91 | readerr:
91   static int
92   binary_copyf(FILE *fp, int asize)
93   {
94 <        const int       skip_thresh = 1024;
94 >        const int       skip_thresh = 8192;
95          const size_t    elsiz = asize*ncomp;
96          const int       width = scanlen(&res);
97          const long      skip_len = (width-ncols)*elsiz;
# Line 199 | Line 199 | io_err:
199          return(0);
200   }
201  
202 + /* Adjust (crop) our view */
203 + static int
204 + adjust_view(void)
205 + {
206 +        double          p0[2], p1[2];
207 +        const char      *err;
208 +
209 +        if (res.rt & YMAJOR) {
210 +                p0[0] = cmin/(double)res.xr;
211 +                p0[1] = rmin/(double)res.yr;
212 +                p1[0] = (cmin+ncols)/(double)res.xr;
213 +                p1[1] = (rmin+nrows)/(double)res.yr;
214 +        } else {
215 +                p0[0] = rmin/(double)res.xr;
216 +                p0[1] = cmin/(double)res.yr;
217 +                p1[0] = (rmin+nrows)/(double)res.xr;
218 +                p1[1] = (cmin+ncols)/(double)res.yr;
219 +        }
220 +        if (res.rt & XDECR) {
221 +                p0[0] = 1. - p0[0];
222 +                p1[0] = 1. - p1[0];
223 +        }
224 +        if (res.rt & YDECR) {
225 +                p0[1] = 1. - p0[1];
226 +                p1[1] = 1. - p1[1];
227 +        }
228 +        err = cropview(&vw, p0[0], p0[1], p1[0], p1[1]);
229 +        if (err) {
230 +                fputs(progname, stderr);
231 +                fputs(": view error - ", stderr);
232 +                fputs(err, stderr);
233 +                fputc('\n', stderr);
234 +                return(0);
235 +        }
236 +        return(1);
237 + }
238 +
239 +
240   /* Main routine -- load header and call processor */
241   int
242   main(int argc, char *argv[])
# Line 234 | Line 272 | main(int argc, char *argv[])
272                  fputs(": cannot open for writing\n", stderr);
273                  return(1);
274          }
275 + #ifdef getc_unlocked            /* avoid stupid semaphores */
276 +        flockfile(fp);
277 +        flockfile(stdout);
278 + #endif
279                                  /* process information header */
280          if (getheader(fp, headline, NULL) < 0) {
281                  fputs(progname, stderr);
# Line 257 | Line 299 | main(int argc, char *argv[])
299                  fputs(": illegal crop\n", stderr);
300                  return(1);
301          }
302 <        printargs(argc, argv, stdout);
303 <        if (gotvw) {
304 <                double          p0[2], p1[2];
263 <                const char      *err;
264 <                if (res.rt & YMAJOR) {
265 <                        p0[0] = cmin/(double)res.xr;
266 <                        p0[1] = rmin/(double)res.yr;
267 <                        p1[0] = (cmin+ncols)/(double)res.xr;
268 <                        p1[1] = (rmin+nrows)/(double)res.yr;
269 <                } else {
270 <                        p0[1] = cmin/(double)res.xr;
271 <                        p0[0] = rmin/(double)res.yr;
272 <                        p1[1] = (cmin+ncols)/(double)res.xr;
273 <                        p1[0] = (rmin+nrows)/(double)res.yr;
274 <                }
275 <                if (res.rt & XDECR) {
276 <                        p0[0] = 1. - p0[0];
277 <                        p1[0] = 1. - p1[0];
278 <                }
279 <                if (res.rt & YDECR) {
280 <                        p0[1] = 1. - p0[1];
281 <                        p1[1] = 1. - p1[1];
282 <                }
283 <                err = cropview(&vw, p0[0], p0[1], p1[0], p1[1]);
284 <                if (err) {
285 <                        fputs(progname, stderr);
286 <                        fputs(": view error - ", stderr);
287 <                        fputs(err, stderr);
288 <                        fputc('\n', stderr);
289 <                        return(1);
290 <                }
291 <                fputs(VIEWSTR, stdout);
302 >        printargs(5, argv, stdout);     /* add to header */
303 >        if (gotvw && adjust_view()) {
304 >                fputs(VIEWSTR, stdout); /* write adjusted view */
305                  fprintview(&vw, stdout);
306                  fputc('\n', stdout);
307          }
308 <        if (gotdims)
308 >        if (gotdims)                    /* dimensions + format */
309                  printf("NROWS=%d\nNCOLS=%d\n", nrows, ncols);
310          if (ncomp)
311                  printf("NCOMP=%d\n", ncomp);
# Line 315 | Line 328 | main(int argc, char *argv[])
328                  asiz = sizeof(float);
329          } else if (!strcmp(fmt, "double")) {
330                  asiz = sizeof(double);
331 +        } else if (!strcmp(fmt, "32-bit_encoded_normal")) {
332 +                asiz = 4;
333 +                ncomp = 1;
334 +        } else if (!strcmp(fmt, "16-bit_encoded_depth")) {
335 +                asiz = 2;
336 +                ncomp = 1;
337          } else if (globmatch(PICFMT, fmt)) {
338                  asiz = -1;
339                  if (!ncomp) ncomp = 3;
340 +                else ncomp *= (ncomp == 3);
341          } else if (strcasecmp(fmt, "ascii")) {
342                  fputs(progname, stderr);
343                  fputs(": unsupported format - ", stderr);
# Line 331 | Line 351 | main(int argc, char *argv[])
351                  return(1);
352          }
353          if (!(asiz < 0 ? colr_copyf(fp) :
354 <                        !asiz ? ascii_copyf(fp) : binary_copyf(fp, asiz)))
354 >                        asiz ? binary_copyf(fp, asiz) : ascii_copyf(fp)))
355                  return(1);
356 +                                        /* need to consume the rest? */
357 +        if (fp == stdin && rmin+nrows < numscans(&res) &&
358 +                        fseek(fp, 0L, SEEK_END) < 0)
359 +                while (getc(fp) != EOF)
360 +                        ;
361          return(0);
362   usage:
363          fputs("Usage: ", stderr);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines