Krita Source Code Documentation
Loading...
Searching...
No Matches
KisHSVCurveAdjustment< _channel_type_, traits > Class Template Reference
+ Inheritance diagram for KisHSVCurveAdjustment< _channel_type_, traits >:

Public Member Functions

 KisHSVCurveAdjustment ()
 
float lookupComponent (float x, float max) const
 
int parameterId (const QString &name) 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
 
- Public Member Functions inherited from KoColorTransformation
virtual bool isValid () const
 
void setParameters (const QHash< QString, QVariant > &parameters)
 
virtual ~KoColorTransformation ()
 

Public Attributes

const float SCALE_FROM_16BIT = 1.0f / 0xFFFF
 

Private Types

enum  ParameterID {
  PAR_CURVE , PAR_CHANNEL , PAR_DRIVER_CHANNEL , PAR_RELATIVE ,
  PAR_LUMA_R , PAR_LUMA_G , PAR_LUMA_B
}
 
typedef RGBTrait::Pixel RGBPixel
 
typedef traits RGBTrait
 

Private Attributes

int m_channel = 0
 
QVector< quint16 > m_curve
 
int m_driverChannel = 0
 
qreal m_lumaBlue
 
qreal m_lumaGreen
 
qreal m_lumaRed
 
bool m_relative = false
 

Detailed Description

template<typename _channel_type_, typename traits>
class KisHSVCurveAdjustment< _channel_type_, traits >

Definition at line 638 of file kis_hsv_adjustment.cpp.

Member Typedef Documentation

◆ RGBPixel

template<typename _channel_type_ , typename traits >
typedef RGBTrait::Pixel KisHSVCurveAdjustment< _channel_type_, traits >::RGBPixel
private

Definition at line 641 of file kis_hsv_adjustment.cpp.

◆ RGBTrait

template<typename _channel_type_ , typename traits >
typedef traits KisHSVCurveAdjustment< _channel_type_, traits >::RGBTrait
private

Definition at line 640 of file kis_hsv_adjustment.cpp.

Member Enumeration Documentation

◆ ParameterID

template<typename _channel_type_ , typename traits >
enum KisHSVCurveAdjustment::ParameterID
private
Enumerator
PAR_CURVE 
PAR_CHANNEL 
PAR_DRIVER_CHANNEL 
PAR_RELATIVE 
PAR_LUMA_R 
PAR_LUMA_G 
PAR_LUMA_B 

Definition at line 818 of file kis_hsv_adjustment.cpp.

Constructor & Destructor Documentation

◆ KisHSVCurveAdjustment()

template<typename _channel_type_ , typename traits >
KisHSVCurveAdjustment< _channel_type_, traits >::KisHSVCurveAdjustment ( )
inline

Definition at line 644 of file kis_hsv_adjustment.cpp.

Member Function Documentation

◆ lookupComponent()

template<typename _channel_type_ , typename traits >
float KisHSVCurveAdjustment< _channel_type_, traits >::lookupComponent ( float x,
float max ) const
inline

Definition at line 796 of file kis_hsv_adjustment.cpp.

797 {
798 // No curve for this component? Pass through unmodified
799 if (max < 2) return x;
800 if (x < 0) return m_curve[0];
801
802 float lookup = x * max;
803 float base = floor(lookup);
804 float offset = lookup - base;
805
806 if (base >= max) {
807 base = max - 1.0f;
808 offset = 1.0f;
809 }
810 int index = (int)base;
811
812 return (1.0f - offset) * m_curve[index]
813 + offset * m_curve[index + 1];
814 }
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()

References KisHSVCurveAdjustment< _channel_type_, traits >::m_curve.

◆ parameterId()

template<typename _channel_type_ , typename traits >
int KisHSVCurveAdjustment< _channel_type_, traits >::parameterId ( const QString & name) const
inlineoverridevirtual

Get the parameter id for a parameter name

Reimplemented from KoColorTransformation.

Definition at line 657 of file kis_hsv_adjustment.cpp.

658 {
659 if (name == "curve") {
660 return PAR_CURVE;
661 } else if (name == "channel") {
662 return PAR_CHANNEL;
663 } else if (name == "driverChannel") {
664 return PAR_DRIVER_CHANNEL;
665 } else if (name == "relative") {
666 return PAR_RELATIVE;
667 } else if (name == "lumaRed") {
668 return PAR_LUMA_R;
669 } else if (name == "lumaGreen") {
670 return PAR_LUMA_G;
671 } else if (name == "lumaBlue") {
672 return PAR_LUMA_B;
673 }
674 return -1;
675 }

References KisHSVCurveAdjustment< _channel_type_, traits >::PAR_CHANNEL, KisHSVCurveAdjustment< _channel_type_, traits >::PAR_CURVE, KisHSVCurveAdjustment< _channel_type_, traits >::PAR_DRIVER_CHANNEL, KisHSVCurveAdjustment< _channel_type_, traits >::PAR_LUMA_B, KisHSVCurveAdjustment< _channel_type_, traits >::PAR_LUMA_G, KisHSVCurveAdjustment< _channel_type_, traits >::PAR_LUMA_R, and KisHSVCurveAdjustment< _channel_type_, traits >::PAR_RELATIVE.

◆ parameters()

template<typename _channel_type_ , typename traits >
QList< QString > KisHSVCurveAdjustment< _channel_type_, traits >::parameters ( ) const
inlineoverridevirtual
Returns
the list of parameters

Reimplemented from KoColorTransformation.

Definition at line 650 of file kis_hsv_adjustment.cpp.

651 {
652 QList<QString> list;
653 list << "curve" << "channel" << "driverChannel" << "relative" << "lumaRed" << "lumaGreen"<< "lumaBlue";
654 return list;
655 }

◆ setParameter()

template<typename _channel_type_ , typename traits >
void KisHSVCurveAdjustment< _channel_type_, traits >::setParameter ( int id,
const QVariant & parameter )
inlineoverridevirtual

curve: adjustment curve as QVector<quin16> channel: which channel to adjust. See KisHSVCurve::ColorChannel. driverChannel: which channel to use as source for adjustments. relative: false: use curve for direct lookup. true: add adjustment to original. In this mode, the curve range is mapped to -1.0 to 1.0 luma Red/Green/Blue: Used for luma calculations.

Reimplemented from KoColorTransformation.

Definition at line 686 of file kis_hsv_adjustment.cpp.

687 {
688 switch(id)
689 {
690 case PAR_CURVE:
691 m_curve = parameter.value<QVector<quint16>>();
692 break;
693 case PAR_CHANNEL:
694 case PAR_DRIVER_CHANNEL: {
695 int channel = parameter.toInt();
696 KIS_ASSERT_RECOVER_RETURN(0 <= channel && channel < KisHSVCurve::ChannelCount && "Invalid channel. Ignored!");
697
698 if (id == PAR_CHANNEL) {
699 m_channel = channel;
700 } else {
701 m_driverChannel = channel;
702 }
703 } break;
704 case PAR_RELATIVE:
705 m_relative = parameter.toBool();
706 break;
707 case PAR_LUMA_R:
708 m_lumaRed = parameter.toDouble();
709 break;
710 case PAR_LUMA_G:
711 m_lumaGreen = parameter.toDouble();
712 break;
713 case PAR_LUMA_B:
714 m_lumaBlue = parameter.toDouble();
715 break;
716 default:
717 KIS_ASSERT_RECOVER_NOOP(false && "Unknown parameter ID. Ignored!");
718 }
719 }
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97

References KisHSVCurve::ChannelCount, KIS_ASSERT_RECOVER_NOOP, KIS_ASSERT_RECOVER_RETURN, KisHSVCurveAdjustment< _channel_type_, traits >::m_channel, KisHSVCurveAdjustment< _channel_type_, traits >::m_curve, KisHSVCurveAdjustment< _channel_type_, traits >::m_driverChannel, KisHSVCurveAdjustment< _channel_type_, traits >::m_lumaBlue, KisHSVCurveAdjustment< _channel_type_, traits >::m_lumaGreen, KisHSVCurveAdjustment< _channel_type_, traits >::m_lumaRed, KisHSVCurveAdjustment< _channel_type_, traits >::m_relative, KisHSVCurveAdjustment< _channel_type_, traits >::PAR_CHANNEL, KisHSVCurveAdjustment< _channel_type_, traits >::PAR_CURVE, KisHSVCurveAdjustment< _channel_type_, traits >::PAR_DRIVER_CHANNEL, KisHSVCurveAdjustment< _channel_type_, traits >::PAR_LUMA_B, KisHSVCurveAdjustment< _channel_type_, traits >::PAR_LUMA_G, KisHSVCurveAdjustment< _channel_type_, traits >::PAR_LUMA_R, and KisHSVCurveAdjustment< _channel_type_, traits >::PAR_RELATIVE.

◆ transform()

template<typename _channel_type_ , typename traits >
void KisHSVCurveAdjustment< _channel_type_, traits >::transform ( const quint8 * src,
quint8 * dst,
qint32 nPixels ) const
inlineoverridevirtual

This function apply the transformation on a given number of pixels.

Parameters
srca pointer to the source pixels
dsta pointer to the destination pixels
nPixelsthe number of pixels

This function may or may not be thread safe. You need to create one KoColorTransformation per thread.

Implements KoColorTransformation.

Definition at line 722 of file kis_hsv_adjustment.cpp.

723 {
724 const RGBPixel* src = reinterpret_cast<const RGBPixel*>(srcU8);
725 RGBPixel* dst = reinterpret_cast<RGBPixel*>(dstU8);
726 float max = m_curve.size() - 1;
727
728 int driverChannel = m_relative ? m_driverChannel : m_channel;
729
730 float component[KisHSVCurve::ChannelCount];
731
732 // Aliases for convenience
733 float &h = component[KisHSVCurve::Hue];
734 float &s = component[KisHSVCurve::Saturation];
735 float &v = component[KisHSVCurve::Value];
736 float &r = component[traits::red_pos];
737 float &g = component[traits::green_pos];
738 float &b = component[traits::blue_pos];
739 float &a = component[KisHSVCurve::Alpha];
740
741 while (nPixels > 0) {
742 r = SCALE_TO_FLOAT(src->red);
743 g = SCALE_TO_FLOAT(src->green);
744 b = SCALE_TO_FLOAT(src->blue);
745 a = SCALE_TO_FLOAT(src->alpha);
746
747 RGBToHSV(r, g, b, &h, &s, &v);
748
749 // Normalize hue to 0.0 to 1.0 range
750 h /= 360.0f;
751
752 float adjustment = lookupComponent(component[driverChannel], max) * SCALE_FROM_16BIT;
753
754 if (m_relative) {
755 // Curve uses range 0.0 to 1.0, but for adjustment we need -1.0 to 1.0
756 adjustment = 2.0f * adjustment - 1.0f;
757
759 r += adjustment;
760 g += adjustment;
761 b += adjustment;
762 } else {
763 component[m_channel] += adjustment;
764 }
765 } else {
767 r = b = g = adjustment;
768 } else {
769 component[m_channel] = adjustment;
770 }
771 }
772
773 h *= 360.0f;
774 if (h > 360) h -= 360;
775 if (h < 0) h += 360;
776
778 HSVToRGB(h, s, v, &r, &g, &b);
779 }
780
781 clamp< _channel_type_ >(&r, &g, &b);
782 FLOAT_CLAMP(&a);
783
784 dst->red = SCALE_FROM_FLOAT(r);
785 dst->green = SCALE_FROM_FLOAT(g);
786 dst->blue = SCALE_FROM_FLOAT(b);
787 dst->alpha = SCALE_FROM_FLOAT(a);
788
789 --nPixels;
790 ++src;
791 ++dst;
792 }
793 }
qreal v
void RGBToHSV(float r, float g, float b, float *h, float *s, float *v)
void HSVToRGB(float h, float s, float v, float *r, float *g, float *b)
float lookupComponent(float x, float max) const
#define SCALE_FROM_FLOAT(v)
#define FLOAT_CLAMP(v)
#define SCALE_TO_FLOAT(v)

References KisHSVCurve::AllColors, KisHSVCurve::Alpha, KisHSVCurve::ChannelCount, FLOAT_CLAMP, HSVToRGB(), KisHSVCurve::Hue, KisHSVCurveAdjustment< _channel_type_, traits >::lookupComponent(), KisHSVCurveAdjustment< _channel_type_, traits >::m_channel, KisHSVCurveAdjustment< _channel_type_, traits >::m_curve, KisHSVCurveAdjustment< _channel_type_, traits >::m_driverChannel, KisHSVCurveAdjustment< _channel_type_, traits >::m_relative, RGBToHSV(), KisHSVCurve::Saturation, KisHSVCurveAdjustment< _channel_type_, traits >::SCALE_FROM_16BIT, SCALE_FROM_FLOAT, SCALE_TO_FLOAT, v, and KisHSVCurve::Value.

Member Data Documentation

◆ m_channel

template<typename _channel_type_ , typename traits >
int KisHSVCurveAdjustment< _channel_type_, traits >::m_channel = 0
private

Definition at line 830 of file kis_hsv_adjustment.cpp.

◆ m_curve

template<typename _channel_type_ , typename traits >
QVector<quint16> KisHSVCurveAdjustment< _channel_type_, traits >::m_curve
private

Definition at line 829 of file kis_hsv_adjustment.cpp.

◆ m_driverChannel

template<typename _channel_type_ , typename traits >
int KisHSVCurveAdjustment< _channel_type_, traits >::m_driverChannel = 0
private

Definition at line 831 of file kis_hsv_adjustment.cpp.

◆ m_lumaBlue

template<typename _channel_type_ , typename traits >
qreal KisHSVCurveAdjustment< _channel_type_, traits >::m_lumaBlue
private

Definition at line 837 of file kis_hsv_adjustment.cpp.

◆ m_lumaGreen

template<typename _channel_type_ , typename traits >
qreal KisHSVCurveAdjustment< _channel_type_, traits >::m_lumaGreen
private

Definition at line 837 of file kis_hsv_adjustment.cpp.

◆ m_lumaRed

template<typename _channel_type_ , typename traits >
qreal KisHSVCurveAdjustment< _channel_type_, traits >::m_lumaRed
private

Definition at line 837 of file kis_hsv_adjustment.cpp.

◆ m_relative

template<typename _channel_type_ , typename traits >
bool KisHSVCurveAdjustment< _channel_type_, traits >::m_relative = false
private

Definition at line 832 of file kis_hsv_adjustment.cpp.

◆ SCALE_FROM_16BIT

template<typename _channel_type_ , typename traits >
const float KisHSVCurveAdjustment< _channel_type_, traits >::SCALE_FROM_16BIT = 1.0f / 0xFFFF

Definition at line 721 of file kis_hsv_adjustment.cpp.


The documentation for this class was generated from the following file: