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.9 by greg, Wed Mar 16 01:51:16 2022 UTC vs.
Revision 1.13 by greg, Thu Apr 7 16:58:30 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;
# Line 100 | Line 98 | binary_copyf(FILE *fp, int asize)
98                                          /* check if fseek() useful */
99          if (skip_len > skip_thresh &&
100                          fseek(fp, (rmin*width + cmin)*elsiz, SEEK_CUR) == 0) {
101 +                off_t   curpos;
102                  buf = (char *)malloc(ncols*elsiz);
103                  if (!buf)
104                          goto memerr;
105 + #ifdef NON_POSIX
106                  for (y = nrows; y-- > 0; ) {
107                          if (getbinary(buf, elsiz, ncols, fp) != ncols)
108                                  goto readerr;
# Line 114 | Line 114 | binary_copyf(FILE *fp, int asize)
114                                  return(0);
115                          }
116                  }
117 <                free(buf);              /* success! */
118 <                return(1);
117 > #else
118 >                curpos = ftello(fp);
119 >                for (y = nrows; y-- > 0; curpos += width*elsiz) {
120 >                        if (pread(fileno(fp), buf, ncols*elsiz,
121 >                                                curpos) != ncols*elsiz)
122 >                                goto readerr;
123 >                        if (putbinary(buf, elsiz, ncols, stdout) != ncols)
124 >                                goto writerr;
125 >                }
126 > #endif
127 >                free(buf);
128 >                if (fflush(stdout) == EOF)
129 >                        goto writerr;
130 >                return(1);              /* success! */
131          }                               /* else need to read it all... */
132          buf = (char *)malloc(width*elsiz);
133          if (!buf)
# Line 199 | Line 211 | io_err:
211          return(0);
212   }
213  
214 + /* Adjust (crop) our view */
215 + static int
216 + adjust_view(void)
217 + {
218 +        double          p0[2], p1[2];
219 +        const char      *err;
220 +
221 +        if (res.rt & YMAJOR) {
222 +                p0[0] = cmin/(double)res.xr;
223 +                p0[1] = rmin/(double)res.yr;
224 +                p1[0] = (cmin+ncols)/(double)res.xr;
225 +                p1[1] = (rmin+nrows)/(double)res.yr;
226 +        } else {
227 +                p0[0] = rmin/(double)res.xr;
228 +                p0[1] = cmin/(double)res.yr;
229 +                p1[0] = (rmin+nrows)/(double)res.xr;
230 +                p1[1] = (cmin+ncols)/(double)res.yr;
231 +        }
232 +        if (res.rt & XDECR) {
233 +                p0[0] = 1. - p0[0];
234 +                p1[0] = 1. - p1[0];
235 +        }
236 +        if (res.rt & YDECR) {
237 +                p0[1] = 1. - p0[1];
238 +                p1[1] = 1. - p1[1];
239 +        }
240 +        err = cropview(&vw, p0[0], p0[1], p1[0], p1[1]);
241 +
242 +        if (!err)
243 +                return(1);      /* success! */
244 +
245 +        fputs(progname, stderr);
246 +        fputs(": view error - ", stderr);
247 +        fputs(err, stderr);
248 +        fputc('\n', stderr);
249 +        return(0);              /* something went wrong */
250 + }
251 +
252 +
253   /* Main routine -- load header and call processor */
254   int
255   main(int argc, char *argv[])
# Line 261 | Line 312 | main(int argc, char *argv[])
312                  fputs(": illegal crop\n", stderr);
313                  return(1);
314          }
315 <        printargs(5, argv, stdout);
316 <        if (gotvw) {            /* adjust view? */
317 <                double          p0[2], p1[2];
318 <                const char      *err;
319 <                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[0] = rmin/(double)res.xr;
275 <                        p0[1] = cmin/(double)res.yr;
276 <                        p1[0] = (rmin+nrows)/(double)res.xr;
277 <                        p1[1] = (cmin+ncols)/(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 <                }
315 >        printargs(5, argv, stdout);     /* add to header */
316 >        if (gotvw && adjust_view()) {
317 >                fputs(VIEWSTR, stdout); /* write adjusted view */
318 >                fprintview(&vw, stdout);
319 >                fputc('\n', stdout);
320          }
321 <        if (gotdims)
321 >        if (gotdims)                    /* dimensions + format */
322                  printf("NROWS=%d\nNCOLS=%d\n", nrows, ncols);
323          if (ncomp)
324                  printf("NCOMP=%d\n", ncomp);
# Line 343 | Line 364 | main(int argc, char *argv[])
364                  return(1);
365          }
366          if (!(asiz < 0 ? colr_copyf(fp) :
367 <                        !asiz ? ascii_copyf(fp) : binary_copyf(fp, asiz)))
367 >                        asiz ? binary_copyf(fp, asiz) : ascii_copyf(fp)))
368                  return(1);
369                                          /* need to consume the rest? */
370          if (fp == stdin && rmin+nrows < numscans(&res) &&

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines