本文整理汇总了C++中KoColor::fromKoColor方法的典型用法代码示例。如果您正苦于以下问题:C++ KoColor::fromKoColor方法的具体用法?C++ KoColor::fromKoColor怎么用?C++ KoColor::fromKoColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KoColor
的用法示例。
在下文中一共展示了KoColor::fromKoColor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: colorAt
void KoStopGradient::colorAt(KoColor& dst, qreal t) const
{
if (! m_stops.count())
return;
if (t <= m_stops.first().first || m_stops.count() == 1) {
// we have only one stop or t is before the first stop
// -> use the color of the first stop
dst.fromKoColor(m_stops.first().second);
} else if (t >= m_stops.last().first) {
// t is after the last stop
// -> use the color of the last stop
dst.fromKoColor(m_stops.last().second);
} else {
// we have at least two color stops
// -> find the two stops which frame our t
QList<KoGradientStop>::const_iterator stop = m_stops.begin();
QList<KoGradientStop>::const_iterator lastStop = m_stops.end();
// we already checked the first stop, so we start at the second
for (++stop; stop != lastStop; ++stop) {
// we break at the stop which is just after our t
if (stop->first > t)
break;
}
if ( !(*buffer.colorSpace() == *colorSpace())) {
buffer = KoColor(colorSpace());
}
const KoGradientStop& leftStop = *(stop - 1);
const KoGradientStop& rightStop = *(stop);
const quint8 *colors[2];
colors[0] = leftStop.second.data();
colors[1] = rightStop.second.data();
qreal localT;
qreal stopDistance = rightStop.first - leftStop.first;
if (stopDistance < DBL_EPSILON) {
localT = 0.5;
} else {
localT = (t - leftStop.first) / stopDistance;
}
qint16 colorWeights[2];
colorWeights[0] = static_cast<quint8>((1.0 - localT) * 255 + 0.5);
colorWeights[1] = 255 - colorWeights[0];
colorSpace()->mixColorsOp()->mixColors(colors, colorWeights, 2, buffer.data());
dst.fromKoColor(buffer);
}
}