Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_burnshadows_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 if( value_red < factor ) new_value_red = 0;
45 else new_value_red = (value_red - factor)/(1 - factor);
46 if( value_green < factor ) new_value_green = 0;
47 else new_value_green = (value_green - factor)/(1 - factor);
48 if( value_blue < factor ) new_value_blue = 0;
49 else new_value_blue = (value_blue - factor)/(1 - factor);
50
52 dst->green = KoColorSpaceMaths< float, _channel_type_ >::scaleToA(new_value_green);
54 dst->alpha = src->alpha;
55
56 --nPixels;
57 ++src;
58 ++dst;
59 }
60 }
61
62 QList<QString> parameters() const override
63 {
64 QList<QString> list;
65 list << "exposure";
66 return list;
67 }
68
69 int parameterId(const QString& name) const override
70 {
71 if (name == "exposure")
72 return 0;
73 return -1;
74 }
75
76 void setParameter(int id, const QVariant& parameter) override
77 {
78 switch(id)
79 {
80 case 0:
81 exposure = parameter.toDouble();
82 break;
83 default:
84 ;
85 }
86 }
87private:
88
89 float exposure {0.0f};
90 };
91
96
98{
100 l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer8BitsColorDepthID));
101 l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer16BitsColorDepthID));
102 l.append(QPair< KoID, KoID >(RGBAColorModelID , Float16BitsColorDepthID));
103 l.append(QPair< KoID, KoID >(RGBAColorModelID , Float32BitsColorDepthID));
104 return l;
105}
106
107KoColorTransformation* KisBurnShadowsAdjustmentFactory::createTransformation(const KoColorSpace* colorSpace, QHash<QString, QVariant> parameters) const
108{
110 if (colorSpace->colorModelId() != RGBAColorModelID) {
111 dbgKrita << "Unsupported color space " << colorSpace->id() << " in KisBurnShadowsAdjustment::createTransformation";
112 return 0;
113 }
114 if (colorSpace->colorDepthId() == Integer8BitsColorDepthID) {
116 }
117#ifdef HAVE_OPENEXR
118 else if (colorSpace->colorDepthId() == Float16BitsColorDepthID) {
120 }
121#endif
122 else if (colorSpace->colorDepthId() == Integer16BitsColorDepthID) {
124 } else if (colorSpace->colorDepthId() == Float32BitsColorDepthID) {
126 } else {
127 dbgKrita << "Unsupported color space " << colorSpace->id() << " in KisBurnShadowsAdjustment::createTransformation";
128 return 0;
129 }
130 adj->setParameters(parameters);
131 return adj;
132
133}
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 setParameter(int id, const QVariant &parameter) override
void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const override
int parameterId(const QString &name) const override
QList< QString > parameters() 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