Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/darbyjohnston/tlRender into…
Browse files Browse the repository at this point in the history
… darby_main_original
  • Loading branch information
ggarra13 committed Feb 22, 2024
2 parents 3083cae + 5a4cdfe commit a59edc8
Show file tree
Hide file tree
Showing 26 changed files with 344 additions and 326 deletions.
72 changes: 72 additions & 0 deletions lib/tlCore/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,78 @@ namespace tl
return out;
}

geom::TriangleMesh2 checkers(
const math::Box2i& box,
const image::Color4f& color0,
const image::Color4f& color1,
const math::Size2i& checkerSize)
{
geom::TriangleMesh2 out;

// X points.
std::vector<int> xs;
int x = box.min.x;
for (; x < box.max.x; x += checkerSize.w)
{
xs.push_back(x);
}
if (x >= box.max.x)
{
xs.push_back(box.max.x);
}

// Y points.
std::vector<int> ys;
int y = box.min.y;
for (; y < box.max.y; y += checkerSize.h)
{
ys.push_back(y);
}
if (y >= box.max.y)
{
ys.push_back(box.max.y);
}

if (!xs.empty() && !ys.empty())
{
// 2D points.
for (int j = 0; j < ys.size(); ++j)
{
for (int i = 0; i < xs.size(); ++i)
{
out.v.push_back(math::Vector2f(xs[i], ys[j]));
}
}

// Colors.
out.c.push_back(math::Vector4f(color0.r, color0.g, color0.b, color0.a));
out.c.push_back(math::Vector4f(color1.r, color1.g, color1.b, color1.a));

// Triangles.
for (int j = 0; j < ys.size() - 1; ++j)
{
for (int i = 0; i < xs.size() - 1; ++i)
{
const int v0 = j * xs.size() + i + 1;
const int v1 = j * xs.size() + (i + 1) + 1;
const int v2 = (j + 1) * xs.size() + (i + 1) + 1;
const int v3 = (j + 1) * xs.size() + i + 1;
const int c = (j + i) % 2 + 1;
out.triangles.push_back({
geom::Vertex2(v0, 0, c),
geom::Vertex2(v1, 0, c),
geom::Vertex2(v2, 0, c) });
out.triangles.push_back({
geom::Vertex2(v2, 0, c),
geom::Vertex2(v3, 0, c),
geom::Vertex2(v0, 0, c) });
}
}
}

return out;
}

TriangleMesh3 sphere(
float radius,
size_t xResolution,
Expand Down
12 changes: 10 additions & 2 deletions lib/tlCore/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <tlCore/Box.h>
#include <tlCore/Color.h>

#include <array>
#include <vector>
Expand Down Expand Up @@ -68,12 +69,19 @@ namespace tl
std::vector<Triangle3> triangles;
};

//! Create a two-dimensional axis aligned box mesh.
//! Create a two-dimensional box mesh.
TriangleMesh2 box(const math::Box2i&, bool flipV = false);

//! Create a two-dimensional axis aligned box mesh.
//! Create a two-dimensional box mesh.
TriangleMesh2 box(const math::Box2f&, bool flipV = false);

//! Create a mesh for drawing checkers.
geom::TriangleMesh2 checkers(
const math::Box2i&,
const image::Color4f& color0,
const image::Color4f& color1,
const math::Size2i& checkerSize);

//! Edge function.
float edge(
const math::Vector2f& p,
Expand Down
52 changes: 38 additions & 14 deletions lib/tlDevice/BMDOutputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace tl
HDRMode hdrMode = HDRMode::FromFile;
image::HDRData hdrData;
timeline::CompareOptions compareOptions;
timeline::BackgroundOptions backgroundOptions;
math::Vector2i viewPos;
double viewZoom = 1.0;
bool frameView = true;
Expand Down Expand Up @@ -327,6 +328,16 @@ namespace tl
p.thread.cv.notify_one();
}

void OutputDevice::setBackgroundOptions(const timeline::BackgroundOptions& value)
{
TLRENDER_P();
{
std::unique_lock<std::mutex> lock(p.mutex.mutex);
p.mutex.backgroundOptions = value;
}
p.thread.cv.notify_one();
}

void OutputDevice::setOverlay(const std::shared_ptr<image::Image>& value)
{
TLRENDER_P();
Expand Down Expand Up @@ -395,7 +406,8 @@ namespace tl
}
device->_p->thread.cv.notify_one();
}
});
},
observer::CallbackAction::Suppress);
p.currentTimeObserver = observer::ValueObserver<otime::RationalTime>::create(
p.players.front()->observeCurrentTime(),
[weak](const otime::RationalTime& value)
Expand All @@ -408,7 +420,8 @@ namespace tl
}
device->_p->thread.cv.notify_one();
}
});
},
observer::CallbackAction::Suppress);
for (size_t i = 0; i < p.players.size(); ++i)
{
if (p.players[i])
Expand All @@ -428,7 +441,8 @@ namespace tl
}
device->_p->thread.cv.notify_one();
}
}));
},
observer::CallbackAction::Suppress));
}
}
p.audioObserver = observer::ListObserver<timeline::AudioData>::create(
Expand All @@ -443,7 +457,8 @@ namespace tl
}
device->_p->thread.cv.notify_one();
}
});
},
observer::CallbackAction::Suppress);
}

{
Expand Down Expand Up @@ -510,6 +525,7 @@ namespace tl
std::vector<timeline::ImageOptions> imageOptions;
std::vector<timeline::DisplayOptions> displayOptions;
timeline::CompareOptions compareOptions;
timeline::BackgroundOptions backgroundOptions;
timeline::Playback playback = timeline::Playback::Stop;
otime::RationalTime currentTime = time::invalidTime;
float volume = 1.F;
Expand All @@ -536,7 +552,7 @@ namespace tl
timeout,
[this, config, enabled,
ocioOptions, lutOptions, imageOptions,
displayOptions, compareOptions,
displayOptions, compareOptions, backgroundOptions,
playback, currentTime,
volume, mute, audioOffset, audioData]
{
Expand All @@ -550,6 +566,7 @@ namespace tl
_p->thread.hdrMode != _p->mutex.hdrMode ||
_p->thread.hdrData != _p->mutex.hdrData ||
compareOptions != _p->mutex.compareOptions ||
backgroundOptions != _p->mutex.backgroundOptions ||
_p->thread.viewPos != _p->mutex.viewPos ||
_p->thread.viewZoom != _p->mutex.viewZoom ||
_p->thread.frameView != _p->mutex.frameView ||
Expand Down Expand Up @@ -584,6 +601,7 @@ namespace tl
p.thread.hdrMode != p.mutex.hdrMode ||
p.thread.hdrData != p.mutex.hdrData ||
compareOptions != p.mutex.compareOptions ||
backgroundOptions != p.mutex.backgroundOptions ||
p.thread.viewPos != p.mutex.viewPos ||
p.thread.viewZoom != p.mutex.viewZoom ||
p.thread.frameView != p.mutex.frameView ||
Expand All @@ -597,6 +615,7 @@ namespace tl
p.thread.hdrMode = p.mutex.hdrMode;
p.thread.hdrData = p.mutex.hdrData;
compareOptions = p.mutex.compareOptions;
backgroundOptions = p.mutex.backgroundOptions;
p.thread.viewPos = p.mutex.viewPos;
p.thread.viewZoom = p.mutex.viewZoom;
p.thread.frameView = p.mutex.frameView;
Expand Down Expand Up @@ -671,7 +690,8 @@ namespace tl
lutOptions,
imageOptions,
displayOptions,
compareOptions);
compareOptions,
backgroundOptions);
}
catch (const std::exception& e)
{
Expand Down Expand Up @@ -916,7 +936,8 @@ namespace tl
const timeline::LUTOptions& lutOptions,
const std::vector<timeline::ImageOptions>& imageOptions,
const std::vector<timeline::DisplayOptions>& displayOptions,
const timeline::CompareOptions& compareOptions)
const timeline::CompareOptions& compareOptions,
const timeline::BackgroundOptions& backgroundOptions)
{
TLRENDER_P();

Expand Down Expand Up @@ -971,13 +992,16 @@ namespace tl
-1.F,
1.F);
p.thread.render->setTransform(pm * vm);

