MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / isColorSpaceLinear

Method isColorSpaceLinear

src/OpenColorIO/Config.cpp:2784–2906  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2782///////////////////////////////////////////////////////////////////////////
2783
2784bool Config::isColorSpaceLinear(const char * colorSpace, ReferenceSpaceType referenceSpaceType) const
2785{
2786 auto cs = getColorSpace(colorSpace);
2787
2788 if (cs == nullptr)
2789 {
2790 std::ostringstream os;
2791 os << "Could not test colorspace linearity. Colorspace " << colorSpace << " does not exist.";
2792 throw Exception(os.str().c_str());
2793 }
2794
2795 if (cs->isData())
2796 {
2797 return false;
2798 }
2799
2800 // Colorspace is not linear if the types are opposite.
2801 if (cs->getReferenceSpaceType() != referenceSpaceType)
2802 {
2803 return false;
2804 }
2805
2806 std::string encoding = cs->getEncoding();
2807 if (!encoding.empty())
2808 {
2809 // Check the encoding value if it is set.
2810 if ((StringUtils::Compare(cs->getEncoding(), "scene-linear") &&
2811 referenceSpaceType == REFERENCE_SPACE_SCENE) ||
2812 (StringUtils::Compare(cs->getEncoding(), "display-linear") &&
2813 referenceSpaceType == REFERENCE_SPACE_DISPLAY))
2814 {
2815 return true;
2816 }
2817 else
2818 {
2819 return false;
2820 }
2821 }
2822
2823 // We want to assess linearity over at least a reasonable range of values, so use a very dark
2824 // value and a very bright value. Test neutral, red, green, and blue points to detect situations
2825 // where the neutral may be linear but there is non-linearity off the neutral axis.
2826 auto evaluate = [](const Config & config, ConstTransformRcPtr &t) -> bool
2827 {
2828 std::vector<float> img =
2829 {
2830 0.0625f, 0.0625f, 0.0625f, 4.f, 4.f, 4.f,
2831 0.0625f, 0.f, 0.f, 4.f, 0.f, 0.f,
2832 0.f, 0.0625f, 0.f, 0.f, 4.f, 0.f,
2833 0.f, 0.f, 0.0625f, 0.f, 0.f, 4.f
2834 };
2835 std::vector<float> dst(img.size(), 0.f);
2836
2837 PackedImageDesc desc(&img[0], 8, 1, CHANNEL_ORDERING_RGB);
2838 PackedImageDesc descDst(&dst[0], 8, 1, CHANNEL_ORDERING_RGB);
2839
2840 auto procToReference = config.getImpl()->getProcessorWithoutCaching(
2841 config, t, TRANSFORM_DIR_FORWARD

Callers 5

IdentifyInterchangeSpaceFunction · 0.80
test_scene_referredMethod · 0.80
test_display_referredMethod · 0.80
OCIO_ADD_TESTFunction · 0.80

Calls 12

CompareFunction · 0.85
EqualWithAbsErrorFunction · 0.85
getImplMethod · 0.80
isDataMethod · 0.45
getReferenceSpaceTypeMethod · 0.45
getEncodingMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
applyMethod · 0.45
getTransformMethod · 0.45

Tested by 4

test_scene_referredMethod · 0.64
test_display_referredMethod · 0.64
OCIO_ADD_TESTFunction · 0.64