| 98 | } |
| 99 | |
| 100 | QColor qColor() const |
| 101 | { |
| 102 | // start with sane component values |
| 103 | qreal _h = wrap(h); |
| 104 | qreal _c = normalize(c); |
| 105 | qreal _y = normalize(y); |
| 106 | |
| 107 | // calculate some needed variables |
| 108 | qreal _hs = _h * 6.0, th, tm; |
| 109 | if (_hs < 1.0) { |
| 110 | th = _hs; |
| 111 | tm = yc[0] + yc[1] * th; |
| 112 | } else if (_hs < 2.0) { |
| 113 | th = 2.0 - _hs; |
| 114 | tm = yc[1] + yc[0] * th; |
| 115 | } else if (_hs < 3.0) { |
| 116 | th = _hs - 2.0; |
| 117 | tm = yc[1] + yc[2] * th; |
| 118 | } else if (_hs < 4.0) { |
| 119 | th = 4.0 - _hs; |
| 120 | tm = yc[2] + yc[1] * th; |
| 121 | } else if (_hs < 5.0) { |
| 122 | th = _hs - 4.0; |
| 123 | tm = yc[2] + yc[0] * th; |
| 124 | } else { |
| 125 | th = 6.0 - _hs; |
| 126 | tm = yc[0] + yc[2] * th; |
| 127 | } |
| 128 | |
| 129 | // calculate RGB channels in sorted order |
| 130 | qreal tn, to, tp; |
| 131 | if (tm >= _y) { |
| 132 | tp = _y + _y * _c * (1.0 - tm) / tm; |
| 133 | to = _y + _y * _c * (th - tm) / tm; |
| 134 | tn = _y - (_y * _c); |
| 135 | } else { |
| 136 | tp = _y + (1.0 - _y) * _c; |
| 137 | to = _y + (1.0 - _y) * _c * (th - tm) / (1.0 - tm); |
| 138 | tn = _y - (1.0 - _y) * _c * tm / (1.0 - tm); |
| 139 | } |
| 140 | |
| 141 | // return RGB channels in appropriate order |
| 142 | if (_hs < 1.0) { |
| 143 | return QColor::fromRgbF(igamma(tp), igamma(to), igamma(tn), a); |
| 144 | } else if (_hs < 2.0) { |
| 145 | return QColor::fromRgbF(igamma(to), igamma(tp), igamma(tn), a); |
| 146 | } else if (_hs < 3.0) { |
| 147 | return QColor::fromRgbF(igamma(tn), igamma(tp), igamma(to), a); |
| 148 | } else if (_hs < 4.0) { |
| 149 | return QColor::fromRgbF(igamma(tn), igamma(to), igamma(tp), a); |
| 150 | } else if (_hs < 5.0) { |
| 151 | return QColor::fromRgbF(igamma(to), igamma(tn), igamma(tp), a); |
| 152 | } else { |
| 153 | return QColor::fromRgbF(igamma(tp), igamma(tn), igamma(to), a); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | qreal h, c, y, a; |