Skip to content

Commit

Permalink
Add video output range
Browse files Browse the repository at this point in the history
  • Loading branch information
darbyjohnston committed Aug 15, 2022
1 parent 908ecad commit d4f302f
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 4 deletions.
17 changes: 17 additions & 0 deletions lib/tlDevice/BMDOutputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include <iostream>
#include <tuple>

#if defined(__linux__)
typedef bool BOOL;
#endif

namespace tl
{
namespace device
Expand Down Expand Up @@ -220,6 +224,14 @@ namespace tl
}
}

DLConfigWrapper::~DLConfigWrapper()
{
if (p)
{
p->Release();
}
}

DLOutputWrapper::~DLOutputWrapper()
{
if (p)
Expand Down Expand Up @@ -327,6 +339,11 @@ namespace tl
}
}

if (_dl.p->QueryInterface(IID_IDeckLinkConfiguration, (void**)&_dlConfig) != S_OK)
{
throw std::runtime_error("Configuration device not found");
}

if (_dl.p->QueryInterface(IID_IDeckLinkOutput, (void**)&_dlOutput) != S_OK)
{
throw std::runtime_error("Output device not found");
Expand Down
10 changes: 10 additions & 0 deletions lib/tlDevice/BMDOutputDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ namespace tl
IDeckLink* p = nullptr;
};

//! Decklink configuration wrapper.
class DLConfigWrapper
{
public:
~DLConfigWrapper();

IDeckLinkConfiguration* p = nullptr;
};

//! Decklink output wrapper.
class DLOutputWrapper
{
Expand Down Expand Up @@ -96,6 +105,7 @@ namespace tl
std::mutex _pixelDataMutex;

DLWrapper _dl;
DLConfigWrapper _dlConfig;
DLOutputWrapper _dlOutput;
DLVideoOutputCallbackWrapper _dlVideoOutputCallback;
};
Expand Down
18 changes: 17 additions & 1 deletion lib/tlGL/RenderShaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace tl
"const uint PixelType_YUV_444P_U16 = 27;\n";

const std::string yuvRange =
"// enum tl::render::YUVRange\n"
"// enum tl::imaging::YUVRange\n"
"const uint YUVRange_Full = 0;\n"
"const uint YUVRange_Video = 1;\n";

Expand Down Expand Up @@ -286,6 +286,10 @@ namespace tl
" float g;\n"
"};\n"
"\n"
"// enum tl::render::OutputRange\n"
"const uint OutputRange_Full = 0;\n"
"const uint OutputRange_Video = 1;\n"
"\n"
"uniform sampler2D textureSampler;\n"
"\n"
"uniform int channels;\n"
Expand All @@ -300,6 +304,7 @@ namespace tl
"uniform bool exposureEnabled;\n"
"uniform Exposure exposure;\n"
"uniform float softClip;\n"
"uniform int outputRange;\n"
"\n"
"vec4 colorFunc(vec4 value, vec3 add, mat4 m)\n"
"{\n"
Expand Down Expand Up @@ -430,6 +435,17 @@ namespace tl
" fColor.g = fColor.a;\n"
" fColor.b = fColor.a;\n"
" }\n"
"\n"
" // Output range.\n"
" if (OutputRange_Video == outputRange)\n"
" {\n"
" const float scale = (940.0 - 64.0) / 1023.0;\n"
" const float offset = 64.0 / 1023.0;\n"
" fColor.r = fColor.r * scale + offset;\n"
" fColor.g = fColor.g * scale + offset;\n"
" fColor.b = fColor.b * scale + offset;\n"
" fColor.a = fColor.a * scale + offset;\n"
" }\n"
"}\n";
}

Expand Down
1 change: 1 addition & 0 deletions lib/tlGL/RenderVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ namespace tl
p.displayShader->setUniform("exposure.f", f);
}
p.displayShader->setUniform("softClip", displayOptions.softClipEnabled ? displayOptions.softClip : 0.F);
p.displayShader->setUniform("outputRange", static_cast<int>(displayOptions.outputRange));

glActiveTexture(static_cast<GLenum>(GL_TEXTURE0));
glBindTexture(GL_TEXTURE_2D, p.buffer->getColorID());
Expand Down
16 changes: 14 additions & 2 deletions lib/tlQt/OutputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,25 @@ namespace tl
{
gl::OffscreenBufferBinding binding(offscreenBuffer);

switch (pixelType)
{
case device::PixelType::_8BitBGRA:
case device::PixelType::_10BitRGBXLE:
for (auto& i : displayOptions)
{
i.outputRange = timeline::OutputRange::Video;
}
break;
default: break;
}

render->setColorConfig(colorConfig);
render->begin(renderSize);
render->drawVideo(
videoData,
timeline::tiles(compareOptions.mode, sizes),
{ imageOptions },
{ displayOptions },
imageOptions,
displayOptions,
compareOptions);
render->end();
}
Expand Down
6 changes: 6 additions & 0 deletions lib/tlTimeline/RenderOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ namespace tl
tint(in.tint);
}

TLRENDER_ENUM_IMPL(
OutputRange,
"Full",
"Video");
TLRENDER_ENUM_SERIALIZE_IMPL(OutputRange);

TLRENDER_ENUM_IMPL(
CompareMode,
"A",
Expand Down
13 changes: 13 additions & 0 deletions lib/tlTimeline/RenderOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ namespace tl
bool operator != (const Exposure&) const;
};

//! Output value range.
enum class OutputRange
{
Full,
Video,

Count,
First = Full
};
TLRENDER_ENUM(OutputRange);
TLRENDER_ENUM_SERIALIZE(OutputRange);

//! Image options.
struct ImageOptions
{
Expand All @@ -144,6 +156,7 @@ namespace tl
Exposure exposure;
bool softClipEnabled = false;
float softClip = 0.F;
OutputRange outputRange = OutputRange::Full;

bool operator == (const DisplayOptions&) const;
bool operator != (const DisplayOptions&) const;
Expand Down
3 changes: 2 additions & 1 deletion lib/tlTimeline/RenderOptionsInline.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ namespace tl
exposureEnabled == other.exposureEnabled &&
exposure == other.exposure &&
softClipEnabled == other.softClipEnabled &&
softClip == other.softClip;
softClip == other.softClip &&
outputRange == other.outputRange;
}

inline bool DisplayOptions::operator != (const DisplayOptions& other) const
Expand Down

0 comments on commit d4f302f

Please sign in to comment.