Skip to content

Commit 0472317

Browse files
hodoulpremia
andauthored
Protect against empty look result color space (#1437) (#1443)
Signed-off-by: Rémi Achard <[email protected]> Co-authored-by: Patrick Hodoul <[email protected]> Co-authored-by: Rémi Achard <[email protected]>
1 parent 7ffd61d commit 0472317

File tree

3 files changed

+74
-12
lines changed

3 files changed

+74
-12
lines changed

src/OpenColorIO/apphelpers/LegacyViewingPipeline.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ ConstProcessorRcPtr LegacyViewingPipelineImpl::getProcessor(const ConstConfigRcP
216216
viewTransform = config->getViewTransform(viewTransformName.c_str());
217217
}
218218

219-
// NB: If the viewTranform is present, then displayColorSpace is a true display color space
219+
// NB: If the viewTransform is present, then displayColorSpace is a true display color space
220220
// rather than a traditional color space.
221221
const std::string name{ config->getDisplayViewColorSpaceName(display.c_str(), view.c_str()) };
222222
// A shared view containing a view transform may set the color space to USE_DISPLAY_NAME,
@@ -344,16 +344,21 @@ ConstProcessorRcPtr LegacyViewingPipelineImpl::getProcessor(const ConstConfigRcP
344344
const char * outCS = skipColorSpaceConversions ? inCS :
345345
LookTransform::GetLooksResultColorSpace(configIn, context,
346346
looks.c_str());
347-
auto lt = LookTransform::Create();
348-
lt->setSrc(inCS);
349-
lt->setDst(outCS);
350-
lt->setLooks(looks.c_str());
351-
lt->setSkipColorSpaceConversion(skipColorSpaceConversions);
352347

353-
group->appendTransform(lt);
348+
// Resulting color space could be null in case of a noop look.
349+
if (outCS && *outCS)
350+
{
351+
auto lt = LookTransform::Create();
352+
lt->setSrc(inCS);
353+
lt->setDst(outCS);
354+
lt->setLooks(looks.c_str());
355+
lt->setSkipColorSpaceConversion(skipColorSpaceConversions);
356+
357+
group->appendTransform(lt);
354358

355-
// Adjust display transform input color space.
356-
dt->setSrc(outCS);
359+
// Adjust display transform input color space.
360+
dt->setSrc(outCS);
361+
}
357362
}
358363

359364
if (m_channelView)
@@ -425,7 +430,7 @@ std::ostream & operator<<(std::ostream & os, const LegacyViewingPipeline & pipel
425430
{
426431
os << ", ";
427432
}
428-
os << "LooksOveerideEnabled";
433+
os << "LooksOverrideEnabled";
429434
first = false;
430435
}
431436
const std::string lo{ pipeline.getLooksOverride() };
@@ -435,11 +440,10 @@ std::ostream & operator<<(std::ostream & os, const LegacyViewingPipeline & pipel
435440
{
436441
os << ", ";
437442
}
438-
os << "LooksOveeride: " << lo;
443+
os << "LooksOverride: " << lo;
439444
first = false;
440445
}
441446
return os;
442447
}
443448

444449
} // namespace OCIO_NAMESPACE
445-

tests/cpu/apphelpers/LegacyViewingPipeline_tests.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,3 +900,56 @@ OCIO_ADD_TEST(LegacyViewingPipeline, fullPipelineNoLook)
900900
OCIO_REQUIRE_ASSERT(ec);
901901
}
902902
}
903+
904+
OCIO_ADD_TEST(LegacyViewingPipeline, processorWithNoOpLook)
905+
{
906+
//
907+
// Validate LegacyViewingPipeline::getProcessor when a noop look override
908+
// is specified.
909+
//
910+
911+
std::istringstream is(category_test_config);
912+
913+
OCIO::ConstConfigRcPtr cfg;
914+
OCIO_CHECK_NO_THROW(cfg = OCIO::Config::CreateFromStream(is));
915+
OCIO_CHECK_NO_THROW(cfg->validate());
916+
917+
OCIO::DisplayViewTransformRcPtr dt = OCIO::DisplayViewTransform::Create();
918+
dt->setDisplay("DISP_2");
919+
dt->setView("VIEW_2");
920+
dt->setSrc("in_1");
921+
922+
OCIO::LegacyViewingPipelineRcPtr vp = OCIO::LegacyViewingPipeline::Create();
923+
vp->setDisplayViewTransform(dt);
924+
vp->setLooksOverrideEnabled(true);
925+
vp->setLooksOverride("look_noop");
926+
927+
// Processor in forward direction.
928+
929+
OCIO::ConstProcessorRcPtr proc;
930+
OCIO_CHECK_NO_THROW(proc = vp->getProcessor(cfg, cfg->getCurrentContext()));
931+
OCIO_REQUIRE_ASSERT(proc);
932+
933+
OCIO::GroupTransformRcPtr groupTransform;
934+
OCIO_CHECK_NO_THROW(groupTransform = proc->createGroupTransform());
935+
936+
OCIO_REQUIRE_ASSERT(groupTransform);
937+
OCIO_CHECK_NO_THROW(groupTransform->validate());
938+
939+
// Repeat in inverse direction.
940+
941+
dt->setDirection(OCIO::TRANSFORM_DIR_INVERSE);
942+
vp->setDisplayViewTransform(dt);
943+
vp->setLooksOverrideEnabled(true);
944+
vp->setLooksOverride("look_noop");
945+
946+
// Processor in inverse direction.
947+
948+
OCIO_CHECK_NO_THROW(proc = vp->getProcessor(cfg, cfg->getCurrentContext()));
949+
OCIO_REQUIRE_ASSERT(proc);
950+
951+
OCIO_CHECK_NO_THROW(groupTransform = proc->createGroupTransform());
952+
953+
OCIO_REQUIRE_ASSERT(groupTransform);
954+
OCIO_CHECK_NO_THROW(groupTransform->validate());
955+
}

tests/cpu/apphelpers/configs.data

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ looks:
4949
process_space: log_1
5050
transform: !<CDLTransform> {slope: [1.2, 2.2, 1.2]}
5151

52+
- !<Look>
53+
name: look_noop
54+
process_space: log_1
55+
transform: !<CDLTransform> {slope: [1, 1, 1], offset: [0, 0, 0], power: [1, 1, 1]}
56+
5257
colorspaces:
5358
- !<ColorSpace>
5459
name: raw

0 commit comments

Comments
 (0)