diff --git a/src/oiiotool/oiiotool.cpp b/src/oiiotool/oiiotool.cpp index 580af0a06e..3c65c4c7fe 100644 --- a/src/oiiotool/oiiotool.cpp +++ b/src/oiiotool/oiiotool.cpp @@ -3483,33 +3483,44 @@ class OpResample : public OiiotoolOp { : OiiotoolOp(ot, opname, argc, argv, 1) { } - virtual int compute_subimages() { return 1; } // just the first one virtual void option_defaults() { options["interp"] = "1"; } virtual bool setup() { - // The size argument will be the resulting display (full) window. - const ImageSpec& Aspec(*ir[1]->spec(0, 0)); - ImageSpec newspec = Aspec; - ot.adjust_geometry(args[0], newspec.full_width, newspec.full_height, - newspec.full_x, newspec.full_y, - args[1].c_str() /*size*/, true); - if (newspec.full_width == Aspec.full_width - && newspec.full_height == Aspec.full_height) { + int subimages = compute_subimages(); + bool nochange = true; + std::vector newspecs(subimages); + for (int s = 0; s < subimages; ++s) { + // The size argument will be the resulting display (full) window. + const ImageSpec& Aspec(*ir[1]->spec(s)); + ImageSpec& newspec(newspecs[s]); + newspec = Aspec; + ot.adjust_geometry(args[0], newspec.full_width, newspec.full_height, + newspec.full_x, newspec.full_y, + args[1].c_str() /*size*/, true); + if (newspec.full_width == Aspec.full_width + && newspec.full_height == Aspec.full_height) { + continue; + } + nochange = false; + // Compute corresponding data window. + float wratio = float(newspec.full_width) / float(Aspec.full_width); + float hratio = float(newspec.full_height) + / float(Aspec.full_height); + newspec.x = newspec.full_x + + int(floorf((Aspec.x - Aspec.full_x) * wratio)); + newspec.y = newspec.full_y + + int(floorf((Aspec.y - Aspec.full_y) * hratio)); + newspec.width = int(ceilf(Aspec.width * wratio)); + newspec.height = int(ceilf(Aspec.height * hratio)); + } + if (nochange) { // No change -- pop the temp result and restore the original ot.pop(); ot.push(ir[1]); return false; // nothing more to do } - // Compute corresponding data window. - float wratio = float(newspec.full_width) / float(Aspec.full_width); - float hratio = float(newspec.full_height) / float(Aspec.full_height); - newspec.x = newspec.full_x - + int(floorf((Aspec.x - Aspec.full_x) * wratio)); - newspec.y = newspec.full_y - + int(floorf((Aspec.y - Aspec.full_y) * hratio)); - newspec.width = int(ceilf(Aspec.width * wratio)); - newspec.height = int(ceilf(Aspec.height * hratio)); - (*ir[0])(0, 0).reset(newspec); + for (int s = 0; s < subimages; ++s) + (*ir[0])(s).reset(newspecs[s]); return true; } virtual int impl(ImageBuf** img) @@ -3529,32 +3540,43 @@ class OpResize : public OiiotoolOp { : OiiotoolOp(ot, opname, argc, argv, 1) { } - virtual int compute_subimages() { return 1; } // just the first one virtual bool setup() { - // The size argument will be the resulting display (full) window. - const ImageSpec& Aspec(*ir[1]->spec(0, 0)); - ImageSpec newspec = Aspec; - ot.adjust_geometry(args[0], newspec.full_width, newspec.full_height, - newspec.full_x, newspec.full_y, - args[1].c_str() /*size*/, true); - if (newspec.full_width == Aspec.full_width - && newspec.full_height == Aspec.full_height) { + int subimages = compute_subimages(); + bool nochange = true; + std::vector newspecs(subimages); + for (int s = 0; s < subimages; ++s) { + // The size argument will be the resulting display (full) window. + const ImageSpec& Aspec(*ir[1]->spec(s)); + ImageSpec& newspec(newspecs[s]); + newspec = Aspec; + ot.adjust_geometry(args[0], newspec.full_width, newspec.full_height, + newspec.full_x, newspec.full_y, + args[1].c_str() /*size*/, true); + if (newspec.full_width == Aspec.full_width + && newspec.full_height == Aspec.full_height) { + continue; + } + nochange = false; + // Compute corresponding data window. + float wratio = float(newspec.full_width) / float(Aspec.full_width); + float hratio = float(newspec.full_height) + / float(Aspec.full_height); + newspec.x = newspec.full_x + + int(floorf((Aspec.x - Aspec.full_x) * wratio)); + newspec.y = newspec.full_y + + int(floorf((Aspec.y - Aspec.full_y) * hratio)); + newspec.width = int(ceilf(Aspec.width * wratio)); + newspec.height = int(ceilf(Aspec.height * hratio)); + } + if (nochange) { // No change -- pop the temp result and restore the original ot.pop(); ot.push(ir[1]); return false; // nothing more to do } - // Compute corresponding data window. - float wratio = float(newspec.full_width) / float(Aspec.full_width); - float hratio = float(newspec.full_height) / float(Aspec.full_height); - newspec.x = newspec.full_x - + int(floorf((Aspec.x - Aspec.full_x) * wratio)); - newspec.y = newspec.full_y - + int(floorf((Aspec.y - Aspec.full_y) * hratio)); - newspec.width = int(ceilf(Aspec.width * wratio)); - newspec.height = int(ceilf(Aspec.height * hratio)); - (*ir[0])(0, 0).reset(newspec); + for (int s = 0; s < subimages; ++s) + (*ir[0])(s).reset(newspecs[s]); return true; } virtual int impl(ImageBuf** img) diff --git a/src/oiiotool/oiiotool.h b/src/oiiotool/oiiotool.h index 7f1abc4092..fa881d1169 100644 --- a/src/oiiotool/oiiotool.h +++ b/src/oiiotool/oiiotool.h @@ -661,6 +661,7 @@ class OiiotoolOp { // Read the inputs for (int i = 1; i < nimages(); ++i) ot.read(ir[i]); + subimages = compute_subimages(); // Initialize the output image ir[0].reset(new ImageRec(opname(), subimages)); ot.push(ir[0]);