Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_dodgeshadows_adjustment.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2013 Sahil Nagpal <nagpal.sahil01@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
8#include <KoConfig.h>
9
10#include <kis_debug.h>
11#include <klocalizedstring.h>
12#ifdef HAVE_OPENEXR
13#include <half.h>
14#endif
15
16#include <KoColorConversions.h>
18#include <KoColorSpace.h>
19#include <KoColorSpaceTraits.h>
21#include <KoID.h>
22
23template<typename _channel_type_, typename traits>
25{
26 typedef traits RGBTrait;
27 typedef typename RGBTrait::Pixel RGBPixel;
28
29public:
31
32 void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const override
33 {
34 const RGBPixel* src = reinterpret_cast<const RGBPixel*>(srcU8);
35 RGBPixel* dst = reinterpret_cast<RGBPixel*>(dstU8);
36 float value_red, value_green, value_blue, new_value_red, new_value_green, new_value_blue;
37 const float factor(exposure * 0.333333);
38 while (nPixels > 0) {
39
43
44 new_value_red = factor + value_red - factor * value_red;
45 new_value_green = factor + value_green - factor * value_green;
46 new_value_blue = factor + value_blue - factor * value_blue;
47
49 dst->green = KoColorSpaceMaths< float, _channel_type_ >::scaleToA(new_value_green);
51 dst->alpha = src->alpha;
52
53 --nPixels;
54 ++src;
55 ++dst;
56 }
57 }
58
59 QList<QString> parameters() const override
60 {
61 QList<QString> list;
62 list << "exposure";
63 return list;
64 }
65
66 int parameterId(const QString& name) const override
67 {
68 if (name == "exposure")
69 return 0;
70 return -1;
71 }
72
73 void setParameter(int id, const QVariant& parameter) override
74 {
75 switch(id)
76 {
77 case 0:
78 exposure = parameter.toDouble();
79 break;
80 default:
81 ;
82 }
83 }
84private:
85
86 float exposure {0.0f};
87 };
88
93
95{
97 l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer8BitsColorDepthID));
98 l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer16BitsColorDepthID));
99 l.append(QPair< KoID, KoID >(RGBAColorModelID , Float16BitsColorDepthID));
100 l.append(QPair< KoID, KoID >(RGBAColorModelID , Float32BitsColorDepthID));
101 return l;
102}
103
104KoColorTransformation* KisDodgeShadowsAdjustmentFactory::createTransformation(const KoColorSpace* colorSpace, QHash<QString, QVariant> parameters) const
105{
107 if (colorSpace->colorModelId() != RGBAColorModelID) {
108 dbgKrita << "Unsupported color space " << colorSpace->id() << " in KisDodgeShadowsAdjustmentFactory::createTransformation";
109 return 0;
110 }
111 if (colorSpace->colorDepthId() == Float32BitsColorDepthID) {
112 adj = new KisDodgeShadowsAdjustment < float, KoRgbTraits < float > >();
113 }
114#ifdef HAVE_OPENEXR
115 else if (colorSpace->colorDepthId() == Float16BitsColorDepthID) {
117 }
118#endif
119 else if (colorSpace->colorDepthId() == Integer16BitsColorDepthID) {
121 } else if (colorSpace->colorDepthId() == Integer8BitsColorDepthID) {
123 } else {
124 dbgKrita << "Unsupported color space " << colorSpace->id() << " in KisDodgeShadowsAdjustmentFactory::createTransformation";
125 return 0;
126 }
127 adj->setParameters(parameters);
128 return adj;
129
130}
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID Float16BitsColorDepthID("F16", ki18n("16-bit float/channel"))
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
QList< QPair< KoID, KoID > > supportedModels() const override
KoColorTransformation * createTransformation(const KoColorSpace *colorSpace, QHash< QString, QVariant > parameters) const override
void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const override
void setParameter(int id, const QVariant &parameter) override
QList< QString > parameters() const override
int parameterId(const QString &name) const override
static _Tdst scaleToA(_T a)
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
void setParameters(const QHash< QString, QVariant > &parameters)
#define dbgKrita
Definition kis_debug.h:45