Changeset View
Changeset View
Standalone View
Standalone View
imagelib/effects/kpEffectHSV.cpp
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Line(s) | 93 | { | |||
---|---|---|---|---|---|
95 | *pSaturation = 0; | 95 | *pSaturation = 0; | ||
96 | } | 96 | } | ||
97 | *pValue = static_cast<float> (r) / 255; | 97 | *pValue = static_cast<float> (r) / 255; | ||
98 | } | 98 | } | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | static unsigned int HSVToColor(int alpha, float hue, float saturation, float value) | 101 | static unsigned int HSVToColor(int alpha, float hue, float saturation, float value) | ||
102 | { | 102 | { | ||
103 | //Q_ASSERT (hue >= 0 && hue <= 1 && saturation >= 0 && saturation <= 1 && value >= 0 && value <= 1); | | |||
104 | | ||||
105 | hue *= 5.999999f; | 103 | hue *= 5.999999f; | ||
106 | int h = static_cast<int> (hue); | 104 | int h = static_cast<int> (hue); | ||
107 | float f = hue - h; | 105 | float f = hue - h; | ||
108 | float p = value * (1.0f - saturation); | 106 | float p = value * (1.0 - saturation); | ||
109 | float q = value * (1.0f - ((h & 1) == 0 ? 1.0f - f : f) * saturation); | 107 | float q = value * (1.0 - ((h & 1) == 0 ? 1.0 - f : f) * saturation); | ||
110 | switch(h) | 108 | switch(h) | ||
111 | { | 109 | { | ||
112 | case 0: return qRgba(static_cast<int> (value * 255.999999f), | 110 | case 0: return qRgba(static_cast<int> (value * 255.999999), | ||
113 | static_cast<int> (q * 255.999999f), | 111 | static_cast<int> (q * 255.999999), | ||
114 | static_cast<int> (p * 255.999999f), alpha); | 112 | static_cast<int> (p * 255.999999), alpha); | ||
115 | 113 | | |||
116 | case 1: return qRgba(static_cast<int> (q * 255.999999f), | 114 | case 1: return qRgba(static_cast<int> (q * 255.999999), | ||
117 | static_cast<int> (value * 255.999999f), | 115 | static_cast<int> (value * 255.999999), | ||
118 | static_cast<int> (p * 255.999999f), alpha); | 116 | static_cast<int> (p * 255.999999), alpha); | ||
119 | 117 | | |||
120 | case 2: return qRgba(static_cast<int> (p * 255.999999f), | 118 | case 2: return qRgba(static_cast<int> (p * 255.999999), | ||
121 | static_cast<int> (value * 255.999999f), | 119 | static_cast<int> (value * 255.999999), | ||
122 | static_cast<int> (q * 255.999999f), alpha); | 120 | static_cast<int> (q * 255.999999), alpha); | ||
123 | 121 | | |||
124 | case 3: return qRgba(static_cast<int> (p * 255.999999f), | 122 | case 3: return qRgba(static_cast<int> (p * 255.999999), | ||
125 | static_cast<int> (q * 255.999999f), | 123 | static_cast<int> (q * 255.999999), | ||
126 | static_cast<int> (value * 255.999999f), alpha); | 124 | static_cast<int> (value * 255.999999), alpha); | ||
127 | 125 | | |||
128 | case 4: return qRgba(static_cast<int> (q * 255.999999f), | 126 | case 4: return qRgba(static_cast<int> (q * 255.999999), | ||
129 | static_cast<int> (p * 255.999999f), | 127 | static_cast<int> (p * 255.999999), | ||
130 | static_cast<int> (value * 255.999999f), alpha); | 128 | static_cast<int> (value * 255.999999), alpha); | ||
131 | 129 | | |||
132 | case 5: return qRgba(static_cast<int> (value * 255.999999f), | 130 | case 5: return qRgba(static_cast<int> (value * 255.999999), | ||
133 | static_cast<int> (p * 255.999999f), | 131 | static_cast<int> (p * 255.999999), | ||
134 | static_cast<int> (q * 255.999999f), alpha); | 132 | static_cast<int> (q * 255.999999), alpha); | ||
135 | } | 133 | } | ||
136 | return qRgba(0, 0, 0, alpha); | 134 | return qRgba(0, 0, 0, alpha); | ||
137 | } | 135 | } | ||
138 | 136 | | |||
139 | static QRgb AdjustHSVInternal (QRgb pix, double hueDiv360, double saturation, double value) | 137 | static QRgb AdjustHSVInternal (QRgb pix, double hueDiv360, double saturation, double value) | ||
140 | { | 138 | { | ||
141 | float h, s, v; | 139 | float h, s, v; | ||
142 | ::ColorToHSV(pix, &h, &s, &v); | 140 | ::ColorToHSV(pix, &h, &s, &v); | ||
143 | 141 | | |||
144 | const int alpha = qAlpha(pix); | 142 | const int alpha = qAlpha(pix); | ||
145 | 143 | | |||
146 | h += static_cast<float> (hueDiv360); | 144 | h += static_cast<float> (hueDiv360); | ||
147 | h -= std::floor(h); | 145 | h -= std::floor(h); | ||
148 | 146 | | |||
149 | s = qMax(0.0f, qMin(1.0f, s + static_cast<float> (saturation))); | 147 | s = qMax(0.0f, qMin(static_cast<float>(1), s + static_cast<float> (saturation))); | ||
150 | 148 | | |||
151 | v = qMax(0.0f, qMin(1.0f, v + static_cast<float> (value))); | 149 | v = qMax(0.0f, qMin(static_cast<float>(1), v + static_cast<float> (value))); | ||
152 | 150 | | |||
153 | return ::HSVToColor(alpha, h, s, v); | 151 | return ::HSVToColor(alpha, h, s, v); | ||
154 | } | 152 | } | ||
155 | 153 | | |||
156 | static void AdjustHSV (QImage* pImage, double hue, double saturation, double value) | 154 | static void AdjustHSV (QImage* pImage, double hue, double saturation, double value) | ||
157 | { | 155 | { | ||
158 | hue /= 360; | 156 | hue /= 360; | ||
159 | 157 | | |||
Show All 32 Lines |