| 2782 | /////////////////////////////////////////////////////////////////////////// |
| 2783 | |
| 2784 | bool 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 |