diff --git a/traceplot.cpp b/traceplot.cpp index d0efa2c..f8b169c 100644 --- a/traceplot.cpp +++ b/traceplot.cpp @@ -26,8 +26,31 @@ TracePlot::TracePlot(std::shared_ptr source) : sampleSourc void TracePlot::paintMid(QPainter &painter, QRect &rect, range_t sampleRange) { - auto image = drawTile(QRect(0, 0, rect.width(), rect.height()), sampleRange); - painter.drawImage(rect, image); + int samplesPerColumn = sampleRange.length() / rect.width(); + int samplesPerTile = tileWidth * samplesPerColumn; + off_t tileID = sampleRange.minimum / samplesPerTile; + off_t tileOffset = sampleRange.minimum % samplesPerTile; // Number of samples to skip from first image tile + int xOffset = tileOffset / samplesPerColumn; // Number of columns to skip from first image tile + + // Paint first (possibly partial) tile + painter.drawImage( + QRect(rect.x(), rect.y(), tileWidth - xOffset, height()), + getTile(tileID++, samplesPerTile), + QRect(xOffset, 0, tileWidth - xOffset, height()) + ); + + // Paint remaining tiles + for (int x = tileWidth - xOffset; x < rect.right(); x += tileWidth) { + painter.drawImage( + QRect(x, rect.y(), tileWidth, height()), + getTile(tileID++, samplesPerTile) + ); + } +} + +QImage TracePlot::getTile(off_t tileID, off_t sampleCount) +{ + return drawTile(QRect(0, 0, tileWidth, height()), {tileID * sampleCount, (tileID + 1) * sampleCount}); } QImage TracePlot::drawTile(const QRect &rect, range_t sampleRange) diff --git a/traceplot.h b/traceplot.h index b7e0c99..1ea5e33 100644 --- a/traceplot.h +++ b/traceplot.h @@ -34,8 +34,10 @@ public: std::shared_ptr source() { return sampleSource; }; private: + const int tileWidth = 1000; std::shared_ptr sampleSource; + QImage getTile(off_t tileID, off_t sampleCount); QImage drawTile(const QRect &rect, range_t sampleRange); void plotTrace(QPainter &painter, const QRect &rect, float *samples, off_t count, int step); };