Skip to content

Commit 0d2e990

Browse files
authored
feat(idiff): allow users to specify a directory as the 2nd argument (#4015)
Teach `idiff` to accept a directory as the 2nd argument. Fixes #4009 ## Tests Functional tests for `idiff` don't currently exist. Manual testing verifies it works as advertised. --------- Signed-off-by: David Aguilar <davvid@gmail.com>
1 parent bda5141 commit 0d2e990

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/doc/idiff.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ Using `idiff`
2626

2727
The `idiff` utility is invoked as follows:
2828

29-
`idiff` [*options*] *image1* *image2*
29+
`idiff` [*options*] *input1* *input2|directory*
3030

3131
Where *input1* and *input2* are the names of two image files that should be
3232
compared. They may be of any format recognized by OpenImageIO (i.e., for
3333
which image-reading plugins are available).
3434

35+
When a *directory* is specified instead of *input2* then `idiff` will use
36+
the same-named file as *input1* in the specified directory.
37+
3538
If the two input images are not the same resolutions, or do not have the
3639
same number of channels, the comparison will return FAILURE immediately and
3740
will not attempt to compare the pixels of the two images. If they are the

src/idiff/idiff.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ getargs(int argc, char* argv[])
4343
ArgParse ap;
4444
ap.intro("idiff -- compare two images\n"
4545
OIIO_INTRO_STRING)
46-
.usage("idiff [options] image1 image2")
46+
.usage("idiff [options] <image1> <image2 | directory>")
4747
.add_version(OIIO_VERSION_STRING)
4848
.print_defaults(true);
4949

@@ -169,6 +169,24 @@ print_subimage(ImageBuf& img0, int subimage, int miplevel)
169169
}
170170

171171

172+
// Append the filename from "first" when "second" is a directory.
173+
// "second" is an output variable and modified in-place.
174+
inline void
175+
add_filename_to_directory(const std::string& first, std::string& second)
176+
{
177+
if (Filesystem::is_directory(second)) {
178+
char last_byte = second.at(second.size() - 1);
179+
if (last_byte != '/' && last_byte != '\\') {
180+
#if defined(_MSC_VER)
181+
second += '\\';
182+
#else
183+
second += '/';
184+
#endif
185+
}
186+
second += Filesystem::filename(first);
187+
}
188+
}
189+
172190

173191
int
174192
main(int argc, char* argv[])
@@ -181,7 +199,9 @@ main(int argc, char* argv[])
181199
ArgParse ap = getargs(argc, argv);
182200

183201
std::vector<std::string> filenames = ap["filename"].as_vec<std::string>();
184-
if (filenames.size() != 2) {
202+
if (filenames.size() == 2) {
203+
add_filename_to_directory(filenames[0], filenames[1]);
204+
} else {
185205
print(stderr, "idiff: Must have two input filenames.\n");
186206
print(stderr, "> {}\n", Strutil::join(filenames, ", "));
187207
ap.usage();

0 commit comments

Comments
 (0)