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.6 by greg, Tue Mar 15 15:01:22 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 234 | Line 271 | main(int argc, char *argv[])
271                  fputs(": cannot open for writing\n", stderr);
272                  return(1);
273          }
274 + #ifdef getc_unlocked            /* avoid stupid semaphores */
275 +        flockfile(fp);
276 +        flockfile(stdout);
277 + #endif
278                                  /* process information header */
279          if (getheader(fp, headline, NULL) < 0) {
280                  fputs(progname, stderr);
# Line 257 | 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) {
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 <                } else {
291 <                        fputs(VIEWSTR, stdout);
292 <                        fprintview(&vw, stdout);
293 <                        fputc('\n', stdout);
294 <                }
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 339 | 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