Skip to content

Simplify oiiotool --resize recent changes #3752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/doc/oiiotool.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3190,10 +3190,6 @@ current top image.
destination image that defines the transformational mapping. This
defaults to the full/display window of the destination image.

`:offset=` [+-] *xoffset* [+-] *yoffset*
An additional offset (after the resize) to adjust the placement of the
result. Fractional pixel offsets are allowed.

`:filter=` *name*
Filter name. The default is `blackman-harris` when increasing
resolution, `lanczos3` when decreasing resolution.
Expand Down
16 changes: 5 additions & 11 deletions src/oiiotool/oiiotool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4325,7 +4325,6 @@ class OpResize final : public OiiotoolOp {
{
from_geom = options("from");
to_geom = options("to");
offset = options("offset");

int subimages = compute_subimages();
bool nochange = true;
Expand Down Expand Up @@ -4399,7 +4398,7 @@ class OpResize final : public OiiotoolOp {
return ok;
}

// Based on requested output size, and optional from/to/offset geometry,
// Based on requested output size, and optional from/to geometry,
// compute (a) newspec, the spec of the output, (b) M, the transformation
// matrix. Return true if the transformation requires a full warp, or
// false if a separable resize will do.
Expand Down Expand Up @@ -4432,12 +4431,8 @@ class OpResize final : public OiiotoolOp {
to_ok = ot.adjust_geometry(args(0), to_w, to_h, to_x, to_y, to_geom,
false);

float offsetx = 0.0f, offsety = 0.0f;
if (offset.size())
scan_offset(offset, offsetx, offsety);

M.makeIdentity();
M.translate(Imath::V2f(to_x + offsetx, to_y + offsety));
M.translate(Imath::V2f(to_x, to_y));
M.scale(Imath::V2f(to_w / from_w, to_h / from_h));
M.translate(Imath::V2f(-from_x, -from_y));

Expand All @@ -4447,7 +4442,6 @@ class OpResize final : public OiiotoolOp {
do_warp |= (to_x != newspec.full_x || to_y != newspec.full_y
|| to_w != newspec.full_width
|| to_h != newspec.full_height);
do_warp |= (offsetx != 0.0f || offsety != 0.0f);

// Safety valve: undocumented "forcewarp" lets you force a warp if
// it's 1, force a resize if it's 0 (default behavior if it's not set).
Expand All @@ -4464,7 +4458,7 @@ class OpResize final : public OiiotoolOp {
Aspec.roi_full(), Aspec.roi(), newspec.roi(),
newspec.roi_full(),
format_resolution(from_w, from_h, from_x, from_y),
format_resolution(to_w, to_h, to_x + offsetx, to_y + offsety),
format_resolution(to_w, to_h, to_x, to_y),
(filtername.size() ? filtername.c_str() : "default"));
print(" M = {}\n", M);
print(" implementing with {}\n", do_warp ? "warp" : "resize");
Expand All @@ -4473,7 +4467,7 @@ class OpResize final : public OiiotoolOp {
}

private:
std::string from_geom, to_geom, offset;
std::string from_geom, to_geom;
std::vector<Imath::M33f> M;
std::vector<bool> do_warp;
};
Expand Down Expand Up @@ -6872,7 +6866,7 @@ Oiiotool::getargs(int argc, char* argv[])
.help("Resample (640x480, 50%) (options: interp=0)")
.action(action_resample);
ap.arg("--resize %s:GEOM")
.help("Resize (640x480, 50%) (options: from=<geom>, to=<geom>, offset=<+x+y> filter=%s, highlightcomp=%d, edgeclamp=%d)")
.help("Resize (640x480, 50%) (options: from=<geom>, to=<geom>, filter=%s, highlightcomp=%d, edgeclamp=%d)")
.action(action_resize);
ap.arg("--fit %s:GEOM")
.help("Resize to fit within a window size (options: filter=%s, pad=%d, fillmode=%s, exact=%d, highlightcomp=%d)")
Expand Down
2 changes: 1 addition & 1 deletion testsuite/oiiotool-xform/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def make_test_pattern1 (filename, xres=288, yres=216) :
# test resize with non-default from/to/offset
command += oiiotool ("../common/grid.tif --resize:from=200x200+300+300 64x64 -o resizefrom.tif")
command += oiiotool ("../common/grid.tif --resize:from=200x200+300+300:to=32x32 64x64 -o resizefromto.tif")
command += oiiotool ("../common/grid.tif --resize:from=200x200+300+300:to=32x32:offset=+5-5 64x64 -o resizefromtooffset.tif")
command += oiiotool ("../common/grid.tif --resize:from=200x200+300+300:to=32x32+5-5 64x64 -o resizefromtooffset.tif")

# test resize with nonzero origin. Save to exr to make extra sure we have
# the display and data windows correct.
Expand Down