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

Refactoring and time warp fixes #33

Merged
merged 10 commits into from
Dec 17, 2024
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
18 changes: 8 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ else()
endif()

set(TOUCAN_PLUGINS
toucanColorSpace
toucanDraw
toucanFilter
toucanGenerator
toucanTransform
toucanTransition)
toucanColorPlugin
toucanDrawPlugin
toucanFilterPlugin
toucanGeneratorPlugin
toucanTransformPlugin
toucanTransitionPlugin)

enable_testing()

Expand All @@ -66,10 +66,8 @@ find_package(OpenColorIO)
find_package(OpenImageIO)
find_package(OTIO)
find_package(OpenFX)
if(toucan_VIEW)
find_package(lunasvg)
find_package(dtk)
endif()
find_package(lunasvg)
find_package(dtk)

include_directories(lib)
include_directories(tests)
Expand Down
122 changes: 39 additions & 83 deletions bin/toucan-filmstrip/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,67 @@

#include "App.h"

#include <toucan/Util.h>
#include <toucanRender/Util.h>

#include <dtk/core/CmdLine.h>
#include <dtk/core/Time.h>

#include <OpenImageIO/imagebufalgo.h>

namespace toucan
{
App::App(std::vector<std::string>& argv)
void App::_init(
const std::shared_ptr<dtk::Context>& context,
std::vector<std::string>& argv)
{
_exe = argv.front();
argv.erase(argv.begin());

_args.list.push_back(std::make_shared<CmdLineValueArg<std::string> >(
std::vector<std::shared_ptr<dtk::ICmdLineArg> > args;
args.push_back(dtk::CmdLineValueArg<std::string>::create(
_args.input,
"input",
"Input .otio file."));
auto outArg = std::make_shared<CmdLineValueArg<std::string> >(
auto outArg = dtk::CmdLineValueArg<std::string>::create(
_args.output,
"output",
"Output image file.");
_args.list.push_back(outArg);
args.push_back(outArg);

_options.list.push_back(std::make_shared<CmdLineFlagOption>(
std::vector<std::shared_ptr<dtk::ICmdLineOption> > options;
options.push_back(dtk::CmdLineFlagOption::create(
_options.verbose,
std::vector<std::string>{ "-v" },
"Print verbose output."));
_options.list.push_back(std::make_shared<CmdLineFlagOption>(
options.push_back(dtk::CmdLineFlagOption::create(
_options.help,
std::vector<std::string>{ "-h" },
"Print help."));

if (!argv.empty())
{
for (const auto& option : _options.list)
{
option->parse(argv);
}
if (!_options.help)
{
for (const auto& arg : _args.list)
{
arg->parse(argv);
}
if (argv.size())
{
_options.help = true;
}
}
}
else
{
_options.help = true;
}
IApp::_init(
context,
argv,
"toucan-filmstrip",
"Render timeline files into filmstrips",
args,
options);
}


App::App()
{}

App::~App()
{}

std::shared_ptr<App> App::create(
const std::shared_ptr<dtk::Context>&context,
std::vector<std::string>&argv)
{
auto out = std::shared_ptr<App>(new App);
out->_init(context, argv);
return out;
}

int App::run()
void App::run()
{
if (_options.help)
{
_printHelp();
return 1;
}

const std::filesystem::path parentPath = std::filesystem::path(_exe).parent_path();
const std::filesystem::path parentPath = std::filesystem::path(getExeName()).parent_path();
const std::filesystem::path inputPath(_args.input);
const std::filesystem::path outputPath(_args.output);
const auto outputSplit = splitFileNameNumber(outputPath.stem().string());
Expand All @@ -84,17 +79,10 @@ namespace toucan
const int frames = timeRange.duration().value();

// Create the image graph.
std::shared_ptr<MessageLog> log;
if (_options.verbose)
{
log = std::make_shared<MessageLog>();
}
ImageGraphOptions imageGraphOptions;
imageGraphOptions.log = log;
_graph = std::make_shared<ImageGraph>(
_context,
inputPath.parent_path(),
_timelineWrapper,
imageGraphOptions);
_timelineWrapper);
const IMATH_NAMESPACE::V2d imageSize = _graph->getImageSize();

// Create the image host.
Expand All @@ -105,11 +93,7 @@ namespace toucan
#else // _WINDOWS
searchPath.push_back(parentPath / ".." / "..");
#endif // _WINDOWS
ImageEffectHostOptions imageHostOptions;
imageHostOptions.log = log;
_host = std::make_shared<ImageEffectHost>(
searchPath,
imageHostOptions);
_host = std::make_shared<ImageEffectHost>(_context, searchPath);

// Initialize the filmstrip.
OIIO::ImageBuf filmstripBuf;
Expand Down Expand Up @@ -162,34 +146,6 @@ namespace toucan

// Write the image.
filmstripBuf.write(outputPath.string());

return 0;
}

void App::_printHelp()
{
std::cout << "Usage:" << std::endl;
std::cout << std::endl;
std::cout << " toucan-filmstrip (input) (output) [options...]" << std::endl;
std::cout << std::endl;
std::cout << "Arguments:" << std::endl;
std::cout << std::endl;
for (const auto& arg : _args.list)
{
std::cout << " " << arg->getName() << " - " << arg->getHelp() << std::endl;
std::cout << std::endl;
}
std::cout << std::endl;
std::cout << "Options:" << std::endl;
std::cout << std::endl;
for (const auto& option : _options.list)
{
for (const auto& line : option->getHelp())
{
std::cout << " " << line << std::endl;
}
std::cout << std::endl;
}
}
}

32 changes: 17 additions & 15 deletions bin/toucan-filmstrip/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,46 @@

#pragma once

#include <toucanRender/ImageEffectHost.h>
#include <toucanRender/ImageGraph.h>
#include <toucanRender/TimelineWrapper.h>

#include <toucan/CmdLine.h>
#include <toucan/ImageEffectHost.h>
#include <toucan/ImageGraph.h>
#include <toucan/TimelineWrapper.h>
#include <dtk/core/IApp.h>

#include <OpenImageIO/imagebuf.h>

namespace toucan
{
class App : public std::enable_shared_from_this<App>
class App : public dtk::IApp
{
protected:
void _init(
const std::shared_ptr<dtk::Context>&,
std::vector<std::string>&);

App();

public:
App(std::vector<std::string>&);

~App();

static std::shared_ptr<App> create(
const std::shared_ptr<dtk::Context>&,
std::vector<std::string>&);

int run();
void run() override;

private:
void _printHelp();

std::string _exe;

struct Args
{
std::string input;
std::string output;
std::vector<std::shared_ptr<ICmdLineArg> > list;
};
Args _args;

struct Options
{
bool verbose = false;
bool help = false;
std::vector<std::shared_ptr<ICmdLineOption> > list;
};
Options _options;

Expand All @@ -48,4 +51,3 @@ namespace toucan
std::shared_ptr<ImageEffectHost> _host;
};
}

2 changes: 1 addition & 1 deletion bin/toucan-filmstrip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(SOURCE
main.cpp)

add_executable(toucan-filmstrip ${HEADERS} ${SOURCE})
target_link_libraries(toucan-filmstrip toucan)
target_link_libraries(toucan-filmstrip toucanRender)
set_target_properties(toucan-filmstrip PROPERTIES FOLDER bin)
add_dependencies(toucan-filmstrip ${TOUCAN_PLUGINS})

Expand Down
10 changes: 8 additions & 2 deletions bin/toucan-filmstrip/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "App.h"

#include <dtk/core/Context.h>
#include <dtk/core/Init.h>

#include <iostream>

using namespace toucan;
Expand All @@ -17,8 +20,11 @@ int main(int argc, char** argv)
}
try
{
auto app = std::make_shared<App>(args);
out = app->run();
auto context = dtk::Context::create();
dtk::coreInit(context);
auto app = App::create(context, args);
app->run();
out = app->getExit();
}
catch (const std::exception& e)
{
Expand Down
Loading
Loading