Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_burnmidtones_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;
37 const float factor(1.0 + exposure * (0.333333));
38 while(nPixels > 0) {
39
40 value_red = pow((float)KoColorSpaceMaths<_channel_type_, float>::scaleToA(src->red), factor);
41 value_green = pow((float)KoColorSpaceMaths<_channel_type_, float>::scaleToA(src->green), factor);
42 value_blue = pow((float)KoColorSpaceMaths<_channel_type_, float>::scaleToA(src->blue), factor);
43
47 dst->alpha = src->alpha;
48
49 --nPixels;
50 ++src;
51 ++dst;
52 }
53 }
54
55 QList<QString> parameters() const override
56 {
57 QList<QString> list;
58 list << "exposure";
59 return list;
60 }
61
62 int parameterId(const QString& name) const override
63 {
64 if (name == "exposure")
65 return 0;
66 return -1;
67 }
68
69 void setParameter(int id, const QVariant& parameter) override
70 {
71 switch(id)
72 {
73 case 0:
74 exposure = parameter.toDouble();
75 break;
76 default:
77 ;
78 }
79 }
80private:
81
82 float exposure {0.0f};
83 };
84
89
91{
93 l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer8BitsColorDepthID));
94 l.append(QPair< KoID, KoID >(RGBAColorModelID , Integer16BitsColorDepthID));
95 l.append(QPair< KoID, KoID >(RGBAColorModelID , Float16BitsColorDepthID));
96 l.append(QPair< KoID, KoID >(RGBAColorModelID , Float32BitsColorDepthID));
97 return l;
98}
99
100KoColorTransformation* KisBurnMidtonesAdjustmentFactory::createTransformation(const KoColorSpace* colorSpace, QHash<QString, QVariant> parameters) const
101{
103 if (colorSpace->colorModelId() != RGBAColorModelID) {
104 dbgKrita << "Unsupported color space " << colorSpace->id() << " in KisBurnMidtonesAdjustment::createTransformation";
105 return 0;
106 }
107 if (colorSpace->colorDepthId() == Float32BitsColorDepthID) {
109 }
110#ifdef HAVE_OPENEXR
111 else if (colorSpace->colorDepthId() == Float16BitsColorDepthID) {
113 }
114#endif
115 else if (colorSpace->colorDepthId() == Integer16BitsColorDepthID) {
117 } else if (colorSpace->colorDepthId() == Integer8BitsColorDepthID) {
119 } else {
120 dbgKrita << "Unsupported color space " << colorSpace->id() << " in KisBurnMidtonesAdjustment::createTransformation";
121 return 0;
122 }
123 adj->setParameters(parameters);
124 return adj;
125
126}
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
int parameterId(const QString &name) const override
QList< QString > parameters() const override
void transform(const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) 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