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.12 by greg, Mon Mar 21 20:19:19 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 114 | Line 112 | binary_copyf(FILE *fp, int asize)
112                                  return(0);
113                          }
114                  }
115 <                free(buf);              /* success! */
116 <                return(1);
115 >                free(buf);
116 >                if (fflush(stdout) == EOF)
117 >                        goto writerr;
118 >                return(1);              /* success! */
119          }                               /* else need to read it all... */
120          buf = (char *)malloc(width*elsiz);
121          if (!buf)
# 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 +
230 +        if (!err)
231 +                return(1);      /* success! */
232 +
233 +        fputs(progname, stderr);
234 +        fputs(": view error - ", stderr);
235 +        fputs(err, stderr);
236 +        fputc('\n', stderr);
237 +        return(0);              /* something went wrong */
238 + }
239 +
240 +
241   /* Main routine -- load header and call processor */
242   int
243   main(int argc, char *argv[])
# Line 261 | Line 300 | main(int argc, char *argv[])
300                  fputs(": illegal crop\n", stderr);
301                  return(1);
302          }
303 <        printargs(argc, argv, stdout);
304 <        if (gotvw) {            /* adjust view? */
305 <                double          p0[2], p1[2];
306 <                const char      *err;
307 <                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 <                }
303 >        printargs(5, argv, stdout);     /* add to header */
304 >        if (gotvw && adjust_view()) {
305 >                fputs(VIEWSTR, stdout); /* write adjusted view */
306 >                fprintview(&vw, stdout);
307 >                fputc('\n', stdout);
308          }
309 <        if (gotdims)
309 >        if (gotdims)                    /* dimensions + format */
310                  printf("NROWS=%d\nNCOLS=%d\n", nrows, ncols);
311          if (ncomp)
312                  printf("NCOMP=%d\n", ncomp);
# Line 343 | Line 352 | main(int argc, char *argv[])
352                  return(1);
353          }
354          if (!(asiz < 0 ? colr_copyf(fp) :
355 <                        !asiz ? ascii_copyf(fp) : binary_copyf(fp, asiz)))
355 >                        asiz ? binary_copyf(fp, asiz) : ascii_copyf(fp)))
356                  return(1);
357                                          /* need to consume the rest? */
358          if (fp == stdin && rmin+nrows < numscans(&res) &&

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines