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