Skip to content

Commit

Permalink
feat(rcrop): Negative counts for #rows or #columns cut from the ends
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregungory committed May 17, 2024
1 parent 7fade2f commit 373a990
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion doc/man/man1/rcrop.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" RCSid "$Id: rcrop.1,v 1.8 2023/12/12 16:31:45 greg Exp $"
.\" RCSid "$Id: rcrop.1,v 1.9 2024/05/17 20:50:57 greg Exp $"
.TH RCROP 1 3/14/2022 RADIANCE
.SH NAME
rcrop - crop RADIANCE matrix or picture
Expand Down Expand Up @@ -35,6 +35,8 @@ If a 0 value is specified for the number of rows to copy, then all rows
will be copied, starting from row0.
Similarly, a 0 value for the number of columns to copy implies all
columns >= col0 will be copied.
A negative count for the number of rows or columns cuts the
corresponding amount off the end(s).
.PP
Using
.I rcrop
Expand Down
2 changes: 2 additions & 0 deletions doc/notes/ReleaseNotes
Original file line number Diff line number Diff line change
Expand Up @@ -2693,3 +2693,5 @@ scenes with sharp cut-offs.

Added -i option to gendaymtx to match -i option of gendaylit.
Thanks to Yongqing for initial implementation.

Changed rcrop so negative #rows or #cols counts back from end.
12 changes: 6 additions & 6 deletions src/util/rcrop.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: rcrop.c,v 1.15 2024/05/16 18:59:19 greg Exp $";
static const char RCSid[] = "$Id: rcrop.c,v 1.16 2024/05/17 20:50:57 greg Exp $";
#endif
/*
* rcrop.c - crop a Radiance picture or matrix data
Expand Down Expand Up @@ -269,7 +269,7 @@ main(int argc, char *argv[])
cmin = atoi(argv[2]);
nrows = atoi(argv[3]);
ncols = atoi(argv[4]);
if ((rmin < 0) | (cmin < 0) | (nrows < 0) | (ncols < 0))
if ((rmin < 0) | (cmin < 0))
goto usage;
if (argc <= 5)
SET_FILE_BINARY(fp);
Expand Down Expand Up @@ -301,10 +301,10 @@ main(int argc, char *argv[])
fputs(": missing input dimensions\n", stderr);
return(1);
}
if (!nrows)
nrows = numscans(&res) - rmin;
if (!ncols)
ncols = scanlen(&res) - cmin;
if (nrows <= 0 )
nrows += numscans(&res) - rmin;
if (ncols <= 0)
ncols += scanlen(&res) - cmin;
if ((nrows <= 0) | (ncols <= 0) |
(rmin+nrows > numscans(&res)) |
(cmin+ncols > scanlen(&res))) {
Expand Down

0 comments on commit 373a990

Please sign in to comment.