QImage QwtPlotRasterItem::compose( const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &imageArea, const QRectF &paintRect, const QSize &imageSize, bool doCache) const { QImage image; if ( imageArea.isEmpty() || paintRect.isEmpty() || imageSize.isEmpty() ) return image; if ( doCache ) { if ( !d_data->cache.image.isNull() && d_data->cache.area == imageArea && d_data->cache.size == paintRect.size() ) { image = d_data->cache.image; } } if ( image.isNull() ) { double dx = 0.0; if ( paintRect.toRect().width() > imageSize.width() ) dx = imageArea.width() / imageSize.width(); const QwtScaleMap xxMap = imageMap(Qt::Horizontal, xMap, imageArea, imageSize, dx); double dy = 0.0; if ( paintRect.toRect().height() > imageSize.height() ) dy = imageArea.height() / imageSize.height(); const QwtScaleMap yyMap = imageMap(Qt::Vertical, yMap, imageArea, imageSize, dy); image = renderImage( xxMap, yyMap, imageArea, imageSize ); if ( doCache ) { d_data->cache.area = imageArea; d_data->cache.size = paintRect.size(); d_data->cache.image = image; } } if ( d_data->alpha >= 0 && d_data->alpha < 255 ) image = toRgba( image, d_data->alpha ); return image; }
/*! \brief Draw the raster data \param painter Painter \param xMap X-Scale Map \param yMap Y-Scale Map \param canvasRect Contents rect of the plot canvas */ void QwtPlotRasterItem::draw(QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const { if ( canvasRect.isEmpty() || d_data->alpha == 0 ) return; QwtDoubleRect area = invTransform(xMap, yMap, canvasRect); if ( boundingRect().isValid() ) area &= boundingRect(); const QRect paintRect = transform(xMap, yMap, area); if ( !paintRect.isValid() ) return; QImage image; bool doCache = true; if ( painter->device()->devType() == QInternal::Printer || painter->device()->devType() == QInternal::Picture ) { doCache = false; } if ( !doCache || d_data->cache.policy == NoCache ) { image = renderImage(xMap, yMap, area); if ( d_data->alpha >= 0 && d_data->alpha < 255 ) image = toRgba(image, d_data->alpha); } else if ( d_data->cache.policy == PaintCache ) { if ( d_data->cache.image.isNull() || d_data->cache.rect != area || d_data->cache.size != paintRect.size() ) { d_data->cache.image = renderImage(xMap, yMap, area); d_data->cache.rect = area; d_data->cache.size = paintRect.size(); } image = d_data->cache.image; if ( d_data->alpha >= 0 && d_data->alpha < 255 ) image = toRgba(image, d_data->alpha); } else if ( d_data->cache.policy == ScreenCache ) { const QSize screenSize = QApplication::desktop()->screenGeometry().size(); if ( paintRect.width() > screenSize.width() || paintRect.height() > screenSize.height() ) { image = renderImage(xMap, yMap, area); } else { if ( d_data->cache.image.isNull() || d_data->cache.rect != area ) { QwtScaleMap cacheXMap = xMap; cacheXMap.setPaintInterval( 0, screenSize.width()); QwtScaleMap cacheYMap = yMap; cacheYMap.setPaintInterval(screenSize.height(), 0); d_data->cache.image = renderImage( cacheXMap, cacheYMap, area); d_data->cache.rect = area; d_data->cache.size = paintRect.size(); } image = d_data->cache.image; } image = toRgba(image, d_data->alpha); } painter->drawImage(paintRect, image); }
void DistanceGrid::convertToSdf(const u8 *pImageDataIn, u8 *pImageDataOut) { fromRgba(pImageDataIn); computeSdf(m_gridInside); computeSdf(m_gridOutside); toRgba(pImageDataOut); }