18 #include <qpaintengine.h> 21 #include <qtconcurrentrun.h> 52 r.setLeft( qRound( rect.left() ) );
53 r.setRight( qRound( rect.right() ) );
54 r.setTop( qRound( rect.top() ) );
55 r.setBottom( qRound( rect.bottom() ) );
67 if ( area.left() <= xInterval.
minValue() )
70 r.adjust(0, 0, -1, 0);
78 if ( area.right() >= xInterval.
maxValue() )
83 r.adjust(0, 0, -1, 0);
89 if ( area.top() <= yInterval.
minValue() )
92 r.adjust(0, 0, 0, -1);
100 if ( area.bottom() >= yInterval.
maxValue() )
103 r.adjust(0, 1, 0, 0);
105 r.adjust(0, 0, 0, -1);
114 const QRectF &
area,
const QRectF &area2,
const QRectF &
paintRect,
117 const QRectF strippedRect =
qwtStripRect(paintRect, area2,
118 xMap, yMap, xInterval, yInterval);
119 const QSize sz = strippedRect.toRect().size();
121 const int w = image.width();
122 const int h = image.height();
125 const double pw = ( r.width() - 1) / w;
126 const double ph = ( r.height() - 1) / h;
133 px0 = px0 - xMap.
transform( area.left() );
143 px0 += strippedRect.left() - paintRect.left();
159 py0 += strippedRect.top() - paintRect.top();
161 QImage expanded( sz, image.format() );
162 if ( image.format() == QImage::Format_Indexed8 )
163 expanded.setColorTable( image.colorTable() );
165 switch( image.depth() )
169 for (
int y1 = 0; y1 < h; y1++ )
178 yy1 = qRound( y1 * ph - py0 );
190 yy2 = qRound( ( y1 + 1 ) * ph - py0 );
191 if ( yy2 > sz.height() )
195 const quint32 *line1 =
196 reinterpret_cast<const quint32 *
>( image.scanLine( y1 ) );
198 for (
int x1 = 0; x1 < w; x1++ )
207 xx1 = qRound( x1 * pw - px0 );
219 xx2 = qRound( ( x1 + 1 ) * pw - px0 );
220 if ( xx2 > sz.width() )
224 const quint32 rgb( line1[x1] );
225 for (
int y2 = yy1; y2 < yy2; y2++ )
227 quint32 *line2 =
reinterpret_cast<quint32 *
>(
228 expanded.scanLine( y2 ) );
230 for (
int x2 = xx1; x2 < xx2; x2++ )
239 for (
int y1 = 0; y1 < h; y1++ )
248 yy1 = qRound( y1 * ph - py0 );
260 yy2 = qRound( ( y1 + 1 ) * ph - py0 );
261 if ( yy2 > sz.height() )
265 const uchar *line1 = image.scanLine( y1 );
267 for (
int x1 = 0; x1 < w; x1++ )
276 xx1 = qRound( x1 * pw - px0 );
288 xx2 = qRound( ( x1 + 1 ) * pw - px0 );
289 if ( xx2 > sz.width() )
293 for (
int y2 = yy1; y2 < yy2; y2++ )
295 uchar *line2 = expanded.scanLine( y2 );
296 memset( line2 + xx1, line1[x1], xx2 - xx1 );
311 const double pw = pixelRect.width();
312 const double ph = pixelRect.height();
314 const double dx1 = pixelRect.left() - rect.left();
315 const double dx2 = pixelRect.right() - rect.right();
316 const double dy1 = pixelRect.top() - rect.top();
317 const double dy2 = pixelRect.bottom() - rect.bottom();
320 r.setLeft( pixelRect.left() -
qwtCeil( dx1 / pw ) * pw );
321 r.setTop( pixelRect.top() -
qwtCeil( dy1 / ph ) * ph );
322 r.setRight( pixelRect.right() -
qwtFloor( dx2 / pw ) * pw );
323 r.setBottom( pixelRect.bottom() -
qwtFloor( dy2 / ph ) * ph );
332 const QPointF p1 = tr.map( QPointF( xMap.
p1(), yMap.
p1() ) );
333 const QPointF p2 = tr.map( QPointF( xMap.
p2(), yMap.
p2() ) );
345 double sx1 = area.left();
346 double sx2 = area.right();
350 double sy1 = area.top();
351 double sy2 = area.bottom();
364 const QPainter *painter )
366 bool doCache =
false;
373 switch ( painter->paintEngine()->type() )
375 case QPaintEngine::SVG:
376 case QPaintEngine::Pdf:
377 case QPaintEngine::PostScript:
378 case QPaintEngine::MacPrinter:
379 case QPaintEngine::Picture:
390 const QRect& tile,
int alpha )
392 const QRgb mask1 = qRgba( 0, 0, 0, alpha );
393 const QRgb mask2 = qRgba( 255, 255, 255, 0 );
394 const QRgb mask3 = qRgba( 0, 0, 0, 255 );
396 const int y0 = tile.top();
397 const int y1 = tile.bottom();
398 const int x0 = tile.left();
399 const int x1 = tile.right();
401 if ( from->depth() == 8 )
403 for (
int y = y0; y <= y1; y++ )
405 QRgb *alphaLine =
reinterpret_cast<QRgb *
>( to->scanLine( y ) );
406 const unsigned char *line = from->scanLine( y );
408 for (
int x = x0; x <= x1; x++ )
409 *alphaLine++ = ( from->color( *line++ ) & mask2 ) | mask1;
412 else if ( from->depth() == 32 )
414 for (
int y = y0; y <= y1; y++ )
416 QRgb *alphaLine =
reinterpret_cast<QRgb *
>( to->scanLine( y ) );
417 const QRgb *line =
reinterpret_cast<const QRgb *
>( from->scanLine( y ) );
419 for (
int x = x0; x <= x1; x++ )
421 const QRgb rgb = *line++;
423 *alphaLine++ = ( rgb & mask2 ) | mask1;
614 const QRectF &canvasRect )
const 633 QRectF
paintRect = painter->transform().mapRect( canvasRect );
637 if ( br.isValid() && !br.contains( area ) )
640 if ( !area.isValid() )
650 if ( !pixelRect.isEmpty() )
653 const double dx = qAbs( xxMap.invTransform( 1 ) - xxMap.invTransform( 0 ) );
656 if ( dx > pixelRect.width() && dy > pixelRect.height() )
663 pixelRect = QRectF();
672 if ( dx > pixelRect.width() )
673 pixelRect.setWidth( dx );
675 if ( dy > pixelRect.height() )
676 pixelRect.setHeight( dy );
680 if ( pixelRect.isEmpty() )
695 area, paintRect, paintRect.size().toSize(), doCache);
696 if ( image.isNull() )
703 xxMap, yyMap, xInterval, yInterval);
705 if ( imageRect != paintRect )
708 qRound( imageRect.x() - paintRect.x()),
709 qRound( imageRect.y() - paintRect.y() ),
710 qRound( imageRect.width() ),
711 qRound( imageRect.height() ) );
713 image = image.copy(r);
724 if ( imageArea.right() == xInterval.
maxValue() &&
727 imageArea.adjust(0, 0, pixelRect.width(), 0);
729 if ( imageArea.bottom() == yInterval.
maxValue() &&
732 imageArea.adjust(0, 0, 0, pixelRect.height() );
736 imageSize.setWidth( qRound( imageArea.width() / pixelRect.width() ) );
737 imageSize.setHeight( qRound( imageArea.height() / pixelRect.height() ) );
740 imageArea, paintRect, imageSize, doCache );
742 if ( image.isNull() )
746 xxMap, yyMap, xInterval, yInterval);
748 if ( ( image.width() > 1 || image.height() > 1 ) &&
756 imageArea, area, paintRect, xInterval, yInterval );
761 painter->setWorldTransform( QTransform() );
805 r.setLeft( -0.5 * max );
812 r.setBottom( intervalY.
maxValue() );
818 r.setTop( -0.5 * max );
822 return r.normalized();
827 const QRectF &imageArea,
const QRectF &
paintRect,
828 const QSize &imageSize,
bool doCache)
const 831 if ( imageArea.isEmpty() || paintRect.isEmpty() || imageSize.isEmpty() )
844 if ( image.isNull() )
847 if ( paintRect.toRect().width() > imageSize.width() )
848 dx = imageArea.width() / imageSize.width();
851 imageMap(Qt::Horizontal, xMap, imageArea, imageSize, dx);
854 if ( paintRect.toRect().height() > imageSize.height() )
855 dy = imageArea.height() / imageSize.height();
858 imageMap(Qt::Vertical, yMap, imageArea, imageSize, dy);
860 image =
renderImage( xxMap, yyMap, imageArea, imageSize );
872 QImage alphaImage( image.size(), QImage::Format_ARGB32 );
874 #if !defined(QT_NO_QFUTURE) 877 if ( numThreads <= 0 )
878 numThreads = QThread::idealThreadCount();
880 if ( numThreads <= 0 )
883 const int numRows = image.height() / numThreads;
886 futures.reserve( numThreads - 1 );
888 for ( uint i = 0; i < numThreads; i++ )
890 QRect tile( 0, i * numRows, image.width(), numRows );
891 if ( i == numThreads - 1 )
893 tile.setHeight( image.height() - i * numRows );
902 for (
int i = 0; i < futures.size(); i++ )
903 futures[i].waitForFinished();
905 const QRect tile( 0, 0, image.width(), image.height() );
926 Qt::Orientation orientation,
928 const QSize &imageSize,
double pixelSize)
const 930 double p1, p2, s1, s2;
932 if ( orientation == Qt::Horizontal )
935 p2 = imageSize.width();
942 p2 = imageSize.height();
947 if ( pixelSize > 0.0 || p2 == 1.0 )
949 double off = 0.5 * pixelSize;
bool testPaintAttribute(PaintAttribute) const
virtual QImage renderImage(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &area, const QSize &imageSize) const =0
Render an image.
static void drawImage(QPainter *, const QRectF &, const QImage &)
Wrapper for QPainter::drawImage()
A class representing an interval.
A class, which displays raster data.
Max value is not included in the interval.
void setPaintAttribute(PaintAttribute, bool on=true)
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
static QRectF qwtStripRect(const QRectF &rect, const QRectF &area, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtInterval &xInterval, const QwtInterval &yInterval)
QFlags< PaintAttribute > PaintAttributes
Paint attributes.
int qwtFloor(qreal value)
The item is represented on the legend.
static QRectF qwtAlignRect(const QRectF &rect)
virtual QwtInterval interval(Qt::Axis) const
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const QWT_OVERRIDE
Draw the raster data.
void setCachePolicy(CachePolicy)
virtual QwtScaleMap imageMap(Qt::Orientation, const QwtScaleMap &map, const QRectF &area, const QSize &imageSize, double pixelSize) const
Calculate a scale map for painting to an image.
QImage compose(const QwtScaleMap &, const QwtScaleMap &, const QRectF &imageArea, const QRectF &paintRect, const QSize &imageSize, bool doCache) const
virtual QRectF boundingRect() const QWT_OVERRIDE
struct QwtPlotRasterItem::PrivateData::ImageCache cache
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
A class representing a text.
void setZ(double z)
Set the z value.
virtual QRectF pixelHint(const QRectF &) const
Pixel hint.
CachePolicy
Cache policy The default policy is NoCache.
Min value is not included in the interval.
QRectF paintRect(const QwtScaleMap &, const QwtScaleMap &) const
Calculate the bounding paint rectangle of 2 maps.
double invTransform(double p) const
BorderFlags borderFlags() const
void setAlpha(int alpha)
Set an alpha value for the raster data.
virtual void itemChanged()
static QImage qwtExpandImage(const QImage &image, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &area, const QRectF &area2, const QRectF &paintRect, const QwtInterval &xInterval, const QwtInterval &yInterval)
uint renderThreadCount() const
QwtPlotRasterItem(const QString &title=QString())
Constructor.
QwtPlotRasterItem::CachePolicy policy
virtual ~QwtPlotRasterItem()
Destructor.
Base class for items on the plot canvas.
void setItemAttribute(ItemAttribute, bool on=true)
double transform(double s) const
CachePolicy cachePolicy() const
static void qwtAdjustMaps(QwtScaleMap &xMap, QwtScaleMap &yMap, const QRectF &area, const QRectF &paintRect)
static QRectF qwtExpandToPixels(const QRectF &rect, const QRectF &pixelRect)
QwtPlotRasterItem::PaintAttributes paintAttributes
static bool roundingAlignment()
const QwtText & title() const
static void qwtTransformMaps(const QTransform &tr, const QwtScaleMap &xMap, const QwtScaleMap &yMap, QwtScaleMap &xxMap, QwtScaleMap &yyMap)
static bool qwtUseCache(QwtPlotRasterItem::CachePolicy policy, const QPainter *painter)
static void qwtToRgba(const QImage *from, QImage *to, const QRect &tile, int alpha)