p.thread.render->drawVideo(
p.thread.videoData,
timeline::getBoxes(compareOptions.mode, p.thread.sizes),
imageOptions,
displayOptions,
compareOptions);
if (!p.thread.videoData.empty())
{
p.thread.render->drawVideo(
p.thread.videoData,
timeline::getBoxes(compareOptions.mode, p.thread.sizes),
imageOptions,
displayOptions,
compareOptions,
backgroundOptions);
}
if (p.thread.overlay)
{
p.thread.render->setTransform(pm);
Expand Down
6 changes: 5 additions & 1 deletion lib/tlDevice/BMDOutputDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ namespace tl
//! Set the comparison options.
void setCompareOptions(const timeline::CompareOptions&);

//! Set the background options.
void setBackgroundOptions(const timeline::BackgroundOptions&);

//! Set the overlay.
void setOverlay(const std::shared_ptr<image::Image>&);

Expand Down Expand Up @@ -120,7 +123,8 @@ namespace tl
const timeline::LUTOptions&,
const std::vector<timeline::ImageOptions>&,
const std::vector<timeline::DisplayOptions>&,
const timeline::CompareOptions&);
const timeline::CompareOptions&,
const timeline::BackgroundOptions&);
void _read();

TLRENDER_PRIVATE();
Expand Down
6 changes: 3 additions & 3 deletions lib/tlPlay/ViewportModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ namespace tl
const std::shared_ptr<Settings>&,
const std::shared_ptr<system::Context>&);

//! Get the timeline viewport background options.
//! Get the background options.
const timeline::BackgroundOptions& getBackgroundOptions() const;

//! Observer the timeline viewport background options.
//! Observe the background options.
std::shared_ptr<observer::IValue<timeline::BackgroundOptions> > observeBackgroundOptions() const;

//! Set the timeline viewport background options.
//! Set the background options.
void setBackgroundOptions(const timeline::BackgroundOptions&);

private:
Expand Down
8 changes: 8 additions & 0 deletions lib/tlPlayApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace tl
std::shared_ptr<observer::ValueObserver<timeline::ImageOptions> > imageOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::DisplayOptions> > displayOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::CompareOptions> > compareOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::BackgroundOptions> > backgroundOptionsObserver;
#endif // TLRENDER_BMD
};

Expand Down Expand Up @@ -639,6 +640,13 @@ namespace tl
{
_p->bmdOutputDevice->setCompareOptions(value);
});

p.backgroundOptionsObserver = observer::ValueObserver<timeline::BackgroundOptions>::create(
p.viewportModel->observeBackgroundOptions(),
[this](const timeline::BackgroundOptions& value)
{
_p->bmdOutputDevice->setBackgroundOptions(value);
});
#endif // TLRENDER_BMD
}

Expand Down
16 changes: 8 additions & 8 deletions lib/tlPlayApp/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ namespace tl
std::shared_ptr<observer::ValueObserver<double> > speedObserver2;
std::shared_ptr<observer::ValueObserver<timeline::Playback> > playbackObserver;
std::shared_ptr<observer::ValueObserver<otime::RationalTime> > currentTimeObserver;
std::shared_ptr<observer::ValueObserver<timeline::BackgroundOptions> > backgroundOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::OCIOOptions> > ocioOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::LUTOptions> > lutOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::ImageOptions> > imageOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::DisplayOptions> > displayOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::CompareOptions> > compareOptionsObserver;
std::shared_ptr<observer::ValueObserver<timeline::BackgroundOptions> > backgroundOptionsObserver;
std::shared_ptr<observer::ValueObserver<bool> > muteObserver;
std::shared_ptr<observer::ListObserver<log::Item> > logObserver;
};
Expand Down Expand Up @@ -550,13 +550,6 @@ namespace tl
}
});

p.backgroundOptionsObserver = observer::ValueObserver<timeline::BackgroundOptions>::create(
app->getViewportModel()->observeBackgroundOptions(),
[this](const timeline::BackgroundOptions& value)
{
_p->timelineViewport->setBackgroundOptions(value);
});

p.ocioOptionsObserver = observer::ValueObserver<timeline::OCIOOptions>::create(
app->getColorModel()->observeOCIOOptions(),
[this](const timeline::OCIOOptions& value)
Expand Down Expand Up @@ -602,6 +595,13 @@ namespace tl
_p->timelineViewport->setCompareOptions(value);
});

p.backgroundOptionsObserver = observer::ValueObserver<timeline::BackgroundOptions>::create(
app->getViewportModel()->observeBackgroundOptions(),
[this](const timeline::BackgroundOptions& value)
{
_p->timelineViewport->setBackgroundOptions(value);
});

p.muteObserver = observer::ValueObserver<bool>::create(
app->getAudioModel()->observeMute(),
[this](bool value)
Expand Down
Loading

0 comments on commit a59edc8

Please sign in to comment.