QImage QgsMapRendererParallelJob::renderedImage()
{
  if ( mStatus == RenderingLayers )
    return composeImage( mSettings, mLayerJobs );
  else
    return mFinalImage; // when rendering labels or idle
}
void QgsMapRendererParallelJob::renderLayersFinished()
{
  Q_ASSERT( mStatus == RenderingLayers );

  // compose final image
  mFinalImage = composeImage( mSettings, mLayerJobs );

  logRenderingTime( mLayerJobs );

  cleanupJobs( mLayerJobs );

  QgsDebugMsg( "PARALLEL layers finished" );

  if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) && !mLabelingRenderContext.renderingStopped() )
  {
    mStatus = RenderingLabels;

    connect( &mLabelingFutureWatcher, SIGNAL( finished() ), this, SLOT( renderingFinished() ) );

    // now start rendering of labeling!
    mLabelingFuture = QtConcurrent::run( renderLabelsStatic, this );
    mLabelingFutureWatcher.setFuture( mLabelingFuture );
  }
  else
  {
    renderingFinished();
  }
}
Example #3
0
DImg InsertTextWidget::makeInsertText()
{
    int orgW     = d->iface->originalSize().width();
    int orgH     = d->iface->originalSize().height();
    float ratioW = (float)orgW/(float)d->w;
    float ratioH = (float)orgH/(float)d->h;

    int x, y;

    if (d->textRect.isValid())
    {
        // convert from widget to image coordinates, then to original size
        x = qRound((d->textRect.x() - d->rect.x()) * ratioW);
        y = qRound((d->textRect.y() - d->rect.y()) * ratioH);
    }
    else
    {
        x = -1;
        y = -1;
    }

    // Get original image
    DImg image      = d->iface->original()->copy();
    int borderWidth = qMax(1, qRound(ratioW));

    // compose and draw result on image
    composeImage(&image, nullptr, x, y,
                 d->textFont, d->textFont.pointSizeF(),
                 d->textRotation, d->textColor, d->textOpacity,
                 d->alignMode, d->textString, d->textTransparent, d->backgroundColor,
                 d->textBorder ? BORDER_NORMAL : BORDER_NONE, borderWidth, borderWidth);

    return image;
}
 void setImage(const QImage& src)
 {
     if ( first ) {
         first = FALSE;
         writeMHDR(src.size(),framerate);
     }
     composeImage(src,QPoint(0,0));
 }
QImage QgsMapRendererSequentialJob::renderedImage()
{
  if ( isActive() && mCache )
    // this will allow immediate display of cached layers and at the same time updates of the layer being rendered
    return composeImage( mSettings, mInternalJob->jobs() );
  else
    return mImage;
}
Example #6
0
void InsertTextWidget::makePixmap()
{
    int orgW = d->iface->originalSize().width();
    int orgH = d->iface->originalSize().height();
    float ratioW = (float)d->w / (float)orgW;
    float ratioH = (float)d->h / (float)orgH;

    int x, y;

    if (d->textRect.isValid())
    {
        // convert from widget to image coordinates
        x = d->textRect.x() - d->rect.x();
        y = d->textRect.y() - d->rect.y();
    }
    else
    {
        x = -1;
        y = -1;
    }

    // get preview image data
    DImg image = d->iface->preview();
    image.setIccProfile( d->iface->original()->getIccProfile() );

    // paint pixmap for drawing this widget
    // First, fill with background color
    d->pixmap->fill(d->bgColor);
    QPainter p(d->pixmap);

    // Convert image to pixmap and draw it
    QPixmap imagePixmap = d->iface->convertToPixmap(image);
    p.drawPixmap(d->rect.x(), d->rect.y(),
                 imagePixmap, 0, 0, imagePixmap.width(), imagePixmap.height());

    // prepare painter for use by compose image
    p.setClipRect(d->rect);
    p.translate(d->rect.x(), d->rect.y());

    int borderWidth = qMax(1, qRound(ratioW));

    // compose image and draw result directly on pixmap, with correct offset
    QRect textRect = composeImage(&image, &p, x, y,
                                  d->textFont, d->textFont.pointSizeF(),
                                  d->textRotation, d->textColor, d->textOpacity,
                                  d->alignMode, d->textString, d->textTransparent, d->backgroundColor,
                                  d->textBorder ? BORDER_NORMAL : BORDER_SUPPORT, borderWidth, borderWidth,
                                  (ratioW > ratioH) ? ratioW : ratioH);

    p.end();

    // store new text rectangle
    // convert from image to widget coordinates
    d->textRect.setX(textRect.x() + d->rect.x());
    d->textRect.setY(textRect.y() + d->rect.y());
    d->textRect.setSize(textRect.size());
}
void QgsMapRendererParallelJob::renderLabelsStatic( QgsMapRendererParallelJob *self )
{
  LabelRenderJob &job = self->mLabelJob;

  if ( !job.cached )
  {
    QTime labelTime;
    labelTime.start();

    QPainter painter;
    if ( job.img )
    {
      job.img->fill( 0 );
      painter.begin( job.img );
    }
    else
    {
      painter.begin( &self->mFinalImage );
    }

    // draw the labels!
    try
    {
      drawLabeling( self->mSettings, job.context, self->mLabelingEngineV2.get(), &painter );
    }
    catch ( QgsException &e )
    {
      Q_UNUSED( e );
      QgsDebugMsg( "Caught unhandled QgsException: " + e.what() );
    }
    catch ( std::exception &e )
    {
      Q_UNUSED( e );
      QgsDebugMsg( "Caught unhandled std::exception: " + QString::fromAscii( e.what() ) );
    }
    catch ( ... )
    {
      QgsDebugMsg( "Caught unhandled unknown exception" );
    }

    painter.end();

    job.renderingTime = labelTime.elapsed();
    job.complete = true;
    job.participatingLayers = _qgis_listRawToQPointer( self->mLabelingEngineV2->participatingLayers() );
    if ( job.img )
    {
      self->mFinalImage = composeImage( self->mSettings, self->mLayerJobs, self->mLabelJob );
    }
  }
}