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

Public Member Functions

 KisHSVAdjustment ()
 
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 ()
 

Private Types

typedef RGBTrait::Pixel RGBPixel
 
typedef traits RGBTrait
 

Private Attributes

double m_adj_h
 
double m_adj_s
 
double m_adj_v
 
bool m_colorize
 
bool m_compatibilityMode
 
qreal m_lumaBlue
 
qreal m_lumaGreen
 
qreal m_lumaRed
 
int m_type
 

Detailed Description

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

Definition at line 319 of file kis_hsv_adjustment.cpp.

Member Typedef Documentation

◆ RGBPixel

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

Definition at line 322 of file kis_hsv_adjustment.cpp.

◆ RGBTrait

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

Definition at line 321 of file kis_hsv_adjustment.cpp.

Constructor & Destructor Documentation

◆ KisHSVAdjustment()

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

Member Function Documentation

◆ parameterId()

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

Get the parameter id for a parameter name

Reimplemented from KoColorTransformation.

Definition at line 558 of file kis_hsv_adjustment.cpp.

559 {
560 if (name == "h") {
561 return 0;
562 } else if (name == "s") {
563 return 1;
564 } else if (name == "v") {
565 return 2;
566 } else if (name == "type") {
567 return 3;
568 } else if (name == "colorize") {
569 return 4;
570 } else if (name == "lumaRed") {
571 return 5;
572 } else if (name == "lumaGreen") {
573 return 6;
574 } else if (name == "lumaBlue") {
575 return 7;
576 } else if (name == "compatibilityMode") {
577 return 8;
578 }
579 return -1;
580 }

◆ parameters()

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

Reimplemented from KoColorTransformation.

Definition at line 551 of file kis_hsv_adjustment.cpp.

552 {
553 QList<QString> list;
554 list << "h" << "s" << "v" << "type" << "colorize" << "lumaRed" << "lumaGreen"<< "lumaBlue" << "compatibilityMode";
555 return list;
556 }

◆ setParameter()

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

name - "h", "s" or "v" (h)ue in range <-1.0, 1.0> ( for user, show as -180, 180 or 0, 360 for colorize) (s)aturation in range <-1.0, 1.0> ( for user, show -100, 100, or 0, 100 for colorize) (v)alue in range <-1.0, 1.0> (for user, show -100, 100) type: 0:HSV, 1:HSL, 2:HSI, 3:HSY, 4:YUV m_colorize: Use colorize formula instead luma Red/Green/Blue: Used for luma calculations.

Reimplemented from KoColorTransformation.

Definition at line 591 of file kis_hsv_adjustment.cpp.

592 {
593 switch(id)
594 {
595 case 0:
596 m_adj_h = parameter.toDouble();
597 break;
598 case 1:
599 m_adj_s = parameter.toDouble();
600 break;
601 case 2:
602 m_adj_v = parameter.toDouble();
603 break;
604 case 3:
605 m_type = parameter.toInt();
606 break;
607 case 4:
608 m_colorize = parameter.toBool();
609 break;
610 case 5:
611 m_lumaRed = parameter.toDouble();
612 break;
613 case 6:
614 m_lumaGreen = parameter.toDouble();
615 break;
616 case 7:
617 m_lumaBlue = parameter.toDouble();
618 break;
619 case 8:
620 m_compatibilityMode = parameter.toBool();
621 break;
622 default:
623 KIS_ASSERT_RECOVER_NOOP(false && "Unknown parameter ID. Ignored!");
624 ;
625 }
626 }
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97

References KIS_ASSERT_RECOVER_NOOP, KisHSVAdjustment< _channel_type_, traits >::m_adj_h, KisHSVAdjustment< _channel_type_, traits >::m_adj_s, KisHSVAdjustment< _channel_type_, traits >::m_adj_v, KisHSVAdjustment< _channel_type_, traits >::m_colorize, KisHSVAdjustment< _channel_type_, traits >::m_compatibilityMode, KisHSVAdjustment< _channel_type_, traits >::m_lumaBlue, KisHSVAdjustment< _channel_type_, traits >::m_lumaGreen, KisHSVAdjustment< _channel_type_, traits >::m_lumaRed, and KisHSVAdjustment< _channel_type_, traits >::m_type.

◆ transform()

template<typename _channel_type_ , typename traits >
void KisHSVAdjustment< _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 340 of file kis_hsv_adjustment.cpp.

341 {
342
343 //if (m_model="RGBA" || m_colorize) {
344 /*It'd be nice to have LCH automatically selector for LAB in the future, but I don't know how to select LAB
345 * */
346 const RGBPixel* src = reinterpret_cast<const RGBPixel*>(srcU8);
347 RGBPixel* dst = reinterpret_cast<RGBPixel*>(dstU8);
348 float h, s, v;
349 float r = 0.0;
350 float g = 0.0;
351 float b = 0.0;
352 qreal lumaR, lumaG, lumaB;
353 //Default to rec 709 when there's no coefficients given//
354 if (m_lumaRed<=0 || m_lumaGreen<=0 || m_lumaBlue<=0) {
355 lumaR = 0.2126;
356 lumaG = 0.7152;
357 lumaB = 0.0722;
358 } else {
359 lumaR = m_lumaRed;
360 lumaG = m_lumaGreen;
361 lumaB = m_lumaBlue;
362 }
363 while (nPixels > 0) {
364
365 if (m_colorize) {
366 h = m_adj_h * 360;
367 if (h >= 360.0) h = 0;
368
369 s = m_adj_s;
370
371 r = SCALE_TO_FLOAT(src->red);
372 g = SCALE_TO_FLOAT(src->green);
373 b = SCALE_TO_FLOAT(src->blue);
374
375 float luminance = r * lumaR + g * lumaG + b * lumaB;
376
377 if (m_adj_v > 0) {
378 luminance *= (1.0 - m_adj_v);
379 luminance += 1.0 - (1.0 - m_adj_v);
380 }
381 else if (m_adj_v < 0 ){
382 luminance *= (m_adj_v + 1.0);
383 }
384 v = luminance;
385 HSLToRGB(h, s, v, &r, &g, &b);
386
387 } else {
388
389 if (m_type == 0) {
390 if (!m_compatibilityMode) {
391 r = SCALE_TO_FLOAT(src->red);
392 g = SCALE_TO_FLOAT(src->green);
393 b = SCALE_TO_FLOAT(src->blue);
394 HSVTransform(&r, &g, &b, m_adj_h, m_adj_s, m_adj_v, HSVPolicy());
395 } else {
396 RGBToHSV(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), SCALE_TO_FLOAT(src->blue), &h, &s, &v);
397 h += m_adj_h * 180;
399 s += m_adj_s;
400 v += m_adj_v;
401 HSVToRGB(h, s, v, &r, &g, &b);
402 }
403 } else if (m_type == 1) {
404
405 if (!m_compatibilityMode) {
406 r = SCALE_TO_FLOAT(src->red);
407 g = SCALE_TO_FLOAT(src->green);
408 b = SCALE_TO_FLOAT(src->blue);
409 HSVTransform(&r, &g, &b, m_adj_h, m_adj_s, m_adj_v, HSLPolicy());
410 } else {
411 RGBToHSL(SCALE_TO_FLOAT(src->red), SCALE_TO_FLOAT(src->green), SCALE_TO_FLOAT(src->blue), &h, &s, &v);
412
413 h += m_adj_h * 180;
415 s *= (m_adj_s + 1.0);
416 if (m_adj_v < 0) {
417 v *= (m_adj_v + 1.0);
418 } else {
419 v += (m_adj_v * (1.0 - v));
420 }
421 HSLToRGB(h, s, v, &r, &g, &b);
422 }
423 } else if (m_type == 2) {
424
425 if (!m_compatibilityMode) {
426 r = SCALE_TO_FLOAT(src->red);
427 g = SCALE_TO_FLOAT(src->green);
428 b = SCALE_TO_FLOAT(src->blue);
429 HSVTransform(&r, &g, &b, m_adj_h, m_adj_s, m_adj_v, HCIPolicy());
430 } else {
431 qreal red = SCALE_TO_FLOAT(src->red);
432 qreal green = SCALE_TO_FLOAT(src->green);
433 qreal blue = SCALE_TO_FLOAT(src->blue);
434 qreal hue, sat, intensity;
435 RGBToHCI(red, green, blue, &hue, &sat, &intensity);
436
437 hue *= 360.0;
438 hue += m_adj_h * 180;
439 hue = normalizeAngleDegrees(hue);
440 sat *= (m_adj_s + 1.0);
441 intensity += m_adj_v;
442
443 HCIToRGB(hue/360.0, sat, intensity, &red, &green, &blue);
444
445 r = red;
446 g = green;
447 b = blue;
448 }
449 } else if (m_type == 3) {
450
451 if (!m_compatibilityMode) {
452 r = SCALE_TO_FLOAT(src->red);
453 g = SCALE_TO_FLOAT(src->green);
454 b = SCALE_TO_FLOAT(src->blue);
455 HSVTransform(&r, &g, &b, m_adj_h, m_adj_s, m_adj_v, HCYPolicy(lumaR, lumaG, lumaB));
456 } else {
457 qreal red = SCALE_TO_FLOAT(src->red);
458 qreal green = SCALE_TO_FLOAT(src->green);
459 qreal blue = SCALE_TO_FLOAT(src->blue);
460 qreal hue, sat, luma;
461 RGBToHCY(red, green, blue, &hue, &sat, &luma, lumaR, lumaG, lumaB);
462
463 hue *= 360.0;
464 hue += m_adj_h * 180;
465 hue = normalizeAngleDegrees(hue);
466 sat *= (m_adj_s + 1.0);
467 luma += m_adj_v;
468
469 HCYToRGB(hue/360.0, sat, luma, &red, &green, &blue, lumaR, lumaG, lumaB);
470 r = red;
471 g = green;
472 b = blue;
473 }
474
475 } else if (m_type == 4) {
476
477 qreal red = SCALE_TO_FLOAT(src->red);
478 qreal green = SCALE_TO_FLOAT(src->green);
479 qreal blue = SCALE_TO_FLOAT(src->blue);
480 qreal y, cb, cr;
481 RGBToYUV(red, green, blue, &y, &cb, &cr, lumaR, lumaG, lumaB);
482
483 cb *= (m_adj_h + 1.0);
484 cr *= (m_adj_s + 1.0);
485 y += (m_adj_v);
486
487 YUVToRGB(y, cb, cr, &red, &green, &blue, lumaR, lumaG, lumaB);
488 r = red;
489 g = green;
490 b = blue;
491 } else {
492 Q_ASSERT_X(false, "", "invalid type");
493 }
494 }
495
496 clamp< _channel_type_ >(&r, &g, &b);
497 dst->red = SCALE_FROM_FLOAT(r);
498 dst->green = SCALE_FROM_FLOAT(g);
499 dst->blue = SCALE_FROM_FLOAT(b);
500 dst->alpha = src->alpha;
501
502 --nPixels;
503 ++src;
504 ++dst;
505 }
506 /*} else if (m_model="LABA"){
507 const LABPixel* src = reinterpret_cast<const LABPixel*>(srcU8);
508 LABPixel* dst = reinterpret_cast<LABPixel*>(dstU8);
509 qreal lightness = SCALE_TO_FLOAT(src->L);
510 qreal a = SCALE_TO_FLOAT(src->a);
511 qreal b = SCALE_TO_FLOAT(src->b);
512 qreal L, C, H;
513
514 while (nPixels > 0) {
515 if (m_type = 4) {
516 a *= (m_adj_h + 1.0);
517 a = qBound(0.0, a, 1.0);
518
519 b *= (m_adj_s + 1.0);
520 b = qBound(0.0, b, 1.0);
521
522 if (m_adj_v < 0)
523 lightness *= (m_adj_v + 1.0);
524 else
525 lightness += (m_adj_v * (1.0 - lightness));
526 } else {//lch
527 LABToLCH(lightness, a, b, &L, &C, &H);
528 H *=360;
529 H += m_adj_h * 180;
530 if (H > 360) h -= 360;
531 if (H < 0) h += 360;
532 C += m_adj_s;
533 C = qBound(0.0,C,1.0);
534 L += m_adj_v;
535 L = qBound(0.0,L,1.0);
536 LCHToLAB(L, C, H/360.0, &lightness, &a, &b);
537 }
538 clamp< _channel_type_ >(&lightness, &a, &b);
539 dst->L = SCALE_FROM_FLOAT(lightness);
540 dst->a = SCALE_FROM_FLOAT(a);
541 dst->b = SCALE_FROM_FLOAT(b);
542 dst->alpha = src->alpha;
543
544 --nPixels;
545 ++src;
546 ++dst;
547 }
548 }*/
549 }
qreal v
void RGBToHSV(float r, float g, float b, float *h, float *s, float *v)
void HCIToRGB(const qreal h, const qreal c, const qreal i, qreal *red, qreal *green, qreal *blue)
void RGBToYUV(const qreal r, const qreal g, const qreal b, qreal *y, qreal *u, qreal *v, qreal R, qreal G, qreal B)
void RGBToHCI(const qreal r, const qreal g, const qreal b, qreal *h, qreal *c, qreal *i)
void RGBToHCY(const qreal r, const qreal g, const qreal b, qreal *h, qreal *c, qreal *y, qreal R, qreal G, qreal B)
void RGBToHSL(float r, float g, float b, float *h, float *s, float *l)
void HSVToRGB(float h, float s, float v, float *r, float *g, float *b)
void YUVToRGB(const qreal y, const qreal u, const qreal v, qreal *r, qreal *g, qreal *b, qreal R, qreal G, qreal B)
void HSLToRGB(float h, float sl, float l, float *r, float *g, float *b)
void HCYToRGB(const qreal h, const qreal c, const qreal y, qreal *red, qreal *green, qreal *blue, qreal R, qreal G, qreal B)
RGBTrait::Pixel RGBPixel
std::enable_if< std::is_floating_point< T >::value, T >::type normalizeAngleDegrees(T a)
Definition kis_global.h:132
#define SCALE_FROM_FLOAT(v)
void HSVTransform(float *r, float *g, float *b, float dh, float ds, float dv, ValuePolicy valuePolicy)
#define SCALE_TO_FLOAT(v)

References HCIToRGB(), HCYToRGB(), HSLToRGB(), HSVToRGB(), HSVTransform(), KisHSVAdjustment< _channel_type_, traits >::m_adj_h, KisHSVAdjustment< _channel_type_, traits >::m_adj_s, KisHSVAdjustment< _channel_type_, traits >::m_adj_v, KisHSVAdjustment< _channel_type_, traits >::m_colorize, KisHSVAdjustment< _channel_type_, traits >::m_compatibilityMode, KisHSVAdjustment< _channel_type_, traits >::m_lumaBlue, KisHSVAdjustment< _channel_type_, traits >::m_lumaGreen, KisHSVAdjustment< _channel_type_, traits >::m_lumaRed, KisHSVAdjustment< _channel_type_, traits >::m_type, normalizeAngleDegrees(), RGBToHCI(), RGBToHCY(), RGBToHSL(), RGBToHSV(), RGBToYUV(), SCALE_FROM_FLOAT, SCALE_TO_FLOAT, v, and YUVToRGB().

Member Data Documentation

◆ m_adj_h

template<typename _channel_type_ , typename traits >
double KisHSVAdjustment< _channel_type_, traits >::m_adj_h
private

Definition at line 630 of file kis_hsv_adjustment.cpp.

◆ m_adj_s

template<typename _channel_type_ , typename traits >
double KisHSVAdjustment< _channel_type_, traits >::m_adj_s
private

Definition at line 630 of file kis_hsv_adjustment.cpp.

◆ m_adj_v

template<typename _channel_type_ , typename traits >
double KisHSVAdjustment< _channel_type_, traits >::m_adj_v
private

Definition at line 630 of file kis_hsv_adjustment.cpp.

◆ m_colorize

template<typename _channel_type_ , typename traits >
bool KisHSVAdjustment< _channel_type_, traits >::m_colorize
private

Definition at line 633 of file kis_hsv_adjustment.cpp.

◆ m_compatibilityMode

template<typename _channel_type_ , typename traits >
bool KisHSVAdjustment< _channel_type_, traits >::m_compatibilityMode
private

Definition at line 634 of file kis_hsv_adjustment.cpp.

◆ m_lumaBlue

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

Definition at line 631 of file kis_hsv_adjustment.cpp.

◆ m_lumaGreen

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

Definition at line 631 of file kis_hsv_adjustment.cpp.

◆ m_lumaRed

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

Definition at line 631 of file kis_hsv_adjustment.cpp.

◆ m_type

template<typename _channel_type_ , typename traits >
int KisHSVAdjustment< _channel_type_, traits >::m_type
private

Definition at line 632 of file kis_hsv_adjustment.cpp.


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