Skip to content

Commit

Permalink
oiiotool --warp improvements (#3341)
Browse files Browse the repository at this point in the history
* New "wrap" optional modifier lets you specify which wrap mode to pass
  to IBA::warp().

* fix typo in error message.
  • Loading branch information
lgritz authored Feb 18, 2022
1 parent a53399d commit e800c05
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/doc/oiiotool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3129,8 +3129,8 @@ current top image.
match on aspect ratio and centering (partial pixel shift if
necessary), whereas the default (0) will only preserve aspect ratio
and centering to the precision of a whole pixel.
- `wrap=` *w* : For "exact" aspect ratio fitting, this determines the
wrap mode used for the resizing kernel (default: `black`, other
- `wrap=` *wrapmode* : For "exact" aspect ratio fitting, this determines
the wrap mode used for the resizing kernel (default: `black`, other
choices include `clamp`, `periodic`, `mirror`).

Examples::
Expand Down Expand Up @@ -3256,6 +3256,10 @@ current top image.
If nonzero, recompute the pixel data window to exactly hold the
transformed image (default=0).

`:wrap=` *wrapmode*
The wrap mode to use when sampling the image for the warp. The default
is `black`; other choices include `clamp`, `periodic`, `mirror`.

`:subimages=` *indices-or-names*
Include/exclude subimages (see :ref:`sec-oiiotool-subimage-modifier`).

Expand Down
6 changes: 4 additions & 2 deletions src/oiiotool/oiiotool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3645,10 +3645,11 @@ OIIOTOOL_OP(warp, 1, [](OiiotoolOp& op, span<ImageBuf*> img) {
std::string filtername = op.options()["filter"];
bool highlightcomp = op.options().get_int("highlightcomp");
bool recompute_roi = op.options().get_int("recompute_roi");
std::string wrapname = op.options().get_string("wrap", "default");
std::vector<float> M(9);
if (Strutil::extract_from_list_string(M, op.args(1)) != 9) {
ot.error(op.opname(),
"expected 9 comma-separatd floats to form a 3x3 matrix");
"expected 9 comma-separated floats to form a 3x3 matrix");
return false;
}
bool ok = true;
Expand All @@ -3661,8 +3662,9 @@ OIIOTOOL_OP(warp, 1, [](OiiotoolOp& op, span<ImageBuf*> img) {
ok &= ImageBufAlgo::rangecompress(tmpimg, *src);
src = &tmpimg;
}
ImageBuf::WrapMode wrap = ImageBuf::WrapMode_from_string(wrapname);
ok &= ImageBufAlgo::warp(*img[0], *src, *(Imath::M33f*)&M[0], filtername,
0.0f, recompute_roi, ImageBuf::WrapDefault);
0.0f, recompute_roi, wrap);
if (highlightcomp && ok) {
// re-expand the range in place
ok &= ImageBufAlgo::rangeexpand(*img[0], *img[0]);
Expand Down

0 comments on commit e800c05

Please sign in to comment.