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.7 by greg, Tue Mar 15 20:21:18 2022 UTC vs.
Revision 1.11 by greg, Wed Mar 16 16:48:39 2022 UTC

# Line 12 | Line 12 | static const char RCSid[] = "$Id$";
12   #include "fvect.h"
13   #include "view.h"
14  
15 #define MAXWORD         64      /* maximum word (number) length */
16
15   char    *progname;              /* global argv[0] */
16  
17   VIEW    vw = STDVIEW;
18   int     gotvw = 0;
19 < char    fmt[MAXFMTLEN] = "Unknown";
19 > char    fmt[MAXFMTLEN] = "ascii";       /* assumed when unspecified */
20   int     ncomp = 0;
21   RESOLU  res;
22   int     rmin, cmin, nrows, ncols;
# Line 199 | Line 197 | io_err:
197          return(0);
198   }
199  
200 + /* Adjust (crop) our view */
201 + static int
202 + adjust_view(void)
203 + {
204 +        double          p0[2], p1[2];
205 +        const char      *err;
206 +
207 +        if (res.rt & YMAJOR) {
208 +                p0[0] = cmin/(double)res.xr;
209 +                p0[1] = rmin/(double)res.yr;
210 +                p1[0] = (cmin+ncols)/(double)res.xr;
211 +                p1[1] = (rmin+nrows)/(double)res.yr;
212 +        } else {
213 +                p0[0] = rmin/(double)res.xr;
214 +                p0[1] = cmin/(double)res.yr;
215 +                p1[0] = (rmin+nrows)/(double)res.xr;
216 +                p1[1] = (cmin+ncols)/(double)res.yr;
217 +        }
218 +        if (res.rt & XDECR) {
219 +                p0[0] = 1. - p0[0];
220 +                p1[0] = 1. - p1[0];
221 +        }
222 +        if (res.rt & YDECR) {
223 +                p0[1] = 1. - p0[1];
224 +                p1[1] = 1. - p1[1];
225 +        }
226 +        err = cropview(&vw, p0[0], p0[1], p1[0], p1[1]);
227 +
228 +        if (!err)
229 +                return(1);      /* success! */
230 +
231 +        fputs(progname, stderr);
232 +        fputs(": view error - ", stderr);
233 +        fputs(err, stderr);
234 +        fputc('\n', stderr);
235 +        return(0);              /* something went wrong */
236 + }
237 +
238 +
239   /* Main routine -- load header and call processor */
240   int
241   main(int argc, char *argv[])
# Line 261 | Line 298 | main(int argc, char *argv[])
298                  fputs(": illegal crop\n", stderr);
299                  return(1);
300          }
301 <        printargs(argc, argv, stdout);
302 <        if (gotvw) {            /* adjust view? */
303 <                double          p0[2], p1[2];
304 <                const char      *err;
305 <                if (res.rt & YMAJOR) {
269 <                        p0[0] = cmin/(double)res.xr;
270 <                        p0[1] = rmin/(double)res.yr;
271 <                        p1[0] = (cmin+ncols)/(double)res.xr;
272 <                        p1[1] = (rmin+nrows)/(double)res.yr;
273 <                } else {
274 <                        p0[1] = cmin/(double)res.xr;
275 <                        p0[0] = rmin/(double)res.yr;
276 <                        p1[1] = (cmin+ncols)/(double)res.xr;
277 <                        p1[0] = (rmin+nrows)/(double)res.yr;
278 <                }
279 <                if (res.rt & XDECR) {
280 <                        p0[0] = 1. - p0[0];
281 <                        p1[0] = 1. - p1[0];
282 <                }
283 <                if (res.rt & YDECR) {
284 <                        p0[1] = 1. - p0[1];
285 <                        p1[1] = 1. - p1[1];
286 <                }
287 <                err = cropview(&vw, p0[0], p0[1], p1[0], p1[1]);
288 <                if (err) {
289 <                        fputs(progname, stderr);
290 <                        fputs(": view error - ", stderr);
291 <                        fputs(err, stderr);
292 <                        fputc('\n', stderr);
293 <                        return(1);
294 <                } else {
295 <                        fputs(VIEWSTR, stdout);
296 <                        fprintview(&vw, stdout);
297 <                        fputc('\n', stdout);
298 <                }
301 >        printargs(5, argv, stdout);     /* add to header */
302 >        if (gotvw && adjust_view()) {
303 >                fputs(VIEWSTR, stdout); /* write adjusted view */
304 >                fprintview(&vw, stdout);
305 >                fputc('\n', stdout);
306          }
307 <        if (gotdims)
307 >        if (gotdims)                    /* dimensions + format */
308                  printf("NROWS=%d\nNCOLS=%d\n", nrows, ncols);
309          if (ncomp)
310                  printf("NCOMP=%d\n", ncomp);
# Line 343 | Line 350 | main(int argc, char *argv[])
350                  return(1);
351          }
352          if (!(asiz < 0 ? colr_copyf(fp) :
353 <                        !asiz ? ascii_copyf(fp) : binary_copyf(fp, asiz)))
353 >                        asiz ? binary_copyf(fp, asiz) : ascii_copyf(fp)))
354                  return(1);
355                                          /* need to consume the rest? */
356          if (fp == stdin && rmin+nrows < numscans(&res) &&

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines