File indexing completed on 2024-06-16 04:15:53
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Sahil Nagpal <nagpal.sahil01@gmail.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "kis_dodgemidtones_adjustment.h" 0008 #include <KoConfig.h> 0009 0010 #include <kis_debug.h> 0011 #include <klocalizedstring.h> 0012 #ifdef HAVE_OPENEXR 0013 #include <half.h> 0014 #endif 0015 0016 #include <KoColorConversions.h> 0017 #include <KoColorModelStandardIds.h> 0018 #include <KoColorSpace.h> 0019 #include <KoColorSpaceTraits.h> 0020 #include <KoColorTransformation.h> 0021 #include <KoID.h> 0022 0023 template<typename _channel_type_, typename traits > 0024 class KisDodgeMidtonesAdjustment : public KoColorTransformation 0025 { 0026 typedef traits RGBTrait; 0027 typedef typename RGBTrait::Pixel RGBPixel; 0028 0029 public: 0030 KisDodgeMidtonesAdjustment(){} 0031 0032 public: 0033 0034 void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const override 0035 { 0036 const RGBPixel* src = reinterpret_cast<const RGBPixel*>(srcU8); 0037 RGBPixel* dst = reinterpret_cast<RGBPixel*>(dstU8); 0038 float value_red, value_green, value_blue; 0039 const float factor(1.0/(1.0 + exposure)); 0040 while(nPixels > 0) { 0041 0042 value_red = pow((float)KoColorSpaceMaths<_channel_type_, float>::scaleToA(src->red), factor); 0043 value_green = pow((float)KoColorSpaceMaths<_channel_type_, float>::scaleToA(src->green), factor); 0044 value_blue = pow((float)KoColorSpaceMaths<_channel_type_, float>::scaleToA(src->blue), factor); 0045 0046 dst->red = KoColorSpaceMaths< float, _channel_type_ >::scaleToA(value_red); 0047 dst->green = KoColorSpaceMaths< float, _channel_type_ >::scaleToA(value_green); 0048 dst->blue = KoColorSpaceMaths< float, _channel_type_ >::scaleToA(value_blue); 0049 dst->alpha = src->alpha; 0050 0051 --nPixels; 0052 ++src; 0053 ++dst; 0054 } 0055 } 0056 0057 QList<QString> parameters() const override 0058 { 0059 QList<QString> list; 0060 list << "exposure"; 0061 return list; 0062 } 0063 0064 int parameterId(const QString& name) const override 0065 { 0066 if (name == "exposure") 0067 return 0; 0068 return -1; 0069 } 0070 0071 void setParameter(int id, const QVariant& parameter) override 0072 { 0073 switch(id) 0074 { 0075 case 0: 0076 exposure = parameter.toDouble(); 0077 break; 0078 default: 0079 ; 0080 } 0081 } 0082 private: 0083 0084 float exposure {0.0f}; 0085 }; 0086 0087 KisDodgeMidtonesAdjustmentFactory::KisDodgeMidtonesAdjustmentFactory() 0088 : KoColorTransformationFactory("DodgeMidtones") 0089 { 0090 } 0091 0092 QList< QPair< KoID, KoID > > KisDodgeMidtonesAdjustmentFactory::supportedModels() const 0093 { 0094 QList< QPair< KoID, KoID > > l; 0095 l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer8BitsColorDepthID)); 0096 l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer16BitsColorDepthID)); 0097 l.append(QPair< KoID, KoID >(RGBAColorModelID , Float16BitsColorDepthID)); 0098 l.append(QPair< KoID, KoID >(RGBAColorModelID , Float32BitsColorDepthID)); 0099 return l; 0100 } 0101 0102 KoColorTransformation* KisDodgeMidtonesAdjustmentFactory::createTransformation(const KoColorSpace* colorSpace, QHash<QString, QVariant> parameters) const 0103 { 0104 KoColorTransformation * adj; 0105 if (colorSpace->colorModelId() != RGBAColorModelID) { 0106 dbgKrita << "Unsupported color space " << colorSpace->id() << " in KisDodgeMidtonesAdjustmentFactory::createTransformation"; 0107 return 0; 0108 } 0109 if (colorSpace->colorDepthId() == Float32BitsColorDepthID) { 0110 adj = new KisDodgeMidtonesAdjustment< float, KoRgbTraits < float > >(); 0111 } 0112 #ifdef HAVE_OPENEXR 0113 else if (colorSpace->colorDepthId() == Float16BitsColorDepthID) { 0114 adj = new KisDodgeMidtonesAdjustment< half, KoRgbTraits < half > >(); 0115 } 0116 #endif 0117 else if(colorSpace->colorDepthId() == Integer16BitsColorDepthID) { 0118 adj = new KisDodgeMidtonesAdjustment< quint16, KoBgrTraits < quint16 > >(); 0119 } else if(colorSpace->colorDepthId() == Integer8BitsColorDepthID) { 0120 adj = new KisDodgeMidtonesAdjustment< quint8, KoBgrTraits < quint8 > >(); 0121 } else { 0122 dbgKrita << "Unsupported color space " << colorSpace->id() << " in KisDodgeMidtonesAdjustmentFactory::createTransformation"; 0123 return 0; 0124 } 0125 adj->setParameters(parameters); 0126 return adj; 0127 }