Changeset View
Changeset View
Standalone View
Standalone View
imagelib/effects/kpEffectHSV.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 43 | { | |||
---|---|---|---|---|---|
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 = (float)(r - g) / ((b - min) * 6) + (float)2 / 3; | 54 | *pHue = static_cast<float> (r - g) / ((b - min) * 6) + static_cast<float> (2) / 3; | ||
55 | *pSaturation = (float)1 - (float)min / (float)b; | 55 | *pSaturation = 1.0f - static_cast<float> (min) / static_cast<float> (b); | ||
56 | } | 56 | } | ||
57 | else | 57 | else | ||
58 | { | 58 | { | ||
59 | *pHue = 0; | 59 | *pHue = 0; | ||
60 | *pSaturation = 0; | 60 | *pSaturation = 0; | ||
61 | } | 61 | } | ||
62 | *pValue = (float)b / 255; | 62 | *pValue = static_cast<float> (b) / 255; | ||
63 | } | 63 | } | ||
64 | else if(g >= r) | 64 | else if(g >= r) | ||
65 | { | 65 | { | ||
66 | // Green | 66 | // Green | ||
67 | min = qMin(b, r); | 67 | min = qMin(b, r); | ||
68 | if(g != min) | 68 | if(g != min) | ||
69 | { | 69 | { | ||
70 | *pHue = (float)(b - r) / ((g - min) * 6) + (float)1 / 3; | 70 | *pHue = static_cast<float> (b - r) / ((g - min) * 6) + static_cast<float> (1) / 3; | ||
71 | *pSaturation = (float)1 - (float)min / (float)g; | 71 | *pSaturation = 1.0f - static_cast<float> (min) / static_cast<float> (g); | ||
72 | } | 72 | } | ||
73 | else | 73 | else | ||
74 | { | 74 | { | ||
75 | *pHue = 0; | 75 | *pHue = 0; | ||
76 | *pSaturation = 0; | 76 | *pSaturation = 0; | ||
77 | } | 77 | } | ||
78 | *pValue = (float)g / 255; | 78 | *pValue = static_cast<float> (g) / 255; | ||
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 = (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) += (float)1; | 88 | (*pHue) += 1.0f; | ||
89 | *pSaturation = (float)1 - (float)min / (float)r; | 89 | *pSaturation = 1.0f - static_cast<float> (min) / static_cast<float> (r); | ||
90 | } | 90 | } | ||
91 | else | 91 | else | ||
92 | { | 92 | { | ||
93 | *pHue = 0; | 93 | *pHue = 0; | ||
94 | *pSaturation = 0; | 94 | *pSaturation = 0; | ||
95 | } | 95 | } | ||
96 | *pValue = (float)r / 255; | 96 | *pValue = static_cast<float> (r) / 255; | ||
97 | } | 97 | } | ||
98 | } | 98 | } | ||
99 | 99 | | |||
100 | static unsigned int HSVToColor(int alpha, float hue, float saturation, float value) | 100 | static unsigned int HSVToColor(int alpha, float hue, float saturation, float value) | ||
101 | { | 101 | { | ||
102 | //Q_ASSERT (hue >= 0 && hue <= 1 && saturation >= 0 && saturation <= 1 && value >= 0 && value <= 1); | 102 | //Q_ASSERT (hue >= 0 && hue <= 1 && saturation >= 0 && saturation <= 1 && value >= 0 && value <= 1); | ||
103 | 103 | | |||
104 | hue *= (float)5.999999; | 104 | hue *= 5.999999f; | ||
105 | int h = (int)hue; | 105 | int h = static_cast<int> (hue); | ||
106 | float f = hue - h; | 106 | float f = hue - h; | ||
107 | float p = value * ((float)1 - saturation); | 107 | float p = value * (1.0f - saturation); | ||
108 | float q = value * ((float)1 - ((h & 1) == 0 ? (float)1 - f : f) * saturation); | 108 | float q = value * (1.0f - ((h & 1) == 0 ? 1.0f - f : f) * saturation); | ||
109 | switch(h) | 109 | switch(h) | ||
110 | { | 110 | { | ||
111 | case 0: return qRgba((int)(value * 255.999999), (int)(q * 255.999999), (int)(p * 255.999999), alpha); | 111 | case 0: return qRgba(static_cast<int> (value * 255.999999f), | ||
112 | case 1: return qRgba((int)(q * 255.999999), (int)(value * 255.999999), (int)(p * 255.999999), alpha); | 112 | static_cast<int> (q * 255.999999f), | ||
113 | case 2: return qRgba((int)(p * 255.999999), (int)(value * 255.999999), (int)(q * 255.999999), alpha); | 113 | static_cast<int> (p * 255.999999f), alpha); | ||
114 | case 3: return qRgba((int)(p * 255.999999), (int)(q * 255.999999), (int)(value * 255.999999), alpha); | 114 | | ||
115 | case 4: return qRgba((int)(q * 255.999999), (int)(p * 255.999999), (int)(value * 255.999999), alpha); | 115 | case 1: return qRgba(static_cast<int> (q * 255.999999f), | ||
116 | case 5: return qRgba((int)(value * 255.999999), (int)(p * 255.999999), (int)(q * 255.999999), alpha); | 116 | static_cast<int> (value * 255.999999f), | ||
117 | static_cast<int> (p * 255.999999f), alpha); | ||||
118 | | ||||
119 | case 2: return qRgba(static_cast<int> (p * 255.999999f), | ||||
120 | static_cast<int> (value * 255.999999f), | ||||
121 | static_cast<int> (q * 255.999999f), alpha); | ||||
122 | | ||||
123 | case 3: return qRgba(static_cast<int> (p * 255.999999f), | ||||
124 | static_cast<int> (q * 255.999999f), | ||||
125 | static_cast<int> (value * 255.999999f), alpha); | ||||
126 | | ||||
127 | case 4: return qRgba(static_cast<int> (q * 255.999999f), | ||||
128 | static_cast<int> (p * 255.999999f), | ||||
129 | static_cast<int> (value * 255.999999f), alpha); | ||||
130 | | ||||
131 | case 5: return qRgba(static_cast<int> (value * 255.999999f), | ||||
132 | static_cast<int> (p * 255.999999f), | ||||
133 | static_cast<int> (q * 255.999999f), alpha); | ||||
117 | } | 134 | } | ||
118 | return qRgba(0, 0, 0, alpha); | 135 | return qRgba(0, 0, 0, alpha); | ||
119 | } | 136 | } | ||
120 | 137 | | |||
121 | static QRgb AdjustHSVInternal (QRgb pix, double hueDiv360, double saturation, double value) | 138 | static QRgb AdjustHSVInternal (QRgb pix, double hueDiv360, double saturation, double value) | ||
122 | { | 139 | { | ||
123 | float h, s, v; | 140 | float h, s, v; | ||
124 | ::ColorToHSV(pix, &h, &s, &v); | 141 | ::ColorToHSV(pix, &h, &s, &v); | ||
125 | 142 | | |||
126 | const int alpha = qAlpha(pix); | 143 | const int alpha = qAlpha(pix); | ||
127 | 144 | | |||
128 | h += (float)hueDiv360; | 145 | h += static_cast<float> (hueDiv360); | ||
129 | h -= floor(h); | 146 | h -= floor(h); | ||
130 | 147 | | |||
131 | s = qMax((float)0, qMin((float)1, s + (float)saturation)); | 148 | s = qMax(0.0f, qMin(1.0f, s + static_cast<float> (saturation))); | ||
132 | 149 | | |||
133 | v = qMax((float)0, qMin((float)1, v + (float)value)); | 150 | v = qMax(0.0f, qMin(1.0f, v + static_cast<float> (value))); | ||
134 | 151 | | |||
135 | return ::HSVToColor(alpha, h, s, v); | 152 | return ::HSVToColor(alpha, h, s, v); | ||
136 | } | 153 | } | ||
137 | 154 | | |||
138 | static void AdjustHSV (QImage* pImage, double hue, double saturation, double value) | 155 | static void AdjustHSV (QImage* pImage, double hue, double saturation, double value) | ||
139 | { | 156 | { | ||
140 | hue /= 360; | 157 | hue /= 360; | ||
141 | 158 | | |||
Show All 32 Lines |