Changeset View
Changeset View
Standalone View
Standalone View
imagelib/effects/kpEffectHSV.cpp
Show All 38 Lines | |||||
39 | #include "pixmapfx/kpPixmapFX.h" | 39 | #include "pixmapfx/kpPixmapFX.h" | ||
40 | 40 | | |||
41 | 41 | | |||
42 | static void ColorToHSV(unsigned int c, float* pHue, float* pSaturation, float* pValue) | 42 | static void ColorToHSV(unsigned int c, float* pHue, float* pSaturation, float* pValue) | ||
43 | { | 43 | { | ||
44 | int r = qRed(c); | 44 | int r = qRed(c); | ||
45 | int g = qGreen(c); | 45 | int g = qGreen(c); | ||
46 | int b = qBlue(c); | 46 | int b = qBlue(c); | ||
47 | int min; | 47 | int min{}; | ||
48 | if(b >= g && b >= r) | 48 | if(b >= g && b >= r) | ||
49 | { | 49 | { | ||
50 | // Blue | 50 | // Blue | ||
51 | min = qMin(r, g); | 51 | min = qMin(r, g); | ||
52 | if(b != min) | 52 | if(b != min) | ||
53 | { | 53 | { | ||
54 | *pHue = static_cast<float> (r - g) / ((b - min) * 6) + static_cast<float> (2) / 3; | 54 | *pHue = static_cast<float> (r - g) / ((b - min) * 6) + static_cast<float> (2) / 3; | ||
55 | *pSaturation = 1.0f - static_cast<float> (min) / static_cast<float> (b); | 55 | *pSaturation = 1.0f - static_cast<float> (min) / static_cast<float> (b); | ||
Show All 23 Lines | |||||
79 | } | 79 | } | ||
80 | else | 80 | else | ||
81 | { | 81 | { | ||
82 | // Red | 82 | // Red | ||
83 | min = qMin(g, b); | 83 | min = qMin(g, b); | ||
84 | if(r != min) | 84 | if(r != min) | ||
85 | { | 85 | { | ||
86 | *pHue = static_cast<float> (g - b) / ((r - min) * 6); | 86 | *pHue = static_cast<float> (g - b) / ((r - min) * 6); | ||
87 | if(*pHue < 0) | 87 | if(*pHue < 0) { | ||
88 | (*pHue) += 1.0f; | 88 | (*pHue) += 1.0f; | ||
89 | } | ||||
89 | *pSaturation = 1.0f - static_cast<float> (min) / static_cast<float> (r); | 90 | *pSaturation = 1.0f - static_cast<float> (min) / static_cast<float> (r); | ||
90 | } | 91 | } | ||
91 | else | 92 | else | ||
92 | { | 93 | { | ||
93 | *pHue = 0; | 94 | *pHue = 0; | ||
94 | *pSaturation = 0; | 95 | *pSaturation = 0; | ||
95 | } | 96 | } | ||
96 | *pValue = static_cast<float> (r) / 255; | 97 | *pValue = static_cast<float> (r) / 255; | ||
▲ Show 20 Lines • Show All 94 Lines • Show Last 20 Lines |