diff --git a/plugins/color/lcms2engine/LcmsRGBP2020PQColorSpace.h b/plugins/color/lcms2engine/LcmsRGBP2020PQColorSpace.h index 736b0fbc04..47d7db6430 100644 --- a/plugins/color/lcms2engine/LcmsRGBP2020PQColorSpace.h +++ b/plugins/color/lcms2engine/LcmsRGBP2020PQColorSpace.h @@ -1,141 +1,142 @@ /* * Copyright (c) 2019 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef LCMSRGBP2020PQCOLORSPACE_H #define LCMSRGBP2020PQCOLORSPACE_H #include #include #ifdef HAVE_OPENEXR #include #endif #include #include "KoColorConversionTransformationFactory.h" #include template struct ColorSpaceFromFactory { }; template<> struct ColorSpaceFromFactory { typedef RgbU8ColorSpace type; }; template<> struct ColorSpaceFromFactory { typedef RgbU16ColorSpace type; }; #ifdef HAVE_OPENEXR template<> struct ColorSpaceFromFactory { typedef RgbF16ColorSpace type; }; #endif template<> struct ColorSpaceFromFactory { typedef RgbF32ColorSpace type; }; /** * Define a singly linked list of supported bit depth traits */ template struct NextTrait { using type = void; }; template<> struct NextTrait { using type = KoBgrU16Traits; }; #ifdef HAVE_OPENEXR template<> struct NextTrait { using type = KoRgbF16Traits; }; template<> struct NextTrait { using type = KoRgbF32Traits; }; #else template<> struct NextTrait { using type = KoRgbF32Traits; }; #endif /** * Recursively add bit-depths conversions to the color space. We add only * **outgoing** conversions for every RGB color space. That is, every color * space has exactly three outgoing edges for color conversion. */ template void addInternalConversion(QList &list, CurrentTraits*) { // general case: add a converter and recurse for the next traits list << new LcmsScaleRGBP2020PQTransformationFactory(); using NextTraits = typename NextTrait::type; addInternalConversion(list, static_cast(0)); } template void addInternalConversion(QList &list, typename ParentColorSpace::ColorSpaceTraits*) { // exception: skip adding an edge to the same bit depth using CurrentTraits = typename ParentColorSpace::ColorSpaceTraits; using NextTraits = typename NextTrait::type; addInternalConversion(list, static_cast(0)); } template void addInternalConversion(QList &, void*) { // stop recursion } template class LcmsRGBP2020PQColorSpaceFactoryWrapper : public BaseColorSpaceFactory { typedef typename ColorSpaceFromFactory::type RelatedColorSpaceType; KoColorSpace *createColorSpace(const KoColorProfile *p) const override { return new RelatedColorSpaceType(this->name(), p->clone()); } QList colorConversionLinks() const override { QList list; /** * We explicitly disable direct conversions to/from integer color spaces, because * they may cause the the conversion system to choose them as an intermediate * color space for the conversion chain, e.g. * p709-g10 F32 -> p2020-g10 U16 -> Rec2020-pq U16, which is incorrect and loses * all the HDR data */ - list << new LcmsFromRGBP2020PQTransformationFactory(); list << new LcmsFromRGBP2020PQTransformationFactory(); + list << new LcmsToRGBP2020PQTransformationFactory(); #ifdef HAVE_OPENEXR + list << new LcmsFromRGBP2020PQTransformationFactory(); list << new LcmsToRGBP2020PQTransformationFactory(); #endif - list << new LcmsToRGBP2020PQTransformationFactory(); + // internally, we can convert to RGB U8 if needed addInternalConversion(list, static_cast(0)); return list; } }; #endif // LCMSRGBP2020PQCOLORSPACE_H