void TransferFunctionEditor::setColorMapStops( const QGradientStops& stops ) { QPolygonF redPoints, greenPoints, bluePoints, alphaPoints; const double redCMHt = _redWidget->height(); const double greenCMHt = _greenWidget->height(); const double blueCMHt = _blueWidget->height(); const double alphaCMHt = _alphaWidget->height(); for( int32_t i = 0; i < stops.size(); ++i ) { double position = stops.at( i ).first; QRgb color = stops.at( i ).second.rgba(); redPoints << QPointF( position * _redWidget->width(), redCMHt - qRed(color) * redCMHt / 255 ); greenPoints << QPointF( position * _greenWidget->width(), greenCMHt - qGreen(color) * greenCMHt / 255 ); bluePoints << QPointF( position * _blueWidget->width(), blueCMHt - qBlue(color) * blueCMHt / 255 ); alphaPoints << QPointF( position * _alphaWidget->width(), alphaCMHt - qAlpha(color) * alphaCMHt / 255 ); } _redWidget->setPoints( redPoints ); _greenWidget->setPoints( greenPoints ); _blueWidget->setPoints( bluePoints ); _alphaWidget->setPoints( alphaPoints ); }
void ColorMapWidget::setGradientStops( const QGradientStops& stops ) { if( _channel != lexis::render::ColorMap::Channel::alpha ) return; _gradient = QLinearGradient( 0.0f, 0.0f, width(), 0.0f ); for( int i = 0; i < stops.size(); ++i ) _gradient.setColorAt( stops.at( i ).first, stops.at( i ).second ); _background = QImage(); _generateBackground(); }
void ShadeWidget::setGradientStops(const QGradientStops &stops) { if (m_shade_type == ARGBShade) { m_alpha_gradient = QLinearGradient(0, 0, width(), 0); for (int i=0; i<stops.size(); ++i) { QColor c = stops.at(i).second; m_alpha_gradient.setColorAt(stops.at(i).first, QColor(c.red(), c.green(), c.blue())); } m_shade = QImage(); generateShade(); update(); } }
void saveGradientStops(QTextStream &str, const QGradient *g) { QGradientStops stops = g->stops(); if (g->interpolationMode() == QGradient::ColorInterpolation) { bool constantAlpha = true; int alpha = stops.at(0).second.alpha(); for (int i = 1; i < stops.size(); ++i) constantAlpha &= (stops.at(i).second.alpha() == alpha); if (!constantAlpha) { const qreal spacing = qreal(0.02); QGradientStops newStops; QRgb fromColor = PREMUL(stops.at(0).second.rgba()); QRgb toColor; for (int i = 0; i + 1 < stops.size(); ++i) { int parts = qCeil((stops.at(i + 1).first - stops.at(i).first) / spacing); newStops.append(stops.at(i)); toColor = PREMUL(stops.at(i + 1).second.rgba()); if (parts > 1) { qreal step = (stops.at(i + 1).first - stops.at(i).first) / parts; for (int j = 1; j < parts; ++j) { QRgb color = INV_PREMUL(INTERPOLATE_PIXEL_256(fromColor, 256 - 256 * j / parts, toColor, 256 * j / parts)); newStops.append(QGradientStop(stops.at(i).first + j * step, QColor::fromRgba(color))); } } fromColor = toColor; } newStops.append(stops.back()); stops = newStops; } } foreach(QGradientStop stop, stops) { QString color = QString::fromLatin1("#%1%2%3") .arg(stop.second.red(), 2, 16, QLatin1Char('0')) .arg(stop.second.green(), 2, 16, QLatin1Char('0')) .arg(stop.second.blue(), 2, 16, QLatin1Char('0')); str << QLatin1String(" <stop offset=\"")<< stop.first << QLatin1String("\" ") << QLatin1String("stop-color=\"") << color << QLatin1String("\" ") << QLatin1String("stop-opacity=\"") << stop.second.alphaF() <<QLatin1String("\" />\n"); }
QGradientStops QQuickGradient::gradientStops() const { QGradientStops stops; for (int i = 0; i < m_stops.size(); ++i){ int j = 0; while (j < stops.size() && stops.at(j).first < m_stops[i]->position()) j++; stops.insert(j, QGradientStop(m_stops.at(i)->position(), m_stops.at(i)->color())); } return stops; }
void GradientEditor::setGradientStops(const QGradientStops &stops) { QPolygonF pts_red, pts_green, pts_blue, pts_alpha; qreal h_red = m_red_shade->height(); qreal h_green = m_green_shade->height(); qreal h_blue = m_blue_shade->height(); qreal h_alpha = m_alpha_shade->height(); for (int i=0; i<stops.size(); ++i) { qreal pos = stops.at(i).first; QRgb color = stops.at(i).second.rgba(); pts_red << QPointF(pos * m_red_shade->width(), h_red - qRed(color) * h_red / 255); pts_green << QPointF(pos * m_green_shade->width(), h_green - qGreen(color) * h_green / 255); pts_blue << QPointF(pos * m_blue_shade->width(), h_blue - qBlue(color) * h_blue / 255); pts_alpha << QPointF(pos * m_alpha_shade->width(), h_alpha - qAlpha(color) * h_alpha / 255); } set_shade_points(pts_red, m_red_shade); set_shade_points(pts_green, m_green_shade); set_shade_points(pts_blue, m_blue_shade); set_shade_points(pts_alpha, m_alpha_shade); }
QSGNode *QQuickRectangle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) { Q_UNUSED(data); Q_D(QQuickRectangle); if (width() <= 0 || height() <= 0 || (d->color.alpha() == 0 && (!d->pen || d->pen->width() == 0 || d->pen->color().alpha() == 0))) { delete oldNode; return 0; } QSGRectangleNode *rectangle = static_cast<QSGRectangleNode *>(oldNode); if (!rectangle) rectangle = d->sceneGraphContext()->createRectangleNode(); rectangle->setRect(QRectF(0, 0, width(), height())); rectangle->setColor(d->color); if (d->pen && d->pen->isValid()) { rectangle->setPenColor(d->pen->color()); rectangle->setPenWidth(d->pen->width()); rectangle->setAligned(d->pen->pixelAligned()); } else { rectangle->setPenWidth(0); } rectangle->setRadius(d->radius); rectangle->setAntialiasing(d->antialiasing); QGradientStops stops; if (d->gradient) { QList<QQuickGradientStop *> qxstops = d->gradient->m_stops; for (int i = 0; i < qxstops.size(); ++i){ int j = 0; while (j < stops.size() && stops.at(j).first < qxstops[i]->position()) j++; stops.insert(j, QGradientStop(qxstops.at(i)->position(), qxstops.at(i)->color())); } } rectangle->setGradientStops(stops); rectangle->update(); return rectangle; }
int QPdfEnginePrivate::gradientBrush(const QBrush &b, const QMatrix &matrix, int *gStateObject) { const QGradient *gradient = b.gradient(); if (!gradient) return 0; QTransform inv = matrix.inverted(); QPointF page_rect[4] = { inv.map(QPointF(0, 0)), inv.map(QPointF(width_, 0)), inv.map(QPointF(0, height_)), inv.map(QPointF(width_, height_)) }; bool opaque = b.isOpaque(); QByteArray shader; QByteArray alphaShader; if (gradient->type() == QGradient::LinearGradient) { const QLinearGradient *lg = static_cast<const QLinearGradient *>(gradient); shader = QPdf::generateLinearGradientShader(lg, page_rect); if (!opaque) alphaShader = QPdf::generateLinearGradientShader(lg, page_rect, true); } else { // ############# return 0; } int shaderObject = addXrefEntry(-1); write(shader); QByteArray str; QPdf::ByteStream s(&str); s << "<<\n" "/Type /Pattern\n" "/PatternType 2\n" "/Shading " << shaderObject << "0 R\n" "/Matrix [" << matrix.m11() << matrix.m12() << matrix.m21() << matrix.m22() << matrix.dx() << matrix.dy() << "]\n"; s << ">>\n" "endobj\n"; int patternObj = addXrefEntry(-1); write(str); currentPage->patterns.append(patternObj); if (!opaque) { bool ca = true; QGradientStops stops = gradient->stops(); int a = stops.at(0).second.alpha(); for (int i = 1; i < stops.size(); ++i) { if (stops.at(i).second.alpha() != a) { ca = false; break; } } if (ca) { *gStateObject = addConstantAlphaObject(stops.at(0).second.alpha()); } else { int alphaShaderObject = addXrefEntry(-1); write(alphaShader); QByteArray content; QPdf::ByteStream c(&content); c << "/Shader" << alphaShaderObject << "sh\n"; QByteArray form; QPdf::ByteStream f(&form); f << "<<\n" "/Type /XObject\n" "/Subtype /Form\n" "/BBox [0 0 " << width_ << height_ << "]\n" "/Group <</S /Transparency >>\n" "/Resources <<\n" "/Shading << /Shader" << alphaShaderObject << alphaShaderObject << "0 R >>\n" ">>\n"; f << "/Length " << content.length() << "\n" ">>\n" "stream\n" << content << "endstream\n" "endobj\n"; int softMaskFormObject = addXrefEntry(-1); write(form); *gStateObject = addXrefEntry(-1); xprintf("<< /SMask << /S /Alpha /G %d 0 R >> >>\n" "endobj\n", softMaskFormObject); currentPage->graphicStates.append(*gStateObject); } } return patternObj; }