Skip to content
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

perf: oiiotool --line --text --point --box speedups #4518

Merged
merged 3 commits into from
Nov 12, 2024
Merged
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
32 changes: 24 additions & 8 deletions src/oiiotool/oiiotool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ using pvt::print_info_options;
op(); \
}

// Lke OIIOTOOL_OP, but designate the op as "inplace" -- which means it
// uses the input image itself as the destination.
#define OIIOTOOL_INPLACE_OP(name, ninputs, ...) \
static void action_##name(Oiiotool& ot, cspan<const char*> argv) \
{ \
if (ot.postpone_callback(ninputs, action_##name, argv)) \
return; \
OiiotoolOp op(ot, "-" #name, argv, ninputs, __VA_ARGS__); \
op.inplace(true); \
op(); \
}

// Canned setup for an op that uses one image on the stack.
#define UNARY_IMAGE_OP(name, impl) \
OIIOTOOL_OP(name, 1, [](OiiotoolOp& op, span<ImageBuf*> img) { \
Expand Down Expand Up @@ -4940,8 +4952,9 @@ OIIOTOOL_OP(contrast, 1, [&](OiiotoolOp& op, span<ImageBuf*> img) {

// --box
// clang-format off
OIIOTOOL_OP(box, 1, nullptr, ([&](OiiotoolOp& op, span<ImageBuf*> img) {
img[0]->copy(*img[1]);
OIIOTOOL_INPLACE_OP(box, 1, nullptr, ([&](OiiotoolOp& op, span<ImageBuf*> img) {
OIIO_ASSERT(img[0] == img[1]); // Assume we're operating in-place
// img[0]->copy(*img[1]); // what we'd do if we weren't in-place
const ImageSpec& Rspec(img[0]->spec());
int x1, y1, x2, y2;
string_view s(op.args(1));
Expand All @@ -4963,8 +4976,9 @@ OIIOTOOL_OP(box, 1, nullptr, ([&](OiiotoolOp& op, span<ImageBuf*> img) {


// --line
OIIOTOOL_OP(line, 1, [&](OiiotoolOp& op, span<ImageBuf*> img) {
img[0]->copy(*img[1]);
OIIOTOOL_INPLACE_OP(line, 1, [&](OiiotoolOp& op, span<ImageBuf*> img) {
OIIO_ASSERT(img[0] == img[1]); // Assume we're operating in-place
// img[0]->copy(*img[1]); // what we'd do if we weren't in-place
const ImageSpec& Rspec(img[0]->spec());
std::vector<int> points;
Strutil::extract_from_list_string(points, op.args(1));
Expand All @@ -4983,8 +4997,9 @@ OIIOTOOL_OP(line, 1, [&](OiiotoolOp& op, span<ImageBuf*> img) {


// --point
OIIOTOOL_OP(point, 1, [&](OiiotoolOp& op, span<ImageBuf*> img) {
img[0]->copy(*img[1]);
OIIOTOOL_INPLACE_OP(point, 1, [&](OiiotoolOp& op, span<ImageBuf*> img) {
OIIO_ASSERT(img[0] == img[1]); // Assume we're operating in-place
// img[0]->copy(*img[1]); // what we'd do if we weren't in-place
const ImageSpec& Rspec(img[0]->spec());
std::vector<int> points;
Strutil::extract_from_list_string(points, op.args(1));
Expand All @@ -5000,8 +5015,9 @@ OIIOTOOL_OP(point, 1, [&](OiiotoolOp& op, span<ImageBuf*> img) {


// --text
OIIOTOOL_OP(text, 1, [&](OiiotoolOp& op, span<ImageBuf*> img) {
img[0]->copy(*img[1]);
OIIOTOOL_INPLACE_OP(text, 1, [&](OiiotoolOp& op, span<ImageBuf*> img) {
OIIO_ASSERT(img[0] == img[1]); // Assume we're operating in-place
// img[0]->copy(*img[1]); // what we'd do if we weren't in-place
const ImageSpec& Rspec(img[0]->spec());
int x = op.options().get_int("x", Rspec.x + Rspec.width / 2);
int y = op.options().get_int("y", Rspec.y + Rspec.height / 2);
Expand Down
Loading