Skip to content

Commit 9017fcd

Browse files
committed
feat(iconvert): allow -o for convenience
iconvert was the very first command line utility for OIIO, and its syntax was just `iconvert [options] infile outfile`. YEARS later, oiiotool came along, superceding iconvert with 100x the functionality, and also differed by requiring `-o` to specify output file. iconvert still exists for testing and examples -- iconvert uses just plain old ImageInput + ImageOutput straightforwardly, whereas oiiotool is a very complex app that's ImageBuf powered. It's often useful for debugging to test the ImageInput/ImageOutput layer without any extra complication, or to directly see how going through an ImageBuf might differ. The fact that oiiotool requires `-o` to specify an output file, whereas iconvert considers that an error, is a minor annoyance when switching back and forth while debugging, and it's really bugging me. So here it is, a tiny patch to let iconvert silently accept -o, or not, and do the obviously right thing. A little quality of life gift to myself. Signed-off-by: Larry Gritz <lg@larrygritz.com>
1 parent aae20f0 commit 9017fcd

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

src/doc/iconvert.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ certain metadata to the image.
1919

2020
The `iconvert` utility is invoked as follows:
2121

22-
`iconvert` *optiions input output*
22+
`iconvert` *options input output*
23+
`iconvert` *options input* `-o` *output*
2324

2425
Where *input* and *output* name the input image and desired output filename.
2526
The image files may be of any format recognized by OpenImageIO (i.e., for
@@ -147,6 +148,10 @@ keywords, or arbitrary string metadata::
147148

148149
Verbose status messages.
149150

151+
.. describe:: -o filename
152+
153+
Specify the output filename. (Alternately, the `-o` can be dropped.)
154+
150155
.. describe:: --threads n
151156

152157
Use *n* execution threads if it helps to speed up image operations. The

src/iconvert/iconvert.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static float gammaval = 1.0f;
2828
static bool verbose = false;
2929
static int nthreads = 0; // default: use #cores threads if available
3030
static std::vector<std::string> filenames;
31+
static std::string out_filename;
3132
static int tile[3] = { 0, 0, 1 };
3233
static bool scanline = false;
3334
//static bool zfile = false;
@@ -69,10 +70,12 @@ getargs(int argc, char* argv[])
6970
ap.options ("iconvert -- copy images with format conversions and other alterations\n"
7071
OIIO_INTRO_STRING "\n"
7172
"Usage: iconvert [options] inputfile outputfile\n"
73+
" or: iconvert [options] inputfile -o outputfile\n"
7274
" or: iconvert --inplace [options] file...\n",
7375
"%*", parse_files, "",
7476
"--help", &help, "Print help message",
7577
"-v", &verbose, "Verbose status messages",
78+
"-o %s:FILENAME", &out_filename, "Output filename",
7679
"--threads %d:NTHREADS", &nthreads, "Number of threads (default 0 = #cores)",
7780
"-d %s:TYPE", &dataformatname, "Set the output data format to one of:"
7881
"uint8, sint8, uint10, uint12, uint16, sint16, half, float, double",
@@ -115,6 +118,17 @@ getargs(int argc, char* argv[])
115118
return;
116119
}
117120

121+
if (!out_filename.empty() && filenames.size() == 1) {
122+
// -o mode: one positional arg is input, -o specifies output
123+
filenames.push_back(out_filename);
124+
} else if (!out_filename.empty() && filenames.size() != 1) {
125+
OIIO::print(stderr,
126+
"iconvert: -o requires exactly one input filename.\n");
127+
ap.usage();
128+
ap.abort();
129+
return_code = EXIT_FAILURE;
130+
return;
131+
}
118132
if (filenames.size() != 2 && !inplace) {
119133
OIIO::print(
120134
stderr,

testsuite/runtest.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,10 @@ def rw_command (dir: str, filename: str, testwrite: bool=True, use_oiiotool: boo
297297
cmd = ""
298298
if output_filename == "" :
299299
output_filename = filename
300+
tool = "oiiotool" if use_oiiotool else "iconvert"
300301
if testwrite :
301-
if use_oiiotool :
302-
cmd = (cmd + oiio_app("oiiotool") + preargs + " " + fn
303-
+ " " + extraargs + " -o " + output_filename + redirect + ";\n")
304-
else :
305-
cmd = (cmd + oiio_app("iconvert") + preargs + " " + fn
306-
+ " " + extraargs + " " + output_filename + redirect + ";\n")
302+
cmd = (cmd + oiio_app(tool) + preargs + " " + fn
303+
+ " " + extraargs + " -o " + output_filename + redirect + ";\n")
307304
cmd = (cmd + oiio_app("idiff") + " -a " + fn
308305
+ " -fail " + str(failthresh)
309306
+ " -failpercent " + str(failpercent)

0 commit comments

Comments
 (0)